web view' * wmi fixing / integration with wmidiag.vbs (see microsoft.com) ... 'on error...
TRANSCRIPT
![Page 1: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/1.jpg)
Const ScriptVersion = "4.18"
'=============== Info =======================================
' USEAGE: CLIENT HEALTH REPAIR
' Based on source at: Rob Olson at Dude Works
' http://wwww.dudeworks.com/Support/SupportForum/tabid/83/mid/475/groupid/6/Default.aspx
' Based on source at: Brian Mason at http://www.abetterpc.com/
' Based on source at: www.1e.com
' Based on source at: Shaun Cassells at http://myitforum.com/cs2/blogs/scassells/default.aspx
'
'============================================================
' Requirements
' Requires sc.exe either present in run directory, %systemroot%\system32\, or %systemroot%\system32\dllcache
' Requires regsrv32.exe to be in %systemroot%\system32\ or accessible in path
'============================================================
' Overview
' The following script fixes generic workstation issues in a networked corporate environment
' not designed to run on servers
'
'
'============================================================
' 4.18 updates - Shaun Cassells
'
'
'
'Area's that need improvement
' * Checking the SMS Client
' * Install methods for SMS/ConfigMgr Client
![Page 2: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/2.jpg)
' * ConfigMgr 2007 specific changes
' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com)
' * BITS Checking - Correct security
' * BITS version correct
'
'============================================================
'On Error Resume Next
Dim objWMIService, oWMIService, oServices
Dim ADSiteName
Dim oUIResManager
Dim oCache, CacheSize
Dim SiteName,SiteCode,GUID,Version,strComputerRole
Dim dd,strLogFile,tempPath,CCM_DIR,ddr
Dim CLIENTSTATE,StrERRType
Dim strValue,strValues
Dim GoodLogPath,BadLogPath,logGood,LogBad,doRunCheck,eventlog
Dim StrCCRServer,strCCRSiteCode,strLOGServer
Dim LocalAdminGroup,admACCT
Dim do_CHK_LOCALADMIN,do_CHK_ADMSHARE,do_CHK_RemoteReg,do_CHK_WMI_SERVICE,do_CHK_BITS_SERVICE,do_CHK_REGXML
Dim do_CHK_AdvClient,do_SEND_CCR,do_RUN_CCMSetUP,do_REBUILD,do_REPAIR,do_CHK_DCOM,do_StartSeriviceViaSC,SCEXELocation
Dim intEventType,strEventDescription
Dim iniResult
Dim sOStype,isOS,OS, sOSversion
Dim strEnvLog, strEnvVal
Dim SMSCLIENTLASTERROR
![Page 3: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/3.jpg)
Dim oSmsversion,SMSVersion,ConfigMgrVersion
' ===================================================================
'===========File System Constants====================================
' ===================================================================
Const ForReading = 1, TemporaryFolder = 2, ForAppending = 8
Const OverwriteExisting = True
' ===================================================================
'===========Registry Constants=======================================
' ===================================================================
Const HKeyName_LOCAL_MACHINE = &H80000002
'Const HKeyName_CURRENT_USER = &H80000001
' ===================================================================
'===========Event Log Constants======================================
' ===================================================================
Const EVENT_SUCCESS = 0
Const EVENT_ERROR = 1
Const EVENT_WARNING = 2
Const EVENT_INFORMATION = 4
Const AUDIT_SUCCESS = 8
Const AUDIT_FAILURE = 16
' ===================================================================
'=============== Load/Create Objects ================================
' ===================================================================
On Error Resume Next
Dim WSHShell: Set WSHShell = CreateObject("WScript.Shell")
If err <> 0 Then WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - WScript.Shell is broken" : CleanUp(err) 'Windows Scripting Host is busted!
![Page 4: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/4.jpg)
WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - Last Run @ " & now
Dim objSysInfo: Set objSysInfo = CreateObject("ADSystemInfo")
If err <> 0 Then WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - ADSystemInfo is broken" : CleanUp(err)
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
If err <> 0 Then WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - Scripting.FileSystemObject is broken" : CleanUp(err)
Dim oLocator: Set oLocator = CreateObject("WbemScripting.SWbemLocator")
If err <> 0 Then WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - WbemScripting.SWbemLocator is broken" : CleanUp(err)
' Dim objNetwork: Set objNetwork = WScript.CreateObject("WScript.Network")
On Error GoTo 0
' ===================================================================
'=============== GET ENVIRONMENT and LOGGING DETAILS ================
' ===================================================================
'Set Current Directory
wshshell.CurrentDirectory = WScript.ScriptFullName & "\.."
Dim strCurrentDir: strCurrentDir = wshSHELL.CurrentDirectory
Dim Computer: Computer = WSHShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Dim HomeDrive: HomeDrive = WSHShell.ExpandEnvironmentStrings("%HOMEDRIVE%")
Dim windir: windir = WSHShell.ExpandEnvironmentStrings("%WINDIR%")
Dim UserTempPath: UserTempPath = WSHShell.ExpandEnvironmentStrings("%TEMP%")
'Check to see what state of client is in
![Page 5: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/5.jpg)
'Errors are incremented
CLIENTSTATE=0
'Grab OS version
GetOs
'Set Logfile location
StrERRType = ""
strFileName = "sms_chk_" & computer & ".log"
strLogFile = UserTempPath & "\" & strFileName
lenWinDir = Len(windir)
strUNCLogFile = "\\" & Computer & "\admin$" & Right(UserTempPath,Len(UserTempPath)- lenWinDir) & "\" & strFileName
' ===================================================================
' ==========CONFIG SETTINGS==========================================
' ===================================================================
'/// Check System role, If role =0 or 1 Then WKS, 2 3 4 & 5 are Server roles
'SMS 2003 SP2 version
SMSVersion="2.50.4160.2000"
ConfigMgrVersion=""
'AUTO because AD is extended with servers published
WKS_ASSIGNSITECODE = "AUTO"
WKS_CacheSize = 2048 'Plenty large enough for service packs
WKS_LocalAdminGroup = "Administrators" 'SpecIfy Local Admin group to add SMS Admin Acount to (DEFAULT=Administrators)
WKS_admACCT = "<EnterYoursHere>" 'SpecIfy SMS Admin account (group)
'//Registry for counts
![Page 6: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/6.jpg)
RegPath = "HKLM\SYSTEM\Setup\ClientHealthStartup"
'Webpage to submit updates to
strWebAddress = "http://<EnterYourFQDNSiteHere>/clienthealth/default.asp"
'// CCR's
StrCCRServer = "<SITESERVER>" 'SpecIfy Site server to send CCR's to
strCCRSiteCode = "<sc>"
'If you use this method you need to grant
'DOMAIN\DOMAIN COMPUTERS write permissions (NFTS) to that share since the script runs under local system
GoodLogPath ="\\<EnterYoursHere>\SMSCLIENTLOGS\GPO\Good" 'SpecIfy Site server to send good/success logs (DEFAULT)
BadLogPath ="\\<EnterYoursHere>\SMSCLIENTLOGS\GPO\Bad" 'SpecIfy Site server to send bad/fail logs
' Always capture your bad client logs so you can see who and where you have bad systems.
'//CCMSetUP LOCATION
CCMSetUP = "\\<EnterYoursHere>\SMSClient\i386\ccmSetup.exe" 'Path to CCMSetup.exe
'Note this is the x32 path. x64 is different
CCM_DIR = windir & "\system32\CCM\"
' ===================================================================
' ==========Logging SETTINGS=========================================
' ===================================================================
'// LOGGING
logToEventsSummary=True 'Post single event log item that includes all events(DEFAULT=True) '
LogToConsoleVerbose=False 'wscript.echo the log file to the console (DEFAULT=False)
![Page 7: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/7.jpg)
LogToConsoleDebug=False 'Wscript.echo for extra debugging (DEFAULT=False)
LogEnvironment=True 'Log environment, will aid in troubleshooting client, includes: system,user,process, volatile
LogGood=False 'copies the log file to a path designated below on a healthy machine (DEFAULT=False)
LogBad=False 'copies the log file to a path designated below on a healthy machine (DEFAULT=False)
Do_WebSubmit = False 'Submits to a website for centralized reporting
'Great for tracking trends via a webpage
'Check Shaun's blog at MyITForum.com (see header)
LogRegCounter = False 'Writes totals to the Registry on the machine
'Great for tracking trends via a SMS Def MOF
'Check Shaun's blog at MyITForum.com (see header)
iHoursBetweenRun = 12 ' Number of hours that must have elapsed before next run
doRunCheck=False ' Will only allow the script to fully run on a system once within iHoursBetweenRun hours
' ===================================================================
' ==========WMI SETTINGS=============================================
' ===================================================================
'// WMI REPAIR OPTIONS - WARNING - ONLY SELECT ONE OPTION TO REPAIR WMI
do_REBUILD = False '(DEFAULT=False)this option uses a BRUTE FORCE and renames the repository to repository_old and allows WMI to rebuild a new repository
![Page 8: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/8.jpg)
'this wil also wipe out any custom data you have stored in WMI- so beware - however this the MOST EFFECTIVE
do_REPAIR = True 'this option uses the repair upgrade option of WMI to attempt a gentle recovery without losing any custom data
'If BOTH options are Set to False we will only log the WMI issue and you'll be able to manually deal with the WMI issues
' however the script will NOT repair anything Else until WMI is fixed.
' ===================================================================
' ==========Functional Checks========================================
' ===================================================================
'// enable True / False tasks you wish to run
do_CHK_CheckLogFileModifyDate = True 'Check to see if log file is updating recently
do_CHK_ASSIGNMENT = True ' If a client is without an assignment, uses AD to determine assignment
do_CHK_CCMEXEC = True ' CHK_CCMEXEC should ALWAYS RUN - LEAVE at TRUE
do_CHK_AdvClient = True ' Checks Advanced client state
'Untested - do_SEND_CCR
do_SEND_CCR = False ' Sends a CCR to your site server( only use If you dont use RUN_CCMSetUP )
do_RUN_CCMSetUP = False ' Runs CCMSetUP from specIfied server share location in order to reinstall the client
'<COMMENT>
' only use one install method CCR or CCMSetUP.. option is for enviroments where clients dont haven rights to write a CCR to the server but can pull CCMSetUP
' Running CCMSetUP can be a little brutal but it should only happen once and its a much surer way to make sure that client gets installed correctly and right away
do_CHK_SMSUPDATECLIENT = False ' CHECK latest SMS client version and install updated client If needed.
do_CHK_CACHESIZE = True ' checks/Sets the cache size
![Page 9: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/9.jpg)
'Checks
do_CHK_SYSTEMPATH = True ' Cleans up the System PATH statement environment by ensuring the wbem is near the front of and that there are no duplicates in the path
do_CHK_DCOM = True ' Forces DCOM security premissions for SMS client access
'May not work currently
do_CHK_LOCALADMIN = True ' Adds your SMS Account to the local admins group
do_CHK_ADMSHARE = True ' checks and repairs Admin$
'Services
do_CHK_RPC_SERVICE = True 'Turns on RPC before everything
do_CHK_WMI_SERVICE = True ' Checks WMI service
do_CHK_FIREWALL_ICS_SERVICE = True 'Truns on ICS after WMI
do_CHK_SERVER_SERVICE = True ' Checks Server Service
do_CHK_RemoteReg = True ' Enables remote registry
do_CHK_BITS_SERVICE = True ' Checks BITS service
do_CHK_WUS_SERVICE = True ' Checks Automatic service
do_CHK_TERMSERVICE_SERVICE = True ' Checks Terminal service
do_CHK_MSI_SERVICE = True ' Checks Windows Installer service
'Register
do_CHK_REGXML = False ' Registers XML
do_CHK_REGBITS = False ' Registers two Bits files
do_CHK_REGOLEAut32 = False ' Registers OLEAut32
do_CHK_REGMsiexec = False ' Registers msiexec /regserver
Debug("********** Start ***********")
'===================================================================
![Page 10: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/10.jpg)
'===================================================================
'=================== START =========================================
'===================================================================
'===================================================================
'check to see when last time script was run based on last log date
' dont run more than once in 12 hrs
' this prevents a client that is really hosed to not keep reinstalling everytime the user logs in
' but rather attempts more fixes once a day
On Error Resume Next
If doRunCheck=True Then
On Error Resume Next
If objFSO.FileExists(strLogFile) Then
Set ofile =objFSO.GetFile(strLogFile)
'Debug("Date diff = " & DateDIff("h", ofile.DateLastModified , Now))
'Debug("iHoursBetweenRun = " & iHoursBetweenRun)
If DateDIff("h", ofile.DateLastModified , Now) < iHoursBetweenRun Then
Debug("ran recently")
WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - Ran less than " & iHoursBetweenRun & " hours ago " & Now
CleanUp("doRunCheck")
End If
End If
End If
'Deletes the previous log file
If objFSO.FileExists(strLogFile) Then
objFSO.DeleteFile(strLogFile)
End If
![Page 11: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/11.jpg)
'Creates new log file
Set oFile = objFSO.CreateTextFile(strLogFile)
oFile.Close
err.clear
WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - Last Full Run @ " & now
ADSiteName = objSysInfo.SiteName
Debug("********** Begin System_Info ***********")
COLLECTMSG "SYSTEM_INFO","SCRIPT_SOURCE","WKS"
COLLECTMSG "SYSTEM_INFO","SCRIPT_VERSION",ScriptVersion
COLLECTMSG "SYSTEM_INFO","SCRIPT_LOCATION",strCurrentDir
COLLECTMSG "SYSTEM_INFO","SYSTEMNAME", Computer
COLLECTMSG "SYSTEM_INFO","OPERATING_SYSTEM",OS & " " & sOSversion
COLLECTMSG "SYSTEM_INFO","SYSTEMROLE",strComputerRole
COLLECTMSG "SYSTEM_INFO","LOGFILE", strLogFile
COLLECTMSG "SYSTEM_INFO","AD_USERNAME", objSysInfo.UserName
COLLECTMSG "SYSTEM_INFO","AD_COMPUTERNAME", objSysInfo.ComputerName
COLLECTMSG "SYSTEM_INFO","AD_SITENAME", objSysInfo.SiteName
' =============================================================================
' RunTasks
' Description: CONNECT TO MGMT SERVICE
' =============================================================================
Err.clear
Debug("********** Chk DCOM & System Path & Local Admin Group ***********")
If do_CHK_DCOM = True Then CHK_DCOM
If do_CHK_SYSTEMPATH = True Then CHK_SYSTEMPATH ' This will ensure that the wbem path is near the front or the environment.
![Page 12: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/12.jpg)
SCFileExist
' True if sc.exe file is found; False if not
' Checks current path and %systemroot%\system32
' SC.exe attempts to start a service
If isOS="workstation" Then
If InStr(UCase(WScript.ScriptName),"SRV") Then CleanUp(err)
LocalAdminGroup = WKS_LocalAdminGroup
admACCT = WKS_admACCT
ASSIGNSITECODE = WKS_ASSIGNSITECODE
CacheSize = WKS_CacheSize
Else
'Disabled as this will not run on servers
COLLECTMSG "isOS","Error","Non workstation computer type"
CleanUp(err)
End If
If do_CHK_LOCALADMIN = True Then CHK_SMSLOCALADMIN
Debug("********** Check WMI Service Mode ***********")
COLLECTMSG "WMI Service",">",null
'Check to see if Service is disabled
Select Case wshshell.regread("HKLM\SYSTEM\CurrentControlSet\Services\winmgmt\Start")
Case 2
'Auto setting - GOOD
COLLECTMSG "WMI","Service in Reg is set to Auto",null
Debug("WMI is set to auto")
Case 3
'Manual setting - Connecting will start
![Page 13: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/13.jpg)
'Make service set to Automatic
COLLECTMSG "WARNING","WMI","Service in Reg is set to Manual"
Debug("WMI is set to Manual")
RegCounter "WMI",1
CLIENTSTATE = CLIENTSTATE + 1
Case 4
'Attempts to use sc.exe to start the service
Debug("WMI Service is not set to AUTO")
Debug("do_StartSeriviceViaSC = " & do_StartSeriviceViaSC)
If do_StartSeriviceViaSC Then StartSeriviceViaSC "winmgmt","auto"
RegCounter "WMI",1
CLIENTSTATE = CLIENTSTATE + 1
End Select
' =============================================================================
'CHECK If WMI IS ACCESSIBLE and CONNECT
' =============================================================================
Debug("********** Check WMI Connection ***********")
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
If Err <> 0 Then
COLLECTMSG "ERRORS","WMI_CONNECT",err & " " & err.description
Debug("********** WMI Connection FAIL ***********")
RegCounter "WMI",1
CLIENTSTATE = CLIENTSTATE + 1
'//CANNOT CONNECT TO WMI
Debug("Registry WMIStatus = " & WSHShell.Regread(RegPath & "\WMIStatus"))
Select Case WSHShell.Regread(RegPath & "\WMIStatus")
![Page 14: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/14.jpg)
Case ""
Debug("WMIStatus = no prior break")
If do_REPAIR = True Then REPAIR_WMI_XP : RegCounter "WMIStatus","REPAIRED"
Case "REPAIRED"
Debug("WMIStatus = REPAIRED")
If do_REBUILD = True Then REBUILD_WMI_BRUTE_FORCE : RegCounter "WMIStatus","REPAIRED"
Case "REBUILT"
Debug("WMIStatus = REBUILT")
RegCounter "WMIFail",1
CLIENTSTATE = CLIENTSTATE + 100
COLLECTMSG "ERRORS","REBUILT","This machine has gone through Repair and Rebuild - still failing"
End Select
If LogBad=True Then
Set_LOGFOLDER()
err.clear
objFSO.CopyFile strLogFile , BadLogPath, OverwriteExisting
If Err<>0 Then COLLECTMSG "LogBad","Error",err & " " & err.description
End If
err.clear
WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - WMI " & WSHShell.Regread(RegPath & "\WMIStatus") & " " & Now
Debug("ClientState = " & CLIENTSTATE)
On Error GoTo 0
CleanUp(err)
End If
![Page 15: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/15.jpg)
'***Repleace with Registry counter
RegCounter "WMIStatus",""
'WriteEnvVar "SMSCLIENT_CHK_WMI_CONNECT","","system","0"
'WriteEnvVar "SMSCLIENT_CHK_WMI_LAST","","system","0"
' =============================================================================
' RunTasks
' Description: Generic Health Tasks
' =============================================================================
Err.clear
Debug("********** Begin Checks ***********")
If do_CHK_ADMSHARE = True Then CHK_ADMSHARE
If do_CHK_REGXML = True Then CHK_REGXML
If do_CHK_REGBITS = True Then CHK_REGSVR32 "CHK_REGBITS", "Qmgr.dll" : CHK_REGSVR32 "CHK_REGBITS", "qmgrprxy.dll"
If do_CHK_REGOLEAut32 = True Then CHK_REGSVR32 "CHK_REGOLEAut32", "OLEaut32.dll"
If do_CHK_REGMsiexec = True Then CHK_REGMsiexec
Debug("********** Begin Services ***********")
If do_CHK_RPC_SERVICE = True Then Fix_Service "CHK_RPC_SERVICE","RpcSs","auto","Running"
If do_CHK_WMI_SERVICE = True Then Fix_Service "CHK_WMI_SERVICE","winmgmt","auto","Running"
If do_CHK_FIREWALL_ICS_SERVICE = True Then Fix_Service "CHK_FIREWALL_ICS_SERVICE","SharedAccess","auto","Running"
If do_CHK_SERVER_SERVICE = True Then Fix_Service "CHK_SERVER_SERVICE","lanmanserver","auto","Running"
If do_CHK_RemoteReg = True Then Fix_Service "CHK_RemoteReg","RemoteRegistry","auto","Running"
If do_CHK_BITS_SERVICE = True Then Fix_Service "CHK_BITS_SERVICE","BITS","Manual","unimportant"
If do_CHK_WUS_SERVICE = True Then Fix_Service "CHK_WUS_SERVICE","wuauserv","auto","Running"
![Page 16: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/16.jpg)
If do_CHK_TERMSERVICE_SERVICE = True Then Fix_Service "TERMSERVICE_SERVICE","TermService","Manual","unimportant"
If do_CHK_MSI_SERVICE = True Then Fix_Service "MSI_SERVICE","MSIServer","Manual","unimportant"
Debug("********** Begin SMS ***********")
CHK_SMSVERSION
If do_CHK_CCMEXEC = True Then Fix_Service "CHK_CCMEXEC","CcmExec","auto","Running"
If do_CHK_SMSUPDATECLIENT = True Then CHK_SMSUPDATECLIENT
COLLECTMSG "SYSTEM_INFO","CLIENTSTATE",CLIENTSTATE
Debug("Client State = " & CLIENTSTATE)
If CLIENTSTATE = 0 Then
' =============================================================================
' RunTasks
' Description: Run Healthy Client
' =============================================================================
Debug("********** Healthy last SMS ***********")
If do_CHK_CheckLogFileModifyDate = True Then CheckLogFileModifyDate("PolicyEvaluator.log")
If do_CHK_ASSIGNMENT = True Then CHK_ASSIGNMENT ' now that everything is fixed we check that the client is assigned and If not we'll
' force a new client install and since everything Else has now been fixed this new
' install should take care of any last client hang ups, If your client still does not
' function after this Then you need to reimage the computer because nothing Else is going to help
If LogGOOD = True Then
COLLECTMSG "SYSTEM_INFO","Set_LOGFOLDER",GoodLogPath
Set_LOGFOLDER()
err.clear
objFSO.CopyFile strLogFile , GoodLogPath , OverwriteExisting
![Page 17: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/17.jpg)
If Err<>0 Then COLLECTMSG "LogGOOD","Error",err & " " & err.description
End If
WSHShell.LogEvent EVENT_INFORMATION, now & " SMS STARTUP SCRIPT/CLIENT STATE= HEALTHY"
Else
' =============================================================================
' RunTasks
' Description: Run Client Stupid Healing Tasks
' =============================================================================
Debug("********** NOT Healthy last SMS ***********")
If do_CHK_AdvClient = True Then CHK_ADVCLIENT
If do_CHK_CACHESIZE = True Then CHK_CACHESIZE
If do_SEND_CCR = True Then SEND_CCR
If do_RUN_CCMSetUP = True Then RUN_CCMSetUP
If LogEnvironment = True Then
GetLogEnvironment
End If
If LogBAD = True Then
COLLECTMSG "SYSTEM_INFO","Set_LOGFOLDER",BadLogPath
Set_LOGFOLDER()
Err.clear
objFSO.CopyFile strLogFile , BadLogPath , OverwriteExisting
If Err<>0 Then COLLECTMSG "LogBAD","Error",err & " " & err.description
End If
'Added now to Next line - not sure If that works with Event_Warning
![Page 18: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/18.jpg)
If logToEventsSummary=True Then WSHShell.LogEvent EVENT_WARNING, Now & vbCRLF & eventlog & vbCrLf & strEnvLog
End If
'Clean up
CleanUp(err)
' =============================================================================
' Method: CHK_SMSVERSION
' Description: checks ccmexec file version, If no match latest version
' reinstall latest client
' =============================================================================
![Page 19: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/19.jpg)
Sub CHK_SMSVERSION()
Dim objWMIServiceCLI,colCLIPropsList,colCLIProps
On Error Resume Next
COLLECTMSG "CHK_SMSVERSION","SMSVERSION_SITE",SMSVersion
Set objWMIServiceCLI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & Computer & "\root\ccm")
If Err <> 0 Then
CLIENTSTATE = CLIENTSTATE + 1
StrERRType=StrERRType & "CHK_SMSVERSION_"
COLLECTMSG "CHK_SMSVERSION","ERROR","Cannot connect to \ROOT\CCM client may not exist"
Exit Sub
End If
Set colCLIPropsList = objWMIServiceCLI.ExecQuery("Select * from SMS_Client")
For Each colCLIProps In colCLIPropsList
COLLECTMSG "CHK_SMSVERSION","VERSION", colCLIProps.ClientVersion
oSmsversion=colCLIProps.ClientVersion
Debug("Client Version " & oSmsversion)
Next
On Error GoTo 0
End Sub
' =============================================================================
' Method: CHK_SMSUPDATECLIENT
' Description: checks SMS Client Version
' =============================================================================
![Page 20: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/20.jpg)
Sub CHK_SMSUPDATECLIENT()
If oSmsversion < SMSVersion Then
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_SMSUPDATECLIENT",1
COLLECTMSG "CHK_SMSVERSION","UPDATE_SMSCLIENT","This system in not running the latest version SMS Client, reinstalling new client"
RUN_CCMSetUP
COLLECTMSG "CHK_SMSVERSION","UPDATE_SMSCLIENT","Completed"
End If
End Sub
' =============================================================================
' Method: CHK_SYSTEMPATH
' Description: checks that wbem is near the front of the sys path and cleans
' any duplicate statements from the path environment
' =============================================================================
Sub CHK_SYSTEMPATH()
WindirPath = LCase(windir)
System32path = LCase(windir & "\system32")
WBEMpath = LCase(windir & "\system32\wbem")
WindirPathFound = False
System32pathFound = False
WBEMpathFound = False
SystemRoot = False
![Page 21: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/21.jpg)
strKeyNamePath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
strValueName = "Path"
'// GET PATH STATEMENT
strValue = wshshell.regRead("HKLM\" & strKeyNamePath & "\" & strValueName)
strValue = LCase(strValue)
ARRpath = Split(LCase(strValue), ";")
For i = 0 To UBound(ARRpath)
'Repalce SystemRoot with actual value
If InStr(ARRpath(i), LCase("%systemroot%")) <> 0 Then strValue = Replace(strValue, LCase("%systemroot%"), LCase(windir)) : SystemRoot = True : COLLECTMSG "CHK_SYSTEMPATH","Warning Replaced %systemroot%",SystemRoot
If ARRpath(i) = WindirPath Then WindirPathFound = True
If ARRpath(i) = System32path Then System32pathFound = True
If ARRpath(i) = WBEMpath Then WBEMpathFound = True
Next
If (WBEMpathFound = True) And (System32pathFound = True) And (WindirPathFound = True) And (SystemRoot = False) Then COLLECTMSG "CHK_SYSTEMPATH","All Paths Found",WBEMpathFound: Exit Sub
COLLECTMSG "CHK_SYSTEMPATH","PATH",strValue
'// Log the results
logit=False
If WBEMpathFound = False Then strValue = WBEMpath & ";" & strValue : COLLECTMSG "CHK_SYSTEMPATH","Error WBEMpathFound", WBEMpathFound:logit=True : CLIENTSTATE = CLIENTSTATE + 1
![Page 22: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/22.jpg)
If WindirPathFound = False Then strValue = WindirPath & ";" & strValue : COLLECTMSG "CHK_SYSTEMPATH","Error WindirPathFound", WindirPathFound :logit=True : CLIENTSTATE = CLIENTSTATE + 1
If System32pathFound = False Then strValue = System32path & ";" & strValue : COLLECTMSG "CHK_SYSTEMPATH","Error System32pathFound",System32pathFound:logit=True : CLIENTSTATE = CLIENTSTATE + 1
If logit = True Then StrERRType = StrERRType & "SYSTEMPATH_"
'//Take out duplicates
'Dictionary Object is Much faster
ARRpath = Split(LCase(strValue), ";")
Set PureString = CreateObject("Scripting.Dictionary")
For i = 0 To UBound(ARRpath)
If Not PureString.Exists(ARRpath(i)) Then PureString.Add ARRpath(i), ARRpath(i) : Debug(ARRpath(i))
Next
strValues = ""
For Each strKeyName in PureString.Keys
strValues = strValues & strKeyName & ";"
Next
Set PureString = Nothing
'Remove duplicate semicolons
If InStr(strValues, ";;") <> 0 Then strValues = Replace(Replace(strValues, ";;", ";"), ";;", ";")
'Remove trailing semicolons
ln = Len(strValues)
If InStr(ln, strValues, ";") <> 0 Then strValues = Left(strValues, ln - 1)
'// Set PATH STATEMENT
'Set to current runtime path
Set oEnv = WshShell.Environment("System")
![Page 23: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/23.jpg)
oEnv("Path")=strValues
Set oEnv = Nothing
'Set to Registry for next restart
wshshell.regwrite "HKLM\" & strKeyNamePath & "\" & strValueName,strValues,"REG_SZ"
RegCounter "CHK_SYSTEMPATH",1
COLLECTMSG "CHK_SYSTEMPATH","PATH_CLEAN", strValues
End Sub
' =============================================================================
' Method: CHK_ADMSHARE
' Description: Checks ADMIN SHARES ACCESS
'Value Data: (0 = disable shares, 1 = enable)
' =============================================================================
Sub CHK_ADMSHARE()
admShareFound = False
Set colshares = objWMIService.ExecQuery("Select * from Win32_Share where Name = 'ADMIN$'")
For Each objShare In colshares
admShareFound = True
COLLECTMSG "CHK_ADMSHARE", "FOUND",admShareFound
Next
If admShareFound = False Then
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_ADMSHARE",1
StrERRType=StrERRType & "CHK_ADMSHARE_"
COLLECTMSG "CHK_ADMSHARE","FOUND",admShareFound
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
![Page 24: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/24.jpg)
Computer & "\root\default:StdRegProv")
strKeyNamePath = "SYSTEM\CurrentControlSet\Services\LanManServer\Parameters"
'strValueNameSRV = "AutoShareServer" ' for servers
strValueNameWS = "AutoShareWks" ' for workstations
oReg.SetDWORDValue HKeyName_LOCAL_MACHINE, strKeyNamePath, strValueNameWS, 1
COLLECTMSG "CHK_ADMSHARE", "FIXED", Null
End If
End Sub
' =============================================================================
' Method: CHK_AdvClient
' Description: Checks CHK_AdvClient components
' =============================================================================
Sub CHK_ADVCLIENT()
On Error Resume Next
Dim oCPAppletMgr 'Control Applet manager object.
Dim oClientComponent 'Individual client components.
Dim oClientComponents 'A collection of client components.
'Get the Control Panel applet manager object.
Set oCPAppletMgr = CreateObject("CPApplet.CPAppletMgr")
If oCPAppletMgr Is Nothing Then
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_ADVCLIENT",1
Debug("Cannot connect to CPApplet.CPAppletMgr")
StrERRType=StrERRType & "CHK_ADVCLIENT_"
![Page 25: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/25.jpg)
Exit Sub
End If
'Get a collection of components.
Set oClientComponents = oCPAppletMgr.GetClientComponents
If oClientComponents Is Nothing Then
Set oCPAppletMgr = Nothing
Debug("No ADV Client Components")
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_ADVCLIENT",1
StrERRType=StrERRType & "CHK_ADVCLIENT_"
Exit Sub
End If
For Each oClientComponent In oClientComponents
Debug(oClientComponent.DisplayName)
Select Case oClientComponent.State
Case 0
cmsg= "installed"
Case 1
cmsg= "enabled"
Case 2
cmsg= "disabled"
End Select
'If oClientComponent.DisplayName = "SMS Client Core Components" Then
'CLIENTSTATE = oClientComponent.State
'COLLECTMSG oClientComponent.DisplayName, oClientComponent.State, Null
'End If
DisplayName=oClientComponent.DisplayName
![Page 26: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/26.jpg)
COLLECTMSG "CHK_ADVCLIENT",DisplayName,cmsg
Next
Set oClientComponents = Nothing
Set oCPAppletMgr = Nothing
If Err <> 0 Then COLLECTMSG "CHK_ADVCLIENT", "ERROR", Null
On Error GoTo 0
End Sub
' =============================================================================
' Method: CHK_ASSIGNMENT
' Description: Checks Client Site Assignment
' =============================================================================
Sub CHK_ASSIGNMENT
On Error Resume Next
Err.clear
Dim oSMSClient
Set oSMSClient = CreateObject ("Microsoft.SMS.Client")
If err.Number<>0 Then
COLLECTMSG "ERRORS","CHK_ASSIGNMENT", Err.description
COLLECTMSG "CHK_ASSIGNMENT","Could not create SMS Client Object - Quitting", Null
Else
If Len(oSMSClient.GetAssignedSite) = 0 Then
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_ASSIGNMENT",1
'oSMSClient.SetAssignedSite("ABC")
![Page 27: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/27.jpg)
'have the client determine from AD or SLP appropraite site code
oSMSClient.ReAssignSite
COLLECTMSG "CHK_ASSIGNMENT", "Client not installed correctly - Setting AUTO", Null
StrERRType=StrERRType & "CHK_ASSIGNMENT_"
End If
End If
Set oSMSClient=Nothing
On Error GoTo 0
End Sub
' =============================================================================
' Method: CHK_CACHESIZE
' Description: Checks Client Cache Size
' =============================================================================
Sub CHK_CACHESIZE
On Error Resume Next
Set oUIResManager = createobject("UIResource.UIResourceMgr")
If oUIResManager Is Nothing Then
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_CACHESIZE",1
COLLECTMSG "ERROR","CHK_CACHESIZE", Err.description
COLLECTMSG "ERROR","CHK_CACHESIZE","Could not create Resource Manager - Quitting"
StrERRType=StrERRType & "CHK_CACHESIZE_"
Exit Sub
End If
Set oCache=oUIResManager.GetCacheInfo()
![Page 28: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/28.jpg)
If oCache Is Nothing Then
Set oUIResManager=Nothing
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_CACHESIZE",1
COLLECTMSG "ERROR","CHK_CACHESIZE","Could not get cache info - Quitting"
StrERRType=StrERRType & "CHK_CACHESIZE_"
Exit Sub
End If
oCache.TotalSize=CacheSize
COLLECTMSG "CHK_CACHESIZE","CACHE SIZE", CacheSize
If Err <> 0 Then COLLECTMSG "CHK_CACHESIZE", "ERROR", Null
On Error GoTo 0
End Sub
' =============================================================================
' Method: CHK_SMSLOCALADMIN
' Description: Adds your SMS Admin Account to the local admininstrators group
' =============================================================================
Sub CHK_SMSLOCALADMIN()
COLLECTMSG "CHK_SMSLOCALADMIN",">", Null
On Error Resume Next
'>>> Add SMS ADMIN to Local Administrator group
If InStr(admACCT, "\") <> 0 Then admACCT = replace(admACCT, "\", "/")
Set objGroup = GetObject("WinNT://" & Computer & "/" & LocalAdminGroup & ",group")
If Not objGroup.IsMember("WinNT://" & admACCT) Then
CLIENTSTATE = CLIENTSTATE + 1
![Page 29: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/29.jpg)
RegCounter "CHK_SMSLOCALADMIN",1
'Change slash to allow adding
objGroup.Add ("WinNT://"& admACCT)
COLLECTMSG "CHK_SMSLOCALADMIN", "Added", Null
StrERRType=StrERRType & "LocalAdmin_"
Else
COLLECTMSG "CHK_SMSLOCALADMIN", "True" , Null
End If
If Err <> 0 Then COLLECTMSG "CHK_SMSLOCALADMIN","ERROR", Null
On Error GoTo 0
End Sub
' =============================================================================
' Method: REPAIR_WMI_XP
' =============================================================================
Sub REPAIR_WMI_XP()
On Error Resume Next
REPAIR_WMI_REGISTER
If do_StartSeriviceViaSC Then StartSeriviceViaSC "winmgmt","auto"
COLLECTMSG "REPAIR_WMI_XP","CMD","rundll32 wbemupgd, UpgradeRepository"
wshshell.run "rundll32 wbemupgd, UpgradeRepository",0,1
StrERRType=StrERRType & "RepairWMI_"
'WriteEnvVar "SMSCLIENT_CHK_WMI_LAST","REPAIRED","system","1"
![Page 30: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/30.jpg)
If Err <> 0 Then COLLECTMSG "ERROR", "REPAIR_WMI_XP", Null
On Error GoTo 0
End Sub
' =============================================================================
' Method: REPAIR_WMI_2003
' =============================================================================
Sub REPAIR_WMI_2003()
'This is never run
'Just for reference
On Error Resume Next
REPAIR_WMI_REGISTER
If do_StartSeriviceViaSC Then StartSeriviceViaSC "winmgmt","auto"
wshshell.run "rundll32 wbemupgd, RepairWMISetup",0,1
StrERRType=StrERRType & "RepairWMI_"
COLLECTMSG "REPAIR_WMI_2003","cmd","rundll32 wbemupgd, RepairWMISetup"
'WriteEnvVar "SMSCLIENT_CHK_WMI_LAST","REPAIRED","system","1"
If Err <> 0 Then COLLECTMSG "ERROR", "REPAIR_WMI_2003", Null
On Error GoTo 0
End Sub
' =============================================================================
' Method: REBUILD_WMI_BRUTE_FORCE
' Description: Rebuilds WMI repository
![Page 31: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/31.jpg)
' =============================================================================
Sub REBUILD_WMI_BRUTE_FORCE()
On Error Resume Next
REPAIR_WMI_REGISTER
wshshell.run "net stop winmgmt /y",0,1
WbemPath = windir & "\system32\wbem\Repository"
'objFSO.MoveFolder WbemPath, WbemPath & "_Old"
'Repalced the following line with StartSeriviceViaSC sub
'wshshell.run "net start winmgmt",0,1
REPAIR_WMI_MOF
REPAIR_SMS_MOF
If do_StartSeriviceViaSC Then StartSeriviceViaSC "winmgmt","auto"
StrERRType=StrERRType & "RebuildWMI_"
COLLECTMSG "REPAIR_WMI","Finished", Null
'WriteEnvVar "SMSCLIENT_CHK_WMI_LAST","REBUILT","system","1"
If Err <> 0 Then COLLECTMSG "REBUILD_WMI_BRUTE_FORCE", "ERROR", Null
On Error GoTo 0
End Sub
![Page 32: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/32.jpg)
' =============================================================================
' Method: REPAIR_WMI_REGISTER
' Description: Re-register WMI components
' =============================================================================
Sub REPAIR_WMI_REGISTER()
On Error Resume Next
COLLECTMSG "REGISTER_WMI",">", Null
'ClearADAP
wshshell.run windir &"\system32\wbem\winmgmt.exe /CLEARADAP"
'ReSynchPref
wshshell.run windir &"\system32\wbem\winmgmt.exe /RESYNCPERF"
Set objFolder = objFSO.GetFolder(windir &"\system32\wbem")
Set colFiles = objFolder.Files
For Each objFile in colFiles
If InStr(objFile.Name,".dll") Then
wshshell.run "RegSvr32 /s " & objFile.Path,0,1
End If
If InStr(objFile.Name,".exe") Then
If InStr(objFile.Name,"wbemtest.exe") Then
Else
wshshell.run objFile.Path & " /RegServer",0,1
End If
End If
COLLECTMSG "REGISTER_WMI",objFile.Path, Null
![Page 33: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/33.jpg)
Next
COLLECTMSG "REGISTER_WMI","Finished", Null
If Err <> 0 Then COLLECTMSG "REGISTER_WMI", "ERROR", Null
On Error GoTo 0
End Sub
' =============================================================================
' Method: REPAIR_WMI_MOF
' Description: MofComp WMI MOF's
' =============================================================================
Sub REPAIR_WMI_MOF()
On Error Resume Next
COLLECTMSG "REPAIR_WMI_MOF",">", Null
Set objFolder = objFSO.GetFolder(windir &"\system32\wbem")
Set colFiles = objFolder.Files
For Each objFile in colFiles
If InStr(objFile.Name,".mof") Then
wshshell.run "mofcomp " & objFile.Path,0,1
End If
If InStr(objFile.Name,".mfl") Then
wshshell.run "mofcomp " & objFile.Path,0,1
End If
COLLECTMSG "REPAIR_WMI_MOF",objFile.Path, Null
Next
![Page 34: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/34.jpg)
COLLECTMSG "REPAIR_WMI_MOF","Finished", Null
If Err <> 0 Then COLLECTMSG "REPAIR_WMI_MOF", "ERROR", Null
On Error GoTo 0
End Sub
' =============================================================================
' Method: REPAIR_SMS_MOF
' Description: MofComp SMS MOF's
' =============================================================================
Sub REPAIR_SMS_MOF()
On Error Resume Next
COLLECTMSG "REPAIR_SMS_MOF",">", Null
Set objFolder = objFSO.GetFolder(windir &"\system32\ccm")
Set colFiles = objFolder.Files
For Each objFile in colFiles
If InStr(objFile.Name,".mof") Then
wshshell.run "mofcomp " & objFile.Path,0,1
End If
If InStr(objFile.Name,".mfl") Then
wshshell.run "mofcomp " & objFile.Path,0,1
End If
COLLECTMSG "REPAIR_SMS_MOF",objFile.Path, Null
Next
COLLECTMSG "REPAIR_SMS_MOF","Finished", Null
If Err <> 0 Then COLLECTMSG "REPAIR_SMS_MOF", "ERROR", Null
On Error GoTo 0
![Page 35: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/35.jpg)
End Sub
' =============================================================================
' Method: CHK_REGXML
' Description: Re-Registers XML DLL
' =============================================================================
Sub CHK_REGXML()
On Error Resume Next
COLLECTMSG "CHK_REGXML",">" , Null
'// Register XML
XMLREG = windir & "\system32\regsvr32.exe /s " & windir & "\system32\msxml3.dll"
COLLECTMSG "CHK_REGXML","CMD | " & XMLREG, Null
Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2:Win32_Process")
result = oWMIService.Create(XMLREG, Null, Null, intProcessID)
COLLECTMSG "CHK_REGXML","ProcessID | " & intProcessID, Null
COLLECTMSG "CHK_REGXML","Result | " & result, Null
If Err <> 0 Then COLLECTMSG "CHK_REGXML", "ERROR", Null : CLIENTSTATE = CLIENTSTATE + 1 : RegCounter "CHK_REGXML",1
On Error GoTo 0
End Sub
' =============================================================================
' Method: CHK_REGMsiexec
' Description: Re-Registers msiexec
' =============================================================================
![Page 36: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/36.jpg)
Sub CHK_REGMsiexec()
On Error Resume Next
COLLECTMSG "CHK_REGMsiexec",">" , Null
'// Register XML
XMLREG = windir & "\system32\msiexec.exe /regserver"
COLLECTMSG "CHK_REGMsiexec","CMD | " & XMLREG, Null
Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2:Win32_Process")
result = oWMIService.Create(XMLREG, Null, Null, intProcessID)
COLLECTMSG "CHK_REGMsiexec","ProcessID | " & intProcessID, Null
COLLECTMSG "CHK_REGMsiexec","Result | " & result, Null
If Err <> 0 Then COLLECTMSG "CHK_REGMsiexec", "ERROR", Null : CLIENTSTATE = CLIENTSTATE + 1 : RegCounter "CHK_REGMsiexec",1
On Error GoTo 0
End Sub
' =============================================================================
' Method: CHK_REGSVR32
' Description: Re-Registers DLLs
' =============================================================================
Sub CHK_REGSVR32(nCHK, nFile)
On Error Resume Next
COLLECTMSG nCHK,">" , Null
'// Register XML
REGsvr = windir & "\system32\regsvr32.exe /s " & windir & "\system32\" & nFile
COLLECTMSG nCHK,"CMD | " & REGsvr, Null
![Page 37: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/37.jpg)
Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2:Win32_Process")
result = oWMIService.Create(REGsvr, Null, Null, intProcessID)
COLLECTMSG nCHK,"ProcessID | " & intProcessID, Null
COLLECTMSG nCHK,"Result | " & result, Null
If Err <> 0 Then COLLECTMSG nCHK, "ERROR", Null : CLIENTSTATE = CLIENTSTATE + 1 : RegCounter nCHK,1
On Error GoTo 0
End Sub
' =============================================================================
' Method: CHK_DCOM
' Description: Sets DCOM sercurity premissions
' =============================================================================
Sub CHK_DCOM()
COLLECTMSG "CHK_DCOM",">" , Null
'// Sets DCOM
If wshshell.regRead("HKLM\SOFTWARE\Microsoft\Ole\EnableDCOM") <> "Y" Then
COLLECTMSG "CHK_DCOM", "ERROR", "EnableDCOM | write reg "
wshshell.RegWrite "HKLM\SOFTWARE\Microsoft\Ole\EnableDCOM","Y","REG_SZ"
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_DCOM",1
End If
If wshshell.regRead("HKLM\SOFTWARE\Microsoft\Ole\EnableRemoteConnect") <> "Y" Then
COLLECTMSG "CHK_DCOM", "ERROR", "EnableDCOM | write reg "
wshshell.RegWrite "HKLM\SOFTWARE\Microsoft\Ole\EnableRemoteConnect","Y","REG_SZ"
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_DCOM",1
![Page 38: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/38.jpg)
End If
If wshshell.regRead("HKLM\SOFTWARE\Microsoft\Ole\LegacyAuthenticationLevel") <> "2" Then
COLLECTMSG "CHK_DCOM", "ERROR", "EnableDCOM | write reg "
wshshell.RegWrite "HKLM\SOFTWARE\Microsoft\Ole\LegacyAuthenticationLevel","0x00000002","REG_DWORD"
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_DCOM",1
End If
If wshshell.regRead("HKLM\SOFTWARE\Microsoft\Ole\LegacyImpersonationLevel") <> "2" Then
COLLECTMSG "CHK_DCOM", "ERROR", "EnableDCOM | write reg "
wshshell.RegWrite "HKLM\SOFTWARE\Microsoft\Ole\LegacyImpersonationLevel","0x00000002","REG_DWORD"
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "CHK_DCOM",1
End If
End Sub
' =============================================================================
' Method: SEND_CCR
' Description: Sends a CCR
' =============================================================================
Sub SEND_CCR()
COLLECTMSG "SEND_CCR",">", Null
CCRPathFile = "\\"& StrCCRServer& "\SMS_" & strCCRSiteCode & "\inboxes\CCR.BOX\" & Computer & ".CCR"
Set fsCCR = objFSO.CreateTextFile(CCRPathFile, True)
fsCCR.writeline ("[NT Client Configuration Request]")
fsCCR.writeline ("Machine Name=" & Computer)
fsCCR.Close
![Page 39: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/39.jpg)
COLLECTMSG "SEND_CCR","SENT|" & CCRPathFile, Null
End Sub
' =============================================================================
' Method: RUN_CCMSetUP
' Description: Runs CCMSetUP to install SMS Client
' =============================================================================
Sub RUN_CCMSetUP()
On Error Resume Next
COLLECTMSG "RUN_CCMSetUP",">", Null
Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2:Win32_Process")
result = oWMIService.Create(CCMSetUP & " SMSSITECODE=" & ASSIGNSITECODE & " SMSCACHESIZE=" & CacheSize & " DISABLECACHEOPT=TRUE DISABLESITEOPT=TRUE CCMHTTPPORT=712", Null, Null, intProcessID)
COLLECTMSG "RUN_CCMSetUP","Path | " & CCMSetUP, Null
COLLECTMSG "RUN_CCMSetUP","SMSSITECODE | " & ASSIGNSITECODE, Null
COLLECTMSG "RUN_CCMSetUP","SMSCACHESIZE | " & CacheSize, Null
COLLECTMSG "RUN_CCMSetUP","ProcessID | " & intProcessID, Null
COLLECTMSG "RUN_CCMSetUP","Result | " & result, Null
Set oWMIService = Nothing
If Err <> 0 Then COLLECTMSG "RUN_CCMSetUP", "ERROR", Null : CLIENTSTATE = CLIENTSTATE + 1 : RegCounter "RUN_CCMSetUP",1
On Error GoTo 0
End Sub
![Page 40: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/40.jpg)
' =============================================================================
' HELPERS
' =============================================================================
' =============================================================================
' Method: GetSystemRole
' Description: Checks System role
' =============================================================================
Function GetSystemRole()
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
("Select DomainRole from Win32_ComputerSystem")
For Each objComputer In colComputers
Select Case objComputer.DomainRole
Case 0
strComputerRole = "Standalone Workstation"
Case 1
strComputerRole = "Member Workstation"
Case 2
strComputerRole = "Standalone Server"
Case 3
strComputerRole = "Member Server"
Case 4
strComputerRole = "Backup Domain Controller"
Case 5
![Page 41: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/41.jpg)
strComputerRole = "Primary Domain Controller"
End Select
GetSystemRole=objComputer.DomainRole
Next
End Function
' =============================================================================
' Determines OS by reading reg val & comparing to known values
' OS version number returned as number of type double:
' Windows Vista: 6
' Windows 2k: 5
' Windows XP: 5.1
' Windows Server 2003: 5.2
' Windows x: >5.2
'
' =============================================================================
Sub GetOs()
On Error Resume Next
Err.clear
sOStype = WSHShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions\ProductType")
sOSversion = WSHShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
sOSType = Trim(sOSversion)
If Err <> 0 Then
![Page 42: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/42.jpg)
CLIENTSTATE = CLIENTSTATE + 1
GetOsVersionNumber = "Unknown NTx"
' Could not determine NT version
Exit Sub ' >>>
End If
Select Case sOSversion
Case 6
Os = "Vista"
isOS="workstation"
Exit Sub
Case 5
Os= "2000"
isOS="workstation"
Case 5.1
Os = "XP"
isOS="workstation"
Exit Sub
Case 5.2
Os = "2003"
isOS="server"
WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - Do not run on servers@ " & now
CleanUp(err)
Exit Sub
End Select
If IsOS ="workstation" And sOStype="WinNT" Then IsOS ="workstation" Else IsOS ="server"
If Os= "2000" And sOStype="WinNT" Then IsOS ="workstation" Else IsOS ="server"
On Error GoTo 0
![Page 43: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/43.jpg)
End Sub
' =============================================================================
' Method: StrDateTime
' Description: Converts WMI TIME tokens
' =============================================================================
Function StrDateTime(d)
Dim strDate
Dim strTime
Dim strVal
strVal = CStr(d)
strDate = DateSerial(Left(strVal, 4), _
Mid(strVal, 5, 2), _
Mid(strVal, 7, 2))
strTime = TimeSerial(Mid(strVal, 9, 2), _
Mid(strVal, 11, 2), _
Mid(strVal, 13, 2))
StrDateTime = strDate + strTime
End Function
' =============================================================================
' Method: Set_LogFolder
' Description: Sets the logginf folder path
' =============================================================================
Sub Set_LOGFOLDER()
If LogGood=True Then
![Page 44: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/44.jpg)
GoodLogPath = GoodLogPath
If objFSO.FolderExists(GoodLogPath) Then
Set objFolder = objFSO.GetFolder(GoodLogPath)
Else
Set objFolder = objFSO.CreateFolder(GoodLogPath)
End If
End If
If LogBad=True Then
BadLogPath = BadLogPath
If objFSO.FolderExists(BadLogPath) Then
Set objFolder = objFSO.GetFolder(BadLogPath)
Else
Set objFolder = objFSO.CreateFolder(BadLogPath)
End If
End If
GoodLogPath = GoodLogPath & "\" & StrERRType & computer & ".log"
BadLogPath = BadLogPath & "\" & StrERRType & computer & ".log"
End Sub
' =============================================================================
' Method: COLLECTMSG
' Description: Collections Errors for logging to log file
' =============================================================================
Sub COLLECTMSG(Section,KeyName,value)
On Error Resume Next
![Page 45: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/45.jpg)
Dim f
strmsg=errmsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set f = objFSO.OpenTextFile(strLogFile, ForAppending, True)
strmsg = now & " | " & Section & " | " & KeyName & " | "& value
If Err <> 0 Then
strmsg=strmsg & vbCrLf _
& "Error | " & Hex(Err.Number) & " h (" & CStr(Err.Number) & ") | Description |" & Err.Description
End If
eventlog=eventlog & strmsg & vbCrLf
f.Writeline strmsg
VerboseCHK(strmsg)
f.Close
strmsg=""
Err.Clear
On Error GoTo 0
End Sub
' =============================================================================
' Method: ReadEnvVar
' Description: Read Environment Variables
' =============================================================================
Function ReadEnvVar(envField,envType)
On Error Resume Next
Select Case envType
![Page 46: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/46.jpg)
Case "system"
Set oEnv = WshShell.Environment("System")
Case "user"
Set oEnv = WshShell.Environment("User")
Case "volatile"
Set oEnv = WshShell.Environment("Volatile")
Case "process"
Set oEnv = WshShell.Environment("Process")
End Select
ReadEnvVar = oEnv(envField)
On Error GoTo 0
End Function
' =============================================================================
' Method: WriteEnvVar
' Description: WMI Write Environment Variables
' Depricated - writes to registry
' =============================================================================
Sub WriteEnvVar(envField,envValue,envType,envAddDel)
On Error Resume Next
Select Case envType
Case "system"
Set oEnv = WshShell.Environment("System")
Case "user"
Set oEnv = WshShell.Environment("User")
Case "volatile"
Set oEnv = WshShell.Environment("Volatile")
![Page 47: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/47.jpg)
Case "process"
Set oEnv = WshShell.Environment("Process")
End Select
' add a var
If envAddDel=1 Then oEnv(envField) = envValue
' remove a var
If envAddDel=0 Then oEnv.Remove envField
On Error GoTo 0
End Sub
' =============================================================================
' Method: GetLogEnvironment
' Description: Get Logs Environments
' Depricated - writes to registry
' =============================================================================
Sub GetLogEnvironment()
Dim f
strmsg=errmsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set f = objFSO.OpenTextFile(strLogFile, ForAppending, True)
'// List all vars in all environment types
'//System Type
Set oEnv = WshShell.Environment("System")
For Each sItem In oEnv
![Page 48: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/48.jpg)
strEnvVal = strEnvVal & sItem & vbCrLf
Next
strEnvLog = strEnvLog & "[SystemEnvironment]" & vbCrLf & strEnvVal & vbCrLf
strEnvVal = ""
'//Process Type
Set oEnv = WshShell.Environment("Process")
For Each sItem In oEnv
strEnvVal = strEnvVal & sItem & vbCrLf
Next
strEnvLog = strEnvLog & "[ProcessEnvironment]" & vbCrLf & strEnvVal & vbCrLf
strEnvVal = ""
'//User Type
Set oEnv = WshShell.Environment("User")
For Each sItem In oEnv
strEnvVal = strEnvVal & sItem & vbCrLf
Next
strEnvLog = strEnvLog & "[UserEnvironment]" & vbCrLf & strEnvVal & vbCrLf
strEnvVal = ""
'//Volatile Type
Set oEnv = WshShell.Environment("Volatile")
For Each sItem In oEnv
strEnvVal = strEnvVal & sItem & vbCrLf
Next
strEnvLog= strEnvLog & "[VolatileEnvironment]" & vbCrLf & strEnvVal & vbCrLf
strEnvVal = ""
![Page 49: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/49.jpg)
Set oEnv = Nothing
f.Writeline strEnvLog
f.Close
Err.Clear
End Sub
' =============================================================================
' Method: StartWMIbyADSI
' =============================================================================
Sub StartWMIbyADSI()
On Error Resume Next
COLLECTMSG "StartWMIbyADSI","ADSI","Start the service"
' define a constant for stopped services
' define ADSI status constants
Const ADS_SERVICE_STOPPED = 1
Const ADS_SERVICE_START_PENDING = 2
Const ADS_SERVICE_STOP_PENDING = 3
Const ADS_SERVICE_RUNNING = 4
Const ADS_SERVICE_CONTINUE_PENDING = 5
Const ADS_SERVICE_PAUSE_PENDING = 6
Const ADS_SERVICE_PAUSED = 7
Const ADS_SERVICE_ERROR = 8
' get an ADSI object for a computer
Set objComputer = GetObject("WinNT://" & COMPUTER & ",computer")
' get an object for a service
Set objService = objComputer.GetObject("Service","winmgmt")
![Page 50: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/50.jpg)
' check to see if the service is stopped
If (objService.Status = ADS_SERVICE_STOPPED) Then
' if the service is stopped, then start it
objService.Start
If Err.number<>0 Then 'Exit sub
'Start Failed
RegCounter "StartWMIbyADSI",1
wshshell.run SCEXELocation & " config winmgmt start= auto",0,1
wshshell.run SCEXELocation & " start winmgmt",0,1
CleanUp(err)
End If
While objService.Status <> ADS_SERVICE_RUNNING: Wend
End If
StrERRType=StrERRType & "StartWMIADSI_"
'WriteEnvVar "StartWMIbyADSI","Started","system","1"
If Err <> 0 Then COLLECTMSG "ERROR", "StartWMIbyADSI", Null
On Error GoTo 0
End Sub
' =============================================================================
' Method: StartSeriviceViaSC
' =============================================================================
Sub StartSeriviceViaSC(ServiceName, nMode)
On Error Resume Next
Debug("ServiceName = " & ServiceName)
Debug("nMode = " & nMode)
COLLECTMSG "ERRORS","StartSeriviceViaSC",ServiceName & " Service not running"
![Page 51: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/51.jpg)
COLLECTMSG "INFO","StartSeriviceViaSC","Attempting to start via sc.exe"
errreturn = 0
Debug("Set " & ServiceName & " to " & nMode & " = " & SCEXELocation & " config " & ServiceName & " start= " & LCase(nMode))
errreturn = wshshell.run(SCEXELocation & " config " & ServiceName & " start= " & LCase(nMode),0,1)
Debug("errreturn = " & errreturn)
If errreturn <> 0 Then
Debug("Errored out in " & ServiceName & " during StartSeriviceViaSC")
RegCounter "StartSeriviceViaSC",1
COLLECTMSG "ERRORS","StartSeriviceViaSC","sub was unable to set service " & ServiceName & " to zero"
Exit Sub
End If
Debug(LCase(nMode) & " = auto")
If LCase(nMode) = "auto" Then
errreturn = 0
errreturn = wshshell.run(SCEXELocation & " start " & ServiceName,0,1)
Debug("errreturn = " & errreturn)
If errreturn <> 0 Then
RegCounter "StartSeriviceViaSC",1
Debug("ErrReturn = " & errreturn)
COLLECTMSG "ERRORS","StartSeriviceViaSC","sub was unable to start service" & ServiceName
Exit Sub
Else
Debug("Successfully Started " & ServiceName)
'Debug("Sleeping 500")
'WSHShell.sleep(500)
End If
![Page 52: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/52.jpg)
End If
COLLECTMSG "INFO","StartSeriviceViaSC","Service is set to " & nMode
StrERRType=StrERRType & "StartWMISC_"
'WriteEnvVar "StartSeriviceViaSC","Started","system","1"
If Err <> 0 Then COLLECTMSG "ERROR", "StartSeriviceViaSC", Null
On Error GoTo 0
End Sub
' =============================================================================
' Method: Fix_Service
' Description: Checks the status of a service
' =============================================================================
Sub Fix_Service(nCHK, nService,nMode,nStatus)
On Error Resume Next
'Variable to identify when a service is missing
' Example Bits is not installed
Dim bServiceFound: bServiceFound = False
COLLECTMSG nCHK,">", Null
err.clear
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name = '" & nService &"'")
If Err<>0 Then
COLLECTMSG "Fix_Service","Error execQuery",err & " " & err.description
Debug("Err = " & err & " " & err.description)
If do_StartSeriviceViaSC Then StartSeriviceViaSC nService, nMode
End If
![Page 53: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/53.jpg)
err.clear
For Each objService In colServiceList
'Found a service
'Debug("objService Name = " & objService.name)
'Debug("objService Caption = " & objService.Caption)
bServiceFound = True
'COLLECTMSG nCHK,"Mode | " & objService.StartMode, Null
'COLLECTMSG nCHK,"Status | " & objService.State, Null
'Added this check in for services that mode matters but not status
'If the status is unimportant then ignore the tests below
If nStatus = "unimportant" Then
tempStatus = objService.State
Else
tempStatus = nStatus
End If
'Debug("tempStatus = " & tempStatus)
If LCase(objService.StartMode) <> LCase(nMode) Or LCase(objService.State) <> LCase(tempStatus) Then
'Debug(objService.StartMode & " <> " & nMode)
'Debug(objService.State & " <> " & tempStatus)
CLIENTSTATE = CLIENTSTATE + 1
RegCounter nCHK,1
COLLECTMSG nCHK,"Current StartMode " & objService.StartMode, "Error"
COLLECTMSG nCHK,"Current State " & objService.State, "Error"
COLLECTMSG nCHK,"Changing StartMode to " & nMode, "Error"
err.clear
errReturnCode = 0
![Page 54: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/54.jpg)
If nMode = "auto" Then nMode = "automatic"
errReturnCode = objService.ChangeStartMode(nMode)
If errReturnCode <> 0 Then
'More detail here
' http://msdn.microsoft.com/en-us/library/aa384896(VS.85).aspx
Debug("err = " & err & " " & err.description & " return code = " & errReturnCode)
COLLECTMSG nCHK,"ChangedStartMode",errReturnCode
COLLECTMSG nCHK,"Failed to Change StartMode | " & nMode, "Error"
CLIENTSTATE = CLIENTSTATE + 1
If do_StartSeriviceViaSC Then StartSeriviceViaSC nService, nMode
End If
err.clear
If ((tempStatus = "Running") Or (nStatus = "Manual")) And objService.State <> nStatus Then
CLIENTSTATE = CLIENTSTATE + 1
RegCounter nCHK,1
err.clear
errReturnCode = objService.startservice
If errReturnCode <> 0 Then
Debug("err= " & err & " RC= " & errReturnCode & " " & err.description)
COLLECTMSG nCHK,"Failed to Startservice | " & nMode, "Error"
CLIENTSTATE = CLIENTSTATE + 1
If do_StartSeriviceViaSC Then StartSeriviceViaSC nService, nMode
End If
COLLECTMSG nCHK,"Startservice | "& errReturnCode, "Info"
End If
StrERRType=StrERRType & nService & "_"
![Page 55: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/55.jpg)
End If
Next
If bServiceFound=False Then
COLLECTMSG nCHK,nService &" Found | FALSE", Null : CLIENTSTATE = CLIENTSTATE + 1 : RegCounter nCHK,1
StrERRType=StrERRType & nService & "_"
End If
If Err <> 0 Then COLLECTMSG nCHK, "ERROR", null : CLIENTSTATE = CLIENTSTATE + 1 : RegCounter nCHK,1
On Error GoTo 0
End Sub
' =============================================================================
' Method: RegCounter subprocedure
' Descriptoin: Takes the value from a KeyName and adds in the number
' =============================================================================
Sub RegCounter(KeyName, Number)
If LogRegCounter = True Then
On Error Resume Next
COLLECTMSG "RegCounter",">", KeyName
CurrentKeyName = WSHShell.Regread(RegPath & "\" & KeyName)
Debug("Orginal CurrentKeyName = " & CurrentKeyName)
If LCase(KeyName) <> LCase("WMIStatus") Then Number = CurrentKeyName + Number
Debug("New Number = " & Number)
'Write new value
WSHSHell.RegWrite RegPath & "\" & KeyName, Number, "REG_SZ"
'Write Time Stamp
![Page 56: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/56.jpg)
WSHSHell.RegWrite RegPath & "\" & KeyName & "_TIME", Now(), "REG_SZ"
End If
End Sub
' =============================================================================
' Method: EmailMessage subprocedure
' Descriptoin: Sends an email to designated account
' =============================================================================
Function EmailMessage(Subject, Body)
' Removed due to support issues
End Function
' =============================================================================
' Method: WebSubmit
' Description: WebPage submit to SQL function Version 2... no outside requirements
' =============================================================================
Function WebSubmit(StatusWeb)
Dim strWebAddress, strPost, strRequest
COLLECTMSG "WebSubmit",">", Null
Dim oHTTP, HTTPPost
On Error Resume Next
' Gather Info
'Debug(strWebAddress)
If Len(StrERRType) = 0 Then StrERRType = "None"
strPost = "Cname=" & Computer & "&LogFile=" & strUNCLogFile & "&ErrType=" & StrERRType & "&Status=" & StatusWeb
COLLECTMSG "WebSubmit","Post", strPost
![Page 57: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/57.jpg)
strRequest = strWebAddress & " " & strPost
'Debug(strRequest)
'Submit Info
Set oHTTP = CreateObject("Microsoft.XMLHTTP")
oHTTP.open "POST", strWebAddress, false
oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHTTP.setRequestHeader "Content-Length", Len(strRequest)
oHTTP.send strPost
WebSubmit = oHTTP.responseText
COLLECTMSG "WebSubmit","Sent", Null
'Debug(WebSubmit)
Set oHTTP = Nothing
End Function
' =============================================================================
' Method: ShowFileAccessInfo
' Description: Get Last File Access Info
' =============================================================================
Function ShowFileAccessInfo(filespec)
On Error Resume Next
COLLECTMSG "ShowFileAccessInfo",">", Null
If objFSO.FileExists(filespec) Then
Set f = objFSO.GetFile(filespec)
filespec_date = f.DateLastModified
FSpace = Instr(filespec_date," ") - 1
ShowFileAccessInfo = Left(filespec_date,FSpace)
COLLECTMSG "ShowFileAccessInfo",filespec & " file date", ShowFileAccessInfo
Else
'File is missing
COLLECTMSG "ShowFileAccessInfo","Error - No Log file to check", filespec
![Page 58: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/58.jpg)
End If
On Error GoTo 0
End Function
' =============================================================================
' Method: SCFileExist
' Description: Does a file exist?
' =============================================================================
Sub SCFileExist()
On Error Resume Next
COLLECTMSG "SCFileExist",">", Null
If objFSO.FileExists(strCurrentDir & "\sc.exe") Then
SCEXELocation = strCurrentDir & "\sc.exe"
do_StartSeriviceViaSC = True
COLLECTMSG "SCFileExist",SCEXELocation,do_StartSeriviceViaSC
ElseIf objFSO.FileExists(windir & "\system32\sc.exe") Then
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "SCFileExist",1
SCEXELocation = windir & "\system32\sc.exe"
do_StartSeriviceViaSC = True
COLLECTMSG "SCFileExist",SCEXELocation,do_StartSeriviceViaSC
ElseIf objFSO.FileExists(windir & "\system32\dllcache\sc.exe") Then
CLIENTSTATE = CLIENTSTATE + 1
RegCounter "SCFileExist",1
SCEXELocation = windir & "\system32\dllcache\sc.exe"
do_StartSeriviceViaSC = True
COLLECTMSG "SCFileExist",SCEXELocation,do_StartSeriviceViaSC
Else
CLIENTSTATE = CLIENTSTATE + 1
![Page 59: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/59.jpg)
RegCounter "SCFileExist",1
'SC.exe does not exist, do not run service start
do_StartSeriviceViaSC = False
COLLECTMSG "SCFileExist","Error - No sc.exe", do_StartSeriviceViaSC
End If
On Error GoTo 0
End Sub
' =============================================================================
' Method: CheckLogFileModifyDate
' Description: SMS Logs recently updated
' =============================================================================
Sub CheckLogFileModifyDate(LogToCheck)
On Error Resume Next
COLLECTMSG "CheckLogFileModifyDate",">", Null
strSMSPolEval = windir & "\system32\CCM\Logs\" & LogToCheck
'Debug(strSMSPolEval)
startdate = ShowFileAccessInfo(strSMSPolEval)
'Debug(startdate)
If isDate(startdate) Then
diffdate = DateDiff("d", startdate, date())
Debug(diffdate)
End If
If diffdate > 14 Then
COLLECTMSG "CheckLogFileModifyDate","Error", LogToCheck & " inactive for " & diffdate & " Days"
Debug("File activity > 14 days Should repair client")
smsClient.RepairClient
![Page 60: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/60.jpg)
End If
On Error GoTo 0
End Sub
' =============================================================================
' Method: VerboseCHK
' Description: Debugging, writes to console
' =============================================================================
Sub VerboseCHK(output)
If LogToConsoleVerbose Then wscript.echo output
End Sub
' =============================================================================
' Method: Debug
' Description: Debugging, writes to console
' =============================================================================
Sub Debug(output)
If LogToConsoleDebug Then wscript.echo output
End Sub
Sub CleanUp(ErrorCode)
On Error Resume Next
Debug("********** Centralize Info ***********")
'Used to count number of times this script has run
RegCounter "RunCount", 1
![Page 61: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/61.jpg)
'Submit Status
If ErrorCode <> "doRunCheck" And Do_WebSubmit Then WebSubmit(CLIENTSTATE)
Debug("********** CleanUp Objects ***********")
Set oHTTP = Nothing
Set objEmail = Nothing
Set colServiceList = Nothing
Set colComputers = Nothing
Set fsCCR = Nothing
Set oWMIService = Nothing
Set objComputer = Nothing
Set objService = Nothing
Set objFolder = Nothing
Set ColFiles = Nothing
Set ofile = Nothing
Set objWMIService = Nothing
Set colCLIPropsList = Nothing
Set objWMIServiceCLI = Nothing
Set PureString = Nothing
Set oEnv = Nothing
Set colshares = Nothing
Set oReg = Nothing
Set oClientComponents = Nothing
Set oCPAppletMgr = Nothing
Set oSMSClient = Nothing
Set oCache = Nothing
Set oUIResManager = Nothing
Set objGroup = Nothing
Set objSysInfo = Nothing
![Page 62: Web view' * WMI fixing / integration with WMIDiag.vbs (see microsoft.com) ... 'On Error Resume Next. Dim objWMIService, oWMIService, oServices](https://reader036.vdocuments.mx/reader036/viewer/2022081512/5a774e327f8b9a93088dc081/html5/thumbnails/62.jpg)
Set objNetwork = Nothing
Set WSHShell = Nothing
Set objSysInfo = Nothing
Set objFSO = Nothing
Set oLocator = Nothing
Debug("********** End ***********")
Debug("ErrorCode = " & ErrorCode)
If ErrorCode = "doRunCheck" Then Wscript.Quit
wscript.quit ErrorCode
End Sub
==============
Missed an email? Check out the list archive:
http://myitforum.com/cs2/blogs/smslist/