找回密码
 加入
搜索
查看: 4756|回复: 8

autoit调用WMI(下)

  [复制链接]
发表于 2008-5-3 14:19:54 | 显示全部楼层 |阅读模式
<table border="0" style="table-layout: fixed"><tbody><tr><td><div class="cnt"><p><strong>八、WMI的应用</strong></p><p>这一节将主要分类举出WMI应用的例子,不过暂时不会涉及WMI事件。</p><p>No.1.计算机硬件</p><blockquote dir="ltr" style="margin-right: 0px"><p>1.查看可用的物理内存</p><p>你可以使用<a href="http://msdn2.microsoft.com/en-us/library/aa394239.aspx"><strong>Win32_OperatingSystem</strong></a>类和<strong>FreePhysicalMemory</strong>属性.</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><br /><span class="re0">$colSettings</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_OperatingSystem&quot;</span><span class="br0">)</span><br /><br /><span class="kw1">For</span> <span class="re0">$objOperatingSystem</span> <span class="kw1">in</span> <span class="re0">$colSettings</span> <br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;可用物理内存: &quot;</span> &amp; _<br /><span class="re0">$objOperatingSystem</span>.<span class="me1">FreePhysicalMemory</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>2.判断计算机是否有DVD驱动器</p><p style="margin-right: 0px" dir="ltr">使用<a href="http://msdn2.microsoft.com/en-us/library/aa394081.aspx"><strong>Win32_CDROMDrive</strong></a>类下的<strong>Name</strong>或者<strong>DeviceID</strong>属性<strong>。</strong></p><blockquote dir="ltr" style="margin-right: 0px"><p style="margin-right: 0px" dir="ltr"><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><br /><span class="re0">$colItems</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_CDROMDrive&quot;</span><span class="br0">)</span><br /><br /><span class="kw1">For</span> <span class="re0">$objItem</span> <span class="kw1">in</span> <span class="re0">$colItems</span> <br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Device ID: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">DeviceID</span> &amp;<span class="re0">@CRLF</span> _<br />&amp; <span class="st0">&quot;Description: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Description</span> &amp;<span class="re0">@CRLF</span> _<br />&amp; <span class="st0">&quot;Name: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Name</span> &amp;<span class="re0">@CRLF</span> &amp;<span class="re0">@CRLF</span><span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>3.检查系统信息处理器数目</p><p>使用<a href="http://msdn2.microsoft.com/en-us/library/aa394102.aspx"><strong>Win32_ComputerSystem</strong></a>类下的<strong>NumberOfProcessors</strong>属性.</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colSettings</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_ComputerSystem&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objComputer</span> <span class="kw1">in</span> <span class="re0">$colSettings</span> <br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;System Name: &quot;</span> &amp; <span class="re0">$objComputer</span>.<span class="me1">Name</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Number of Processors: &quot;</span> &amp; _<br /><span class="re0">$objComputer</span>.<span class="me1">NumberOfProcessors</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>4.检查PCMCIA接口数量</p><p style="margin-right: 0px" dir="ltr">使用<a href="http://msdn2.microsoft.com/en-us/library/aa394251.aspx"><strong>Win32_PCMCIAController</strong></a>类下的<strong> Count</strong> 属性</p><blockquote dir="ltr" style="margin-right: 0px"><p style="margin-right: 0px" dir="ltr"><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&#92;&#92;&quot;</span> &amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colItems</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span><span class="br0">(</span><span class="st0">&quot;Select * from Win32_PCMCIAController&quot;</span><span class="br0">)</span><br /><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Number of PCMCIA slots: &quot;</span> _<br />&amp; <span class="re0">$colItems</span>.<span class="me1">Count</span><span class="br0">)</span></p></blockquote><p>5.列出没有工作的硬件</p><p>你可以使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394353.aspx"><strong>Win32_PnPEntity</strong></a> 类, 然后通过使用<a href="http://msdn2.microsoft.com/en-us/library/aa392902.aspx">WQL</a> 查询 <strong>WHERE ConfigManagerErrorCode &lt;&gt; 0</strong> 来判断</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&#92;&#92;&quot;</span> &amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colItems</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_PnPEntity &quot;</span> _<br />&amp; <span class="st0">&quot;WHERE ConfigManagerErrorCode &lt;&gt; 0&quot;</span><span class="br0">)</span><br /><br /><span class="kw1">For</span> <span class="re0">$objItem</span> <span class="kw1">in</span> <span class="re0">$colItems</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Class GUID: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">ClassGuid</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Description: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Description</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Device ID: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">DeviceID</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Manufacturer: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Manufacturer</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Name: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Name</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;PNP Device ID: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">PNPDeviceID</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Service: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Service</span> &amp; <span class="re0">@CRLF</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>6.列出所有鼠标的信息</p><p>使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394356.aspx"><strong>Win32_PointingDevice</strong></a> 类,这样会列出所有指针设备,而不仅仅是鼠标</p><blockquote dir="ltr" style="margin-right: 0px"><p>.<span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span> _<br /><span class="st0">&quot;winmgmts:&#92;&#92;&quot;</span> &amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colItems</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span><span class="br0">(</span> _<br /><span class="st0">&quot;Select * from Win32_PointingDevice&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objItem</span> <span class="kw1">in</span> <span class="re0">$colItems</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Description: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Description</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Device ID: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">DeviceID</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Device Interface: &quot;</span> _<br />&amp; <span class="re0">$objItem</span>.<span class="me1">DeviceInterface</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Double Speed Threshold: &quot;</span> _<br />&amp; <span class="re0">$objItem</span>.<span class="me1">DoubleSpeedThreshold</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Handedness: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Handedness</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Hardware Type: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">HardwareType</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;INF File Name: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">InfFileName</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;INF Section: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">InfSection</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Manufacturer: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Manufacturer</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Name: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Name</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Number Of Buttons: &quot;</span> _<br />&amp; <span class="re0">$objItem</span>.<span class="me1">NumberOfButtons</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;PNP Device ID: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">PNPDeviceID</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Pointing Type: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">PointingType</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Quad Speed Threshold: &quot;</span> _<br />&amp; <span class="re0">$objItem</span>.<span class="me1">QuadSpeedThreshold</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Resolution: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Resolution</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Sample Rate: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">SampleRate</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Synch: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Synch</span> &amp; <span class="re0">@CRLF</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>7.判断计算机是台式机还是笔记本</p><p>使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394474.aspx"><strong>Win32_SystemEnclosure</strong></a> 类下的 <strong>ChassisType</strong> 属性</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colChassis</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_SystemEnclosure&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objChassis</span> <span class="kw1">in</span> <span class="re0">$colChassis</span><br /><span class="kw1">For</span> <span class="re0">$objItem</span> <span class="kw1">in</span> <span class="re0">$objChassis</span>.<span class="me1">ChassisTypes</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Chassis Type: &quot;</span> &amp; <span class="re0">$objItem</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span><br /><span class="kw1">Next</span></p></blockquote><p>8.检查USB接口里插入的是什么设备</p><p>使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394506.aspx"><strong>Win32_USBHub</strong></a> 类并检查 <strong>Description</strong> 属性</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&#92;&#92;&quot;</span> &amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colItems</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span><span class="br0">(</span> _<br /><span class="st0">&quot;Select * from Win32_USBHub&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objItem</span> <span class="kw1">in</span> <span class="re0">$colItems</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Device ID: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">DeviceID</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;PNP Device ID: &quot;</span> _<br />&amp; <span class="re0">$objItem</span>.<span class="me1">PNPDeviceID</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Description: &quot;</span> _<br />&amp; <span class="re0">$objItem</span>.<span class="me1">Description</span> &amp; <span class="re0">@CRLF</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>9.检查系统有多少Tape设备</p><p>使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394491.aspx"><strong>Win32_TapeDrive</strong></a> 类然后使用 <a href="http://msdn2.microsoft.com/en-us/library/aa393763.aspx"><strong>Count</strong></a> 途径</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colItems</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span><span class="br0">(</span> _<br /><span class="st0">&quot;Select * from Win32_TapeDrive&quot;</span><span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Number of tape drives: &quot;</span> _<br />&amp; <span class="re0">$colItems</span>.<span class="me1">Count</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span></p></blockquote></blockquote><p dir="ltr">No.2.计算机软件</p><blockquote dir="ltr" style="margin-right: 0px"><p dir="ltr">1.卸载软件</p><p dir="ltr">如果软件是使用Microsoft Windows Installer (MSI) 安装的话,使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394378.aspx"><strong>Win32_Product</strong></a> 类和 <a href="http://msdn2.microsoft.com/en-us/library/aa393941.aspx"><strong>Uninstall</strong></a> 途径</p><blockquote dir="ltr" style="margin-right: 0px"><p dir="ltr"><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colSoftware</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_Product &quot;</span> _<br />&amp; <span class="st0">&quot;Where Name = 'Personnel database'&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objSoftware</span> <span class="kw1">in</span> <span class="re0">$colSoftware</span><br /><span class="re0">$objSoftware</span>.<span class="me1">Uninstall</span><span class="br0">(</span><span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>2.列出全部的已安装的软件</p><p>如果软件是使用Microsoft Windows Installer (MSI) 安装的话,使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394378.aspx"><strong>Win32_Product</strong></a> 类</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colSoftware</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_Product&quot;</span><span class="br0">)</span><br /><br /><span class="kw1">For</span> <span class="re0">$objSoftware</span> <span class="kw1">in</span> <span class="re0">$colSoftware</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Name: &quot;</span> &amp; <span class="re0">$objSoftware</span>.<span class="me1">Name</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Version: &quot;</span> &amp; <span class="re0">$objSoftware</span>.<span class="me1">Version</span> &amp; <span class="re0">@CRLF</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>3.检查用户安装的Microsoft Office的版本</p><p>使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394378.aspx"><strong>Win32_Product</strong></a> 类下的 <strong>Version</strong> 属性</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colSoftware</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span><span class="br0">(</span><span class="st0">&quot;Select * from Win32_Product &quot;</span> &amp; _<br /><span class="st0">&quot;Where IdentifyingNumber =&quot;</span> _<br />&amp; <span class="st0">&quot; '&#123;90280409-6000-11D3-8CFE-0050048383C9&#125;'&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objItem</span> <span class="kw1">in</span> <span class="re0">$colSoftware</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Name: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Name</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Version: &quot;</span> &amp; <span class="re0">$objItem</span>.<span class="me1">Version</span> &amp; <span class="re0">@CRLF</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote></blockquote><p dir="ltr">No.3.桌面管理</p><blockquote dir="ltr" style="margin-right: 0px"><p>1.判断系统是否启动在安全模式的网络状态下下</p><p>使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394102.aspx"><strong>Win32_ComputerSystem</strong></a> 类并检查 <strong>PrimaryOwnerName</strong> 属性.</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colSettings</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_ComputerSystem&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objComputer</span> <span class="kw1">in</span> <span class="re0">$colSettings</span> <br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;System Name: &quot;</span> _<br />&amp; <span class="re0">$objComputer</span>.<span class="me1">Name</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Registered owner: &quot;</span> _<br />&amp; <span class="re0">$objComputer</span>.<span class="me1">PrimaryOwnerName</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>2.检查屏幕保护是否需要密码</p><p>使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394121.aspx"><strong>Win32_Desktop</strong></a> 类并检查 <strong>ScreenSaverSecure</strong> 属性.</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&#92;&#92;&quot;</span> &amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colItems</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span><span class="br0">(</span><span class="st0">&quot;Select * from Win32_Desktop&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objItem</span> <span class="kw1">in</span> <span class="re0">$colItems</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Screen Saver Secure: &quot;</span> _<br />&amp; <span class="re0">$objItem</span>.<span class="me1">ScreenSaverSecure</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>3.获取屏幕分辨率</p><p>使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394122.aspx"><strong>Win32_DesktopMonitor</strong></a> 类并检查 <strong>ScreenHeight</strong> 和 <strong>ScreenWidth</strong> 属性.</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&#92;&#92;&quot;</span> &amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colItems</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span><span class="br0">(</span> <span class="st0">&quot;Select * from Win32_DesktopMonitor&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objItem</span> <span class="kw1">in</span> <span class="re0">$colItems</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Screen Height: &quot;</span> _<br />&amp; <span class="re0">$objItem</span>.<span class="me1">ScreenHeight</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Screen Width: &quot;</span> _<br />&amp; <span class="re0">$objItem</span>.<span class="me1">ScreenWidth</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>4.获取系统开机的时间</p><p>使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394239.aspx"><strong>Win32_OperatingSystem</strong></a> 类的 <strong>LastBootUpTime</strong> 属性. </p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colOperatingSystems</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_OperatingSystem&quot;</span><span class="br0">)</span><br /><br /><span class="kw1">For</span> <span class="re0">$objOS</span> <span class="kw1">in</span> <span class="re0">$colOperatingSystems</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="re0">$objOS</span>.<span class="me1">LastBootUpTime</span><span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p dir="ltr">.5.重启或关闭远程计算机</p><p dir="ltr">使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394239.aspx"><strong>Win32_OperatingSystem</strong></a> 类以及 <a href="http://msdn2.microsoft.com/en-us/library/aa394058.aspx"><strong>Win32Shutdown</strong></a> 途径</p><blockquote dir="ltr" style="margin-right: 0px"><p dir="ltr"><span class="re0">$strComputer</span> = <span class="st0">&quot;atl-dc-01&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate,(Shutdown)&#125;!&#92;&#92;&quot;</span> &amp; _<br /><span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colOperatingSystems</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_OperatingSystem&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objOperatingSystem</span> <span class="kw1">in</span> <span class="re0">$colOperatingSystems</span><br /><span class="re0">$ObjOperatingSystem</span>.<span class="kw3">Shutdown</span><span class="br0">(</span><span class="nu0">1</span><span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote><p>6.检查开机自启动项</p><p>使用 <a href="http://msdn2.microsoft.com/en-us/library/aa394464.aspx"><strong>Win32_StartupCommand</strong></a> 类</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">&quot;.&quot;</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">&quot;winmgmts:&quot;</span> _<br />&amp; <span class="st0">&quot;&#123;impersonationLevel=impersonate&#125;!&#92;&#92;&quot;</span> _<br />&amp; <span class="re0">$strComputer</span> &amp; <span class="st0">&quot;&#92;root&#92;cimv2&quot;</span><span class="br0">)</span><br /><span class="re0">$colStartupCommands</span> = <span class="re0">$objWMIService</span>.<span class="me1">ExecQuery</span> _<br /><span class="br0">(</span><span class="st0">&quot;Select * from Win32_StartupCommand&quot;</span><span class="br0">)</span><br /><span class="kw1">For</span> <span class="re0">$objStartupCommand</span> <span class="kw1">in</span> <span class="re0">$colStartupCommands</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">&quot;Command: &quot;</span> &amp; <span class="re0">$objStartupCommand</span>.<span class="me1">Command</span> &amp; <span class="re0">@CRLF</span> _<br />&amp; <span class="st0">&quot;Description: &quot;</span> &amp; <span class="re0">$objStartupCommand</span>.<span class="me1">Description</span> &amp; <span class="re0">@CRLF</span> _<br />&amp; <span class="st0">&quot;Location: &quot;</span> &amp; <span class="re0">$objStartupCommand</span>.<span class="me1">Location</span> &amp; <span class="re0">@CRLF</span> _<br />&amp; <span class="st0">&quot;Name: &quot;</span> &amp; <span class="re0">$objStartupCommand</span>.<span class="me1">Name</span> &amp; <span class="re0">@CRLF</span> _<br />&amp; <span class="st0">&quot;SettingID: &quot;</span> &amp; <span class="re0">$objStartupCommand</span>.<span class="me1">SettingID</span> &amp; <span class="re0">@CRLF</span> _<br />&amp; <span class="st0">&quot;User: &quot;</span> &amp; <span class="re0">$objStartupCommand</span>.<span class="me1">User</span> &amp; <span class="re0">@CRLF</span> &amp; <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote></blockquote>
发表于 2009-5-3 00:52:45 | 显示全部楼层
DDDDDDDDDD
发表于 2009-5-3 14:18:28 | 显示全部楼层
发表于 2010-8-19 17:26:01 | 显示全部楼层
学习了,谢谢。楼主
发表于 2010-8-27 17:21:29 | 显示全部楼层
顶!!!!
学习下
发表于 2010-8-31 13:11:55 | 显示全部楼层
搞成一本书,发表一下吧!
发表于 2010-9-2 23:12:33 | 显示全部楼层
有用,不错.
发表于 2010-9-2 23:16:06 | 显示全部楼层
看了,不错,找下上册
发表于 2010-9-5 01:13:40 | 显示全部楼层
看看                                ok
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-4 16:23 , Processed in 0.091091 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表