手机
当前位置:查字典教程网 >脚本专栏 >vbs >WINDOWS脚本实践:为SAP补丁制作的VBS脚本代码
WINDOWS脚本实践:为SAP补丁制作的VBS脚本代码
摘要:脚本主要功能包括:注册表读取与修改文件内容修改如HOSTS、SERVICES文件文件属性修改和文件复制系统环境变量设置等,仅供参考复制代码代...

脚本主要功能包括:

注册表读取与修改

文件内容修改如HOSTS、SERVICES文件

文件属性修改和文件复制

系统环境变量设置

等,仅供参考

复制代码 代码如下:

'SAP设置脚本

'编写:SCZ2005.04.20

'最后修改日期:2005.04.22

'必须存在目录:BW(补丁文件)和登入界面

'========================================================================

'全局变量、处理过程

'========================================================================

WScript.Echo"该脚本只能正常运行在WIN2000/XP/2003的操作系统管理员权限下,按'确定'继续"

SetobjFSO=CreateObject("Scripting.FileSystemObject")'文件系统对象

strWindir=GetWindir()'获取WINDOWS目录

strSystem=GetSystemPath()'获取System目录

strSapPath=GetSAPPath()'SAPFrontEnd目录

strSapGuiPath=strSapPath&"SAPgui"'SapGui目录

strSapBWPath=strSapPath&"BW"'BW目录

strHostPath=GetHostFilePath()'host文件所在目录

strServicesPath=GetServicesPath()'services文件所在目录

CallCopyFiles()'复制文件

CallModifyHost(strHostPath)'修改HOST文件

CallModifyServices(strServicesPath)'修改SERVICES文件

CallSetEvn(strSapGuiPath)'设置环境变量

CallSetTCPIP(strServicesPath)'修改TCPIP参数

WScript.Echo"BW设置处理完毕,请手动安装SAP系统补丁"

'========================================================================

'通过注册获取SAPFrontEnd目录

'========================================================================

FunctionGetSAPPath()

ConstHKEY_LOCAL_MACHINE=&H80000002

strComputer="."

SetobjReg=GetObject("winmgmts:{impersonationLevel=impersonate}!"&_

strComputer&"ootdefault:StdRegProv")

strKeyPath="SOFTWARESAPSAPShared"

strEntryName="SAPdestdir"

objReg.GetStringValueHKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue

GetSAPPath=strValue

IfIsNull(strValue)Then

Wscript.Echo"SAP注册信息读取失败,SAP未安装或系统已损坏,安装终止"

Err.Raise(507)

Err.Clear

EndIf

EndFunction

'========================================================================

'获取WINDOWS目录

'========================================================================

FunctionGetWindir()

ConstWindowFolder=0

SetGetWindir=objFSO.GetSpecialFolder(WindowFolder)

EndFunction

'========================================================================

'获取SYSTEM目录

'========================================================================

FunctionGetSystemPath()

ConstSystemFolder=1

SetGetSystemPath=objFSO.GetSpecialFolder(SystemFolder)

EndFunction

'========================================================================

'获取HOST文件所在目录

'========================================================================

FunctionGetHostFilePath()

GetHostFilePath=strSystem&"driversetc"

EndFunction

'========================================================================

'获取Services文件所在目录

'========================================================================

FunctionGetServicesPath()

GetServicesPath=strSystem&"driversetc"

EndFunction

'========================================================================

'复制文件

'========================================================================

FunctionCopyFiles()

IfNOTobjFSO.FolderExists(strSapBWPath)Then

WScript.Echo"BW组件未安装,请先安装SAP的BW组件,再运行该脚本"

Err.Raise(507)

Err.Clear

EndIf

CallClearAttribs(strSapBWPath)

objFSO.CopyFile"登陆界面*.ini",strWindir

objFSO.CopyFile"BWgssntlm.dll",strSapGuiPath&"gssntlm.dll"

objFSO.CopyFile"BWsncgss32.dll",strSystem&"sncgss32.dll"

strBakFolder=strSapBWPath&"ak"

IFNOTobjFSO.FolderExists(strBakFolder)Then

objFSO.CreateFolder(strBakFolder)

Else

CallClearAttribs(strBakFolder)

EndIf

objFSO.CopyFilestrSapBWPath&"*.xla",strBakFolder

objFSO.CopyFile"BW*.xla",strSapBWPath

EndFunction

'========================================================================

'去除文件只读属性

'========================================================================

FunctionClearAttribs(strFolder)

CallClearFileAttrib(strFolder&"sapbex.xla")

CallClearFileAttrib(strFolder&"sapbexc.xla")

CallClearFileAttrib(strFolder&"sapbexs.xla")

CallClearFileAttrib(strFolder&"sapbex0.xla")

CallClearFileAttrib(strSystem&"sncgss32.dll")

EndFunction

'========================================================================

'去除文件只读属性

'========================================================================

FunctionClearFileAttrib(strFile)

IfobjFSO.FileExists(strFile)Then

Setf=objFSO.GetFile(strFile)

f.Attributes=0

EndIf

EndFunction

'========================================================================

'修改HOST文件

'========================================================================

FunctionModifyHost(strHostPath)

strHostFile=strHostPath&"hosts"

strHostBak=strHostPath&"hosts.bak"

ConstForReading=1,ForWriting=2,ForAppending=8

objFSO.CopyFilestrHostFile,strHostBak

SetobjFile=objFSO.OpenTextFile(strHostFile,ForReading,False)

strContents=objFile.ReadAll

objFile.Close

SetobjFile=objFSO.OpenTextFile(strHostFile,ForAppending,False)

objFile.WriteBlankLines1

compResult=Instr(strContents,"192.168.0.136")

IfcompResult=0ThenobjFile.WriteLine("192.168.0.136"&Chr(9)&"bwprd")

compResult=Instr(strContents,"192.168.0.135")

IfcompResult=0ThenobjFile.WriteLine("192.168.0.135"&Chr(9)&"bwdev")

compResult=Instr(strContents,"192.168.0.171")

IfcompResult=0ThenobjFile.WriteLine("192.168.0.171"&Chr(9)&"bwqas")

objFile.close

EndFunction

'========================================================================

'修改SERVICES文件

'========================================================================

FunctionModifyServices(strServicesPath)

strServicesFile=strServicesPath&"services"

strServicesbak=strServicesPath&"services.bak"

ConstForReading=1,ForWriting=2,ForAppending=8

objFSO.CopyFilestrServicesFile,strServicesbak

SetobjFile=objFSO.OpenTextFile(strServicesFile,ForReading,False)

strContents=objFile.ReadAll

objFile.Close

SetobjFile=objFSO.OpenTextFile(strServicesFile,ForAppending,False)

objFile.WriteBlankLines1

compResult=Instr(strContents,"sapmsP01")

IfcompResult=0ThenobjFile.WriteLine("sapmsP01"&Chr(9)&"3600/tcp")

objFile.Close

EndFunction

'========================================================================

'设置环境变量

'------------------------------------------------------------------------

FunctionSetEvn(strSapGuiPath)

strComputer="."

SetobjWMIService=GetObject("winmgmts:"&strComputer&"ootcimv2")

SetcolItems=objWMIService.ExecQuery("Select*fromWin32_Environmentwherename='SNC_LIB'")

Found=False

ForEachobjItemincolItems

IfUCase(objItem.Name)="SNC_LIB"Then

Found=True

objItem.VariableValue=strSapGuiPath&"gssntlm.dll"

objItem.Put_

EndIf

Next

If(Found=False)Then

SetoEvn=objWMIService.Get("Win32_Environment").Spawninstance_

oEvn.Name="SNC_LIB"

oEvn.VariableValue=strSapGuiPath&"gssntlm.dll"

oEvn.SystemVariable=True

oEvn.UserName="<SYSTEM>"

oEvn.Status="OK"

SetoPath=oEvn.Put_

EndIf

EndFunction

'========================================================================

'========================================================================

'设置TCP/IP参数

'------------------------------------------------------------------------

FunctionSetTCPIP(strServicesPath)

ConstHKEY_LOCAL_MACHINE=&H80000002

strComputer="."

SetobjReg=GetObject("winmgmts:{impersonationLevel=impersonate}!"&_

strComputer&"ootdefault:StdRegProv")

strKeyPath="SYSTEMCurrentControlSetServicesTcpipParameters"

strEntryName="DataBasePath"

objReg.SetStringValueHKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strServicesPath

EndFunction

'========================================================================

【WINDOWS脚本实践:为SAP补丁制作的VBS脚本代码】相关文章:

自动复制U盘文件的VBS脚本

批量替换快捷方式目的路径的VBS脚本

用vbs实现枚举网络连接的代码

刷QQ群的VBS脚本

常用VBS代码 值得一看

vbs实现的eMule电驴自动关机脚本代码

用vbs脚本来关闭 HTML 页面的代码

用vbs实现本地连接禁用/启用脚本代码

获取远程机器共享目录的物理路径的代码

VBS实现的系统服务备份优化代码

精品推荐
分类导航