wmic 命令行介紹

1.wmic 是Microsoft Windows Management Instrumentation(windows管理體系結構)的簡稱。

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 /?

在DOS窗口裏面使用wmic命令行,必須切換到C:\WINDOWS\system32\wbem路徑下

查看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


 

計算機名稱和用戶賬戶管理

 

::重命名計算機名稱administrator爲admin

wmic computersystem where "name=administrator" call rename admin

USERACCOUNT - 用戶帳戶管理

::更改用戶administrator全名爲admin
wmic USERACCOUNT where name="Administrator" set FullName="admin"

 ::更改用戶名admin爲admin00
wmic useraccount where "name='admin" call Rename admin00

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章