可以从一台远程服务器运行 SP2 安装程序Install.vbs
程序员文章站
2022-06-23 22:08:37
install.vbs 发布者 microsoft corporation 脚本专家 此脚本由 scenario1.vbs ...
install.vbs
发布者 microsoft corporation 脚本专家
此脚本由 scenario1.vbs 在一台网络主机上启动。install.vbs 可以在安装了 sp2 的主机上以本地方式运行,它执行以下任务:
? 从一台远程服务器运行 sp2 安装程序。
? 在主机上设置 autoadmin 和 runonce 两个注册表项。
? 将结果记录到文本文件 computername-sp2-instlog.txt 并将该文件复制回管理工作站。
? 强制重新启动,随后 runonce.vbs 将自动启动。
在基本方案中,sp 2 安装程序文件位于列表中的所有网络主机均可访问的一台远程服务器上。在该方案的某种变化方案中,如果将 sp 2 安装程序复制到本地主机并从这里运行,则应重命名此脚本(例如重命名为 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 是 application compatibility testing and mitigation guide for windows xp service pack 2(windows xp service pack 2 应用程序兼容性测试和缓解指南)“附录”中介绍的附带脚本之一。您可以从以下网址下载用来安装该指南及其关联脚本的 windows installer (.msi) 文件:
http://www.microsoft.com/downloads/details.aspx?familyid=9300becf-2dee-4772-add9-ad0eaf89c4a7&displaylang=en
要使用此脚本,请复制代码,将代码粘贴到记事本中,然后将脚本另存为 install.vbs。此脚本被设计成了作为 scenario1.vbs 启动的进程的一部分自动运行。
脚本代码
'******************************************************************************
'install.vbs
'author: peter costantini, the microsoft scripting guys
'date: 9/1/04
'must be deployed to a client and launched remotely by scenario1.vbs.
'assumes that runonce.vbs is in same directory as script.
'assumes that windows xp service pack 2 setup program is on a remote server
'and runonce.vbs are in same directory as script.
'1. runs service pack 2 setup program from remote server to install
' windows xp service pack 2. this could take one or two hours.
'2. configures the autoadmin and runonce registry settings necessary
' to run runonce.vbs.
'3. logs results to text file, <computername>-sp2-instlog.txt and copies
' the file back to admin workstation.
'4. forces a reboot of the local machine so that the autoadmin and runonce
' registry settings take effect.
'******************************************************************************
on error resume next
'initialize global constants and variables.
const for_appending = 8
g_strlocalfolder = "c:\temp-ac"
'change name of computer to actual administrative workstation or local
'path to which log should be copied.
g_strremotefolder = "\\<adminwkstn>\c$\temp-ac"
'get computer name.
g_strcomputer = getcomputername
g_strlogfile = g_strcomputer & "-sp2-instlog.txt"
'create log file.
set objfso = createobject("scripting.filesystemobject")
set objtextstream = objfso.opentextfile(g_strlogfile, for_appending, true)
objtextstream.writeline "windows xp service pack 2 " & _
"installation and configuration log: phase 1"
objtextstream.writeline now
objtextstream.writeline g_strcomputer
objtextstream.writeline string(len(g_strcomputer), "-")
'handle logic of calling functions and sub-routines to install service pack 2
'and configure autoadministration.
blninstallsp = installsp
if blninstallsp = false then
copylog
wscript.quit
end if
blnautoadmin = configautoadmin
if blnautoadmin = false then
copylog
wscript.quit
end if
reboot
'******************************************************************************
function getcomputername
set objwmiservice = getobject("winmgmts:{impersonationlevel=impersonate}!\\." _
&"\root\cimv2")
set colsystems = objwmiservice.execquery("select * from win32_computersystem")
for each objsytem in colsystems
getcomputername = objsytem.name
next
end function
'******************************************************************************
function installsp
'edit this line to include the server and share name where the windows xp
'service pack 2 setup program is located.
strinstallpath = "\\servername\xpsp2\windowsxp-kb835935-sp2-enu.exe " & _
"/quiet /norestart /o"
set wshshell = createobject("wscript.shell")
set objexec = wshshell.exec(strinstallpath)
'this could take one or two hours.
objtextstream.writeline "installation started ..."
if err = 0 then
'loop until exec is finished - status = 1.
do while objexec.status = 0
'pause for 10 seconds before checking.
'to reduce network traffic, make interval longer.
wscript.sleep 10000
loop
objtextstream.writeline "service pack 2 installation completed."
installsp = true
else
objtextstream.writeline "unable to install service pack 2." & vbcrlf & _
"error connecting to service pack 2 on server." & vbcrlf & _
"error number: " & err.number & vbcrlf & _
"error source: " & err.source & vbcrlf & _
"error description: " & err.description
installsp = false
end if
err.clear
end function
'******************************************************************************
function configautoadmin
const hkey_local_machine = &h80000002
strkeypath1 = "software\microsoft\windows nt\currentversion\winlogon"
strkeypath2 = "software\microsoft\windows\currentversion\runonce"
strdefaultusername = "administrator"
strdefaultpassword = "p@ssw0rd"
strdefaultdomainname = "contoso"
intautoadminlogon = 1
strrunonceentry = "myscript"
strrunoncepath = g_strlocalfolder & "\runonce.vbs"
set objreg = getobject("winmgmts:{impersonationlevel=impersonate}!\\" & _
g_strcomputer & "\root\default:stdregprov")
'set strdefaultusername to user with administrator credentials.
intret1 = objreg.setstringvalue(hkey_local_machine, strkeypath1, _
"defaultusername", strdefaultusername)
if intret1 <> 0 then
objtextstream.writeline "error: defaultusername not configured."
end if
'set strdefaultpassword to password of default username.
intret2 = objreg.setstringvalue(hkey_local_machine, strkeypath1, _
"defaultpassword", strdefaultpassword)
if intret2 <> 0 then
objtextstream.writeline "error: defaultpassword not configured."
end if
'uncomment next 5 lines and edit last parameter if default domain
'for the credentials is different from that already set.
'intret3 = objreg.setstringvalue(hkey_local_machine, strkeypath1, _
' "defaultdomainname", strdefaultdomainname)
'if intret3 <> 0 then
' objtextstream.writeline "error: defaultdomainname not configured."
'end if
'turn on autoadminlogon
intret4 = objreg.setstringvalue(hkey_local_machine, strkeypath1, _
"autoadminlogon", "1")
if intret4 <> 0 then
objtextstream.writeline "error: autoadminlogon not configured."
end if
'add myscript entry to runonce subkey.
intret5 = objreg.setstringvalue(hkey_local_machine, strkeypath2, _
strrunonceentry, strrunoncepath)
if intret5 <> 0 then
objtextstream.writeline "error: myscript runonce entry not configured."
end if
'check that all registry write operations succeeded.
if (intret1 + intret2 + intret3 + intret4 + intret5) = 0 then
objtextstream.writeline "autoadminlogon and runonce configured."
configautoadmin = true
else
objtextstream.writeline "error: autoadminlogon and runonce not fully " & _
"configured."
configautoadmin = false
end if
end function
'******************************************************************************
sub reboot
const forced_reboot = 6
set objwmiservice = getobject("winmgmts:{impersonationlevel=impersonate," & _
"(shutdown)}!\\" & g_strcomputer & "\root\cimv2")
set coloses = objwmiservice.execquery("select * from win32_operatingsystem")
objtextstream.writeline "attempting to reboot ..."
copylog
for each objos in coloses 'only one objos in collection
intreturn = objos.win32shutdown(forced_reboot)
if intreturn <> 0 then
set objtextstream = objfso.opentextfile(g_strlogfile, for_appending, true)
objtextstream.writeline now
objtextstream.writeline "error: unable to reboot. " & vbcrlf & _
"return code: " & intreturn
copylog
end if
next
end sub
'******************************************************************************
sub copylog
'close text file.
objtextstream.writeline "closing log and attempting to copy file to " & _
"administrative workstation."
objtextstream.writeline
objtextstream.writeline string(80, "-")
objtextstream.writeline
objtextstream.close
'copy log.
if not objfso.folderexists(g_strremotefolder) then
objfso.createfolder(g_strremotefolder)
if err <> 0 then
err.clear
exit sub
end if
end if
objfso.copyfile g_strlogfile, g_strremotefolder & "\"
end sub
要获得在线同行支持,请加入 msnews.microsoft.com 新闻服务器上的 microsoft.public.windows.server.scripting 社区。要提供反馈或报告示例脚本或“脚本指南”中的错误,请联系 microsoft technet。
免责声明
此示例脚本不受任何 microsoft 标准支持计划或服务的支持。这里仅按原样提供示例脚本,而不作任何类型的担保。microsoft 进一步明确拒绝所有的暗示担保,包括但不限于对适销性或对特定目的适用性的任何暗示担保。使用或执行示例脚本和文档所引起的全部风险应由您自己承担。在任何情况下,对于使用或不能使用示例脚本或文档所引起的任何损害(包括但不限于商业利润损失、业务中断、商业信息丢失或其他资金损失所造成的损害),microsoft、其作者以及参与脚本创建、生产或传递的任何其他人员都概不负责,即使 microsoft 已被告知存在这些损害的可能性。
发布者 microsoft corporation 脚本专家
此脚本由 scenario1.vbs 在一台网络主机上启动。install.vbs 可以在安装了 sp2 的主机上以本地方式运行,它执行以下任务:
? 从一台远程服务器运行 sp2 安装程序。
? 在主机上设置 autoadmin 和 runonce 两个注册表项。
? 将结果记录到文本文件 computername-sp2-instlog.txt 并将该文件复制回管理工作站。
? 强制重新启动,随后 runonce.vbs 将自动启动。
在基本方案中,sp 2 安装程序文件位于列表中的所有网络主机均可访问的一台远程服务器上。在该方案的某种变化方案中,如果将 sp 2 安装程序复制到本地主机并从这里运行,则应重命名此脚本(例如重命名为 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 是 application compatibility testing and mitigation guide for windows xp service pack 2(windows xp service pack 2 应用程序兼容性测试和缓解指南)“附录”中介绍的附带脚本之一。您可以从以下网址下载用来安装该指南及其关联脚本的 windows installer (.msi) 文件:
http://www.microsoft.com/downloads/details.aspx?familyid=9300becf-2dee-4772-add9-ad0eaf89c4a7&displaylang=en
要使用此脚本,请复制代码,将代码粘贴到记事本中,然后将脚本另存为 install.vbs。此脚本被设计成了作为 scenario1.vbs 启动的进程的一部分自动运行。
脚本代码
复制代码 代码如下:
'******************************************************************************
'install.vbs
'author: peter costantini, the microsoft scripting guys
'date: 9/1/04
'must be deployed to a client and launched remotely by scenario1.vbs.
'assumes that runonce.vbs is in same directory as script.
'assumes that windows xp service pack 2 setup program is on a remote server
'and runonce.vbs are in same directory as script.
'1. runs service pack 2 setup program from remote server to install
' windows xp service pack 2. this could take one or two hours.
'2. configures the autoadmin and runonce registry settings necessary
' to run runonce.vbs.
'3. logs results to text file, <computername>-sp2-instlog.txt and copies
' the file back to admin workstation.
'4. forces a reboot of the local machine so that the autoadmin and runonce
' registry settings take effect.
'******************************************************************************
on error resume next
'initialize global constants and variables.
const for_appending = 8
g_strlocalfolder = "c:\temp-ac"
'change name of computer to actual administrative workstation or local
'path to which log should be copied.
g_strremotefolder = "\\<adminwkstn>\c$\temp-ac"
'get computer name.
g_strcomputer = getcomputername
g_strlogfile = g_strcomputer & "-sp2-instlog.txt"
'create log file.
set objfso = createobject("scripting.filesystemobject")
set objtextstream = objfso.opentextfile(g_strlogfile, for_appending, true)
objtextstream.writeline "windows xp service pack 2 " & _
"installation and configuration log: phase 1"
objtextstream.writeline now
objtextstream.writeline g_strcomputer
objtextstream.writeline string(len(g_strcomputer), "-")
'handle logic of calling functions and sub-routines to install service pack 2
'and configure autoadministration.
blninstallsp = installsp
if blninstallsp = false then
copylog
wscript.quit
end if
blnautoadmin = configautoadmin
if blnautoadmin = false then
copylog
wscript.quit
end if
reboot
'******************************************************************************
function getcomputername
set objwmiservice = getobject("winmgmts:{impersonationlevel=impersonate}!\\." _
&"\root\cimv2")
set colsystems = objwmiservice.execquery("select * from win32_computersystem")
for each objsytem in colsystems
getcomputername = objsytem.name
next
end function
'******************************************************************************
function installsp
'edit this line to include the server and share name where the windows xp
'service pack 2 setup program is located.
strinstallpath = "\\servername\xpsp2\windowsxp-kb835935-sp2-enu.exe " & _
"/quiet /norestart /o"
set wshshell = createobject("wscript.shell")
set objexec = wshshell.exec(strinstallpath)
'this could take one or two hours.
objtextstream.writeline "installation started ..."
if err = 0 then
'loop until exec is finished - status = 1.
do while objexec.status = 0
'pause for 10 seconds before checking.
'to reduce network traffic, make interval longer.
wscript.sleep 10000
loop
objtextstream.writeline "service pack 2 installation completed."
installsp = true
else
objtextstream.writeline "unable to install service pack 2." & vbcrlf & _
"error connecting to service pack 2 on server." & vbcrlf & _
"error number: " & err.number & vbcrlf & _
"error source: " & err.source & vbcrlf & _
"error description: " & err.description
installsp = false
end if
err.clear
end function
'******************************************************************************
function configautoadmin
const hkey_local_machine = &h80000002
strkeypath1 = "software\microsoft\windows nt\currentversion\winlogon"
strkeypath2 = "software\microsoft\windows\currentversion\runonce"
strdefaultusername = "administrator"
strdefaultpassword = "p@ssw0rd"
strdefaultdomainname = "contoso"
intautoadminlogon = 1
strrunonceentry = "myscript"
strrunoncepath = g_strlocalfolder & "\runonce.vbs"
set objreg = getobject("winmgmts:{impersonationlevel=impersonate}!\\" & _
g_strcomputer & "\root\default:stdregprov")
'set strdefaultusername to user with administrator credentials.
intret1 = objreg.setstringvalue(hkey_local_machine, strkeypath1, _
"defaultusername", strdefaultusername)
if intret1 <> 0 then
objtextstream.writeline "error: defaultusername not configured."
end if
'set strdefaultpassword to password of default username.
intret2 = objreg.setstringvalue(hkey_local_machine, strkeypath1, _
"defaultpassword", strdefaultpassword)
if intret2 <> 0 then
objtextstream.writeline "error: defaultpassword not configured."
end if
'uncomment next 5 lines and edit last parameter if default domain
'for the credentials is different from that already set.
'intret3 = objreg.setstringvalue(hkey_local_machine, strkeypath1, _
' "defaultdomainname", strdefaultdomainname)
'if intret3 <> 0 then
' objtextstream.writeline "error: defaultdomainname not configured."
'end if
'turn on autoadminlogon
intret4 = objreg.setstringvalue(hkey_local_machine, strkeypath1, _
"autoadminlogon", "1")
if intret4 <> 0 then
objtextstream.writeline "error: autoadminlogon not configured."
end if
'add myscript entry to runonce subkey.
intret5 = objreg.setstringvalue(hkey_local_machine, strkeypath2, _
strrunonceentry, strrunoncepath)
if intret5 <> 0 then
objtextstream.writeline "error: myscript runonce entry not configured."
end if
'check that all registry write operations succeeded.
if (intret1 + intret2 + intret3 + intret4 + intret5) = 0 then
objtextstream.writeline "autoadminlogon and runonce configured."
configautoadmin = true
else
objtextstream.writeline "error: autoadminlogon and runonce not fully " & _
"configured."
configautoadmin = false
end if
end function
'******************************************************************************
sub reboot
const forced_reboot = 6
set objwmiservice = getobject("winmgmts:{impersonationlevel=impersonate," & _
"(shutdown)}!\\" & g_strcomputer & "\root\cimv2")
set coloses = objwmiservice.execquery("select * from win32_operatingsystem")
objtextstream.writeline "attempting to reboot ..."
copylog
for each objos in coloses 'only one objos in collection
intreturn = objos.win32shutdown(forced_reboot)
if intreturn <> 0 then
set objtextstream = objfso.opentextfile(g_strlogfile, for_appending, true)
objtextstream.writeline now
objtextstream.writeline "error: unable to reboot. " & vbcrlf & _
"return code: " & intreturn
copylog
end if
next
end sub
'******************************************************************************
sub copylog
'close text file.
objtextstream.writeline "closing log and attempting to copy file to " & _
"administrative workstation."
objtextstream.writeline
objtextstream.writeline string(80, "-")
objtextstream.writeline
objtextstream.close
'copy log.
if not objfso.folderexists(g_strremotefolder) then
objfso.createfolder(g_strremotefolder)
if err <> 0 then
err.clear
exit sub
end if
end if
objfso.copyfile g_strlogfile, g_strremotefolder & "\"
end sub
要获得在线同行支持,请加入 msnews.microsoft.com 新闻服务器上的 microsoft.public.windows.server.scripting 社区。要提供反馈或报告示例脚本或“脚本指南”中的错误,请联系 microsoft technet。
免责声明
此示例脚本不受任何 microsoft 标准支持计划或服务的支持。这里仅按原样提供示例脚本,而不作任何类型的担保。microsoft 进一步明确拒绝所有的暗示担保,包括但不限于对适销性或对特定目的适用性的任何暗示担保。使用或执行示例脚本和文档所引起的全部风险应由您自己承担。在任何情况下,对于使用或不能使用示例脚本或文档所引起的任何损害(包括但不限于商业利润损失、业务中断、商业信息丢失或其他资金损失所造成的损害),microsoft、其作者以及参与脚本创建、生产或传递的任何其他人员都概不负责,即使 microsoft 已被告知存在这些损害的可能性。