You can run the SP2 Setup program from a remote server install.vbs_vbs

Source: Internet
Author: User
Tags pack
Install.vbs
Publisher Microsoft Corporation Scripting Guys

This script is started by scenario1.vbs on a single network host. Install.vbs can be run locally on a host that has SP2 installed, and it performs the following tasks:

? Run the SP2 Setup program from a remote server.

? Set the Autoadmin and RunOnce two registry keys on the host.

? Record the results to a text file computername-sp2-instlog.txt and copy the file back to the management workstation.

? Force a reboot, and then Runonce.vbs will start automatically.


In a basic scenario, the SP 2 installer file is located on a remote server that is accessible to all network hosts in the list. In some variation of the scenario, if you copy SP 2 Setup to the local host and run from here, you should rename the script (for example, rename to Install-remote.vbs), and then rename Install-local.vbs to Install.vbs. You must also make minor changes to the Scenario1.vbs and new Install.vbs mentioned in these scripts.

For further instructions on scenario 1 and the role of individual scripts, see the introduction to these scripts, which are:

Http://www.microsoft.com/technet/scriptcenter/solutions/appcompat.msxp

Install.vbs corresponds to Install.cmd, but some new features are added; Install.cmd is application compatibility testing and mitigation for Windows XP One of the accompanying scripts described in "Appendix" for Service Pack 2 (Windows XP Service Pack 2 Application Compatibility Test and Mitigation Guide). You can download the Windows Installer (. msi) file that is used to install the guide and its associated scripts from the following URLs:

http://www.microsoft.com/downloads/details.aspx?FamilyId=9300BECF-2DEE-4772-ADD9-AD0EAF89C4A7&displaylang=en

To use this script, copy the code, paste the code into Notepad, and then save the script as a install.vbs. This script is designed to run automatically as part of a process initiated by Scenario1.vbs.

Scripting code

Copy Code code as follows:

'******************************************************************************
' Install.vbs
' Author:peter Costantini, the Microsoft Scripting Guys
' Date:9/1/04
' must is deployed to a client and launched remotely by Scenario1.vbs.
' Assumes ' runonce.vbs is in same directory as script.
' assumes that Windows XP Service Pack 2 The Setup program was 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 ' 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 is 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 ten seconds before checking.
' To reduce network traffic and 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 = &AMP;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 are 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

To get online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report sample scripts or errors in the Scripting Guide, contact Microsoft TechNet.

Legal Disclaimer

This sample script is not supported by any Microsoft standard support plan or service. This provides only the sample script as is, without warranty of any kind. Microsoft further expressly rejects all implied warranties, including, but not limited to, any implied warranties of merchantability or fitness for a particular purpose. All the risks associated with using or executing sample scripts and documents should be borne by you. In any case, Microsoft, its author, and any other person involved in the creation, production, or delivery of a script is not liable for any damages (including, but not limited to, loss of commercial profits, business interruption, loss of business information, or other financial losses) caused by the use of or inability to use the sample script or document , even if Microsoft has been told that there is a possibility of such damage.

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.