<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>奋斗博客 &#187; CPU使用率</title>
	<atom:link href="http://www.fendou.info/tag/cpu%e4%bd%bf%e7%94%a8%e7%8e%87/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fendou.info</link>
	<description>WordPress&#124;SEO&#124;Web&#124;Linux&#124;Windows&#124;Android</description>
	<lastBuildDate>Wed, 16 May 2012 07:29:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>VBS脚本得到CPU使用率，硬盘使用率和内存使用率</title>
		<link>http://www.fendou.info/vbs-get-cpu-harddisk-ram-rate/</link>
		<comments>http://www.fendou.info/vbs-get-cpu-harddisk-ram-rate/#comments</comments>
		<pubDate>Mon, 25 May 2009 10:31:14 +0000</pubDate>
		<dc:creator>dev</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[CPU使用率]]></category>
		<category><![CDATA[VBS]]></category>
		<category><![CDATA[内存使用率]]></category>
		<category><![CDATA[硬盘使用率]]></category>

		<guid isPermaLink="false">http://www.fendou.info/?p=153</guid>
		<description><![CDATA[VBS脚本得到CPU使用率，硬盘使用率和内存使用率 <a href="http://www.fendou.info/vbs-get-cpu-harddisk-ram-rate/">继续阅读 <span class="meta-nav">&#8594;</span></a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"></font></b></td>
    </tr>
    
        <tr>
                <td width="111" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="VBS代码收集" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.fendou.info%2Fvbs-code-collect%2F&from=http%3A%2F%2Fwww.fendou.info%2Fvbs-get-cpu-harddisk-ram-rate%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 105px !important; height: 105px !important;" src="http://static.wumii.com/site_images/2011/11/20/11181867.jpg" width="105px" height="105px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 111px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">VBS代码收集</font>
                    </a>
                </td>
                <td width="111" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="VBS代码加密解密" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.fendou.info%2Fvbs-code-encode-and-unencode%2F&from=http%3A%2F%2Fwww.fendou.info%2Fvbs-get-cpu-harddisk-ram-rate%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 105px !important; height: 105px !important;" src="http://static.wumii.com/site_images/2011/10/16/9293540.png" width="105px" height="105px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 111px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">VBS代码加密解密</font>
                    </a>
                </td>
                <td width="111" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="vbs脚本实现普通用户以管理员权限运行程序" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.fendou.info%2Fvbs-run-software-as-administrator%2F&from=http%3A%2F%2Fwww.fendou.info%2Fvbs-get-cpu-harddisk-ram-rate%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 105px !important; height: 105px !important;" src="http://static.wumii.com/site_images/2011/10/16/9293898.jpg" width="105px" height="105px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 111px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">vbs脚本实现普通用户以管理员权限运行程序</font>
                    </a>
                </td>
                <td width="111" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="人为踩死鸟为食亡" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.fendou.info%2Fcambodia-serious-stampede%2F&from=http%3A%2F%2Fwww.fendou.info%2Fvbs-get-cpu-harddisk-ram-rate%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 105px !important; height: 105px !important;" src="http://static.wumii.com/site_images/2011/10/16/9293762.jpg" width="105px" height="105px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 111px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">人为踩死鸟为食亡</font>
                    </a>
                </td>
                <td width="111" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="巧用QQ空间动画制作网站欢迎Flash" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.fendou.info%2Fmake-special-flash%2F&from=http%3A%2F%2Fwww.fendou.info%2Fvbs-get-cpu-harddisk-ram-rate%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 105px !important; height: 105px !important;" src="http://static.wumii.com/site_images/2011/12/27/13129276.gif" width="105px" height="105px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 111px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">巧用QQ空间动画制作网站欢迎Flash</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>在不用第三方软件前提下想定时检查服务器的cpu使用率硬盘使用率和内存使用率，并生成报表在服务器巡检过程中相当实用，其实在Windows下，可以用批处理命令写一个脚本，在一定程度上完成这些简单的任务，但是如果想要实现复杂的功能，批处理命令就力不从心了。处理批处理命令，微软还提供了WSH。我们可以使用VBScript来写脚本，访问其内置对象或COM对象，然后让其在WSH中执行，就可以完成较为复杂的功能。下面提供几种实用的代码，只需要将代码复制到文本文档然后保存为vbs格式就可以在windows上直接运行了，如果是win2k的系统那么你需要从xp或win2003的system32下copy “CScript.exe”到vbs的脚本目录。<span id="more-153"></span></p>
<p>CPU 使用率代码如下<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #151B8D; font-weight: bold;">On</span> <span style="color: #151B8D; font-weight: bold;">Error</span> <span style="color: #151B8D; font-weight: bold;">Resume</span> <span style="color: #8D38C9; font-weight: bold;">Next</span>
&nbsp;
<span style="color: #151B8D; font-weight: bold;">Set</span> objProc  = <span style="color: #E56717; font-weight: bold;">GetObject</span>(<span style="color: #800000;">&quot;winmgmts:\\.\root\cimv2:win32_processor='cpu0'&quot;</span>)
Wscript.Echo <span style="color: #800000;">&quot;CPU 使用率: &quot;</span> &amp; objProc.LoadPercentage &amp; <span style="color: #800000;">&quot;%&quot;</span></pre></div></div>

<p></code></p>
<p>硬盘 使用率代码如下<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #151B8D; font-weight: bold;">Set</span> fsoobj = <span style="color: #E56717; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.FileSystemObject&quot;</span>)
 DriversInfo = GetDriversInfo
 DriversInfo = Replace(DriversInfo, <span style="color: #800000;">&quot;|&quot;</span>, vbCrLf)
 sReturn =<span style="color: #800000;">&quot;硬盘信息：&quot;</span> &amp; vbCrLf &amp; DriversInfo
 Wscript.Echo sReturn
<span style="color: #E56717; font-weight: bold;">Function</span> GetDriversInfo()
&nbsp;
   GetDriversInfo = <span style="color: #800000;">&quot;&quot;</span>
   <span style="color: #151B8D; font-weight: bold;">Set</span> drvObj = fsoobj.Drives
   <span style="color: #8D38C9; font-weight: bold;">For</span> <span style="color: #8D38C9; font-weight: bold;">Each</span> D <span style="color: #8D38C9; font-weight: bold;">In</span> drvObj
       Err.Clear
       <span style="color: #8D38C9; font-weight: bold;">If</span> D.DriveLetter &lt;&gt; <span style="color: #800000;">&quot;A&quot;</span> <span style="color: #8D38C9; font-weight: bold;">Then</span>
           <span style="color: #8D38C9; font-weight: bold;">If</span> D.isReady <span style="color: #8D38C9; font-weight: bold;">Then</span>
               GetDriversInfo = GetDriversInfo &amp; <span style="color: #800000;">&quot;分区:&quot;</span> &amp; D.DriveLetter &amp; vbCrLf
               GetDriversInfo = GetDriversInfo &amp; <span style="color: #800000;">&quot;可用空间:&quot;</span> &amp; cSize(D.FreeSpace) &amp; vbCrLf
               GetDriversInfo = GetDriversInfo &amp; <span style="color: #800000;">&quot;总大小:&quot;</span> &amp; cSize( D.TotalSize) &amp; vbCrLf
               GetDriversInfo = GetDriversInfo &amp; <span style="color: #800000;">&quot;使用率 :&quot;</span> &amp; (100*((D.TotalSize-D.FreeSpace)/D.TotalSize)) &amp;<span style="color: #800000;">&quot;%&quot;</span> &amp; vbCrLf
               GetDriversInfo = GetDriversInfo &amp; <span style="color: #800000;">&quot;|&quot;</span>
             <span style="color: #8D38C9; font-weight: bold;">Else</span>
           <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
         <span style="color: #8D38C9; font-weight: bold;">Else</span>
       <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
   <span style="color: #8D38C9; font-weight: bold;">Next</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span>
&nbsp;
 <span style="color: #E56717; font-weight: bold;">Function</span> cSize(tSize)
&nbsp;
     <span style="color: #8D38C9; font-weight: bold;">If</span> tSize &gt;= 1073741824 <span style="color: #8D38C9; font-weight: bold;">Then</span>
         cSize = Int((tSize / 1073741824) * 1000) / 1000 &amp; <span style="color: #800000;">&quot; GB&quot;</span>
       <span style="color: #8D38C9; font-weight: bold;">ElseIf</span> tSize &gt;= 1048576 <span style="color: #8D38C9; font-weight: bold;">Then</span>
         cSize = Int((tSize / 1048576) * 1000) / 1000 &amp; <span style="color: #800000;">&quot; MB&quot;</span>
       <span style="color: #8D38C9; font-weight: bold;">ElseIf</span> tSize &gt;= 1024 <span style="color: #8D38C9; font-weight: bold;">Then</span>
         cSize = Int((tSize / 1024) * 1000) / 1000 &amp; <span style="color: #800000;">&quot; KB&quot;</span>
       <span style="color: #8D38C9; font-weight: bold;">Else</span>
         cSize = tSize &amp; <span style="color: #800000;">&quot;B&quot;</span>
     <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></pre></div></div>

<p></code></p>
<p>内存 使用率代码如下<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">strComputer = <span style="color: #800000;">&quot;.&quot;</span>
<span style="color: #151B8D; font-weight: bold;">set</span> objWMI = <span style="color: #E56717; font-weight: bold;">GetObject</span>(<span style="color: #800000;">&quot;winmgmts:\\&quot;</span> &amp; strComputer &amp; <span style="color: #800000;">&quot;\root\cimv2&quot;</span>)
<span style="color: #151B8D; font-weight: bold;">set</span> colOS = objWMI.InstancesOf(<span style="color: #800000;">&quot;Win32_OperatingSystem&quot;</span>)
<span style="color: #8D38C9; font-weight: bold;">for</span> <span style="color: #8D38C9; font-weight: bold;">each</span> objOS <span style="color: #8D38C9; font-weight: bold;">in</span> colOS
strReturn = <span style="color: #800000;">&quot;内存总数: &quot;</span> &amp;  round(objOS.TotalVisibleMemorySize / 1024) &amp; <span style="color: #800000;">&quot; MB&quot;</span> &amp; vbCrLf &amp;<span style="color: #800000;">&quot;内存可用数: &quot;</span> &amp; round(objOS.FreePhysicalMemory / 1024) &amp; <span style="color: #800000;">&quot; MB&quot;</span> &amp; vbCrLf &amp;<span style="color: #800000;">&quot;内存使用率 :&quot;</span> &amp; Round(((objOS.TotalVisibleMemorySize-objOS.FreePhysicalMemory)/objOS.TotalVisibleMemorySize)*100) &amp; <span style="color: #800000;">&quot;%&quot;</span>
Wscript.Echo strReturn
<span style="color: #8D38C9; font-weight: bold;">next</span></pre></div></div>

<p></code></p>
<p>如果想把结果保存在文本里只需要用批处理调用</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">echo off
echo CPU信息：&gt;info.xls
cscript //Nologo cpu.vbs &gt;&gt; info.xls
echo.&gt;&gt;info.xls
echo 内存信息：&gt;&gt;info.txt
cscript //Nologo ram.vbs &gt;&gt; info.txt
echo.&gt;&gt;info.xls
cscript //Nologo hard.vbs &gt;&gt; info.txt
rem copy info.xls <span style="color: #800000;">&quot;%date%&quot;</span>.xls</pre></div></div>

<p></code></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"></font></b></td>
    </tr>
    
        <tr>
                <td width="111" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="VBS代码收集" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.fendou.info%2Fvbs-code-collect%2F&from=http%3A%2F%2Fwww.fendou.info%2Fvbs-get-cpu-harddisk-ram-rate%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 105px !important; height: 105px !important;" src="http://static.wumii.com/site_images/2011/11/20/11181867.jpg" width="105px" height="105px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 111px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">VBS代码收集</font>
                    </a>
                </td>
                <td width="111" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="VBS代码加密解密" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.fendou.info%2Fvbs-code-encode-and-unencode%2F&from=http%3A%2F%2Fwww.fendou.info%2Fvbs-get-cpu-harddisk-ram-rate%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 105px !important; height: 105px !important;" src="http://static.wumii.com/site_images/2011/10/16/9293540.png" width="105px" height="105px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 111px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">VBS代码加密解密</font>
                    </a>
                </td>
                <td width="111" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="vbs脚本实现普通用户以管理员权限运行程序" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.fendou.info%2Fvbs-run-software-as-administrator%2F&from=http%3A%2F%2Fwww.fendou.info%2Fvbs-get-cpu-harddisk-ram-rate%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 105px !important; height: 105px !important;" src="http://static.wumii.com/site_images/2011/10/16/9293898.jpg" width="105px" height="105px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 111px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">vbs脚本实现普通用户以管理员权限运行程序</font>
                    </a>
                </td>
                <td width="111" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Google Artists Hub 允许独立音乐人自己传歌自己卖" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.fendou.info%2Fgoogles-artists-hub%2F&from=http%3A%2F%2Fwww.fendou.info%2Fvbs-get-cpu-harddisk-ram-rate%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 105px !important; height: 105px !important;" src="http://static.wumii.com/site_images/2011/11/18/11082358.jpg" width="105px" height="105px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 111px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Google Artists Hub 允许独立音乐人自己传歌自己卖</font>
                    </a>
                </td>
                <td width="111" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="那些外国人告诉我们的事" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.fendou.info%2Fabout-china%2F&from=http%3A%2F%2Fwww.fendou.info%2Fvbs-get-cpu-harddisk-ram-rate%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 105px !important; height: 105px !important;" src="http://static.wumii.com/site_images/2011/11/03/10232783.jpg" width="105px" height="105px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 111px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">那些外国人告诉我们的事</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.fendou.info/vbs-get-cpu-harddisk-ram-rate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

