wmic说明

wmic说明

2023年7月3日发(作者:)

WMIC命令使用详解

执行“wmic”命令启动WMIC命令行环境。这个命令可以在XP或 .NET Server的标准命令行解释器()、Telnet会话或“运行”对话框中执行。这些启动方法可以在本地使用,也可以通过.NET Server终端服务会话使用。

第一次执行WMIC命令时,Windows首先要安装WMIC,然后显示出WMIC的命令行提示符。在WMIC命令行提示符上,命令以交互的方式执行。

wimic的运行方式可以有两种法:

1、搞入wimic进入后输入命令运行,键入wimic后出现wmic:rootcli>时你就可以输入命令了,如输入process显示所有的进程。不知道有什么命令时可以输入用/?来显示帮助。exit 是退出交互模式。具体帮助用法如下:

命令行帮助

命令例子说明

/? 或 -? 显示所有全局开关和别名的语法

/ /? /user /? 显示指定全局开关的信息

/? class /? 显示某个命令的信息

/? memcache /? 显示某个别名的信息

/? temperature get /? 显示别名与动词组合的信息

/?:Fullirq get /?:Full 显示动词的帮助信息

如:我要查看process命令的帮助,键入:process/?后显示如下:

wmic:rootcli>process /?

PROCESS - 进程管理。

提示: BNF 的别名用法。

( [WMIObject] | [] | [] ) [].

用法:

PROCESS ASSOC []

PROCESS CALL []

PROCESS CREATE

PROCESS DELETE

PROCESS GET [] []

PROCESS LIST [] []

2、用wimic后面直接跟命令运行,如wmic process 就显示了所有的进程了。这两种运行方法就是:交互模式(Interactive mode)和非交互模式(Non-Interactive mode)

下面我们能过一些实例来说明用法:

=====================================================================

显示进程的详细信息

输入 process where name="" list full

将显示出进程所有的信息如下:

CommandLine="D:"

CSName=CHINA-46B1E8590

Description=

ExecutablePath=D:

ExecutionState=

Handle=684 HandleCount=2296

InstallDate=

KernelModeTime=3495000000

MaximumWorkingSetSize=1413120

MinimumWorkingSetSize=204800

Name=

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:rootcli>Service where caption="windows time" call startservice

执行

(startservice'>CHINA-46B1E8590ROOTCIMV2:Win32_="W32Time")->startservice()

方法执行成功。

输出参数:

instance of __PARAMETERS

{

ReturnValue = 0;

};

wmic:rootcli>

================================================================================================

显示出BIOS信息wmic bios list full

大家可能注意到了上面命令行中还有两个参数list和full。list决定显示的信息格式与范围,它有Brief、Full、Instance、 Status、System、Writeable等多个参数,full只是它的一个参数,也是list的缺省参数,表示显示所有的信息。其他几个参数顾名思义,如Brief表示只显示摘要信息,Instance表示只显示对象实例,Status表示显示对象状态,Writeable表示只显示该对象的可写入的属性信息等。

************************************************************************=====================

停止进程的操作

例如,执行下面的命令将关闭正在运行的:

例1、wmic process where name='' call terminate

命令运行结束后,WMIC命令行提示出如下结果:

C:>wmic process where name='' call terminate

执行 (terminate'>CHINA-46B1E8590ROOTCIMV2:Win32_="728")->terminate()

方法执行成功。

输出参数:

instance of __PARAMETERS

{

ReturnValue = 0;

};

例2、wmic process where name="" delete

命令运行结束后,WMIC命令行提示出如下结果:

C:>wmic process where name="" delete

删除范例 CHINA-46B1E8590ROOTCIMV2:Win32_="2820"

范例删除成功。

======================================================================

列出所有的进程 wmic process

==================================================================

连接远程电脑

★★连接远程的电脑,不过好象对要开一些相应的服务

wmic /node:"192.168.203.131" /password:"" /user:"administrator"

BIOS - 基本输入/输出服务 (BIOS) 管理 ★★查看bios版本型号

wmic bios get Manufacturer,Name

WMIC设置IP地址

★★配置或更新IP地址:

wmicnicconfig where index=0 call enablestatic("192.168.1.5"), ("255.255.255.0") ;index=0说明是配置网络接口1。

配置网关(默认路由):

wmicnicconfig where index=0 call setgateways("192.168.1.1"),(1)

COMPUTERSYSTEM - 计算机系统管理

★★查看系统启动选项,boot的内容

wmic COMPUTERSYSTEM get SystemStartupOptions

★★查看工作组/域

wmiccomputersystem get domain

★★更改计算机名abc为123

wmiccomputersystem where "name='abc'" call rename 123

★★更改工作组google为MyGroup

wmiccomputersystem where "name='google'" call joindomainorworkgroup "","","MyGroup",1

CPU - CPU 管理

★★查看cpu型号

wmiccpu get name

DATAFILE - DataFile管理

★★查找e盘下test目录(不包括子目录)下的文件

wmicdatafile where "drive='e:' and path='test' and FileName='cc' and Extension='cmd'" list

★★查找e盘下所有目录和子目录下的文件,且文件大小大于1K

wmicdatafile where "drive='e:' and FileName='cc' and Extension='cmd' and FileSize>'1000'" list

★★删除e盘下文件大小大于10M的.cmd文件

wmicdatafile where "drive='e:' and Extension='cmd' and FileSize>'10000000'" call delete

★★删除e盘下test目录(不包括子目录)下的非.cmd文件

wmicdatafile where "drive='e:' and Extension<>'cmd' and path='test'" call delete

★★复制e盘下test目录(不包括子目录)下的文件到e:,并改名为

wmicdatafile where "drive='e:' and path='test' and FileName='cc' and Extension='cmd'" call copy

"e:"

★★改名c:为c:

wmicdatafile "c:" call rename c:

★★查找h盘下目录含有test,文件名含有perl,后缀为txt的文件

wmicdatafile 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

★★更改path环境变量值,新增e:tools

wmic ENVIRONMENT where "name='path' and username=''" set

VariableValue="%path%;e:tools"

★★新增系统环境变量home,值为%HOMEDRIVE%%HOMEPATH%

wmic ENVIRONMENT create

name="home",username="",VariableValue="%HOMEDRIVE%%HOMEPATH%"

★★删除home环境变量

wmic ENVIRONMENT where "name='home'" delete

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文件夹

wmicfsdir "c:good" call delete

★★重命名c:good文件夹为abb

wmicfsdir "c:good" rename "c:abb"

LOGICALDISK - 本地储存设备管理

★★获取硬盘系统格式、总大小、可用空间等

wmic LOGICALDISK get name,Description,filesystem,size,freespace

NIC - 网络界面控制器 (NIC) 管理

OS - 已安装的操作系统管理

★★设置系统时间

wmicos where(primary=1) call setdatetime 22.555555+480

PAGEFILESET - 页面文件设置管理

★★更改当前页面文件初始大小和最大值

wmic PAGEFILESET set InitialSize="512",MaximumSize="512"

★★页面文件设置到d:下,执行下面两条命令

wmicpagefileset create name='d:',initialsize=512,maximumsize=1024

wmicpagefilesetwhere"name='c:'" delete

PROCESS - 进程管理

★★列出进程的核心信息,类似任务管理器

wmic process list brief

★★结束进程,路径为非C:的

wmic process where "name='' and

ExecutablePath<>'C:'" call Terminate

★★新建notepad进程

wmic process call create notepad

PRODUCT - 安装包任务管理

★★安装包在C:WINDOWSInstaller目录下

★★卸载.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

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

SHARE - 共享资源管理

★★删除共享

wmic SHARE where name="e$" call delete

★★添加共享

WMIC SHARE CALL Create "","test","3","TestShareName","","c:test",0

SOUNDDEV - 声音设备管理

wmic SOUNDDEV list

STARTUP - 用户登录到计算机系统时自动运行命令的管理

★★查看msconfig中的启动选项

wmic STARTUP list

SYSDRIVER - 基本服务的系统驱动程序管理

wmic SYSDRIVER list

USERACCOUNT - 用户帐户管理

★★更改用户administrator全名为admin

wmic USERACCOUNT where name="Administrator" set FullName="admin"

★★更改用户名admin为admin00

wmicuseraccount where "name='admin" call Rename admin00

================================================获取补丁信息

★★查看当前系统打了哪些补丁

/node:legacyhostqfe get hotfixid

查看CPU当前的速度

★★cpu当前的速度

wmiccpu get CurrentClockSpeed

远程计算机的远程桌面连接

★★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 1

wmic获取进程名称以及可执行路径: wmic process get name,executablepath

wmic删除指定进程(根据进程名称):

wmic process where name="" call terminate

或者用

wmic process where name="" delete

wmic删除指定进程(根据进程PID):

wmic process where pid="123" delete

wmic创建新进程

wmic process call create "C:Program "

在远程机器上创建新进程:

wmic /node:192.168.201.131 /user:administrator /password:123456 process call create

关闭本地计算机

wmic process call create

重启远程计算机

wmic /node:192.168.1.10/user:administrator /password:123456 process call create " -r -f

-m"

更改计算机名称

wmiccomputersystem where "caption='%ComputerName%'" call rename newcomputername

更改帐户名

wmic USERACCOUNT where "name='%UserName%'" call rename newUserName

wmic结束可疑进程(根据进程的启动路径)

wmic process where "name='' and

executablepath<>'%SystemDrive%'" delete

wmic获取物理内存

wmicmemlogical get TotalPhysicalMemory|find /i /v "t"

wmic获取文件的创建、访问、修改时间

@echo off

for /f "skip=1 tokens=1,3,5 delims=. " %%a in ('wmicdatafile where

name^="c:" get CreationDate^,LastAccessed^,LastModified') do (

set a=%%a

set b=%%b

set c=%%c

echo 文件: c:

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.

pause

wmic全盘搜索某文件并获取该文件所在目录 for /f "skip=1 tokens=1*" %i in ('wmicdatafile 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

wmicPageFileSet set InitialSize="512",MaximumSize="512"

设置虚拟内存到E盘,并删除C盘下的页面文件,重启计算机后生效

wmicPageFileSet create name="E:",InitialSize="1024",MaximumSize="1024"

wmicPageFileSet where "name='C:'" delete

获得进程当前占用的内存和最大占用内存的大小:

wmic process where caption='' get WorkingSetSize,PeakWorkingSetSize

以KB为单位显示

@echo off

for /f "skip=1 tokens=1-2 delims= " %%a in ('wmic process where caption^="" get

WorkingSetSize^,PeakWorkingSetSize') do (

set /a m=%%a/1024

set /a mm=%%b/1024

echo 进程现在占用内存:%m%K;最高占用内存:%mm%K

)

pause

远程打开计算机远程桌面

wmic /node:%pcname% /USER:%pcaccount% PATH win32_terminalservicesetting WHERE

(__Class!="") CALL SetAllowTSConnections 1

发布者:admin,转转请注明出处:http://www.yc00.com/news/1688384865a130058.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信