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-9F E9-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-B6 E4-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!"