RE: Does WMI have to be installed on Remote Computer?
- From: Mark <mark@xxxxxxxxxxx>
- Date: Wed, 15 Mar 2006 14:06:29 -0800
IMHO this looks like a well constructed and very vell commented script. The
wmi statements look ok, although you could benefit from creating some
variables for those long select statements in the same way as you have done
for the oledb connection string.
You may want to ech some response to screen at various stages through the
script to identify where the errors are occuring and try agains a sample
machine rather than work through a recordset before evaluting the results.
It may be that the target machines are locked down to prevent remote
quieries. Although I forget where this is set.
Are you running this from an account with administrative rights? You may
have TS access to the remote machines bu this does not imply admin access.
WMI comes as standard on w2k w2k3 and xp, addon for for NT4
Mark
"Jennifer" wrote:
Hello. I'm new to WMI, learning as I go. I have a script which is.
supposed to check disk space on a number of remote computers.
Sometimes I get an error number back, without a description:
-2147217405. After looking around here, it seems that that means
permission is denied, or it might mean that WMI is not installed on the
remote computer. I'm not sure which. Which brings up the question -
does WMI need to be installed on the remote computer in order for a
script which uses WMI to work? I would have thought it wouldn't since
the script is not being run from the remote computer. Does it?
Another question. If -2147217405 does mean that permission is denied,
I just want to be clear about what exactly that means. Sometimes that
error comes back, but I can log on to that computer and look at the
disk space through a remote desktop connection. So if permission is
denied, how can that be?
My script is below, just in case someone had questions about what I am
doing. And just on a side note, constructive criticism is very
welcome.
Thanks,
Jennifer
On Error Resume Next
Dim CN, RS
Const HARD_DISK = 3
Const CONVERSION_FACTOR = 1048576
Dim
objWMIService,colItems,diskid,freemegabytes,diskspace,totalspace,sInsQry
Dim sErrQry
Dim sErrMsg
Set CN = CreateObject("ADODB.Connection")
Set RS = CreateObject("ADODB.REcordset")
sCon = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=True;Initial Catalog=Server_Disk_Utilization;Data Source=XXXXX"
CN.ConnectionString = sCon
CN.CommandTimeout = 180
CN.Open
sQry = "Select ServerName from Servers"
RS.Open sQry, CN
RS.MoveFirst
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Loop throug the list of servers. Server names are in the
''' Recordset called RS.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Do Until RS.EOF
StrComputer = RS("ServerName").Value
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' First try to ping the server. Server name is in strComputer.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
Set colPings = objWMIService.ExecQuery _
("Select * From Win32_PingStatus where Address = '" &
StrComputer & "'")
For Each objStatus in colPings
If IsNull(objStatus.StatusCode) _
or objStatus.StatusCode <> 0 Then
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' If PING does not work, then log it to the errors table.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Err.Number <> 0 Then
Call LogError ("DriveSpace.VBS", "Try Ping", strComputer, Err.Number,
Err.Source, Err.Description)
End If
Else
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' If PING does work, then try to create a connection with
''' WMI to the Server.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' If the connection does not work, log it to the errors table.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Err.Number <> 0 Then
Call LogError ("DriveSpace.VBS", "Connect to Server", strComputer,
Err.Number, Err.Source, Err.Description)
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' If the connection does work, get a list of drives from
''' the server.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set colItems = objWMIService.ExecQuery("Select * from
Win32_logicalDisk " & _
"where drivetype = " & HARD_DISK & "")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' If getting the list of drives fails, log it to the errors table.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Err.Number <> 0 Then
Call LogError ("DriveSpace.VBS", "Get Drive Letter", strComputer,
Err.Number, Err.Source, Err.Description)
End If
For Each objItem In colItems
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' If getting the list of drives works, then get the drive space
''' for each drive. Write the drive space to the Server_DiskUsage
''' table.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
diskid = objitem.deviceid
freemegabytes = objitem.freespace / conversion_factor
diskspace = round(freemegabytes,0)
totalspace = round(objitem.size/ conversion_factor)
sInsQry = "Insert Into Server_DiskUsage (" & _
" CollectedDateTime, " & _
" ServerName, " & _
" DriveLetter, " & _
" Capacity, " & _
" Used) " & _
"Values ('" & _
Now & "','" & strComputer & "','" & _
diskID & "'," & TotalSpace & "," &
TotalSpace - FreeMegabytes & ")"
CN.Execute sInsQry
If Err.Number <> 0 Then
Call LogError ("DriveSpace.VBS", "Insert Into Server_DiskUsage",
strComputer, Err.Number, Err.Source, Err.Description & " " & DiskID &
" " & Now )
End If
DiskID = ""
TotalSpace = 0
FreeMegaBytes = 0
Next
End If
Next
Set objWMIService = Nothing
Set colItems = Nothing
RS.MoveNext
Loop
Sub LogError (ScriptName, Location, Server, N, S, Desc)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' LogError Subroutine - logs the errors to the Server_ErrorLog
table.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim sCon, CN
sCon = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=True;Initial Catalog=Server_Disk_Utilization;Data
Source=XXXXX"
Set CN = CreateObject("ADODB.Connection")
cN.ConnectionString = sCon
cN.CommandTimeout = 180
CN.Open
If Err.Number = -2147217405 Then
sErrMsg = "Permission Denied"
Else
sErrMsg = Desc
End If
sErrQry = "Insert Into Server_ErrorLog (" & _
" ErrDateTime, " & _
" Script_Name, " & _
" Script_Location, " & _
" ServerName, " & _
" ErrNumber, " & _
" ErrSource, " & _
" ErrDescription) " & _
" Values ('" & _
Now & "','" & ScriptName & "','" & Location & "','" &
Server& "','" & N & "','" & _
S & "','" & sErrMsg & "')"
CN.Execute sErrQry
Err.Clear
CN.Close
Set CN = Nothing
End Sub
- Follow-Ups:
- Re: Does WMI have to be installed on Remote Computer?
- From: Jennifer
- Re: Does WMI have to be installed on Remote Computer?
- References:
- Does WMI have to be installed on Remote Computer?
- From: Jennifer
- Does WMI have to be installed on Remote Computer?
- Prev by Date: Re: Error 800A0046 while running a vbs script on a remote computer
- Next by Date: Re: Copy "Services" file script ??
- Previous by thread: Does WMI have to be installed on Remote Computer?
- Next by thread: Re: Does WMI have to be installed on Remote Computer?
- Index(es):
Relevant Pages
|