国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

WINDOWS腳本實踐:為SAP補丁制作的VBS腳本代碼

2020-06-26 18:06:44
字體:
來源:轉載
供稿:網友
腳本主要功能包括: 

注冊表讀取與修改  
文件內容修改如HOSTS、SERVICES文件  
文件屬性修改和文件復制  
系統環境變量設置  
等,僅供參考  

復制代碼代碼如下:

'SAP設置腳本  
'編寫:SCZ 2005.04.20  
'最后修改日期: 2005.04.22  
'必須存在目錄: BW(補丁文件) 和 登入界面  
'========================================================================  
'全局變量、處理過程  
'========================================================================  
WScript.Echo "該腳本只能正常運行在WIN2000/XP/2003的操作系統管理員權限下,按'確定'繼續"  
Set objFSO = CreateObject("Scripting.FileSystemObject") '文件系統對象  
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()                    '復制文件  
Call ModifyHost(strHostPath)                '修改HOST文件  
Call ModifyServices(strServicesPath)            '修改SERVICES文件  
Call SetEvn(strSapGuiPath)                '設置環境變量  
Call SetTCPIP(strServicesPath)                '修改TCPIP參數  
WScript.Echo "BW設置處理完畢,請手動安裝SAP系統補丁"  



'========================================================================  
'通過注冊獲取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注冊信息讀取失敗,SAP未安裝或系統已損壞,安裝終止"  
        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  

'========================================================================  
'復制文件  
'========================================================================  
Function CopyFiles()  
    If NOT objFSO.FolderExists(strSapBWPath) Then    
        WScript.Echo "BW組件未安裝,請先安裝SAP的BW組件,再運行該腳本"  
        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   

'========================================================================  
'設置環境變量  
'------------------------------------------------------------------------  
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  

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

'========================================================================  
'設置TCP/IP參數  
'------------------------------------------------------------------------  
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  
'========================================================================
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙川县| 富蕴县| 农安县| 东宁县| 安达市| 会同县| 泾源县| 黄平县| 崇州市| 邵东县| 株洲县| 文昌市| 龙门县| 汉中市| 鄂托克前旗| 江陵县| 鞍山市| 兴仁县| 佛冈县| 航空| 武胜县| 文成县| 防城港市| 噶尔县| 高安市| 广饶县| 平潭县| 桦甸市| 根河市| 江孜县| 小金县| 温州市| 波密县| 德兴市| 中宁县| 石楼县| 甘孜| 丹东市| 合作市| 门源| 垣曲县|