With Windows Management Instrumentation (WMI), Windows Server 2003 administrators have a powerful tool to perform many administrative tasks quickly and efficiently. WMI functions allow access to inventory data for hardware and software, system settings, and configuration data. WMI determines the required basic data from resources such as registry, drivers, file system, or Active Directory. Administrators can use WSH scripts to view and manipulate all information provided by WMI. Regrettably, these scripts are usually difficult to create and require a deeper understanding of object-oriented programming with Windows Script Host.
For the reasons described earlier, Windows Server 2003 comes with a new script interface, Windows Management Instrumentation Command-line (WMIC). WMIC uses aliases that provide primary WMI data. You do not necessarily need to have knowledge about WMI-specific concepts. Following are the key aliases for terminal servers:
Printer Administration of printers using these methods: AddPrinterConnection, CancelAllJobs, Pause, PrintTestPage, RenamePrinter, Reset, Resume, SetDefaultPrinter, and SetPowerState.
Process Process administration using these methods: Create, GetOwner, SetPriority, Terminate, and more.
Rdaccount Permission management of terminal server connections using these methods: Delete, ModifyAuditPermissions, and ModifyPermissions.
Rdnic Network adapter management using these methods: SelectAllNetworkAdapters, SelectNetworkAdapterID, and SelectNetworkAdapterIP.
Rdpermissions Setting permissions for a certain terminal server connection using the methods AddAccount and RestoreDefaults.
Rdtoggle The monitoring thread for terminal server connections is switched on or off remotely using the SetAllowTSConnections method.
Registry Registry management. Only the recommended registry size can be modified.
Service Windows services management using StartService, StopService, and other methods.
The following example shows a command-line string that uses WMIC to change the terminal server configuration. First, the terminal server connections are disabled. This works only if the administrator is logged on locally to the relevant terminal server.
WMIC rdtoggle where AllowTSConnections=1 call SetAllowTSConnections 0
If the administrator is logged on to a remote computer, it is slightly more difficult to call up the same WMIC functionality:
WMIC /Node:”<Servername>“ /User:”<Domainname\Username>“ /Password:”<Password>“ rdtoggle where AllowTSConnections=1 call SetAllowTSConnections 0
The following command lets the locally logged-on administrator view the current printer queue settings on a terminal server:
WMIC service where Name=”Spooler”
After verifying the printer queue status, the administrator can stop the corresponding Windows service with this command:
WMIC service where Name=”Spooler” call StopService
Finally, all priority 13 processes are displayed every five seconds in a list. This allows monitoring of certain system statuses.
WMIC process where Priority=”13” list brief /every:5
Even these few examples show that the WMIC command-line extensions allow one to perform complex administrative tasks. Alternatively, it is possible to open a console using Wmic.exe without parameters. The console offers comprehensive help (using /?) for each alias and all methods. Furthermore, commands can be executed in the console, which leads to output results in a better format.
It is quite evident that WMIC allows local and remote access to the properties and configuration settings of terminal servers using the command line. The individual WMIC calls can, of course, also be used within batch-processing scripts.
Note |
To use the functionalities described in this section, you must be a member of the administrators group or have the corresponding Active Directory permissions. |
It is not easy to understand WMI properties and methods—not even with the possibilities offered by WMIC. WMI CIM Studio provides great help. It can be downloaded from the Microsoft Web server at http://www.microsoft.com. In the Root\CIMV2 default namespace, WMI CIM Studio shows all of the details of all classes and instances within WMI. A search using Terminal or TS character strings leads to all relevant classes for terminal servers.
WMI queries, such as the one described earlier involving the WMIC console, are written in WMI Query Language (WQL). This language is reminiscent of SQL, which is normally used for database queries. Further information about WQL is located in the WMI area of the Platform SDK.
Note |
Only if you are a member of the administrator group can you have full access to all WMI functions. Members of the local user group have only read access in the entire WMI namespace. |