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:
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
Open your preferred editor to write or edit your VBScript script for WMI. Your script should have a ".VBS" extension.
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."
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: " & pObject.DisplayName & vbCrLf & _ " State: " & pObject.State & vbCrLf & _ " Start Mode: " & pObject.StartMode
The script will loop through each entity in pSWbemObjectSet to display the attributes "DisplayName," "State" and "StartMode."
Save the script as "<your script name>.VBS."
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.
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.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for