|
bagpipe
银牌会员
     DOS联盟捡破烂的
积分 1144
发帖 425
注册 2005-10-20 来自 北京
状态 离线
|
『楼 主』:
[转贴]WMIC 简单介绍
使用 LLM 解释/回答一下
这是我在论坛里的最后一帖,希望大家原谅以前我所说过的话,请大家原谅!
WMIC 全新的超级命令行管理工具
微软Windows Server的图形界面接口在为网络管理提供便利的同时,因其消耗资源偏大、操作缓慢而颇受Windows管理员的微词,为提供一个图形管理界面之外的另一种选择,微软推出了集WMI的强大与命令行的简洁于一身的全新的命令行管理工具WMIC。加入了WMIC的Windows server 2003的命令行,据称可以完成几乎所有的管理任务。
以DOS起家的微软,最终靠图形界面一统了天下。传统的微软Windows Server的图形界面接口,在使系统管理简单易行的同时,其偏大的资源消耗与缓慢的操作速度,不但使众多IT Pro级系统管理员颇有微词,也使许多从Unix、NetWare转过来的系统管理员短时间内难以适从。虽然微软开发了WMI(Windows Management Instrumentation,Windows管理架构),并在Support Tools和Resource Kits提供了大量基于WMI的脚本让管理员使用,在命令行下管理服务器,但复杂的脚本编程同样令许多管理员却步,因为并非每个管理员都是脚本编程高手。从另一个角度讲,图形界面接口像一个黑盒子,使许多管理员丧失了量身定制管理任务的机会与乐趣,只能亦步亦趋地跟在越来越多的向导屁股后面,不停地点按着"下一步"。
鉴于上述原因,微软在Windows Server 2003中,综合了WMI的强大与命令行的简洁,推出了全新的命令行管理工具WMIC,英文全称Windows Management Instrumentation Command-line,即Windows管理规范命令行。并声称使用WMIC,再配合其他现存的命令行工具,管理员几乎可以完成所有的管理任务,而不必再过多地依赖那些图形界面。
本文将对WMIC进行一个简单的介绍,由于笔者在撰稿时Windows Server 2003还没有正式发布,所以一切技术均以Windows Server 2003 RC2(Build 3718)为准,最终版本正式发布后可能会有变化。
背景:WMI、WBEM与CIM
关于WMI,我们在以前的文章中多次提及,并有过具体的应用,如《使用VS.NET实现WMI调用》(2003年1月刊),《限制域用户同时的多点登录》与《来一段脚本,Kill掉Mike的歌》(2003年2月刊)等。这里不准备再对其做详细的说明,只做一下简单的介绍。
WMI是微软基于Web的企业管理(WBEM)这一理念与标准的具体实现,并对CIM(Common Information Model,公用信息模型)提供完整的支持。WMI由符合CIM标准的对象储备库(Object Repository)和CIM对象管理器(WMI Object Manager)组成,其中对象储备库是对象定义的数据库,对象管理器负责处理储备库中对象的收集和操作,并从WMI提供程序(WMI Provider)收集信息。WMI提供程序在WMI与操作系统组件、应用程序和其他系统之间充当中间人角色,两者通过WMI提供程序交换信息。WMI提供程序的主要作用就是为WMI提供下层对象的相关信息,以及允许WMI通过它对下层对象进行管理。例如,注册表提供程序从注册表中提供信息,而SNMP提供程序则从SNMP设备中提供数据和事件等。
WMI被许多计算机管理工具所用,如Microsoft Systems Management Server、Microsoft Health Monitor和Microsoft Operations Manager等。
WMIC概述
WMIC,是一款新出现在Windows Server 2003中的命令行管理工具。使用WMIC,你不但可以管理本地计算机,而且可以管理同一Windows域内的所有远程计算机(需要必要的权限),而被管理的远程计算机不必事先安装WMIC,只需要支持WMI即可。
WMIC有一个能够分析、解释和执行从命令行接收的别名(Alias)的引擎,它是一个可执行文件,名为WMIC.exe,这个文件通常位于"c:\windows\
system32\wbem"文件夹中,该程序运行于用户当前登录的计算机上。任何对WMIC命令行的扩展性能都经过别名文件定义或者注册。别名又称友好名称(Friendly Names),通过MOF(Management Object Format,管理对象格式)格式定义。WMIC引擎接收到输入的命令后,先进行分析。如果命令是一个别名,WMIC会从当前操作命名空间(比如root\cli)调用该别名的定义,应用当前的环境设置(如目标命名空间),并将别名命令与它的原始命令进行对应,然后执行。
具体来说,你可以使用WMIC实现如下的管理任务:
1、本地计算机管理
2、远程单个计算机管理
3、远程多个计算机管理
4、使用远程会话的计算机管理(如Telnet)
5、使用管理脚本的自动管理
只有本地管理员组成员才能够启动WMIC,由于WMIC本质上是WMI的一个客户端,因此WMIC的安全受限于WMI的安全。当WMIC在一个远程会话中被使用时,如Telnet、终端服务等,缺省情况下,它使用发起此会话的用户的安全上下文。在使用WMIC管理一个远程计算机之前,WMIC会Ping一下远程计算机以确定其状态。
在使用WMIC命令行时,可以随时使用"/?"来获得当前命令上下文的帮助信息。
执行模式
WMIC可以以两种模式执行:交互模式(Interactive mode)和非交互模式(Non-Interactive mode),经常使用Netsh命令行的管理员应该非常熟悉这两种模式。
交互模式。如果你在命令提示符下或通过"运行"菜单只输入WMIC,都将进入WMIC的交互模式,每当一个命令执行完毕后,系统还会返回到WMIC提示符下,如"Root\cli",交互模式通常在需要执行多个WMIC指令时使用。当你需要先执行"CONTEXT"命令查看环境变量,再使用"OS"命令查看当前操作系统消息时,就可以使用交互模式,如图1所示。交互模式有时还会对一些敏感的操作要求确认,比如删除操作,最大限度地防止管理员出现失误。
非交互模式。非交互模式是指将WMIC指令直接作为WMIC的参数放在WMIC后面,当指令执行完毕后再返回到普通的命令提示符下,而不是进入到WMIC上下文环境中。WMIC的非交互模式主要用于批处理或者其他一些脚本文件中,比如上面的"OS"命令在非交互模式下就可以使用下面的方式执行:
wmic os /?
使用WMIC管理系统
WMIC包含了众多的开关、命令,以及内置的别名,详细内容见表1、表2和表3。下面让我们通过具体的实例体验一下WMIC的强大功能。
简单管理任务
使用WMIC,可以完成一些简单的管理任务,比如查看硬件与操作系统信息。如果不使用WMIC,查询硬件如BIOS、CPU、操作系统等信息,通常是使用系统提供的API接口进行编程,或者编写一小段脚本程序,是一件比较麻烦的事情,如表4所示就是一个查询BIOS信息的传统VBscript脚本。如果使用WMIC,那情况就大不相同,只需要一个简单命令就能搞定:
wmic bios list full
结果如图2所示。
大家可能注意到了上面命令行中还有两个参数list和full。list决定显示的信息格式与范围,它有Brief、Full、Instance、Status、System、Writeable等多个参数,full只是它的一个参数,也是list的缺省参数,表示显示所有的信息。其他几个参数顾名思义,如Brief表示只显示摘要信息,Instance表示只显示对象实例,Status表示显示对象状态,Writeable表示只显示该对象的可写入的属性信息等。
在管理过程中,尤其是进行远程系统管理的时候,管理员多数喜欢列一下进程列表,以了解当前系统中正在运行的程序。下面的命令就可以达到这一目的:
wmic process list brief
它会显示当前所有进程的一些摘要信息,比如进程名称、进程ID和优先级等。在我以前的文章《来一段脚本,Kill掉Mike的歌》中,就可以使用这一命令代替那个list.vbs脚本。
复杂管理任务
WMIC在完成复杂管理任务方面也是非常出色的,先看一下查询事件日志并生成结果文件的例子:
WMIC /node:"dc2" /user:"mytest" NTEVENTswheres"eventtype<3 and eventtype>0 AND logfile='Application'" GET Logfile, SourceName, Eventtype, Message, TimeGenerated /FORMAT:htable:"sortby=EventType">c:\Application.htm
这行长长的命令表示从计算机DC2中查询应用程序日志信息,事件类型为小于3且大于0的事件,通常是警告与错误事件。因为是远程计算机,所以命令中使用了"/node"和"/user"开关。输出结果保存为网页格式,保存在"c:\Application.htm"文件中,并以事件类型进行排序。当你使用上面的命令时,因为使用了"/user"开关,所以系统会首先提示你输入与该用户匹配的密码,如图3所示,查询结果如图4所示。
同样,你还可以使用WMIC同时重新启动多台被管理的服务器或工作站,命令如下:
WMIC /NODE:@"c:\MyServerList.txt" OSswheres(Primary="TRUE") CALL Win32ShutDown 6
WMIC会首先从"c:\MyServerList.txt"中取得服务器名称列表,这些服务器名称在文件中以逗号分割,如"dc1,dc2"。要注意的是,在/node开关后面使用服务器列表文件时,一定要在文件名的前面加上"@"引导符。该命令执行结果如图5所示,在执行重新启动过程中,WMIC会返回详细的执行结果。
WMIC还可以从Active Directory中取得数据,下面是一个从Active Directory中取得用户信息的例子,取得的用户信息包括显示名称、UPN名称、名称和创建时间等,返回结果如图6所示:
WMIC/NAMESPACE:\root\directory\ldap PATH ds_user GET ds_displayname, ds_userprincipalname, ds_cn, ds_name, ds_whencreated /VALUE
总结
WMIC是我所见到的基于windows平台的功能最强大的命令行工具,但同样也是最复杂的工具。尤其是在完成复杂的管理任务时,你需要对WMI的Win32类的属性及方法非常熟悉才可能做到游刃有余。因此,在希望熟悉运用WMIC之前,建议先学习WMI,熟悉其Win32类的各种属性及方法。国内现在出过几本不错的WMI书籍,你也可以到微软的MSDN网站(MSDN.microsoft.com)上查询这方面的信息。
有了WMIC的加入,命令行们应该可以大声说:"虽然我很丑,但是我很强大"了
WMIC 全新的超级命令行管理工具
微软Windows Server的图形界面接口在为网络管理提供便利的同时,因其消耗资源偏大、操作缓慢而颇受Windows管理员的微词,为提供一个图形管理界面之外的另一种选择,微软推出了集WMI的强大与命令行的简洁于一身的全新的命令行管理工具WMIC。加入了WMIC的Windows server 2003的命令行,据称可以完成几乎所有的管理任务。
以DOS起家的微软,最终靠图形界面一统了天下。传统的微软Windows Server的图形界面接口,在使系统管理简单易行的同时,其偏大的资源消耗与缓慢的操作速度,不但使众多IT Pro级系统管理员颇有微词,也使许多从Unix、NetWare转过来的系统管理员短时间内难以适从。虽然微软开发了WMI(Windows Management Instrumentation,Windows管理架构),并在Support Tools和Resource Kits提供了大量基于WMI的脚本让管理员使用,在命令行下管理服务器,但复杂的脚本编程同样令许多管理员却步,因为并非每个管理员都是脚本编程高手。从另一个角度讲,图形界面接口像一个黑盒子,使许多管理员丧失了量身定制管理任务的机会与乐趣,只能亦步亦趋地跟在越来越多的向导屁股后面,不停地点按着"下一步"。
鉴于上述原因,微软在Windows Server 2003中,综合了WMI的强大与命令行的简洁,推出了全新的命令行管理工具WMIC,英文全称Windows Management Instrumentation Command-line,即Windows管理规范命令行。并声称使用WMIC,再配合其他现存的命令行工具,管理员几乎可以完成所有的管理任务,而不必再过多地依赖那些图形界面。
本文将对WMIC进行一个简单的介绍,由于笔者在撰稿时Windows Server 2003还没有正式发布,所以一切技术均以Windows Server 2003 RC2(Build 3718)为准,最终版本正式发布后可能会有变化。
背景:WMI、WBEM与CIM
关于WMI,我们在以前的文章中多次提及,并有过具体的应用,如《使用VS.NET实现WMI调用》(2003年1月刊),《限制域用户同时的多点登录》与《来一段脚本,Kill掉Mike的歌》(2003年2月刊)等。这里不准备再对其做详细的说明,只做一下简单的介绍。
WMI是微软基于Web的企业管理(WBEM)这一理念与标准的具体实现,并对CIM(Common Information Model,公用信息模型)提供完整的支持。WMI由符合CIM标准的对象储备库(Object Repository)和CIM对象管理器(WMI Object Manager)组成,其中对象储备库是对象定义的数据库,对象管理器负责处理储备库中对象的收集和操作,并从WMI提供程序(WMI Provider)收集信息。WMI提供程序在WMI与操作系统组件、应用程序和其他系统之间充当中间人角色,两者通过WMI提供程序交换信息。WMI提供程序的主要作用就是为WMI提供下层对象的相关信息,以及允许WMI通过它对下层对象进行管理。例如,注册表提供程序从注册表中提供信息,而SNMP提供程序则从SNMP设备中提供数据和事件等。
WMI被许多计算机管理工具所用,如Microsoft Systems Management Server、Microsoft Health Monitor和Microsoft Operations Manager等。
WMIC概述
WMIC,是一款新出现在Windows Server 2003中的命令行管理工具。使用WMIC,你不但可以管理本地计算机,而且可以管理同一Windows域内的所有远程计算机(需要必要的权限),而被管理的远程计算机不必事先安装WMIC,只需要支持WMI即可。
WMIC有一个能够分析、解释和执行从命令行接收的别名(Alias)的引擎,它是一个可执行文件,名为WMIC.exe,这个文件通常位于"c:\windows\
system32\wbem"文件夹中,该程序运行于用户当前登录的计算机上。任何对WMIC命令行的扩展性能都经过别名文件定义或者注册。别名又称友好名称(Friendly Names),通过MOF(Management Object Format,管理对象格式)格式定义。WMIC引擎接收到输入的命令后,先进行分析。如果命令是一个别名,WMIC会从当前操作命名空间(比如root\cli)调用该别名的定义,应用当前的环境设置(如目标命名空间),并将别名命令与它的原始命令进行对应,然后执行。
具体来说,你可以使用WMIC实现如下的管理任务:
1、本地计算机管理
2、远程单个计算机管理
3、远程多个计算机管理
4、使用远程会话的计算机管理(如Telnet)
5、使用管理脚本的自动管理
只有本地管理员组成员才能够启动WMIC,由于WMIC本质上是WMI的一个客户端,因此WMIC的安全受限于WMI的安全。当WMIC在一个远程会话中被使用时,如Telnet、终端服务等,缺省情况下,它使用发起此会话的用户的安全上下文。在使用WMIC管理一个远程计算机之前,WMIC会Ping一下远程计算机以确定其状态。
在使用WMIC命令行时,可以随时使用"/?"来获得当前命令上下文的帮助信息。
执行模式
WMIC可以以两种模式执行:交互模式(Interactive mode)和非交互模式(Non-Interactive mode),经常使用Netsh命令行的管理员应该非常熟悉这两种模式。
交互模式。如果你在命令提示符下或通过"运行"菜单只输入WMIC,都将进入WMIC的交互模式,每当一个命令执行完毕后,系统还会返回到WMIC提示符下,如"Root\cli",交互模式通常在需要执行多个WMIC指令时使用。当你需要先执行"CONTEXT"命令查看环境变量,再使用"OS"命令查看当前操作系统消息时,就可以使用交互模式,如图1所示。交互模式有时还会对一些敏感的操作要求确认,比如删除操作,最大限度地防止管理员出现失误。
非交互模式。非交互模式是指将WMIC指令直接作为WMIC的参数放在WMIC后面,当指令执行完毕后再返回到普通的命令提示符下,而不是进入到WMIC上下文环境中。WMIC的非交互模式主要用于批处理或者其他一些脚本文件中,比如上面的"OS"命令在非交互模式下就可以使用下面的方式执行:
wmic os /?
使用WMIC管理系统
WMIC包含了众多的开关、命令,以及内置的别名,详细内容见表1、表2和表3。下面让我们通过具体的实例体验一下WMIC的强大功能。
简单管理任务
使用WMIC,可以完成一些简单的管理任务,比如查看硬件与操作系统信息。如果不使用WMIC,查询硬件如BIOS、CPU、操作系统等信息,通常是使用系统提供的API接口进行编程,或者编写一小段脚本程序,是一件比较麻烦的事情,如表4所示就是一个查询BIOS信息的传统VBscript脚本。如果使用WMIC,那情况就大不相同,只需要一个简单命令就能搞定:
wmic bios list full
结果如图2所示。
大家可能注意到了上面命令行中还有两个参数list和full。list决定显示的信息格式与范围,它有Brief、Full、Instance、Status、System、Writeable等多个参数,full只是它的一个参数,也是list的缺省参数,表示显示所有的信息。其他几个参数顾名思义,如Brief表示只显示摘要信息,Instance表示只显示对象实例,Status表示显示对象状态,Writeable表示只显示该对象的可写入的属性信息等。
在管理过程中,尤其是进行远程系统管理的时候,管理员多数喜欢列一下进程列表,以了解当前系统中正在运行的程序。下面的命令就可以达到这一目的:
wmic process list brief
它会显示当前所有进程的一些摘要信息,比如进程名称、进程ID和优先级等。在我以前的文章《来一段脚本,Kill掉Mike的歌》中,就可以使用这一命令代替那个list.vbs脚本。
复杂管理任务
WMIC在完成复杂管理任务方面也是非常出色的,先看一下查询事件日志并生成结果文件的例子:
WMIC /node:"dc2" /user:"mytest" NTEVENTswheres"eventtype<3 and eventtype>0 AND logfile='Application'" GET Logfile, SourceName, Eventtype, Message, TimeGenerated /FORMAT:htable:"sortby=EventType">c:\Application.htm
这行长长的命令表示从计算机DC2中查询应用程序日志信息,事件类型为小于3且大于0的事件,通常是警告与错误事件。因为是远程计算机,所以命令中使用了"/node"和"/user"开关。输出结果保存为网页格式,保存在"c:\Application.htm"文件中,并以事件类型进行排序。当你使用上面的命令时,因为使用了"/user"开关,所以系统会首先提示你输入与该用户匹配的密码,如图3所示,查询结果如图4所示。
同样,你还可以使用WMIC同时重新启动多台被管理的服务器或工作站,命令如下:
WMIC /NODE:@"c:\MyServerList.txt" OSswheres(Primary="TRUE") CALL Win32ShutDown 6
WMIC会首先从"c:\MyServerList.txt"中取得服务器名称列表,这些服务器名称在文件中以逗号分割,如"dc1,dc2"。要注意的是,在/node开关后面使用服务器列表文件时,一定要在文件名的前面加上"@"引导符。该命令执行结果如图5所示,在执行重新启动过程中,WMIC会返回详细的执行结果。
WMIC还可以从Active Directory中取得数据,下面是一个从Active Directory中取得用户信息的例子,取得的用户信息包括显示名称、UPN名称、名称和创建时间等,返回结果如图6所示:
WMIC/NAMESPACE:\root\directory\ldap PATH ds_user GET ds_displayname, ds_userprincipalname, ds_cn, ds_name, ds_whencreated /VALUE
总结
WMIC是我所见到的基于windows平台的功能最强大的命令行工具,但同样也是最复杂的工具。尤其是在完成复杂的管理任务时,你需要对WMI的Win32类的属性及方法非常熟悉才可能做到游刃有余。因此,在希望熟悉运用WMIC之前,建议先学习WMI,熟悉其Win32类的各种属性及方法。国内现在出过几本不错的WMI书籍,你也可以到微软的MSDN网站(MSDN.microsoft.com)上查询这方面的信息。
有了WMIC的加入,命令行们应该可以大声说:"虽然我很丑,但是我很强大"了
WMIC从命令行对Windows的全面管理
从Windows 2000开始,WMI(Windows 管理规范)就是Windows系统管理的重要组成部分。WMIC是Windows Management Instrumentation Command-line的简称,在WMIC出现之前,要从命令行访问WMI数据库或WMI名称空间不是一件容易的事情。现在,WMIC利用WMI强大的功能把系统管理扩展到了命令行。
一、什么是WMIC?
WMIC扩展WMI,提供了从命令行接口和批命令脚本执行系统管理的支持。在WMIC出现之前,如果要管理WMI系统,必须使用一些专门的WMI应用,例如SMS,或者使用WMI的脚本编程API,或者使用象CIM Studio之类的工具。如果不熟悉C++之类的编成语言或VBScript之类的脚本语言,或者不掌握WMI名称空间的基本知识,要用WMI管理系统是很困难的。WMIC改变了这种情况,为WMI名称空间提供了一个强大的、友好的命令行接口。
WMIC比WMI简单、直观得多,这主要是由于使用了别名(Alias)。别名机制获取用户在命令行上输入的一些简单命令,按照预定义的方式操作WMI名称空间,例如根据一个简单的WMIC别名Get命令构造出一个复杂的WMI查询语言(WQL)命令。从这个意义上看,别名是用户和名称空间之间一个简化操作的中间层。例如,如果在WMIC命令行上执行下面这个简单的WMIC命令,就可以获得用户帐户的基本信息:
useraccount list brief
在上面的命令中,Useraccount别名执行了一个Win32_Useraccount类的WQL查询,以文本的形式显示出从该类提取的信息。另外,WMIC还以文本的形式显示出Win32_Useraccount类的属性。除了文本形式的输出之外,WMIC还能够以其他形式返回命令执行结果,例如XML、HTML或者CSV(逗号分隔的文本文件)。
WMIC以WMI模式中类的实例的形式保存别名。默认的别名类——MSFT_CliAlias,以及其他支持WMIC的类保存在模式的默认名称空间,或者说root\cli角色。角色可以简单地看成专门用来支持WMIC的另一个WMI名称空间。默认角色root\cli连接到root\cimv2名称空间,操作root\cimv2之内的类。虽然使用WMIC时一般不需要用到CIM Studio,但CIM Studio可以用来方便地查看root\cli名称空间。例如,图一显示了root\cli节点以及MSFT_CliAlias类的一些属性。
图一
你可以向root\cli名称空间和其他名称空间加入新的别名,还可以用Class和Path命令直接访问WMI名称空间,本文后面将详细说明Class和Path命令。
二、运行WMIC
执行“wmic”命令启动WMIC命令行环境。这个命令可以在XP或.NET Server的标准命令行解释器(cmd.exe)、Telnet会话或“运行”对话框中执行。这些启动方法可以在本地使用,也可以通过.NET Server终端服务会话使用。
第一次执行WMIC命令时,Windows首先要安装WMIC,然后显示出WMIC的命令行提示符。在WMIC命令行提示符上,命令以交互的方式执行。例如,执行下面的命令将关闭正在运行的Outlook:
process where name='outlook.exe' call terminate
命令运行结束后,WMIC命令行提示符重新出现,如图二所示。每个命令必须在一行之内输入,中间不能插入换行符。
图二
WMIC也可以按照非交互的模式运行。如果要执行某个单步的任务,或者运行批命令中的一系列WMIC命令,非交互模式就很有用。要使用非交互模式,只要在同一个命令行上启动WMIC并输入要执行的命令就可以了。例如,执行cmd.exe打开一个命令行窗口,然后执行下面的命令,就可以输出连接到MACHINE1的打印机清单:
wmic /node:MACHINE1 printer list status
在这个例子中,第一个操作是启动WMIC,然后是根据/node参数建立一个到MACHINE1的远程连接,最后执行一个WMIC命令显示出打印机状态信息。命令运行结束后,返回到Windows命令行提示符状态。
安装了WMIC的机器可以连接到任何一台安装了WMI的机器,被连接的机器不需要安装WMIC。例如,从一台运行Win XP Pro的机器启动WMIC,可以连接和管理所有运行着XP、Win2K、Windows NT 4.0、Windows Me和Windows 9x的机器。
三、WMIC命令行构成
WMIC提供了大量的全局开关、别名、动词、命令和丰富的命令行帮助增强用户接口。全局开关是适用于整个WMIC会话的配置选项。例如,/trace:on开关启用错误跟踪机制,如果这个开关处于打开状态,WMIC返回每一个命令的错误信息。利用/note开关可以访问远程机器,/interactive:on开关要求WMIC在执行删除操作之前提示确认,其他的全局开关还包括/role、/user、/implevel以及/namespace。
如前所述,别名是用户和WMI名称空间一个简化语法的中间层。当你指定一个别名时,动词(Verb)表示要执行的动作。例如,前面例子中的List和Call就是两个动词的例子。表一描述了其他一些WMIC动词,并为每一个动词给出了例子。
表一:WMIC动词
动词 例子 说明
Assoc group where name= 'administrators' assoc 显示出Administrators组与系统的所有关联,包括Administrators组成员等。又如,os assoc显示出有关操作系统的信息和已经安装的补丁。
Create environment create name="progloc", username="work01\User1",variablevalue= "%programfiles%\prog01" 创建一个名字为Progloc的变量,把它的值设置为Program Files文件夹的一个子文件夹,把这个变量加入到Work01工作组计算机User1帐户。
Delete environment where(name= "progloc") delete 删除Progloc环境变量。测试WMIC命令时,为了防止意外地删除,可以使用/interactive:on全局开关,这时删除之前会要求确认。
Get partition get bootpartition, description, deviceid, bootable 返回分区是否可启动、描述信息和设备ID属性等信息。
Set path WIN32_USERACCOUNT where(name="user01") set disabled="true" 在成员服务器或工作站上禁用User01用户帐户。
命令用来控制对WMIC和WMI名称空间的访问。注意表一的最后一个例子,这个例子用的是Path和Win32_USERACCOUNT类,而不是Useraccount别名。Path是一个直接访问WMI名称空间中实例的命令,不必再通过别名访问。如果待执行的系统管理任务没有现成的别名可用,Path命令特别有用。虽然你可以用新的别名和角色扩展WMIC,但如果你对WMI名称空间比较熟悉,使用Path命令也很方便
除了Path命令之外,WMIC还支持Class、Context、Quit和Exit命令。Class命令用来直接访问WMI模式内的类或创建现有类的实例。Class命令和Path命令的不同之处在于,Path命令的作用对象是实例以及它的属性(例如,提取管理用的信息),而Class命令的作用对象是类的定义。例如,如果要提取出WIN32_SOFTWAREELEMENT类的所有属性,可以执行如下命令:
class WIN32_SOFTWAREELEMENT get
这个命令的输出是HTML格式,稍后我们将了解如何用/output全局开关把输出重定向到可用浏览器打开的HTML文件。Class命令加上Assoc动词能够显示出类的名称空间路径以及其他与该类关联的类。利用Class命令可以删除类、创建类的实例,但不能创建类。
Context命令显示出全局开关的当前设置。Quit和Exit命令用来退出WMIC命令提示符环境,返回以前的Shell环境(例如Telnet环境,或XP的命令行提示符环境)。
命令行帮助是熟悉WMIC的有效途径。表二是在WMIC提示符下查找信息的常用命令:
表二:命令行帮助
命令 例子 说明
/? 或 -? 显示所有全局开关和别名的语法
/ /? /user /? 显示指定全局开关的信息
/? class /? 显示某个命令的信息
/? memcache /? 显示某个别名的信息
/? temperature get /? 显示别名与动词组合的信息
/?:Full irq get /?:Full 显示动词的帮助信息
四、实践应用
以上我们了解了WMIC命令行环境的基础知识,下面来看看如何用批命令运行WMIC,以及把输出结果定向到控制台或HTML、XML文件。从批命令文件运行WMIC的好处在于不需要重复输入一系列复杂的命令,例如,下面是一个批命令文件的内容,它的作用是显示出MACHINE1和MACHINE2这两台机器的CPU信息,输出结果显示在控制台上。/format开关是面向动词的开关,而不是全局开关,它只用于Get和List动词。
wmic /node:MACHINE1, MACHINE4 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xsl
WMIC批命令可以使用变量。也就是说,对于上面的批命令,服务器的名字不仅可以直接指定,而且还可以通过%1、%2的形式指定,下面就是一个例子。把下面的代码放入一个批命令文件,然后在执行批命令文件时加上一到二个机器的名字即可;另外,也可以创建一个独立的文本文件,然后在文本文件中放入机器名字的清单,清单可以是CSV格式,或用换行符分隔的格式。如果使用独立的文本文件提供机器名字,只需在/node全局开关后面加上以@符号为前缀的文本文件名字,@符号告诉/node开关后面的参数是一个文件名字而不是机器名字。
@echo offif "%1"=="" goto msgif "%2"=="" goto singlewmic /node:%1, %2 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xslgoto end:singlewmic /node:%1 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xslgoto end:msgecho 必须指定至少一台计算机的名字。:end
如前所述,WMIC命令的输出结果不仅可以发送到控制台,还可以发送到XML或HTML、MOF(Managed Object Format)格式的文件。在安装了WMI的计算机上,MOF是WMI数据库中类和类实例的原始保存形式。下面的例子显示了如何把MACHINE4处理器信息的查询结果输出到HTML文件,/output全局开关要求WMIC把输出发送到file1.htm,/format开关要求WMIC把原始的XML输出转换成HTML格式。用来转换格式的XSL样式文件既可以是自定义的,也可以是任何安装了WMIC的机器上\%systemroot%\system32\wbem文件夹下面的任意XSL文件。例如,利用csv.xsl样式文件可以把输出结果转换成CSV格式,利用htable.xsl样式可以构造出一个包含结果数据的表格。图三是在浏览器中打开的file1.htm文件。
wmic /node:MACHINE4 /output:e:\file1.htm cpu get description, maxclockspeed, extclock, manufacturer, revision /format:hform.xsl
图三
前面已经提到,Class命令加上Get动词的默认输出是HTML格式。因此,如果要把这类命令的输出结果保存到HTML文件,只需指定/output开关,不必加上/format开关。/record和/append全局开关也能够从WMIC命令行截取信息,请利用WMIC的命令行帮助功能了解有关这些开关的更多信息。
如果要以XML格式输出,用/translate开关和Basicxml关键词把大于符号“>”和小于符号“<”转换成XML中有意义的字符。下面是输出XML的一个例子,输出的XML数据可导入到数据库或其他能够理解XML标记的系统。下面代码的输出中包含了WMIC命令、命令行请求参数、目标节点、全局开关以及命令执行结果。
wmic cpu get maxclockspeed /translate:basicxml /format:rawxml.xsl
总之,WMIC是XP和.NET Server中命令行管理功能的一次重要改进,对于从命令行访问和管理WMI名称空间提供了强健的支持。虽然掌握和熟悉WMIC命令行环境需要一段时间,但只要你熟悉了它,一个系统管理的全新境界将展现在你的面前
WMIC从命令行对Windows的全面管理(2)
WMIC也可以按照非交互的模式运行。如果要执行某个单步的任务,或者运行批命令中的一系列WMIC命令,非交互模式就很有用。要使用非交互模式,只要在同一个命令行上启动WMIC并输入要执行的命令就可以了。例如,执行cmd.exe打开一个命令行窗口,然后执行下面的命令,就可以输出连接到MACHINE1的打印机清单:
wmic /node:MACHINE1 printer list status
在这个例子中,第一个操作是启动WMIC,然后是根据/node参数建立一个到MACHINE1的远程连接,最后执行一个WMIC命令显示出打印机状态信息。命令运行结束后,返回到Windows命令行提示符状态。
安装了WMIC的机器可以连接到任何一台安装了WMI的机器,被连接的机器不需要安装WMIC。例如,从一台运行Win XP Pro的机器启动WMIC,可以连接和管理所有运行着XP、Win2K、Windows NT 4.0、Windows Me和Windows 9x的机器。
三、WMIC命令行构成
WMIC提供了大量的全局开关、别名、动词、命令和丰富的命令行帮助增强用户接口。全局开关是适用于整个WMIC会话的配置选项。例如,/trace:on开关启用错误跟踪机制,如果这个开关处于打开状态,WMIC返回每一个命令的错误信息。利用/note开关可以访问远程机器,/interactive:on开关要求WMIC在执行删除操作之前提示确认,其他的全局开关还包括/role、/user、/implevel以及/namespace。
如前所述,别名是用户和WMI名称空间一个简化语法的中间层。当你指定一个别名时,动词(Verb)表示要执行的动作。例如,前面例子中的List和Call就是两个动词的例子。表一描述了其他一些WMIC动词,并为每一个动词给出了例子。
表一:WMIC动词
动词 例子 说明
Assoc group where name= 'administrators' assoc 显示出Administrators组与系统的所有关联,包括Administrators组成员等。又如,os assoc显示出有关操作系统的信息和已经安装的补丁。
Create environment create name="progloc", username="work01\User1",variablevalue= "%programfiles%\prog01" 创建一个名字为Progloc的变量,把它的值设置为Program Files文件夹的一个子文件夹,把这个变量加入到Work01工作组计算机User1帐户。
Delete environment where(name= "progloc") delete 删除Progloc环境变量。测试WMIC命令时,为了防止意外地删除,可以使用/interactive:on全局开关,这时删除之前会要求确认。
Get partition get bootpartition, description, deviceid, bootable 返回分区是否可启动、描述信息和设备ID属性等信息。
Set path WIN32_USERACCOUNT where(name="user01") set disabled="true" 在成员服务器或工作站上禁用User01用户帐户。
命令用来控制对WMIC和WMI名称空间的访问。注意表一的最后一个例子,这个例子用的是Path和Win32_USERACCOUNT类,而不是Useraccount别名。Path是一个直接访问WMI名称空间中实例的命令,不必再通过别名访问。如果待执行的系统管理任务没有现成的别名可用,Path命令特别有用。虽然你可以用新的别名和角色扩展WMIC,但如果你对WMI名称空间比较熟悉,使用Path命令也很方便
除了Path命令之外,WMIC还支持Class、Context、Quit和Exit命令。Class命令用来直接访问WMI模式内的类或创建现有类的实例。Class命令和Path命令的不同之处在于,Path命令的作用对象是实例以及它的属性(例如,提取管理用的信息),而Class命令的作用对象是类的定义。例如,如果要提取出WIN32_SOFTWAREELEMENT类的所有属性,可以执行如下命令:
class WIN32_SOFTWAREELEMENT get
这个命令的输出是HTML格式,稍后我们将了解如何用/output全局开关把输出重定向到可用浏览器打开的HTML文件。Class命令加上Assoc动词能够显示出类的名称空间路径以及其他与该类关联的类。利用Class命令可以删除类、创建类的实例,但不能创建类。
Context命令显示出全局开关的当前设置。Quit和Exit命令用来退出WMIC命令提示符环境,返回以前的Shell环境(例如Telnet环境,或XP的命令行提示符环境)。
命令行帮助是熟悉WMIC的有效途径。表二是在WMIC提示符下查找信息的常用命令:
表二:命令行帮助
命令 例子 说明
/? 或 -? 显示所有全局开关和别名的语法
/ /? /user /? 显示指定全局开关的信息
/? class /? 显示某个命令的信息
/? memcache /? 显示某个别名的信息
/? temperature get /? 显示别名与动词组合的信息
/?:Full irq get /?:Full 显示动词的帮助信息
四、实践应用
以上我们了解了WMIC命令行环境的基础知识,下面来看看如何用批命令运行WMIC,以及把输出结果定向到控制台或HTML、XML文件。从批命令文件运行WMIC的好处在于不需要重复输入一系列复杂的命令,例如,下面是一个批命令文件的内容,它的作用是显示出MACHINE1和MACHINE2这两台机器的CPU信息,输出结果显示在控制台上。/format开关是面向动词的开关,而不是全局开关,它只用于Get和List动词。
wmic /node:MACHINE1, MACHINE4 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xsl
WMIC批命令可以使用变量。也就是说,对于上面的批命令,服务器的名字不仅可以直接指定,而且还可以通过%1、%2的形式指定,下面就是一个例子。把下面的代码放入一个批命令文件,然后在执行批命令文件时加上一到二个机器的名字即可;另外,也可以创建一个独立的文本文件,然后在文本文件中放入机器名字的清单,清单可以是CSV格式,或用换行符分隔的格式。如果使用独立的文本文件提供机器名字,只需在/node全局开关后面加上以@符号为前缀的文本文件名字,@符号告诉/node开关后面的参数是一个文件名字而不是机器名字。
@echo offif "%1"=="" goto msgif "%2"=="" goto singlewmic /node:%1, %2 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xslgoto end:singlewmic /node:%1 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xslgoto end:msgecho 必须指定至少一台计算机的名字。:end
如前所述,WMIC命令的输出结果不仅可以发送到控制台,还可以发送到XML或HTML、MOF(Managed Object Format)格式的文件。在安装了WMI的计算机上,MOF是WMI数据库中类和类实例的原始保存形式。下面的例子显示了如何把MACHINE4处理器信息的查询结果输出到HTML文件,/output全局开关要求WMIC把输出发送到file1.htm,/format开关要求WMIC把原始的XML输出转换成HTML格式。用来转换格式的XSL样式文件既可以是自定义的,也可以是任何安装了WMIC的机器上\%systemroot%\system32\wbem文件夹下面的任意XSL文件。例如,利用csv.xsl样式文件可以把输出结果转换成CSV格式,利用htable.xsl样式可以构造出一个包含结果数据的表格。图三是在浏览器中打开的file1.htm文件。
wmic /node:MACHINE4 /output:e:\file1.htm cpu get description, maxclockspeed, extclock, manufacturer, revision /format:hform.xsl
前面已经提到,Class命令加上Get动词的默认输出是HTML格式。因此,如果要把这类命令的输出结果保存到HTML文件,只需指定/output开关,不必加上/format开关。/record和/append全局开关也能够从WMIC命令行截取信息,请利用WMIC的命令行帮助功能了解有关这些开关的更多信息。
如果要以XML格式输出,用/translate开关和Basicxml关键词把大于符号“>”和小于符号“<”转换成XML中有意义的字符。下面是输出XML的一个例子,输出的XML数据可导入到数据库或其他能够理解XML标记的系统。下面代码的输出中包含了WMIC命令、命令行请求参数、目标节点、全局开关以及命令执行结果。
wmic cpu get maxclockspeed /translate:basicxml /format:rawxml.xsl
总之,WMIC是XP和.NET Server中命令行管理功能的一次重要改进,对于从命令行访问和管理WMI名称空间提供了强健的支持。虽然掌握和熟悉WMIC命令行环境需要一段时间,但只要你熟悉了它,一个系统管理的全新境界将展现在你的面前
This is my last post in the forum. I hope everyone will forgive what I said before, please forgive me!
WMIC: A Brand-New Super Command-Line Management Tool
While the graphical interface of Microsoft Windows Server provides convenience for network management, it has been criticized by Windows administrators for consuming excessive resources and operating slowly. To provide an alternative to the graphical management interface, Microsoft has introduced the brand-new command-line management tool WMIC, which combines the power of WMI with the simplicity of the command line. It is claimed that the command line of Windows Server 2003 with WMIC can perform almost all management tasks.
Microsoft, which started with DOS, finally dominated the world with the graphical interface. The traditional graphical interface of Microsoft Windows Server, while making system management simple and easy, has excessive resource consumption and slow operation speed, which not only makes many IT Pro-level system administrators complain but also makes it difficult for many system administrators switching from Unix and NetWare to adapt in a short time. Although Microsoft has developed WMI (Windows Management Instrumentation) and provided a large number of WMI-based scripts in Support Tools and Resource Kits for administrators to use for server management from the command line, complex script programming also deters many administrators because not every administrator is a script programming expert. From another perspective, the graphical interface is like a black box, depriving many administrators of the opportunity and fun to tailor management tasks, and they can only follow more and more wizards step by step, constantly clicking "Next".
In view of the above reasons, Microsoft integrated the power of WMI with the simplicity of the command line in Windows Server 2003 and launched the brand-new command-line management tool WMIC, whose full English name is Windows Management Instrumentation Command-line. And it is claimed that by using WMIC and other existing command-line tools, administrators can almost complete all management tasks without relying too much on those graphical interfaces.
This article will give a simple introduction to WMIC. Since Windows Server 2003 was not officially released when the author was writing, all technologies are based on Windows Server 2003 RC2 (Build 3718), and there may be changes after the final version is officially released.
Background: WMI, WBEM, and CIM
We have mentioned WMI many times in previous articles and have had specific applications, such as "Using VS.NET to Implement WMI Calls" (January 2003 issue), "Limiting Multi-Point Logins of Domain Users" and "Write a Script to Kill Mike's Song" (February 2003 issue), etc. Here, it will not be explained in detail but only briefly introduced.
WMI is a specific implementation of Microsoft based on the concept and standard of Web-based Enterprise Management (WBEM) and provides complete support for CIM (Common Information Model). WMI consists of an object repository (Object Repository) that complies with CIM standards and a CIM object manager (WMI Object Manager). The object repository is a database for object definitions, and the object manager is responsible for processing the collection and operation of objects in the repository and collecting information from WMI providers (WMI Provider). The WMI provider acts as an intermediary between WMI and operating system components, applications, and other systems, and the two exchange information through the WMI provider. The main function of the WMI provider is to provide relevant information of the lower-layer objects for WMI and allow WMI to manage the lower-layer objects through it. For example, the registry provider provides information from the registry, and the SNMP provider provides data and events from SNMP devices, etc.
WMI is used by many computer management tools, such as Microsoft Systems Management Server, Microsoft Health Monitor, and Microsoft Operations Manager, etc.
Overview of WMIC
WMIC is a newly appeared command-line management tool in Windows Server 2003. With WMIC, you can not only manage the local computer but also manage all remote computers in the same Windows domain (with necessary permissions), and the managed remote computers do not need to install WMIC in advance, only need to support WMI.
WMIC has an engine that can analyze, interpret, and execute aliases (Alias) received from the command line. It is an executable file named WMIC.exe, which is usually located in the "c:\windows\system32\wbem" folder and runs on the computer where the user is currently logged in. Any extended performance of the WMIC command line is defined or registered through the alias file. Alias is also called a friendly name (Friendly Names) and is defined in the MOF (Management Object Format) format. After receiving the input command, the WMIC engine first analyzes it. If the command is an alias, WMIC will call the definition of the alias from the current operation namespace (such as root\cli), apply the current environment settings (such as the target namespace), and correspond the alias command with its original command, and then execute it.
Specifically, you can use WMIC to achieve the following management tasks:
1. Local computer management
2. Remote single computer management
3. Remote multiple computer management
4. Computer management using remote sessions (such as Telnet)
5. Automatic management using management scripts
Only members of the local administrator group can start WMIC. Since WMIC is essentially a client of WMI, the security of WMIC is limited by the security of WMI. When WMIC is used in a remote session, such as Telnet, terminal services, etc., by default, it uses the security context of the user who initiated this session. Before using WMIC to manage a remote computer, WMIC will ping the remote computer to determine its status.
When using the WMIC command line, you can always use "/?" to get help information of the current command context.
Execution Modes
WMIC can be executed in two modes: interactive mode (Interactive mode) and non-interactive mode (Non-Interactive mode). Administrators who often use the Netsh command line should be very familiar with these two modes.
Interactive mode. If you only enter "WMIC" at the command prompt or through the "Run" menu, you will enter the interactive mode of WMIC. Whenever a command is executed, the system will return to the WMIC prompt, such as "Root\cli". Interactive mode is usually used when multiple WMIC instructions need to be executed. When you need to first execute the "CONTEXT" command to view environment variables and then use the "OS" command to view current operating system messages, you can use interactive mode, as shown in Figure 1. Interactive mode sometimes also requires confirmation for some sensitive operations, such as deletion operations, to prevent administrators from making mistakes to the greatest extent.
Non-interactive mode. Non-interactive mode means directly putting the WMIC instruction as a parameter of WMIC after WMIC. After the instruction is executed, it returns to the ordinary command prompt instead of entering the WMIC context environment. The non-interactive mode of WMIC is mainly used in batch processing or other script files. For example, the above "OS" command can be executed in non-interactive mode in the following way:
wmic os /?
Managing the System with WMIC
WMIC contains many switches, commands, and built-in aliases. The detailed contents are shown in Tables 1, 2, and 3. Let's experience the powerful functions of WMIC through specific examples.
Simple Management Tasks
With WMIC, some simple management tasks can be completed, such as viewing hardware and operating system information. If WMIC is not used, querying hardware such as BIOS, CPU, operating system, etc., is usually to program using the API interface provided by the system or write a short script program, which is a relatively troublesome thing. For example, Table 4 is a traditional VBScript script for querying BIOS information. If WMIC is used, the situation is completely different, and only a simple command can be used to get it done:
wmic bios list full
The result is shown in Figure 2.
You may have noticed that there are also two parameters list and full in the above command line. list determines the information format and range to be displayed. It has multiple parameters such as Brief, Full, Instance, Status, System, Writeable, etc. full is just one of its parameters and is also the default parameter of list, which means displaying all information. The other parameters are as the name implies. For example, Brief means displaying only summary information, Instance means displaying only object instances, Status means displaying object status, Writeable means displaying only the writable attribute information of the object, etc.
In the management process, especially when performing remote system management, administrators mostly like to list the process list to understand the programs running in the current system. The following command can achieve this purpose:
wmic process list brief
It will display some summary information of all current processes, such as process name, process ID, and priority, etc. In my previous article "Write a Script to Kill Mike's Song", this command can be used to replace that list.vbs script.
Complex Management Tasks
WMIC is also very excellent in completing complex management tasks. Let's first look at an example of querying event logs and generating a result file:
WMIC /node:"dc2" /user:"mytest" NTEVENTswheres"eventtype<3 and eventtype>0 AND logfile='Application'" GET Logfile, SourceName, Eventtype, Message, TimeGenerated /FORMAT:htable:"sortby=EventType">c:\Application.htm
This long command means querying application log information from the computer DC2. The event type is an event less than 3 and greater than 0, which are usually warning and error events. Since it is a remote computer, the "/node" and "/user" switches are used in the command. The output result is saved in web page format, saved in the "c:\Application.htm" file, and sorted by event type. When you use the above command, because the "/user" switch is used, the system will first prompt you to enter the password matching this user, as shown in Figure 3, and the query result is shown in Figure 4.
Similarly, you can also use WMIC to restart multiple managed servers or workstations at the same time. The command is as follows:
WMIC /NODE:@"c:\MyServerList.txt" OSswheres(Primary="TRUE") CALL Win32ShutDown 6
WMIC will first obtain the server name list from "c:\MyServerList.txt", and these server names are separated by commas in the file, such as "dc1,dc2". It should be noted that when using the server list file after the /node switch, you must add the "@" guide character in front of the file name. The execution result of this command is shown in Figure 5. During the restart process, WMIC will return detailed execution results.
WMIC can also obtain data from Active Directory. The following is an example of obtaining user information from Active Directory. The obtained user information includes display name, UPN name, name, creation time, etc. The returned result is shown in Figure 6:
WMIC/NAMESPACE:\root\directory\ldap PATH ds_user GET ds_displayname, ds_userprincipalname, ds_cn, ds_name, ds_whencreated /VALUE
Summary
WMIC is the most powerful command-line tool based on the Windows platform that I have seen, but it is also the most complex tool. Especially when completing complex management tasks, you need to be very familiar with the properties and methods of the Win32 classes of WMI to be able to handle it with ease. Therefore, it is recommended to learn WMI first and be familiar with various properties and methods of its Win32 classes before hoping to be proficient in using WMIC. There are several good WMI books in China now, and you can also query information in this regard on Microsoft's MSDN website (MSDN.microsoft.com).
With the addition of WMIC, command lines can say loudly: "Although I am ugly, I am powerful"
WMIC: A Brand-New Super Command-Line Management Tool
While the graphical interface of Microsoft Windows Server provides convenience for network management, it has been criticized by Windows administrators for consuming excessive resources and operating slowly. To provide an alternative to the graphical management interface, Microsoft has introduced the brand-new command-line management tool WMIC, which combines the power of WMI with the simplicity of the command line. It is claimed that the command line of Windows Server 2003 with WMIC can perform almost all management tasks.
Microsoft, which started with DOS, finally dominated the world with the graphical interface. The traditional graphical interface of Microsoft Windows Server, while making system management simple and easy, has excessive resource consumption and slow operation speed, which not only makes many IT Pro-level system administrators complain but also makes it difficult for many system administrators switching from Unix and NetWare to adapt in a short time. Although Microsoft has developed WMI (Windows Management Instrumentation) and provided a large number of WMI-based scripts in Support Tools and Resource Kits for administrators to use for server management from the command line, complex script programming also deters many administrators because not every administrator is a script programming expert. From another perspective, the graphical interface is like a black box, depriving many administrators of the opportunity and fun to tailor management tasks, and they can only follow more and more wizards step by step, constantly clicking "Next".
In view of the above reasons, Microsoft integrated the power of WMI with the simplicity of the command line in Windows Server 2003 and launched the brand-new command-line management tool WMIC, whose full English name is Windows Management Instrumentation Command-line. And it is claimed that by using WMIC and other existing command-line tools, administrators can almost complete all management tasks without relying too much on those graphical interfaces.
This article will give a simple introduction to WMIC. Since Windows Server 2003 was not officially released when the author was writing, all technologies are based on Windows Server 2003 RC2 (Build 3718), and there may be changes after the final version is officially released.
Background: WMI, WBEM, and CIM
We have mentioned WMI many times in previous articles and have had specific applications, such as "Using VS.NET to Implement WMI Calls" (January 2003 issue), "Limiting Multi-Point Logins of Domain Users" and "Write a Script to Kill Mike's Song" (February 2003 issue), etc. Here, it will not be explained in detail but only briefly introduced.
WMI is a specific implementation of Microsoft based on the concept and standard of Web-based Enterprise Management (WBEM) and provides complete support for CIM (Common Information Model). WMI consists of an object repository (Object Repository) that complies with CIM standards and a CIM object manager (WMI Object Manager). The object repository is a database for object definitions, and the object manager is responsible for processing the collection and operation of objects in the repository and collecting information from WMI providers (WMI Provider). The WMI provider acts as an intermediary between WMI and operating system components, applications, and other systems, and the two exchange information through the WMI provider. The main function of the WMI provider is to provide relevant information of the lower-layer objects for WMI and allow WMI to manage the lower-layer objects through it. For example, the registry provider provides information from the registry, and the SNMP provider provides data and events from SNMP devices, etc.
WMI is used by many computer management tools, such as Microsoft Systems Management Server, Microsoft Health Monitor, and Microsoft Operations Manager, etc.
Overview of WMIC
WMIC is a newly appeared command-line management tool in Windows Server 2003. With WMIC, you can not only manage the local computer but also manage all remote computers in the same Windows domain (with necessary permissions), and the managed remote computers do not need to install WMIC in advance, only need to support WMI.
WMIC has an engine that can analyze, interpret, and execute aliases (Alias) received from the command line. It is an executable file named WMIC.exe, which is usually located in the "c:\windows\system32\wbem" folder and runs on the computer where the user is currently logged in. Any extended performance of the WMIC command line is defined or registered through the alias file. Alias is also called a friendly name (Friendly Names) and is defined in the MOF (Management Object Format) format. After receiving the input command, the WMIC engine first analyzes it. If the command is an alias, WMIC will call the definition of the alias from the current operation namespace (such as root\cli), apply the current environment settings (such as the target namespace), and correspond the alias command with its original command, and then execute it.
Specifically, you can use WMIC to achieve the following management tasks:
1. Local computer management
2. Remote single computer management
3. Remote multiple computer management
4. Computer management using remote sessions (such as Telnet)
5. Automatic management using management scripts
Only members of the local administrator group can start WMIC. Since WMIC is essentially a client of WMI, the security of WMIC is limited by the security of WMI. When WMIC is used in a remote session, such as Telnet, terminal services, etc., by default, it uses the security context of the user who initiated this session. Before using WMIC to manage a remote computer, WMIC will ping the remote computer to determine its status.
When using the WMIC command line, you can always use "/?" to get help information of the current command context.
Execution Modes
WMIC can be executed in two modes: interactive mode (Interactive mode) and non-interactive mode (Non-Interactive mode). Administrators who often use the Netsh command line should be very familiar with these two modes.
Interactive mode. If you only enter "WMIC" at the command prompt or through the "Run" menu, you will enter the interactive mode of WMIC. Whenever a command is executed, the system will return to the WMIC prompt, such as "Root\cli". Interactive mode is usually used when multiple WMIC instructions need to be executed. When you need to first execute the "CONTEXT" command to view environment variables and then use the "OS" command to view current operating system messages, you can use interactive mode, as shown in Figure 1. Interactive mode sometimes also requires confirmation for some sensitive operations, such as deletion operations, to prevent administrators from making mistakes to the greatest extent.
Non-interactive mode. Non-interactive mode means directly putting the WMIC instruction as a parameter of WMIC after WMIC. After the instruction is executed, it returns to the ordinary command prompt instead of entering the WMIC context environment. The non-interactive mode of WMIC is mainly used in batch processing or other script files. For example, the above "OS" command can be executed in non-interactive mode in the following way:
wmic os /?
Managing the System with WMIC
WMIC contains many switches, commands, and built-in aliases. The detailed contents are shown in Tables 1, 2, and 3. Let's experience the powerful functions of WMIC through specific examples.
Simple Management Tasks
With WMIC, some simple management tasks can be completed, such as viewing hardware and operating system information. If WMIC is not used, querying hardware such as BIOS, CPU, operating system, etc., is usually to program using the API interface provided by the system or write a short script program, which is a relatively troublesome thing. For example, Table 4 is a traditional VBScript script for querying BIOS information. If WMIC is used, the situation is completely different, and only a simple command can be used to get it done:
wmic bios list full
The result is shown in Figure 2.
You may have noticed that there are also two parameters list and full in the above command line. list determines the information format and range to be displayed. It has multiple parameters such as Brief, Full, Instance, Status, System, Writeable, etc. full is just one of its parameters and is also the default parameter of list, which means displaying all information. The other parameters are as the name implies. For example, Brief means displaying only summary information, Instance means displaying only object instances, Status means displaying object status, Writeable means displaying only the writable attribute information of the object, etc.
In the management process, especially when performing remote system management, administrators mostly like to list the process list to understand the programs running in the current system. The following command can achieve this purpose:
wmic process list brief
It will display some summary information of all current processes, such as process name, process ID, and priority, etc. In my previous article "Write a Script to Kill Mike's Song", this command can be used to replace that list.vbs script.
Complex Management Tasks
WMIC is also very excellent in completing complex management tasks. Let's first look at an example of querying event logs and generating a result file:
WMIC /node:"dc2" /user:"mytest" NTEVENTswheres"eventtype<3 and eventtype>0 AND logfile='Application'" GET Logfile, SourceName, Eventtype, Message, TimeGenerated /FORMAT:htable:"sortby=EventType">c:\Application.htm
This long command means querying application log information from the computer DC2. The event type is an event less than 3 and greater than 0, which are usually warning and error events. Since it is a remote computer, the "/node" and "/user" switches are used in the command. The output result is saved in web page format, saved in the "c:\Application.htm" file, and sorted by event type. When you use the above command, because the "/user" switch is used, the system will first prompt you to enter the password matching this user, as shown in Figure 3, and the query result is shown in Figure 4.
Similarly, you can also use WMIC to restart multiple managed servers or workstations at the same time. The command is as follows:
WMIC /NODE:@"c:\MyServerList.txt" OSswheres(Primary="TRUE") CALL Win32ShutDown 6
WMIC will first obtain the server name list from "c:\MyServerList.txt", and these server names are separated by commas in the file, such as "dc1,dc2". It should be noted that when using the server list file after the /node switch, you must add the "@" guide character in front of the file name. The execution result of this command is shown in Figure 5. During the restart process, WMIC will return detailed execution results.
WMIC can also obtain data from Active Directory. The following is an example of obtaining user information from Active Directory. The obtained user information includes display name, UPN name, name, creation time, etc. The returned result is shown in Figure 6:
WMIC/NAMESPACE:\root\directory\ldap PATH ds_user GET ds_displayname, ds_userprincipalname, ds_cn, ds_name, ds_whencreated /VALUE
Summary
WMIC is the most powerful command-line tool based on the Windows platform that I have seen, but it is also the most complex tool. Especially when completing complex management tasks, you need to be very familiar with the properties and methods of the Win32 classes of WMI to be able to handle it with ease. Therefore, it is recommended to learn WMI first and be familiar with various properties and methods of its Win32 classes before hoping to be proficient in using WMIC. There are several good WMI books in China now, and you can also query information in this regard on Microsoft's MSDN website (MSDN.microsoft.com).
With the addition of WMIC, command lines can say loudly: "Although I am ugly, I am powerful"
WMIC: Comprehensive Management of Windows from the Command Line
Since Windows 2000, WMI (Windows Management Instrumentation) has been an important part of Windows system management. WMIC is the abbreviation of Windows Management Instrumentation Command-line. Before the appearance of WMIC, it was not an easy thing to access the WMI database or WMI namespace from the command line. Now, WMIC expands system management to the command line by using the powerful functions of WMI.
1. What is WMIC?
WMIC expands WMI and provides support for performing system management from the command line interface and batch command scripts. Before the appearance of WMIC, if you wanted to manage the WMI system, you had to use some special WMI applications, such as SMS, or use the WMI script programming API, or use tools like CIM Studio. If you are not familiar with programming languages like C++ or script languages like VBScript, or do not master the basic knowledge of the WMI namespace, it is very difficult to manage the system with WMI. WMIC changes this situation and provides a powerful and friendly command-line interface for the WMI namespace.
WMIC is much simpler and more intuitive than WMI, mainly because of the use of aliases (Alias). The alias mechanism obtains some simple commands entered by the user on the command line and operates the WMI namespace in a predefined way. For example, a complex WMI Query Language (WQL) command is constructed according to a simple WMIC alias Get command. In this sense, the alias is an intermediate layer that simplifies the operation between the user and the namespace. For example, if you execute the following simple WMIC command on the WMIC command line, you can obtain the basic information of the user account:
useraccount list brief
In the above command, the Useraccount alias executes a WQL query of the Win32_Useraccount class and displays the information extracted from this class in text form. In addition, WMIC also displays the properties of the Win32_Useraccount class in text form. In addition to text form output, WMIC can also return command execution results in other forms, such as XML, HTML, or CSV (comma-separated text file).
WMIC saves aliases in the form of instances of classes in the WMI mode. The default alias class - MSFT_CliAlias, and other classes that support WMIC are saved in the default namespace of the mode, or the root\cli role. The role can simply be regarded as another WMI namespace specially used to support WMIC. The default role root\cli is connected to the root\cimv2 namespace and operates the classes within root\cimv2. Although CIM Studio is generally not needed when using WMIC, CIM Studio can be used to conveniently view the root\cli namespace. For example, Figure 1 shows the root\cli node and some properties of the MSFT_CliAlias class.
Figure 1
You can add new aliases to the root\cli namespace and other namespaces, and you can also directly access the WMI namespace using the Class and Path commands. The Class and Path commands will be described in detail later in this article.
2. Running WMIC
Execute the "wmic" command to start the WMIC command line environment. This command can be executed in the standard command line interpreter (cmd.exe) of XP or.NET Server, Telnet session, or "Run" dialog box. These startup methods can be used locally or through the.NET Server terminal services session.
When executing the WMIC command for the first time, Windows will first install WMIC and then display the command line prompt of WMIC. On the WMIC command line prompt, commands are executed interactively. For example, executing the following command will close the running Outlook:
process where name='outlook.exe' call terminate
After the command is run, the WMIC command line prompt reappears, as shown in Figure 2. Each command must be entered in one line without inserting line breaks.
Figure 2
WMIC can also run in non-interactive mode. Non-interactive mode is very useful if you want to perform a single-step task or run a series of WMIC commands in a batch command. To use non-interactive mode, just start WMIC on the same command line and enter the command to be executed. For example, execute cmd.exe to open a command line window, and then execute the following command to output the printer list connected to MACHINE1:
wmic /node:MACHINE1 printer list status
In this example, the first operation is to start WMIC, then establish a remote connection to MACHINE1 according to the /node parameter, and finally execute a WMIC command to display the printer status information. After the command is run, it returns to the Windows command line prompt state.
A machine with WMIC installed can connect to any machine with WMI installed, and the connected machine does not need to install WMIC. For example, starting WMIC from a machine running Win XP Pro can connect and manage all machines running XP, Win2K, Windows NT 4.0, Windows Me, and Windows 9x.
3. Composition of the WMIC Command Line
WMIC provides a large number of global switches, aliases, verbs, commands, and rich command line help to enhance the user interface. Global switches are configuration options applicable to the entire WMIC session. For example, the /trace:on switch enables the error tracking mechanism. If this switch is on, WMIC returns the error information of each command. The /note switch can be used to access remote machines, the /interactive:on switch requires WMIC to prompt for confirmation before performing deletion operations. Other global switches also include /role, /user, /implevel, and /namespace.
As mentioned earlier, the alias is an intermediate layer that simplifies the syntax between the user and the WMI namespace. When you specify an alias, the verb (Verb) indicates the action to be executed. For example, List and Call in the previous example are examples of two verbs. Table 1 describes other WMIC verbs and gives examples for each verb.
Table 1: WMIC Verbs
Verb Example Description
Assoc group where name= 'administrators' assoc Displays all associations between the Administrators group and the system, including members of the Administrators group, etc. For another example, os assoc displays information about the operating system and installed patches.
Create environment create name="progloc", username="work01\User1",variablevalue= "%programfiles%\prog01" Creates a variable named Progloc, sets its value to a subfolder of the Program Files folder, and adds this variable to the User1 account of the Work01 workgroup computer.
Delete environment where(name= "progloc") delete Deletes the Progloc environment variable. When testing WMIC commands, to prevent accidental deletion, you can use the /interactive:on global switch, and confirmation will be required before deletion.
Get partition get bootpartition, description, deviceid, bootable Returns information such as whether the partition is bootable, description information, and device ID attributes.
Set path WIN32_USERACCOUNT where(name="user01") set disabled="true" Disables the User01 user account on the member server or workstation.
The command is used to control access to WMIC and the WMI namespace. Note the last example in Table 1. This example uses the Path and Win32_USERACCOUNT classes instead of the Useraccount alias. The Path is a command to directly access the instance in the WMI namespace without accessing through the alias. The Path command is especially useful if there is no ready-made alias available for the system management task to be executed. Although you can expand WMIC with new aliases and roles, if you are familiar with the WMI namespace, using the Path command is also convenient
In addition to the Path command, WMIC also supports the Class, Context, Quit, and Exit commands. The Class command is used to directly access the classes in the WMI mode or create instances of existing classes. The difference between the Class command and the Path command is that the Path command acts on instances and their properties (for example, extracting management information), while the Class command acts on the definition of the class. For example, if you want to extract all properties of the WIN32_SOFTWAREELEMENT class, you can execute the following command:
class WIN32_SOFTWAREELEMENT get
The output of this command is in HTML format. We will later understand how to use the /output global switch to redirect the output to an HTML file that can be opened by a browser. The Class command plus the Assoc verb can display the namespace path of the class and other classes associated with this class. The Class command can be used to delete classes and create instances of classes, but cannot create classes.
The Context command displays the current settings of the global switch. The Quit and Exit commands are used to exit the WMIC command prompt environment and return to the previous Shell environment (for example, Telnet environment or XP command line prompt environment).
Command line help is an effective way to be familiar with WMIC. Table 2 is a common command for finding information under the WMIC prompt:
Table 2: Command Line Help
Command Example Description
/? or -? Displays the syntax of all global switches and aliases
/ /? /user /? Displays information about the specified global switch
/? class /? Displays information about a certain command
/? memcache /? Displays information about a certain alias
/? temperature get /? Displays information about the combination of alias and verb
/?:Full irq get /?:Full Displays help information about the verb
4. Practical Applications
We have understood the basic knowledge of the WMIC command line environment above. Let's see how to run WMIC with batch commands and redirect the output result to the console or HTML, XML files. The advantage of running WMIC from a batch command file is that there is no need to repeatedly enter a series of complex commands. For example, the following is the content of a batch command file, which is used to display the CPU information of the two machines MACHINE1 and MACHINE2, and the output result is displayed on the console. The /format switch is a verb-oriented switch, not a global switch, and it is only used for the Get and List verbs.
wmic /node:MACHINE1, MACHINE4 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xsl
WMIC batch commands can use variables. That is to say, for the above batch command, the name of the server can not only be directly specified but also can be specified in the form of %1, %2. The following is an example. Put the following code into a batch command file, and then add one or two machine names when executing the batch command file; in addition, you can also create an independent text file and put the list of machine names in the text file. The list can be in CSV format or in the format separated by line breaks. If an independent text file is used to provide the machine names, you only need to add the text file name prefixed with the @ symbol after the /node global switch. The @ symbol tells the /node switch that the parameter behind is a file name instead of a machine name.
@echo offif "%1"=="" goto msgif "%2"=="" goto singlewmic /node:%1, %2 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xslgoto end:singlewmic /node:%1 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xslgoto end:msgecho 必须指定至少一台计算机的名字。:end
As mentioned earlier, the output result of the WMIC command can not only be sent to the console but also to XML or HTML, MOF (Managed Object Format) format files. On a computer with WMI installed, MOF is the original form for saving classes and class instances in the WMI database. The following example shows how to output the query result of the MACHINE4 processor information to an HTML file. The /output global switch requires WMIC to send the output to file1.htm, and the /format switch requires WMIC to convert the original XML output into HTML format. The XSL style file used for conversion can be a custom one or any XSL file in the \%systemroot%\system32\wbem folder of any machine with WMIC installed. For example, using the csv.xsl style file can convert the output result into CSV format, and using the htable.xsl style can construct a table containing the result data. Figure 3 is the file1.htm file opened in the browser.
wmic /node:MACHINE4 /output:e:\file1.htm cpu get description, maxclockspeed, extclock, manufacturer, revision /format:hform.xsl
Figure 3
It has been mentioned earlier that the default output of the Class command plus the Get verb is in HTML format. Therefore, if you want to save the output result of such a command to an HTML file, you only need to specify the /output switch without adding the /format switch. The /record and /append global switches can also intercept information from the WMIC command line. Please use the command line help function of WMIC to understand more information about these switches.
If you want to output in XML format, use the /translate switch and the Basicxml keyword to convert the greater-than symbol ">" and less-than symbol "<" into meaningful characters in XML. The following is an example of outputting XML. The output XML data can be imported into a database or other systems that can understand XML tags. The output of the following code includes the WMIC command, command line request parameters, target node, global switch, and command execution result.
wmic cpu get maxclockspeed /translate:basicxml /format:rawxml.xsl
In conclusion, WMIC is an important improvement in the command line management function in XP and.NET Server, and it provides robust support for accessing and managing the WMI namespace from the command line. Although it takes some time to master and be familiar with the WMIC command line environment, once you are familiar with it, a brand-new realm of system management will unfold in front of you
WMIC: Comprehensive Management of Windows from the Command Line (2)
WMIC can also run in non-interactive mode. Non-interactive mode is very useful if you want to perform a single-step task or run a series of WMIC commands in a batch command. To use non-interactive mode, just start WMIC on the same command line and enter the command to be executed. For example, execute cmd.exe to open a command line window, and then execute the following command to output the printer list connected to MACHINE1:
wmic /node:MACHINE1 printer list status
In this example, the first operation is to start WMIC, then establish a remote connection to MACHINE1 according to the /node parameter, and finally execute a WMIC command to display the printer status information. After the command is run, it returns to the Windows command line prompt state.
A machine with WMIC installed can connect to any machine with WMI installed, and the connected machine does not need to install WMIC. For example, starting WMIC from a machine running Win XP Pro can connect and manage all machines running XP, Win2K, Windows NT 4.0, Windows Me, and Windows 9x.
3. Composition of the WMIC Command Line
WMIC provides a large number of global switches, aliases, verbs, commands, and rich command line help to enhance the user interface. Global switches are configuration options applicable to the entire WMIC session. For example, the /trace:on switch enables the error tracking mechanism. If this switch is on, WMIC returns the error information of each command. The /note switch can be used to access remote machines, the /interactive:on switch requires WMIC to prompt for confirmation before performing deletion operations. Other global switches also include /role, /user, /implevel, and /namespace.
As mentioned earlier, the alias is an intermediate layer that simplifies the syntax between the user and the WMI namespace. When you specify an alias, the verb (Verb) indicates the action to be executed. For example, List and Call in the previous example are examples of two verbs. Table 1 describes other WMIC verbs and gives examples for each verb.
Table 1: WMIC Verbs
Verb Example Description
Assoc group where name= 'administrators' assoc Displays all associations between the Administrators group and the system, including members of the Administrators group, etc. For another example, os assoc displays information about the operating system and installed patches.
Create environment create name="progloc", username="work01\User1",variablevalue= "%programfiles%\prog01" Creates a variable named Progloc, sets its value to a subfolder of the Program Files folder, and adds this variable to the User1 account of the Work01 workgroup computer.
Delete environment where(name= "progloc") delete Deletes the Progloc environment variable. When testing WMIC commands, to prevent accidental deletion, you can use the /interactive:on global switch, and confirmation will be required before deletion.
Get partition get bootpartition, description, deviceid, bootable Returns information such as whether the partition is bootable, description information, and device ID attributes.
Set path WIN32_USERACCOUNT where(name="user01") set disabled="true" Disables the User01 user account on the member server or workstation.
The command is used to control access to WMIC and the WMI namespace. Note the last example in Table 1. This example uses the Path and Win32_USERACCOUNT classes instead of the Useraccount alias. The Path is a command to directly access the instance in the WMI namespace without accessing through the alias. The Path command is especially useful if there is no ready-made alias available for the system management task to be executed. Although you can expand WMIC with new aliases and roles, if you are familiar with the WMI namespace, using the Path command is also convenient
In addition to the Path command, WMIC also supports the Class, Context, Quit, and Exit commands. The Class command is used to directly access the classes in the WMI mode or create instances of existing classes. The difference between the Class command and the Path command is that the Path command acts on instances and their properties (for example, extracting management information), while the Class command acts on the definition of the class. For example, if you want to extract all properties of the WIN32_SOFTWAREELEMENT class, you can execute the following command:
class WIN32_SOFTWAREELEMENT get
The output of this command is in HTML format. We will later understand how to use the /output global switch to redirect the output to an HTML file that can be opened by a browser. The Class command plus the Assoc verb can display the namespace path of the class and other classes associated with this class. The Class command can be used to delete classes and create instances of classes, but cannot create classes.
The Context command displays the current settings of the global switch. The Quit and Exit commands are used to exit the WMIC command prompt environment and return to the previous Shell environment (for example, Telnet environment or XP command line prompt environment).
Command line help is an effective way to be familiar with WMIC. Table 2 is a common command for finding information under the WMIC prompt:
Table 2: Command Line Help
Command Example Description
/? or -? Displays the syntax of all global switches and aliases
/ /? /user /? Displays information about the specified global switch
/? class /? Displays information about a certain command
/? memcache /? Displays information about a certain alias
/? temperature get /? Displays information about the combination of alias and verb
/?:Full irq get /?:Full Displays help information about the verb
4. Practical Applications
We have understood the basic knowledge of the WMIC command line environment above. Let's see how to run WMIC with batch commands and redirect the output result to the console or HTML, XML files. The advantage of running WMIC from a batch command file is that there is no need to repeatedly enter a series of complex commands. For example, the following is the content of a batch command file, which is used to display the CPU information of the two machines MACHINE1 and MACHINE2, and the output result is displayed on the console. The /format switch is a verb-oriented switch, not a global switch, and it is only used for the Get and List verbs.
wmic /node:MACHINE1, MACHINE4 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xsl
WMIC batch commands can use variables. That is to say, for the above batch command, the name of the server can not only be directly specified but also can be specified in the form of %1, %2. The following is an example. Put the following code into a batch command file, and then add one or two machine names when executing the batch command file; in addition, you can also create an independent text file and put the list of machine names in the text file. The list can be in CSV format or in the format separated by line breaks. If an independent text file is used to provide the machine names, you only need to add the text file name prefixed with the @ symbol after the /node global switch. The @ symbol tells the /node switch that the parameter behind is a file name instead of a machine name.
@echo offif "%1"=="" goto msgif "%2"=="" goto singlewmic /node:%1, %2 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xslgoto end:singlewmic /node:%1 cpu get name, caption, maxclockspeed, systemname /format:textvaluelist.xslgoto end:msgecho 必须指定至少一台计算机的名字。:end
As mentioned earlier, the output result of the WMIC command can not only be sent to the console but also to XML or HTML, MOF (Managed Object Format) format files. On a computer with WMI installed, MOF is the original form for saving classes and class instances in the WMI database. The following example shows how to output the query result of the MACHINE4 processor information to an HTML file. The /output global switch requires WMIC to send the output to file1.htm, and the /format switch requires WMIC to convert the original XML output into HTML format. The XSL style file used for conversion can be a custom one or any XSL file in the \%systemroot%\system32\wbem folder of any machine with WMIC installed. For example, using the csv.xsl style file can convert the output result into CSV format, and using the htable.xsl style can construct a table containing the result data. Figure 3 is the file1.htm file opened in the browser.
wmic /node:MACHINE4 /output:e:\file1.htm cpu get description, maxclockspeed, extclock, manufacturer, revision /format:hform.xsl
It has been mentioned earlier that the default output of the Class command plus the Get verb is in HTML format. Therefore, if you want to save the output result of such a command to an HTML file, you only need to specify the /output switch without adding the /format switch. The /record and /append global switches can also intercept information from the WMIC command line. Please use the command line help function of WMIC to understand more information about these switches.
If you want to output in XML format, use the /translate switch and the Basicxml keyword to convert the greater-than symbol ">" and less-than symbol "<" into meaningful characters in XML. The following is an example of outputting XML. The output XML data can be imported into a database or other systems that can understand XML tags. The output of the following code includes the WMIC command, command line request parameters, target node, global switch, and command execution result.
wmic cpu get maxclockspeed /translate:basicxml /format:rawxml.xsl
In conclusion, WMIC is an important improvement in the command line management function in XP and.NET Server, and it provides robust support for accessing and managing the WMI namespace from the command line. Although it takes some time to master and be familiar with the WMIC command line environment, once you are familiar with it, a brand-new realm of system management will unfold in front of you
|
|
2006-8-24 14:32 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
不能原谅 必须发帖
呵呵 正在看这些东西
Can't forgive, must post a thread
Hehe, currently looking at these things
|
|
2006-8-24 15:31 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
虽然说不再发帖呢,回帖还是要的
Although I said I won't post anymore, I still need to reply
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-8-24 16:01 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
bagpipe不发帖了,是论坛的一大损失。
The absence of bagpipe from posting is a great loss to the forum.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-8-25 10:41 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
“千里马常有而伯乐不常有~"
"A thousand-mile horse is common, but a伯乐is not common~"
|
|
2006-10-7 15:21 |
|
|
jieok3375
中级用户
  
积分 282
发帖 130
注册 2006-9-20 来自 广东
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
干嘛不发贴了呢?
不来这个论坛了吗?
5555
Why didn't you post anymore?
Don't come to this forum anymore?
5555
|

~~~~好好学习
天天向上~~~~ |
|
2006-10-10 00:49 |
|
|
weilong888
银牌会员
    
积分 1270
发帖 548
注册 2004-5-31
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
这个wmic.exe可不好掌握。
This wmic.exe is not easy to master.
|
|
2006-10-10 06:39 |
|
|
htysm
高级用户
   
积分 866
发帖 415
注册 2005-12-4
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
太难了,看得我云里雾里。
为什么说是最后一次呢?
It's too difficult. It makes me confused. Why is it said to be the last time?
|
|
2007-2-16 05:12 |
|
|
xycoordinate
中级用户
  
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
参数太多了!
不好记!
汗!!!
There are too many parameters!
Hard to remember!
Sweat!!!
|
|
2007-3-13 08:11 |
|
|
6622186
高级用户
   
积分 894
发帖 411
注册 2007-2-17
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
wmci 太复杂了,不易掌握. 我从本站看到一个用 wmic 查询进程序所在路径的方法很受用.
wmci is too complicated and not easy to master. I found a method to query the path where the process is located using wmic on this site, which is very useful.
|

@set c= 不知则觉多,知则觉少,越知越多,便觉越来越少. --- 知多少.
@for,/l,%%i,in,(1,1,55)do,@call,set/p=%%c:~%%i,1%%<nul&ping/n 1 127.1>nul
|
|
2007-3-13 12:00 |
|
|
kgdetg1127
初级用户
 
积分 158
发帖 89
注册 2007-4-25
状态 离线
|
|
2007-10-23 13:38 |
|
|
tempuser
高级用户
   
积分 547
发帖 261
注册 2006-4-15
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
很好的工具,可惜我不会,但我要学!
A very good tool, but unfortunately I don't know how to use it, but I want to learn!
|
|
2007-11-19 16:20 |
|
|
z640919a
初级用户
 
积分 157
发帖 72
注册 2006-10-22
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
lz最下的"WMIC从命令行对Windows的全面管理(2)"是不是搞错了,和上面的重复了.
Is the "WMIC Comprehensive Management of Windows from the Command Line (2)" at the bottom of lz mistaken? It repeats with the above one.
|
|
2007-11-28 09:54 |
|
|
uouobb
初级用户
 
积分 82
发帖 37
注册 2007-12-15
状态 离线
|
|
2007-12-15 15:01 |
|
|
flying008
中级用户
  
积分 245
发帖 103
注册 2006-6-30
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
好久没来了,请问大大,这个WMIC有在WIN2000SP4下面的用的程序吗?
Long time no see. Excuse me, sir, is there a program for WMIC under WIN2000SP4?
|
|
2007-12-17 12:47 |
|
|