佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > WINDOWS腳本實(shí)踐:為SAP補(bǔ)丁制作的VBS腳本代碼

WINDOWS腳本實(shí)踐:為SAP補(bǔ)丁制作的VBS腳本代碼

熱門(mén)標(biāo)簽:智能手機(jī) 呼叫中心市場(chǎng)需求 網(wǎng)站文章發(fā)布 檢查注冊(cè)表項(xiàng) 美圖手機(jī) 銀行業(yè)務(wù) 服務(wù)器配置 鐵路電話系統(tǒng)
腳本主要功能包括:

注冊(cè)表讀取與修改 
文件內(nèi)容修改如HOSTS、SERVICES文件 
文件屬性修改和文件復(fù)制 
系統(tǒng)環(huán)境變量設(shè)置 
等,僅供參考 

復(fù)制代碼 代碼如下:

'SAP設(shè)置腳本 
'編寫(xiě):SCZ 2005.04.20 
'最后修改日期: 2005.04.22 
'必須存在目錄: BW(補(bǔ)丁文件) 和 登入界面 
'======================================================================== 
'全局變量、處理過(guò)程 
'======================================================================== 
WScript.Echo "該腳本只能正常運(yùn)行在WIN2000/XP/2003的操作系統(tǒng)管理員權(quán)限下,按'確定'繼續(xù)" 
Set objFSO = CreateObject("Scripting.FileSystemObject") '文件系統(tǒng)對(duì)象 
strWindir = GetWindir()                    '獲取WINDOWS目錄 
strSystem = GetSystemPath()                '獲取System目錄 
strSapPath = GetSAPPath()                 'SAP FrontEnd目錄 
strSapGuiPath = strSapPath  "SAPgui"            'SapGui目錄 
strSapBWPath = strSapPath  "BW"            'BW目錄 
strHostPath = GetHostFilePath()             'host 文件所在目錄 
strServicesPath = GetServicesPath()             'services 文件所在目錄 

Call CopyFiles()                    '復(fù)制文件 
Call ModifyHost(strHostPath)                '修改HOST文件 
Call ModifyServices(strServicesPath)            '修改SERVICES文件 
Call SetEvn(strSapGuiPath)                '設(shè)置環(huán)境變量 
Call SetTCPIP(strServicesPath)                '修改TCPIP參數(shù) 
WScript.Echo "BW設(shè)置處理完畢,請(qǐng)手動(dòng)安裝SAP系統(tǒng)補(bǔ)丁" 



'======================================================================== 
'通過(guò)注冊(cè)獲取SAP FrontEnd目錄 
'======================================================================== 
Function GetSAPPath() 
    Const HKEY_LOCAL_MACHINE = H80000002 
    strComputer = "." 
    Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\"  _ 
         strComputer  " ootdefault:StdRegProv") 

    strKeyPath = "SOFTWARESAPSAP Shared" 
    strEntryName = "SAPdestdir" 
    objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue 
    GetSAPPath = strValue 
    If IsNull(strValue) Then  
        Wscript.Echo "SAP注冊(cè)信息讀取失敗,SAP未安裝或系統(tǒng)已損壞,安裝終止" 
        Err.Raise(507) 
        Err.Clear 
    End If 
End Function 


'======================================================================== 
'獲取WINDOWS目錄 
'======================================================================== 
Function GetWindir() 
    Const WindowFolder = 0 
    Set GetWindir = objFSO.GetSpecialFolder(WindowFolder) 
End Function 


'======================================================================== 
'獲取SYSTEM目錄 
'======================================================================== 
Function GetSystemPath() 
    Const SystemFolder = 1 
    Set GetSystemPath = objFSO.GetSpecialFolder(SystemFolder) 
End Function 


'======================================================================== 
'獲取HOST文件所在目錄 
'======================================================================== 
Function GetHostFilePath() 
    GetHostFilePath = strSystem  "driversetc" 
End Function 


'======================================================================== 
'獲取Services文件所在目錄 
'======================================================================== 
Function GetServicesPath() 
    GetServicesPath = strSystem  "driversetc" 
End Function 

'======================================================================== 
'復(fù)制文件 
'======================================================================== 
Function CopyFiles() 
    If NOT objFSO.FolderExists(strSapBWPath) Then   
        WScript.Echo "BW組件未安裝,請(qǐng)先安裝SAP的BW組件,再運(yùn)行該腳本" 
        Err.Raise(507) 
        Err.Clear 
    End If 

    Call ClearAttribs(strSapBWPath) 

    objFSO.CopyFile "登陸界面*.ini" , strWindir 
    objFSO.CopyFile "BWgssntlm.dll" , strSapGuiPath  "gssntlm.dll" 
    objFSO.CopyFile "BWsncgss32.dll" , strSystem   "sncgss32.dll" 

    strBakFolder =strSapBWPath  "ak" 
    IF NOT objFSO.FolderExists(strBakFolder) Then   
        objFSO.CreateFolder(strBakFolder) 
    Else  
        Call ClearAttribs(strBakFolder) 
    End If 

    objFSO.CopyFile strSapBWPath  "*.xla" , strBakFolder 
    objFSO.CopyFile "BW*.xla" , strSapBWPath 
End Function 

'======================================================================== 
'去除文件只讀屬性 
'======================================================================== 
Function ClearAttribs(strFolder) 
    Call ClearFileAttrib(strFolder  "sapbex.xla") 
    Call ClearFileAttrib(strFolder  "sapbexc.xla") 
    Call ClearFileAttrib(strFolder  "sapbexs.xla") 
    Call ClearFileAttrib(strFolder  "sapbex0.xla") 
    Call ClearFileAttrib(strSystem   "sncgss32.dll") 
End Function 

'======================================================================== 
'去除文件只讀屬性 
'======================================================================== 
Function ClearFileAttrib(strFile) 
    If objFSO.FileExists(strFile) Then  
        Set f = objFSO.GetFile(strFile) 
        f.Attributes = 0 
    End If  
End Function 

'======================================================================== 
'修改HOST文件 
'======================================================================== 
Function ModifyHost(strHostPath) 
    strHostFile = strHostPath  "hosts" 
    strHostBak = strHostPath  "hosts.bak" 
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 
    objFSO.CopyFile strHostFile , strHostBak 
    Set objFile = objFSO.OpenTextFile(strHostFile, ForReading, False) 
    strContents = objFile.ReadAll 
    objFile.Close 

    Set objFile = objFSO.OpenTextFile(strHostFile, ForAppending, False) 
    objFile.WriteBlankLines 1 
    compResult = Instr(strContents,"192.168.0.136") 
    If compResult = 0 Then objFile.WriteLine("192.168.0.136"  Chr(9)  "bwprd") 
    compResult = Instr(strContents,"192.168.0.135") 
    If compResult = 0 Then objFile.WriteLine("192.168.0.135"  Chr(9)  "bwdev") 
    compResult = Instr(strContents,"192.168.0.171") 
    If compResult = 0 Then objFile.WriteLine("192.168.0.171"  Chr(9)  "bwqas") 
    objFile.close 
End Function  

'======================================================================== 
'修改SERVICES文件 
'======================================================================== 
Function ModifyServices(strServicesPath) 
    strServicesFile = strServicesPath  "services" 
    strServicesbak = strServicesPath  "services.bak" 
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 
    objFSO.CopyFile strServicesFile , strServicesbak 
    Set objFile = objFSO.OpenTextFile(strServicesFile, ForReading, False) 
    strContents = objFile.ReadAll 
    objFile.Close 

    Set objFile = objFSO.OpenTextFile(strServicesFile, ForAppending, False) 
    objFile.WriteBlankLines 1 
    compResult = Instr(strContents, "sapmsP01") 
    If compResult = 0 Then objFile.WriteLine("sapmsP01"  Chr(9)  "3600/tcp") 
    objFile.Close 
End Function  

'======================================================================== 
'設(shè)置環(huán)境變量 
'------------------------------------------------------------------------ 
Function SetEvn(strSapGuiPath) 
    strComputer = "." 
    Set objWMIService = GetObject("winmgmts:\"  strComputer  " ootcimv2") 
    Set colItems = objWMIService.ExecQuery( "Select * from Win32_Environment where name = 'SNC_LIB'") 
    Found = False 

    For Each objItem in colItems 
        If UCase(objItem.Name) = "SNC_LIB" Then 
                Found = True 
                objItem.VariableValue = strSapGuiPath  "gssntlm.dll" 
                objItem.Put_ 
           End If 
    Next 

    If (Found = False) Then   
            Set oEvn = objWMIService.Get("Win32_Environment").Spawninstance_ 
            oEvn.Name = "SNC_LIB" 
            oEvn.VariableValue = strSapGuiPath  "gssntlm.dll" 
            oEvn.SystemVariable = True 
            oEvn.UserName = "SYSTEM>" 
            oEvn.Status = "OK" 
            Set oPath = oEvn.Put_ 
     End If 

End Function 

'======================================================================== 

'======================================================================== 
'設(shè)置TCP/IP參數(shù) 
'------------------------------------------------------------------------ 
Function SetTCPIP(strServicesPath) 
    Const HKEY_LOCAL_MACHINE = H80000002 
    strComputer = "." 
    Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\"  _ 
         strComputer  " ootdefault:StdRegProv") 

    strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters" 
    strEntryName = "DataBasePath" 
    objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strServicesPath 
End Function 
'========================================================================

標(biāo)簽:滄州 上海 河南 新疆 長(zhǎng)治 紅河 沈陽(yáng) 樂(lè)山

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《WINDOWS腳本實(shí)踐:為SAP補(bǔ)丁制作的VBS腳本代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    西盟| 金秀| 衡山县| 南投市| 张北县| 北辰区| 元江| 松潘县| 黄平县| 株洲市| 修武县| 正宁县| 通州市| 克拉玛依市| 建湖县| 波密县| 临沂市| 吕梁市| 县级市| 巩义市| 和政县| 勐海县| 齐齐哈尔市| 雷州市| 金阳县| 金塔县| 汕头市| 安溪县| 青田县| 长岭县| 阿瓦提县| 陇南市| 个旧市| 沅陵县| 林口县| 元江| 南昌市| 民丰县| 武平县| 湖北省| 大城县|