Once upon a time I wrote a Client Health repair script for Windows XP SMS and SCCM 2007 environments. By far and away the biggest issue was WMI corruption. The point of this script was to fix as much as humanly possible WITHOUT using WMI. No minor feat and you can see one section below here. A major issue that was EASILY remedied was ensuring WMI was in the system path. This was recently pointed out to me that people were charging for simple logic. So here is a nice way to do it for free with a few more frills thrown in for free.
Solution: Fix the WMI in the System Path
The fix below will parse you entire system path and remove any %variable%, remove duplicates, and ensure certain items are in the System path like WMI. I always wanted to add in a check to look for UNC (\\) paths as those always make a system go slower.
The following script will NOT work. Please see the full CLIFIX script
Dim windir: windir = WSHShell.ExpandEnvironmentStrings("%WINDIR%") ' ============================================================================= ' 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 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 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") 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