Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to query for 2 events and count

Status
Not open for further replies.

vajpowb

Technical User
Jan 18, 2008
16
US
I cannot get this to work. I've looked at the objects and
am cornfused. It works through the registry queries but does not give me what I need from the application event log.

On Error Resume Next
Dim strComputer, strPingResults
DIM fso, IPAKFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set IPAKFile = fso.CreateTextFile("verify_RA_Svr_Snp_PING.txt", True)

Const HKEY_LOCAL_MACHINE = &H80000002

Set InputFile = fso_OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strComputer) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
IPAKFile.WriteLine strComputer
strKeyPath = "SOFTWARE\Altiris\Express\Recovery Solution Agent"
strValueName = "Agent Name"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If isnull(strValue) then
IPAKFile.WriteLine("Altiris Recovery Solution Agent is not installed")
else
IPAKFile.WriteLine strValue & (" is installed.")
end if


strKeyPath = "SOFTWARE\Altiris\Express\Recovery Solution Agent"
strValueName = "ServerAddress"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If IsNull(strValue) then
IPAKFile.WriteLine("There is NO Recovery Server Listed")
Else
IPAKFile.WriteLine("Recovery Server: ") & strValue
End If
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " & "EventCode = '31' and " & "Message = 'Snapshot completed successfully'")

IPAKFile.WriteLine("Successful Snapshots: ") & colLoggedEvents.Count
Else
IPAKFile.WriteLine("Computer :") & strComputer & (" cannot be reached.")
End If

IPAKFile.WriteLine(".................................................")
loop



Wscript.Echo "Done"
 
[1] Assert the security privilege for querying on nteventlog.
>Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

[tt]Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate[red],(Security)[/red]}!\\" & strComputer & "\root\cimv2")[/tt]

[2] Better close file handle after the job done.
[tt]
'etc etc
loop
[blue]InputFile.close
IPAKFile.close[/blue]
Wscript.Echo "Done"
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top