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