Windows Management Instrument Command-line
- 注意: 如果wmic命令上头有
ver|find "5." >nul 2>nul
则会引起奇葩的无限等待问题(XP
).
rem 更改用户名
wmic useraccount where "name='admin'" call Rename "admin00"
rem 查看CPU型号
wmic cpu get name
rem 获取当前系统进程名称以及可执行路径
wmic process get name,executablepath
rem 获取文件信息
wmic datafile where "name='c:\\notepad.exe'" get CreationDate,LastAccessed,LastModified
rem 文件搜索
wmic datafile where "filename='qq' and extension='exe' and drive='d:' and filesize>=9560" get drive,path
rem 更改计算机名
wmic computersystem where "name='abc'" call rename "12 3"
rem 更改工作组google --> MyGroup
wmic computersystem where "name='google'" call joindomainorworkgroup "","","MyGroup",1
rem 查看屏幕分辨率
wmic desktopmonitor where status='ok' get screenheight,screenwidth
rem 获取硬盘固定分区盘符(非光驱、移动存储器)
wmic logicaldisk where "drivetype=3" get name
rem 获取硬盘各分区文件系统以及可用空间
wmic logicaldisk where "drivetype=3" get name,filesystem,freespace
rem 获得环境变量home的用户名以及变量值,结果可能是: ComputerName\lei %homedrive%%homepath%(==%home%==userprofile)
wmic environment where "name='temp'" get userName,variablevalue
rem 编辑系统环境变量,添加新的值
wmic environment where "name='path' and username='<system>'" set VariableValue="%path%;e:\tools"
rem 新增用户环境变量home,值为%home%
wmic environment create name="home",username="%username%",VariableValue="%home%"
rem 删除home环境变量
wmic environment where "name='home'" delete
rem 设置新的页面文件删除旧的,单位是MB.
wmic pagefileset create name='d:\pagefile.sys',initialsize=512,maximumsize=1024
wmic pagefileset where "name='c:\\pagefile.sys'" delete
rem 更改页面文件大小
wmic pagefileset set InitialSize="512",MaximumSize="512"