天天看點

Windows下 wmic process指令程序管理

【整理,部分非原創】

      WMIC擴充WMI(Windows Management Instrumentation,Windows管理規範) ,提供了從指令行接口和批指令腳本執行系統管理的支援。為WMI名稱空間提供了一個強大的、友好的指令行接口。

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

wmic process一種實際用法,用于判斷查詢是否已啟動某個應用的java程式程序。可用于配合zabbix的自定義監控.

wmic process where name="java.exe" get commandline 2>nul | find "appKey" 1>nul 2>nul && echo 1 || echo 0

含義為:如果windows下啟動了 "appKey" 為關鍵字名字的jar包主程式,指令傳回1;若沒有啟動或者不存在則傳回0

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

netstat -an -b -o   //擷取程序名稱 端口 pid

wmic process list brief >> d:\process.txt  //擷取程序摘要資訊寫入檔案

結束一個程序(可根據程序對應的PID)

wmic process where name="notepad.exe" delete

wmic process where name="notepad.exe" terminate

wmic process where pid="123" delete

wmic path win32_process where "name='notepad.exe'" delete

 建立一個程序

wmic process call create "c:\windows\system32\calc.exe"

查詢程序的啟動路徑(将得到的資訊輸出)

wmic process get name,executablepath,processid

wmic /output:c:\process.html process get processid,name,executablepath /format:htable.xsl

查詢指定程序的資訊

wmic process where name="notepad.exe" get name,executablepath,processid

在遠端計算上建立程序

wmic /node:192.168.8.10 /user:administrator /password:xiongyefeng process call create "c:\windows\notepad.exe"

查詢遠端計算機上的程序清單

wmic /node:192.168.8.10 /user:administrator /password:xiongyefeng process get name,executablepath,processid

将獲得到的遠端計算機程序清單儲存到本地

wmic/output:c:\process.html /node:192.168.8.10 /user:administrator/password:xiongyefeng process get processid,name,executablepath/format:htable.xsl

結束遠端計算上的指定程序

wmic /node:192.168.8.10 /user:administrator /password:xiongyefeng process where name="notepad.exe" delete

重新開機遠端計算機

wmic /node:192.168.8.10 /user:administrator /password:xiongyefeng process call create "shutdown -r -f"

關閉遠端計算機

wmic /node:192.168.8.10 /user:administrator /password:xiongyefeng process call create "shutdown -s -f"

進階應用:

結束可疑的程序

wmic process where "name='explorer.exe' and executablepath <> '%systemdrive%\\windows\\explorer.exe'" delete

wmicprocess where "name='svchost.exe' and executablepath <>'%systemdrive%\\windows\\system32\\svchost.exe'" call terminate

======對磁盤的管理========

檢視磁盤的屬性

wmic logicaldisk list brief

根據磁盤的類型檢視相關屬性

wmic logicaldisk where drivetype=3 list brief

使用get參數來獲得自己想要參看的屬性

wmic logicaldisk where drivetype=3 get deviceid,size,freespace,description,filesystem

隻顯示c盤的相關資訊

wmic logicaldisk where name="c:" get deviceid,size,freespace,description,filesystem

更改卷标的名稱

wmic logicaldisk where name="c:" set volumename=lsxq

獲得U盤的盤符号

wmic logicaldisk where drivetype='2' get deviceid,description

--------------------------------------------------

------------------------------------------------

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

::檢視bios版本型号

wmic bios get Manufacturer,Name

COMPUTERSYSTEM - 計算機系統管理

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

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

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 - 服務程式管理

::運作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