腳本主要功能包括:
注冊(cè)表讀取與修改
文件內(nèi)容修改如HOSTS、SERVICES文件
文件屬性修改和文件復(fù)制
系統(tǒng)環(huán)境變量設(shè)置
等,僅供參考
復(fù)制代碼 代碼如下:
'SAP設(shè)置腳本
'編寫: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
'========================================================================