WINDOWS Script practice: VBS script code for SAP Patches

Source: Internet
Author: User

Script functions include:

Read and modify the Registry
File Content modification, such as HOSTS and SERVICES files
File Attribute Modification and file copy
System environment variable settings
For reference only

Copy codeThe Code is as follows: 'sap setup script
'Compilation: SCZ 2005.04.20
'Last modification date: 2005.04.22
'The directory must exist: BW (patch file) and logon Interface
'================================================ ======================================
'Global variables, processing process
'================================================ ======================================
WScript. Echo "the script can only run normally under the Operating System Administrator permission of WIN2000/XP/2003, and press" OK "to continue"
Set objFSO = CreateObject ("Scripting. FileSystemObject") 'File System Object
StrWindir = GetWindir () 'to obtain the WINDOWS directory
StrSystem = GetSystemPath () 'Get the System directory
StrSapPath = GetSAPPath () 'sap FrontEnd directory
StrSapGuiPath = strSapPath & "SAPgui" 'sapgui directory
StrSapBWPath = strSapPath & "BW" 'bw directory
StrHostPath = GetHostFilePath () 'Directory of the host file
StrServicesPath = GetServicesPath () 'service file directory

Call CopyFiles () 'Copy an object
Call ModifyHost (strHostPath) 'to modify the HOST file
Call ModifyServices (strServicesPath) 'to modify the SERVICES file
Call SetEvn (strSapGuiPath) 'to set the environment variable
Call SetTCPIP (strServicesPath) 'to modify the TCPIP Parameter
WScript. Echo "BW settings are completed. Install SAP system patches manually"

'================================================ ======================================
'Obtain the SAP FrontEnd directory through registration
'================================================ ======================================
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 "failed to read SAP registration information. SAP is not installed or the system is damaged. installation is terminated"
Err. Raise (507)
Err. Clear
End If
End Function

'================================================ ======================================
'Get the WINDOWS directory
'================================================ ======================================
Function GetWindir ()
Const WindowFolder = 0
Set GetWindir = objFSO. GetSpecialFolder (WindowFolder)
End Function

'================================================ ======================================
'Get the SYSTEM directory
'================================================ ======================================
Function GetSystemPath ()
Const SystemFolder = 1
Set GetSystemPath = objFSO. GetSpecialFolder (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 an object
'================================================ ======================================
Function CopyFiles ()
If NOT objFSO. FolderExists (strSapBWPath) Then
WScript. Echo "The BW component is not installed. Install the sap bw component before running the script"
Err. Raise (507)
Err. Clear
End If

Call ClearAttribs (strSapBWPath)

ObjFSO. CopyFile "Logon interface *. ini", strWindir
ObjFSO. CopyFile "BWgssntlm. dll", strSapGuiPath & "gssntlm. dll"
ObjFSO. CopyFile "BWsncgss32.dll", strSystem & "sncgss32.dll"

StrBakFolder = strSapBWPath &"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.