|
-
Apr 11th, 2007, 06:17 PM
#1
Thread Starter
Addicted Member
[RESOLVED] WMI querying against remote machines
Hi All,
Does anyone out there have an working vb.net 2005 code that runs WMI queries against a remote machine on the same network?
I am trying to make the cross from vbs & vb6 to vb.net 2005. WMI querying was straight forward in the past, but I can't seem to find any working code that queries a remote machine.
Any sample code would be greatly appreciated. Thank you.
Last edited by Giraffe Frenzy; Apr 11th, 2007 at 06:39 PM.
-
Apr 12th, 2007, 06:21 AM
#2
Thread Starter
Addicted Member
Re: WMI querying against remote machines
I have been researching this for awhile now, but I still can not figure this out. I think if I see one working example of a WMI query that connects to a remote machine and pulls hardware data, then I will be able to run with it from there.
Any help would greatly be appreciated.
-
Apr 12th, 2007, 07:08 AM
#3
Re: WMI querying against remote machines
What kind of data are you trying to query for?
-
Apr 12th, 2007, 07:10 AM
#4
Thread Starter
Addicted Member
Re: WMI querying against remote machines
Well for testing purposes, any kind of hardware specs would be fine. At this point I would be glad to see anything queried from a remote machine.
-
Apr 12th, 2007, 08:16 AM
#5
Re: WMI querying against remote machines
Try this example... It won't work if the remote system has firewall turned on.
I've tried it on win2003 servers, winxp sp2 (with firewall disabled) and win2000 and it works fine. However, when firewall is enabled on winxp sp2 sytems, it won't work. And I don't know how you can bypass the firewall if it is enabled 
Don't forget to add a reference of System.Management and import it to your project.
vb Code:
Private Sub QueryProcessorExample(ByVal RemoteMachineName As String)
Dim manScope As ManagementScope
Dim manPath As ManagementPath
Dim manClass As ManagementClass
Dim manObj As ManagementObject
Dim manObjCol As ManagementObjectCollection
Dim output As String = String.Empty
Try
manPath = New ManagementPath("\\" & RemoteMachineName & "\root\CIMV2:Win32_Processor")
manScope = New ManagementScope(manPath)
'Since it is a remote system, you must provide proper credentials to access it
manScope.Options.Username = "yourDomainName\administrator"
manScope.Options.Password = "yourPassword"
manClass = New ManagementClass(manScope, manPath, Nothing)
manObjCol = manClass.GetInstances()
For Each manObj In manObjCol
output &= "Processor Description: " & manObj("Description").ToString & Chr(10) & _
"Max Clock Speed: " & manObj("MaxClockSpeed").ToString & Chr(10) & _
"Current Clock Speed: " & manObj("CurrentClockSpeed").ToString & Chr(10) & _
"Load Percentage: " & manObj("LoadPercentage").ToString & Chr(10) & _
"Status: " & manObj("Status").ToString & Chr(10)
Next
MessageBox.Show(output)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
manPath = Nothing
manScope = Nothing
manClass = Nothing
manObjCol = Nothing
End Try
End Sub
-
Apr 13th, 2007, 06:15 AM
#6
Thread Starter
Addicted Member
Re: WMI querying against remote machines
Thanks stan,
That is exactly what I needed.
For anyone who needs help finding the classes to run WMI against, the best app I have found is the "WMI Code Creator" (see link below).
http://www.microsoft.com/downloads/d...displaylang=en
Thanks for your help, Stan!
-
Apr 13th, 2007, 07:46 AM
#7
Re: [RESOLVED] WMI querying against remote machines
You can also lookup the info for Win32 classes in MSDN online library... And that's where I always go to when I'm in doubt about something.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|