<?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>JEDI Windows API &#187; ProcessExplorer</title>
	<atom:link href="http://blog.delphi-jedi.net/tag/processexplorer/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.delphi-jedi.net</link>
	<description>Joint Endeavor of Delphi Innovators of Windows Programming</description>
	<lastBuildDate>Sat, 21 Aug 2010 05:44:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>The case of the unexplained&#8230;</title>
		<link>http://blog.delphi-jedi.net/2008/03/16/the-case-of-the-unexplained/</link>
		<comments>http://blog.delphi-jedi.net/2008/03/16/the-case-of-the-unexplained/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 17:51:24 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[Handle]]></category>
		<category><![CDATA[Kernel Microsoft]]></category>
		<category><![CDATA[Process]]></category>
		<category><![CDATA[ProcessExplorer]]></category>
		<category><![CDATA[Russinovich]]></category>
		<category><![CDATA[Thread]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/2008/03/16/the-case-of-the-unexplained/</guid>
		<description><![CDATA[As you maybe already have noted, I use the ProcessExplorer of Mark Russinovich a lot. It is a very powerful tool, that can help you finding out what&#8217;s going on in your Windows system&#8230; Processes Threads Properties Handles Kernel Bluescreens (WinDbg) and many more If you are interested in getting an introduction into the great [...]]]></description>
			<content:encoded><![CDATA[<p>As you maybe already have noted, I use the <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx">ProcessExplorer</a> of Mark Russinovich a lot. It is a very powerful tool, that can help you finding out what&#8217;s going on in your Windows system&#8230;</p>
<ul>
<li>
<div>Processes</div>
</li>
<li>
<div>Threads</div>
</li>
<li>
<div>Properties</div>
</li>
<li>
<div>Handles</div>
</li>
<li>
<div>Kernel</div>
</li>
<li>Bluescreens (WinDbg)</li>
<li>
<div>and many more</div>
</li>
</ul>
<p>If you are interested in getting an introduction into the great application, you should watch this video. Mark presents his tool with many examples from his own experiences.</p>
<p><a href="http://www.microsoft.com/emea/spotlight/sessionh.aspx?videoid=722">http://www.microsoft.com/emea/spotlight/sessionh.aspx?videoid=722</a></p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2008/03/16/the-case-of-the-unexplained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why aren&#8217;t dialogs themed in elevated COM methods.</title>
		<link>http://blog.delphi-jedi.net/2008/03/14/why-arent-dialogs-themed-in-elevated-com-methods/</link>
		<comments>http://blog.delphi-jedi.net/2008/03/14/why-arent-dialogs-themed-in-elevated-com-methods/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 14:07:33 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[JEDI Windows Security Code Lib]]></category>
		<category><![CDATA[callback]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[DLL]]></category>
		<category><![CDATA[factory]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[mailinglist]]></category>
		<category><![CDATA[manifest]]></category>
		<category><![CDATA[ProcessExplorer]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/2008/03/14/why-arent-dialogs-themed-in-elevated-com-methods/</guid>
		<description><![CDATA[I found this question in the borland mailinglist: &#8230; I get my dialog and all runs well &#8211; *except* I&#8217;ve lost theming on this particular dialog. This means the application&#8217;s main windows shows up correctly themed, the progress dialog does not. I&#8217;ve already added the XP manifest to the progress dialog, too, but to no [...]]]></description>
			<content:encoded><![CDATA[<p>I found this question in the <a href="news://newsgroups.borland.com:119/borland.public.delphi.language.delphi.win32">borland mailinglist</a>:</p>
<blockquote><p>&#8230; I get my dialog and all runs well &#8211; *except* I&#8217;ve lost theming<br />
on this particular dialog. This means the application&#8217;s main windows shows<br />
up correctly themed, the progress dialog does not. I&#8217;ve already added the<br />
XP manifest to the progress dialog, too, but to no avail so far.</p></blockquote>
<p>A theme is only applied if an EXE or DLL file has a manifest that explicitly enables theme support. If Windows cannot find this manifest, the process is only shown with the regular window design.</p>
<p><span id="more-47"></span></p>
<p><img src="http://blog.delphi-jedi.net/wp-content/uploads/2008/03/bild-9-1-small.jpg" alt="Bild" height="168" width="225" /><img src="http://blog.delphi-jedi.net/wp-content/uploads/2008/03/bild-12-small.jpg" alt="Bild" height="168" width="225" /></p>
<p>However the Vista elevation is done by creating a COM object and offers its methods through a seperate process. A seperate process is necessary because the same process cannot get assigned the ncessary administrator token. In our case a service in the service container svchost.exe has the task to host the COM object. The contained service is called dllhost.exe (service name: &#8220;COMSysApp&#8221;) and does not run until requested. It does not matter whether the service is deactivated or not because it is started directly by svchost.</p>
<p><a href="http://blog.delphi-jedi.net/wp-content/uploads/2008/03/bild-6.jpg" rel="lightbox[47]" title="Why aren't dialogs themed in elevated COM methods."><img src="http://blog.delphi-jedi.net/wp-content/uploads/2008/03/bild-6-small.jpg" alt="Bild" height="100" width="450" /></a></p>
<p>The COM method and the dialog will run in the process space of the newly elevated dllhost.exe. And because there is no manifest information in this file you cannot get a themed dialog layout.</p>
<p><img src="http://blog.delphi-jedi.net/wp-content/uploads/2008/03/bild-7.jpg" alt="Bild" height="105" width="215" /></p>
<p>So how can you get a themed dialog anyhow?</p>
<p>The task is done by using the basic principles of COM. COM knowns Callback interfaces and other stuff. By using a Callback interface you can turn around the server &#8211; client principle.</p>
<ol>
<li>Define a well known interface that is implemented by the client only. But also known to the server.</li>
<li>Add a parameter to your elevated COM method that receives a pointer to this interface.</li>
<li>Before calling an elevated method, create the interface and</li>
<li>apply a pointer to the method&#8217;s parameter you added.</li>
<li>Call the method and use the methods in the given callback interface. COM will automatically transfer the method calls to your non-elevated process. In this way you can create themed windows, do window management stuff (progress bar) and eventually close the window.</li>
</ol>
<p>If you prefer to read code instead of text you should study this code excerpts.</p>
<p>Define a callback interface for your client and add it to the server&#8217;s TypeLib. Delphi will generate code for it automatically in a file called &lt;Name&gt;_TLB.pas (TLB Header). Do not create the interface by using the Delphi&#8217;s ActiveX expert. Just add it manually.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">type</span><br />
&nbsp; IMyCallback = <span class="kw1">interface</span><span class="br0">&#40;</span><span class="kw4">IUnknown</span><span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#91;</span>MYCALLBACK_GUID<span class="br0">&#93;</span><br />
&nbsp; &nbsp; <span class="kw1">procedure</span> ACallBackMethod<span class="br0">&#40;</span>DataFromServer : &#8230;<span class="br0">&#41;</span>; <span class="kw1">safecall</span>;<br />
&nbsp; <span class="kw1">end</span>;<br />
&nbsp;<span class="co1">//We do not need a CoClass</span></div>
<p><em>IMyCallback </em>interface is known to both the server and the client, because we use the TLB Header in the client and the server. The client will implement and the server will receive a pointer to it and then call the included method <em>ACallBackMethod</em> everytime it wishes to do so.</p>
<p>The server implements a method to allow a callback interface to be passed to it.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">type</span><br />
&nbsp; IServerInt = <span class="kw1">interface</span><span class="br0">&#40;</span>IDispatch<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#91;</span>ISERVERINT_GUID<span class="br0">&#93;</span><br />
&nbsp; &nbsp; <span class="kw1">procedure</span> DoStuffThatNeedsCallBack<span class="br0">&#40;</span><span class="kw1">const</span> Callback: IMyCallback;&#8230;<span class="br0">&#41;</span> <span class="kw1">safecall</span>;<br />
&nbsp; <span class="kw1">end</span>;<br />
&nbsp; <span class="co1">//TypeLib editor also declares a CoClass called CoServerInt</span></div>
<p>Of course you have to implement both interfaces: <em>IServerInt</em> and <em>IMyCallback</em>. However <em>IServerInt </em>is implemented on server side and <em>IMyCallback </em>is only implemented on the client side.</p>
<p>On client side (namely your application) write..</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">uses</span> &#8230;, ComSrv,ComObj;<br />
<span class="kw1">type</span><br />
&nbsp; TMyCallback = <span class="kw1">class</span><span class="br0">&#40;</span>TComObject, IMyCallback<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">procedure</span> ACallBackMethod<span class="br0">&#40;</span>DataFromServer : &#8230;<span class="br0">&#41;</span>; <span class="kw1">safecall</span>;<br />
&nbsp; <span class="kw1">end</span>;</p>
<p>&#8230;</p></div>
<p>Install the COM object anywhere before you&#8217;re going to use it.</p>
<div class="dean_ch" style="white-space: wrap;"> &nbsp;TComObjectFactory.<span class="me1">Create</span><span class="br0">&#40;</span>ComServer,<br />
&nbsp; &nbsp; &nbsp;TMyCallback, Class_MyCallback,<br />
&nbsp; &nbsp; &nbsp;<span class="st0">&#8216;MyCallback&#8217;</span>, <span class="co1">//Classname</span><br />
&nbsp; &nbsp; &nbsp;<span class="st0">&#8216;Description here&#8217;</span>,<br />
&nbsp; &nbsp; &nbsp;ciMultiInstance<span class="br0">&#41;</span>;</div>
<p>After all implement the callback method&#8230;</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">procedure</span> TMyCallback.<span class="me1">ACallBackMethod</span><span class="br0">&#40;</span>DataFromServer : &#8230;<span class="br0">&#41;</span>;<br />
<span class="kw1">begin</span><br />
&nbsp; <span class="co1">//do stuff on the non-elevated client side</span><br />
<span class="kw1">end</span>;</div>
<p>&#8230;and anywhere you like, call the method to use our Callback interface.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">var</span> Server : IServerInt;<br />
&nbsp; &nbsp; Callback : IMyCallback;<br />
<span class="kw1">begin</span><br />
&nbsp; Server := CoServerInt.<span class="me1">Create</span>;<br />
&nbsp; Callback := TMyCallback.<span class="me1">Create</span> <span class="kw1">as</span> IMyCallback;</p>
<p>&nbsp; Server.<span class="me1">DoStuffThatNeedsCallBack</span><span class="br0">&#40;</span>Callback, &#8230;<span class="br0">&#41;</span>;<br />
<span class="kw1">end</span>;</div>
<p>I&#8217;m using TComObject and TComObjectFactory on the client side , because this way works for  console applications, too. If you need the possibilities of TAutoIntfObject, you will have to write a standalone COM server with TApplication. However this is not necessary here.  The method ACallBackMethod will be run in the client&#8217;s process space rather than the elevated helper process. You can check whether the callback method runs in the correct process (elevated or not?) with the following code.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">procedure</span> TMyCallback.<span class="me1">ACallBackMethod</span><span class="br0">&#40;</span>DataFromServer : &#8230;<span class="br0">&#41;</span>;<br />
<span class="kw1">var</span> Token : TJwSecurityToken;<br />
<span class="kw1">begin</span><br />
&nbsp; &nbsp;Token := TJwSecurityToken.<span class="me1">CreateTokenEffective</span><span class="br0">&#40;</span>TOKEN_QUERY <span class="kw1">or</span> TOKEN_READ<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="kw1">try</span><br />
&nbsp; &nbsp; &nbsp;<span class="kw1">if</span> Token.<span class="me1">RunElevation</span> = <span class="nu0">0</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;ShowMessage<span class="br0">&#40;</span><span class="st0">&#8216;Process is NOT Elevated: &#8216;</span>+<span class="kw3">IntToStr</span><span class="br0">&#40;</span>GetCurrentProcessId<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;ShowMessage<span class="br0">&#40;</span><span class="st0">&#8216;Process is Elevated: &#8216;</span>+<span class="kw3">IntToStr</span><span class="br0">&#40;</span>GetCurrentProcessId<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="kw1">finally</span><br />
&nbsp; &nbsp; &nbsp;Token.<span class="me1">Free</span>;<br />
&nbsp; &nbsp;<span class="kw1">end</span>;<br />
<span class="kw1">end</span>;</div>
<p><u>Second way, still on the client side:</u><br />
If you already have a form class, you can add the interface to it.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">type</span><br />
&nbsp; TForm1 = <span class="kw1">class</span><span class="br0">&#40;</span>TForm, IMyCallback<span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">protected</span><br />
&nbsp; &nbsp; <span class="kw1">procedure</span> ACallBackMethod<span class="br0">&#40;</span>DataFromServer : &#8230;<span class="br0">&#41;</span>; <span class="kw1">safecall</span>;<br />
&nbsp; <span class="kw1">end</span>;</div>
<p>Instead of creating the COM object, you pass a self-pointer to the method parameter.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">procedure</span> TForm1.<span class="me1">OnButtonClick</span><span class="br0">&#40;</span>&#8230;<span class="br0">&#41;</span>;<br />
<span class="kw1">var</span> Server : IServerInt;<br />
&nbsp; &nbsp; Callback : IMyCallback;<br />
<span class="kw1">begin</span><br />
&nbsp; Server := CoServerInt.<span class="me1">Create</span>;</p>
<p>&nbsp; Server.<span class="me1">DoStuffThatNeedsCallBack</span><span class="br0">&#40;</span><span class="kw2">Self</span>, &#8230;<span class="br0">&#41;</span>;<br />
<span class="kw1">end</span>;</div>
<p>Be aware that in a multi thread environment, you have to make sure that resources in that specific form are accessed only by one thread at a time.</p>
<p>Eventually the server side calls the methods within the callback interface:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">uses</span> &#8230;, ComSrv,ComObj; </p>
<p><span class="kw1">type</span><br />
&nbsp; TServerIntImpl = <span class="kw1">class</span><span class="br0">&#40;</span>TAutoObject, IServerInt<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">procedure</span> DoStuffThatNeedsCallBack<span class="br0">&#40;</span><span class="kw1">const</span> Callback: IMyCallback;&#8230;<span class="br0">&#41;</span> <span class="kw1">safecall</span>;<br />
&nbsp; <span class="kw1">end</span>;</p>
<p>&#8230;<br />
<span class="kw1">procedure</span> TServerIntImpl.<span class="me1">DoStuffThatNeedsCallBack</span><span class="br0">&#40;</span><span class="kw1">const</span> Callback: IMyCallback;&#8230;<span class="br0">&#41;</span><br />
<span class="kw1">begin</span><br />
&nbsp; &#8230;<br />
&nbsp; <span class="me1">Callback</span>.<span class="me1">ACallBackMethod</span><span class="br0">&#40;</span>&#8230;<span class="br0">&#41;</span>;<br />
<span class="kw1">end</span>;</p>
<p>&#8230;<br />
<span class="kw1">initialization</span><br />
&nbsp; TAutoObjectFactory.<span class="me1">Create</span><span class="br0">&#40;</span>ComServer, TMyCallback,<br />
&nbsp; &nbsp; &nbsp;Class_MyCallback, ciMultiInstance<span class="br0">&#41;</span>;</div>
<p>The callback method will be called in the context of the client. So it will not be elevated. This is because there is no ordinary method call here. COM will pack the function stack and all its parameter into a stream, send it to the client, unpack it and restore a proper function stack to be executed. This happens in the client process of course.<br />
Get more information about COM callbacks <a href="http://www.informit.com/articles/article.aspx?p=130494&amp;seqNum=5" title="Go to external link.">here</a>.</p>
<hr size="2" width="100%" />Aside from the themed dialog problem you never should show window elements in such an elevated method. There is no need to it. All window elements can be displayed by using standard user rights. They do not need Administrator rights; otherwise we had to logon as Administrator.<br />
However you only should do stuff that needs Administrator privileges in these COM methods. The more code you add to the method the more likely a bug may lead to a security risk. So simply call your function that needs Administrator rights, get the results and go back to Standard user rights. There is really no need to display a window with Administrator privilege.<br />
<hr size="2" width="100%" /><strong>Tell me how you liked this blog entry by adding a comment.</strong></p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2008/03/14/why-arent-dialogs-themed-in-elevated-com-methods/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
