WMIC开发技术资料全收藏

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值