autoit调用WMI(下)
<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">"."</span><br /><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_OperatingSystem"</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">"可用物理内存: "</span> & _<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">"."</span><br /><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_CDROMDrive"</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">"Device ID: "</span> & <span class="re0">$objItem</span>.<span class="me1">DeviceID</span> &<span class="re0">@CRLF</span> _<br />& <span class="st0">"Description: "</span> & <span class="re0">$objItem</span>.<span class="me1">Description</span> &<span class="re0">@CRLF</span> _<br />& <span class="st0">"Name: "</span> & <span class="re0">$objItem</span>.<span class="me1">Name</span> &<span class="re0">@CRLF</span> &<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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_ComputerSystem"</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">"System Name: "</span> & <span class="re0">$objComputer</span>.<span class="me1">Name</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Number of Processors: "</span> & _<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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:\\"</span> & <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_PCMCIAController"</span><span class="br0">)</span><br /><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Number of PCMCIA slots: "</span> _<br />& <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 <> 0</strong> 来判断</p><blockquote dir="ltr" style="margin-right: 0px"><p><span class="re0">$strComputer</span> = <span class="st0">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:\\"</span> & <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_PnPEntity "</span> _<br />& <span class="st0">"WHERE ConfigManagerErrorCode <> 0"</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">"Class GUID: "</span> & <span class="re0">$objItem</span>.<span class="me1">ClassGuid</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Description: "</span> & <span class="re0">$objItem</span>.<span class="me1">Description</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Device ID: "</span> & <span class="re0">$objItem</span>.<span class="me1">DeviceID</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Manufacturer: "</span> & <span class="re0">$objItem</span>.<span class="me1">Manufacturer</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Name: "</span> & <span class="re0">$objItem</span>.<span class="me1">Name</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"PNP Device ID: "</span> & <span class="re0">$objItem</span>.<span class="me1">PNPDeviceID</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Service: "</span> & <span class="re0">$objItem</span>.<span class="me1">Service</span> & <span class="re0">@CRLF</span> & <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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span> _<br /><span class="st0">"winmgmts:\\"</span> & <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_PointingDevice"</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">"Description: "</span> & <span class="re0">$objItem</span>.<span class="me1">Description</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Device ID: "</span> & <span class="re0">$objItem</span>.<span class="me1">DeviceID</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Device Interface: "</span> _<br />& <span class="re0">$objItem</span>.<span class="me1">DeviceInterface</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Double Speed Threshold: "</span> _<br />& <span class="re0">$objItem</span>.<span class="me1">DoubleSpeedThreshold</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Handedness: "</span> & <span class="re0">$objItem</span>.<span class="me1">Handedness</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Hardware Type: "</span> & <span class="re0">$objItem</span>.<span class="me1">HardwareType</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"INF File Name: "</span> & <span class="re0">$objItem</span>.<span class="me1">InfFileName</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"INF Section: "</span> & <span class="re0">$objItem</span>.<span class="me1">InfSection</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Manufacturer: "</span> & <span class="re0">$objItem</span>.<span class="me1">Manufacturer</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Name: "</span> & <span class="re0">$objItem</span>.<span class="me1">Name</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Number Of Buttons: "</span> _<br />& <span class="re0">$objItem</span>.<span class="me1">NumberOfButtons</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"PNP Device ID: "</span> & <span class="re0">$objItem</span>.<span class="me1">PNPDeviceID</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Pointing Type: "</span> & <span class="re0">$objItem</span>.<span class="me1">PointingType</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Quad Speed Threshold: "</span> _<br />& <span class="re0">$objItem</span>.<span class="me1">QuadSpeedThreshold</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Resolution: "</span> & <span class="re0">$objItem</span>.<span class="me1">Resolution</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Sample Rate: "</span> & <span class="re0">$objItem</span>.<span class="me1">SampleRate</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Synch: "</span> & <span class="re0">$objItem</span>.<span class="me1">Synch</span> & <span class="re0">@CRLF</span> & <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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_SystemEnclosure"</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">"Chassis Type: "</span> & <span class="re0">$objItem</span> & <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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:\\"</span> & <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_USBHub"</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">"Device ID: "</span> & <span class="re0">$objItem</span>.<span class="me1">DeviceID</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"PNP Device ID: "</span> _<br />& <span class="re0">$objItem</span>.<span class="me1">PNPDeviceID</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Description: "</span> _<br />& <span class="re0">$objItem</span>.<span class="me1">Description</span> & <span class="re0">@CRLF</span> & <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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_TapeDrive"</span><span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Number of tape drives: "</span> _<br />& <span class="re0">$colItems</span>.<span class="me1">Count</span> & <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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_Product "</span> _<br />& <span class="st0">"Where Name = 'Personnel database'"</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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_Product"</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">"Name: "</span> & <span class="re0">$objSoftware</span>.<span class="me1">Name</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Version: "</span> & <span class="re0">$objSoftware</span>.<span class="me1">Version</span> & <span class="re0">@CRLF</span> & <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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_Product "</span> & _<br /><span class="st0">"Where IdentifyingNumber ="</span> _<br />& <span class="st0">" '{90280409-6000-11D3-8CFE-0050048383C9}'"</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">"Name: "</span> & <span class="re0">$objItem</span>.<span class="me1">Name</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Version: "</span> & <span class="re0">$objItem</span>.<span class="me1">Version</span> & <span class="re0">@CRLF</span> & <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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_ComputerSystem"</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">"System Name: "</span> _<br />& <span class="re0">$objComputer</span>.<span class="me1">Name</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Registered owner: "</span> _<br />& <span class="re0">$objComputer</span>.<span class="me1">PrimaryOwnerName</span> & <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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:\\"</span> & <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_Desktop"</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">"Screen Saver Secure: "</span> _<br />& <span class="re0">$objItem</span>.<span class="me1">ScreenSaverSecure</span> & <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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:\\"</span> & <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_DesktopMonitor"</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">"Screen Height: "</span> _<br />& <span class="re0">$objItem</span>.<span class="me1">ScreenHeight</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw3">ConsoleWrite</span><span class="br0">(</span> <span class="st0">"Screen Width: "</span> _<br />& <span class="re0">$objItem</span>.<span class="me1">ScreenWidth</span> & <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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_OperatingSystem"</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">"atl-dc-01"</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate,(Shutdown)}!\\"</span> & _<br /><span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_OperatingSystem"</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">"."</span><br /><span class="re0">$objWMIService</span> = <span class="kw3">ObjGet</span><span class="br0">(</span><span class="st0">"winmgmts:"</span> _<br />& <span class="st0">"{impersonationLevel=impersonate}!\\"</span> _<br />& <span class="re0">$strComputer</span> & <span class="st0">"\root\cimv2"</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">"Select * from Win32_StartupCommand"</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">"Command: "</span> & <span class="re0">$objStartupCommand</span>.<span class="me1">Command</span> & <span class="re0">@CRLF</span> _<br />& <span class="st0">"Description: "</span> & <span class="re0">$objStartupCommand</span>.<span class="me1">Description</span> & <span class="re0">@CRLF</span> _<br />& <span class="st0">"Location: "</span> & <span class="re0">$objStartupCommand</span>.<span class="me1">Location</span> & <span class="re0">@CRLF</span> _<br />& <span class="st0">"Name: "</span> & <span class="re0">$objStartupCommand</span>.<span class="me1">Name</span> & <span class="re0">@CRLF</span> _<br />& <span class="st0">"SettingID: "</span> & <span class="re0">$objStartupCommand</span>.<span class="me1">SettingID</span> & <span class="re0">@CRLF</span> _<br />& <span class="st0">"User: "</span> & <span class="re0">$objStartupCommand</span>.<span class="me1">User</span> & <span class="re0">@CRLF</span> & <span class="re0">@CRLF</span> <span class="br0">)</span><br /><span class="kw1">Next</span></p></blockquote></blockquote> :face (34):DDDDDDDDDD :face (29): 学习了,谢谢。楼主 顶!!!!学习下 搞成一本书,发表一下吧! 有用,不错. 看了,不错,找下上册 看看 ok
页:
[1]