可以从一台远程服务器运行 SP2 安装程序Install.vbs
作者 佚名
来源 ASP编程
浏览
发布时间 2013-07-09
Install.vbs 发布者MicrosoftCorporation脚本专家 此脚本由scenario1.vbs在一台网络主机上启动。Install.vbs可以在安装了SP2的主机上以本地方式运行,它执行以下任务: ?从一台远程服务器运行SP2安装程序。 ?在主机上设置AutoAdmin和RunOnce两个注册表项。 ?将结果记录到文本文件computername-sp2-instlog.txt并将该文件复制回管理工作站。 ?强制重新启动,随后runonce.vbs将自动启动。 在基本方案中,SP2安装程序文件位于列表中的所有网络主机均可访问的一台远程服务器上。在该方案的某种变化方案中,如果将SP2安装程序复制到本地主机并从这里运行,则应重命名此脚本(例如重命名为install-remote.vbs),然后将install-local.vbs重命名为install.vbs。您还必须对这些脚本中提到的scenario1.vbs和新的install.vbs做一些细微更改。 有关方案1以及各个脚本的作用的进一步说明,请参见对这些脚本的介绍,网址是: http://www.microsoft.com/technet/scriptcenter/solutions/appcompat.msxp Install.vbs对应于install.cmd,但增加了一些新功能;install.cmd是ApplicationCompatibilityTestingandMitigationGuideforWindowsXPServicePack2(WindowsXPServicePack2应用程序兼容性测试和缓解指南)“附录”中介绍的附带脚本之一。您可以从以下网址下载用来安装该指南及其关联脚本的WindowsInstaller(.msi)文件: http://www.microsoft.com/downloads/details.aspx?FamilyId=9300BECF-2DEE-4772-ADD9-AD0EAF89C4A7&displaylang=en 要使用此脚本,请复制代码,将代码粘贴到记事本中,然后将脚本另存为install.vbs。此脚本被设计成了作为scenario1.vbs启动的进程的一部分自动运行。 脚本代码 复制代码 代码如下: ''****************************************************************************** ''install.vbs ''Author:PeterCostantini,theMicrosoftScriptingGuys ''Date:9/1/04 ''Mustbedeployedtoaclientandlaunchedremotelybyscenario1.vbs. ''Assumesthatrunonce.vbsisinsamedirectoryasscript. ''AssumesthatWindowsXPServicePack2setupprogramisonaremoteserver ''andrunonce.vbsareinsamedirectoryasscript. ''1.RunsServicePack2setupprogramfromremoteservertoinstall ''WindowsXPServicePack2.Thiscouldtakeoneortwohours. ''2.ConfigurestheAutoAdminandRunOnceregistrysettingsnecessary ''torunrunonce.vbs. ''3.Logsresultstotextfile,<computername>-sp2-instlog.txtandcopies ''thefilebacktoadminworkstation. ''4.ForcesarebootofthelocalmachinesothattheAutoAdminandRunOnce ''registrysettingstakeeffect. ''****************************************************************************** OnErrorResumeNext ''Initializeglobalconstantsandvariables. ConstFOR_APPENDING=8 g_strLocalFolder="c:\temp-ac" ''Changenameofcomputertoactualadministrativeworkstationorlocal ''pathtowhichlogshouldbecopied. g_strRemoteFolder="\\<adminwkstn>\c$\temp-ac" ''Getcomputername. g_strComputer=GetComputerName g_strLogFile=g_strComputer&"-sp2-instlog.txt" ''Createlogfile. SetobjFSO=CreateObject("Scripting.FileSystemObject") SetobjTextStream=objFSO.OpenTextFile(g_strLogFile,FOR_APPENDING,True) objTextStream.WriteLine"WindowsXPServicePack2"&_ "InstallationandConfigurationLog:Phase1" objTextStream.WriteLineNow objTextStream.WriteLineg_strComputer objTextStream.WriteLineString(Len(g_strComputer),"-") ''Handlelogicofcallingfunctionsandsub-routinestoinstallServicePack2 ''andconfigureAutoAdministration. blnInstallSP=InstallSP IfblnInstallSP=FalseThen CopyLog WScript.Quit EndIf blnAutoAdmin=ConfigAutoAdmin IfblnAutoAdmin=FalseThen CopyLog WScript.Quit EndIf Reboot ''****************************************************************************** FunctionGetComputerName SetobjWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\."_ &"\root\cimv2") SetcolSystems=objWMIService.ExecQuery("SELECT*FROMWin32_ComputerSystem") ForEachobjSytemIncolSystems GetComputerName=objSytem.Name Next EndFunction ''****************************************************************************** FunctionInstallSP ''EditthislinetoincludetheserverandsharenamewheretheWindowsXP ''ServicePack2setupprogramislocated. strInstallPath="\\servername\xpsp2\WindowsXP-KB835935-SP2-ENU.exe"&_ "/quiet/norestart/o" SetWshShell=CreateObject("Wscript.Shell") SetobjExec=WshShell.Exec(strInstallPath) ''Thiscouldtakeoneortwohours. objTextStream.WriteLine"Installationstarted..." IfErr=0Then ''LoopuntilExecisfinished-Status=1. DoWhileobjExec.Status=0 ''Pausefor10secondsbeforechecking. ''Toreducenetworktraffic,makeintervallonger. WScript.Sleep10000 Loop objTextStream.WriteLine"ServicePack2installationcompleted." InstallSP=True Else objTextStream.WriteLine"UnabletoinstallServicePack2."&VbCrLf&_ "ErrorconnectingtoServicePack2onserver."&VbCrLf&_ "Errornumber:"&Err.Number&VbCrLf&_ "Errorsource:"&Err.Source&VbCrLf&_ "Errordescription:"&Err.Description InstallSP=False EndIf Err.Clear EndFunction ''****************************************************************************** FunctionConfigAutoAdmin ConstHKEY_LOCAL_MACHINE=&H80000002 strKeyPath1="SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon" strKeyPath2="SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" strDefaultUserName="Administrator" strDefaultPassword="P@ssw0rd" strDefaultDomainName="Contoso" intAutoAdminLogon=1 strRunOnceEntry="MyScript" strRunoncePath=g_strLocalFolder&"\runonce.vbs" SetobjReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_ g_strComputer&"\root\default:StdRegProv") ''SetstrDefaultUserNametouserwithAdministratorcredentials. intRet1=objReg.SetStringValue(HKEY_LOCAL_MACHINE,strKeyPath1,_ "DefaultUserName",strDefaultUserName) IfintRet1<>0Then objTextStream.WriteLine"Error:DefaultUserNamenotconfigured." EndIf ''SetstrDefaultPasswordtopasswordofdefaultusername. intRet2=objReg.SetStringValue(HKEY_LOCAL_MACHINE,strKeyPath1,_ "DefaultPassword",strDefaultPassword) IfintRet2<>0Then objTextStream.WriteLine"Error:DefaultPasswordnotconfigured." EndIf ''Uncommentnext5linesandeditlastparameterifdefaultdomain ''forthecredentialsisdifferentfromthatalreadyset. ''intRet3=objReg.SetStringValue(HKEY_LOCAL_MACHINE,strKeyPath1,_ ''"DefaultDomainName",strDefaultDomainName) ''IfintRet3<>0Then ''objTextStream.WriteLine"Error:DefaultDomainNamenotconfigured." ''EndIf ''TurnonAutoAdminLogon intRet4=objReg.SetStringValue(HKEY_LOCAL_MACHINE,strKeyPath1,_ "AutoAdminLogon","1") IfintRet4<>0Then objTextStream.WriteLine"Error:AutoAdminLogonnotconfigured." EndIf ''AddMyScriptentrytoRunOncesubkey. intRet5=objReg.SetStringValue(HKEY_LOCAL_MACHINE,strKeyPath2,_ strRunOnceEntry,strRunoncePath) IfintRet5<>0Then objTextStream.WriteLine"Error:MyScriptRunOnceentrynotconfigured." EndIf ''Checkthatallregistrywriteoperationssucceeded. If(intRet1+intRet2+intRet3+intRet4+intRet5)=0Then objTextStream.WriteLine"AutoAdminLogonandRunOnceconfigured." ConfigAutoAdmin=True Else objTextStream.WriteLine"Error:AutoAdminLogonandRunOncenotfully"&_ "configured." ConfigAutoAdmin=False EndIf EndFunction ''****************************************************************************** SubReboot ConstFORCED_REBOOT=6 SetobjWMIService=GetObject("winmgmts:{impersonationLevel=impersonate,"&_ "(Shutdown)}!\\"&g_strComputer&"\root\cimv2") SetcolOSes=objWMIService.ExecQuery("SELECT*FROMWin32_OperatingSystem") objTextStream.WriteLine"Attemptingtoreboot..." CopyLog ForEachobjOSIncolOSes''OnlyoneobjOSincollection intReturn=objOS.Win32Shutdown(FORCED_REBOOT) IfintReturn<>0Then SetobjTextStream=objFSO.OpenTextFile(g_strLogFile,FOR_APPENDING,True) objTextStream.WriteLineNow objTextStream.WriteLine"Error:Unabletoreboot."&VbCrLf&_ "Returncode:"&intReturn CopyLog EndIf Next EndSub ''****************************************************************************** SubCopyLog ''Closetextfile. objTextStream.WriteLine"Closinglogandattemptingtocopyfileto"&_ "administrativeworkstation." objTextStream.WriteLine objTextStream.WriteLineString(80,"-") objTextStream.WriteLine objTextStream.Close ''Copylog. IfNotobjFSO.FolderExists(g_strRemoteFolder)Then objFSO.CreateFolder(g_strRemoteFolder) IfErr<>0Then Err.Clear ExitSub EndIf EndIf objFSO.CopyFileg_strLogFile,g_strRemoteFolder&"\" EndSub 要 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于可以从一台远程服务器运行 SP2 安装程序Install.vbs的所有评论