You can run the SP2 installer Install. vbs from a remote server.

Source: Internet
Author: User

Install. vbs
Publisher: Microsoft Corporation scripting expert

This script is started by scenario1.vbs on a network host. Install. vbs can run locally on the host with SP2 installed. It executes the following tasks:

? Run the SP2 installer from a remote server.

? Set the AutoAdmin and RunOnce registry keys on the host.

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

? Force restart, and then runonce. vbs will automatically start.

In the basic solution, the SP 2 installer file is located on a remote server that can be accessed by all network hosts in the list. In a change scheme of this scheme, if you copy the SP 2 installer to a local host and run it from here, you should rename this script (for example, rename it to a install-remote.vbs ), rename the install-local.vbs to install. vbs. You must also make some minor changes to the scenario1.vbs and the new install. vbs mentioned in these scripts.

For more information about solution 1 and the functions of each script, see the introduction to these scripts:

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

Install. vbs corresponds to install. cmd, but some new features are added; install. cmd is one of the additional scripts described in "Appendix" in Application Compatibility Testing and Mitigation Guide for Windows XP Service Pack 2 (Windows XP Service Pack 2 Application Compatibility test and Mitigation Guide. You can download the Windows Installer (. msi) file used to install the Guide and its associated scripts from the following URL:

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 save the script as install. vbs. This script is designed to run automatically as part of the process started by scenario1.vbs.

Script code

Copy codeThe Code is as follows: '*************************************** ***************************************
'Install. vbs
'Author: Peter costanini, 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 cocould 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 shoshould 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 ob1_miservice = GetObject ("winmgmts: {impersonationLevel = impersonate }! \\."_
& "\ Root \ cimv2 ")
Set colSystems = ob1_miservice. 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 coshould 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"
Strdefauserusername = "Administrator"
StrDefaultPassword = "P @ ssw0rd"
Strdefadodomainname = "Contoso"
IntAutoAdminLogon = 1
StrRunOnceEntry = "MyScript"
StrRunoncePath = g_strLocalFolder & "\ runonce. vbs"

Set objReg = GetObject ("winmgmts: {impersonationLevel = impersonate }! \\"&_
G_strComputer & "\ root \ default: StdRegProv ")

'Set strdefauserusername to user with Administrator credentials.
IntRet1 = objReg. SetStringValue (HKEY_LOCAL_MACHINE, strKeyPath1 ,_
"DefaultUserName", strdefauserusername)
If intRet1 <> 0 Then
ObjTextStream. WriteLine "Error: DefaultUserName not configured ."
End If

'Set strdefapassword password to password of default username.
IntRet2 = objReg. SetStringValue (HKEY_LOCAL_MACHINE, strKeyPath1 ,_
"DefaultPassword", strdefapassword password)
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 ,_
'"Defadodomainname", strdefadodomainname)
'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 ob1_miservice = GetObject ("winmgmts: {impersonationLevel = impersonate ,"&_
"(Shutdown )}! \ "& G_strComputer &" \ root \ cimv2 ")
Set colOSes = ob1_miservice. 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 "&_
"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 obtain Online peer support, join the microsoft. public. windows. server. scripting community on the msnews.microsoft.com news server. To provide feedback or report errors in the sample script or script guide, contact Microsoft TechNet.

Disclaimer

This sample script is not supported by any Microsoft standard support plan or service. The sample script is provided as is, without any type of guarantee. Microsoft further expressly disclaims all implied warranties, including but not limited to any implied warranties of merchantability or fitness for a specific purpose. All risks arising from the use or execution of sample scripts and documents shall be borne by you. In any situation, any damages caused by the use or inability to use sample scripts or documents, including but not limited to damages caused by loss of business profits, business interruptions, loss of business information, or other financial losses ), microsoft, its authors, and any other person involved in Script Creation, production, or delivery are not liable even if Microsoft has been notified of the possibility of such damages.

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.