windows比cmd更强大的 WMIC命令使用详解
文章目录
什么是wmic ?
WMIC是扩展WMI(Windows Management Instrumentation,Windows管理规范),提供了从命令行接口和批命令脚本执行系统管理的支持。在WMIC出现之前,如果要管理WMI系统,必须使用一些专门的WMI应用,比如SMS,或者使用WMI的脚本编程API,或者使用象CIM Studio之类的工具。如果不熟悉C++之类的 编程语言或VBScript之类的 脚本语言,或者不掌握WMI 名称空间的基本知识,要使用WMI管理系统是很困难的。WMIC改变了这种情况,为WMI 名称空间提供了一个强大的、友好的命令行接口。
本文将主要介绍我在使用过程中的一些经验,本着实用主义的原则,过多的概念性的东西我就不多介绍了,在用到的时候我再进行一些解释。
和上面的官方定义比起来,还有一个更好理解的解释:WMIC,是一款命令行管理工具。使用WMIC,我们不但可以管理本地计算机,而且还可以管理同一Windows域内的所有远程计算机(需要必要的权限),而被管理的远程计算机不必事先安装WMIC,只需要支持WMI即可。WMIC有一个能够分析、解释和执行从命令行接收的别名(Alias)的引擎,它是一个可执行文件,名为WMIC.exe,这个文件通常位于“c:\windows\system32\wbem”文件夹中(支持WinXP和Win2003系统, win7也支持)。这样就比较好理解了吧,可以使用WMI管理远程计算机,是不是非常有吸引力呀!
WMIC能做什么?
可以使用WMIC实现如下的管理任务:
1、本地 计算机管理
2、远程单个 计算机管理
3、远程多个 计算机管理
4、使用远程会话的 计算机管理(如Telnet)
5、使用管理脚本的自动管理
WMIC命令使用帮助文档
wmic / ?
[global switches] <command>The following global switches are available: /NAMESPACE Path for the namespace the alias operate against. /ROLE Path for the role containing the alias definitions. /NODE Servers the alias will operate against. /IMPLEVEL Client impersonation level. /AUTHLEVEL Client authentication level. /LOCALE Language id the client should use. /PRIVILEGES Enable or disable all privileges. /TRACE Outputs debugging information to stderr. /RECORD Logs all input commands and output. /INTERACTIVE Sets or resets the interactive mode. /FAILFAST Sets or resets the FailFast mode. /USER User to be used during the session. /PASSWORD Password to be used for session login. /OUTPUT Specifies the mode for output redirection. /APPEND Specifies the mode for output redirection. /AGGREGATE Sets or resets aggregate mode. /AUTHORITY Specifies the <authority type> for the connection. /?[:<BRIEF|FULL>] Usage information. For more information on a specific global switch, type: switch-name /? The following alias/es are available in the current role: ALIAS - Access to the aliases available on the local system BASEBOARD - Base board (also known as a motherboard or system board) management. BIOS - Basic input/output services (BIOS) management. BOOTCONFIG - Boot configuration management. CDROM - CD-ROM management. COMPUTERSYSTEM - Computer system management. CPU - CPU management. CSPRODUCT - Computer system product information from SMBIOS. DATAFILE - DataFile Management. DCOMAPP - DCOM Application management. DESKTOP - User's Desktop management. DESKTOPMONITOR - Desktop Monitor management. DEVICEMEMORYADDRESS - Device memory addresses management. DISKDRIVE - Physical disk drive management. DISKQUOTA - Disk space usage for NTFS volumes. DMACHANNEL - Direct memory access (DMA) channel management. ENVIRONMENT - System environment settings management. FSDIR - Filesystem directory entry management. GROUP - Group account management. IDECONTROLLER - IDE Controller management. IRQ - Interrupt request line (IRQ) management. JOB - Provides access to the jobs scheduled using the schedule service. LOADORDER - Management of system services that define execution dependencies. LOGICALDISK - Local storage device management. LOGON - LOGON Sessions. MEMCACHE - Cache memory management. MEMORYCHIP - Memory chip information. MEMPHYSICAL - Computer system's physical memory management. NETCLIENT - Network Client management. NETLOGIN - Network login information (of a particular user) management. NETPROTOCOL - Protocols (and their network characteristics) management. NETUSE - Active network connection management. NIC - Network Interface Controller (NIC) management. NICCONFIG - Network adapter management. NTDOMAIN - NT Domain management. NTEVENT - Entries in the NT Event Log. NTEVENTLOG - NT eventlog file management. ONBOARDDEVICE - Management of common adapter devices built into the motherboard (system board). OS - Installed Operating System/s management. PAGEFILE - Virtual memory file swapping management. PAGEFILESET - Page file settings management. PARTITION - Management of partitioned areas of a physical disk. PORT - I/O port management. PORTCONNECTOR - Physical connection ports management. PRINTER - Printer device management. PRINTERCONFIG - Printer device configuration management. PRINTJOB - Print job management. PROCESS - Process management. PRODUCT - Installation package task management. QFE - Quick Fix Engineering. QUOTASETTING - Setting information for disk quotas on a volume. RDACCOUNT - Remote Desktop connection permission management. RDNIC - Remote Desktop connection management on a specific network adapter. RDPERMISSIONS - Permissions to a specific Remote Desktop connection. RDTOGGLE - Turning Remote Desktop listener on or off remotely. RECOVEROS - Information that will be gathered from memory when the operating system fails. REGISTRY - Computer system registry management. SCSICONTROLLER - SCSI Controller management. SERVER - Server information management. SERVICE - Service application management. SHADOWCOPY - Shadow copy management. SHADOWSTORAGE - Shadow copy storage area management. SHARE - Shared resource management. SOFTWAREELEMENT - Management of the elements of a software product installed on a system. SOFTWAREFEATURE - Management of software product subsets of SoftwareElement. SOUNDDEV - Sound Device management. STARTUP - Management of commands that run automatically when users log onto the computer system. SYSACCOUNT - System account management. SYSDRIVER - Management of the system driver for a base service. SYSTEMENCLOSURE - Physical system enclosure management. SYSTEMSLOT - Management of physical connection points including ports, slots and peripherals, and proprietary connections points. TAPEDRIVE - Tape drive management. TEMPERATURE - Data management of a temperature sensor (electronic thermometer). TIMEZONE - Time zone data management. UPS - Uninterruptible power supply (UPS) management. USERACCOUNT - User account management. VOLTAGE - Voltage sensor (electronic voltmeter) data management. VOLUME - Local storage volume management. VOLUMEQUOTASETTING - Associates the disk quota setting with a specific disk volume. VOLUMEUSERQUOTA - Per user storage volume quota management. WMISET - WMI service operational parameters management. For more information on a specific alias, type: alias /? CLASS - Escapes to full WMI schema. PATH - Escapes to full WMI object paths. CONTEXT - Displays the state of all the global switches. QUIT/EXIT - Exits the program. For more information on CLASS/PATH/CONTEXT, type: (CLASS | PATH | CONTEXT) /?123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
中文翻译:
[global switches] <command>以下全局开关可用: /NAMESPACE 别名操作的命名空间的路径。 /ROLE 包含别名定义的角色的路径。 /NODE 别名将对其进行操作的服务器。 /IMPLEVEL 客户端模拟级别。 /AUTHLEVEL 客户端身份验证级别。 /LOCALE 客户端应使用的语言ID。 /PRIVILEGES 启用或禁用所有权限。 /TRACE 将调试信息输出到stderr。 /RECORD 记录所有输入命令和输出。 /INTERACTIVE 设置或重置交互模式。 /FAILFAST 设置或重置FailFast模式。 /USER 在会话期间使用的用户。 /PASSWORD 用于会话登录的密码。 /OUTPUT 指定输出重定向的模式。 /APPEND 指定输出重定向的模式。 /AGGREGATE 设置或重置聚合模式。 /AUTHORITY 指定连接的<authority type>。 /?[:<BRIEF | FULL>] 使用信息。 有关特定全局开关的更多信息,请键入:switch-name /? 当前角色中提供了以下别名/ es: ALIAS - 访问本地系统上可用的别名 BASEBOARD - 基板(也称为主板或系统板)管理。 BIOS - 基本输入/输出服务(BIOS)管理。 BOOTCONFIG - 引导配置管理。 CDROM - CD-ROM管理。 COMPUTERSYSTEM - 计算机系统管理。 CPU - CPU管理。 CSPRODUCT - 来自SMBIOS的计算机系统产品信息。 DATAFILE - DataFile管理。 DCOMAPP - DCOM应用程序管理。 DESKTOP - 用户的桌面管理。 DESKTOPMONITOR - 桌面监视器管理。 DEVICEMEMORYADDRESS - 设备内存地址管理。 DISKDRIVE - 物理磁盘驱动器管理。 DISKQUOTA - NTFS卷的磁盘空间使用情况。 DMACHANNEL - 直接内存访问(DMA)通道管理。 ENVIRONMENT - 系统环境设置管理。 FSDIR - 文件系统目录条目管理。 GROUP - 集团账户管理。 IDECONTROLLER - IDE控制器管理。 IRQ - 中断请求线(IRQ)管理。 JOB - 提供对使用计划服务计划的作业的访问。 LOADORDER - 管理定义执行依赖性的系统服务。 LOGICALDISK - 本地存储设备管理。 LOGON - 登录会话。 MEMCACHE - 缓存内存管理。 MEMORYCHIP - 存储芯片信息。 MEMPHYSICAL - 计算机系统的物理内存管理。 NETCLIENT - 网络客户端管理。 NETLOGIN - (特定用户的)网络登录信息管理。 NETPROTOCOL - 协议(及其网络特征)管理。 NETUSE - 主动网络连接管理。 NIC - 网络接口控制器(NIC)管理。 NICCONFIG - 网络适配器管理。 NTDOMAIN - NT域管理。 NTEVENT - NT事件日志中的条目。 NTEVENTLOG - NT事件日志文件管理。 ONBOARDDEVICE - 管理主板(系统板)内置的通用适配器设备。 OS - 已安装的操作系统/管理。 PAGEFILE - 虚拟内存文件交换管理。 PAGEFILESET - 页面文件设置管理。 PARTITION - 管理物理磁盘的分区区域。 PORT - I / O端口管理。 PORTCONNECTOR - 物理连接端口管理。 PRINTER - 打印机设备管理。 PRINTERCONFIG - 打印机设备配置管理。 PRINTJOB - 打印作业管理。 PROCESS - 进程管理。 PRODUCT - 安装包任务管理。 QFE - 快速修复工程。 QUOTASETTING - 设置卷上磁盘配额的信息。 RDACCOUNT - 远程桌面连接权限管理。 RDNIC - 特定网络适配器上的远程桌面连接管理。 RDPERMISSIONS - 特定远程桌面连接的权限。 RDTOGGLE - 远程打开或关闭远程桌面监听器。 RECOVEROS - 操作系统出现故障时将从内存中收集的信息。 REGISTRY - 计算机系统注册表管理. SCSICONTROLLER - SCSI 控制器管理。 SERVER - 服务器信息管理。 SERVICE - 服务程序管理。 SHARE - 共享资源管理。 SOFTWAREELEMENT - 安装在系统上的软件产品元素的管理。 SOFTWAREFEATURE - SoftwareElement 的软件产品组件的管理。 SOUNDDEV - 声音设备管理。 STARTUP - 用户登录到计算机系统时自动运行命令的管理。 SYSACCOUNT - 系统帐户管理。 SYSDRIVER - 基本服务的系统驱动程序管理。 SYSTEMENCLOSURE - 物理系统封闭管理。 SYSTEMSLOT - 包括端口、插口、附件和主要连接点的物理连接点管理。 TAPEDRIVE - 磁带驱动器管理。 TEMPERATURE - 温度感应器的数据管理 (电子温度表)。 TIMEZONE - 时间区域数据管理。 UPS - 不可中断的电源供应 (UPS) 管理。 USERACCOUNT - 用户帐户管理。 VOLTAGE - 电压感应器 (电子电量计) 数据管理。 VOLUMEQUOTASETTING - 将某一磁盘卷与磁盘配额设置关联。 WMISET - WMI 服务操作参数管理。 有关CLASS / PATH / CONTEXT的更多信息,请键入:(CLASS | PATH | CONTEXT)/?123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
WMIC命令使用实例
执行“wmic”命令启动WMIC命令行环境。这个命令可以在XP或 .NET Server的标准命令行解释器(cmd.exe)、Telnet会话或“运行”对话框中执行。这些启动方法可以在本地使用,也可以通过.NET Server终端服务会话使用。
第一次执行WMIC命令时,Windows首先要安装WMIC(win7中自带wmic命令),然后显示出WMIC的命令行提示符。在WMIC命令行提示符上,命令以交互的方式执行。
wmic的运行方式可以有两种法
1、在cmd命令行键入wimic后出现wmic:root\cli>时你就可以输入命令了,如输入process显示所有的进程。可以输入用wimic /?来显示帮助。exit是退出交互模式。具体帮助用法如下:
命令行帮助:
| 命令 | 例子 | 说明 |
|---|---|---|
| /? 或 -? : | wmic:root\cli>/? | 显示所有全局开关和别名的语法 |
| /[command]/? | /user /? | 显示指定全局开关的信息 |
| [command]/? | class /? | 显示某个命令的信息 |
| [command]/? | memcache /? | 显示某个别名的信息 |
| [command][get]/? | 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>]1234567
2、用wmic 后面直接跟命令运行,如wmic process 就显示了所有的进程了。这两种运行方法就是:交互模式(Interactive mode)和非交互模式(Non-Interactive mode).
下面我们能过一些实例来说明用法:
1.显示进程的详细信息
输入 process where name="chrome.exe" list full
将显示出mxathon.exe进程所有的信息如下:
CommandLine="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --type=renderer --field-trial-handle=1584,11641743188553082976,10633258324074541617,131072 --laCSName=JSCOMPU Description=chrome.exe ExecutablePath=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe ExecutionState=Handle=4600 HandleCount=343 InstallDate=KernelModeTime=12636081 MaximumWorkingSetSize=1380 MinimumWorkingSetSize=200 Name=chrome.exe OSName=Microsoft Windows 7 Ultimate |C:\Windows|\Device\Harddisk0\Partition1 OtherOperationCount=1117 OtherTransferCount=7266 PageFaults=96314 PageFileUsage=48820 ParentProcessId=4708 PeakPageFileUsage=74276 PeakVirtualSize=627687424 PeakWorkingSetSize=114980 Priority=4 PrivatePageCount=49991680 ProcessId=4600 QuotaNonPagedPoolUsage=30 QuotaPagedPoolUsage=656 QuotaPeakNonPagedPoolUsage=42 QuotaPeakPagedPoolUsage=667 ReadOperationCount=35218 ReadTransferCount=109458393 SessionId=2 Status=TerminationDate=ThreadCount=15 UserModeTime=80808518 VirtualSize=607399936 WindowsVersion=6.1.7601 WorkingSetSize=96845824 WriteOperationCount=39509 WriteTransferCount=23883003123456789101112131415161718192021222324252627282930313233343536373839
2.停止、暂停和运行服务功能
启动服务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;};123456783.显示出BIOS信息
wmic bios list full
大家可能注意到了上面命令行中还有两个参数list和full。list决定显示的信息格式与范围,它有Brief、Full、Instance、 Status、System、Writeable等多个参数,full只是它的一个参数,也是list的缺省参数,表示显示所有的信息。其他几个参数顾名思义,如Brief表示只显示摘要信息,Instance表示只显示对象实例,Status表示显示对象状态,Writeable表示只显示该对象的可写入的属性信息等。
BiosCharacteristics={7,11,12,15,16,17,19,23,24,25,26,27,28,29,32,33,39,40,42,43,50,57,58,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79} BuildNumber= CodeSet= CurrentLanguage=en|US|iso8859-1
Description=BIOS Date: 11/09/12 11:49:42 Ver: 04.06.05
IdentificationCode= InstallableLanguages=1
InstallDate= LanguageEdition= ListOfLanguages={"en|US|iso8859-1"} Manufacturer=American Megatrends Inc.
Name=BIOS Date: 11/09/12 11:49:42 Ver: 04.06.05
OtherTargetOS= PrimaryBIOS=TRUE
ReleaseDate=20121109000000.000000+000
SerialNumber=D2N0CV068533064
SMBIOSBIOSVersion=K55VD.406
SMBIOSMajorVersion=2
SMBIOSMinorVersion=7
SMBIOSPresent=TRUE
SoftwareElementID=BIOS Date: 11/09/12 11:49:42 Ver: 04.06.05
SoftwareElementState=3
Status=OK
TargetOperatingSystem=0
Version=_ASUS_ - 1072009
123456789101112131415161718192021222324254.停止进程的操作
例如,执行下面的命令将关闭正在运行的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;};12345678例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"范例删除成功。123
列出所有的进程 : wmic process.
5.连接远程电脑
连接远程的电脑,不过好象对要开一些相应的服务
wmic /node:"192.168.203.131" /password:"" /user:"administrator"
6. BIOS - 基本输入/输出服务 (BIOS) 管理
查看bios版本型号wmic bios get Manufacturer,Name
7.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)
8.COMPUTERSYSTEM - 计算机系统管理
查看系统启动选项,boot的内容wmic COMPUTERSYSTEM get SystemStartupOptions
查看工作组/域wmic computersystem get domain
更改计算机名abc为123wmic computersystem where "name='abc'" call rename 123
更改工作组google为MyGroupwmic computersystem where "name='google'" call joindomainorworkgroup "","","MyGroup",1
9.CPU - CPU 管理
查看cpu型号wmic cpu get name
10.DATAFILE - DataFile 管理
查找e盘下test目录(不包括子目录)下的cc.cmd文件wmic datafile where "drive='e:' and path='\\test\\' and FileName='cc' and Extension='cmd'" list
查找e盘下所有目录和子目录下的cc.cmd文件,且文件大小大于1Kwmic 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.batwmic datafile where "drive='e:' and path='\\test\\' and FileName='cc' and Extension='cmd'" call copy "e:\aa.bat"
改名c:\hello.txt为c:\test.txtwmic 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
11.DESKTOPMONITOR - 监视器管理
获取屏幕分辨率wmic DESKTOPMONITOR where Status='ok' get ScreenHeight,ScreenWidth
DISKDRIVE - 物理磁盘驱动器管理
获取物理磁盘型号大小等wmic DISKDRIVE get Caption,size,InterfaceType
12.ENVIRONMENT - 系统环境设置管理
获取temp环境变量wmic ENVIRONMENT where "name='temp'" get UserName,VariableValue
更改path环境变量值,新增e:\toolswmic ENVIRONMENT where "name='path' and username='<system>'" set VariableValue="%path%;e:\tools"
新增系统环境变量home,值为%HOMEDRIVE%%HOMEPATH%wmic ENVIRONMENT create name="home",username="<system>",VariableValue="%HOMEDRIVE%%HOMEPATH%"
删除home环境变量wmic ENVIRONMENT where "name='home'" delete
13.FSDIR - 文件目录系统项目管理
查找e盘下名为test的目录wmic FSDIR where "drive='e:' and filename='test'" list
删除e:\test目录下除过目录abc的所有目录wmic FSDIR where "drive='e:' and path='\\test\\' and filename<>'abc'" call delete
删除c:\good文件夹wmic fsdir "c:\\good" call delete
重命名c:\good文件夹为abbwmic fsdir "c:\\good" rename "c:\abb"
14.LOGICALDISK - 本地储存设备管理
获取硬盘系统格式、总大小、可用空间等wmic LOGICALDISK get name,Description,filesystem,size,freespace
15.NIC - 网络界面控制器 (NIC) 管理
16.OS - 已安装的操作系统管理
设置系统时间wmic os where(primary=1) call setdatetime 20070731144642.555555+480
17.PAGEFILESET - 页面文件设置管理
更改当前页面文件初始大小和最大值wmic PAGEFILESET set InitialSize="512",MaximumSize="512"
页面文件设置到d:\下,执行下面两条命令wmic pagefileset create name='d:\pagefile.sys',initialsize=512,maximumsize=1024wmic pagefileset where"name='c:\\pagefile.sys'" delete
18.PROCESS - 进程管理
列出进程的核心信息,类似任务管理器wmic process list brief
结束svchost.exe进程,路径为非C:\WINDOWS\system32\svchost.exe的wmic process where "name='svchost.exe' and ExecutablePath<>'C:\\WINDOWS\\system32\\svchost.exe'" call Terminate
新建notepad进程wmic process call create notepad
19.PRODUCT - 安装包任务管理
安装包在C:\WINDOWS\Installer目录下
卸载.msi安装包wmic PRODUCT where "name='Microsoft .NET Framework 1.1' and Version='1.1.4322'" call Uninstall
修复.msi安装包wmic PRODUCT where "name='Microsoft .NET Framework 1.1' and Version='1.1.4322'" call Reinstall
20.SERVICE - 服务程序管理
运行spooler服务wmic SERVICE where name="Spooler" call startservice
停止spooler服务wmic SERVICE where name="Spooler" call stopservice
暂停spooler服务wmic SERVICE where name="Spooler" call PauseService
更改spooler服务启动类型[auto|Disabled|Manual] 释[自动|禁用|手动]wmic SERVICE where name="Spooler" set StartMode="auto"
删除服务wmic SERVICE where name="test123" call delete
21.SHARE - 共享资源管理
删除共享wmic SHARE where name="e$" call delete
添加共享WMIC SHARE CALL Create "","test","3","TestShareName","","c:\test",0
22.SOUNDDEV - 声音设备管理
wmic SOUNDDEV list
STARTUP - 用户登录到计算机系统时自动运行命令的管理
查看msconfig中的启动选项wmic STARTUP list
23.SYSDRIVER - 基本服务的系统驱动程序管理
wmic SYSDRIVER list
24.USERACCOUNT - 用户帐户管理
更改用户administrator全名为adminwmic USERACCOUNT where name="Administrator" set FullName="admin"
更改用户名admin为admin00wmic useraccount where "name='admin" call Rename admin00
25.获取补丁信息
查看当前系统打了哪些补丁/node:legacyhost qfe get hotfixid
26.查看CPU当前的速度
cpu当前的速度wmic cpu get CurrentClockSpeed
27.远程计算机的远程桌面连接
WMIC命令开启远程计算机的远程桌面连接
执行wmic /node:192.168.1.2 /USER:administrator PATH win32_terminalservicesetting WHERE (__Class!="") CALL SetAllowTSConnections 1
具体格式:
wmic /node:"[full machine name]" /USER:"[domain]\[username]"PATH win32_terminalservicesetting WHERE (__Class!="") CALL SetAllowTSConnections 112
实例summary
wmic 获取进程名称以及可执行路径:wmic process get name,executablepath
wmic 删除指定进程(根据进程名称):wmic process where name="qq.exe" call terminate
或者用wmic process where name="qq.exe" delete
wmic 删除指定进程(根据进程PID):wmic process where pid="123" delete
wmic 创建新进程wmic process call create "C:\Program Files\Tencent\QQ\QQ.exe"
在远程机器上创建新进程:wmic /node:192.168.201.131 /user:administrator /password:123456 process call create cmd.exe
关闭本地计算机wmic process call create shutdown.exe
重启远程计算机wmic /node:192.168.1.10/user:administrator /password:123456 process call create "shutdown.exe -r -f -m"
更改计算机名称wmic computersystem where "caption='%ComputerName%'" call rename newcomputername
更改帐户名wmic USERACCOUNT where "name='%UserName%'" call rename newUserName
wmic 结束可疑进程(根据进程的启动路径)
wmic process where "name='explorer.exe' and executablepath<>'%SystemDrive%\\windows\\explorer.exe'" delete
wmic 获取物理内存wmic memlogical get TotalPhysicalMemory|find /i /v "t"
wmic 获取文件的创建、访问、修改时间
@echo offfor /f "skip=1 tokens=1,3,5 delims=. " %%a in ('wmic datafile where name^="c:\\windows\\system32\\notepad.exe" get CreationDate^,LastAccessed^,LastModified') do (set a=%%aset b=%%bset c=%%cecho 文件: c:\windows\system32\notepad.exe
echo.echo 创建时间: %a:~0,4% 年 %a:~4,2% 月 %a:~6,2% 日 %a:~8,2% 时 %a:~10,2% 分 %a:~12,2% 秒echo 最后访问: %b:~0,4% 年 %b:~4,2% 月 %b:~6,2% 日 %b:~8,2% 时 %b:~10,2% 分 %b:~12,2% 秒echo 最后修改: %c:~0,4% 年 %c:~4,2% 月 %c:~6,2% 日 %c:~8,2% 时 %c:~10,2% 分 %c:~12,2% 秒)echo.
pause12345678910111213wmic 全盘搜索某文件并获取该文件所在目录for /f "skip=1 tokens=1*" %i in ('wmic datafile where "FileName='qq' and extension='exe'" get drive^,path') do (set "qPath=%i%j"&@echo %qPath:~0,-3%)
获取屏幕分辨率 wmic DESKTOPMONITOR where Status='ok' get ScreenHeight,ScreenWidth
wmic PageFileSet set InitialSize="512",MaximumSize="512"
设置虚拟内存到E盘,并删除C盘下的页面文件,重启计算机后生效
wmic PageFileSet create name="E:\\pagefile.sys",InitialSize="1024",MaximumSize="1024"wmic PageFileSet where "name='C:\\pagefile.sys'" delete12
获得进程当前占用的内存和最大占用内存的大小:
wmic process where caption='filename.exe' get WorkingSetSize,PeakWorkingSetSize
以KB为单位显示
@echo offfor /f "skip=1 tokens=1-2 delims= " %%a in ('wmic process where caption^="conime.exe" get WorkingSetSize^,PeakWorkingSetSize') do (set /a m=%%a/1024set /a mm=%%b/1024echo 进程conime.exe现在占用内存:%m%K;最高占用内存:%mm%K)pause1234567远程打开计算机远程桌面
wmic /node:%pcname% /USER:%pcaccount% PATH win32_terminalservicesetting WHERE (__Class!="") CALL SetAllowTSConnections 1
WMIC学习小结
在WINDOWS\Help目下,wmic.chm文档是这样解释wmi的:Windows Management Instrumentation (WMI) 是“基于 Web 的企业管理倡议 (WBEM)”(这是一个旨在建立在企业网络上访问和共享管理信息的标准的工业倡议)的 Microsoft 的实现。有关 WBEM 的详细信息,请访问 WBEM。XOXWMI 为公用信息模型 (CIM)(该数据模型描述存在于管理环境中的对象)提供完整的支持。WMI 包括对象储备库和 CIM 对象管理器,其中对象储备库是包含对象定义的数据库,对象管理器负责处理储备库中对象的收集和操作并从 WMI 提供程序 (WMI provider) 收集信息。WMI 提供程序 (WMI provider) 在 WMI 和操作系统、应用程序以及其他系统的组件之间充当中介。例如,注册表提供程序从注册表中提供信息,而 SNMP 提供程序则从 SNMP 设备中提供数据和事件。提供程序提供关于其组件的信息,也可能提供一些方法,这些方法可以操作可设置的组件、属性,或者操作可能警告您在组件中要发生更改的事件。Windows Management Instrumentation 命令行 (WMIC) 向您提供了简单的 Windows Management Instrumentation (WMI) 命令行界面,这样即可利用 WMI 来管理运行 Windows 的计算机。WMIC 与现有命令行程序和实用程序命令相互操作,且很容易通过脚本或其他面向管理的应用程序来扩展 WMIC。
以上的这些说法太专业了,通俗一点讲就是wmic.exe是一个命令行程序,可以用它这个接口来实现在命令行下直接管理计算机软硬件等方方面面的操作,相当于批处理的api了。
































































































