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

首頁 > 編程 > VBScript > 正文

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

2020-07-26 12:03:29
字體:
來源:轉載
供稿:網友
腳本主要功能包括:

注冊表讀取與修改 
文件內容修改如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 
'========================================================================
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肇东市| 古田县| 来宾市| 西藏| 台州市| 新竹县| 太仓市| 浦城县| 信阳市| 蒙城县| 林芝县| 乡宁县| 双峰县| 德钦县| 永吉县| 监利县| 临澧县| 江安县| 昭苏县| 车致| 临夏市| 加查县| 邓州市| 宝山区| 买车| 龙口市| 五常市| 弥勒县| 宁陵县| 贵州省| 北安市| 长乐市| 桂平市| 洛南县| 海淀区| 东兴市| 平定县| 福安市| 大荔县| 琼中| 札达县|