找回密码
 加入
搜索
查看: 13281|回复: 23

在Autoit中使用WMI:第三部分

 火.. [复制链接]
发表于 2008-5-3 14:19:50 | 显示全部楼层 |阅读模式
<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>
发表于 2008-12-16 11:23:46 | 显示全部楼层
  这么好的文章没人顶
发表于 2008-12-18 04:36:37 | 显示全部楼层
看到这张后   终于知道了可以做什么了 好东西呀
收藏  返回研究前面的再来
发表于 2009-1-13 10:08:59 | 显示全部楼层
收藏同,不断学习中
发表于 2009-2-2 14:56:17 | 显示全部楼层
不错,收下了
发表于 2009-2-2 15:13:08 | 显示全部楼层
写的 真好 差点没看懂!
发表于 2009-4-28 15:10:42 | 显示全部楼层
真是不错。
发表于 2009-10-13 20:49:28 | 显示全部楼层
正在学习找这方面的资料,学习了
发表于 2009-10-22 14:55:03 | 显示全部楼层
写的 真好 差点没看懂!
发表于 2009-11-25 15:19:18 | 显示全部楼层
绝对好资料,顶了……
发表于 2010-4-17 11:23:30 | 显示全部楼层
牛B...强悍..谢谢了
发表于 2010-4-18 13:36:06 | 显示全部楼层
前面的连接在哪
发表于 2010-4-18 16:09:38 | 显示全部楼层
好东西该支持下
发表于 2010-4-19 08:08:48 | 显示全部楼层
顶贴拿分,顶贴拿分
发表于 2010-4-21 14:26:26 | 显示全部楼层
讲解到位。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-22 16:23 , Processed in 0.116639 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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