RegObj freaks out and won't re-initialize 
Author Message
 RegObj freaks out and won't re-initialize

I have a quick and dirty script to report on installed McAfee versions that
does an ok job, until it hits a PC with a "half install" (Has the Network
Associates key, but is missing the subkeys because it's waiting for
reboot).  On that specific PC, the script correctly reports that it can't
find the keys it needs, but ALL subsequent attempts to connect to any
remote registries fail.  I have another script that sets all objects
relating to remote registries to Nothing and recreates them with no effect
(that script suffers from the exact same symptoms - I'm posting the
reporting code only since it's shorter).  Anyone have any ideas on how to
clear this condition/re-init the remote registry objects?

'--------------------------------------------------------------------
'
'Program Name    McPukeReport.VBS
'
'Author        Adam Ackermann
'
'Credits    This script incorporates Brad Smith's IsValidPing function from
'         http://www.*-*-*.com/
'
'Description    VBS Script for Reporting NA VirusScan DAT and engine
versions
'
'Design         Script enumerates all computers in the domain
'               and checks the registry of each for information
'               on it's VirusScan engine and DAT version.  It looks
'        First for 4.5.x data and if not found, will look for 4.0.x data
'        Also reports on current status of McShield service
'
'Edit History    07/31/01    Begin coding
'        08/08/01    Add capability to report on McShield Service status

'--------------------------------------------------------------------
'Declare global variables here
'--------------------------------------------------------------------

Option Explicit

Dim oShell        'Wscript.Shell object
Dim oNet        'Wscript.Network object
Dim oFSO        'Wscript.FileSystem object
Dim objReg        'Registry Object
Dim objRemote        'Remote Registry Object
Dim DomainName        'Name of NT domain to enumerate
Dim DomainObj        'Domain Object
Dim Computer        'Individual Computer Object
Dim Logfile        'Output of report
Dim McPukeEngine    'Version of VirusScan Engine in Use
Dim McPukeDAT        'Version of VirusScan DAT in Use
Dim McPukeDATDate    'Date of DAT file in Use
Dim RootKey        'Root of registry key on remote computer
Dim oName        'Name of sub object in remote registry
Dim oVal        'Value of sub object in remote registry
Dim LogfilePath        'Path to logfile
Dim CompObj        'Another object handle for computer
Dim SvcObj        'Handle for service object
Dim McShieldStatus    'Status of McShield Service
Dim ReturnLine        'Return Line from ping

'--------------------------------------------------------------------
'Set Global variables here
'--------------------------------------------------------------------

DomainName = "AMG"
LogfilePath = "f:\data\codetemp\McPukeReport.csv"

'--------------------------------------------------------------------
'Objects
'--------------------------------------------------------------------

Set oShell = CreateObject("Wscript.Shell")
Set oNet   = CreateObject("Wscript.Network")
Set oFSO   = CreateObject("Scripting.FileSystemObject")
Set DomainObj = GetObject("WinNT://" & DomainName)
Set objReg = WScript.CreateObject("RegObj.Registry")

'--------------------------------------------------------------------
'Main Body
'--------------------------------------------------------------------

'Only use computer accounts
DomainObj.Filter = Array("Computer")

'Delete old log file if it exists
If (oFSO.FileExists(LogfilePath)) Then
    Set Logfile = oFSO.GetFile(LogfilePath)
    Logfile.Delete
End If

'Create a log file
Set Logfile = oFSO.CreateTextFile(LogfilePath)

'Suppress errors from this point on
'(failure to attach to computer would abort script otherwise)
On Error Resume Next  

'Loop through computer accounts
For Each Computer in DomainObj
    Set objRemote = Nothing
    Set RootKey = Nothing
    Set objReg = Nothing

    If IsValidPing(Computer.Name) Then

        Set objReg = WScript.CreateObject("RegObj.Registry")

        'Attach to remote registry
        Set objRemote = objReg.RemoteRegistry("\\" & Computer.Name)
        If Err <> 0 Then
            Wscript.Sleep 500
            Set objRemote = Nothing
            Set objReg = Nothing
            Set objReg = WScript.CreateObject("RegObj.Registry")
            Set objRemote = objReg.RemoteRegistry(Computer.Name)
        End If        
        If Err <> 0 Then
            Wscript.Sleep 500
            Set objRemote = Nothing
            Set objReg = Nothing
            Set objReg = WScript.CreateObject("RegObj.Registry")
            Set objRemote = objReg.RemoteRegistry(Computer.Name)
        End If        
        If Err = 0 Then

            'Check for V 4.5.x Registry keys
            Set RootKey =
objRemote.RegKeyFromString("\HKEY_LOCAL_MACHINE\SOFTWARE\Network
Associates\TVD\Shared Components\VirusScan Engine\4.0.xx")
            If Err = 0 Then

                'Look for Version 4.5.x data
                McPukeEngine = RootKey.Values("szEngineVer").Value
                If Err <> 0 Then McPukeEngine = "error" End If

                'Get rest of Version 4.5.x data
                McPukeDAT = RootKey.Values("szDatVersion").Value
                If Err <> 0 Then McPukeDAT = "error" End If
                McPukeDATDate = RootKey.Values("szDatDate").Value
                If Err <> 0 Then McPukeDATDate = "error" End If
            Else

                'Initialize error buffer
                Err.Clear

                'Set RootKey to correct point in registry
                Set RootKey =
objRemote.RegKeyFromString("\HKEY_LOCAL_MACHINE\SOFTWARE\Mcafee\VirusScan")

                If Err = 0 Then

                    'Look for Version 4.0.x data
                    McPukeEngine = RootKey.Values("szProductVer").Value
                    If Err <> 0 Then McPukeEngine = "error" End If

                    'Get rest of Version 4.0.x data
                    McPukeDAT = RootKey.Values("szVirDefVer").Value
                    If Err <> 0 Then McPukeDAT = "error" End If
                    McPukeDATDate = RootKey.Values("szVirDefDate").Value
                    If Err <> 0 Then McPukeDATDate = "error" End If
                Else

                    'Machine is FUBAR
                    McPukeEngine = "nokeyfound"
                    McPukeDAT = "nokeyfound"
                    McPukeDATDate = "nokeyfound"

                End If

                'Check on status of McShield service
                Set CompObj = Nothing
                Set SvcObj = Nothing
                Set CompObj = GetObject("WinNT://" & DomainName & "/" &
Computer.Name & ",computer")
                If Err = 0 Then
                    Set SvcObj = CompObj.GetObject("Service", "McShield")
                    If Err = 0 Then
                        McShieldStatus = "no response"
                        Select Case SvcObj.Status
                            Case 1
                                McShieldStatus = "FUBAR - Stopped"
                            Case 2
                                McShieldStatus = "FUBAR - Start Pending"
                            Case 3    
                                McShieldStatus = "FUBAR - Stop Pending"
                            Case 4
                                McShieldStatus = "Running"
                            Case 5
                                McShieldStatus = "FUBAR - Continue Pending"
                            Case 6
                                McShieldStatus = "FUBAR - Pause Pending"
                            Case 7
                                McShieldStatus = "FUBAR - Paused"
                            Case 8
                                McShieldStatus = "FUBAR - Error"
                        End Select
                    Else
                        McShieldStatus = "unknown"
                    End If
                Else
                    McShieldStatus = "error connecting"
                End If
                Set CompObj = Nothing
                Set SvcObj = Nothing

            End If

            'Check on status of McShield service
            Set CompObj = Nothing
            Set SvcObj = Nothing
            Set CompObj = GetObject("WinNT://" & DomainName & "/" &
Computer.Name & ",computer")
            If Err = 0 Then
                Set SvcObj = CompObj.GetObject("Service", "McShield")
                If Err = 0 Then
                    McShieldStatus = "no response"
                    Select Case SvcObj.Status
                        Case 1
                            McShieldStatus = "FUBAR - Stopped"
                        Case 2
                            McShieldStatus = "FUBAR - Start Pending"
                        Case 3
                            McShieldStatus = "FUBAR - Stop Pending"
                        Case 4
                            McShieldStatus = "Running"
                        Case 5
                            McShieldStatus = "FUBAR - Continue Pending"
                        Case 6
                            McShieldStatus = "FUBAR - Pause Pending"
                        Case 7
                            McShieldStatus = "FUBAR - Paused"
                        Case 8
                            McShieldStatus = "FUBAR - Error"
                    End Select
                Else
                    McShieldStatus = "unknown"
                End If
            Else
                McShieldStatus = "error connecting"
            End If
            Set CompObj = Nothing
            Set SvcObj = Nothing

            'Log findings
            Logfile.WriteLine(Computer.Name & "," & McPukeEngine & "," &
McPukeDAT & "," & McPukeDATDate & "," & McShieldStatus & "," & ReturnLine)      

            'Release registry object
            Set objRemote = Nothing
        Else
            Logfile.WriteLine(Computer.Name & ",error connect remote
registry")
        End If
    Else
        Logfile.WriteLine(Computer.Name & ",OFFLINE")
    End If
Next

'--------------------------------------------------------------------
'Wrap up script
'--------------------------------------------------------------------

'Notify of completion
Wscript.Echo ("McPuke version report done!")

Set oShell = Nothing
Set oNet = Nothing
Set oFSO = Nothing
Set DomainObj = Nothing
Set Logfile = Nothing
Set objReg = Nothing

'--------------------------------------------------------------------
'IsValidPing function
'--------------------------------------------------------------------

function IsValidPing(byval vsIpAddress)
  dim objFSO, objShell, objTempFile, objTS
  dim sCommand, sReadLine
  dim bReturn

  '* Create objects.
  set objShell = WScript.CreateObject("Wscript.Shell")
  set objFSO = CreateObject("Scripting.FileSystemObject")

  '* Set default return value.
  bReturn = false

  '* Create command line to ping and save results to a temp file.
  sCommand = "cmd /c ping -n 3 -w 1000 "
  sCommand = sCommand & vsIpAddress
  sCommand = sCommand & " > temp.txt"

  '* Execute the command.
  objShell.run sCommand, 0, true

  '* Get the temp file.
  set objTempFile = objFSO.GetFile("temp.txt")
  set objTS = objTempFile.OpenAsTextStream(1)

  '* Loop through the temp file to see if ping was successful.
  do while objTs.AtEndOfStream <> true
    sReadLine = objTs.ReadLine
    '* if "reply from" is found in temp file then ping was successful.
    if instr(lcase(sReadLine), "reply from") > 0 then
      bReturn = true
      ReturnLine = sReadLine
      exit do
    end if
  loop

  '* Close temp file and release objects.
  objTS.close
  objTempFile.delete
  set objTS = nothing
  set objTempFile = nothing
  set objShell = nothing
  set objFSO = nothing

  '* Return value.
  IsValidPing = bReturn

end function



Sat, 31 Jan 2004 21:34:07 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Initialize event won't fire in vbscript v5

2. Jet Driver Won't Initialize

3. Snapins won't initialize properly

4. 'Like' clause freaking out

5. Can't Create Object WScript.Shell in Win 98 (1st Ed) and Win 95

6. Form-Level variables don't reinitialize

7. I'm Confused: RegObj Processing

8. Session Variable Time-outs

9. Two Q's [Closing a file][why won't work]

10. Simple script won't run on certain user's PC

11. MSINET.OCX *still* won't register, and now IE4 won't install

12. Runtime Err:3447 - can't initialize VBAJET or VBAJET32 dll's -HELP

 

 
Powered by phpBB® Forum Software