Text
Text
'To Do
' * install client loop which waits for ccmsetup.exe should log once per minute
' * clientConfig should not honor ForceReinstall or ForceUninstall if the option
exists and does not equal true.
' * forceUninstall should only uninstall right before the client is installed
(because of a client health failure, or forceReinstall).
'known issues: (f)InWinPE will return true if the system is -not- in WinPE but an
X: exists.
Option Explicit
'Cert hotfix ID
Const CERTHOTFIXID = "CertHotFixID"
Const PROCESSOR_ARCHITECTURE_X86 = 0
Const PROCESSOR_ARCHITECTURE_IA64 = 6
Const PROCESSOR_ARCHITECTURE_X64 = 9
'Default Options
Const OPTION_LOCALADMIN =
"LocalAdmin"
Const OPTION_LOCALADMIN_GROUP =
"LocalAdminGroup"
Const OPTION_AGENTVERSION =
"AgentVersion"
Const OPTION_DEFAULT_RUNINTERVAL = "MinimumInterval"
Const OPTION_CACHESIZE =
"CacheSize"
Const OPTION_INSTALLPATH =
"ClientLocation"
Const OPTION_SITECODE =
"SiteCode"
Const OPTION_OTHERINSTALLPROPS =
"OtherInstallationProperties"
Const OPTION_MAXLOGFILE_SIZE = "MaxLogFile"
Const OPTION_ERROR_LOCATION =
"ErrorLocation"
Const OPTION_AUTOHOTFIX =
"AutoHotfix"
Const OPTION_STARTUPDELAY =
"Delay"
Const OPTION_WMISCRIPT =
"WMIScript"
Const OPTION_WMISCRIPT_ASYNCH =
"WMIScriptAsynch"
Const OPTION_WMISCRIPTOPTIONS =
"WMIScriptOptions"
Const OPTION_FORCE_REINSTALL =
"ForceReinstall"
Const OPTION_FORCE_UNINSTALL =
"ForceUninstall"
Const OPTION_XP_2003_X64_CERTHOTFIX = "LegacyOSHotfix_XP2003_x64"
Const OPTION_XP_X32_CERTHOTFIX = "LegacyOSHotfix_XP_x32"
Const OPTION_2003_X32_CERTHOTFIX = "LegacyOSHotfix_2003_x32"
Const DEFAULT_REGISTRY_LOCATION = "HKLM\Software\
ConfigMgrStartup"
Const DEFAULT_LOCALADMIN_GROUP = "Administrators"
Const DEFAULT_AGENTVERSION =
"4.00.6487.2000"
Const DEFAULT_RUN_INTERVAL = 12
Const DEFAULT_CACHESIZE =
"5120"
Const DEFAULT_REGISTRY_LASTRUN_VALUE = "Last Run"
Const DEFAULT_REGISTRY_LOGLOCATION_VALUE = "Log Location"
Const DEFAULT_REGISTRY_LASTRESULT_VALUE = "Last Execution Result"
Const DEFAULT_CONFIGFILE_PARAMETER = "config"
Const DEFAULT_MAXLOGFILE_SIZE = "6144"
Const DEFAULT_EVENTLOG_PREFIX = "ConfigMgr
StartUp Script -- "
Const DEFAULT_WMISCRIPT_ASYNCH = "1"
Const DEFAULT_XP_2003_X64_CERTHOTFIX = "WindowsServer2003.WindowsXP-
KB968730-x64-ENU.exe"
'= Functions =
Sub Main
Dim argsNamed
Dim WshShell
Dim xmlConfig
Dim configOptions
Dim parameters
Dim bClientOK
Dim lastResult
Dim clientVerCheck
Dim bContinue
Dim bInstallClient
Dim iClientStatus
Dim i
Dim msg
Dim bAction
Dim OSVer, OSArch
Dim bLegacyHotfixNeeded
Dim clientInstalled
Dim bSkipAction
Dim bResult
Const CLIENT_INSTALLED = 1
Const CLIENT_CLIENT_UPDATE_REQUIRED = 2
Const CLIENT_CACHE_FAILURE = 3
Const CLIENT_ASSIGNMENT_FAIlURE = 4
Const CLIENT_CHECK_FAILED = 6
Const CLIENT_UNKNOWN_ERROR = 8
bInstallClient = False
bContinue = True
bClientOK = False
'Load Config
If OpenConfig (argsNamed, xmlConfig) Then
LoadOptions xmlConfig, configOptions, parameters
Else
bContinue = False
End If
'Check the script and system environments to see if the script can run
and complete.
lastResult = GetLastResult(configOptions)
If Check_OSWMI(configOptions) <> True Then
bContinue = False
ElseIf CheckServices(xmlConfig) <> True Then
bContinue = False
ElseIf Conform_AdminShareOptions <> True Then
bContinue = False
ElseIf Confirm_RegistryOptions(xmlConfig) <> True Then
bContinue = False
ElseIf Conform_LocalAdminOptions(configOptions) <> True Then
bContinue = False
ElseIf LastRunOK(configOptions) <> True Then
bContinue = False
End If
'obey forceUninstall
If configOptions.Exists(OPTION_FORCE_UNINSTALL) Then
If configOptions.Item(OPTION_FORCE_UNINSTALL) = True Then
bAction = UninstallClient(configOptions, parameters)
End If
End If
'obey forceReinstall
'If bContinue = True Then
If configOptions.Exists(OPTION_FORCE_REINSTALL) Then
If configOptions.Item(OPTION_FORCE_REINSTALL) = "True" Then
writeLogMsg "Reinstalling client immediately per
config options.", 1, 1, 0
bAction = InstallClient(configOptions, parameters)
End If
End If
'End If
' End If
WriteLogMsg "Script execution complete.", 1, 1, 0
WriteFinalLogMsg configOptions
End Sub
Function Check_ClientSiteAssignment(configOptions)
Dim smsClient, siteCode
Dim errorCode
Dim bResults
bResults = False
WriteLogMsg MSG_CHECKASSIGNMENT_START, 1, 1, 1
On Error Resume Next
Err.Clear
Set smsClient = CreateObject ("Microsoft.SMS.Client")
errorCode = Err.Number
siteCode = smsClient.GetAssignedSite
On Error GoTo 0
Function Check_ClientCacheSizeOK(configOptions)
Dim uiResManager, cache
Dim errorCode, errorMsg
Dim desiredCacheSize
Dim msg, bResults, bContinue
bResults = False
bContinue = True
WriteLogMsg MSG_CHECKCACHE_START, 1, 1, 1
bResults = False
bContinue = True
WriteLogMsg MSG_CHECKCACHE_START, 1, 1, 1
bResults = Check_ClientCacheSizeOK(configOptions)
Fix_ClientCacheSize = bResults
End Function
Function Check_ClientVersionLevel(configOptions)
Dim wmi, ccmWMI, errorCode, errorMsg
Dim clientProperties, clientProp
Dim sActualClientVersion, expectedVersion
Dim configMgrLogPath
Dim clientCheck
Dim bResults
Dim bContinue
Dim msg
bContinue = True
bResults = False
Function Find_CurrentClientVersion(ccmWmi)
Dim clientProperties
Dim clientProp
Dim sActualClientVersion
Dim msg
Dim retval
WriteLogMsg MSG_CHECKCLIENT_VERSION, 1, 1, 0
Set clientProperties = ccmWmi.ExecQuery("Select * from SMS_Client")
On Error Resume Next
For Each clientProp In clientProperties
'msg = "Iterating current WMI property version number: " +
clientProp.ClientVersion
'WriteLogMsg msg, 1, 1, 0
Function Check_ClientServicesRunning(configOptions)
Dim wmi, errorCode, errorMsg
Dim bResults
WriteLogMsg MSG_CHECKCLIENT_CCMEXEC, 1, 1, 0
Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\
cimv2")
If CheckService(wmi, "CCMExec", "Running", "Auto", True) = False Then
bResults = False
Else
bResults = True
End If
Set wmi = Nothing
Function Check_ClientWmiConnectivity(configOptions)
Dim wmi, ccmWMI, errorCode, errorMsg
Dim bResults
Function Check_IsClientInstalled(configOptions)
Dim wmi
Dim bResults
On Error GoTo 0
Else
WriteLogMsg MSG_LOGMSG_CLIENTSTATUS & MSG_LASTRESULT_SUCCEED, 1, 1, 0
g_WshShell.LogEvent 0, MSG_LOGMSG_CLIENTSTATUS & MSG_LASTRESULT_SUCCEED
g_WshShell.RegWrite registryLocation, MSG_LASTRESULT_SUCCEED, "REG_SZ"
On Error GoTo 0
End If
End Sub
Dim countdown
End Sub
GetLastResult = True
registryLocation = DEFAULT_REGISTRY_LOCATION & "\" &
DEFAULT_REGISTRY_LASTRESULT_VALUE
WriteLogMsg MSG_LASTRESULT_VERIFYING & registryLocation, 1, 1, 0
Verify = true
Set optionsNodes = config.documentElement.selectNodes ( "/Startup/Option" )
WriteLogMsg MSG_LOADOPTIONS_STARTED, 1, 1, 0
End If
Next
If msgtype = 6 Then
outmsg = msg
End If
If eventlog = 1 Then
g_WshShell.LogEvent 0, DEFAULT_EVENTLOG_PREFIX & msg
End If
End Sub
Sub WriteOpeningBlock
Dim registryLocation
Dim logfile, logpath
Dim userEnv
Dim errorCode
Dim logFileSize, maxLogFileSize
'Open logfile
If errorCode = 0 Then
On Error Resume Next
Set logfile = g_fso.OpenTextFile(g_logPathandName, 8, True)
errorCode = Err.Number
On Error GoTo 0
minimumRunInterval = CInt(GetOptionValue(OPTION_DEFAULT_RUNINTERVAL,
DEFAULT_RUN_INTERVAL, options))
If errorCode <> 0 Then
WriteLogMsg MSG_LASTRUN_NOLASTRUN, 1, 1, 0
lastRunInterval = minimumRunInterval + 1
Else
lastRunInterval = DateDiff("h", lastRunTime, Now)
WriteLogMsg MSG_LASTRUN_TIME & lastRunTime, 1, 1, 0
End If
CheckServices = True
Set serviceCheckNodes = config.documentElement.selectNodes (
"/Startup/ServiceCheck" )
serviceStatus = 1
CheckService = True
returnCode = service.ChangeStartMode(newStartMode)
If returnCode = 0 Then
msg = msg & MSG_CHECKSERVICE_STARTMODEOK &
newStartMode
Else
msg = msg & MSG_CHECKSERVICE_STARTMODEFAIL &
returnCode
serviceStatus = 3
CheckService = False
End If
End If
End If
If returnCode = 0 Then
msg = msg & MSG_CHECKSERVICE_STARTEDOK
Else
msg = msg & MSG_CHECKSERVICE_STARTEDFAIL &
returnCode
serviceStatus = 3
CheckService = False
End If
If serviceStatus = 1 Then
msg = msg & MSG_OK
Else
msg = msg & MSG_NOTOK
End If
WriteLogMsg msg, serviceStatus, 1, 0
End Function
Function Conform_AdminShareOptions()
Dim wmi, adminShare, adminShareRegValue, errorMsg, errorCode
Dim msg, status
adminShareRegValue = 1
status = 1
WriteLogMsg MSG_CHECKADMINSHARE_START, 1, 1, 1
If IsObject(adminShare) Then
msg = msg & MSG_FOUND
Else
msg = msg & MSG_NOTFOUND
status = 3
If errorCode = 0 Then
msg = msg & MSG_CHECKADMINSHARE_SETSUCCESS
Else
msg = msg & MSG_CHECKADMINSHARE_SETFAIL & errorMsg
status = 3
End If
End If
End If
If status = 1 Then
msg = msg & MSG_OK
Conform_AdminShareOptions = True
Else
msg = msg & MSG_NOTOK
Conform_AdminShareOptions = False
End If
WriteLogMsg msg, status, 1, 0
Set wmi = Nothing
End Function
Confirm_RegistryOptions = True
Set registryCheckNodes = config.documentElement.selectNodes (
"/Startup/RegistryValueCheck" )
WriteLogMsg MSG_CHECKREGISTRY_START, 1, 1, 1
regStatus = 1
If valueType = "REG_DWORD" Then
expectedValue = CInt(expectedValue)
End If
If errorCode = 0 Then
msg = msg & MSG_CHECKREGISTRY_ENFORCEOK
Confirm_RegistryOptions = True
Else
msg = msg & MSG_CHECKREGISTRY_ENFORCEFAIL
regStatus = 3
Confirm_RegistryOptions = False
End If
End If
status = 1
Conform_LocalAdminOptions = True
If options.Exists(OPTION_LOCALADMIN) Then
WriteLogMsg MSG_CHECKLOCALADMIN_START, 1, 1, 1
adminAccountName = options.Item(OPTION_LOCALADMIN)
localAdminGroupName =
GetOptionValue(OPTION_LOCALADMIN_GROUP,DEFAULT_LOCALADMIN_GROUP, options)
msg = " *" & localAdminGroupName
Set network = WScript.CreateObject("WScript.Network")
If errorCode = 0 Then
msg = msg & MSG_FOUND & "...(" & adminAccountName & ")"
If localAdminGroup.IsMember("WinNT://" & adminAccountName) Then
msg = msg & MSG_CHECKLOCALADMIN_ALREADYMEMBER
Else
On Error Resume Next
Err.Clear
localAdminGroup.Add ("WinNT://"& adminAccountName)
errorCode = Err.Number
errorMsg = Err.Description & " (" & Err.Number & ")"
On Error GoTo 0
If errorCode = 0 Then
msg = msg & MSG_CHECKLOCALADMIN_ADDMEMBEROK
Else
msg = msg & MSG_CHECKLOCALADMIN_ADDMEMBERFAIL & errorMsg
status = 3
End If
End If
Else
msg = msg & MSG_NOTFOUND
status = 2
End If
If status = 1 Then
msg = msg & MSG_OK
Conform_LocalAdminOptions = True
Else
msg = msg & MSG_NOTOK
Conform_LocalAdminOptions = False
End If
WriteLogMsg msg, status, 1, 0
End If
End Function
WriteLogMsg MSG_CHECKCACHE_START, 1, 1, 1
WriteLogMsg MSG_CHECKCACHE_START, 1, 1, 1
cacheSize = cache.Size
WriteLogMsg " *Current cache size is: " & cacheSize, 1, 1, 1
desiredCacheSize = CInt(GetOptionValue(OPTION_CACHESIZE, DEFAULT_CACHESIZE,
options))
If cacheSize <> desiredCacheSize Then
cache.Size = desiredCacheSize
On Error Resume Next
Err.Clear
cache.Put_
errorCode = Err.Number
errorMsg = Err.Description & " (" & Err.Number & ")"
On Error GoTo 0
Function CheckAssignment
Dim smsClient, siteCode
Dim errorCode
WriteLogMsg MSG_CHECKASSIGNMENT_START, 1, 1, 1
On Error Resume Next
Err.Clear
Set smsClient = CreateObject ("Microsoft.SMS.Client")
errorCode = Err.Number
siteCode = smsClient.GetAssignedSite
On Error GoTo 0
If Len(siteCode) = 0 Or errorCode <> 0 Then
WriteLogMsg MSG_CHECKASSIGNMENT_NOTOK & siteCode, 1, 1, 0
CheckAssignment = False
Else
WriteLogMsg MSG_CHECKASSIGNMENT_OK & siteCode, 1, 1, 0
CheckAssignment = True
End If
installPatchProperty = ""
WriteLogMsg "Uninstalling Client", 1, 1, 0
If options.Exists(OPTION_INSTALLPATH) Then
cacheSize = GetOptionValue(OPTION_CACHESIZE, DEFAULT_CACHESIZE,
options)
TrimTrailingSlash commandLine
commandLine = options.Item(OPTION_INSTALLPATH) & "\ccmsetup.exe"
msg = MSG_INSTALLCLIENT_PATHCHECK & commandLine
installPatchProperty = ""
WriteLogMsg MSG_INSTALLCLIENT_START, 1, 1, 0
If options.Exists(OPTION_INSTALLPATH) Then
cacheSize = GetOptionValue(OPTION_CACHESIZE, DEFAULT_CACHESIZE,
options)
TrimTrailingSlash commandLine
commandLine = options.Item(OPTION_INSTALLPATH) & "\ccmsetup.exe"
msg = MSG_INSTALLCLIENT_PATHCHECK & commandLine
'other props
If options.Exists(OPTION_OTHERINSTALLPROPS) Then
commandLine = commandLine & " " &
options.Item(OPTION_OTHERINSTALLPROPS)
End If
Else
WriteLogMsg msg & MSG_NOTFOUND & ": " &
errorMsg, 2, 1, 0
End If
End If
Else
commandLine = commandLine & " " & param & "=" &
parameters.Item(param)
End If
Next
Function InWinPE
Dim sysEnv, systemDrive
Set sysEnv = g_WshShell.Environment("PROCESS")
systemDrive = sysEnv("SYSTEMDRIVE")
Function IsAdmin
On Error Resume Next
CreateObject("WScript.Shell").RegRead("HKEY_USERS\S-1-5-19\Environment\TEMP")
If err.number = 0 Then
IsAdmin = True
Else
IsAdmin = False
'WScript.Echo "User is not a local admin."
End If
On Error GoTo 0
End Function
'Make the file name of the new log file to be placed on \\winfs\logs
strLogName = strComputerName & "_" & "ConfigMgrStartupLog.txt"
'Attach the Winfs\logs UNC path to the new log file name.
g_finalLog = options.Item(CONFIGMGRLOGPATH) & strLogName
'Open log file on local machine and read the contents to a variable
set localLog = g_fso.OpenTextFile(g_logPathandName, 1, True)
ReadAllTextFile = localLog.ReadAll
'write the contents of the client log file into the final log file share
remoteLog.Write(ReadAllTextFile)
strComputerName = g_WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
'Get Operating system info
'Connect the wmiservices to target computer
Set objWMIService = GetObject("winmgmts:\\" & strComputerName & "\root\
cimv2")
Set colObjOS = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
strComputerName = g_WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
'Get Operating system info
'Connect the wmiservices to target computer
Set objWMIService = GetObject("winmgmts:\\" & strComputerName & "\root\
cimv2")
Set colObjOS = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each oOS in colObjOS
sVer = oOS.version
If(Left(sVer,3)) >= 6.0 Then 'If Win7
oArch = oOS.OSArchitecture
Select Case oArch
Case "32-bit"
OSArch = 32
Case "64-bit"
OSArch = 64
End Select
Else 'XP
Set colObjProc = objWMIService.ExecQuery("SELECT * FROM
Win32_Processor")
For Each objProc in colObjProc
iWidth = objProc.AddressWidth
If iWidth = 32 or iWidth = 64 Then
OSArch = iWidth
End If
Next
End If
Next
End Sub
Function IsLegacyOS()
Dim oArch
Dim sVer
Dim colObjOS
Dim iWidth
Dim oOS
Dim bLegacyOS
IsLegacyOS = bLegacyOS
End Function
'set wmiObj
Set ccmWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\
ccm")
bHotfixNeeded = true
CheckOSNeedsCertHotfix = bHotfixNeeded
End Function
Case Else
sHFXFilename = False
End Select
Case Else
bFail = True
End Select
bResults = False
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\
cimv2")
''' Begin
WriteOpeningBlock
Main