Results 1 to 7 of 7

Thread: [RESOLVED] WMI querying against remote machines

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Resolved [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.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    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.

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: WMI querying against remote machines

    What kind of data are you trying to query for?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    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.

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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:
    1. Private Sub QueryProcessorExample(ByVal RemoteMachineName As String)
    2.         Dim manScope As ManagementScope
    3.         Dim manPath As ManagementPath
    4.         Dim manClass As ManagementClass
    5.         Dim manObj As ManagementObject
    6.         Dim manObjCol As ManagementObjectCollection
    7.         Dim output As String = String.Empty
    8.         Try
    9.             manPath = New ManagementPath("\\" & RemoteMachineName & "\root\CIMV2:Win32_Processor")
    10.             manScope = New ManagementScope(manPath)
    11.             'Since it is a remote system, you must provide proper credentials to access it
    12.             manScope.Options.Username = "yourDomainName\administrator"
    13.             manScope.Options.Password = "yourPassword"
    14.             manClass = New ManagementClass(manScope, manPath, Nothing)
    15.             manObjCol = manClass.GetInstances()
    16.             For Each manObj In manObjCol
    17.                 output &= "Processor Description: " & manObj("Description").ToString & Chr(10) & _
    18.                           "Max Clock Speed: " & manObj("MaxClockSpeed").ToString & Chr(10) & _
    19.                           "Current Clock Speed: " & manObj("CurrentClockSpeed").ToString & Chr(10) & _
    20.                           "Load Percentage: " & manObj("LoadPercentage").ToString & Chr(10) & _
    21.                           "Status: " & manObj("Status").ToString & Chr(10)
    22.             Next
    23.             MessageBox.Show(output)
    24.         Catch ex As Exception
    25.             MessageBox.Show(ex.Message)
    26.         Finally
    27.             manPath = Nothing
    28.             manScope = Nothing
    29.             manClass = Nothing
    30.             manObjCol = Nothing
    31.         End Try
    32.     End Sub

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    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!

  7. #7
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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
  •  



Click Here to Expand Forum to Full Width