From: Tony Logan on
My script sometimes quits on this line:
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strCompName & "\root\default:StdRegProv")

The script is for installing the Microsoft SCCM client to a group of remote
PCs. The script checks if the remote PC can be pinged, checks the local PC
for the necessary installation files, and copies whichever files are needed
to the remote PC. Remote PCs can either already have the SCCM client, the SMS
client (the previous version of SCCM), or neither client. If either the 2nd
or 3rd case are true, the SCCM client gets installed on the remote PC. The
script reports the results to a log file and runs against multiple PCs by
reading a txt file.

It works fine most of the time, but every so often it bombs at the line I
noted above. As an alternative I tried this:
Set objReg = GetObject("winmgmts:\\" & strCompName &
"\root\default:StdRegProv")

But that produced the same result: the script gets to that line and quits
running instead of continuing on to the rest of the script or going to the
next PC.

I added "On Error Resume Next" to the file to allow the script to continue
if it finds a PC it can't ping. But even when I comment that out, the code
errors on the lines above and then exits. The error message says "Permission
denied: GetObject. The remote server has been paused or is in the process of
being restarted."

All the PCs are Windows XP, Service Pack 2, Office 2003.
From: Richard Mueller [MVP] on

"Tony Logan" <TonyLogan(a)discussions.microsoft.com> wrote in message
news:1DEEB21F-7A24-4299-B297-E8E5E34C0BEF(a)microsoft.com...
> My script sometimes quits on this line:
> Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
> strCompName & "\root\default:StdRegProv")
>
> The script is for installing the Microsoft SCCM client to a group of
> remote
> PCs. The script checks if the remote PC can be pinged, checks the local PC
> for the necessary installation files, and copies whichever files are
> needed
> to the remote PC. Remote PCs can either already have the SCCM client, the
> SMS
> client (the previous version of SCCM), or neither client. If either the
> 2nd
> or 3rd case are true, the SCCM client gets installed on the remote PC. The
> script reports the results to a log file and runs against multiple PCs by
> reading a txt file.
>
> It works fine most of the time, but every so often it bombs at the line I
> noted above. As an alternative I tried this:
> Set objReg = GetObject("winmgmts:\\" & strCompName &
> "\root\default:StdRegProv")
>
> But that produced the same result: the script gets to that line and quits
> running instead of continuing on to the rest of the script or going to the
> next PC.
>
> I added "On Error Resume Next" to the file to allow the script to continue
> if it finds a PC it can't ping. But even when I comment that out, the code
> errors on the lines above and then exits. The error message says
> "Permission
> denied: GetObject. The remote server has been paused or is in the process
> of
> being restarted."
>
> All the PCs are Windows XP, Service Pack 2, Office 2003.

On some clients it might help to use:

Set objReg = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
& strCompName & "\root\cimv2")

If that doesn't work, then possibly a firewall is blocking. The following
command at a command prompt on the problem PC should unblock:

netsh firewall set service remoteadmin enable

Finally, WMI can become corrupt. I have used the following links to help
troubleshoot:

http://www.microsoft.com/technet/scriptcenter/topics/help/wmi.mspx

http://support.microsoft.com/kb/875605

http://www.microsoft.com/technet/scriptcenter/resources/wmifaq.mspx

You can rebuild the WMI repository, if you have XP SP2, with the command:

rundll32 wbemupgd, UpgradeRepository

The following commands reinstall WMI in the registry:

winmgmt /clearadap
winmgmt /kill
winmgmt /unregserver
winmgmt /regserver
winmgmt /resyncperf

http://msdn.microsoft.com/en-us/library/aa389286(VS.85).aspx

I hope this helps.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


From: Tony Logan on
Oops. Bet it would help if I posted the entire script:

Dim fName, strCompName
Dim objFSO, objReg
Dim bSCCM_setup, bSMS_ext, bSCCM, bSmsextFileExists, bCcsetupFileExists
Dim StdOut
Dim strKeyPath, strValueName, strValue

On Error Resume Next ' added this to get past error when a PC can't be pinged

' set constant to path of exe's
Const SCCM_EXE_LOCAL = "C:\Windows\system32\ccmsetup\ccmsetup.exe"
Const SMSEXT_EXE_LOCAL = "C:\Windows\system32\ccmsetup\smsext.exe"
' constants for the Scheduled Job we'll trigger to do the install on the
remote PC
Const INTERVAL = "n"
Const MINUTES = 1
' constant for use with querying registry on remote PC
Const HKEY_LOCAL_MACHINE = &H80000002
' allows us to read from txt file list of PCs
Const ForReading = 1
'set constant for writing to a log file
Const ForWriting = 8

' name & location of log file

' ASSUMES LOG FILE WILL BE NAMED AND LOCATED ACCORDING TO
' NEXT LINE OF CODE. CHANGE THE FILENAME AND/OR PATH AS NEEDED.
strFileName = "C:\SCCM_Results.log"

' create object representing log file; open it for writing
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO1. OpenTextFile(strFileName, ForWriting, True)

' create object representing the text file
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
' now open that text file
' ASSUMES TEXT FILE OF PC IDs WILL BE NAMED AND LOCATED ACCORDING TO
' NEXT LINE OF CODE. CHANGE THE FILENAME AND/OR PATH AS NEEDED.
Set objFile = objFSO2.OpenTextFile("C:\RemoteInstallScripts\PC_list.txt")

' CALL TO ROUTINE THAT READS EACH PC NAME
ReadPCname ' read name of each PC from PC_list.txt

' SUB-ROUTINES

Sub ReadPCname()
' read through text file until the end
Do Until objFile.AtEndOfStream
' read each line of the text file, one line at a time
strCompName = objFile.ReadLine
ClientCheck ' check if remote PC can be pinged, then
' check local PC for necessary exe's;
' check if local PC has SCCM client, SMS client, or no client,
' and install accordingly
Loop
End Sub

Sub ClientCheck()
' confirm that remote PC can be pinged; use PingPoller function on PS1AE80
Set objPing = GetObject("winmgmts://PS1AE80/root/default:PingPoller")
objPing.Trace strCompName, "30", "1000", "1", TraceResult, Addresses
WScript.Echo TraceResult
If TraceResult <> 0 Then
objLog.WriteLine strCompName & vbTab & "Did not respond to ping."
Else ' if TraceResult = 0, PC can be pinged
' Check if remote PC already has SCCM installed
strKeyPath =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{CE6A85D8-D6B9-479A-9FE9-A06E56881E61}"
strValueName = "DisplayName"
' code chokes here and exits, but only for some PCs
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strCompName & "\root\default:StdRegProv")
' Tried next line as alternative to above line, but same result
'Set objReg = GetObject("winmgmts:\\" & strCompName &
"\root\default:StdRegProv")
objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If strValue = "Configuration Manager Client" Then
' remote PC has SCCM client
bSCCM = 1 ' SCCM installed
objLog.WriteLine strCompName & vbTab & "has SCCM client installed."
Exit Sub
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(SCCM_EXE_LOCAL) Then
' now check if the EXE version indicates SCCM rather than the SMS client
(4.0.6221.1000 is SCCM)
strSCCM_Version = objFSO.GetFileVersion(SCCM_EXE_LOCAL)
If strSCCM_Version <> "4.0.6221.1000" Then
bSCCM_setup = 0 ' 0 means SCCM exe does NOT reside on local PC
Else
bSCCM_setup = 1 ' 1 means SCCM exe resides on local PC
End If
Else
bSCCM_setup = 0 ' 0 means SCCM exe does NOT reside on local PC
End If
If objFSO.FileExists(SMSEXT_EXE_LOCAL) Then
bSMS_ext = 1 ' 1 means smsext.exe resides on local PC
Else
bSMS_ext = 0 ' 0 means smsext.exe does NOT reside on local PC
End If
If bSCCM_setup = 0 And bSMS_ext = 0 Then
MsgBox "Required files (ccmsetup.exe v4.0.6221.1000 and smsext.exe)
missing from local PC." & vbCrLf _
& "Please copy the required files before continuing.", 1, "Files Missing"
Exit Sub
'WScript.Quit
ElseIf bSCCM_setup = 0 And bSMS_ext <> 0 Then
MsgBox "ccmsetup.exe (v4.0.6221.1000) missing from local PC." & vbCrLf _
& "Please copy the file locally before continuing.", 1, "File Missing"
Exit Sub
'WScript.Quit
ElseIf bSCCM_setup <> 0 And bSMS_ext = 0 Then
MsgBox "smsext.exe missing from local PC." & vbCrLf _
& "Please copy the file locally before continuing.", 1, "File Missing"
Exit Sub
End If

' THIS IS FOR SMSEXT.EXE
' check if remote PC has SCCM client, SMS client, or neither.
' copy the appropriate file to the remote PC and install it.
bSCCM = 0 'set boolean to indicate SCCM is not installed
strKeyPath =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{83AD5E71-80C0-4818-B6E4-CA2607B6A141}"
strValueName = "DisplayName"
objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If strValue = "SMS Advanced Client" Then ' remote PC has SMS client
' copy smsext.exe to remote PC (removes SMS, installs SCCM)
objFSO.CopyFile SMSEXT_EXE_LOCAL, "\\" & strCompName & "\C$\Windows\Temp\"
' install smsext.exe on remote PC, which uninstalls SMS and then installs
the SCCM client
strCommand = "\\" & strCompName & "\C$\Windows\Temp\ccmsetup.exe"
Set objWMIService = GetObject("winmgmts:\\" & strCompName & "\root\cimv2")
Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value,
False, 0, 0, True, intJobID)
If errReturn = 0 Then
objLog.WriteLine strCompName & vbTab & "smsext.exe starting in 1 minute."
Else
objLog.WriteLine strCompName & vbTab & "ERROR. smsext.exe could not be
started."
End If
bSCCM = 1 ' SCCM installed
End If

' THIS IS FOR CCMSETUP.EXE
' If neither of the above cases meet the conditions, then remote PC has
neither SMS nor SCCM,
' so install SCCM client.
If bSCCM = 0 Then
objFSO.CopyFile SCCM_EXE_LOCAL, "\\" & strCompName & "\C$\Windows\Temp\"
' run ccmsetup.exe on remote PC
' install the SCCM client on the remote PC
strCommand = "\\" & strCompName & "\C$\Windows\Temp\ccmsetup.exe
SMSSITECODE=AUTO"
Set objWMIService = GetObject("winmgmts:\\" & strCompName & "\root\cimv2")
Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value,
False, 0, 0, True, intJobID)
If errReturn = 0 Then
objLog.WriteLine strCompName & vbTab & "ccmsetup.exe installation
starting in 1 minute."
Else
objLog.WriteLine strCompName & vbTab & "ERROR. ccmsetup.exe could not be
started."
End If
End If
End If
End Sub

MsgBox "Done!",,"DONE!"

 | 
Pages: 1
Prev: Sorting files by month
Next: Script