<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>32bit</title>
        <link>http://geekswithblogs.net/khanna/category/705.aspx</link>
        <description>32bit</description>
        <language>en-US</language>
        <copyright>Gaurav Khanna</copyright>
        <managingEditor>gaurav@wintoolzone.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>[Article] Authoring a Stack Walker for X86</title>
            <link>http://geekswithblogs.net/khanna/archive/2008/01/07/article-authoring-a-stack-walker-for-x86.aspx</link>
            <description>&lt;p&gt;&lt;font face="Calibri" size="3"&gt;Stack walking is second nature to debuggers. But if you had more interest in it than just debugging and either:&lt;/font&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;font face="Calibri" size="3"&gt;wanted to know what stack walking is about, or&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font face="Calibri" size="3"&gt;wanted to know how stack walking is implemented, or&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font face="Calibri" size="3"&gt;wanted to know how a custom stack walker can be authored for your application&lt;/font&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font face="Calibri" size="3"&gt;then you might find the article, &lt;strong&gt;Authoring a Stack Walker for X86, &lt;/strong&gt;useful. Its my attempt to help clarify the basics of stack walking and explain key concepts and show how it can be implemented on x86 platform. The article can be read &lt;/font&gt;&lt;a href="http://www.wintoolzone.com/PermaLink.aspx?ID=141" target="_blank"&gt;&lt;font face="Calibri" size="3"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font face="Calibri" size="3"&gt; and its accompanying stack walker implementation source code can be downloaded from &lt;/font&gt;&lt;a href="http://www.wintoolzone.com/Permalink.aspx?ID=140" target="_blank"&gt;&lt;font face="Calibri" size="3"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font face="Calibri" size="3"&gt;.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Calibri" size="3"&gt;Below is an output from the stack walker implementation discussed in the article:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;img src="http://www.wintoolzone.com/images/stackwalker_ss.jpg" /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118317"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118317" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/khanna/aggbug/118317.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Khanna</dc:creator>
            <guid>http://geekswithblogs.net/khanna/archive/2008/01/07/article-authoring-a-stack-walker-for-x86.aspx</guid>
            <pubDate>Mon, 07 Jan 2008 12:48:58 GMT</pubDate>
            <comments>http://geekswithblogs.net/khanna/archive/2008/01/07/article-authoring-a-stack-walker-for-x86.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/khanna/comments/commentRss/118317.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/khanna/services/trackbacks/118317.aspx</trackback:ping>
        </item>
        <item>
            <title>Advanced Windows Debugging</title>
            <link>http://geekswithblogs.net/khanna/archive/2007/12/22/advanced-windows-debugging.aspx</link>
            <description>&lt;p&gt;The book is a &lt;u&gt;&lt;strong&gt;&lt;a href="http://www.amazon.com/Advanced-Debugging-Addison-Wesley-Microsoft-Technology/dp/0321374460/ref=pd_bbs_sr_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1198357122&amp;amp;sr=8-1" target="_blank"&gt;must have&lt;/a&gt;&lt;/strong&gt;&lt;/u&gt; for every serious Windows developer!&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117934"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117934" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/khanna/aggbug/117934.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Khanna</dc:creator>
            <guid>http://geekswithblogs.net/khanna/archive/2007/12/22/advanced-windows-debugging.aspx</guid>
            <pubDate>Sun, 23 Dec 2007 05:00:21 GMT</pubDate>
            <comments>http://geekswithblogs.net/khanna/archive/2007/12/22/advanced-windows-debugging.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/khanna/comments/commentRss/117934.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/khanna/services/trackbacks/117934.aspx</trackback:ping>
        </item>
        <item>
            <title>Lessons in Exception Handling</title>
            <link>http://geekswithblogs.net/khanna/archive/2007/05/13/Lessons-in-Exception-Handling.aspx</link>
            <description>&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;Working on the CLR's exception handling subsystem is not just challenging but also gives unique opportunities to understand how the various exception handling subsystems (e.g. SEH, C++ EH, etc) work, and in particular, how they interoperate with one another. It was such case that had me discuss one such issue with &lt;/font&gt;&lt;a href="http://blogs.msdn.com/freik/" target="_blank"&gt;&lt;font size="2"&gt;Kevin&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;, development lead of the JIT, that he mentions &lt;/font&gt;&lt;a href="http://blogs.msdn.com/freik/archive/2007/03/15/how-to-use-rtlunwindex.aspx" target="_blank"&gt;&lt;font size="2"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;That discussion got me exploring the interoperability aspects of EH further and resulted in the bullets listed below. Incase you are interested, download the PDF version of this article from &lt;/font&gt;&lt;a href="http://www.wintoolzone.com/articles/Lessons_in_EH.aspx" target="_blank"&gt;&lt;font size="2"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; and the accompanying source code from &lt;/font&gt;&lt;a href="http://www.wintoolzone.com/ListWin32.aspx?Listtype=5" target="_blank"&gt;&lt;font size="2"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;. For those uninitiated to exception handling, Matt Pietrek's &lt;strong&gt;must&lt;/strong&gt; read article is &lt;/font&gt;&lt;a href="http://www.microsoft.com/msj/0197/exception/exception.aspx" target="_blank"&gt;&lt;font size="2"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;Now, onto the interoperability aspects of EH.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;i&gt;&lt;font size="2"&gt;Note: the following discussion is in context of the x86 platform&lt;/font&gt;&lt;/i&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;b&gt;&lt;font size="2"&gt;Catching an exception using __try/__except SEH handler will result in &lt;i&gt;RtlUnwind&lt;/i&gt; being called without exception record&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;i&gt;&lt;br /&gt;&lt;font size="2"&gt;Structured Exception Handling (SEH) &lt;/font&gt;&lt;/i&gt;&lt;font size="2"&gt;is built into the Windows OS and it is how the OS processes the exceptions. Compilers offer their own specific ways of setting up a &lt;i&gt;SEH handler. &lt;/i&gt;To setup one using Microsoft Visual C++, we use &lt;i&gt;__try/__except &lt;/i&gt;keywords. For example: &lt;br /&gt;&lt;br /&gt;&lt;/font&gt; &lt;p&gt;__try&lt;br /&gt;{ &lt;br /&gt;&lt;span style="color: #0000ff"&gt;printf&lt;/span&gt;("&lt;span style="color: #8b0000"&gt;Calling the /EHSc function\n&lt;/span&gt;"); &lt;br /&gt;InvokeCPPFunction(); &lt;br /&gt;} &lt;br /&gt;__except (IsForUs(GetExceptionInformation())) &lt;br /&gt;{ &lt;br /&gt;&lt;span style="color: #0000ff"&gt;printf&lt;/span&gt;("&lt;span style="color: #8b0000"&gt;In __except\n&lt;/span&gt;"); &lt;br /&gt;} &lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;If the &lt;i&gt;InvokeCPPFunction &lt;/i&gt;throws an exception, the OS will invoke the &lt;i&gt;filter function &lt;/i&gt;(the &lt;i&gt;IsForUs &lt;/i&gt;function referenced in the braces of __&lt;i&gt;except&lt;/i&gt;) and check its return value. The filter function can be passed exception details that can be retrieved using the &lt;i&gt;GetExceptionInformation &lt;/i&gt;function and using that information, it can decide whether it wants to process the exception or not. &lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;If the filter function returns &lt;a href="http://msdn2.microsoft.com/en-us/library/6wxdsc38(vs.80).aspx" target="_blank"&gt;EXCEPTION_CONTINUE_EXECUTION&lt;/a&gt;, the OS retries the instruction that created the exception. However, if the return value is &lt;a href="http://msdn2.microsoft.com/en-us/library/6wxdsc38(vs.80).aspx" target="_blank"&gt;EXCEPTION_CONTINUE_SEARCH&lt;/a&gt;, it tells the OS that the filter function has declined to process the exception and the OS continues its search for the handler in the &lt;i&gt;SEH handler chain &lt;/i&gt;(that is available from &lt;i&gt;FS:0 &lt;/i&gt;on x86 machines for each OS thread). &lt;/font&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font size="2"&gt;The filter function can also return &lt;a href="http://msdn2.microsoft.com/en-us/library/6wxdsc38(vs.80).aspx" target="_blank"&gt;EXCEPTION_EXECUTE_HANDLER&lt;/a&gt; to tell the OS that it wants to handle the exception and the OS proceeds to invoke the &lt;i&gt;funclet &lt;/i&gt;within the &lt;i&gt;__except &lt;/i&gt;block. But before invoking the &lt;i&gt;funclet, the OS &lt;/i&gt;has to unwind&lt;i&gt; &lt;/i&gt;the call stack. On x86, the code generated by VC++ compiler does this by invoking &lt;i&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms680609.aspx" target="_blank"&gt;RtlUnwind&lt;/a&gt; &lt;/i&gt;API, with &lt;i&gt;NULL &lt;/i&gt;for the third argument - this argument is a pointer to the exception record for the exception being processed. This is done by the compiler by invoking &lt;i&gt;GlobalUnwind &lt;/i&gt;(an internal function) after doing some processing. &lt;i&gt;GlobalUnwind &lt;/i&gt;makes the call to &lt;i&gt;RtlUnwind &lt;/i&gt;as shown below: &lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;@_EH4_GlobalUnwind@4: &lt;/em&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;70508FB2 push ebp &lt;/em&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;70508FB3 mov ebp,esp &lt;/em&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;70508FB5 push ebx &lt;/em&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;70508FB6 push esi &lt;/em&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;70508FB7 push edi &lt;/em&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;70508FB8 push 0 &lt;/em&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;font size="2"&gt;&lt;em&gt;&lt;font color="#ff0000"&gt;70508FBA push 0&lt;/font&gt; &lt;/em&gt;&lt;/font&gt;&lt;/b&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;70508FBC push offset ReturnPoint (70508FC7h) &lt;/em&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;70508FC1 push ecx &lt;/em&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;70508FC2 call RtlUnwind (70526620h)&lt;/em&gt; &lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;The highlighted &lt;font color="#ff0000"&gt;&lt;strong&gt;red&lt;/strong&gt;&lt;/font&gt; line is the one where NULL is pushed for exception record. &lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;What this implies that all &lt;i&gt;SEH handlers &lt;/i&gt;that are in the x86 FS:0 chain&lt;i&gt;, &lt;/i&gt;prior to the one that agreed to process the exception, will be called by the OS once again to give them a chance to do some cleanup (e.g. release resources) – this is typically known as &lt;i&gt;unwinding &lt;/i&gt;of the stack. And since the unwind was initiated with a NULL for the exception record, if your &lt;i&gt;SEH handler &lt;/i&gt;relies on checking the exception record for details before deciding to do the cleanup, it can potentially fail (e.g. not end up doing the cleanup)! &lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;ul&gt; &lt;li&gt;&lt;font size="2"&gt;&lt;b&gt;Corollary Lesson: Don’t throw (and expect to catch &lt;i&gt;correctly&lt;/i&gt;) exception across environment boundaries. E.g. throwing a C++ exception and trying to catch it using a SEH handler&lt;br /&gt;&lt;br /&gt;&lt;/b&gt;Since a C++ application can have a mix of both C++ exception handling constructs and SEH exception handing constructs, it is easy to commit the mistake of writing code that throws an exception from C++ EH and excepts that to be &lt;i&gt;correctly &lt;/i&gt;caught and processed in SEH EH constructs – the focus is on correct processing. &lt;br /&gt;&lt;br /&gt;Let’s extend the previous example. Assume that &lt;i&gt;InvokeCPPFunction &lt;/i&gt;is a function in a DLL that was compiled to use C++ EH (using the &lt;i&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/1deeycx5(VS.80).aspx" target="_blank"&gt;/EHSc&lt;/a&gt; &lt;/i&gt;switch) and implemented as shown below:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CPPClass2 &lt;br /&gt;{ &lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt;: &lt;br /&gt;CPPClass2() &lt;br /&gt;{ &lt;br /&gt;printf("&lt;span style="color: #8b0000"&gt;CPPClass2 constructor\n&lt;/span&gt;"); &lt;br /&gt;} &lt;br /&gt;~CPPClass2() &lt;br /&gt;{ &lt;br /&gt;printf("&lt;span style="color: #8b0000"&gt;CPPClass2 destructor\n&lt;/span&gt;"); &lt;br /&gt;} &lt;br /&gt;}; &lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CPPClass &lt;br /&gt;{ &lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt;: &lt;br /&gt;CPPClass() &lt;br /&gt;{ &lt;br /&gt;printf("&lt;span style="color: #8b0000"&gt;CPPClass constructor\n&lt;/span&gt;"); &lt;br /&gt;} &lt;br /&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ThrowException() &lt;br /&gt;{ &lt;br /&gt;CPPClass2 cpp2; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; 1; &lt;br /&gt;} &lt;br /&gt;~CPPClass() &lt;br /&gt;{ &lt;br /&gt;printf("&lt;span style="color: #8b0000"&gt;CPPClass destructor\n&lt;/span&gt;"); &lt;br /&gt;} &lt;br /&gt;}; &lt;br /&gt;&lt;br /&gt;__declspec (dllexport) &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InvokeCPPFunction() &lt;br /&gt;{ &lt;br /&gt;CPPClass cpp; &lt;br /&gt;cpp.ThrowException(); &lt;br /&gt;}&lt;br /&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;&lt;/b&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font size="2"&gt;We have two classes, &lt;i&gt;CPPClass &amp;amp; CPPClass2 &lt;/i&gt;that have destructors each. &lt;i&gt;InvokeCPPFunction &lt;/i&gt;instantiates &lt;i&gt;CPPClass &lt;/i&gt;object, &lt;i&gt;cpp, &lt;/i&gt;and invokes the &lt;i&gt;ThrowException &lt;/i&gt;method, which in turn, instantiates &lt;i&gt;CPPClass2 &lt;/i&gt;object, &lt;i&gt;cpp2, &lt;/i&gt;and throws an exception. &lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;As per the C++ semantics, when this exception is caught, the destructors should be invoked as they are expected to do the cleanup for the respective class instance. However, &lt;i&gt;this depends upon who catches the exception. &lt;/i&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;In our previous example, &lt;i&gt;InvokeCPPFunction &lt;/i&gt;was invoked from within &lt;i&gt;__try/__except &lt;/i&gt;SEH mechanism. Hence, when &lt;i&gt;ThrowException &lt;/i&gt;throws an exception, the OS walks the &lt;i&gt;FS:0 &lt;/i&gt;chain to look for a handler that will handle the exception. When the OS comes to our &lt;i&gt;__except &lt;/i&gt;block, if the filter &lt;i&gt;funclet &lt;/i&gt;returns EXECEPTION_EXECUTE_HANDLER, as per our last discussion, &lt;i&gt;RtlUnwind &lt;/i&gt;is invoked with a NULL for the exception record pointer. &lt;/font&gt; &lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;When this happens and the unwind call comes to C++ exception handler, the &lt;i&gt;C++ EH does not process the unwind since the exception record is NULL&lt;/i&gt;. This is because C++ EH only processes the unwind when the exception code in the exception record has the C++ exception code (0Xe06d7363). Thus, &lt;i&gt;no destructors are invoked&lt;/i&gt; and that is not something you want. Below is the output this example: &lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://www.wintoolzone.com/images/f060de3d24ca_144A7/clip_image0026.jpg" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="313" src="http://www.wintoolzone.com/images/f060de3d24ca_144A7/clip_image002_thumb1.jpg" width="623" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;Hence, it’s important to catch the exception in the &lt;i&gt;environment/EH-context &lt;/i&gt;it was thrown in, since that &lt;i&gt;EH-context &lt;/i&gt;will know how to process it correctly. &lt;/font&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:1828d01d-0707-4ea1-a8a6-673c0e5d61ee" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/Exception%20Handling" rel="tag"&gt;Exception Handling&lt;/a&gt;, &lt;a href="http://technorati.com/tags/RtlUnwind" rel="tag"&gt;RtlUnwind&lt;/a&gt;, &lt;a href="http://technorati.com/tags/RtlUnwindEx" rel="tag"&gt;RtlUnwindEx&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Structured%20Exception%20Handling" rel="tag"&gt;Structured Exception Handling&lt;/a&gt;, &lt;a href="http://technorati.com/tags/SEH" rel="tag"&gt;SEH&lt;/a&gt;, &lt;a href="http://technorati.com/tags/C++%20Exception%20Handling" rel="tag"&gt;C++ Exception Handling&lt;/a&gt;, &lt;a href="http://technorati.com/tags/FS:[0]" rel="tag"&gt;FS:[0]&lt;/a&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=113751"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=113751" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/khanna/aggbug/113751.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Khanna</dc:creator>
            <guid>http://geekswithblogs.net/khanna/archive/2007/05/13/Lessons-in-Exception-Handling.aspx</guid>
            <pubDate>Sun, 13 May 2007 23:50:29 GMT</pubDate>
            <comments>http://geekswithblogs.net/khanna/archive/2007/05/13/Lessons-in-Exception-Handling.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/khanna/comments/commentRss/113751.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/khanna/services/trackbacks/113751.aspx</trackback:ping>
        </item>
        <item>
            <title>Adding process enumeration support in Rotor v1.0</title>
            <link>http://geekswithblogs.net/khanna/archive/2006/01/05/64897.aspx</link>
            <description>
&lt;div&gt;&lt;font face="Tahoma" color="darkgoldenrod" size="2"&gt;&lt;strong&gt;[Original Post Date: 
5th September 2005]&lt;/strong&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;a href="http://msdn.microsoft.com/net/sscli"&gt;&lt;font face="Tahoma" size="2"&gt;Share Source CLI&lt;/font&gt;&lt;/a&gt;&lt;font face="Tahoma" size="2"&gt;, better known as 
&lt;em&gt;Rotor&lt;/em&gt;, is one of the best ways to understand how .NET Framework works. 
And with the source code availability as part of &lt;em&gt;Rotor &lt;/em&gt;distribution, 
its an excellent academic/hobby interest - you can extend it by adding more 
functionality, or modify the existing one and see how it behaves.&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Tahoma" size="2"&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Tahoma" size="2"&gt;Yesterday, I went about doing the same. One of the 
functionality which I found missing in &lt;em&gt;Rotor &lt;/em&gt;is that of enumerating 
system process list. .NET Framework's &lt;em&gt;&lt;a href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessClassTopic.asp"&gt;System.Diagnostics.Process&lt;/a&gt;&amp;nbsp;&lt;/em&gt;class 
has methods, like &lt;em&gt;&lt;a href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdiagnosticsprocessclassgetprocessestopic.asp"&gt;GetProcesses&lt;/a&gt;, 
&lt;/em&gt;that allow you to do the same. &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Tahoma" size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;font face="Tahoma" size="2"&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Tahoma" size="2"&gt;So, I went about implementing &lt;em&gt;GetProcesses 
&lt;/em&gt;method overloads&lt;em&gt;&lt;/em&gt;in &lt;em&gt;System.Diagnostics.Process &lt;/em&gt;class that 
allow me to enumerate process list on the &lt;em&gt;local machine only. &lt;/em&gt;This 
required modification in the Platform Adaptation Layer (PAL) of &lt;em&gt;Rotor. 
&lt;/em&gt;Since, I just have it running on Win32 for the moment, I modified the Win32 
PAL to implement the support via &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/library/en-us/perfmon/base/taking_a_snapshot_and_viewing_processes.asp"&gt;&lt;font face="Tahoma" size="2"&gt;ToolHelp&lt;/font&gt;&lt;/a&gt;&lt;font face="Tahoma" size="2"&gt; API. Now, on a 
Windows system, its possible to enumerate the system process list using 
&lt;em&gt;Rotor&lt;/em&gt;, as exemplified by the snippet below:&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;
&lt;div&gt;&lt;font color="#000000"&gt;&lt;em&gt;&lt;font face="Tahoma"&gt;&lt;font size="2"&gt;using&lt;b&gt; 
System;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;
&lt;div&gt;&lt;em&gt;&lt;font face="Tahoma"&gt;&lt;font size="2"&gt;using&lt;b&gt; 
System.Diagnostics;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/em&gt;&lt;/div&gt;&lt;font color="#0000ff"&gt;
&lt;div&gt;&lt;font color="#000000"&gt;&lt;em&gt;&lt;font face="Tahoma"&gt;&lt;font size="2"&gt;public&lt;b&gt;&lt;/b&gt;class&lt;b&gt; EnumProcess&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Tahoma" color="#000000" size="2"&gt;&lt;em&gt;{&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 50px"&gt;&lt;font color="#000000"&gt;&lt;em&gt;&lt;font face="Tahoma"&gt;&lt;font size="2"&gt;public&lt;b&gt;&lt;/b&gt;static&lt;b&gt;&lt;/b&gt;void&lt;b&gt; 
Main()&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 50px"&gt;&lt;font face="Tahoma" color="#000000" size="2"&gt;&lt;em&gt;{&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 100px"&gt;&lt;font face="Tahoma" color="#000000" size="2"&gt;&lt;em&gt;Process[] arrProcess = Process.GetProcesses();&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 100px"&gt;&lt;font color="#000000"&gt;&lt;em&gt;&lt;font face="Tahoma"&gt;&lt;font size="2"&gt;if&lt;strong&gt; (&lt;/strong&gt;arrProcess &lt;strong&gt;== 
&lt;/strong&gt;null&lt;b&gt;)&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 100px"&gt;&lt;font face="Tahoma" color="#000000" size="2"&gt;&lt;em&gt;{&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 150px"&gt;&lt;font color="#000000"&gt;&lt;em&gt;&lt;font face="Tahoma"&gt;&lt;font size="2"&gt;Console.WriteLine("Unable to get process 
list!"&lt;b&gt;);&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 150px"&gt;&lt;font color="#000000"&gt;&lt;em&gt;&lt;font face="Tahoma"&gt;&lt;font size="2"&gt;return&lt;b&gt;;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 100px"&gt;&lt;font color="#000000"&gt;&lt;em&gt;&lt;font face="Tahoma" size="2"&gt;}&lt;br&gt;Console.WriteLine("{0} processes 
enumerated.",arrProcess.Length);&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 100px"&gt;&lt;font color="#000000"&gt;&lt;em&gt;&lt;font face="Tahoma" size="2"&gt;foreach (Process proc in arrProcess)&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 150px"&gt;&lt;font color="#000000"&gt;&lt;em&gt;&lt;font face="Tahoma" size="2"&gt;Console.WriteLine("Process ID {0}, Handle: {1}", proc.Id, 
proc.Handle);&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div style="PADDING-LEFT: 50px"&gt;&lt;font face="Tahoma" color="#000000" size="2"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Tahoma" color="#000000" size="2"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Tahoma" size="2"&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#000000"&gt;&lt;font face="Tahoma" size="2"&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;font color="#000000"&gt;&lt;font face="Tahoma" size="2"&gt;You can download the updated 
source files for &lt;em&gt;Rotor v1.0 &lt;/em&gt;from &lt;/font&gt;&lt;a href="http://www.wintoolzone.com/showpage.aspx?url=rotor.aspx"&gt;&lt;font face="Tahoma" size="2"&gt;http://www.wintoolzone.com/showpage.aspx?url=rotor.aspx&lt;/font&gt;&lt;/a&gt;&lt;font face="Tahoma" size="2"&gt;. The zipped archive contains &lt;em&gt;Changes for Process 
Enumeration.txt &lt;/em&gt;that indicates where the updated files need to be copied. 
Once done, rebuild &lt;em&gt;Rotor &lt;/em&gt;to get the changes into 
effect.&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Tahoma" size="2"&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Tahoma" size="2"&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div id="CSBloggerSig"&gt;&lt;font face="Tahoma" size="2"&gt;&lt;/font&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=64897"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=64897" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/khanna/aggbug/64897.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Khanna</dc:creator>
            <guid>http://geekswithblogs.net/khanna/archive/2006/01/05/64897.aspx</guid>
            <pubDate>Thu, 05 Jan 2006 17:44:00 GMT</pubDate>
            <comments>http://geekswithblogs.net/khanna/archive/2006/01/05/64897.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/khanna/comments/commentRss/64897.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/khanna/services/trackbacks/64897.aspx</trackback:ping>
        </item>
        <item>
            <title>Shared Source Bluetooth Library</title>
            <link>http://geekswithblogs.net/khanna/archive/2005/05/26/40624.aspx</link>
            <description>&lt;P&gt;Check out the shared source &lt;STRONG&gt;Bluetooth class library&lt;/STRONG&gt; - &lt;A href="http://msdn.microsoft.com/embedded/usewinemb/ce/sharedsrccode/west/default.aspx"&gt;Windows Embedded Source Tools for Bluetooth&lt;/A&gt;&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=40624"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=40624" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/khanna/aggbug/40624.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Khanna</dc:creator>
            <guid>http://geekswithblogs.net/khanna/archive/2005/05/26/40624.aspx</guid>
            <pubDate>Fri, 27 May 2005 02:47:00 GMT</pubDate>
            <comments>http://geekswithblogs.net/khanna/archive/2005/05/26/40624.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/khanna/comments/commentRss/40624.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/khanna/services/trackbacks/40624.aspx</trackback:ping>
        </item>
        <item>
            <title>Win32 API -&gt; .NET Framework Mapping</title>
            <link>http://geekswithblogs.net/khanna/archive/2005/03/01/24619.aspx</link>
            <description>&lt;P&gt;Do you want to know which Win32 API maps to what part of the .NET Framework? If yes, visit &lt;A href="http://msdn.microsoft.com/netframework/programming/interop/default.aspx?pull=/library/en-us/dndotnet/html/win32map.asp"&gt;http://msdn.microsoft.com/netframework/programming/interop/default.aspx?pull=/library/en-us/dndotnet/html/win32map.asp&lt;/A&gt;&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=24619"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=24619" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/khanna/aggbug/24619.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Khanna</dc:creator>
            <guid>http://geekswithblogs.net/khanna/archive/2005/03/01/24619.aspx</guid>
            <pubDate>Wed, 02 Mar 2005 00:25:00 GMT</pubDate>
            <comments>http://geekswithblogs.net/khanna/archive/2005/03/01/24619.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/khanna/comments/commentRss/24619.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/khanna/services/trackbacks/24619.aspx</trackback:ping>
        </item>
        <item>
            <title>Managed code impersonation: CLR ThreadPool and more...</title>
            <link>http://geekswithblogs.net/khanna/archive/2005/02/09/22441.aspx</link>
            <description>&lt;FONT class=postText&gt;Under managed code, once you impersonate your application's thread using &lt;B&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthn/security/logonuser.asp" target=_blank&gt;LogonUser&lt;/A&gt;&lt;/B&gt; and &lt;B&gt;&lt;A href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemsecurityprincipalwindowsidentityclasstopic.asp" target=_blank&gt;WindowsIdentity&lt;/A&gt;&lt;/B&gt; class's &lt;B&gt;&lt;A href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemsecurityprincipalwindowsidentityclassimpersonatetopic.asp" target=_blank&gt;Impersonate&lt;/A&gt;&lt;/B&gt; method, you can go ahead and perform tasks using the &lt;I&gt;impersonated&lt;/I&gt; thread as you require. However, there are couple of catches to this:&lt;BR&gt;&lt;BR&gt;1) If you launch a process using &lt;B&gt;&lt;A href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdiagnosticsprocessclassstarttopic.asp" target=_blank&gt;Process.Start&lt;/A&gt;&lt;/B&gt; method, the launched process &lt;B&gt;will not&lt;/B&gt; execute under the impersonation context of your application. If you want to make that happen, you will have to launch the process using &lt;B&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocesswithlogonw.asp" target=_blank&gt;CreateProcessWithLogonW&lt;/A&gt;&lt;/B&gt; as I have discussed at &lt;B&gt;&lt;A href="http://geekswithblogs.net/khanna/archive/2005/02/09/22430.aspx" target=_blank&gt;http://geekswithblogs.net/khanna/archive/2005/02/09/22430.aspx&lt;/A&gt;&lt;/B&gt;.&lt;BR&gt;&lt;BR&gt;2) If, from the impersonated thread, you schedule some task to execute using &lt;B&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingthreadpoolclassqueueuserworkitemtopic1.asp" target=_blank&gt;QueueUserWorkItem&lt;/A&gt;&lt;/B&gt; of &lt;B&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemThreadingThreadPoolClassTopic.asp" target=_blank&gt;ThreadPool&lt;/A&gt;&lt;/B&gt; class, even the &lt;B&gt;ThreadPool&lt;/B&gt; threads &lt;B&gt;do not get the impersonated context&lt;/B&gt;, as shown below:&lt;BR&gt;&lt;BR&gt;&lt;IMG title="Before ThreadPool thread impersonation" src="http://www.wintoolzone.com/images/TPImpersonationBefore.JPG" border=0&gt;&lt;BR&gt;&lt;BR&gt;However, once the &lt;B&gt;ThreadPool&lt;/B&gt; thread is impersonated, results are as expected:&lt;BR&gt;&lt;BR&gt;&lt;IMG title="After ThreadPool thread impersonation" src="http://www.wintoolzone.com/images/TPImpersonationAfter.JPG" border=0&gt;&lt;BR&gt;&lt;BR&gt;Below is the snippet to accomplish this: &lt;PRE&gt;
&lt;FONT color=#0000ff size=2&gt;private &lt;FONT color=#0000ff size=2&gt;static&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; IntPtr LogUser(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; strUsername, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; strDomain, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; strPassword)
		{
			IntPtr tokenHandle = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; IntPtr(0);
			IntPtr dupeTokenHandle = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; IntPtr(0);

			&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; UserName, MachineName,passWord;
			&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;const &lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; LOGON32_PROVIDER_DEFAULT = 0;
			&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;//This parameter causes LogonUser to create a primary token.&lt;/FONT&gt;
&lt;FONT size=2&gt;			&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;const &lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; LOGON32_LOGON_INTERACTIVE = 2;
			&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;const &lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SecurityImpersonation = 2;

			tokenHandle = IntPtr.Zero;
			dupeTokenHandle = IntPtr.Zero;

			&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;// Call LogonUser to obtain a handle to an access token.&lt;/FONT&gt;
&lt;FONT size=2&gt;			&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;bool&lt;/FONT&gt;&lt;FONT size=2&gt; returnValue = LogonUser(strUsername, strDomain, strPassword, 
				LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
				&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; tokenHandle);

				
			&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;false&lt;/FONT&gt;&lt;FONT size=2&gt; == returnValue)
			{
				&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; ret = Marshal.GetLastWin32Error();
				&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;return&lt;/FONT&gt;&lt;FONT size=2&gt; IntPtr.Zero;
			}

			WindowsIdentity mWI1 = WindowsIdentity.GetCurrent();
			IntPtr token2 = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; IntPtr(tokenHandle.ToInt32());

			&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;return&lt;/FONT&gt;&lt;FONT size=2&gt; token2;
		}

		&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;/// &lt;FONT color=#808080 size=2&gt;&lt;SUMMARY&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;FONT size=2&gt;		&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;///&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt; The main entry point for the application.&lt;/FONT&gt;
&lt;FONT size=2&gt;		&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;/// &lt;FONT color=#808080 size=2&gt;&lt;/SUMMARY&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;FONT size=2&gt;		[STAThread]
		&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;static &lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; Main(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt;[] args)
		{
			&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;// show current principal..&lt;/FONT&gt;
&lt;FONT size=2&gt;			IIdentity curI = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;;
			curI = WindowsIdentity.GetCurrent();
			Console.WriteLine("Your current identity is {0}",curI.Name);
			
			&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;// Impersonate&lt;/FONT&gt;
&lt;FONT size=2&gt;			IntPtr token = LogUser("username","domain","password!");
			WindowsIdentity mWI2 = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; WindowsIdentity(token);
			WindowsPrincipal winPrin = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; WindowsPrincipal(mWI2);
			System.Threading.Thread.CurrentPrincipal = winPrin;
			WindowsImpersonationContext impersonatedUser = mWI2.Impersonate();

			curI = WindowsIdentity.GetCurrent();
			Console.WriteLine("After impersonation in the main thread, you are {0}",curI.Name);

			ThreadPool.QueueUserWorkItem(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; WaitCallback(callback));
			Console.ReadLine();
		}

		&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;static &lt;FONT color=#0000ff size=2&gt;void&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; callback(Object stateInfo) 
		{
			&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;// No state object was passed to QueueUserWorkItem, so &lt;/FONT&gt;
&lt;FONT size=2&gt;			&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;// stateInfo is null.&lt;/FONT&gt;
&lt;FONT size=2&gt;			Console.WriteLine("Hello from the thread pool.");

			IIdentity curI = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;;
			curI = WindowsIdentity.GetCurrent();
			Console.WriteLine("In ThreadPool Thread, you are {0}",curI.Name);

			IntPtr token = LogUser("username","domain","password!");
			WindowsIdentity mWI2 = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; WindowsIdentity(token);
			
			WindowsPrincipal winPrin = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; WindowsPrincipal(mWI2);
			System.Threading.Thread.CurrentPrincipal = winPrin;
			WindowsImpersonationContext impersonatedUser = mWI2.Impersonate();

			curI = WindowsIdentity.GetCurrent();
			Console.WriteLine("After impersonation, in ThreadPool Thread, you are {0}",curI.Name);
		}&lt;/FONT&gt;
&lt;/PRE&gt;&lt;/FONT&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=22441"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=22441" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/khanna/aggbug/22441.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Khanna</dc:creator>
            <guid>http://geekswithblogs.net/khanna/archive/2005/02/09/22441.aspx</guid>
            <pubDate>Wed, 09 Feb 2005 19:43:00 GMT</pubDate>
            <comments>http://geekswithblogs.net/khanna/archive/2005/02/09/22441.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/khanna/comments/commentRss/22441.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/khanna/services/trackbacks/22441.aspx</trackback:ping>
        </item>
        <item>
            <title>Managed CreateProcessWithLogonW</title>
            <link>http://geekswithblogs.net/khanna/archive/2005/02/09/22430.aspx</link>
            <description>&lt;font class="postText"&gt;I returned this past weekend after a family function. It had me very busy and thus, no blogging for sometime for me :)&lt;br&gt;&lt;br&gt;

That said, today I was working with one of my friends over email - she was stuck about getting to &lt;i&gt;launch a process in a specific user context&lt;/i&gt;, using managed code. Since the .NET Framework doesn't support such functionality out of the box, we tried different ways to do this:&lt;br&gt;&lt;br&gt;

1) &lt;b&gt;LogonUser&lt;/b&gt; followed by &lt;b&gt;WindowsIdentity&lt;/b&gt; impersonation using the obtained token - the token wasn't getting down to the spawned process even after we attempted &lt;b&gt;Impersonate&lt;/b&gt; method of &lt;b&gt;WindowsIdentity&lt;/b&gt;.&lt;br&gt;
2) &lt;b&gt;WMI&lt;/b&gt; also tried - it works but needs to be slightly modified when running on a local machine compared to a remote machine (we cannot specify credentials for local machine in the options).&lt;br&gt;&lt;br&gt;

Finally, we thought about working on &lt;b&gt;CreateProcessWithLogonW&lt;/b&gt;. It turned out to be rather simple and clean way of achieving our goal. For those who are interested, the following snippet uses &lt;b&gt;CreateProcessWithLogonW&lt;/b&gt; via PInvoke and launches a process under the specified user context:&lt;br&gt;&lt;br&gt;

The following are the &lt;b&gt;PInvoke&lt;/b&gt; declarations and data types required:

&lt;pre&gt;
&lt;font size=2&gt;
        [Flags]
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;enum&lt;/font&gt;&lt;font size=2&gt; LogonFlags 
	{
		LOGON_WITH_PROFILE         = 0x00000001,
		LOGON_NETCREDENTIALS_ONLY  = 0x00000002        
	}

	[Flags]
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;enum&lt;/font&gt;&lt;font size=2&gt; CreationFlags 
	{
		CREATE_SUSPENDED           = 0x00000004,
		CREATE_NEW_CONSOLE         = 0x00000010,
		CREATE_NEW_PROCESS_GROUP   = 0x00000200,
		CREATE_UNICODE_ENVIRONMENT = 0x00000400,
		CREATE_SEPARATE_WOW_VDM    = 0x00000800,
		CREATE_DEFAULT_ERROR_MODE  = 0x04000000,
	}

	[StructLayout(LayoutKind.Sequential)]
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;struct&lt;/font&gt;&lt;font size=2&gt; ProcessInfo 
	{
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public&lt;/font&gt;&lt;font size=2&gt; IntPtr hProcess; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public&lt;/font&gt;&lt;font size=2&gt; IntPtr hThread; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;uint&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt; dwProcessId; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;uint&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt; dwThreadId; 
	}

	[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;struct&lt;/font&gt;&lt;font size=2&gt; StartupInfo 
	{
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;int&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;     cb; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;  reserved1; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;  desktop; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;  title; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;uint&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;    dwX; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;uint&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;    dwY; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;uint&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;    dwXSize; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;uint&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;    dwYSize; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;uint&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;    dwXCountChars; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;uint&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;    dwYCountChars; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;uint&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;    dwFillAttribute; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;uint&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;    dwFlags; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;ushort&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;  wShowWindow; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;short&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;   reserved2; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public &lt;font color="#0000FF" size=2&gt;int&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;     reserved3; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public&lt;/font&gt;&lt;font size=2&gt; IntPtr  hStdInput; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public&lt;/font&gt;&lt;font size=2&gt; IntPtr  hStdOutput; 
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;public&lt;/font&gt;&lt;font size=2&gt; IntPtr  hStdError; 
	}

	[DllImport("advapi32.dll", CharSet=CharSet.Unicode, ExactSpelling=&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;true&lt;/font&gt;&lt;font size=2&gt;, SetLastError=&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;true&lt;/font&gt;&lt;font size=2&gt;)]
	&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;static &lt;font color="#0000FF" size=2&gt;extern &lt;font color="#0000FF" size=2&gt;bool&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt; CreateProcessWithLogonW(
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;string&lt;/font&gt;&lt;font size=2&gt; principal,
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;string&lt;/font&gt;&lt;font size=2&gt; authority,
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;string&lt;/font&gt;&lt;font size=2&gt; password,
		LogonFlags logonFlags,
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;string&lt;/font&gt;&lt;font size=2&gt; appName,
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;string&lt;/font&gt;&lt;font size=2&gt; cmdLine,
		CreationFlags creationFlags,
		IntPtr environmentBlock,
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;string&lt;/font&gt;&lt;font size=2&gt; currentDirectory,
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;ref&lt;/font&gt;&lt;font size=2&gt; StartupInfo startupInfo,
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;out&lt;/font&gt;&lt;font size=2&gt; ProcessInfo processInfo);

	[DllImport("kernel32.dll")]
	&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;static &lt;font color="#0000FF" size=2&gt;extern &lt;font color="#0000FF" size=2&gt;bool&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt; CloseHandle(IntPtr h);&lt;/font&gt;

&lt;/pre&gt;&lt;br&gt;&lt;br&gt;

The following is the code snippet that does the &lt;b&gt;PInvoke&lt;/b&gt; and spawns the process under a specific user context:

&lt;pre&gt;

&lt;font size=2&gt;                StartupInfo si = &lt;/font&gt;&lt;font color="#0000FF" size=2&gt;new&lt;/font&gt;&lt;font size=2&gt; StartupInfo();
		si.cb = Marshal.SizeOf(&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;typeof&lt;/font&gt;&lt;font size=2&gt;(StartupInfo));
		si.title = "This is impersonated command prompt";

		ProcessInfo pi = &lt;/font&gt;&lt;font color="#0000FF" size=2&gt;new&lt;/font&gt;&lt;font size=2&gt; ProcessInfo();
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;string&lt;/font&gt;&lt;font size=2&gt; app = Path.Combine(Environment.SystemDirectory, "cmd.exe");

			&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;if&lt;/font&gt;&lt;font size=2&gt; (CreateProcessWithLogonW("username", "domain", "password",
			LogonFlags.LOGON_WITH_PROFILE,
			app, &lt;/font&gt;&lt;font color="#0000FF" size=2&gt;null&lt;/font&gt;&lt;font size=2&gt;,
			0, IntPtr.Zero, &lt;/font&gt;&lt;font color="#0000FF" size=2&gt;null&lt;/font&gt;&lt;font size=2&gt;,
			&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;ref&lt;/font&gt;&lt;font size=2&gt; si, &lt;/font&gt;&lt;font color="#0000FF" size=2&gt;out&lt;/font&gt;&lt;font size=2&gt; pi)) 
		{
			CloseHandle(pi.hProcess);
			CloseHandle(pi.hThread);
		}
		&lt;/font&gt;&lt;font color="#0000FF" size=2&gt;else&lt;/font&gt;&lt;font size=2&gt; Console.WriteLine("Error code: {0}", Marshal.GetLastWin32Error());&lt;/font&gt;
&lt;/pre&gt;&lt;/font&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=22430"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=22430" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/khanna/aggbug/22430.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Khanna</dc:creator>
            <guid>http://geekswithblogs.net/khanna/archive/2005/02/09/22430.aspx</guid>
            <pubDate>Wed, 09 Feb 2005 17:38:00 GMT</pubDate>
            <comments>http://geekswithblogs.net/khanna/archive/2005/02/09/22430.aspx#feedback</comments>
            <slash:comments>6</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/khanna/comments/commentRss/22430.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/khanna/services/trackbacks/22430.aspx</trackback:ping>
        </item>
        <item>
            <title>ActiveSync aware - are you?</title>
            <link>http://geekswithblogs.net/khanna/archive/2004/12/14/17486.aspx</link>
            <description>&lt;font class="postText"&gt;Ever wondered how the &lt;b&gt;ActiveSync&lt;/b&gt; synchronization application gets launched automatically when you plug-in your SmartPhone or PocketPC? Or, would you like to build your application &lt;i&gt;&lt;b&gt;ActiveSync-aware&lt;/b&gt;&lt;/i&gt;, getting invoked when &lt;b&gt;ActiveSync&lt;/b&gt; connection has been established or disconnected?&lt;br&gt;&lt;br&gt;

On your desktop, under the following registry key, create an entry for the application to be launched when &lt;b&gt;ActiveSync&lt;/b&gt; connection has been established:&lt;br&gt;&lt;br&gt;

&lt;i&gt;HKEY_LOCAL_MACHINE\Software\Microsoft\Windows CE Services\AutoStartOnConnect&lt;/i&gt;&lt;br&gt;&lt;br&gt;

Likewise, to invoke an application when &lt;b&gt;ActiveSync&lt;/b&gt; connection is disrupted, create an entry under the following registry key:&lt;br&gt;&lt;br&gt;

&lt;i&gt;HKLM\Software\Microsoft\Windows CE Services\AutoStartOnDisconnect&lt;/i&gt;&lt;/font&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=17486"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=17486" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/khanna/aggbug/17486.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Khanna</dc:creator>
            <guid>http://geekswithblogs.net/khanna/archive/2004/12/14/17486.aspx</guid>
            <pubDate>Tue, 14 Dec 2004 15:36:00 GMT</pubDate>
            <comments>http://geekswithblogs.net/khanna/archive/2004/12/14/17486.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/khanna/comments/commentRss/17486.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/khanna/services/trackbacks/17486.aspx</trackback:ping>
        </item>
        <item>
            <title>Source Code - Windows CE File Manager</title>
            <link>http://geekswithblogs.net/khanna/archive/2004/12/13/17387.aspx</link>
            <description>&lt;font class="postText"&gt;As part of the recently concluded &lt;b&gt;Mobile and Embedded DevCon 2004&lt;/b&gt; at Bangalore, from 9th-11th Dec 2004, I delivered a talk on &lt;b&gt;Remote API (RAPI)&lt;/b&gt;, amongst other things. To demonstrate the tremendous power and capability of Windows CE RAPI (which allows us to managed CE based devices from the desktop), I wrote a &lt;b&gt;Windows CE File Manager&lt;/b&gt; - a Windows Explorer like application that can be used to navigate the CE device's file system and move files to/fro the device and your desktop and open them from the device directly.&lt;br&gt;&lt;br&gt;

For those interested in the source code of the application, it can be downloaded from the &lt;i&gt;Source Code&lt;/i&gt; section at the following URI:&lt;br&gt;&lt;br&gt;

&lt;b&gt;&lt;a href="http://www.wintoolzone.com/showpage.aspx?url=win32.aspx" target="_blank"&gt;http://www.wintoolzone.com/showpage.aspx?url=win32.aspx&lt;/a&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;

Its a VS.NET 2003 VC++ Solution.&lt;/font&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=17387"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=17387" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/khanna/aggbug/17387.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Khanna</dc:creator>
            <guid>http://geekswithblogs.net/khanna/archive/2004/12/13/17387.aspx</guid>
            <pubDate>Mon, 13 Dec 2004 22:27:00 GMT</pubDate>
            <comments>http://geekswithblogs.net/khanna/archive/2004/12/13/17387.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/khanna/comments/commentRss/17387.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/khanna/services/trackbacks/17387.aspx</trackback:ping>
        </item>
    </channel>
</rss>