強大的WMIC


 
 
 

WMIC簡單介紹

  1. WMIC 全新的超級命令行管理工具
  2.   微軟Windows Server的圖形界面接口在為網絡管理提供便利的同時,因其消耗資源偏大、操作緩慢而頗受Windows管理員的微詞,為提供一個圖形管理界面之外的另一種選擇,微軟推出了集WMI的強大與命令行的簡潔於一身的全新的命令行管理工具WMIC。加入了WMIC的Windows server 2003的命令行,據稱可以完成幾乎所有的管理任務。
  3.   以DOS起家的微軟,最終靠圖形界面一統了天下。傳統的微軟Windows Server的圖形界面接口,在使系統管理簡單易行的同時,其偏大的資源消耗與緩慢的操作速度,不但使眾多IT Pro級系統管理員頗有微詞,也使許多從Unix、NetWare轉過來的系統管理員短時間內難以適從。雖然微軟開發了WMI(Windows Management Instrumentation,Windows管理架構),並在Support Tools和Resource Kits提供了大量基於WMI的腳本讓管理員使用,在命令行下管理服務器,但復雜的腳本編程同樣令許多管理員卻步,因為並非每個管理員都是腳本編程高手。從另一個角度講,圖形界面接口像一個黑盒子,使許多管理員喪失了量身定制管理任務的機會與樂趣,只能亦步亦趨地跟在越來越多的向導屁股后面,不停地點按着"下一步"。
  4.   鑒於上述原因,微軟在Windows Server 2003中,綜合了WMI的強大與命令行的簡潔,推出了全新的命令行管理工具WMIC,英文全稱Windows Management Instrumentation Command-line,即Windows管理規范命令行。並聲稱使用WMIC,再配合其他現存的命令行工具,管理員幾乎可以完成所有的管理任務,而不必再過多地依賴那些圖形界面。
  5.   本文將對WMIC進行一個簡單的介紹,由於筆者在撰稿時Windows Server 2003還沒有正式發布,所以一切技術均以Windows Server 2003 RC2(Build 3718)為准,最終版本正式發布后可能會有變化。
  6.   背景:WMI、WBEM與CIM
  7.   關於WMI,我們在以前的文章中多次提及,並有過具體的應用,如《使用VS.NET實現WMI調用》(2003年1月刊),《限制域用戶同時的多點登錄》與《來一段腳本,Kill掉Mike的歌》(2003年2月刊)等。這里不准備再對其做詳細的說明,只做一下簡單的介紹。
  8.   WMI是微軟基於Web的企業管理(WBEM)這一理念與標准的具體實現,並對CIM(Common Information Model,公用信息模型)提供完整的支持。WMI由符合CIM標准的對象儲備庫(Object Repository)和CIM對象管理器(WMI Object Manager)組成,其中對象儲備庫是對象定義的數據庫,對象管理器負責處理儲備庫中對象的收集和操作,並從WMI提供程序(WMI Provider)收集信息。WMI提供程序在WMI與操作系統組件、應用程序和其他系統之間充當中間人角色,兩者通過WMI提供程序交換信息。WMI提供程序的主要作用就是為WMI提供下層對象的相關信息,以及允許WMI通過它對下層對象進行管理。例如,注冊表提供程序從注冊表中提供信息,而SNMP提供程序則從SNMP設備中提供數據和事件等。
  9.   WMI被許多計算機管理工具所用,如Microsoft Systems Management Server、Microsoft Health Monitor和Microsoft Operations Manager等。
  10.   WMIC概述
  11.   WMIC,是一款新出現在Windows Server 2003中的命令行管理工具。使用WMIC,你不但可以管理本地計算機,而且可以管理同一Windows域內的所有遠程計算機(需要必要的權限),而被管理的遠程計算機不必事先安裝WMIC,只需要支持WMI即可。
  12.   WMIC有一個能夠分析、解釋和執行從命令行接收的別名(Alias)的引擎,它是一個可執行文件,名為WMIC.exe,這個文件通常位於"c:\windows\
  13.   system32\wbem"文件夾中,該程序運行於用戶當前登錄的計算機上。任何對WMIC命令行的擴展性能都經過別名文件定義或者注冊。別名又稱友好名稱(Friendly Names),通過MOF(Management Object Format,管理對象格式)格式定義。WMIC引擎接收到輸入的命令后,先進行分析。如果命令是一個別名,WMIC會從當前操作命名空間(比如root\cli)調用該別名的定義,應用當前的環境設置(如目標命名空間),並將別名命令與它的原始命令進行對應,然后執行。
  14.   具體來說,你可以使用WMIC實現如下的管理任務:
  15.   1、本地計算機管理
  16.   2、遠程單個計算機管理
  17.   3、遠程多個計算機管理
  18.   4、使用遠程會話的計算機管理(如Telnet)
  19.   5、使用管理腳本的自動管理
  20.   只有本地管理員組成員才能夠啟動WMIC,由於WMIC本質上是WMI的一個客戶端,因此WMIC的安全受限於WMI的安全。當WMIC在一個遠程會話中被使用時,如Telnet、終端服務等,缺省情況下,它使用發起此會話的用戶的安全上下文。在使用WMIC管理一個遠程計算機之前,WMIC會Ping一下遠程計算機以確定其狀態。
  21.   在使用WMIC命令行時,可以隨時使用"/?"來獲得當前命令上下文的幫助信息。
  22.   執行模式
  23.   WMIC可以以兩種模式執行:交互模式(Interactive mode)和非交互模式(Non-Interactive mode),經常使用Netsh命令行的管理員應該非常熟悉這兩種模式。
  24.   交互模式。如果你在命令提示符下或通過"運行"菜單只輸入WMIC,都將進入WMIC的交互模式,每當一個命令執行完畢后,系統還會返回到WMIC提示符下,如"Root\cli",交互模式通常在需要執行多個WMIC指令時使用。當你需要先執行"CONTEXT"命令查看環境變量,再使用"OS"命令查看當前操作系統消息時,就可以使用交互模式,如圖1所示。交互模式有時還會對一些敏感的操作要求確認,比如刪除操作,最大限度地防止管理員出現失誤。
  25.   非交互模式。非交互模式是指將WMIC指令直接作為WMIC的參數放在WMIC后面,當指令執行完畢后再返回到普通的命令提示符下,而不是進入到WMIC上下文環境中。WMIC的非交互模式主要用於批處理或者其他一些腳本文件中,比如上面的"OS"命令在非交互模式下就可以使用下面的方式執行:
  26.   wmic os /?
  27.   使用WMIC管理系統
  28.   WMIC包含了眾多的開關、命令,以及內置的別名,詳細內容見表1、表2和表3。下面讓我們通過具體的實例體驗一下WMIC的強大功能。
  29.   簡單管理任務
  30.   使用WMIC,可以完成一些簡單的管理任務,比如查看硬件與操作系統信息。如果不使用WMIC,查詢硬件如BIOS、CPU、操作系統等信息,通常是使用系統提供的API接口進行編程,或者編寫一小段腳本程序,是一件比較麻煩的事情,如表4所示就是一個查詢BIOS信息的傳統VBscript腳本。如果使用WMIC,那情況就大不相同,只需要一個簡單命令就能搞定:
  31.   wmic bios list full
  32.   結果如圖2所示。
  33.   大家可能注意到了上面命令行中還有兩個參數list和full。list決定顯示的信息格式與范圍,它有Brief、Full、Instance、Status、System、Writeable等多個參數,full只是它的一個參數,也是list的缺省參數,表示顯示所有的信息。其他幾個參數顧名思義,如Brief表示只顯示摘要信息,Instance表示只顯示對象實例,Status表示顯示對象狀態,Writeable表示只顯示該對象的可寫入的屬性信息等。
  34.   在管理過程中,尤其是進行遠程系統管理的時候,管理員多數喜歡列一下進程列表,以了解當前系統中正在運行的程序。下面的命令就可以達到這一目的:
  35.   wmic process list brief
  36.   它會顯示當前所有進程的一些摘要信息,比如進程名稱、進程ID和優先級等。在我以前的文章《來一段腳本,Kill掉Mike的歌》中,就可以使用這一命令代替那個list.vbs腳本。
  37.   復雜管理任務
  38.   WMIC在完成復雜管理任務方面也是非常出色的,先看一下查詢事件日志並生成結果文件的例子:
  39.   WMIC /node:"dc2" /user:"mytest" NTEVENTswheres"eventtype<3 and eventtype>0 AND logfile='Application'" GET Logfile, SourceName, Eventtype, Message, TimeGenerated /FORMAT:htable:"sortby=EventType">c:\Application.htm
  40.   這行長長的命令表示從計算機DC2中查詢應用程序日志信息,事件類型為小於3且大於0的事件,通常是警告與錯誤事件。因為是遠程計算機,所以命令中使用了"/node"和"/user"開關。輸出結果保存為網頁格式,保存在"c:\Application.htm"文件中,並以事件類型進行排序。當你使用上面的命令時,因為使用了"/user"開關,所以系統會首先提示你輸入與該用戶匹配的密碼,如圖3所示,查詢結果如圖4所示。
  41.   同樣,你還可以使用WMIC同時重新啟動多台被管理的服務器或工作站,命令如下:
  42.   WMIC /NODE:@"c:\MyServerList.txt" OSswheres(Primary="TRUE") CALL Win32ShutDown 6
  43.   WMIC會首先從"c:\MyServerList.txt"中取得服務器名稱列表,這些服務器名稱在文件中以逗號分割,如"dc1,dc2"。要注意的是,在/node開關后面使用服務器列表文件時,一定要在文件名的前面加上"@"引導符。該命令執行結果如圖5所示,在執行重新啟動過程中,WMIC會返回詳細的執行結果。
  44.   WMIC還可以從Active Directory中取得數據,下面是一個從Active Directory中取得用戶信息的例子,取得的用戶信息包括顯示名稱、UPN名稱、名稱和創建時間等,返回結果如圖6所示:
  45.   WMIC/NAMESPACE:\root\directory\ldap PATH ds_user GET ds_displayname, ds_userprincipalname, ds_cn, ds_name, ds_whencreated /VALUE
  46.   總結
  47.   WMIC是我所見到的基於windows平台的功能最強大的命令行工具,但同樣也是最復雜的工具。尤其是在完成復雜的管理任務時,你需要對WMI的Win32類的屬性及方法非常熟悉才可能做到游刃有余。因此,在希望熟悉運用WMIC之前,建議先學習WMI,熟悉其Win32類的各種屬性及方法。國內現在出過幾本不錯的WMI書籍,你也可以到微軟的MSDN網站(MSDN.microsoft.com)上查詢這方面的信息。
  48.   有了WMIC的加入,命令行們應該可以大聲說:"雖然我很丑,但是我很強大"了
 
 

TOP

 
 
 
 

WMIC開發技術資料全收藏

  1. 最近收集了一些WIM WMIC的有關資料,現在貼一些上來,需要的可以頂帖,如果斑竹看的上可以加精!
  2. 謝謝,對於WIM和WIMC我不懂,最近聽說這個東西很好,可以配合WINDOWS腳本完成絕大多數的系統維護操作,而且到MS網站上的腳本中心看到大量的腳本實例,覺得很有研究價值!
  3. 根據樓下的兄弟建議,把所有的都轉移到頂貼中便於下載。謝謝該兄弟的建議。
  4. 1.《WMI技術指南》:這個是基本上已經絕版的好圖書,在網上唯一能找到的是來自“MS技術中國”的掃描版,該書我也是向該論壇斑竹索取的。謝謝技術中國也謝謝CN-DOS。
  5. 下載地址:
  6. http://zhenlove.com.cn/cndos/fileup/files/Wmi技術指南(PDF).rar
  7. 2.《WMI開發文檔》來自MS網站,下載地址是:http://zhenlove.com.cn/cndos/fileup/files/wmisdk(WMI開發文檔).rar
  8. 3.《WMIC:從命令行對Windows的全面管理》,收集於網站:下載地址:
  9. http://zhenlove.com.cn/cndos/fileup/files/WMIC從命令行對Windows的全面管理.rar
  10. 4.一段關於WMI的腳本,該腳本來自MS網站,原內容有點問題,稍微修正了一下.要運行該腳本,請復制代碼到記事本中並保存為"search.vbs",注意保存時必須加引號,否則不是腳本文件而是文本文件;然后到CMD下使用命令,格式如下:Search.vbs 類關鍵字,該腳本可以實現搜索WMI CLASS的是屬性等.
  11. ;代碼開始=============================================
  12. Set args = wscript.arguments
  13. If args.Count <= 0 Then
  14.     Wscript.Echo "Tool to search for a matching class in the WMI Repository. "
  15.     Wscript.Echo "USAGE: <keywordToSearch> [<namespaceToSearchIn>]"
  16.     Wscript.Echo "Example1: Cscript search.vbs service"
  17.     Wscript.Echo "Example2: Cscript search.vbs video root\cimv2"
  18. Else
  19.     ' If no Namespace is specified then the Default is the ROOT namespace
  20.     rootNamespace = "\\.\ROOT"
  21.     keyword = args(0)
  22.     If args.Count > 1 Then
  23.         rootNamespace = args(1)
  24.     End If   
  25.     EnumNameSpace rootNamespace
  26.     Wscript.Echo vbNewLine
  27. End if
  28.   
  29. ' Subroutine to recurse through the namespaces
  30. Sub EnumNameSpace(parentNamespaceName)
  31. Set objService = GetObject("winmgmts:" & parentNamespaceName)
  32. Set collMatchingClasses = objService.Execquery _
  33.     ("Select * From meta_class Where __class " & _
  34.     "Like '%" & keyword & "%'")
  35. If (collMatchingClasses.count > 0) Then
  36.     Wscript.Echo vbNewLine
  37.     Wscript.Echo vbNewLine
  38.     Wscript.Echo "Matching Classes Under Namespace: " & parentNamespaceName
  39.     For Each matchingClass in collMatchingClasses
  40.         Wscript.Echo "    " & matchingClass.Path_.CLASS
  41.     Next   
  42. End if
  43. Set collSubNamespaces = objService.Execquery _
  44.     ("select * from __namespace")
  45. For Each subNameSpace in collSubNamespaces
  46.     EnumNameSpace subNameSpace.path_.namespace + _
  47.         "\" + subNameSpace.Name
  48. Next
  49. End Sub
  50. ;代碼結束======================================================
  51. 5.WMI CLASSES有關資料,來源於MS網站,下載地址:http://zhenlove.com.cn/cndos/fileup/files/WMI Classes.rar
  52. 關於檢查電腦所有腳本版本檢測的有關腳本,請把代碼保存為version.vbs.雙擊運行或在CMD下輸入 start version.vbs (注意匹配自己的路徑)
  53. ;代碼開始===============================================
  54. On Error Resume Next
  55. WScript.Echo "WSH Version: " & WScript.Version
  56. Wscript.Echo "VBScript Version: " & ScriptEngineMajorVersion _
  57.     & "." & ScriptEngineMinorVersion
  58. strComputer = "."
  59. Set objWMIService = GetObject("winmgmts:" _
  60.     & "{impersonationLevel=impersonate}!\\" & strComputer _
  61.         & "\root\cimv2")
  62. Set colWMISettings = objWMIService.ExecQuery _
  63.     ("Select * from Win32_WMISetting")
  64. For Each objWMISetting in colWMISettings
  65.     Wscript.Echo "WMI Version: " & objWMISetting.BuildVersion
  66. Next
  67. Set objShell = CreateObject("WScript.Shell")
  68. strAdsiVersion = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{E92B03AB-B707-11d2-9CBD-0000F87A369E}\Version")
  69. If strAdsiVersion = vbEmpty Then
  70.     strAdsiVersion = objShell.RegRead("HKLM\SOFTWARE\Microsoft\ADs\Providers\LDAP\")
  71.     If strAdsiVersion = vbEmpty Then
  72.         strAdsiVersion = "ADSI is not installed."
  73.     Else
  74.         strAdsiVersion = "2.0"
  75.     End If
  76. End If
  77. WScript.Echo "ADSI Version: " & strAdsiVersion
  78. ;代碼結束==========================================
  79. .再來傳一個WMI的有關工具,這個還是從MS網站上搞下來的.MS把這個東西吹的很好喲.這個實際上是一個HTML文件.我把代碼貼上來,請復制所有代碼到文本文件中,然后保存為"scriptomatic.hta"雙擊運行即可.
  80. ;代碼開始====================================
  81. <html>
  82. <!--********************************************************************
  83. '*
  84. '*  File:           scriptomatic.hta
  85. '*  Created:        August 2002
  86. '*  Version:        1.0
  87. '*
  88. '*  Description:    Learning tool. Enables users to generate and run
  89. '*                  WSH scripts (in VBScript) that use WMI to display
  90. '*                  properties available through the Win32_ classes.      
  91. '*
  92. '*
  93. '* Copyright (C) 2002 Microsoft Corporation
  94. '*
  95. '********************************************************************-->
  96. <title>Windows .NET Server Resource Kit - Scriptomatic</title>
  97. <HTA:APPLICATION
  98.      ID="objScriptomatic"
  99.      APPLICATIONNAME="Scriptomatic"
  100.      SCROLL="no"
  101.      SINGLEINSTANCE="yes"
  102.      WINDOWSTATE="normal"
  103. >
  104. <head>
  105. <style>
  106. BODY
  107. {
  108.    background-color: buttonface;
  109.    font-family: Helvetica;
  110.    font-size: 8pt;
  111.    margin-top: 10px;
  112.    margin-left: 10px;
  113.    margin-right: 10px;
  114.    margin-bottom: 10px;
  115. }
  116. .button
  117. {
  118.    font-family: Helvetica;
  119.    font-size: 8pt;
  120.    width: 35px;
  121. }
  122. textarea
  123. {
  124.    font-family: arial;
  125.    font-size: 8pt;
  126.    margin-left: 3px;
  127. }
  128. select
  129. {
  130.    font-family: arial;
  131.    font-size: 8pt;
  132.    width: 450px;
  133.    margin-left: 0px;
  134. }
  135. </style>
  136. <script language="vbscript">
  137. '*********************************************
  138. '* WHILE LOADING...
  139. '*
  140. '* As the application loads, we open a new
  141. '* browser window to act as a crude progress dialog
  142. '* while we wait for the enumeration of the WMI
  143. '* classes to complete.
  144. '*
  145. '* We minimize the parent window prior to presenting
  146. '* the progress dialog and resize it back to normal
  147. '* once the classes are enumerated.
  148. '*
  149. '*********************************************
  150. Sub Window_Onload
  151.    '* resize parent window
  152.    self.ResizeTo 1,1
  153.    self.MoveTo 300,300
  154.    
  155.    '* create dialog window
  156.    Set objDialogWindow = window.Open("about:blank","ProgressWindow","height=15,width=250,left=300,top=300,status=no,titlebar=no,toolbar=no,menubar=no,location=no,scrollbars=no")
  157.    objDialogWindow.Focus()
  158.    objDialogWindow.ResizeTo 250,15
  159.    objDialogWindow.document.body.style.fontFamily = "Helvetica"
  160.    objDialogWindow.document.body.style.fontSize = "11pt"
  161.    objDialogWindow.document.writeln "<html><body>Loading WMI Classes.</body></html>"
  162.    objDialogWindow.document.title = "Please wait."
  163.    objDialogWindow.document.body.style.backgroundColor = "buttonface"
  164.    objDialogWindow.document.body.style.borderStyle = "none"
  165.    objDialogWindow.document.body.style.marginTop = 15
  166.    '****************************************************************************
  167.    '* enumerate the WMI classes in the cimv2 namespace, filling up a recordset
  168.    '* with the names of the classes that begin with Win32_ and are not association
  169.    '* classes. we'll use the class names stored in the recordset to populate a
  170.    '* pulldown.
  171.    '*****************************************************************************
  172.    Const adVarChar = 200
  173.    Const MaxCharacters = 255
  174.    strComputer = "."
  175.    
  176.    Set rsDataList = CreateObject("ADODB.Recordset")
  177.    rsDataList.Fields.Append "ClassName", adVarChar, MaxCharacters
  178.    rsDataList.Open
  179.    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  180.    
  181.    iCounter = 0
  182.    For Each objclass in objWMIService.SubclassesOf()
  183.    '* write a . to the dialog window once for every 250 classes
  184.    '* to let the user know something is still happening.
  185.       iCounter = iCounter + 1
  186.       If iCounter Mod 250 = 0 Then
  187.          objDialogWindow.document.writeln "."
  188.       End If
  189.       bIsQualifier = False
  190.       If UCase(Left(objClass.Path_.Class,5)) = "WIN32" Then
  191.          For Each Qualifier in objClass.Qualifiers_
  192.             If UCase(Trim(Qualifier.Name)) = "ASSOCIATION" Then
  193.                bIsQualifier = True
  194.             End If
  195.          Next
  196.    '* the class name starts with win32_ and is not an association
  197.    '* class - so append it to the recordset
  198.          If bIsQualifier = False Then
  199.             rsDataList.AddNew
  200.             rsDataList("ClassName") = objClass.Path_.Class
  201.             rsDataList.Update
  202.          End If
  203.       End If
  204.    Next
  205.    '* populate the pulldown
  206.    rsDataList.Sort = "ClassName"
  207.    rsDataList.MoveFirst
  208.    strHTML = "<select onChange=""ComposeCode()"" name=ClassesPulldown>" &_
  209.              "<option value=""PulldownMessage"">Begin by selecting a class"
  210.    Do Until rsDataList.EOF
  211.       strHTML = strHTML & "<option value= " & chr(34) &_
  212.       rsDataList.Fields.Item("ClassName") & chr(34) &_
  213.       ">" & rsDataList.Fields.Item("ClassName")
  214.       rsDataList.MoveNext
  215.    Loop
  216.    strHTML = strHTML & "</select>"
  217.    wmi_classes.insertAdjacentHTML "beforeEnd", strHTML
  218.    '* the classes are enumerated, close the progress dialog
  219.    '* and resize the main window
  220.    objDialogWindow.Close
  221.    self.Focus()
  222.    self.ResizeTo 670,550
  223.    self.MoveTo 200,200
  224.    
  225.    '* the user hasn't had a chance to select a class and generate
  226.    '* a script - so disable the run and save buttons because
  227.    '* they are not yet meaningful.
  228.    
  229.    run_button.disabled = True
  230.    save_button.disabled = True
  231. End Sub
  232. '****************************************************************************
  233. '* when the user selects a class from the pulldown, the ComposeCode subroutine
  234. '* is called. it queries WMI to determine the properties of the class the user
  235. '* selected and uses the information to construct sample code which it puts
  236. '* in the main window's textarea.
  237. '****************************************************************************
  238. Sub ComposeCode
  239.    '* if the user happens to select the message instead of a class, just
  240.    '* disable the run and save buttons and exit the subroutine
  241.    If ClassesPulldown.Value = "PulldownMessage" Then
  242.       run_button.disabled = True
  243.       save_button.disabled = True
  244.       Exit Sub
  245.    End If
  246.    strComputer = "."
  247.    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  248.    Set objClass = objWMIService.Get(ClassesPulldown.Value)
  249.    strHTML = "<textarea cols=100 rows=30>"
  250.    strHTML = strHTML & "On Error Resume Next" & Chr(10)
  251.    strHTML = strHTML & "strComputer = " & chr(34) & "." & chr(34) & Chr(10)
  252.    strHTML = strHTML & "Set objWMIService = GetObject(" & chr(34) & "winmgmts:\\" & chr(34) & " & strComputer & " & chr(34) & "\root\cimv2" & chr(34) & ")" & Chr(10)
  253.    strHTML = strHTML & "Set colItems = objWMIService.ExecQuery(" & chr(34) & "Select * from " & ClassesPulldown.value & chr(34) & ",,48)" & Chr(10)
  254.    strHTML = strHTML & "For Each objItem in colItems" & Chr(10)
  255.    For Each objProperty in objClass.properties_
  256.       strHTML = strHTML & "&nbsp; &nbsp; Wscript.Echo " & chr(34) & objProperty.name & ": " & chr(34) & " & " & "objItem." & objProperty.name & Chr(10)
  257.    Next
  258.    strHTML = strHTML & "Next" & "</textarea>"
  259.    code.InnerHTML= strHTML
  260.    '* once the code is successfully composed and put into the textarea, ensure
  261.    '* that the run and save buttons are enabled
  262.    run_button.disabled = False
  263.    save_button.disabled = False
  264. End Sub
  265. '****************************************************************************
  266. '* when the user presses the Run button, we use the WshShell object's Run
  267. '* method to run the code currently in the textarea under cscript.exe. we use
  268. '* cmd.exe's /k parameter to ensure the command window remains visible after
  269. '* the script has finished running.
  270. '****************************************************************************
  271. Sub RunScript
  272.    Set objFS = CreateObject("Scripting.FileSystemObject")
  273.    strTmpName = "temp_script.vbs"
  274.    Set objScript = objFS.CreateTextFile(strTmpName)
  275.    objScript.Write code.InnerText
  276.    objScript.Close
  277.    Set objShell = CreateObject("WScript.Shell")
  278.    strCmdLine = "cmd /k cscript.exe "
  279.    strCmdLine = strCmdLine & strTmpName
  280.    objShell.Run(strCmdLine)
  281. End Sub
  282. '****************************************************************************
  283. '* when the user presses the Save button, we present them with an InputBox
  284. '* and force them to give us the full path to where they'd like to the save
  285. '* the script that is currently in the textarea. The user is probably quite
  286. '* upset with our laziness here....and who can blame them?
  287. '****************************************************************************
  288. Sub SaveScript
  289.    Set objFSO = CreateObject("Scripting.FileSystemObject")
  290.    strSaveFileName = InputBox("Please enter the complete path where you want to save your script (for example, C:\Scripts\MyScript.vbs).")
  291.    If strSaveFileName = "" Then
  292.       Exit Sub
  293.    End If
  294.    Set objFile = objFSO.CreateTextFile(strSaveFileName)
  295.    objFile.WriteLine code.InnerText
  296.    objFile.Close
  297. End Sub
  298. '****************************************************************************
  299. '* when the user presses the Open button, we present them with an InputBox
  300. '* and force them to give us the full path to the script they'd like to open.
  301. '* This is, of course, rather wonky - but it's meant to be.
  302. '****************************************************************************
  303. Sub OpenScript
  304.    Set objFSO = CreateObject("Scripting.FileSystemObject")
  305.    strOpenFileName = InputBox("Please enter the complete path name for your script (for example, C:\Scripts\MyScript.vbs).")
  306.    If strOpenFileName = "" Then
  307.       Exit Sub
  308.    End If
  309.    Set objFile = objFSO.OpenTextFile(strOpenFileName)
  310.    strHTML = "<textarea cols=100 rows=30>"
  311.    strHTML = strHTML & objFile.ReadAll()
  312.    strHTML = strHTML & "</textarea>"
  313.    code.InnerHTML =  strHTML
  314.    objFile.Close
  315.    run_button.disabled = False
  316.    save_button.disabled = False
  317. End Sub
  318. '****************************************************************************
  319. '* when the user presses the Quit button, the file where we've been storing
  320. '* the scripts gets deleted and the main window closes.
  321. '****************************************************************************
  322. Sub QuitScript
  323.    On Error Resume Next
  324.    Set objFSO = CreateObject("Scripting.FileSystemObject")
  325.    objFSO.DeleteFile "temp_script.vbs"
  326.    Set objFSO = Nothing
  327.    self.Close()
  328. End Sub
  329. </script>
  330. </head>
  331. '***********************************************************
  332. '* our HTML layout - the only thing of note here is that when
  333. '* each of the buttons is pressed (clicked), their onClick
  334. '* attributes causes the appropriate subroutine to be called
  335. '***********************************************************
  336. <body>
  337. <table>
  338.    <td>
  339.       <span id="wmi_classes">&nbsp;</span>
  340.       <input id=runbutton  class="button" type="button" value="Run"  name="run_button"  onClick="RunScript()">
  341.       <input id=savebutton class="button" type="button" value="Save" name="save_button" onClick="SaveScript()">
  342.       <input id=openbutton class="button" type="button" value="Open" name="open_button" onClick="OpenScript()">
  343.       <input id=quitbutton class="button" type="button" value="Quit" name="quit_button" onClick="QuitScript()">
  344.       <div ID=code_header></div>
  345.       <div id="code"></div>
  346.    </td>
  347. </tr>
  348. </table>
  349. </body>
  350. </html>
  351. ;代碼結束==============================================
  352. 9.再來一個WMI腳本教程.這個也是從網絡上搜集的,不記得下載地址了.好象里面差一個第四章的,可以自己到網絡上搜索,好象在MS網站也有,地址是http://www.microsoft.com/china/M ... inicscripting.mspx.
  353. 下載地址:http://zhenlove.com.cn/cndos/fileup/files/wmi腳本入門(pdf不完整).rar
  354. 8.再來一個WMI查詢分析工具.是外國網站的.里面賦有源代碼,不下載的要后悔喲.不過我的電腦上運行不了該程序,不知道為什么,大家測試反饋下是什么問題.謝謝。
  355. 下載地址:
  356. http://zhenlove.com.cn/cndos/fileup/files/WQLAnalyzer_1.02(wmi查詢分析工具有源代碼).zip
  357. 10.《WINDOWS WMI參考》,由於這個只能在網絡上閱讀,找不到相關的電子書下載,所以就把所有抓的網頁發上來。其中名稱前面的數字代表章節號,如0101代表第一章第一節,050105代表第五章-第一節-第一小節。
  358. 下載地址:
  359. http://zhenlove.com.cn/cndos/fileup/files/windowswmi參考.rar
  360. 11.《WMI開發工具包》,這個是直接從MS 網站上下的,其中已經包含前面發的wmisdk(WMI開發文檔).rar,所以下載這個的可以不再下載上面的哪個。
  361. http://zhenlove.com.cn/cndos/fileup/files/
  362. wmisdk(WMI開發工具包).rar
 
 
 

 

 
 

WMIC應用類日志

  1. 所有Win32 Classes (Win32節點) ,篩選顯示信息見2樓舉例
  2. Wmic Path Win32_1394Controller
  3. Wmic Path Win32_1394ControllerDevice
  4. Wmic Path Win32_Account
  5. Wmic Path Win32_AccountSID
  6. Wmic Path Win32_ACE
  7. Wmic Path Win32_ActionCheck
  8. Wmic Path Win32_ActiveRoute
  9. Wmic Path Win32_AllocatedResource
  10. Wmic Path Win32_ApplicationCommandLine
  11. Wmic Path Win32_ApplicationService
  12. Wmic Path Win32_AssociatedBattery
  13. Wmic Path Win32_AssociatedProcessorMemory
  14. Wmic Path Win32_AutochkSetting
  15. Wmic Path Win32_BaseBoard
  16. Wmic Path Win32_BaseService
  17. Wmic Path Win32_Battery
  18. Wmic Path Win32_Binary
  19. Wmic Path Win32_BindImageAction
  20. Wmic Path Win32_BIOS
  21. Wmic Path Win32_BootConfiguration
  22. Wmic Path Win32_Bus
  23. Wmic Path Win32_CacheMemory
  24. Wmic Path Win32_CDROMDrive
  25. Wmic Path Win32_CheckCheck
  26. Wmic Path Win32_CIMLogicalDeviceCIMDataFile
  27. Wmic Path Win32_ClassicCOMApplicationClasses
  28. Wmic Path Win32_ClassicCOMClass
  29. Wmic Path Win32_ClassicCOMClassSetting
  30. Wmic Path Win32_ClassicCOMClassSettings
  31. Wmic Path Win32_ClassInfoAction
  32. Wmic Path Win32_ClientApplicationSetting
  33. Wmic Path Win32_CodecFile
  34. Wmic Path Win32_CollectionStatistics
  35. Wmic Path Win32_COMApplication
  36. Wmic Path Win32_COMApplicationClasses
  37. Wmic Path Win32_COMApplicationSettings
  38. Wmic Path Win32_COMClass
  39. Wmic Path Win32_ComClassAutoEmulator
  40. Wmic Path Win32_ComClassEmulator
  41. Wmic Path Win32_CommandLineAccess
  42. Wmic Path Win32_ComponentCategory
  43. Wmic Path Win32_ComputerShutdownEvent
  44. Wmic Path Win32_ComputerSystem
  45. Wmic Path Win32_ComputerSystemEvent
  46. Wmic Path Win32_ComputerSystemProcessor
  47. Wmic Path Win32_ComputerSystemProduct
  48. Wmic Path Win32_ComputerSystemWindowsProductActivationSetting
  49. Wmic Path Win32_COMSetting
  50. Wmic Path Win32_Condition
  51. Wmic Path Win32_ConnectionShare
  52. Wmic Path Win32_ControllerHasHub
  53. Wmic Path Win32_CreateFolderAction
  54. Wmic Path Win32_CurrentProbe
  55. Wmic Path Win32_CurrentTime
  56. Wmic Path Win32_DCOMApplication
  57. Wmic Path Win32_DCOMApplicationAccessAllowedSetting
  58. Wmic Path Win32_DCOMApplicationLaunchAllowedSetting
  59. Wmic Path Win32_DCOMApplicationSetting
  60. Wmic Path Win32_DefragAnalysis
  61. Wmic Path Win32_DependentService
  62. Wmic Path Win32_Desktop
  63. Wmic Path Win32_DesktopMonitor
  64. Wmic Path Win32_DeviceBus
  65. Wmic Path Win32_DeviceChangeEvent
  66. Wmic Path Win32_DeviceMemoryAddress
  67. Wmic Path Win32_DeviceSettings
  68. Wmic Path Win32_DFSNode
  69. Wmic Path Win32_DFSNodeTarget
  70. Wmic Path Win32_DFSTarget
  71. Wmic Path Win32_Directory
  72. Wmic Path Win32_DirectorySpecification
  73. Wmic Path Win32_DiskDrive
  74. Wmic Path Win32_DiskDrivePhysicalMedia
  75. Wmic Path Win32_DiskDriveToDiskPartition
  76. Wmic Path Win32_DiskPartition
  77. Wmic Path Win32_DiskQuota
  78. Wmic Path Win32_DisplayConfiguration
  79. Wmic Path Win32_DisplayControllerConfiguration
  80. Wmic Path Win32_DMAChannel
  81. Wmic Path Win32_DriverForDevice
  82. Wmic Path Win32_DriverVXD
  83. Wmic Path Win32_DuplicateFileAction
  84. Wmic Path Win32_Environment
  85. Wmic Path Win32_EnvironmentSpecification
  86. Wmic Path Win32_ExtensionInfoAction
  87. Wmic Path Win32_Fan
  88. Wmic Path Win32_FileSpecification
  89. Wmic Path Win32_FloppyController
  90. Wmic Path Win32_FloppyDrive
  91. Wmic Path Win32_FontInfoAction
  92. Wmic Path Win32_Group
  93. Wmic Path Win32_GroupInDomain
  94. Wmic Path Win32_GroupUser
  95. Wmic Path Win32_HeatPipe
  96. Wmic Path Win32_IDEController
  97. Wmic Path Win32_IDEControllerDevice
  98. Wmic Path Win32_ImplementedCategory
  99. Wmic Path Win32_InfraredDevice
  100. Wmic Path Win32_IniFileSpecification
  101. Wmic Path Win32_InstalledSoftwareElement
  102. Wmic Path Win32_IP4PersistedRouteTable
  103. Wmic Path Win32_IP4RouteTable
  104. Wmic Path Win32_IP4RouteTableEvent
  105. Wmic Path Win32_IRQResource
  106. Wmic Path Win32_JobObjectStatus
  107. Wmic Path Win32_Keyboard
  108. Wmic Path Win32_LaunchCondition
  109. Wmic Path Win32_LoadOrderGroup
  110. Wmic Path Win32_LoadOrderGroupServiceDependencies
  111. Wmic Path Win32_LoadOrderGroupServiceMembers
  112. Wmic Path Win32_LocalTime
  113. Wmic Path Win32_LoggedOnUser
  114. Wmic Path Win32_LogicalDisk
  115. Wmic Path Win32_LogicalDiskRootDirectory
  116. Wmic Path Win32_LogicalDiskToPartition
  117. Wmic Path Win32_LogicalFileAccess
  118. Wmic Path Win32_LogicalFileAuditing
  119. Wmic Path Win32_LogicalFileGroup
  120. Wmic Path Win32_LogicalFileOwner
  121. Wmic Path Win32_LogicalFileSecuritySetting
  122. Wmic Path Win32_LogicalMemoryConfiguration
  123. Wmic Path Win32_LogicalProgramGroup
  124. Wmic Path Win32_LogicalProgramGroupDirectory
  125. Wmic Path Win32_LogicalProgramGroupItem
  126. Wmic Path Win32_LogicalProgramGroupItemDataFile
  127. Wmic Path Win32_LogicalShareAccess
  128. Wmic Path Win32_LogicalShareAuditing
  129. Wmic Path Win32_LogicalShareSecuritySetting
  130. Wmic Path Win32_LogonSession
  131. Wmic Path Win32_LogonSessionMappedDisk
  132. Wmic Path Win32_LUID
  133. Wmic Path Win32_LUIDandAttributes
  134. Wmic Path Win32_ManagedSystemElementResource
  135. Wmic Path Win32_MappedLogicalDisk
  136. Wmic Path Win32_MemoryArray
  137. Wmic Path Win32_MemoryArrayLocation
  138. Wmic Path Win32_MemoryDevice
  139. Wmic Path Win32_MemoryDeviceArray
  140. Wmic Path Win32_MemoryDeviceLocation
  141. Wmic Path Win32_MethodParameterClass
  142. Wmic Path Win32_MIMEInfoAction
  143. Wmic Path Win32_ModuleLoadTrace
  144. Wmic Path Win32_ModuleTrace
  145. Wmic Path Win32_MotherboardDevice
  146. Wmic Path Win32_MountPoint
  147. Wmic Path Win32_MoveFileAction
  148. Wmic Path Win32_MSIResource
  149. Wmic Path Win32_NamedJobObject
  150. Wmic Path Win32_NamedJobObjectActgInfo
  151. Wmic Path Win32_NamedJobObjectLimit
  152. Wmic Path Win32_NamedJobObjectLimitSetting
  153. Wmic Path Win32_NamedJobObjectProcess
  154. Wmic Path Win32_NamedJobObjectSecLimit
  155. Wmic Path Win32_NamedJobObjectSecLimitSetting
  156. Wmic Path Win32_NamedJobObjectStatistics
  157. Wmic Path Win32_NetworkAdapter
  158. Wmic Path Win32_NetworkAdapterConfiguration
  159. Wmic Path Win32_NetworkAdapterSetting
  160. Wmic Path Win32_NetworkClient
  161. Wmic Path Win32_NetworkConnection
  162. Wmic Path Win32_NetworkLoginProfile
  163. Wmic Path Win32_NetworkProtocol
  164. Wmic Path Win32_NTDomain
  165. Wmic Path Win32_NTEventlogFile
  166. Wmic Path Win32_NTLogEvent
  167. Wmic Path Win32_NTLogEventComputer
  168. Wmic Path Win32_NTLogEventLog
  169. Wmic Path Win32_NTLogEventUser
  170. Wmic Path Win32_ODBCAttribute
  171. Wmic Path Win32_ODBCDataSourceAttribute
  172. Wmic Path Win32_ODBCDataSourceSpecification
  173. Wmic Path Win32_ODBCDriverAttribute
  174. Wmic Path Win32_ODBCDriverSoftwareElement
  175. Wmic Path Win32_ODBCDriverSpecification
  176. Wmic Path Win32_ODBCSourceAttribute
  177. Wmic Path Win32_ODBCTranslatorSpecification
  178. Wmic Path Win32_OnBoardDevice
  179. Wmic Path Win32_OperatingSystem
  180. Wmic Path Win32_OperatingSystemAutochkSetting
  181. Wmic Path Win32_OperatingSystemQFE
  182. Wmic Path Win32_OSRecoveryConfiguration
  183. Wmic Path Win32_PageFile
  184. Wmic Path Win32_PageFileElementSetting
  185. Wmic Path Win32_PageFileSetting
  186. Wmic Path Win32_PageFileUsage
  187. Wmic Path Win32_ParallelPort
  188. Wmic Path Win32_Patch
  189. Wmic Path Win32_PatchFile
  190. Wmic Path Win32_PatchPackage
  191. Wmic Path Win32_PCMCIAController
  192. Wmic Path Win32_Perf
  193. Wmic Path Win32_PerfFormattedData
  194. Wmic Path Win32_PerfFormattedData_ASP_ActiveServerPages
  195. Wmic Path Win32_PerfFormattedData_ContentFilter_IndexingServiceFilter
  196. Wmic Path Win32_PerfFormattedData_ContentIndex_IndexingService
  197. Wmic Path Win32_PerfFormattedData_InetInfo_InternetInformationServicesGlobal
  198. Wmic Path Win32_PerfFormattedData_ISAPISearch_HttpIndexingService
  199. Wmic Path Win32_PerfFormattedData_MSDTC_DistributedTransactionCoordinator
  200. Wmic Path Win32_PerfFormattedData_NTFSDRV_SMTPNTFSStoreDriver
  201. Wmic Path Win32_PerfFormattedData_PerfDisk_LogicalDisk
  202. Wmic Path Win32_PerfFormattedData_PerfDisk_PhysicalDisk
  203. Wmic Path Win32_PerfFormattedData_PerfNet_Browser
  204. Wmic Path Win32_PerfFormattedData_PerfNet_Redirector
  205. Wmic Path Win32_PerfFormattedData_PerfNet_Server
  206. Wmic Path Win32_PerfFormattedData_PerfNet_ServerWorkQueues
  207. Wmic Path Win32_PerfFormattedData_PerfOS_Cache
  208. Wmic Path Win32_PerfFormattedData_PerfOS_Memory
  209. Wmic Path Win32_PerfFormattedData_PerfOS_Objects
  210. Wmic Path Win32_PerfFormattedData_PerfOS_PagingFile
  211. Wmic Path Win32_PerfFormattedData_PerfOS_Processor
  212. Wmic Path Win32_PerfFormattedData_PerfOS_System
  213. Wmic Path Win32_PerfFormattedData_PerfProc_FullImage_Costly
  214. Wmic Path Win32_PerfFormattedData_PerfProc_Image_Costly
  215. Wmic Path Win32_PerfFormattedData_PerfProc_JobObject
  216. Wmic Path Win32_PerfFormattedData_PerfProc_JobObjectDetails
  217. Wmic Path Win32_PerfFormattedData_PerfProc_Process
  218. Wmic Path Win32_PerfFormattedData_PerfProc_ProcessAddressSpace_Costly
  219. Wmic Path Win32_PerfFormattedData_PerfProc_Thread
  220. Wmic Path Win32_PerfFormattedData_PerfProc_ThreadDetails_Costly
  221. Wmic Path Win32_PerfFormattedData_PSched_PSchedFlow
  222. Wmic Path Win32_PerfFormattedData_PSched_PSchedPipe
  223. Wmic Path Win32_PerfFormattedData_RemoteAccess_RASPort
  224. Wmic Path Win32_PerfFormattedData_RemoteAccess_RASTotal
  225. Wmic Path Win32_PerfFormattedData_RSVP_ACSRSVPInterfaces
  226. Wmic Path Win32_PerfFormattedData_RSVP_ACSRSVPService
  227. Wmic Path Win32_PerfFormattedData_SMTPSVC_SMTPServer
  228. Wmic Path Win32_PerfFormattedData_Spooler_PrintQueue
  229. Wmic Path Win32_PerfFormattedData_TapiSrv_Telephony
  230. Wmic Path Win32_PerfFormattedData_Tcpip_ICMP
  231. Wmic Path Win32_PerfFormattedData_Tcpip_IP
  232. Wmic Path Win32_PerfFormattedData_Tcpip_NBTConnection
  233. Wmic Path Win32_PerfFormattedData_Tcpip_NetworkInterface
  234. Wmic Path Win32_PerfFormattedData_Tcpip_TCP
  235. Wmic Path Win32_PerfFormattedData_Tcpip_UDP
  236. Wmic Path Win32_PerfFormattedData_TermService_TerminalServices
  237. Wmic Path Win32_PerfFormattedData_TermService_TerminalServicesSession
  238. Wmic Path Win32_PerfFormattedData_W3SVC_WebService
  239. Wmic Path Win32_PerfRawData
  240. Wmic Path Win32_PerfRawData_ASP_ActiveServerPages
  241. Wmic Path Win32_PerfRawData_ContentFilter_IndexingServiceFilter
  242. Wmic Path Win32_PerfRawData_ContentIndex_IndexingService
  243. Wmic Path Win32_PerfRawData_InetInfo_InternetInformationServicesGlobal
  244. Wmic Path Win32_PerfRawData_ISAPISearch_HttpIndexingService
  245. Wmic Path Win32_PerfRawData_MSDTC_DistributedTransactionCoordinator
  246. Wmic Path Win32_PerfRawData_NTFSDRV_SMTPNTFSStoreDriver
  247. Wmic Path Win32_PerfRawData_PerfDisk_LogicalDisk
  248. Wmic Path Win32_PerfRawData_PerfDisk_PhysicalDisk
  249. Wmic Path Win32_PerfRawData_PerfNet_Browser
  250. Wmic Path Win32_PerfRawData_PerfNet_Redirector
  251. Wmic Path Win32_PerfRawData_PerfNet_Server
  252. Wmic Path Win32_PerfRawData_PerfNet_ServerWorkQueues
  253. Wmic Path Win32_PerfRawData_PerfOS_Cache
  254. Wmic Path Win32_PerfRawData_PerfOS_Memory
  255. Wmic Path Win32_PerfRawData_PerfOS_Objects
  256. Wmic Path Win32_PerfRawData_PerfOS_PagingFile
  257. Wmic Path Win32_PerfRawData_PerfOS_Processor
  258. Wmic Path Win32_PerfRawData_PerfOS_System
  259. Wmic Path Win32_PerfRawData_PerfProc_FullImage_Costly
  260. Wmic Path Win32_PerfRawData_PerfProc_Image_Costly
  261. Wmic Path Win32_PerfRawData_PerfProc_JobObject
  262. Wmic Path Win32_PerfRawData_PerfProc_JobObjectDetails
  263. Wmic Path Win32_PerfRawData_PerfProc_Process
  264. Wmic Path Win32_PerfRawData_PerfProc_ProcessAddressSpace_Costly
  265. Wmic Path Win32_PerfRawData_PerfProc_Thread
  266. Wmic Path Win32_PerfRawData_PerfProc_ThreadDetails_Costly
  267. Wmic Path Win32_PerfRawData_PSched_PSchedFlow
  268. Wmic Path Win32_PerfRawData_PSched_PSchedPipe
  269. Wmic Path Win32_PerfRawData_RemoteAccess_RASPort
  270. Wmic Path Win32_PerfRawData_RemoteAccess_RASTotal
  271. Wmic Path Win32_PerfRawData_RSVP_ACSRSVPInterfaces
  272. Wmic Path Win32_PerfRawData_RSVP_ACSRSVPService
  273. Wmic Path Win32_PerfRawData_SMTPSVC_SMTPServer
  274. Wmic Path Win32_PerfRawData_Spooler_PrintQueue
  275. Wmic Path Win32_PerfRawData_TapiSrv_Telephony
  276. Wmic Path Win32_PerfRawData_Tcpip_ICMP
  277. Wmic Path Win32_PerfRawData_Tcpip_IP
  278. Wmic Path Win32_PerfRawData_Tcpip_NBTConnection
  279. Wmic Path Win32_PerfRawData_Tcpip_NetworkInterface
  280. Wmic Path Win32_PerfRawData_Tcpip_TCP
  281. Wmic Path Win32_PerfRawData_Tcpip_UDP
  282. Wmic Path Win32_PerfRawData_TermService_TerminalServices
  283. Wmic Path Win32_PerfRawData_TermService_TerminalServicesSession
  284. Wmic Path Win32_PerfRawData_W3SVC_WebService
  285. Wmic Path Win32_PhysicalMedia
  286. Wmic Path Win32_PhysicalMemory
  287. Wmic Path Win32_PhysicalMemoryArray
  288. Wmic Path Win32_PhysicalMemoryLocation
  289. Wmic Path Win32_PingStatus
  290. Wmic Path Win32_PnPAllocatedResource
  291. Wmic Path Win32_PnPDevice
  292. Wmic Path Win32_PnPEntity
  293. Wmic Path Win32_PnPSignedDriver
  294. Wmic Path Win32_PnPSignedDriverCIMDataFile
  295. Wmic Path Win32_PointingDevice
  296. Wmic Path Win32_PortableBattery
  297. Wmic Path Win32_PortConnector
  298. Wmic Path Win32_PortResource
  299. Wmic Path Win32_POTSModem
  300. Wmic Path Win32_POTSModemToSerialPort
  301. Wmic Path Win32_PowerManagementEvent
  302. Wmic Path Win32_Printer
  303. Wmic Path Win32_PrinterConfiguration
  304. Wmic Path Win32_PrinterController
  305. Wmic Path Win32_PrinterDriver
  306. Wmic Path Win32_PrinterDriverDll
  307. Wmic Path Win32_PrinterSetting
  308. Wmic Path Win32_PrinterShare
  309. Wmic Path Win32_PrintJob
  310. Wmic Path Win32_PrivilegesStatus
  311. Wmic Path Win32_Process
  312. ::::::AttachDebugger Method of the Win32_Process Class
  313. ::::::Create Method of the Win32_Process Class
  314. ::::::GetOwner Method of the Win32_Process Class
  315. ::::::GetOwnerSid Method of the Win32_Process Class
  316. ::::::SetPriority Method of the Win32_Process Class
  317. ::::::Terminate Method of the Win32_Process Class
  318. Wmic Path Win32_Processor
  319. Wmic Path Win32_ProcessStartTrace
  320. Wmic Path Win32_ProcessStartup
  321. Wmic Path Win32_ProcessStopTrace
  322. Wmic Path Win32_ProcessTrace
  323. Wmic Path Win32_Product
  324. Wmic Path Win32_ProductCheck
  325. Wmic Path Win32_ProductResource
  326. Wmic Path Win32_ProductSoftwareFeatures
  327. Wmic Path Win32_ProgIDSpecification
  328. Wmic Path Win32_ProgramGroup
  329. Wmic Path Win32_ProgramGroupContents
  330. Wmic Path Win32_ProgramGroupOrItem
  331. Wmic Path Win32_Property
  332. Wmic Path Win32_ProtocolBinding
  333. Wmic Path Win32_Proxy
  334. Wmic Path Win32_PublishComponentAction
  335. Wmic Path Win32_QuickFixEngineering
  336. Wmic Path Win32_QuotaSetting
  337. Wmic Path Win32_Refrigeration
  338. Wmic Path Win32_Registry
  339. Wmic Path Win32_RegistryAction
  340. Wmic Path Win32_RemoveFileAction
  341. Wmic Path Win32_RemoveIniAction
  342. Wmic Path Win32_ReserveCost
  343. Wmic Path Win32_ScheduledJob
  344. Wmic Path Win32_SCSIController
  345. Wmic Path Win32_SCSIControllerDevice
  346. Wmic Path Win32_SecurityDescriptor
  347. Wmic Path Win32_SecurityDescriptorHelper
  348. Wmic Path Win32_SecuritySetting
  349. Wmic Path Win32_SecuritySettingAccess
  350. Wmic Path Win32_SecuritySettingAuditing
  351. Wmic Path Win32_SecuritySettingGroup
  352. Wmic Path Win32_SecuritySettingOfLogicalFile
  353. Wmic Path Win32_SecuritySettingOfLogicalShare
  354. Wmic Path Win32_SecuritySettingOfObject
  355. Wmic Path Win32_SecuritySettingOwner
  356. Wmic Path Win32_SelfRegModuleAction
  357. Wmic Path Win32_SerialPort
  358. Wmic Path Win32_SerialPortConfiguration
  359. Wmic Path Win32_SerialPortSetting
  360. Wmic Path Win32_ServerConnection
  361. Wmic Path Win32_ServerSession
  362. Wmic Path Win32_Service
  363. Wmic Path Win32_ServiceControl
  364. Wmic Path Win32_ServiceSpecification
  365. Wmic Path Win32_ServiceSpecificationService
  366. Wmic Path Win32_Session
  367. Wmic Path Win32_SessionConnection
  368. Wmic Path Win32_SessionProcess
  369. Wmic Path Win32_SettingCheck
  370. Wmic Path Win32_ShadowBy
  371. Wmic Path Win32_ShadowContext
  372. Wmic Path Win32_ShadowCopy
  373. Wmic Path Win32_ShadowDiffVolumeSupport
  374. Wmic Path Win32_ShadowFor
  375. Wmic Path Win32_ShadowOn
  376. Wmic Path Win32_ShadowProvider
  377. Wmic Path Win32_ShadowStorage
  378. Wmic Path Win32_ShadowVolumeSupport
  379. Wmic Path Win32_Share
  380. Wmic Path Win32_ShareToDirectory
  381. Wmic Path Win32_ShortcutAction
  382. Wmic Path Win32_ShortcutFile
  383. Wmic Path Win32_ShortcutSAP
  384. Wmic Path Win32_SID
  385. Wmic Path Win32_SIDandAttributes
  386. Wmic Path Win32_SMBIOSMemory
  387. Wmic Path Win32_SoftwareElement
  388. Wmic Path Win32_SoftwareElementAction
  389. Wmic Path Win32_SoftwareElementCheck
  390. Wmic Path Win32_SoftwareElementCondition
  391. Wmic Path Win32_SoftwareElementResource
  392. Wmic Path Win32_SoftwareFeature
  393. Wmic Path Win32_SoftwareFeatureAction
  394. Wmic Path Win32_SoftwareFeatureCheck
  395. Wmic Path Win32_SoftwareFeatureParent
  396. Wmic Path Win32_SoftwareFeatureSoftwareElements
  397. Wmic Path Win32_SoundDevice
  398. Wmic Path Win32_StartupCommand
  399. Wmic Path Win32_SubDirectory
  400. Wmic Path Win32_SystemAccount
  401. Wmic Path Win32_SystemBIOS
  402. Wmic Path Win32_SystemBootConfiguration
  403. Wmic Path Win32_SystemConfigurationChangeEvent
  404. Wmic Path Win32_SystemDesktop
  405. Wmic Path Win32_SystemDevices
  406. Wmic Path Win32_SystemDriver
  407. Wmic Path Win32_SystemDriverPnPEntity
  408. Wmic Path Win32_SystemEnclosure
  409. Wmic Path Win32_SystemLoadOrderGroups
  410. Wmic Path Win32_SystemLogicalMemoryConfiguration
  411. Wmic Path Win32_SystemMemoryResource
  412. Wmic Path Win32_SystemNetworkConnections
  413. Wmic Path Win32_SystemOperatingSystem
  414. Wmic Path Win32_SystemPartitions
  415. Wmic Path Win32_SystemProcesses
  416. Wmic Path Win32_SystemProgramGroups
  417. Wmic Path Win32_SystemResources
  418. Wmic Path Win32_SystemServices
  419. Wmic Path Win32_SystemSetting
  420. Wmic Path Win32_SystemSlot
  421. Wmic Path Win32_SystemSystemDriver
  422. Wmic Path Win32_SystemTimeZone
  423. Wmic Path Win32_SystemTrace
  424. Wmic Path Win32_SystemUsers
  425. Wmic Path Win32_TapeDrive
  426. Wmic Path Win32_TCPIPPrinterPort
  427. Wmic Path Win32_TemperatureProbe
  428. Wmic Path Win32_Thread
  429. Wmic Path Win32_ThreadStartTrace
  430. Wmic Path Win32_ThreadStopTrace
  431. Wmic Path Win32_ThreadTrace
  432. Wmic Path Win32_TimeZone
  433. Wmic Path Win32_TokenGroups
  434. Wmic Path Win32_TokenPrivileges
  435. Wmic Path Win32_Trustee
  436. Wmic Path Win32_TypeLibraryAction
  437. Wmic Path Win32_UninterruptiblePowerSupply
  438. Wmic Path Win32_USBController
  439. Wmic Path Win32_USBControllerDevice
  440. Wmic Path Win32_USBHub
  441. Wmic Path Win32_UserAccount
  442. Wmic Path Win32_UserDesktop
  443. Wmic Path Win32_UserInDomain
  444. Wmic Path Win32_UTCTime
  445. Wmic Path Win32_VideoConfiguration
  446. Wmic Path Win32_VideoController
  447. Wmic Path Win32_VideoSettings
  448. Wmic Path Win32_VoltageProbe
  449. Wmic Path Win32_Volume
  450. Wmic Path Win32_VolumeChangeEvent
  451. Wmic Path Win32_VolumeQuota
  452. Wmic Path Win32_VolumeQuotaSetting
  453. Wmic Path Win32_VolumeUserQuota
  454. Wmic Path Win32_WindowsProductActivation
  455. Wmic Path Win32_WMIElementSetting
  456. Wmic Path Win32_WMISetting  
  457. 手把手教你如何Get篩選類型
  458. 有了上面一些命令后,執行后窗口顯示的往往是亂七八糟大部分都是些不想要的信息,這時我們就要篩選出自己想要的內容了。
  459. —————————————————————————————————————————————
  460. 例子:
  461. 遍歷本地磁盤信息,篩選只顯示“文件系統”“驅動器類型”“盤符”其他亂七八糟的一概不顯示
  462. 步驟1: WMIC Path Win32_LogicalDisk>tmp.txt得到的一個亂七八糟的磁盤信息文本
  463. 步驟2: 打開tmp.txt會看到下面內容,因為篇幅不夠這里就只貼部分內容了
  464.            Description                DeviceID   FileSystem  FreeSpace     ........
  465.            3 1/2 英寸軟盤驅動器  A:                                                  ........
  466.            本地固定磁盤             C:            NTFS         1521709056 ........
  467.            本地固定磁盤             D:            NTFS         4812705792 ........
  468.            本地固定磁盤             E:            FAT32        2951413760 ........
  469.            CD-ROM 磁盤             F:                                                 ........
  470.            CD-ROM 磁盤             G:           CDFS          0               ........
  471. 步驟3:如上所示紅色部分就是分支節點名稱,這樣我們可以用Get去篩選了,開始輸入命令
  472.         WMIC Path Win32_LogicalDisk Get Description,DeviceID,FileSystem
  473. 好了屏幕顯示的內容是不是很整齊啊,如果想分行顯示可以在命令后面加/format:list
  474. 用for遍歷所有本地磁盤盤符到%Disk%變量例子
  475. --------------------------------------------------------------------------------
  476. @echo off
  477. for /f "skip=2 tokens=3* delims=," %%i in ('WMIC Path Win32_LogicalDisk Get Description^,DeviceID^,FileSystem /format:csv^|findstr /i /v "英寸 CD-ROM"') do call set Disk=%%Disk%% %%i
  478. set Disk=%Disk:~1%
  479. echo %Disk%
  480. pause
  481. 遍歷所有本地FAT32文件系統磁盤盤符到%FATDisk%變量例子
  482. --------------------------------------------------------------------------------
  483. @echo off
  484. for /f "skip=2 tokens=3* delims=," %%i in ('WMIC Path Win32_LogicalDisk Get Description^,DeviceID^,FileSystem /format:csv^|findstr /i /v "英寸 CD-ROM 移動 NTFS"') do call set FATDisk=%%FATDisk%% %%i
  485. set FATDisk=%FATDisk:~1%
  486. echo %FATDisk%
  487. pause
  488. 遍歷所有本地可移動磁盤盤符到%USBDisk%變量例子
  489. --------------------------------------------------------------------------------
  490. @echo off
  491. for /f "tokens=3* delims=," %%i in ('WMIC Path Win32_LogicalDisk Get DeviceID^,FileSystem^,Description /format:csv^|find /i "移動"') do call set USBDisk=%%USBDisk%% %%i
  492. echo %USBDisk:~1%
  493. pause
  494. 遍歷所有本地CD-ROM盤符到%CDROM%變量例子
  495. --------------------------------------------------------------------------------
  496. @echo off
  497. for /f "tokens=3* delims=," %%i in ('WMIC Path Win32_LogicalDisk Get DeviceID^,FileSystem^,Description /format:csv^|find /i "CD-ROM"') do call set CDROM=%%CDROM%% %%i
  498. echo %CDROM:~1%
  499. pause
  500. 遍歷非閑置(有光盤的)CD-ROM盤符到%CDROM%變量例子
  501. --------------------------------------------------------------------------------
  502. @echo off
  503. for /f "tokens=3* delims=," %%i in ('WMIC Path Win32_LogicalDisk Get DeviceID^,FileSystem^,Description /format:csv^|find /i "CD-ROM"^|find "CDFS"') do call set CDROM=%%CDROM%% %%i
  504. echo %CDROM:~1%
  505. pause
  506. 遍歷移動硬盤盤符到%RemovalDisk%變量例子(非U盤)
  507. --------------------------------------------------------------------------------
  508. @echo off
  509. for /f "tokens=3* delims=," %%i in ('WMIC Path Win32_LogicalDisk Get DeviceID^,VolumeDirty^,Description /format:csv^|find /i "TRUE"') do call set RemovalDisk=%%RemovalDisk%% %%i
  510. if not "%RemovalDisk%"==""  echo %RemovalDisk:~1%
  511. pause
  512. WMI命令行示例(某某同志看到下面示例比較眼熟別埋怨我^_^)
  513. BIOS  - 基本輸入/輸出服務 (BIOS) 管理
  514. ::查看bios版本型號
  515. wmic bios get Manufacturer,Name
  516. COMPUTERSYSTEM - 計算機系統管理
  517. ::查看系統啟動選項,boot的內容
  518. wmic COMPUTERSYSTEM get SystemStartupOptions
  519. ::查看工作組/域
  520. wmic computersystem get domain
  521. ::更改計算機名abc為123
  522. wmic computersystem where "name='abc'" call rename 123
  523. ::更改工作組google為MyGroup
  524. wmic computersystem where "name='google'" call joindomainorworkgroup "","","MyGroup",1
  525. CPU - CPU 管理
  526. ::查看cpu型號
  527. wmic cpu get name
  528. DATAFILE - DataFile 管理
  529. ::查找e盤下test目錄(不包括子目錄)下的cc.cmd文件
  530. wmic datafile where "drive='e:' and path='\\test\\' and FileName='cc' and Extension='cmd'" list
  531. ::查找e盤下所有目錄和子目錄下的cc.cmd文件,且文件大小大於1K
  532. wmic datafile where "drive='e:' and FileName='cc' and Extension='cmd' and FileSize>'1000'" list
  533. ::刪除e盤下文件大小大於10M的.cmd文件
  534. wmic datafile where "drive='e:' and Extension='cmd' and FileSize>'10000000'" call delete
  535. ::刪除e盤下test目錄(不包括子目錄)下的非.cmd文件
  536. wmic datafile where "drive='e:' and Extension<>'cmd' and path='test'" call delete
  537. ::復制e盤下test目錄(不包括子目錄)下的cc.cmd文件到e:\,並改名為aa.bat
  538. wmic datafile where "drive='e:' and path='\\test\\' and FileName='cc' and Extension='cmd'" call copy "e:\aa.bat"
  539. ::改名c:\hello.txt為c:\test.txt
  540. wmic datafile "c:\\hello.txt" call rename c:\test.txt
  541. ::查找h盤下目錄含有test,文件名含有perl,后綴為txt的文件
  542. wmic datafile where "drive='h:' and extension='txt' and path like '%\\test\\%' and filename like '%perl%'" get name
  543. DESKTOPMONITOR - 監視器管理
  544. ::獲取屏幕分辨率
  545. wmic DESKTOPMONITOR where Status='ok' get ScreenHeight,ScreenWidth
  546. DISKDRIVE  - 物理磁盤驅動器管理
  547. ::獲取物理磁盤型號大小等
  548. wmic DISKDRIVE get Caption,size,InterfaceType
  549. ENVIRONMENT  - 系統環境設置管理
  550. ::獲取temp環境變量
  551. wmic ENVIRONMENT where "name='temp'" get UserName,VariableValue
  552. ::更改path環境變量值,新增e:\tools
  553. wmic ENVIRONMENT where "name='path' and username='<system>'" set VariableValue="%path%;e:\tools"
  554. ::新增系統環境變量home,值為%HOMEDRIVE%%HOMEPATH%
  555. wmic ENVIRONMENT create name="home",username="<system>",VariableValue="%HOMEDRIVE%%HOMEPATH%"
  556. ::刪除home環境變量
  557. wmic ENVIRONMENT where "name='home'" delete
  558. FSDIR  - 文件目錄系統項目管理
  559. ::查找e盤下名為test的目錄
  560. wmic FSDIR where "drive='e:' and filename='test'" list
  561. ::刪除e:\test目錄下除過目錄abc的所有目錄
  562. wmic FSDIR where "drive='e:' and path='\\test\\' and filename<>'abc'" call delete
  563. ::刪除c:\good文件夾
  564. wmic fsdir "c:\\good" call delete
  565. ::重命名c:\good文件夾為abb
  566. wmic fsdir "c:\\good" rename "c:\abb"
  567. LOGICALDISK  - 本地儲存設備管理
  568. ::獲取硬盤系統格式、總大小、可用空間等
  569. wmic LOGICALDISK get name,Description,filesystem,size,freespace
  570. NIC - 網絡界面控制器 (NIC) 管理
  571. OS  - 已安裝的操作系統管理
  572. ::設置系統時間
  573. wmic os where(primary=1) call setdatetime 20070731144642.555555+480
  574. PAGEFILESET  - 頁面文件設置管理
  575. ::更改當前頁面文件初始大小和最大值
  576. wmic PAGEFILESET set InitialSize="512",MaximumSize="512"
  577. ::頁面文件設置到d:\下,執行下面兩條命令
  578. wmic pagefileset create name='d:\pagefile.sys',initialsize=512,maximumsize=1024
  579. wmic pagefileset where"name='c:\\pagefile.sys'" delete
  580. PROCESS - 進程管理
  581. ::列出進程的核心信息,類似任務管理器
  582. wmic process list brief
  583. ::結束svchost.exe進程,路徑為非C:\WINDOWS\system32\svchost.exe的
  584. wmic process where "name='svchost.exe' and ExecutablePath<>'C:\\WINDOWS\\system32\\svchost.exe'" call Terminate
  585. ::新建notepad進程
  586. wmic process call create notepad
  587. PRODUCT - 安裝包任務管理
  588. ::安裝包在C:\WINDOWS\Installer目錄下
  589. ::卸載.msi安裝包
  590. wmic PRODUCT where "name='Microsoft .NET Framework 1.1' and Version='1.1.4322'" call Uninstall
  591. ::修復.msi安裝包
  592. wmic PRODUCT where "name='Microsoft .NET Framework 1.1' and Version='1.1.4322'" call Reinstall
  593. SERVICE - 服務程序管理
  594. ::運行spooler服務
  595. wmic SERVICE where name="Spooler" call startservice
  596. ::停止spooler服務
  597. wmic SERVICE where name="Spooler" call stopservice
  598. ::暫停spooler服務
  599. wmic SERVICE where name="Spooler" call PauseService
  600. ::更改spooler服務啟動類型[auto|Disabled|Manual] 釋[自動|禁用|手動]
  601. wmic SERVICE where name="Spooler" set StartMode="auto"
  602. ::刪除服務
  603. wmic SERVICE where name="test123" call delete
  604. SHARE - 共享資源管理
  605. ::刪除共享
  606. wmic SHARE where name="e$" call delete
  607. ::添加共享
  608. WMIC SHARE CALL Create "","test","3","TestShareName","","c:\test",0
  609. SOUNDDEV - 聲音設備管理
  610. wmic SOUNDDEV list
  611. STARTUP - 用戶登錄到計算機系統時自動運行命令的管理
  612. ::查看msconfig中的啟動選項
  613. wmic STARTUP list
  614. SYSDRIVER  - 基本服務的系統驅動程序管理
  615. wmic SYSDRIVER list
  616. USERACCOUNT  - 用戶帳戶管理
  617. ::更改用戶administrator全名為admin
  618. wmic USERACCOUNT where name="Administrator" set FullName="admin"
  619. ::更改用戶名admin為admin00
  620. wmic useraccount where "name='admin" call Rename admin00
  621. Datafile 別名
  622. wmic datafile "c:\\hello.txt" call rename c:\ppp.txt
  623. wmic datafile Where "drive='d:' and extension='txt' and path='\\'" get name
  624. WMIC FSDIR別名
  625. wmic fsdir where(name='c:\\good') delete
  626. wmic fsdir where(name='c:\\good') call delete
  627. 刪除c:\good文件夾
  628. wmic fsdir where(name='c:\\good') rename "c:\abb"
  629. 重命名c:\good文件夾為abb
  630. 復制文件夾
  631. wmic fsdir where(name='d:\\test') call copy "c:\ppcd"
  632. 復制D盤下TEST文件夾的所有文件到C盤下的PPCD,如果PPCD存在直接復制過去,如果不存在他會自動創建並將文件復制過去
  633. wmic fsdir where(name='d:\\test') call Compress
  634. 壓縮指定文件夾,以便節省磁盤空間
  635. wmic fsdir where(name='d:\\test') call unCompress
  636. 解除壓縮文件夾
  637. Job 別名
  638. wmic job call create "sol.exe",0,0,1,0,********154600.000000+480
  639. 這個命令和AT命令是一模一樣啊,AT添加的計划任務他可以看到,他添加的同樣AT命令也是可以看到
  640. wmic job call create "sol.exe",0,0,true,false,********154800.000000+480
  641. wmic job call create "sol.exe",0,0,1,0,********154600.000000+480
  642. 這兩句是相同的,TRUE可以用1表示,同樣的FALSE可以用0值表示,時間前為何用八個星號,這是WMIC的特性,他顯示時間的方式是YYYYMMDDHHMMSS.MMMMMM+時區 ,可是,我們並不需要指定年份和月份還有天,所以用*星號來替代
  643. Os 別名
  644. wmic os Where (primary='1') call win32shutdown *
  645. 這個*參數可以有如下值:
  646. Const LOGOFF=0
  647. Const SHUTDOWN=1
  648. Const REBOOT=2
  649. Const FORCE=4
  650. Const POWEROFF=8
  651. 這些參數可以進行任意組合,例如:
  652. 強制注銷:4 (0+4)的組合
  653. 強制關機:5 (1+4)的組合
  654. 強制重啟:6 (2+4)的組合
  655. 強制關閉電源:12 (8+4)的組合
  656. WMIC設置系統時間
  657. 要求需要有管理員權限
  658. wmic os where(primary=1) call setdatetime 20070731144642.555555+480
  659. Process 別名
  660. wmic process call create sol.exe
  661. wmic process 3848 call terminate
  662. 可以看出PROCESS別名是以HANDLE屬性為默認屬性進行操作的
  663. wmic process 2556 call setpriority 64
  664. wmic process Where "processid='%pid%'" call Terminate
  665. wmic process Where "name='%imagename%'" call Terminate
  666. wmic path Win32_Process.name="%imagename%" call Terminate
  667. wmic path Win32_Process.processid="%pid%" call Terminate
  668. wmic process Where name='sol.exe' delete
  669. Nicconfig 別名
  670. wmic nicconfig where(index='8') call enablestatic "192.168.1.81","255.255.255.0"   
  671. 設置IP地址和子網掩碼
  672. wmic nicconfig where(index='8') call setgateways "192.168.0.1",1          
  673. 設置網關和躍點數
  674. wmic nicconfig where(index='8') call setdnsdomain ("192.168.0.1","192.168.0.11")  
  675. 設置DNS服務器地址,設置完畢后不會馬上生效,必需要設置主次才可以生效
  676. wmic nicconfig where(index='8') call SetDNSServerSearchOrder ("192.168.0.1","192.168.0.11") 
  677. 設置DNS服務器地址的主次順序,192.168.0.1在前表示為首選DNS地址,在后為備用DNS地址
  678. wmic path Win32_NetworkAdapterConfiguration.index=8 call enabledhcp
  679. WMIC默認的NICCONFIG別名是不提供enabledhcp這個方法的,所以我們只能調用他的WMI函數來設置動態分配IP地址的設置
  680. wmic nicconfig where(index='8') get /value ###INDEX值為你當前網卡的索引值,每台機器都不一樣
  681. WMIC對注冊表的操作
  682. wmic /namespace:\\root\default path stdregprov call getstringvalue ^&H80000002,"SOFTWARE\libowen","hello"
  683. wmic /namespace:\\root\default path stdregprov call createkey ^&h80000001,"libowen\good"
  684. 建立libowen\good 這個鍵值
  685. wmic /namespace:\\root\default path stdregprov call deletekey ^&h80000001,"libowen\sdd"  
  686. 刪除鍵值SDD,注意此鍵值必須是最底層
  687. wmic /namespace:\\root\default path stdregprov call EnumKey ^&h80000001,"Keyboard Layout"
  688. 枚舉Keyboard Layout下的所有子鍵值
  689. wmic /namespace:\\root\default path stdregprov call Enumvalues ^&h80000001,"Keyboard Layout\preload"
  690. 枚舉Keyboard Layout\preload這個鍵值下的所有數值及其數值所對應的類型
  691. wmic /namespace:\\root\default path stdregprov call SetStringValue ^&h80000001,"libowen\test","hello world!","test"
  692. 建立一個名為test的string的數值,值為hello world!
  693. wmic /namespace:\\root\default path stdregprov call SetStringValue ^&h80000001,"libowen\test","test","aabb"
  694. 修改aabb的數值為test
  695. Pagefileset 別名
  696. wmic pagefileset get /value
  697. 用來察看本地計算機虛擬內存情況,初始大小,最大值,保存位置等
  698. 下面我們可以改變虛擬內存文件(也就是我們常說的頁面文件) 所在位置以及初始大小和最大值
  699. wmic pagefileset set initialsize=512,maximumsize=1024
  700. 這個只是改變初始大小和最大值,SET不能修改頁面文件所存放的位置,也就是說默認頁面文件在C盤這時不能把他的位置修改到D盤,如果要修改到D盤我們可以這樣來做
  701. wmic pagefileset create name='d:\pagefile.sys',initialsize=512,maximumsize=1024
  702. 然后刪除以前的就可以了,請看
  703. wmic pagefileset where "name='c:\\pagefile.sys'"  delete
  704. 這樣就實現了把頁面文件轉移到D盤的效果
  705. WMIC設置代理服務器
  706. wmic path win32_proxy get /value
  707. wmic path win32_proxy Where ServerName='ql-libowen.ql-art.com' call setproxysetting "8080","192.168.1.59"
  708. wmic path win32_proxy.servername="ql-libowen.ql-art.com" call setproxysetting "",""
  709. WMIC 設置共享
  710. 輸入參數是 OBJECT 類型
  711. 原因:對於 OBJECT 類型的輸入參數,還沒有實現全面支持。默認值(空字符串:"")是目前支持的唯一值。
  712. 解決方案:使用下面的命令為三個用戶設置 c:\test 目錄的共享:
  713. WMIC SHARE CALL Create "","test","3","TestShareName","","c:\test",0
  714. 建立共享文件夾
  715. WMIC SHARE where(path='c:\\test') call delete
  716. WMIC對於共享文件夾操作
  717. WMIC SHARE where(path='c:\\test') delete
  718. Computersystem 別名
  719. wmic computersystem Where "name='原計算機名稱'" call rename "要修改的計算機名"
  720. 主要功能:修改計算機名稱
  721. wmic computersystem Where "name='計算機名稱'" call joindomainorworkgroup "","","MyGroup"
  722. 主要功能:更改現有工作組為指定的工作組
  723. wmic computersystem Where "name='計算機名稱' call UnjoinDomainOrWorkgroup
  724. 主要功能:退出所在域
  725. wmic computersystem Where "name='計算機名稱'" call joindomainorworkgroup "",1,"域名稱","域管理員密碼","域管理員用戶名"
  726. Useraccount 別名
  727. wmic useraccount where(LocalAccount='1' and name='good') set disabled=true
  728. wmic useraccount where(LocalAccount='1' and name='good') set fullname="hello world!"
  729. wmic useraccount where(localaccount=true and name='good') set passwordchangeable=true
  730. wmic useraccount Where "domain='ql-libowen' and name='libowen'" set PasswordExpires=false
復制代碼
原文地址:http://www.cn-dos.net/forum/viewthread.php?tid=35681
 
 

 

 
 
 
 

WMIC從命令行對Windows的全面管理

  1. 從Windows 2000開始,WMI(Windows 管理規范)就是Windows系統管理的重要組成部分。WMIC是Windows Management Instrumentation Command-line的簡稱,在WMIC出現之前,要從命令行訪問WMI數據庫或WMI名稱空間不是一件容易的事情。現在,WMIC利用WMI強大的功能把系統管理擴展到了命令行。
  2.   一、什么是WMIC?
  3.   WMIC擴展WMI,提供了從命令行接口和批命令腳本執行系統管理的支持。在WMIC出現之前,如果要管理WMI系統,必須使用一些專門的WMI應用,例如SMS,或者使用WMI的腳本編程API,或者使用象CIM Studio之類的工具。如果不熟悉C++之類的編成語言或VBScript之類的腳本語言,或者不掌握WMI名稱空間的基本知識,要用WMI管理系統是很困難的。WMIC改變了這種情況,為WMI名稱空間提供了一個強大的、友好的命令行接口。
  4.   WMIC比WMI簡單、直觀得多,這主要是由於使用了別名(Alias)。別名機制獲取用戶在命令行上輸入的一些簡單命令,按照預定義的方式操作WMI名稱空間,例如根據一個簡單的WMIC別名Get命令構造出一個復雜的WMI查詢語言(WQL)命令。從這個意義上看,別名是用戶和名稱空間之間一個簡化操作的中間層。例如,如果在WMIC命令行上執行下面這個簡單的WMIC命令,就可以獲得用戶帳戶的基本信息:
  5. useraccount list brief
  6.   在上面的命令中,Useraccount別名執行了一個Win32_Useraccount類的WQL查詢,以文本的形式顯示出從該類提取的信息。另外,WMIC還以文本的形式顯示出Win32_Useraccount類的屬性。除了文本形式的輸出之外,WMIC還能夠以其他形式返回命令執行結果,例如XML、HTML或者CSV(逗號分隔的文本文件)。
  7. WMIC以WMI模式中類的實例的形式保存別名。默認的別名類——MSFT_CliAlias,以及其他支持WMIC的類保存在模式的默認名稱空間,或者說root\cli角色。角色可以簡單地看成專門用來支持WMIC的另一個WMI名稱空間。默認角色root\cli連接到root\cimv2名稱空間,操作root\cimv2之內的類。雖然使用WMIC時一般不需要用到CIM Studio,但CIM Studio可以用來方便地查看root\cli名稱空間。
  8.   你可以向root\cli名稱空間和其他名稱空間加入新的別名,還可以用Class和Path命令直接訪問WMI名稱空間,本文后面將詳細說明Class和Path命令。
  9.   二、運行WMIC
  10.   執行“wmic”命令啟動WMIC命令行環境。這個命令可以在XP或.NET Server的標准命令行解釋器(cmd.exe)、Telnet會話或“運行”對話框中執行。這些啟動方法可以在本地使用,也可以通過.NET Server終端服務會話使用。
  11.   第一次執行WMIC命令時,Windows首先要安裝WMIC,然后顯示出WMIC的命令行提示符。在WMIC命令行提示符上,命令以交互的方式執行。例如,執行下面的命令將關閉正在運行的Outlook:
  12. process where name='outlook.exe'  call terminate
  13.   命令運行結束后,WMIC命令行提示符重新出現。每個命令必須在一行之內輸入,中間不能插入換行符。
  14.   WMIC也可以按照非交互的模式運行。如果要執行某個單步的任務,或者運行批命令中的一系列WMIC命令,非交互模式就很有用。要使用非交互模式,只要在同一個命令行上啟動WMIC並輸入要執行的命令就可以了。例如,執行cmd.exe打開一個命令行窗口,然后執行下面的命令,就可以輸出連接到MACHINE1的打印機清單:
  15. wmic /node:MACHINE1 printer list status
  16.   在這個例子中,第一個操作是啟動WMIC,然后是根據/node參數建立一個到MACHINE1的遠程連接,最后執行一個WMIC命令顯示出打印機狀態信息。命令運行結束后,返回到Windows命令行提示符狀態。
  17.   安裝了WMIC的機器可以連接到任何一台安裝了WMI的機器,被連接的機器不需要安裝WMIC。例如,從一台運行Win XP Pro的機器啟動WMIC,可以連接和管理所有運行着XP、Win2K、Windows NT 4.0、Windows Me和Windows 9x的機器。
  18.   三、WMIC命令行構成
  19.   WMIC提供了大量的全局開關、別名、動詞、命令和豐富的命令行幫助增強用戶接口。全局開關是適用於整個WMIC會話的配置選項。例如,/trace:on開關啟用錯誤跟蹤機制,如果這個開關處於打開狀態,WMIC返回每一個命令的錯誤信息。利用/note開關可以訪問遠程機器,/interactive:on開關要求WMIC在執行刪除操作之前提示確認,其他的全局開關還包括/role、/user、/implevel以及/namespace。
  20.   如前所述,別名是用戶和WMI名稱空間一個簡化語法的中間層。當你指定一個別名時,動詞(Verb)表示要執行的動作。例如,前面例子中的List和Call就是兩個動詞的例子。表一描述了其他一些WMIC動詞,並為每一個動詞給出了例子。
  21. 表一:WMIC動詞  
  22. 動詞  例子  說明  
  23. Assoc  group where name= 'administrators' assoc  顯示出Administrators組與系統的所有關聯,包括Administrators組成員等。又如,os assoc顯示出有關操作系統的信息和已經安裝的補丁。  
  24. Create  environment create name="progloc", username="work01\User1",variablevalue= "%programfiles%\prog01"  創建一個名字為Progloc的變量,把它的值設置為Program Files文件夾的一個子文件夾,把這個變量加入到Work01工作組計算機User1帳戶。  
  25. Delete  environment where(name= "progloc") delete  刪除Progloc環境變量。測試WMIC命令時,為了防止意外地刪除,可以使用/interactive:on全局開關,這時刪除之前會要求確認。  
  26. Get  partition get bootpartition, description, deviceid, bootable  返回分區是否可啟動、描述信息和設備ID屬性等信息。  
  27. Set  path WIN32_USERACCOUNT where(name="user01") set disabled="true"  在成員服務器或工作站上禁用User01用戶帳戶。  
  28.   命令用來控制對WMIC和WMI名稱空間的訪問。注意表一的最后一個例子,這個例子用的是Path和Win32_USERACCOUNT類,而不是Useraccount別名。Path是一個直接訪問WMI名稱空間中實例的命令,不必再通過別名訪問。如果待執行的系統管理任務沒有現成的別名可用,Path命令特別有用。雖然你可以用新的別名和角色擴展WMIC,但如果你對WMI名稱空間比較熟悉,使用Path命令也很方便。
  29.  
  30. 除了Path命令之外,WMIC還支持Class、Context、Quit和Exit命令。Class命令用來直接訪問WMI模式內的類或創建現有類的實例。Class命令和Path命令的不同之處在於,Path命令的作用對象是實例以及它的屬性(例如,提取管理用的信息),而Class命令的作用對象是類的定義。例如,如果要提取出WIN32_SOFTWAREELEMENT類的所有屬性,可以執行如下命令:
  31. class WIN32_SOFTWAREELEMENT get
  32.   這個命令的輸出是HTML格式,稍后我們將了解如何用/output全局開關把輸出重定向到可用瀏覽器打開的HTML文件。Class命令加上Assoc動詞能夠顯示出類的名稱空間路徑以及其他與該類關聯的類。利用Class命令可以刪除類、創建類的實例,但不能創建類。
  33.   Context命令顯示出全局開關的當前設置。Quit和Exit命令用來退出WMIC命令提示符環境,返回以前的Shell環境(例如Telnet環境,或XP的命令行提示符環境)。
  34.   命令行幫助是熟悉WMIC的有效途徑。表二是在WMIC提示符下查找信息的常用命令:
  35. 四、實踐應用
  36.   以上我們了解了WMIC命令行環境的基礎知識,下面來看看如何用批命令運行WMIC,以及把輸出結果定向到控制台或HTML、XML文件。從批命令文件運行WMIC的好處在於不需要重復輸入一系列復雜的命令,例如,下面是一個批命令文件的內容,它的作用是顯示出MACHINE1和MACHINE2這兩台機器的CPU信息,輸出結果顯示在控制台上。/format開關是面向動詞的開關,而不是全局開關,它只用於Get和List動詞。
  37. wmic /node:MACHINE1, MACHINE4 cpu get name, caption,
  38.      maxclockspeed, systemname /format:textvaluelist.xsl
  39.   WMIC批命令可以使用變量。也就是說,對於上面的批命令,服務器的名字不僅可以直接指定,而且還可以通過%1、%2的形式指定,下面就是一個例子。把下面的代碼放入一個批命令文件,然后在執行批命令文件時加上一到二個機器的名字即可;另外,也可以創建一個獨立的文本文件,然后在文本文件中放入機器名字的清單,清單可以是CSV格式,或用換行符分隔的格式。如果使用獨立的文本文件提供機器名字,只需在/node全局開關后面加上以@符號為前綴的文本文件名字,@符號告訴/node開關后面的參數是一個文件名字而不是機器名字。
  40. @echo off
  41. if "%1"=="" goto msg
  42. if "%2"=="" goto single
  43. wmic /node:%1, %2 cpu get name, caption, maxclockspeed, systemname
  44.      /format:textvaluelist.xsl
  45. goto end
  46. :single
  47. wmic /node:%1 cpu get name, caption, maxclockspeed,  
  48.      systemname /format:textvaluelist.xsl
  49. goto end
  50. :msg
  51. echo 必須指定至少一台計算機的名字。
  52. :end
  53.  如前所述,WMIC命令的輸出結果不僅可以發送到控制台,還可以發送到XML或HTML、MOF(Managed Object Format)格式的文件。在安裝了WMI的計算機上,MOF是WMI數據庫中類和類實例的原始保存形式。下面的例子顯示了如何把MACHINE4處理器信息的查詢結果輸出到HTML文件,/output全局開關要求WMIC把輸出發送到file1.htm,/format開關要求WMIC把原始的XML輸出轉換成HTML格式。用來轉換格式的XSL樣式文件既可以是自定義的,也可以是任何安裝了WMIC的機器上\%systemroot%\system32\wbem文件夾下面的任意XSL文件。例如,利用csv.xsl樣式文件可以把輸出結果轉換成CSV格式,利用htable.xsl樣式可以構造出一個包含結果數據的表格。
  54. wmic /node:MACHINE4 /output:e:\file1.htm cpu get description,
  55.      maxclockspeed, extclock, manufacturer,  revision /format:hform.xsl
  56.   前面已經提到,Class命令加上Get動詞的默認輸出是HTML格式。因此,如果要把這類命令的輸出結果保存到HTML文件,只需指定/output開關,不必加上/format開關。/record和/append全局開關也能夠從WMIC命令行截取信息,請利用WMIC的命令行幫助功能了解有關這些開關的更多信息。
  57.   如果要以XML格式輸出,用/translate開關和Basicxml關鍵詞把大於符號“>”和小於符號“<”轉換成XML中有意義的字符。下面是輸出XML的一個例子,輸出的XML數據可導入到數據庫或其他能夠理解XML標記的系統。下面代碼的輸出中包含了WMIC命令、命令行請求參數、目標節點、全局開關以及命令執行結果。
  58. wmic cpu get maxclockspeed /translate:basicxml /format:rawxml.xsl
  59.   總之,WMIC是XP和.NET Server中命令行管理功能的一次重要改進,對於從命令行訪問和管理WMI名稱空間提供了強健的支持。雖然掌握和熟悉WMIC命令行環境需要一段時間,但只要你熟悉了它,一個系統管理的全新境界將展現在你的面前。
復制代碼
原文地址:http://www.cn-dos.net/forum/viewthread.php?tid=22790

 

 

 

獲取磁盤資料:
wmic DISKDRIVE get deviceid,Caption,size,InterfaceType
獲取分區資料:
wmic LOGICALDISK get name,Description,filesystem,size,freespace
獲取CPU資料:
wmic cpu get name,addresswidth,processorid
獲取主板資料:
wmic BaseBoard get Manufacturer,Product,Version,SerialNumber
獲取內存數:
wmic memlogical get totalphysicalmemory
獲得品牌機的序列號:
wmic csproduct get IdentifyingNumber
獲取聲卡資料:
wmic SOUNDDEV get ProductName
獲取屏幕分辨率
wmic DESKTOPMONITOR where Status='ok' get ScreenHeight,ScreenWidth


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM