<?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>Timothy&#039;s Space &#187; VC</title>
	<atom:link href="http://www.xiaozhou.net/tag/vc/feed" rel="self" type="application/rss+xml" />
	<link>http://www.xiaozhou.net</link>
	<description>君看一叶舟，出没风波里</description>
	<lastBuildDate>Thu, 02 Sep 2010 15:10:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>VC源动力站点关闭</title>
		<link>http://www.xiaozhou.net/aboutsite/sitelog/vc-source-for-site-closure-2009-09-25.htm</link>
		<comments>http://www.xiaozhou.net/aboutsite/sitelog/vc-source-for-site-closure-2009-09-25.htm#comments</comments>
		<pubDate>Fri, 25 Sep 2009 13:24:04 +0000</pubDate>
		<dc:creator>Timothy</dc:creator>
				<category><![CDATA[站点日志]]></category>
		<category><![CDATA[close]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[VC]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=243</guid>
		<description><![CDATA[VC源动力是一个Visual C++ 开发相关的网站，从2004年09月开始建立，站点的主要宗旨是向广大VC开发爱好者提供免费的文章、代码、交流平台，至今已经有5年的时间了。但是由于我的精力有限，站点长时间荒废没有更新，很是惭愧。再加上如今自己的工作方向不再是VC开发，而是转向.net了开发，所以我决定将VC源动力站点关闭。原来的www.xiaozhou.net由我的个人博客所代替，原有博客的地址http://www.xiaozhou.net/cooldog也会自动跳转到http://www.xiaozhou.net。 在此感谢各位网友曾经对该站的支持和帮助，如果这个站点所提供的信息曾经帮助过你解决过VC开发上所遇到的问题，又或者在开发过程中带给你灵感，那将是我的荣幸。等我有时间，我会把所有的站点资料整理成文件供网友下载。希望大家会记得这个名字：VC源动力。 你可能也对下列文章感兴趣2010年01月4日 -- 违法网站 (15)2004年10月26日 -- VC中实现历史记录的全面清除 (2)2004年09月7日 -- 在VC中使用WMI（英文原版） (0)]]></description>
			<content:encoded><![CDATA[<p><a href="/pics/VC_9AA8/xiaozhou.gif"><img style="display: inline;" title="xiaozhou" src="/pics/VC_9AA8/xiaozhou_thumb.gif" alt="xiaozhou" width="160" height="60" /></a></p>
<p>VC源动力是一个Visual C++ 开发相关的网站，从2004年09月开始建立，站点的主要宗旨是向广大VC开发爱好者提供免费的文章、代码、交流平台，至今已经有5年的时间了。但是由于我的精力有限，站点长时间荒废没有更新，很是惭愧。再加上如今自己的工作方向不再是VC开发，而是转向.net了开发，所以我决定将VC源动力站点关闭。原来的<a href="http://www.xiaozhou.net">www.xiaozhou.net</a>由我的个人博客所代替，原有博客的地址<a href="http://www.xiaozhou.net/cooldog">http://www.xiaozhou.net/cooldog</a>也会自动跳转到<a href="http://www.xiaozhou.net">http://www.xiaozhou.net</a>。</p>
<p>在此感谢各位网友曾经对该站的支持和帮助，如果这个站点所提供的信息曾经帮助过你解决过VC开发上所遇到的问题，又或者在开发过程中带给你灵感，那将是我的荣幸。等我有时间，我会把所有的站点资料整理成文件供网友下载。希望大家会记得这个名字：VC源动力。</p>
<h3  class="related_post_title">你可能也对下列文章感兴趣</h3><ul class="related_post"><li>2010年01月4日 -- <a href="http://www.xiaozhou.net/essay/illegal_site-2010-01-04.htm" title="违法网站">违法网站</a> (15)</li><li>2004年10月26日 -- <a href="http://www.xiaozhou.net/vcdevelopment/vc-to-realize-the-full-history-removal-2004-10-26.htm" title="VC中实现历史记录的全面清除">VC中实现历史记录的全面清除</a> (2)</li><li>2004年09月7日 -- <a href="http://www.xiaozhou.net/vcdevelopment/in-the-vc-to-use-wmi-english-original-2004-09-07.htm" title="在VC中使用WMI（英文原版）">在VC中使用WMI（英文原版）</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.xiaozhou.net/aboutsite/sitelog/vc-source-for-site-closure-2009-09-25.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VC中实现历史记录的全面清除</title>
		<link>http://www.xiaozhou.net/vcdevelopment/vc-to-realize-the-full-history-removal-2004-10-26.htm</link>
		<comments>http://www.xiaozhou.net/vcdevelopment/vc-to-realize-the-full-history-removal-2004-10-26.htm#comments</comments>
		<pubDate>Tue, 26 Oct 2004 09:48:57 +0000</pubDate>
		<dc:creator>Timothy</dc:creator>
				<category><![CDATA[VC开发]]></category>
		<category><![CDATA[clear]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[VC]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=40</guid>
		<description><![CDATA[http://www.vckbase.com/document/viewdoc.asp?id=280 你可能也对下列文章感兴趣2009年09月25日 -- VC源动力站点关闭 (0)2004年09月7日 -- 在VC中使用WMI（英文原版） (0)]]></description>
			<content:encoded><![CDATA[<p>http://www.vckbase.com/document/viewdoc.asp?id=280</p>
<h3  class="related_post_title">你可能也对下列文章感兴趣</h3><ul class="related_post"><li>2009年09月25日 -- <a href="http://www.xiaozhou.net/aboutsite/sitelog/vc-source-for-site-closure-2009-09-25.htm" title="VC源动力站点关闭">VC源动力站点关闭</a> (0)</li><li>2004年09月7日 -- <a href="http://www.xiaozhou.net/vcdevelopment/in-the-vc-to-use-wmi-english-original-2004-09-07.htm" title="在VC中使用WMI（英文原版）">在VC中使用WMI（英文原版）</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.xiaozhou.net/vcdevelopment/vc-to-realize-the-full-history-removal-2004-10-26.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>在VC中使用WMI（英文原版）</title>
		<link>http://www.xiaozhou.net/vcdevelopment/in-the-vc-to-use-wmi-english-original-2004-09-07.htm</link>
		<comments>http://www.xiaozhou.net/vcdevelopment/in-the-vc-to-use-wmi-english-original-2004-09-07.htm#comments</comments>
		<pubDate>Tue, 07 Sep 2004 06:51:10 +0000</pubDate>
		<dc:creator>Timothy</dc:creator>
				<category><![CDATA[VC开发]]></category>
		<category><![CDATA[VC]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=15</guid>
		<description><![CDATA[作者：BugSearcher Introduction We normally find a lot of ways and a number of resources to use WMI or to get information from “Windows Management Instrumentation” while using Visual Basic 6 and C#, but I could not find a single resource describing the same thing in Visual C++. MSDN resources are also very limited in this [...]]]></description>
			<content:encoded><![CDATA[<p>作者：BugSearcher<br />
Introduction<br />
We normally find a lot of ways and a number of resources to use WMI or to get information from “Windows Management Instrumentation” while using Visual Basic 6 and C#, but I could not find a single resource describing the same thing in Visual C++. MSDN resources are also very limited in this context.</p>
<p>Code<br />
Following is the code on how to get the current processor load from a WMI class Win32_Processor defined in a .mof file. .mof files are managed object files which have a typical way of defining classes and methods.</p>
<p>WMI provides the COM service which is used to connect to the WMI services. The important parts of the code include:</p>
<p>bstrNamespace : The initialization of this variable is very tricky. The first three forward slashes //./ represent the Host Computer name from which you want to get information from. A “.” Indicates that information is to be obtained from the Same Computer on which you are working. You can give any Network name here but getting information from network depends upon your Access Rights etc. cimv2 is the namespace containing the Win32_Processor class.<br />
pIWbemLocator is the argument in which we get the Interface pointer.<br />
After that, we call the function ConnectServer of the pIWbemLocator to get a pointer to pWbemServices.<br />
WMI uses its own Query Language to get information known as WQL (the acronym for WMI Query Language). So, when calling the function ExecQuery, we have to specify the language as its first argument. Second argument is the Query itself. Last argument is important because here we get a pointer to an Enumeration object through which we can enumerate through the objects available. This enumeration is important because consider the case that we want to know the information about running processes and we are using Win32_Process class for this purpose. Then through this enumeration object, we can go through different processes one by one.<br />
By calling the Reset and Next methods of pEnumObject, we are moving through the objects. We get the pointer to an object in pClassObject.<br />
The last function through which we get the Actual value of a property is Get. We pass a BSTR to this function to get the value in a Variant.<br />
CoInitialize(NULL);</p>
<p>//Security needs to be initialized in XP first</p>
<p>if(CoInitializeSecurity( NULL,<br />
-1,<br />
NULL,<br />
NULL,<br />
RPC_C_AUTHN_LEVEL_PKT,<br />
RPC_C_IMP_LEVEL_IMPERSONATE,<br />
NULL,<br />
EOAC_NONE,<br />
0<br />
) != S_OK)<br />
    return;</p>
<p>IWbemLocator * pIWbemLocator = NULL;<br />
IWbemServices * pWbemServices = NULL;<br />
IEnumWbemClassObject * pEnumObject = NULL;<br />
BSTR bstrNamespace = (L&#8221;root\\cimv2&#8243;);<br />
HRESULT hRes = CoCreateInstance (<br />
  CLSID_WbemAdministrativeLocator,<br />
  NULL ,<br />
  CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,<br />
  IID_IUnknown ,<br />
  ( void ** ) &#038; pIWbemLocator<br />
  ) ;<br />
if (SUCCEEDED(hRes))<br />
{<br />
  hRes = pIWbemLocator->ConnectServer(<br />
  bstrNamespace, // Namespace<br />
  NULL, // Userid<br />
  NULL, // PW<br />
  NULL, // Locale<br />
  0, // flags<br />
  NULL, // Authority<br />
  NULL, // Context<br />
  &#038;pWbemServices<br />
  );<br />
}<br />
BSTR strQuery = (L&#8221;Select * from win32_Processor&#8221;);<br />
BSTR strQL = (L&#8221;WQL&#8221;);<br />
hRes = pWbemServices->ExecQuery(strQL, strQuery,<br />
  WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&#038;pEnumObject);</p>
<p>ULONG uCount = 1, uReturned;<br />
IWbemClassObject * pClassObject = NULL;<br />
hRes = pEnumObject->Reset();<br />
hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &#038;pClassObject, &#038;uReturned);<br />
VARIANT v;<br />
BSTR strClassProp = SysAllocString(L&#8221;LoadPercentage&#8221;);<br />
hRes = pClassObject->Get(strClassProp, 0, &#038;v, 0, 0);<br />
SysFreeString(strClassProp);</p>
<p>_bstr_t bstrPath = &#038;v; //Just to convert BSTR to ANSI<br />
char* strPath=(char*)bstrPath;<br />
if (SUCCEEDED(hRes))<br />
MessageBox(strPath);<br />
else<br />
MessageBox(”Error in getting object”);<br />
VariantClear( &#038;v );<br />
pIWbemLocator->Release();<br />
pWbemServices->Release();<br />
pEnumObject->Release();<br />
pClassObject->Release();<br />
CoUninitialize();<br />
Conclusion<br />
This was the shortest method I was able to work out to get information from any WMI class. You can simply change the class name in the Query and Property Name while calling Get method and you will get information from all the classes supported in your OS. I tested this code in Windows 2000 Professional. I hope it will work well for Win XP but probably not in previous versions of windows because they don’t support a lot of WMI classes.</p>
<p>Update<br />
I am updating this Article and the code for Windows XP. As I said in the beginning, this was initially intended for Windows 2K and it was still working fine on Windows 2K machine (I have checked it on at least 10 now coz I was getting so many complaints). Well, for Windows XP there is one major change and that was suggested by igoychev. Many thanks for that. The problem with Windows XP was that it needed security to be initialized first. Plus, I have also changed those confusing slashes in bstrNamespace to some simpler ones. I am using Windows 2003 Advance Server and it is working fine on it. You need to include wbemuuid.lib in Project Settings -> Linker -> Additional Dependencies to get this code working. I have also added some error checking to avoid crashes, hope it works for you. You need to have Platform SDK installed for this code to compile. WMI SDK is not necessary once again. Sorry rbervgm, your work was great using WMI SDK but I thought better to keep it WMI SDK Clean. Hope you don&#8217;t mind. Now, I hope that downloadable project will work for most of the people. One more thing, it still works for Windows 2K machines.</p>
<h3  class="related_post_title">你可能也对下列文章感兴趣</h3><ul class="related_post"><li>2009年09月25日 -- <a href="http://www.xiaozhou.net/aboutsite/sitelog/vc-source-for-site-closure-2009-09-25.htm" title="VC源动力站点关闭">VC源动力站点关闭</a> (0)</li><li>2004年10月26日 -- <a href="http://www.xiaozhou.net/vcdevelopment/vc-to-realize-the-full-history-removal-2004-10-26.htm" title="VC中实现历史记录的全面清除">VC中实现历史记录的全面清除</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.xiaozhou.net/vcdevelopment/in-the-vc-to-use-wmi-english-original-2004-09-07.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
