1. 程式人生 > >常用WMIC命令集(批處理版本)

常用WMIC命令集(批處理版本)

BIOS - 基本輸入/輸出服務 (BIOS) 管理
::檢視bios版本型號
wmic bios get Manufacturer,Name

COMPUTERSYSTEM - 計算機系統管理
::檢視系統啟動選項,boot的內容
wmic COMPUTERSYSTEM get SystemStartupOptions
::檢視工作組/域
wmic computersystem get domain
::更改計算機名admin為higkoo
wmic computersystem where "name='admin'" call rename higkoo
::更改工作組workgroup為family
wmic computersystem where "name='workgroup'"
call joindomainorworkgroup "","","family",1

CPU - CPU 管理
::檢視cpu型號
wmic cpu get name

DATAFILE - DataFile 管理
::查詢D盤下tmp目錄(不包括子目錄)下的test.txt檔案
wmic datafile where "drive='D:' and path='//tmp//' and FileName='cc' and Extension='txt'" list
::查詢D盤下所有目錄和子目錄下的test.txt檔案,且檔案大小大於1K
wmic datafile where "drive='D:' and FileName='test' and Extension='txt' and FileSize>'1024'"
list
::刪除e盤下檔案大小大於1K的.txt檔案
wmic datafile where "drive='E:' and Extension='txt' and FileSize>'1024'" call delete
::刪除E盤下tmp目錄(不包括子目錄)下的非.txt檔案
wmic datafile where "drive='E:' and Extension<>'txt' and path='tmp'" call delete
::複製e盤下test目錄(不包括子目錄)下的test.txt檔案到E:/,並改名為tmp.bat
wmic datafile where "drive='e:' and path='//test//' and FileName='test' and Extension='cmd'"
call copy "e:/tmp.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 20090315103155.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='D://pagefile.sys'" delete

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

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 - 服務程式管理
::sc config servicename start=[boot|system|auto|demand|disabled
::執行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="AutoTest" call delete

SHARE - 共享資源管理
::刪除共享
wmic SHARE where name="e$" call delete
::新增共享
WMIC SHARE CALL Create "","test","3","TestShareName","","D:/tmp",0

SOUNDDEV - 聲音裝置管理
wmic SOUNDDEV list

STARTUP - 使用者登入到計算機系統時自動執行命令的管理
::檢視msconfig中的啟動選項
wmic STARTUP list

SYSDRIVER - 基本服務的系統驅動程式管理
wmic SYSDRIVER list

USERACCOUNT - 使用者帳戶管理
::更改使用者administrator全名為higkoo
wmic USERACCOUNT where name="Administrator" set FullName="higkoo"
::更改使用者名稱administratorhigkoo
wmic useraccount where "name='Administrator" call Rename higkoo