执行“wmic”命令启动WMIC命令行环境。这个命令可以在XP或 .NET Server的标准命令行解释器(cmd.exe)、Telnet会话或“运行”对话框中执行。这些启动方法可以在本地使用,也可以通过.NET Server终端服务会话使用。
第一次执行WMIC命令时,Windows首先要安装WMIC,然后显示出WMIC的命令行提示符。在WMIC命令行提示符上,命令以交互的方式执行。
wimic的运行方式可以有两种法:
1、搞入wimic进入后输入命令运行,键入wimic后出现wmic:root\cli>时你就可以输入命令了,如输入process显示所有的进程。不知道有什么命令时可以输入用/?来显示帮助。exit 是退出交互模式。具体帮助用法如下:
命令行帮助
命令 例子 说明
/? 或 -? 显示所有全局开关和别名的语法
/ /? /user /? 显示指定全局开关的信息
/? class /? 显示某个命令的信息
/? memcache /? 显示某个别名的信息
/? temperature get /? 显示别名与动词组合的信息
/?:Full irq get /?:Full 显示动词的帮助信息
如:我要查看process命令的帮助,键入:process/?后显示如下:
wmic:root\cli>process /?
PROCESS - 进程管理。
提示: BNF 的别名用法。
(<alias> [WMIObject] | <alias> [<path where>] | [<alias>] <path where>) [<verb clause>].
用法:
PROCESS ASSOC [<format specifier>]
PROCESS CALL <method name> [<actual param list>]
PROCESS CREATE <assign list>
PROCESS DELETE
PROCESS GET [<property list>] [<get switches>]
PROCESS LIST [<list format>] [<list switches>]
2、用wimic 后面直接跟命令运行,如wmic process 就显示了所有的进程了。这两种运行方法就是:交互模式(Interactive mode)和非交互模式(Non-Interactive mode)
下面我们能过一些实例来说明用法:
=====================================================================
显示进程的详细信息
输入 process where name="maxthon.exe" list full
将显示出mxathon.exe进程所有的信息如下:
CommandLine="D:\mytools\Maxthon2\Maxthon.exe"
CSName=CHINA-46B1E8590
Description=Maxthon.exe
ExecutablePath=D:\mytools\Maxthon2\Maxthon.exe
ExecutionState=
Handle=684
HandleCount=2296
InstallDate=
KernelModeTime=3495000000
MaximumWorkingSetSize=1413120
MinimumWorkingSetSize=204800
Name=Maxthon.exe
OSName=Microsoft Windows XP Professional|C:\WINDOWS|
OtherOperationCount=307814
OtherTransferCount=60877207
PageFaults=1367971
PageFileUsage=89849856
ParentProcessId=1924
PeakPageFileUsage=90091520
PeakVirtualSize=385802240
PeakWorkingSetSize=94031872
Priority=8
PrivatePageCount=89849856
ProcessId=684
QuotaNonPagedPoolUsage=43496
QuotaPagedPoolUsage=257628
QuotaPeakNonPagedPoolUsage=72836
QuotaPeakPagedPoolUsage=271372
ReadOperationCount=85656
ReadTransferCount=121015982
SessionId=0
Status=
TerminationDate=
ThreadCount=57
UserModeTime=1778750000
VirtualSize=353206272
WindowsVersion=5.1.2600
WorkingSetSize=93716480
WriteOperationCount=30940
WriteTransferCount=24169673
******************************************************************************
停止、暂停和运行服务功能
启动服务startservice,
停止服务stopservice,
暂停服务pauseservice
Service where caption="windows time" call stopservice ------停止服务
Service where caption="windows time" call startservice ------启动服务
Service where name="w32time" call stopservice ------停止服务,注意name和caption的区别。
caption 显示服务名name服务名称,如: telnet服务的显示名称是telnet 服务名称是tlntsvr,还有Windows Time服务的名称是w32time 显示名称是"Windows Time"要用引号引起来,主要是有一个空格。
好了具体看一下:输入Service where caption="windows time" call startservice后有一个确认输入y就可以了,返回ReturnValue = 0;表示成功
wmic:root\cli>Service where caption="windows time" call startservice
执行 (\\CHINA-46B1E8590\ROOT\CIMV2:Win32_Service.Name="W32Time")->startservice()
方法执行成功。
输出参数:
instance of __PARAMETERS
{
ReturnValue = 0;
};
wmic:root\cli>
================================================================================================
显示出BIOS信息 wmic bios list full
大家可能注意到了上面命令行中还有两个参数list和full。list决定显示的信息格式与范围,它有Brief、Full、Instance、 Status、System、Writeable等多个参数,full只是它的一个参数,也是list的缺省参数,表示显示所有的信息。其他几个参数顾名思义,如Brief表示只显示摘要信息,Instance表示只显示对象实例,Status表示显示对象状态,Writeable表示只显示该对象的可写入的属性信息等。
************************************************************************=====================
停止进程的操作
例如,执行下面的命令将关闭正在运行的QQ.exe:
例1、wmic process where name='QQ.exe' call terminate
命令运行结束后,WMIC命令行提示出如下结果:
C:\>wmic process where name='QQ.exe' call terminate
执行 (\\CHINA-46B1E8590\ROOT\CIMV2:Win32_Process.Handle="728")->terminate()
方法执行成功。
输出参数:
instance of __PARAMETERS
{
ReturnValue = 0;
};
例2、wmic process where name="qq.exe" delete
命令运行结束后,WMIC命令行提示出如下结果:
C:\>wmic process where name="qq.exe" delete
删除范例 \\CHINA-46B1E8590\ROOT\CIMV2:Win32_Process.Handle="2820"
范例删除成功。
======================================================================
列出所有的进程 wmic process
==================================================================
连接远程电脑
★★连接远程的电脑,不过好象对要开一些相应的服务
wmic /node:"192.168.203.131" /password:"" /user:"administrator"
BIOS - 基本输入/输出服务 (BIOS) 管理
★★查看bios版本型号
wmic bios get Manufacturer,Name
WMIC设置IP地址
★★配置或更新IP地址:
wmic nicconfig where index=0 call enablestatic("192.168.1.5"), ("255.255.255.0") ;index=0说明是配置网络接口1。
配置网关(默认路由):
wmic nicconfig where index=0 call setgateways("192.168.1.1"),(1)
COMPUTERSYSTEM - 计算机系统管理
★★查看系统启动选项,boot的内容
wmic COMPUTERSYSTEM get SystemStartupOptions
★★查看工作组/域
wmic computersystem get domain
★★更改计算机名abc为123
wmic computersystem where "name='abc'" call rename 123
★★更改工作组google为MyGroup
wmic computersystem where "name='google'" call joindomainorworkgroup "","","MyGroup",1
CPU - CPU 管理
★★查看cpu型号
wmic cpu get name
DATAFILE - DataFile 管理
★★查找e盘下test目录(不包括子目录)下的cc.cmd文件
wmic datafile where "drive='e:' and path='\\test\\' and FileName='cc' and Extension='cmd'" list
★★查找e盘下所有目录和子目录下的cc.cmd文件,且文件大小大于1K
wmic datafile where "drive='e:' and FileName='cc' and Extension='cmd' and FileSize>'1000'" list
★★删除e盘下文件大小大于10M的.cmd文件
wmic datafile where "drive='e:' and Extension='cmd' and FileSize>'10000000'" call delete
★★删除e盘下test目录(不包括子目录)下的非.cmd文件
wmic datafile where "drive='e:' and Extension<>'cmd' and path='test'" call delete
★★复制e盘下test目录(不包括子目录)下的cc.cmd文件到e:\,并改名为aa.bat
wmic datafile where "drive='e:' and path='\\test\\' and FileName='cc' and Extension='cmd'" call copy "e:\aa.bat"
★★改名c:\hello.txt为c:\test.txt
wmic datafile "c:\\hello.txt" call rename c:\test.txt
★★查找h盘下目录含有test,文件名含有perl,后缀为txt的文件
wmic datafile where "drive='h:' and extension='txt' and path like '%\\test\\%' and filename like '%perl%'" get name
DESKTOPMONITOR - 监视器管理
★★获取屏幕分辨率
wmic DESKTOPMONITOR where Status='ok' get ScreenHeight,ScreenWidth
DISKDRIVE - 物理磁盘驱动器管理
★★获取物理磁盘型号大小等
wmic DISKDRIVE get Caption,size,InterfaceType
ENVIRONMENT - 系统环境设置管理
★★获取temp环境变量
wmic ENVIRONMENT where "name='temp'" get UserName,VariableValue

