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
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
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