Help WMI Error in VBS
- From: "Matthew" <MKruer@xxxxxxxxx>
- Date: 31 Aug 2006 14:22:01 -0700
I need help with debugging this code. the code works for everything
except in once instance where a server name is in the list, but not on
the network the entire scrips fails at this point at SET objWMIService
= GetObject("winmgmts://" & Computer) with a permission denied error.
I though i was error trapping with the next line, but it is almost like
the script never gets to that point before blowing up. can someone take
a look and see what i am missing.
-TIA-
'Objective: Find Disk Free Space in all the listed servers and write to
a database, and add error log.
Const kbConversion= 1024
Dim AdCn, AdRec, AdRec1, SQL
Set AdCn = CreateObject("ADODB.Connection")
Set AdRec = CreateObject("ADODB.Recordset")
Set AdRec1 = CreateObject("ADODB.Recordset")
' NOTE: Change the connection string according to your environment.
AdCn.Open = "Provider=SQLOLEDB.1; Data Source=sdlc;Integrated
Security=SSPI;Persist SecurityInfo=False; Initial Catalog=DISK_Dev;
user id=diskuser; password=disk"
SQL1 = "SELECT SystemName FROM System_Monitor_List WHERE MonitorEnabled
= 1 AND MonitorDiskSpace = 1"
'wscript.echo SQL1 ' Debugging
AdRec1.Open SQL1, AdCn,1,1
'Adrec1.movefirst
DO UNTIL AdRec1.EOF
Computer = AdRec1("SystemName")
' wscript.echo Computer ' Debugging
SET objWMIService = GetObject("winmgmts://" & Computer)
If err.number <> 0 THEN
ErrorSQL="INSERT INTO System_Monitor_Log_Errors (SystemName,
SystemError) VALUES ('" & Computer & "','" & Err.description & "')"
wscript.echo "Start Error :" & ErrorSQL ' Debugging
AdRec.Open ErrorSQL, AdCn,1,1
ELSE
SET colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk")
FOR EACH objLogicalDisk IN colLogicalDisk
IF err.number <> 0 THEN
ErrorSQL="INSERT INTO System_Monitor_Log_Errors (SystemName,
SystemError) VALUES ('" & Computer & "','" & Err.description & "')"
wscript.echo "Loop Error: " & ErrorSQL ' Debugging
AdRec.Open SQL, AdCn,1,1
END IF
IF objLogicalDisk.drivetype=3 THEN
SQL="INSERT INTO System_Monitor_Log_Disk_Space (SystemName, Drive,
Size, FreeSpace, AuditDateTime) VALUES ('" & Computer & "','" &
objLogicalDisk.DeviceID & "','" & objLogicalDisk.size/kbConversion &
"','" & objLogicalDisk.freespace/kbConversion & "','" & now() & "')"
wscript.echo sql ' Debugging
AdRec.Open SQL, AdCn,1,1
END IF
NEXT
END IF
Adrec1.movenext
err.Clear
LOOP
.
- Follow-Ups:
- Re: Help WMI Error in VBS
- From: Dan
- Re: Help WMI Error in VBS
- Prev by Date: HOWTO: Re-raise an error?
- Next by Date: Re: How to do practical error handling
- Previous by thread: HOWTO: Re-raise an error?
- Next by thread: Re: Help WMI Error in VBS
- Index(es):
Relevant Pages
|