天天看點

強大的指令行工具wmic

1.wmic=Microsoft Windows Management Instrumentation

2. C:\WINDOWS\system32\wbem 下的東西,特别是.xsl格式化檔案,實作wmic的格式化輸出

如wmic /output:c:\process.html process list /format:htable.xsl

/format:textvaluelist.xsl

/format:hform.xsl

/format:htable.xsl

/format:csv.xsl

/format:xml.xsl

3.wmic可以做什麼?系統管理、遠端主機資訊擷取。。。都可以

4.wmic /?

檢視wmic對象有何可用屬性: wmic 對象名稱 get /?   例如

wmic process get /?

檢視wmic對象某個屬性的值: wmic 對象名稱 get 對象某個屬性   例如

wmic process get name

PROCESS - 程序管理

::列出程序的核心資訊,類似任務管理器

wmic process list brief

::建立notepad程序

wmic process call create notepad

::列出程序的資訊

wmic process get caption,handle,commandline,executablepath

::結束程序

wmic process [handle/PID] delete

wmic process [handle/PID] call terminate

::結束svchost.exe程序,路徑為非C:\WINDOWS\system32\svchost.exe的

wmic process where "name='svchost.exe' and ExecutablePath<>'C:\\WINDOWS\\system32\\svchost.exe'" call Terminate

::結束svchost.exe程序,路徑為C:\WINDOWS\svchost.exe的(關鍵點:路徑中的\一定要換成\\)

wmic process where "name='svchost.exe' and ExecutablePath='C:\\WINDOWS\\svchost.exe'" call Terminate

BIOS - 基本輸入/輸出服務 (BIOS) 管理

::檢視bios版本型号

wmic bios get name,SMBIOSBIOSVersion,manufacturer

COMPUTERSYSTEM - 計算機系統管理

::檢視硬體、作業系統基本資訊

wmic computersystem get Name,workgroup,NumberOfProcessors,manufacturer,Model

::檢視系統啟動選項boot.ini的内容

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

::更改path環境變量值,新增e:\tools

wmic 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

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檔案夾為abb

wmic fsdir "c:\\good" rename "c:\abb"

LOGICALDISK - 本地儲存裝置管理

::擷取硬碟系統格式、總大小、可用空間等

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

NIC - 網絡界面控制器 (NIC) 管理

OS - 已安裝的作業系統管理

::設定系統時間

wmic os where(primary=1) call setdatetime 20070731144642.555555+480

PAGEFILESET - 頁面檔案設定管理

::更改目前頁面檔案初始大小和最大值

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

::頁面檔案設定到d:\下,執行下面兩條指令

wmic pagefileset create name='d:\pagefile.sys',initialsize=512,maximumsize=1024

wmic pagefileset where"name='c:\\pagefile.sys'" delete

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

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

wmic useraccount where "name='admin" call Rename admin00