'SAP setup script
'Written by: SCZ 2005.04.20
'Last modified date: 2005.04.22
'The directory must exist: BW (patch file) and login interface
'========================================================================
'Global variables, processing process
'========================================================================
"This script can only run normally under the operating system administrator privileges of WIN2000/XP/2003, press 'OK' to continue"
Set objFSO = CreateObject("") 'File System Object
strWindir = GetWindir() �
strSystem= GetSystemPath()
strSapPath = GetSAPPath() 'SAP FrontEnd directory
strSapGuiPath = strSapPath & "SAPgui" 'SapGui Directory
strSapBWPath = strSapPath & "BW" 'BW Directory
strHostPath = GetHostFilePath() �
strServicesPath = GetServicesPath() �
Call CopyFiles() �
Call ModifyHost(strHostPath)
Call ModifyServices(strServicesPath) 'Modify SERVICES file
Call SetEvn(strSapGuiPath) 'Set environment variables
Call SetTCPIP(strServicesPath) �
"BW settings are processed, please manually install the SAP system patch"
'========================================================================
'Get the SAP FrontEnd directory by registering
'========================================================================
Function GetSAPPath()
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" & _
strComputer & " ootdefault:StdRegProv")
strKeyPath = "SOFTWARESAPSAP Shared"
strEntryName = "SAPdestdir"
HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
GetSAPPath = strValue
If IsNull(strValue) Then
"SAP registration information failed to be read, SAP is not installed or the system is damaged, installation is terminated"
(507)
End If
End Function
'========================================================================
'Get the WINDOWS directory
'========================================================================
Function GetWindir()
Const WindowFolder = 0
Set GetWindir = (WindowFolder)
End Function
'========================================================================
'Get the SYSTEM directory
'========================================================================
Function GetSystemPath()
Const SystemFolder = 1
Set GetSystemPath = (SystemFolder)
End Function
'========================================================================
'Get the directory where the HOST file is located
'========================================================================
Function GetHostFilePath()
GetHostFilePath = strSystem & "driversetc"
End Function
'========================================================================
'Get the directory where the Services file is located
'========================================================================
Function GetServicesPath()
GetServicesPath = strSystem & "driversetc"
End Function
'========================================================================
'Copy the file
'========================================================================
Function CopyFiles()
If NOT (strSapBWPath) Then
"The BW component is not installed. Please install the BW component of SAP first, and then run the script"
(507)
End If
Call ClearAttribs(strSapBWPath)
"Login interface*.ini" , strWindir
"" , strSapGuiPath & ""
"" , strSystem & ""
strBakFolder =strSapBWPath & "ak"
IF NOT (strBakFolder) Then
(strBakFolder)
Else
Call ClearAttribs(strBakFolder)
End If
strSapBWPath & "*.xla" , strBakFolder
"BW*.xla" , strSapBWPath
End Function
'========================================================================
'Remove the file read-only attribute
'========================================================================
Function ClearAttribs(strFolder)
Call ClearFileAttrib(strFolder & "")
Call ClearFileAttrib(strFolder & "")
Call ClearFileAttrib(strFolder & "")
Call ClearFileAttrib(strFolder & "")
Call ClearFileAttrib(strSystem & "")
End Function
'========================================================================
'Remove the file read-only attribute
'========================================================================
Function ClearFileAttrib(strFile)
If (strFile) Then
Set f = (strFile)
= 0
End If
End Function
'========================================================================
'Modify the HOST file
'========================================================================
Function ModifyHost(strHostPath)
strHostFile = strHostPath & "hosts"
strHostBak = strHostPath & ""
Const ForReading = 1, ForWriting = 2, ForAppending = 8
strHostFile , strHostBak
Set objFile = (strHostFile, ForReading, False)
strContents =
Set objFile = (strHostFile, ForAppending, False)
1
compResult = Instr(strContents,"192.168.0.136")
If compResult = 0 Then ("192.168.0.136" & Chr(9) & "bwprd")
compResult = Instr(strContents,"192.168.0.135")
If compResult = 0 Then ("192.168.0.135" & Chr(9) & "bwdev")
compResult = Instr(strContents,"192.168.0.171")
If compResult = 0 Then ("192.168.0.171" & Chr(9) & "bwqas")
End Function
'========================================================================
'Modify the SERVICES file
'========================================================================
Function ModifyServices(strServicesPath)
strServicesFile = strServicesPath & "services"
strServicesbak = strServicesPath & ""
Const ForReading = 1, ForWriting = 2, ForAppending = 8
strServicesFile , strServicesbak
Set objFile = (strServicesFile, ForReading, False)
strContents =
Set objFile = (strServicesFile, ForAppending, False)
1
compResult = Instr(strContents, "sapmsP01")
If compResult = 0 Then ("sapmsP01" & Chr(9) & "3600/tcp")
End Function
'========================================================================
'Set environment variables
'------------------------------------------------------------------------
Function SetEvn(strSapGuiPath)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & " ootcimv2")
Set colItems = ( "Select * from Win32_Environment where name = 'SNC_LIB'")
Found = False
For Each objItem in colItems
If UCase() = "SNC_LIB" Then
Found = True
= strSapGuiPath & ""
objItem.Put_
End If
Next
If (Found = False) Then
Set oEvn = ("Win32_Environment").Spawninstance_
= "SNC_LIB"
= strSapGuiPath & ""
= True
= "<SYSTEM>"
= "OK"
Set oPath = oEvn.Put_
End If
End Function
'========================================================================
'========================================================================
'Set TCP/IP parameters
'------------------------------------------------------------------------
Function SetTCPIP(strServicesPath)
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" & _
strComputer & " ootdefault:StdRegProv")
strKeyPath = "SYSTEMCurrentControlSetServicesTcpipParameters"
strEntryName = "DataBasePath"
HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strServicesPath
End Function
'========================================================================