I found 4.19 on my "archive of everything I ever glanced at"; but not .21

On Fri, Mar 17, 2017 at 3:45 PM, Art Flores <art_flo...@hotmail.com> wrote:

> Greetings and Felicitations!
>
>
>
> I read about this script at the link below.
>
> Public_SMS_CLIFIX_V4.21.vbs.txt
>
>
>
> https://shauncassells.wordpress.com/2017/03/09/sms-
> 2003-client-health-group-policy-initiated-based-script-
> all-those-core-fixes-still-work-great-with-sccm-current-branch-for-free/
>
>
>
> Does anyone have a copy of Public_SMS_CLIFIX_V4.21.vbs.txt they could
> share?
>
>
>
> The author, Shaun Cassells, is also looking for it.
>
>
>
> Thanks,
>
>
>
> Art
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


-- 
Thank you,

Sherry Kissinger

My Parameters:  Standardize. Simplify. Automate
Blogs: http://www.mofmaster.com, http://mnscug.org/blogs/sherry-kissinger,
http://www.smguru.org


Const ScriptVersion = "4.19"
'=============== Info =======================================
' USEAGE: CLIENT HEALTH REPAIR
' Based on source at: Dude Works 
http://wwww.dudeworks.com/Support/SupportForum/tabid/83/mid/475/groupid/6/Default.aspx
' 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
'============================================================
' UPDATES
' 4.19
' Fixed %Temp% not existing
' Fixed error log reporting to be consistant
' Fixed CLIENTSTATE to be less sensetive 
'     (including not caring where sc.exe is found as long as it is found)
' Other random bug fixes
' ToDo
'   Test with ConfigMgr 2007
'============================================================

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_REG_XML
Dim 
do_CHK_AdvClient,do_SEND_CCR,do_RUN_CCMSetUP,do_REBUILD,do_REPAIR,do_CHK_DCOM,do_StartSeriviceViaSC,SCEXELocation
Dim intEventType,strEventDescription
Dim bClientExist
Dim iniResult
Dim sOStype,isOS,OS, sOSversion
Dim strEnvLog, strEnvVal
Dim SMSCLIENTLASTERROR
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_ERROR, "SMS STARTUP SCRIPT - 
WScript.Shell is broken" : CleanUp(err) 'Windows Scripting Host is busted!
WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - Last Run @ " & now

Dim objSysInfo: Set objSysInfo = CreateObject("ADSystemInfo")
If err <> 0 Then WSHShell.LogEvent EVENT_ERROR, "SMS STARTUP SCRIPT - 
ADSystemInfo is broken" : CleanUp(err)

Dim objFSO:             Set objFSO = CreateObject("Scripting.FileSystemObject")
If err <> 0 Then WSHShell.LogEvent EVENT_ERROR, "SMS STARTUP SCRIPT - 
Scripting.FileSystemObject is broken" : CleanUp(err)

Dim oLocator:   Set oLocator = CreateObject("WbemScripting.SWbemLocator")
If err <> 0 Then WSHShell.LogEvent EVENT_ERROR, "SMS STARTUP SCRIPT - 
WbemScripting.SWbemLocator is broken" : CleanUp(err)

'       Dim objNetwork: Set objNetwork = WScript.CreateObject("WScript.Network")


'=============== GET ENVIRONMENT and LOGGING DETAILS ==============

'Set Current Directory
wshshell.CurrentDirectory = WScript.ScriptFullName & "\.."
Dim strCurrentDir:      strCurrentDir = wshSHELL.CurrentDirectory

Dim Computer:           Computer = 
WSHShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
If Computer = "%COMPUTERNAME%" Then WSHShell.LogEvent EVENT_ERROR, "SMS STARTUP 
SCRIPT - COMPUTERNAME value is empty" : CleanUp(err)
Dim windir:                             windir = 
WSHShell.ExpandEnvironmentStrings("%WINDIR%")
If windir = "%WINDIR%" Then WSHShell.LogEvent EVENT_ERROR, "SMS STARTUP SCRIPT 
- WINDIR value is empty" : CleanUp(err)
Dim SysDrive:                           SysDrive = 
WSHShell.ExpandEnvironmentStrings("%SystemDrive%")
If SysDrive = "%SystemDrive%" Then WSHShell.LogEvent EVENT_ERROR, "SMS STARTUP 
SCRIPT - SysDrive value is empty" : CleanUp(err)
Dim UserTempPath:       UserTempPath = 
WSHShell.ExpandEnvironmentStrings("%TEMP%")
If err <> 0 Then WSHShell.LogEvent EVENT_ERROR, "SMS STARTUP SCRIPT - 
ExpandEnvironmentStrings is broken" : CleanUp(err)
        
'Set Logfile location
StrERRType = ""
strFileName = "sms_chk_" & computer & ".log"

'Issue with this variable
'Some machines do not have a %temp% defined.
'Default seems to be %windir%\temp.  However some machines have c:\temp.  
Oppurtunity to classify.  I just go with the flow.
'If a machine does not have a %temp% defined then I write an ERROR and set path 
to %windir%\temp
'Check if Directory exists

If objFSO.FolderExists(UserTempPath) Then
        'Check to see if last char is a \.  if so remove it.
        If Right(UserTempPath,1) = "\" Then 
                UserTempPath = Left(UserTempPath,Len(UserTempPath) - 1)
        End If
        strLogFile = UserTempPath & "\" & strFileName
        If InStr(UserTempPath,windir) Then
                strDirectory = "\Admin$" & 
Right(UserTempPath,Len(UserTempPath)- Len(windir))
        Else 
                strDirectory = "\C$" & Right(UserTempPath,Len(UserTempPath)- 
Len(SysDrive))
        End If
        
        strUNCLogFile = "\\" & Computer & strDirectory & "\" & strFileName
Else
'Houston we have a problem
        WSHShell.LogEvent EVENT_ERROR, "SMS STARTUP SCRIPT - TEMP value is 
empty"
        UserTempPath = windir & "\temp"
        strLogFile = UserTempPath & "\" & strFileName
        'Ran into machines without the %windir%\temp directory for system 
account
        'lenWinDir = Len(windir)
        'strUNCLogFile = "\\" & Computer & "\admin$" & 
Right(UserTempPath,Len(UserTempPath)- lenWinDir) & "\" & strFileName
        '****Fixed write to %windir%\temp directory
        strUNCLogFile = "\\" & Computer & "\admin$\Temp\" & strFileName
End If

'Check to see what state of client is in
'Errors are incremented
CLIENTSTATE=0

' ==========CONFIG SETTINGS=========================================
'/// Check System role, If role =0 or 1 Then WKS, 2 3 4 & 5 are Server roles
SMSVersion="2.50.4160.2000"
ConfigMgrVersion="4.0.6221.1000" 'SP1
CompanyName="<CompanyName>"
bClientExist = False

'AUTO because AD is extended with servers published
WKS_ASSIGNSITECODE = "AUTO"
WKS_CacheSize = 3500                            'Plenty large enough for 
service packs
WKS_PortNumber = 712                            'We use a non 80 port number so 
the network monitors wont give false positives.
WKS_LocalAdminGroup = "Administrators"          'SpecIfy Local Admin group to 
add SMS Admin Acount to (DEFAULT=Administrators)
WKS_admACCT = "Domain\Group"    'SpecIfy SMS Admin account (group)
'//Registry for counts
RegPath = "HKLM\SYSTEM\Setup\ClientHealthStartup"
'// CCR's
StrCCRServer = "<SITESERVER>"                   'SpecIfy Site server to send 
CCR's to
strCCRSiteCode = "<sc>"
' ===================================================================
' ==========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)
LogToConsoleDebug=False                 'Wscript.echo for debugging 
(DEFAULT=False)     
LogEnvironment=True                             'Log environment, will aid in 
troubleshooting client, includes: system,user,process, volatile
Do_WebSubmit = False 'Submits to a website for centralized reporting

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

LogGood=False           'Renames the front of the file to represent a good file 
prefix
LogBad=False                    'Add prefix for type of ERROR
'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 ="\\<FQDN>\SMSCLIENTLOGS\GPO\Good"  'SpecIfy Site server to send 
good/success logs  (DEFAULT)
BadLogPath ="\\<FQDN>\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.
' ===================================================================
' ==========SMS Install SETTINGS=====================================
' ===================================================================
'//CCMSetUP LOCATION
CCMSetUP = "\\<FQDN>\SMSClient\i386\ccmSetup.exe"       'Path to CCMSetup.exe
CCM_DIR = windir & "\system32\CCM\"
' ===================================================================
' ==========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
                                                '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.
' ===================================================================
' ==========WMI SETTINGS=============================================
' ===================================================================
'// enable True / False tasks you wish to run
do_CHK_CheckLogFileModifyDate = True 'Check to see if log file is updating 
recently
do_CHK_CCMEXEC = True                                   ' CHK_CCMEXEC  should 
ALWAYS RUN - LEAVE at TRUE
do_CHK_AdvClient = True                         ' Checks Advanced client state
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
'Requires that Domain\Domain Computers account have access to share to run the 
setup file.  Must be explicitly set on server share

' 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

'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_REG_XML = False                                      ' Registers XML
do_REG_BITS = False                             ' Registers two Bits files - if 
True service will be reset too
do_REG_OLEAut32 = False         ' Registers OLEAut32
do_REG_Msiexec = False                  ' Registers msiexec /regserver


Debug("********** Start ***********")
'===================================================================
'===================================================================
'=================== 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
        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_WARNING, "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

'Creates new log file
err.clear
Set oFile = objFSO.CreateTextFile(strLogFile)
If err <> 0 Then WSHShell.LogEvent EVENT_ERROR, "SMS STARTUP SCRIPT - Unable to 
create log file: " & strLogFile : CleanUp(err)
oFile.Close
err.clear


'Grab OS version
GetOs

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
        PortNumber = WKS_PortNumber
Else
        'Disabled as this will not run on servers
        COLLECTMSG "isOS","ERROR","Non workstation computer type"
        WSHShell.LogEvent EVENT_FAILURE, "SMS STARTUP SCRIPT - Ran less than " 
& iHoursBetweenRun & " hours ago " & Now
        CleanUp(err)
End If


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
'Disabled because this check uses WMI.  Also this script is designed to only 
run on workstations
'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.     

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 do_CHK_LOCALADMIN = True Then CHK_SMSLOCALADMIN
        
Debug("********** Check WMI Service Mode ***********")  
COLLECTMSG "WMI Service",">",null
'Check to see if Service is disabled
WMIRegValue = 
wshshell.regread("HKLM\SYSTEM\CurrentControlSet\Services\winmgmt\Start")
Select Case WMIRegValue
        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
                'Make service set to Automatic
                COLLECTMSG "WMI","WARNING","Service in Reg is set to Manual"
                Debug("WMI is set to Manual")
                Debug("do_StartSeriviceViaSC = " & do_StartSeriviceViaSC)
                If do_StartSeriviceViaSC Then StartSeriviceViaSC 
"winmgmt","auto"
                StrERRType=StrERRType & "WMIManual_"
                RegCounter "WMI",1
                CLIENTSTATE = CLIENTSTATE + 1
        Case 4
                'Attempts to use sc.exe to start the service
                COLLECTMSG "WMI","WARNING","Service in Reg is set to Disabled"
                Debug("WMI Service is not set to AUTO")
                Debug("do_StartSeriviceViaSC = " & do_StartSeriviceViaSC)
                If do_StartSeriviceViaSC Then StartSeriviceViaSC 
"winmgmt","auto"
                StrERRType=StrERRType & "WMIDisabled_"
                RegCounter "WMI",1
                CLIENTSTATE = CLIENTSTATE + 1
        Case Else
                'UNKNOWN Service State
                COLLECTMSG "WMI","ERROR","Service in Reg is set to " & 
WMIRegValue & " Unknown value"
                Debug("WMI Service is not set to " & WMIRegValue & " Unkown")
                Debug("do_StartSeriviceViaSC = " & do_StartSeriviceViaSC)
                If do_StartSeriviceViaSC Then StartSeriviceViaSC 
"winmgmt","auto"
                StrERRType=StrERRType & "WMIUnknown_"
                RegCounter "WMI",1
                CLIENTSTATE = CLIENTSTATE + 1
End Select

' =============================================================================
'CHECK If WMI IS ACCESSIBLE and CONNECT
' =============================================================================
Debug("********** Check WMI Connection ***********")
On ERROR Resume Next
err.clear
Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
If Err <> 0 Then
        COLLECTMSG "WMI_CONNECT","ERROR",err & " " & err.description
        Debug("********** WMI Connection FAIL ***********")
        RegCounter "WMI",1
        StrERRType=StrERRType & "WMIConnect_"
        '//CANNOT CONNECT TO WMI
        Debug("Registry WMIStatus = " & WSHShell.Regread(RegPath & 
"\WMIStatus"))
        Select Case WSHShell.Regread(RegPath & "\WMIStatus")
                Case ""
                        Debug("WMIStatus = no prior break") 
                        RegCounter "WMIFail",1
                        CLIENTSTATE = CLIENTSTATE + 50
                        If do_REPAIR = True Then 
                                REPAIR_WMI_XP : RegCounter 
"WMIStatus","REPAIRED"
                                COLLECTMSG "WMI Repair","Waring","Doing the 
first repair on WMI"
                                StrERRType=StrERRType & "WMIRepair_"
                        End If
                Case "REPAIRED" 
                        Debug("WMIStatus = REPAIRED")
                        RegCounter "WMIFail",1
                        CLIENTSTATE = CLIENTSTATE + 100
                        If do_REBUILD = True Then 
                                REBUILD_WMI_BRUTE_FORCE : RegCounter 
"WMIStatus","REPAIRED"
                                COLLECTMSG "WMI BRUTE FORCE","ERROR","This 
machine has gone through Repair - still failing"
                                StrERRType=StrERRType & "WMIRebuild_"
                        End If
                Case "REBUILT"
                        Debug("WMIStatus = REBUILT")
                        RegCounter "WMIFail",1
                        CLIENTSTATE = CLIENTSTATE + 1000
                        StrERRType=StrERRType & "WMIFAIL_"
                        COLLECTMSG "WMI REBUILT","ERROR","This machine has gone 
through Repair and Rebuild - still failing"
        End Select

        err.clear
        WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - WMI " & 
WSHShell.Regread(RegPath & "\WMIStatus") & " " & Now
        Debug("ClientState = " & CLIENTSTATE)
        
        CleanUp(err)
End If

'***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_REG_XML = True Then REG_XML
If do_REG_BITS = True Then REG_SVR32 "REG_BITS", "Qmgr.dll"  : REG_SVR32 
"REG_BITS", "qmgrprxy.dll"
If do_REG_OLEAut32 = True Then REG_SVR32 "REG_OLEAut32", "OLEaut32.dll"
If do_REG_Msiexec = True Then REG_Msiexec
        
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","NotDisabled","unimportant"
If do_CHK_WUS_SERVICE = True Then Fix_Service 
"CHK_WUS_SERVICE","wuauserv","auto","Running"
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 bClientExist = 
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")
        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

        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 bClientExist = False Then
                If do_SEND_CCR = True Then SEND_CCR
                If do_RUN_CCMSetUP = True Then RUN_CCMSetUP
        End If

        If LogEnvironment = True Then
                GetLogEnvironment
        End If

        'Added now to Next line - not sure If that works with Event_Warning
        If logToEventsSummary=True Then WSHShell.LogEvent EVENT_WARNING, Now & 
vbCRLF & eventlog & vbCrLf & strEnvLog
        
End If

'Clean up
CleanUp(err)























'***********************************************************************************************
'***********************************************************************************************
'*************  Start SMS Client SECTION
'***********************************************************************************************
'***********************************************************************************************

' =============================================================================
' Method:       CHK_SMSVERSION
' Description:  checks ccmexec file version, If no match latest version
'                               reinstall latest client
' =============================================================================

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 & "SMSVERSION_"
                COLLECTMSG "CHK_SMSVERSION","ERROR","Cannot connect to 
\ROOT\CCM client may not exist"
                bClientExist = False
                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)
                bClientExist = True
        Next
        
End Sub

' =============================================================================
' Method:       CHK_SMSUPDATECLIENT
' Description:  checks SMS Client Version
' =============================================================================
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"
                If Do_RUN_CCMSetUP Then RUN_CCMSetUP
                ElseIf do_SEND_CCR = True Then SEND_CCR
                End If
                COLLECTMSG "CHK_SMSVERSION","UPDATE_SMSCLIENT","Completed"
        End If

End Sub


' =============================================================================
' Method:       CHK_AdvClient
' Description:  Checks CHK_AdvClient components
' =============================================================================
Sub CHK_ADVCLIENT()
        On ERROR Resume Next
        COLLECTMSG "CHK_ADVCLIENT",">", Null
  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 & "CPAppletMgr_"
                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 & "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
        
                COLLECTMSG "CHK_ADVCLIENT",DisplayName,cmsg
        Next

  Set oClientComponents = Nothing
  Set oCPAppletMgr = Nothing

  If Err <> 0 Then COLLECTMSG "CHK_ADVCLIENT", "ERROR", Null
        
End Sub


' =============================================================================
' Method:       CHK_ASSIGNMENT
' Description:  Checks Client Site Assignment
' =============================================================================
Sub CHK_ASSIGNMENT
        On ERROR Resume Next
                Err.clear
        COLLECTMSG "CHK_ASSIGNMENT",">",NULL
        Dim oSMSClient
        Set oSMSClient = CreateObject ("Microsoft.SMS.Client")
        If err.Number<>0 Then
                COLLECTMSG "CHK_ASSIGNMENT","ERROR", 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("CRV")
                        'have the client determine from AD or SLP appropraite 
site code
                        oSMSClient.ReAssignSite
                        COLLECTMSG "CHK_ASSIGNMENT", "Error - Client not 
installed correctly - Setting AUTO", Null
        StrERRType=StrERRType & "ASSIGNMENT_"
    Else
        COLLECTMSG "CHK_ASSIGNMENT",">", "Assigned Site = " & 
oSMSClient.GetAssignedSite
                End If
        End If
        Set oSMSClient=Nothing
        
End Sub


' =============================================================================
' Method:       CHK_CACHESIZE
' Description:  Checks Client Cache Size
' =============================================================================
Sub CHK_CACHESIZE
        On ERROR Resume Next
        COLLECTMSG "CHK_CACHESIZE",">",NULL
        Set oUIResManager = createobject("UIResource.UIResourceMgr")
        If oUIResManager Is Nothing Then
                CLIENTSTATE = CLIENTSTATE + 1
                RegCounter "CHK_CACHESIZE",1
                COLLECTMSG "CHK_CACHESIZE","ERROR", Err.description
          COLLECTMSG "CHK_CACHESIZE","ERROR","Could not create Resource Manager 
- Quitting"
          StrERRType=StrERRType & "UIResourceMgr_"
          Exit Sub
        End If

        Set oCache=oUIResManager.GetCacheInfo()

        If oCache Is Nothing Then
          Set oUIResManager=Nothing
          CLIENTSTATE = CLIENTSTATE + 1
                RegCounter "CHK_CACHESIZE",1
          COLLECTMSG "CHK_CACHESIZE","ERROR","Could not get cache info - 
Quitting"
          StrERRType=StrERRType & "CACHESIZE_"
          Exit Sub
        End If

        oCache.TotalSize=CacheSize
        COLLECTMSG "CHK_CACHESIZE","CACHE SIZE", CacheSize

        If Err <> 0 Then COLLECTMSG "CHK_CACHESIZE", "ERROR", Null
        
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
    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=" & PortNumber , 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 : StrERRType=StrERRType & 
"RUN_CCMSetUP_"
        
End Sub

'***********************************************************************************************
'***********************************************************************************************
'*************  End SMS Client SECTION
'***********************************************************************************************
'***********************************************************************************************
'*************  Start WMI SECTION
'***********************************************************************************************
'***********************************************************************************************

' =============================================================================
' Method:       REPAIR_WMI_XP
' =============================================================================
Sub REPAIR_WMI_XP()
        On ERROR Resume Next
        COLLECTMSG "REPAIR_WMI_XP",">", Null
        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"

        If Err <> 0 Then COLLECTMSG "REPAIR_WMI_XP","ERROR", Null
        
End Sub

' =============================================================================
' Method:       REBUILD_WMI_BRUTE_FORCE
' Description:  Rebuilds WMI repository
' =============================================================================
Sub REBUILD_WMI_BRUTE_FORCE()
        On ERROR Resume Next
        COLLECTMSG "REBUILD_WMI_BRUTE_FORCE",">", Null  
        REPAIR_WMI_REGISTER
        
        StrERRType=StrERRType & "BruteWMI_"
        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 (6 lines lower)
        'wshshell.run "net start winmgmt",0,1
        If do_StartSeriviceViaSC Then StartSeriviceViaSC "winmgmt","auto"

        REPAIR_WMI_MOF
        REPAIR_SMS_MOF
        
        StrERRType=StrERRType & "RebuildWMI_"
        COLLECTMSG "REBUILD_WMI_BRUTE_FORCE","Finished", Null

        'WriteEnvVar "SMSCLIENT_CHK_WMI_LAST","REBUILT","system","1"

        If Err <> 0 Then COLLECTMSG "REBUILD_WMI_BRUTE_FORCE","ERROR", 
Err.Description
        
End Sub


' =============================================================================
' 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
        Next

        COLLECTMSG "REGISTER_WMI","Finished", Null
        If Err <> 0 Then COLLECTMSG "REGISTER_WMI", "ERROR", Null : 
StrERRType=StrERRType & "REGISTER_WMI_"
        
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

        COLLECTMSG "REPAIR_WMI_MOF","Finished", Null
        If Err <> 0 Then COLLECTMSG "REPAIR_WMI_MOF", "ERROR", Null : 
StrERRType=StrERRType & "REPAIR_WMI_MOF_"
        
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 : 
StrERRType=StrERRType & "REPAIR_SMS_MOF_"
        
End Sub

'***********************************************************************************************
'***********************************************************************************************
'*************  END WMI SECTION
'***********************************************************************************************
'***********************************************************************************************


' =============================================================================
' Method:       REG_XML
' Description:  Re-Registers XML DLL
' =============================================================================
Sub REG_XML()
        On ERROR Resume Next
        COLLECTMSG "REG_XML",">"        , Null
        '// Register XML
        XMLREG = windir & "\system32\regsvr32.exe /s " & windir & 
"\system32\msxml3.dll"
        COLLECTMSG "REG_XML","CMD | " & XMLREG, Null

        Set oWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" & Computer & 
"\root\cimv2:Win32_Process")
        result = oWMIService.Create(XMLREG, Null, Null, intProcessID)
        If Err <> 0 Then COLLECTMSG "REG_XML", "ERROR", Null : CLIENTSTATE = 
CLIENTSTATE + 1 : RegCounter "REG_XML",1 : StrERRType=StrERRType & "REGXML_"
        COLLECTMSG "REG_XML","ProcessID | " & intProcessID, Null
        COLLECTMSG "REG_XML","Result | " & result, Null
        
End Sub

' =============================================================================
' Method:       REG_Msiexec
' Description:  Re-Registers msiexec
' =============================================================================
Sub REG_Msiexec()
        On ERROR Resume Next
        COLLECTMSG "REG_Msiexec",">"    , Null
        '// Register XML
        XMLREG = windir & "\system32\msiexec.exe /regserver"
        COLLECTMSG "REG_Msiexec","CMD | " & XMLREG, Null

        Set oWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" & Computer & 
"\root\cimv2:Win32_Process")
        result = oWMIService.Create(XMLREG, Null, Null, intProcessID)
        If Err <> 0 Then COLLECTMSG "REG_Msiexec", "ERROR", Null : CLIENTSTATE 
= CLIENTSTATE + 1 : RegCounter "REG_Msiexec",1 : StrERRType=StrERRType & 
"REGMsiexec_"
        COLLECTMSG "REG_Msiexec","ProcessID | " & intProcessID, Null
        COLLECTMSG "REG_Msiexec","Result | " & result, Null
        
End Sub

' =============================================================================
' Method:       REG_SVR32
' Description:  Re-Registers DLLs
' =============================================================================
Sub REG_SVR32(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

        Set oWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" & Computer & 
"\root\cimv2:Win32_Process")
        result = oWMIService.Create(REGsvr, Null, Null, intProcessID)
        If Err <> 0 Then COLLECTMSG nCHK, "ERROR", Null : CLIENTSTATE = 
CLIENTSTATE + 1 : RegCounter nCHK,1 : StrERRType=StrERRType & "RegServ32_"
        COLLECTMSG nCHK,"ProcessID | " & intProcessID, Null
        COLLECTMSG nCHK,"Result | " & result, Null
        
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 Y"
                wshshell.RegWrite 
"HKLM\SOFTWARE\Microsoft\Ole\EnableDCOM","Y","REG_SZ"
                CLIENTSTATE = CLIENTSTATE + 1
                RegCounter "CHK_DCOM",1
                StrERRType=StrERRType & "DCOME_"
        End If
        If wshshell.regRead("HKLM\SOFTWARE\Microsoft\Ole\EnableRemoteConnect") 
<> "Y" Then
                COLLECTMSG "CHK_DCOM", "ERROR", "EnableRemoteConnect | write 
reg Y"
                wshshell.RegWrite 
"HKLM\SOFTWARE\Microsoft\Ole\EnableRemoteConnect","Y","REG_SZ"
                CLIENTSTATE = CLIENTSTATE + 1
                RegCounter "CHK_DCOM",1
                StrERRType=StrERRType & "DCOMERC_"
        End If
        If 
wshshell.regRead("HKLM\SOFTWARE\Microsoft\Ole\LegacyAuthenticationLevel") <> 
"2" Then
                COLLECTMSG "CHK_DCOM", "ERROR", "LegacyAuthenticationLevel | 
write reg 2"
                wshshell.RegWrite 
"HKLM\SOFTWARE\Microsoft\Ole\LegacyAuthenticationLevel","0x00000002","REG_DWORD"
                CLIENTSTATE = CLIENTSTATE + 1
                RegCounter "CHK_DCOM",1
                StrERRType=StrERRType & "DCOMLAL_"
        End If
        If 
wshshell.regRead("HKLM\SOFTWARE\Microsoft\Ole\LegacyImpersonationLevel") <> "2" 
Then
                COLLECTMSG "CHK_DCOM", "ERROR", "LegacyImpersonationLevel | 
write reg 2"
                wshshell.RegWrite 
"HKLM\SOFTWARE\Microsoft\Ole\LegacyImpersonationLevel","0x00000002","REG_DWORD"
                CLIENTSTATE = CLIENTSTATE + 1
                RegCounter "CHK_DCOM",1
                StrERRType=StrERRType & "DCOMLIL_"
        End If
        'Orginal Code
        'wshshell.run ("REG ADD HKLM\SOFTWARE\Microsoft\Ole /v EnableDCOM /t 
REG_SZ /d Y /f",0,1)
        'wshshell.run ("REG ADD HKLM\SOFTWARE\Microsoft\Ole /v 
EnableRemoteConnect  /t REG_SZ /d Y /f",0,1)
        'wshshell.run ("REG ADD HKLM\SOFTWARE\Microsoft\Ole /v 
LegacyAuthenticationLevel /t REG_DWORD /d 0x00000002 /f",0,1)
        'wshshell.run ("REG ADD HKLM\SOFTWARE\Microsoft\Ole /v 
LegacyImpersonationLevel /t REG_DWORD /d 0x00000002 /f",0,1)
End Sub



' =============================================================================
' Method:       Fix_Service
' Description:  Checks the status of a service
' =============================================================================
Function 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 nMode = "NotDisabled" Then nMode = "Manual"
                If do_StartSeriviceViaSC Then StartSeriviceViaSC nService, nMode
        End If          
        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)
                
                'Added this check in for services that mode doesn't matter as 
long as it is not disabled
                'Example being BITS
                Debug("nMode = " & nMode)
                If nMode = "NotDisabled" Then
                        If objService.StartMode <> "disabled" Then
                                tempMode = objService.StartMode
                                'Debug("1 tempMode = " & tempMode)
                        Else
                                'Service is set to disabled.  Change to manual 
to allow it to start
                                tempMode = "Manual"
                                'Debug("2 tempMode = " & tempMode)
                        End If
                Else
                        'Service is setting to some value
                        tempMode = nMode
                        'Debug("3 tempMode = " & tempMode)
                End If
                
                If LCase(objService.StartMode) <> LCase(tempMode) Or 
LCase(objService.State) <> LCase(tempStatus) Then
                        'Debug(objService.StartMode & " <> " & nMode)
                        'Debug(objService.State & " <> " & tempStatus)
                        CLIENTSTATE = CLIENTSTATE + 1
                        RegCounter nCHK,1
                        
                        COLLECTMSG nCHK, "ERROR","Current StartMode " & 
objService.StartMode
                        COLLECTMSG nCHK, "ERROR","Current State " & 
objService.State
                        COLLECTMSG nCHK, "ERROR","Changing StartMode to " & 
tempMode
                        err.clear
                        errReturnCode = 0
                        If tempMode = "auto" Then tempMode = "automatic"
                        errReturnCode = objService.ChangeStartMode(tempMode)
                        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, "ERROR","Failed to Change 
StartMode | " & tempMode 
                                CLIENTSTATE = CLIENTSTATE + 1
                                If do_StartSeriviceViaSC Then 
StartSeriviceViaSC nService, tempMode
                        End If
                        err.clear
                        If (tempStatus = "Running") 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, "ERROR","Failed to 
Startservice | " & tempMode
                                        CLIENTSTATE = CLIENTSTATE + 1
                                        If do_StartSeriviceViaSC Then 
StartSeriviceViaSC nService, tempMode
                                End If
                                COLLECTMSG nCHK, "Info","Startservice | "& 
errReturnCode
                        End If
                        StrERRType=StrERRType & nService & "_"
                End If
        Next

        If bServiceFound=False Then
                COLLECTMSG nCHK,"ERROR", nService & " | Found | FALSE" : 
CLIENTSTATE = CLIENTSTATE + 1 : RegCounter nCHK,1
                StrERRType=StrERRType & "NO" & nService & "_"
        End If
        Fix_Service = bServiceFound
        If Err <> 0 Then COLLECTMSG nCHK, "ERROR", null : CLIENTSTATE = 
CLIENTSTATE + 1 : RegCounter nCHK,1
        
End Function

' =============================================================================
' 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
                End If
    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

' =============================================================================
' 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
                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", Err & Err.Description
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 & "ADMSHARE_"
                COLLECTMSG "CHK_ADMSHARE","FOUND",admShareFound
                Set oReg = 
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
                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










' =============================================================================
'        HELPERS
' =============================================================================

' =============================================================================
' Method:       GetSystemRole
' Description:  Checks System role
' Disabled as this check requires WMI and reporting of this info is before WMI 
check
' =============================================================================
Function GetSystemRole()
        On ERROR Resume Next
        COLLECTMSG "GetSystemRole",">", Null
        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
                                strComputerRole = "Primary Domain Controller"

                End Select
                GetSystemRole=objComputer.DomainRole
                COLLECTMSG "GetSystemRole","System Role", GetSystemRole
        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
        COLLECTMSG "GetOs",">", Null
        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
                CLIENTSTATE = CLIENTSTATE + 1
                GetOsVersionNumber = "Unknown NTx"
                ' Could not determine NT version
                Exit Sub ' >>>
        End If

        Select Case sOSversion
                Case 6.1
                        Os = "Windows 7"
                        isOS="workstation"
                        Exit Sub
                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
                        COLLECTMSG "GetOs","ERROR", "Server OS Quiting"
                        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"
        
End Sub


' =============================================================================
' Method:       StrDateTime
' Description:  Converts WMI TIME tokens
' Not USED
' =============================================================================
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()
On ERROR Resume Next
        If LogGood=True And ClientState=0 Then
                LogPath = GoodLogPath
                If objFSO.FolderExists(GoodLogPath) Then
                Set objFolder = objFSO.GetFolder(LogPath)
                Else
                        Set objFolder = objFSO.CreateFolder(LogPath)
                End If
                LogPath = GoodLogPath & "\" & StrERRType &  computer & ".log"
                COLLECTMSG "Set_LOGFOLDER","ClientState = " & 
ClientState,"LogPath = " & LogPath
                Err.clear
                objFSO.CopyFile strLogFile , LogPath , OverwriteExisting
                If Err<>0 Then COLLECTMSG "Set_LOGFOLDER","ERROR","Write Log 
Folder File " & err & " " & err.description
        ElseIf LogBad=True And ClientState<>0 Then
                LogPath = BadLogPath
                If objFSO.FolderExists(BadLogPath) Then
                Set objFolder = objFSO.GetFolder(LogPath)
                Else
                        Set objFolder = objFSO.CreateFolder(LogPath)
                End If
                LogPath = BadLogPath & "\" & StrERRType &  computer & ".log"
                COLLECTMSG "Set_LOGFOLDER","ClientState = " & 
ClientState,"LogPath = " & LogPath
                Err.clear
                objFSO.CopyFile strLogFile , LogPath , OverwriteExisting
                If Err<>0 Then COLLECTMSG "Set_LOGFOLDER","ERROR","Write Log 
Folder File " & err & " " & err.description
        Else
                COLLECTMSG "Set_LOGFOLDER","No Criteria Matched for Log 
Forwarding","ClientState = " & ClientState & " LogGood = " & LogGood & " LogBad 
= " & LogBad
        End If
End Sub



' =============================================================================
' Method:       COLLECTMSG
' Description:  Collections Errors for logging to log file
' =============================================================================
Sub COLLECTMSG(Section,KeyName,value)
        On ERROR Resume Next
        Dim f
        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 COLLECTMSG | " & 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
        
End Sub

' =============================================================================
' Method:       ReadEnvVar
' Description:  Read Environment Variables
' =============================================================================
Function ReadEnvVar(envField,envType)
        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")
                Case "process"
                        Set oEnv = WshShell.Environment("Process")
        End Select

        ReadEnvVar = oEnv(envField)
        
End Function

' =============================================================================
' Method:       WriteEnvVar
' Description:  WMI Write Environment Variables
' =============================================================================
Sub WriteEnvVar(envField,envValue,envType,envAddDel)
        'Example Call
        'WriteEnvVar "StartWMIbyADSI","Started","system","1"
        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")
                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
        
End Sub




' =============================================================================
' Method:       GetLogEnvironment
' Description:  Get Logs Environments
' =============================================================================
Sub GetLogEnvironment()
        Dim f
        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
                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 = ""

        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")
        ' 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 "StartWMIbyADSI","ERROR",Err & " " & 
Err.Description
        
End Sub

' =============================================================================
' Method:       StartSeriviceViaSC
' =============================================================================
Sub StartSeriviceViaSC(ServiceName, nMode)
        On ERROR Resume Next
        Debug("ServiceName = " & ServiceName)
        Debug("nMode = " & nMode)
        COLLECTMSG "StartSeriviceViaSC","ERROR",ServiceName & " Service not 
running"
        COLLECTMSG "StartSeriviceViaSC","INFO","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 "StartSeriviceViaSC","ERROR","sub was unable to set 
service " & ServiceName & " to zero"
                StrERRType=StrERRType & "Start" & ServiceName & "SC_"
                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 "StartSeriviceViaSC","ERROR","sub was unable 
to start service" & ServiceName
                        StrERRType=StrERRType & "Start" & ServiceName & "SC_"
                        Exit Sub
                Else
                        Debug("Successfully Started " & ServiceName)
                        'Debug("Sleeping 500")
                        'WSHShell.sleep(500)
                End If
        End If
        COLLECTMSG "StartSeriviceViaSC","INFO","Service is set to " & nMode
        
        
        'WriteEnvVar "StartSeriviceViaSC","Started","system","1"

        If Err <> 0 Then COLLECTMSG "StartSeriviceViaSC","ERROR", Err & " " & 
Err.Description : StrERRType=StrERRType & "Start" & ServiceName & "SC_"
        
End Sub


' =============================================================================
' Method: RegCounter subprocedure
' Descriptoin: Takes the value from a KeyName and adds in the number
' =============================================================================
Sub RegCounter(KeyName, Number)
        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
        WSHSHell.RegWrite RegPath & "\" & KeyName & "_TIME", Now(), "REG_SZ"
End Sub


' =============================================================================
' 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
  strWebAddress = "http://<FQDN>/clienthealth/default.asp"
  'Debug(strWebAddress)
  If Len(StrERRType) = 0 Then StrERRType = "None"
  strPost = "Cname=" & Computer & "&LogFile=" & strUNCLogFile & "&ErrType=" & 
StrERRType & "&Status=" & StatusWeb 
  COLLECTMSG "WebSubmit","Post", strPost
  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
  End If
  
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 
                'Disabled due to user requests
                '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 
                'Disabled due to user requests
                'CLIENTSTATE = CLIENTSTATE + 1
                'RegCounter "SCFileExist",1
                SCEXELocation = windir & "\system32\dllcache\sc.exe"
        do_StartSeriviceViaSC = True
        COLLECTMSG "SCFileExist",SCEXELocation,do_StartSeriviceViaSC      
  Else
        'Only ERROR
        CLIENTSTATE = CLIENTSTATE + 1
                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
  
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")
                                Dim oSMSClient
                                        Set oSMSClient = CreateObject 
("Microsoft.SMS.Client")
                                        If err.Number<>0 Then
                                                COLLECTMSG 
"CheckLogFileModifyDate","ERROR", Err & " " & Err.description
                                                COLLECTMSG 
"CheckLogFileModifyDate","Could not create SMS Client Object - Quitting", Null
                                        Else
                                            oSMSClient.RepairClient
                                            COLLECTMSG 
"CheckLogFileModifyDate","RepairClient",Null
                                        End If
  End If
  
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
        'Submit Status
        If ErrorCode <> "doRunCheck" Then
                If LogGood Or LogBad Then Set_LOGFOLDER
                If Do_WebSubmit Then WebSubmit(CLIENTSTATE)
        End If  
        COLLECTMSG "CleanUp","Successfully got to the end",ErrorCode
        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
        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 "12Hour"
        wscript.quit ErrorCode
End Sub

Reply via email to