How to Get WMI Script to Work on a Remote Workgroup Computer

Written by leena kudalkar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Get WMI Script to Work on a Remote Workgroup Computer
WMI scripts administer resources on Microsoft Windows networks. (informatique image by gilles vallée from Fotolia.com)

Microsoft Windows Management Instrumentation (WMI) is the core management tool and technology built into Windows XP, 2000 and the Windows Server 2003 family. Using WMI, you can access, configure, monitor and manage almost all Windows resources, such as workstations, servers, hard disks and file systems, printers. Before WMI, Windows administrators had to deploy several distinct graphical tools. Another value that WMI adds is scripting. You can access Windows resources via WMI scripts, which was previously possible through only the Windows 32-bit Application Programming Interfaces (APIs). Write WMI scripts using Windows Script Host and Visual Basic Scripting Edition (VBScript) or any scripting language supported by Microsoft's Component Object Modeling (COM) technology.

Skill level:
Easy

Other People Are Reading

Things you need

  • Intel Pentium PC
  • Microsoft Windows XP, 2000 or any one of Windows Server 2003 family of operating systems
  • Visual Basic Scripting Edition for your version and edition of Windows

Show MoreHide

Instructions

  1. 1

    Open your preferred editor to write or edit your VBScript script for WMI. Your script should have a ".VBS" extension.

  2. 2

    Add the following VBScript statements at the beginning of your script:

    "strTargetWorkstation = <your remote workstation name as a string>

    Set pSWbemServices = GetObject("winmgmts:\" & strTargetWorkstation)"

    The string variable "strTargetWorkstation" should be assigned the host name of your remote workstation. The second line is a call to the "GetObject" function with the name of WMI Scripting Library's moniker as its parameter. This name will be "winmgmts:" followed by the host name of the target computer (for example, contents of "strTargetWorkstation"). The target computer could be local or remote. The function "GetObject" returns a reference (pointer) to a WMI Script Library Object called "SWbemServices."

  3. 3

    Call the methods of the SWbemServices object to access the Windows resources on the remote workstation.

    For example, to retrieve information about a WMI-managed resource on the remote workstaion, call the "InstanceOf" method of the SWbemServices object, which is the variable "pSWbemServices" in your script. Add the following statements to the script to get information about Win32 Services on the remote workstation:

    "Set pSWbemObjectSet = pSWbemServices.InstancesOf("Win32_Service")

    For Each pObject In pSWbemObjectSet

    WScript.Echo "Display Name:  " &amp; pObject.DisplayName &amp; vbCrLf &amp; _
    
                 "   State:      " &amp; pObject.State       &amp; vbCrLf &amp; _
    
                 "   Start Mode: " &amp; pObject.StartMode
    

    Next"

    The script will loop through each entity in pSWbemObjectSet to display the attributes "DisplayName," "State" and "StartMode."

  4. 4

    Save the script as "<your script name>.VBS."

  5. 5

    Open an MD-DOS window and go to the directory where your WMI script resides using the change directory (cd) command as follows:

    "cd <WMI Scripts Directory Path>"

    Execute "dir *.VBS" on the DOS Prompt to display a list of .VBS scripts in this directory. Verify that the script your just wrote and saved is in the list.

  6. 6

    Run the script on the MS-DOS Command Prompt as follows:

    "[WMI Scripts Directory Path]>cscript <your script name>.VBS"

    You should see a list of services with the state they are in (Stopped/Running) and the service start mode (Manual/Auto). This is a comprehensive test to check that the remote connection was made and resources were accessed.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.