<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Http Client Protocol Issues</title><link>http://blogs.msdn.com/jpsanders/default.aspx</link><description>If you use any of these solutions, Please let me know so I can track if any of this is useful to you!  Thanks!

This is an area to share observations I have made working with Http Client Protocols and the associated technologies.  I currently work for the Microsoft team that supports the WinInet, WinHTTP and System.Net API's and classes associated with these technologies.  This is not a replacement for Microsoft Support, but an area to discuss these technologies.  These postings are provided "AS IS" with no warranties, and confer no rights. Use of included code samples are subject to the terms specified at &lt;a href="http://www.microsoft.com/info/cpyright.htm"&gt;Microsoft - Information on Terms of Use&lt;/a&gt;</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How to iterate over contained controls to set a common event handler (Click) in .NET</title><link>http://blogs.msdn.com/jpsanders/archive/2009/10/14/how-to-iterate-over-contained-controls-to-set-a-common-event-handler-click-in-net.aspx</link><pubDate>Wed, 14 Oct 2009 16:16:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9907222</guid><dc:creator>jpsanders</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9907222.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9907222</wfw:commentRss><description>&lt;p&gt;The requirement was to assign a click event handler to all Label Controls contained in a .NET User Control.&amp;nbsp; This is a simple technique but I found there was no good documentation on how to do this.&amp;nbsp; &lt;/p&gt; &lt;p&gt;To illustrate how to do this, I created a simple Windows Form application in C# and added a new Windows Forms User Control to the project.&amp;nbsp; I called it AutoLabelClickControl.&amp;nbsp; I placed a label right on the control called ‘Control Label’.&amp;nbsp; I added a panel with a label on it called ‘Panel Label’ and then placed a panel contained in the first panel and put a label on it called ‘Panel in a Panel Label’.&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Howtoiterateovercontainedcontrolstos.NET_AC85/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Howtoiterateovercontainedcontrolstos.NET_AC85/image_thumb_1.png" width="449" height="288"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;The idea now is that when the control ‘AutoLabelClickControl’ is loaded, code should hook up a common click event handler for all labels.&amp;nbsp; Add a _Load event handler to your Control (not the Form) using the wizard and let’s add the necessary code:&lt;/p&gt; &lt;p&gt;// This is the Common Event Handler for all Label Clicks&lt;br&gt;private void LabelClickEventHandler(object sender, EventArgs e)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Ensure we can typecast correctly!&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (sender is Label)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Do whatever you want... in this case show the Name of the control clicked&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Label aLabel = sender as Label;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(aLabel.Name);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }  &lt;p&gt;}  &lt;p&gt;// Walk the collection recursively and find Label Controls and wire them up&lt;br&gt;private void FindLabelControlsInContainerAndAssignEvent(Control.ControlCollection aCollection)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (Control aControl in aCollection)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // does this control contain other controls?&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (aControl.Controls.Count &amp;gt; 0)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // call this function recursively!&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FindLabelControlsInContainerAndAssignEvent(aControl.Controls);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // wire up our Common Event Handler&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (aControl is System.Windows.Forms.Label)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aControl.Click += new System.EventHandler(LabelClickEventHandler);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}  &lt;p&gt;private void AutoLabelClickControl_Load(object sender, EventArgs e)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // When loading wire up the events for all contained Labels&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FindLabelControlsInContainerAndAssignEvent(this.Controls);&lt;br&gt;}  &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;And here is the test! &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Howtoiterateovercontainedcontrolstos.NET_AC85/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Howtoiterateovercontainedcontrolstos.NET_AC85/image_thumb_3.png" width="431" height="347"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Note:&amp;nbsp; Although you may think you cannot have a label contained in a label control, you can actually do this if you edit the Designer code (not recommended) and that is why I did not have an ‘else’ statement between these:&lt;/p&gt; &lt;p&gt;// does this control contain other controls?&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (aControl.Controls.Count &amp;gt; 0)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // call this function recursively!&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FindLabelControlsInContainerAndAssignEvent(aControl.Controls);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }  &lt;p&gt;// LOOK – NO ELSE STATEMENT… IN THEORY A LABEL COULD CONTAIN A LABEL BUT YOU WOULD HAVE TO HACK IT IN &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // wire up our Common Event Handler&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (aControl is System.Windows.Forms.Label)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aControl.Click += new System.EventHandler(LabelClickEventHandler);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/p&gt; &lt;p&gt;It would be EXTREMELY weird for someone to do this but…&amp;nbsp; I have been around a while so that is why I wrote that code that way :-)&lt;/p&gt; &lt;p&gt;Note:&amp;nbsp; It is up to you to apply proper error checking and try/catch blocks to this code.&amp;nbsp; See the terms of use in my Blog header.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Please drop me a note if you find this useful!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9907222" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/.NET+Controls/default.aspx">.NET Controls</category></item><item><title>WinHttpWriteData will fail with ERROR_INVALID_PARAMETER if you are trying to send more data than specified in WinHttpSendRequest on Windows 7 (by design)</title><link>http://blogs.msdn.com/jpsanders/archive/2009/10/13/winhttpwritedata-may-fail-with-error-invalid-parameter-if-you-are-trying-to-send-more-data-than-specified-in-winhttpsendrequest-on-windows-7-by-design.aspx</link><pubDate>Tue, 13 Oct 2009 15:37:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9906655</guid><dc:creator>jpsanders</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9906655.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9906655</wfw:commentRss><description>&lt;p&gt;There are new checks in Windows 7 to prevent you from doing bad things with the WinHttp APIs.&amp;nbsp; In the sample code below, I do not get an error pre-Windows 7 but on Windows 7 the WinHttpWriteData call results in bResults being 0 and GetLastError() returns 87 (ERROR_INVALID_PARAMETER):&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;LPSTR pszData = "WinHttpWriteData Example";  &lt;p&gt;LPSTR pszMoreData = "WinHttpWriteData Example";&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Send a Request.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (hRequest) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bResults = WinHttpSendRequest( hRequest, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WINHTTP_NO_ADDITIONAL_HEADERS,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0, pszData, strlen(pszData), &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strlen(pszData), 0); &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Write data to the server.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (bResults)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bResults = WinHttpWriteData( hRequest, pszMoreData, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strlen(pszMoreData), &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;dwBytesWritten);  &lt;p&gt;Looking at a Network Monitor trace, you see something very strange in the HTTP traffic pre Windows 7:  &lt;p&gt;You see a POST - Http: Request, POST /ReadAll.asp ContentLength:&amp;nbsp; 24 and the text I sent: HTTPPayloadLine: WinHttpWriteData Example  &lt;p&gt;and then the successful return code from the server -Http: Response, HTTP/1.1, Status Code = 200, URL: /ReadAll.asp  &lt;p&gt;But the following bunch of Data in the next frame! - HtmlPayload: WinHttpWriteData Example  &lt;p&gt;So the POST is being sent, then more data after the initial POST and 200 OK response from the server!  &lt;p&gt;Looking at the headers, you can see the Content-Length is set to 24 (this is what you set in WinHttpSendRequest the &lt;em&gt;dwTotalLength&lt;/em&gt; = strlen(pszData)), and that is why the server returns 200 (because as far as it is concerned you told it you were sending only 24 bytes of data and that was what your client had sent).&amp;nbsp; However the extra 24 bytes of data gets sent by the WinHttpWriteData call!  &lt;p&gt;For Windows 7, a check was put in place internally to prevent you from making such a bad protocol violation.&amp;nbsp; Now WinHttpWriteData will return 0 and GetLastError() will indicate 87 which means that you have passed invalid data.&amp;nbsp; In this case the length of the data you intend to write exceeded what you set as the content length in WinHttpSendRequest!&amp;nbsp; The fix is for you to correct your buggy code and indicate the correct content length by setting the &lt;em&gt;dwTotalLength&lt;/em&gt; parameter correctly in the call to WinHttpSendRequest.&amp;nbsp; In this case I can change the code to this:  &lt;p&gt;&amp;nbsp;&lt;/p&gt;// Send a Request.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (hRequest) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bResults = WinHttpSendRequest( hRequest, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WINHTTP_NO_ADDITIONAL_HEADERS,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0, pszData, strlen(pszData), &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strlen(pszData)+ strlen(pszMoreData), 0);  &lt;p&gt;Please drop me a comment if you found this helpful!  &lt;p&gt;Reference: &lt;a title="http://msdn.microsoft.com/en-us/library/aa384110(VS.85).aspx" href="http://msdn.microsoft.com/en-us/library/aa384110(VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/aa384110(VS.85).aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9906655" width="1" height="1"&gt;</description></item><item><title>How To: Walkthrough Using HttpListener as an SSL Simple Server</title><link>http://blogs.msdn.com/jpsanders/archive/2009/09/29/walkthrough-using-httplistener-as-an-ssl-simple-server.aspx</link><pubDate>Tue, 29 Sep 2009 23:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9900972</guid><dc:creator>jpsanders</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9900972.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9900972</wfw:commentRss><description>&lt;P&gt;There seems to be no simple end-to-end walkthrough for creating a simple HttpListener based SSL Listener that includes how to configure the computer by generating and installing a Certificate for this listener.&lt;/P&gt;
&lt;P&gt;Basic concepts covered:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Write the listener code to listen for SSL requests 
&lt;LI&gt;Generate a self signed Certificate 
&lt;LI&gt;Configure the machine to use a Certificate&lt;/LI&gt;&lt;/UL&gt;
&lt;H3&gt;Write the listener code to listen for SSL requests&lt;/H3&gt;
&lt;P&gt;Here is the documentation for HttpListener: &lt;A title=http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx href="http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Copy the code from the above page and paste it into a new C# Console application right under the Main() function.&amp;nbsp; Then add the System.Net namespace right under using System.Text;: using System.Net;&lt;/P&gt;
&lt;P&gt;Now from the Main function call the function you pasted in passing the prefixes you wish to listen to.&amp;nbsp; In my case I will listen to http requests on port 8080 when the URI ends with the ‘listener’ prefix and https requests on port 8081 again with the ‘listener’ prefix.&amp;nbsp; Every time a request is handled you need to restart the program.&lt;/P&gt;
&lt;P&gt;static void Main(string[] args)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string[] thePrefixes = { "&lt;A href="http://+:8080/listener/%22" mce_href='http://+:8080/listener/"'&gt;http://+:8080/listener/"&lt;/A&gt;, "&lt;A href="https://+:8081/listener/%22" mce_href='https://+:8081/listener/"'&gt;https://+:8081/listener/"&lt;/A&gt; };&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SimpleListenerExample(thePrefixes);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } 
&lt;P&gt;The code should now compile and you can run in the debugger.&amp;nbsp; I then used Internet Explorer to try and reach the listener: &lt;A title=http://jsan17708317:8080/listener/ href="http://jsan17708317:8080/listener/" mce_href="http://jsan17708317:8080/listener/"&gt;http://jsan17708317:8080/listener/&lt;/A&gt; and this succeeds!&amp;nbsp; However the https site does not succeed: &lt;A href="https://jsan17708317:8081/listener/%22" mce_href='https://jsan17708317:8081/listener/"'&gt;https://jsan17708317:8081/listener/"&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The failure occurs because we have not set up a certificate for the listener to use for SSL traffic (https).&amp;nbsp; This brings us to the next two items.&lt;/P&gt;
&lt;H3&gt;Generate a self signed Certificate&lt;/H3&gt;
&lt;P&gt;First of all, if this is a production environment, you will want to get a server certificate issued by a Trusted Root authority.&amp;nbsp; This Post illustrates how to create a self signed certificate to test your code before you get a certificate from an authority.&lt;/P&gt;
&lt;P&gt;This is the documentation for MakeCert.exe : &lt;A title=http://msdn.microsoft.com/en-us/library/bfsktky3.aspx href="http://msdn.microsoft.com/en-us/library/bfsktky3.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bfsktky3.aspx"&gt;http://msdn.microsoft.com/en-us/library/bfsktky3.aspx&lt;/A&gt;.&amp;nbsp; You can use this program to generate a self signed Server Certificate for the application.&lt;/P&gt;
&lt;P&gt;Using Visual Studio 2008 you can simply use the Visual Studio 2008 command prompt from the program menu to access MakeCert.exe.&lt;/P&gt;
&lt;P&gt;The syntax would look something like this (replace the name of the machine ‘jsan17708317’ with yours, and see the makecert documentation for an explanation of the arguments used here): &lt;/P&gt;
&lt;P&gt;makecert.exe -sr LocalMachine -ss MY -a sha1 -n "CN=jsan17708317" -sky exchange -pe -eku 1.3.6.1.5.5.7.3.1&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;The command should return ‘Succeeded’.&lt;/P&gt;
&lt;P&gt;Now you need to ensure the Root Authority is trusted.&amp;nbsp; To do this from the same command prompt you used above, type MMC.&amp;nbsp; Then choose ‘File’, ‘Add/Remove Snap-in…’&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_6.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_2.png" width=281 height=159 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_2.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;and then hit the ‘Add’ Button, select ‘Certificates’.&amp;nbsp; Click the ‘Add’ button…&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_8.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_8.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_3.png" width=338 height=386 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_3.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Select ‘Computer account’ and then click ‘Next &amp;gt;’, ‘Finish’, ‘Close’ and ‘OK’. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_10.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_10.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_4.png" width=244 height=176 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_4.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;You should them be able to expand the Tree on the left to show the Personal Certificates and find the one you just added (mine is the only one shown)…&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_12.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_12.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_5.png" width=456 height=100 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_5.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Double click on your certificate and you will see something similar to this:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_14.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_14.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_6.png" width=244 height=203 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_6.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;You need to resolve the Red X problem (the certificate cannot be verified up to a trusted root).&lt;/P&gt;
&lt;P&gt;Click on the&amp;nbsp; ‘Certification Path’ tab in this dialog, and the problem certificate (Root Agency) then on ‘View Certificate’.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_16.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_16.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_7.png" width=229 height=144 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_7.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;You will see the problem is that this Certificate is not in the ‘Trusted Root’ store.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_18.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_18.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_8.png" width=244 height=172 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_8.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;To get it into the store, click the ‘Details’ Tab and then the ‘Copy to File…’ button&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_20.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_20.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_9.png" width=221 height=244 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_9.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Hit ‘Next &amp;gt;’ twice then the ‘Browse’ button and save the file to your local Documents directory (name it something like ‘RootCert’) then finish up the wizard until you have successfully exported the certificate.&amp;nbsp; Now we will import the certificate into the trusted root store.&lt;/P&gt;
&lt;P&gt;Expand the ‘Trusted Root Certification Authorities’ tree and right click on ‘Certificates’&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_22.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_22.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_10.png" width=244 height=117 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_10.png"&gt;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the context menu select ‘All Tasks…’ then ‘Import…’ and navigate to where you saved the ‘RootCert’ and import the certificate by completing the Wizard.&lt;/P&gt;
&lt;P&gt;Now you should be able to go back to your Server Certificate in the Personal Store and see that there are no problems with the Certificate (leave this dialog up for the next step):&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_24.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_24.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_11.png" width=244 height=151 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_11.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;The final step here is to get thumbprint hash for use in the next section.&lt;/P&gt;
&lt;P&gt;Click on the ‘Details’ tab, and scroll down to the ‘Thumbprint’ Field in the dialog and click on it.&amp;nbsp; Then sweep out the numbers below with your mouse (don’t miss any) and copy those numbers with the Ctrl+C key combination. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_26.png" mce_href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_26.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_12.png" width=244 height=197 mce_src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/WalkthroughUsingHttpListenerasanSSLSimpl_CAC6/image_thumb_12.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Open notepad and paste these numbers into it for use in the next step.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Supplemental note:&lt;/P&gt;
&lt;P&gt;If you have IIS installed, I like the SSL Diagnostics tool instead of Makecert: &lt;A title=http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=cabea1d0-5a10-41bc-83d4-06c814265282 href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=cabea1d0-5a10-41bc-83d4-06c814265282" mce_href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=cabea1d0-5a10-41bc-83d4-06c814265282"&gt;http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=cabea1d0-5a10-41bc-83d4-06c814265282&lt;/A&gt; Instructions for generating the certificate are in the help file for this tool.&amp;nbsp; Once you run this tool it creates a temporary certificate and installs it in the local computer Trusted Root Authorities Certificate store for you!&lt;/P&gt;
&lt;H3&gt;Configure the machine to use a Certificate&lt;/H3&gt;
&lt;P&gt;Finally you need to configure the machine to associate the certificate you just created, with the port and ip address that the HttpListener is listening on for https requests.&lt;/P&gt;
&lt;P&gt;You need to obtain httpcfg.exe to do this next step.&amp;nbsp; Search Technet for the latest version of this tool for your OS.&amp;nbsp; For example, XP SP2 tools have it (Note: this is an &lt;STRONG&gt;optional&lt;/STRONG&gt; component for XP so you will need to do a &lt;STRONG&gt;COMPLETE install&lt;/STRONG&gt; to get this tool): &lt;A title=http://www.microsoft.com/downloads/details.aspx?FamilyId=49AE8576-9BB9-4126-9761-BA8011FABF38&amp;amp;displaylang=en href="http://www.microsoft.com/downloads/details.aspx?FamilyId=49AE8576-9BB9-4126-9761-BA8011FABF38&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyId=49AE8576-9BB9-4126-9761-BA8011FABF38&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=49AE8576-9BB9-4126-9761-BA8011FABF38&amp;amp;displaylang=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;You will need to run httpcfg from the command line and supply the Thumbprint hash you obtained in the previous section but you need to remove the spaces between the numbers.&amp;nbsp; In my example I removed the spaces and the hash is: f4bb35424190e006e5476e97430c5b8136ee5da5&lt;/P&gt;
&lt;P&gt;This is the httpcfg command I ran to associate the cert for all IP addresses associated with my machine and port 8081 (/i 0.0.0.0:8081):&lt;/P&gt;
&lt;P&gt;C:\Program Files\Support Tools&amp;gt;httpcfg set ssl /i 0.0.0.0:8081 /h f4bb35424190e006e5476e97430c5b8136ee5da5&lt;/P&gt;
&lt;P&gt;When you run this you will see the result: HttpSetServiceConfiguration completed with 0.&lt;/P&gt;
&lt;P&gt;Now double check the SSL bindings for this computer:&lt;/P&gt;
&lt;P&gt;C:\Program Files\Support Tools&amp;gt;httpcfg query ssl&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0.0.0.0:8081&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Hash&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : f4bb35424190e0 6e5476e9743 c5b8136ee5da5&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Guid&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : {00000000-0000-0000-0000-000000000000}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CertStoreName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : (null)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CertCheckMode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RevocationFreshnessTime : 0&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UrlRetrievalTimeout&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SslCtlIdentifier&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : (null)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SslCtlStoreName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : (null)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Flags&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0&lt;BR&gt;------------------------------------------------------------------------------ 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;You can verify that the IP shows up and the Hash you entered (note that weirdness where some of the 0 characters do not appear… I don’t know why that is). 
&lt;P&gt;Now you should be able to run the above Test application and hit the SSL Site using Internet Explorer.&amp;nbsp; In my case the URL is: &lt;A title=https://jsan17708317:8081/listener/ href="https://jsan17708317:8081/listener/" mce_href="https://jsan17708317:8081/listener/"&gt;https://jsan17708317:8081/listener/&lt;/A&gt;&lt;/P&gt;
&lt;H3&gt;Troubleshooting&lt;/H3&gt;
&lt;P&gt;If the app does not work, first verified you did each step above correctly (did not leave out something or some step).&lt;/P&gt;
&lt;P&gt;Verify your certificate appears with the IP and Hash fields the correspond with what you are listening for and that the Hash is the hash you obtained previously for the certificate.&lt;/P&gt;
&lt;P&gt;Check with httpcfg query ssl and see if there are other listeners that may conflict for that same port.&amp;nbsp; Delete conflicts with the command http delete ssl /i x.x.x.x:8081&amp;nbsp; (replace x.x.x.x with any IP address you see that are listening on the same port).&lt;/P&gt;
&lt;H3&gt;Supplemental Information&lt;/H3&gt;
&lt;P&gt;This is a simple example.&amp;nbsp; You probably do not want to stop listening after you process one request.&amp;nbsp; You will need to provide a way to gracefully close the listener and handle the requests on worker threads.&lt;/P&gt;
&lt;P&gt;You can specify a specific IP range in HttpCfg (search MSDN for HttpCfg syntax).&amp;nbsp; In my example you can use this to bind to the ip address 10.10.3.4: &lt;BR&gt;httpcfg set ssl /i 10.10.3.4:8081 /h f4bb35424190e006e5476e97430c5b8136ee5da5&lt;/P&gt;
&lt;P&gt;You cannot listen for http and https traffic on the same port.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this gets you started with your HttpListener project and will help you troubleshoot the initial setup of your code.&amp;nbsp; Please Drop me a note if you find this useful!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9900972" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/HttpListener/default.aspx">HttpListener</category></item><item><title>How to get a dump for a System.Net.WebException using DebugDiag (Debug Diagnostics)</title><link>http://blogs.msdn.com/jpsanders/archive/2009/09/29/how-to-get-a-dump-for-a-system-net-webexception-using-debugdiag-debug-diagnostics.aspx</link><pubDate>Tue, 29 Sep 2009 17:13:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9900795</guid><dc:creator>jpsanders</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9900795.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9900795</wfw:commentRss><description>&lt;p&gt;This information is available in the help file as well.&amp;nbsp; For more options please refer to the Help Documentation include with DebugDiag.&lt;/p&gt; &lt;p&gt;Install the latest Debug Diagnostics from &lt;a href="http://download.microsoft.com"&gt;http://download.microsoft.com&lt;/a&gt; (search for Debug Diagnostics once on that site)&lt;/p&gt; &lt;p&gt;Configure a crash rule for all w3wp.exe processes (if this dialog does not appear simply press the ‘Add Rule…’ button).&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_thumb.png" width="376" height="331"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Select ‘A specific process’&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_thumb_1.png" width="369" height="326"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Make sure you DO NOT check ‘This process instance only’ and type in the process we wish to monitor (in this case asp.net is running in w3wp.exe).&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_thumb_2.png" width="373" height="328"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;In the ‘Advanced Configuration Dialog’ select the 'Exceptions...’ button at the bottom of this dialog:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_thumb_3.png" width="376" height="331"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Choose ‘Add Exception…’.&amp;nbsp; Clicking this button will bring up the Configure Exception dialog.&amp;nbsp; Use this to configure actions for a specific type of first chance exception.&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_thumb_4.png" width="374" height="243"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;In the Configure Exception Dialog, Choose 'CLR (.NET) Exception'&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_12.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_thumb_5.png" width="380" height="303"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;For the 'Net Exception Type' field: (This will only be available when choosing the E0434F4D CLR (.NET) Exception code)&amp;nbsp;&amp;nbsp; You must specify the exact name of the exception in this field.&amp;nbsp; This field is case sensitive.&amp;nbsp; In our case we want System.Net.WebException&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_14.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_thumb_6.png" width="382" height="305"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;In the ‘Action Type’ pull down specify ‘Full User Dump’ and you will be able to capture the state when we have the 401 (or other) WebException in the w3wp.exe process.&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_16.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_thumb_7.png" width="385" height="308"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;The ‘Action Limit’ by default is set to 1.&amp;nbsp; This means only one dump will be created.&amp;nbsp; If you wish to catch more than one dump, increase this number (usually 3 is sufficient).&amp;nbsp; Then hit OK and proceed by hitting the ‘Save &amp;amp; Close’ button (note you will see the configured CLR exception now).&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_18.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_thumb_8.png" width="388" height="252"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Finally hit the ‘Next &amp;gt;’ button twice and then ‘Finish’.&amp;nbsp; The rule will be activated.&lt;/p&gt; &lt;p&gt;You do not need to keep the UI up for DebugDiag.&amp;nbsp; If you do keep it up you will see the ‘Userdump Count’ increase with each exception you encounter (up to the limit you set previously) and the location of the dump is listed as well.&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_22.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/How.WebExceptionusingDebugDiagDebugDiagn_8F59/image_thumb_10.png" width="523" height="116"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Finally to analyze the dump, you can use DebugDiag to analyze the script.&amp;nbsp; You can use the special script I developed &lt;a href="http://blogs.msdn.com/jpsanders/archive/2009/02/23/anaylyze-httpwebrequest-hangs-with-a-vb-debugdiag-script.aspx" target="_blank"&gt;here&lt;/a&gt; to get a good picture of what the problem may be.&lt;/p&gt; &lt;p&gt;Please drop me a note and let me know if this Post helped you!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9900795" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/System.Net/default.aspx">System.Net</category><category domain="http://blogs.msdn.com/jpsanders/archive/tags/HttpWebRequest/default.aspx">HttpWebRequest</category><category domain="http://blogs.msdn.com/jpsanders/archive/tags/Certificates/default.aspx">Certificates</category><category domain="http://blogs.msdn.com/jpsanders/archive/tags/SSL/default.aspx">SSL</category></item><item><title>Troubleshooting ASP.NET - The remote certificate is invalid according to the validation procedure</title><link>http://blogs.msdn.com/jpsanders/archive/2009/09/16/troubleshooting-asp-net-the-remote-certificate-is-invalid-according-to-the-validation-procedure.aspx</link><pubDate>Wed, 16 Sep 2009 17:01:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9895867</guid><dc:creator>jpsanders</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9895867.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9895867</wfw:commentRss><description>&lt;p&gt;This error message is caused because the process is not being able to validate the Server Certificate supplied by the Server during an HTTPS (SSL) request.&amp;nbsp; The very first troubleshooting step should be to see if the server supplied certificate and every certificate in the chain is trouble free.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Example 1 – Root Certificate only (self signed certificate in this case)&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 1 – Validate the certificate, any intermediate certificates and the root certificate&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;One super handy and technical tool to help you do this first step is Internet Explorer.&amp;nbsp; Simply try to hit the same URL that your ASP.NET web application tries to hit when it gets this error.&amp;nbsp; For example, type in to the browser the path to the .asmx file and see what Internet Explorer says about the certificate. &lt;/p&gt; &lt;p&gt;This would be a bad sign:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb.png" width="743" height="322"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;If Internet Explorer has certificate problems, chances are you will have problems with the HttpWebRequest (or Web Service) call as well.&amp;nbsp; The easiest fix is to install a valid certificate for the server, the root authority and all intermediate authorities.&amp;nbsp; Then go back and verify Internet Explorer can access the https site with no errors at all.&lt;/p&gt; &lt;p&gt;If you continue to the site using Internet Explorer, sometimes you can diagnose the certificate problem by viewing the certificate.&amp;nbsp; In this example the problem is spelled out for me when I typed in &lt;a href="https://jsanders4"&gt;https://jsanders4&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_1.png" width="336" height="419"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;So in my case, it appears that the I simply need to install the certificate in the ‘Trusted Root Certification Authorities’ store.&amp;nbsp; So indeed I do this!&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_2.png" width="244" height="222"&gt;&lt;/a&gt;&amp;nbsp; &lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_3.png" width="244" height="222"&gt;&lt;/a&gt;&amp;nbsp; &lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_4.png" width="244" height="223"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;But I still got the certificate error…&amp;nbsp; To avoid a long discussion about this, the problem is simple.&amp;nbsp; I typed in &lt;a href="https://jsanders4"&gt;https://jsanders4&lt;/a&gt; but note the certificate is for the full domain name of this machine.&amp;nbsp; If I instead browse to &lt;a href="https://jsanders4.northamerica.corp.microsoft.com"&gt;https://jsanders4.northamerica.corp.microsoft.com&lt;/a&gt; then I get no certificate error.&amp;nbsp; Now that I am sure I can browse ok to the site with no certificate errors using Internet Explorer.&lt;/p&gt; &lt;p&gt;You would continue to solve problems with the other Certificates in the Certificate chain by using Internet Explorer until they are all resolved.&amp;nbsp; For example, perhaps the certificate is expired, or the Intermediate Authority is not in the Intermediate Certificate Authorities store (a very common one).&amp;nbsp; Once you have resolved all errors with Internet Explorer your are only half way finished.&amp;nbsp; You need to get the same information into the Local Computer store.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 2 – Troubleshoot the ASP.NET problem&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;I try my ASP.NET application and try to access the same site.&amp;nbsp; I get this error: ‘The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.’&lt;/p&gt; &lt;p&gt;But Internet Explorer was fine… &lt;/p&gt; &lt;p&gt;The next step should be to get a System.Net trace.&amp;nbsp; To do this open the Web.Config for the troubled ASP.NET application and see if there is a &amp;lt;configuration&amp;gt; section in the file.&amp;nbsp; If there is, add the contents inside the &amp;lt;configuration&amp;gt; &amp;lt;/configuration&amp;gt; tags from this blog: &lt;a title="http://blogs.msdn.com/jpsanders/archive/2009/03/24/my-favorite-system-net-trace-configuration-file-dumps-process-id-and-date-time-information.aspx" href="http://blogs.msdn.com/jpsanders/archive/2009/03/24/my-favorite-system-net-trace-configuration-file-dumps-process-id-and-date-time-information.aspx"&gt;http://blogs.msdn.com/jpsanders/archive/2009/03/24/my-favorite-system-net-trace-configuration-file-dumps-process-id-and-date-time-information.aspx&lt;/a&gt;.&amp;nbsp; If it does not exist, add the entire contents before the closing tag of the Web.Config.&amp;nbsp; Now edit this line:&amp;nbsp;&amp;nbsp; initializeData="System.Net.trace.log"&amp;nbsp; You must ensure that the Network Service account can write this .log so change this entry to a folder that the Network Service account can write to.&amp;nbsp; For example, I created a folder c:\mylogs and assigned the Network Service account FULL privileges.&amp;nbsp; Then changed this setting to initializeData="c:\mylogs\System.Net.trace.log"&lt;/p&gt; &lt;p&gt;I ran the asp.net application and saw at the end of the log file (c:\mylogs\System.Net.trace.log) this information:&lt;/p&gt; &lt;p&gt;System.Net Information: 0 : [0880] SecureChannel#14701405 - Remote certificate has errors:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessId=5700&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTime=2009-09-16T12:54:06.5718699Z&lt;br&gt;System.Net Information: 0 : [0880] SecureChannel#14701405 -&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessId=5700&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTime=2009-09-16T12:54:06.5718699Z&lt;br&gt;System.Net Information: 0 : [0880] SecureChannel#14701405 - Remote certificate was verified as invalid by the user.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessId=5700&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTime=2009-09-16T12:54:06.5718699Z&lt;br&gt;System.Net.Sockets Verbose: 0 : [0880] Socket#26833123::Dispose()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessId=5700&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTime=2009-09-16T12:54:06.5718699Z&lt;br&gt;System.Net Error: 0 : [0880] Exception in the HttpWebRequest#31364015:: - The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessId=5700&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTime=2009-09-16T12:54:06.5718699Z  &lt;p&gt;This is the key to this particular problem:&amp;nbsp; A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider. &lt;/p&gt; &lt;p&gt;However I thought I just added this certificate trough Internet Explore to my Trusted Root Authorities!&amp;nbsp; In reality I simply added it so the store of the logged on user.&amp;nbsp; ASP.NET is running in the local machine context.&amp;nbsp; To resolve this, start MMC (Windows key + R and type MMC) and add the following snap-ins:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_5.png" width="244" height="143"&gt;&lt;/a&gt; &lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_6.png" width="244" height="149"&gt;&lt;/a&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_18.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_8.png" width="244" height="151"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;And ensure you see the ‘Current User’ and ‘(Local Computer)’ Certificates listed (then hit OK):&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_20.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_9.png" width="244" height="185"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;In the console expand the ‘Current User’ Trusted Root store and you see I have the certificate stored there.&amp;nbsp; However expanding the ‘(Local Computer)’ trusted root, it is NOT there:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_22.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_10.png" width="244" height="195"&gt;&lt;/a&gt; &lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_24.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_11.png" width="238" height="244"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Simply Copy (do not Drag and drop) the jsanders4 certificate from the Current User\Trusted Root store to the (Local Computer)\Trusted Root store and retest.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_26.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_12.png" width="244" height="152"&gt;&lt;/a&gt; &lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_28.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_13.png" width="244" height="147"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Success!&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Example 2 – Intermediate Certificate Authorities Involved&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;This next example is a bit manufactured but illustrates a problem that I have had to help solve a few times.&amp;nbsp; The trouble shooting steps remain the same, but in this case there are one or more intermediate certificates.&amp;nbsp; This intermediate certificates should be in the ‘Intermediate Certification Authorities’ store to resolve this problem Take a look at the certificate chain for &lt;a href="https://www.microsoft.com"&gt;https://www.microsoft.com&lt;/a&gt; (you do this by clicking on the padlock icon in Internet Explorer and choosing the Certification Path tab:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_30.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/Tro.NETTheremotecertificateisinvalidacco_D4C1/image_thumb_14.png" width="244" height="167"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;For the purpose of this example, assume that the three certificates that are not highlighted all have a warning icon next to them indicating a problem.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 1 – Validate the certificate, any intermediate certificates and the root certificate&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Note: For Internet Explorer there actually was no problem with the certification path.&amp;nbsp; The four certificates show no warning icons.&amp;nbsp; For &lt;em&gt;this&lt;/em&gt; example, let’s say that the ‘GTE CyberTrust Global Root’, ‘Microsoft Internet Authority’ and ‘Microsoft Secure Server Authority’ certificates were all missing from my ‘Current User’ stores.&amp;nbsp; The steps below are contrived from this assumption.&lt;/p&gt; &lt;p&gt;To fix this I add the ‘GTE CyberTrust Global Root’ cert to the ‘Trusted Root Certification Authorities’ Store and the other two certificates to the ‘Intermediate Certification Authorities’ store of the Current User.&amp;nbsp; Test with IE again and Internet Explorer shows no problem after installing the certificates.&amp;nbsp; Next when I tested the ASP.NET application I got an error (because I did not add these certificates to the same stores in the (Local Computer) store).&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 2 – Troubleshoot the ASP.NET problem&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;From the first example I was smart enough to copy the ‘GTE CyberTrust Global Root’ certificate to the ‘(Local Computer)’ trusted root store but I still have an error!&lt;/p&gt; &lt;p&gt;The ASP.NET program now has an error: System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---&amp;gt; System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.&lt;/p&gt; &lt;p&gt;Again taking the System.Net trace you see an error towards the end of the file in these entries:&lt;/p&gt; &lt;p&gt;Remote certificate has errors:&lt;br&gt;A certificate chain could not be built to a trusted root authority. &lt;br&gt;Remote certificate was verified as invalid by the user.&lt;br&gt;The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.  &lt;p&gt;&lt;em&gt;This entry is the key:&lt;/em&gt; ‘A certificate chain could not be built to a trusted root authority.’&amp;nbsp; This means that a certificate before the Root Authority is not in the ‘(Local Computer) Intermediate Certification Authorities’ store.&amp;nbsp; Once the two intermediate certificates are copied to the Intermediate store from the Current User intermediate store the problem is solved!  &lt;p&gt;I hope this blog helped you get to the root of your problem.&amp;nbsp; If this was helpful please leave me a comment!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9895867" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/Certificates/default.aspx">Certificates</category><category domain="http://blogs.msdn.com/jpsanders/archive/tags/SSL/default.aspx">SSL</category><category domain="http://blogs.msdn.com/jpsanders/archive/tags/Asp.Net/default.aspx">Asp.Net</category></item><item><title>How to get the window handle for the Internet Explorer process you created (LCIE IE 8)</title><link>http://blogs.msdn.com/jpsanders/archive/2009/09/04/how-to-get-the-window-handle-for-the-internet-explorer-process-you-created-lcie-ie-8.aspx</link><pubDate>Fri, 04 Sep 2009 20:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9891532</guid><dc:creator>jpsanders</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9891532.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9891532</wfw:commentRss><description>&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;One technique people use in accessibility applications is to kick off an application and then grab the Window handle of the process to hook it or do other processing.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;With loosely coupled Internet Explorer (LCIE) this is a little more difficult that simply getting the handle of the iexplore.exe process you kick off.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The reason is that there is a broker IE process and this kicks of the actual IE instance.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Look at the links at the end of the article for more information how this works.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;The technique you can use is to iterate over the processes and wait for your expected IE instance to get a valid window handle.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If there are no other IE instances running the technique is relatively simple.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;Here is a simple console application you can debug and play with to investigate this technique.&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;o:p&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;Full listing below (&lt;A href="javascript:CopyCode('VBDDcodesection1');"&gt;Copy Code&lt;/A&gt;):&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR: #e0e0e0" id=VBDDcodesection1&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt; System;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt; System.Collections.Generic;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt; System.Linq;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt; System.Text;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt; System.Threading;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt; System.Diagnostics;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt"&gt;namespace&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt; LCIE&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Program&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; dumpIEWindows(&lt;SPAN style="COLOR: #2b91af"&gt;Process&lt;/SPAN&gt; [] processes)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; abFoundHandle = &lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ((processes == &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)||(processes.Length == 0))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"No IE Processes found"&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;Process&lt;/SPAN&gt; nextProcess &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; processes)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (nextProcess.MainWindowHandle == &lt;SPAN style="COLOR: #2b91af"&gt;IntPtr&lt;/SPAN&gt;.Zero)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.Write(&lt;SPAN style="COLOR: #a31515"&gt;"IE process with Window handle set to 0: "&lt;/SPAN&gt; + nextProcess.Id.ToString());&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;".&amp;nbsp; This could be the Broker, or the windows is not created yet"&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abFoundHandle = &lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"IE process with handle: "&lt;/SPAN&gt; + nextProcess.Id.ToString() + &lt;SPAN style="COLOR: #a31515"&gt;".&amp;nbsp; Window Title: "&lt;/SPAN&gt; + nextProcess.MainWindowTitle);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; abFoundHandle;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Main(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;[] args)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//TODO:&amp;nbsp; Trap exceptions and take appropriate action if there is an exception&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Process&lt;/SPAN&gt;[] arrayOfProcesses;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Process&lt;/SPAN&gt; aProcess;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// See if there are any iexplore processes already&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arrayOfProcesses = System.Diagnostics.&lt;SPAN style="COLOR: #2b91af"&gt;Process&lt;/SPAN&gt;.GetProcessesByName(&lt;SPAN style="COLOR: #a31515"&gt;"iexplore"&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (arrayOfProcesses.Length == 0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// create iexplore.exe process&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aProcess = &lt;SPAN style="COLOR: #2b91af"&gt;Process&lt;/SPAN&gt;.Start(&lt;SPAN style="COLOR: #a31515"&gt;"iexplore.exe"&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aProcess.WaitForInputIdle();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arrayOfProcesses = System.Diagnostics.&lt;SPAN style="COLOR: #2b91af"&gt;Process&lt;/SPAN&gt;.GetProcessesByName(&lt;SPAN style="COLOR: #a31515"&gt;"iexplore"&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// TODO:&amp;nbsp; Add some safety valve here to abort the loop after a certain amount of time&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// or after a few iterations.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;while&lt;/SPAN&gt; (dumpIEWindows(arrayOfProcesses) == &lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// no IE Windows with a handle so we need to wait for window creation.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// another possibility is that the iexplore broker process has started and it &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// did not yet create the brokered process (see LCIE).&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// Take a nap...&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Thread&lt;/SPAN&gt;.Sleep(500);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arrayOfProcesses = System.Diagnostics.&lt;SPAN style="COLOR: #2b91af"&gt;Process&lt;/SPAN&gt;.GetProcessesByName(&lt;SPAN style="COLOR: #a31515"&gt;"iexplore"&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;You can extend this example to find the exact window created in the event there are other iexplore.exe processes running before you kick off your process simply by getting a list of PIds (Process Ids) before you create your IExplore.exe process and compare that to the one that you get after you create the process.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The process without a NULL window handle will be the correct instance.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;&lt;STRONG&gt;Helpful links&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;IE 8 LCIE:&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;A href="http://blogs.msdn.com/ie/archive/2008/03/11/ie8-and-loosely-coupled-ie-lcie.aspx" mce_href="http://blogs.msdn.com/ie/archive/2008/03/11/ie8-and-loosely-coupled-ie-lcie.aspx"&gt;&lt;FONT size=3 face=Calibri&gt;http://blogs.msdn.com/ie/archive/2008/03/11/ie8-and-loosely-coupled-ie-lcie.aspx&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;Controlling and configuring LCIE:&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;A href="http://blogs.msdn.com/askie/archive/2009/03/09/opening-a-new-tab-may-launch-a-new-process-with-internet-explorer-8-0.aspx" mce_href="http://blogs.msdn.com/askie/archive/2009/03/09/opening-a-new-tab-may-launch-a-new-process-with-internet-explorer-8-0.aspx"&gt;&lt;FONT size=3 face=Calibri&gt;http://blogs.msdn.com/askie/archive/2009/03/09/opening-a-new-tab-may-launch-a-new-process-with-internet-explorer-8-0.aspx&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;How to determine which IE tabs goes to which Iexplore.exe process when using Internet Explorer 8:&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;A href="http://blogs.msdn.com/askie/archive/2009/03/20/how-to-i-determine-which-ie-tabs-go-to-which-iexplore-exe-process-when-using-internet-explorer-8.aspx" mce_href="http://blogs.msdn.com/askie/archive/2009/03/20/how-to-i-determine-which-ie-tabs-go-to-which-iexplore-exe-process-when-using-internet-explorer-8.aspx"&gt;&lt;FONT size=3 face=Calibri&gt;http://blogs.msdn.com/askie/archive/2009/03/20/how-to-i-determine-which-ie-tabs-go-to-which-iexplore-exe-process-when-using-internet-explorer-8.aspx&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;Please drop me a comment if you found this Blog useful!&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;SCRIPT language=jscript&gt;
    function CopyCode(elemName) { var obj = document.getElementById(elemName); window.clipboardData.setData("Text", obj.innerText) }
&lt;/SCRIPT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9891532" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/Internet+Explorer/default.aspx">Internet Explorer</category><category domain="http://blogs.msdn.com/jpsanders/archive/tags/IE+8/default.aspx">IE 8</category></item><item><title>Using HttpWebRequest with Credential Manager</title><link>http://blogs.msdn.com/jpsanders/archive/2009/09/03/using-httpwebrequest-with-credential-manager.aspx</link><pubDate>Thu, 03 Sep 2009 21:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9891052</guid><dc:creator>jpsanders</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9891052.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9891052</wfw:commentRss><description>&lt;P&gt;A little know fact is that the .NET framework will use the stored credentials in the Credential Manager when accessing a network resource if the credentials exist for that particular resource (host).&amp;nbsp; I intend to clear up how this functionality works for the HttpWebRequests (you could extend this to WebService calls as well).&lt;/P&gt;
&lt;P&gt;In Internet Explorer, you can access a website that challenges you for credentials by filling in a username and password when the dialog is presented and asks you for authentication.&amp;nbsp; If you check ‘Remember my password’ these credentials will be stored in protected storage (Credential Manager).&amp;nbsp; You can see the stored credentials by running this command: Control Keymgr.dll.&amp;nbsp; These credentials are stored in protected storage in each user’s My folder.&amp;nbsp; You can store these credentials by using control Keymgr.dll, by using the interface available in Internet Explorer or by using C++/C and the Credentials API’s (Such as CredWrite).&amp;nbsp; If you do not check ‘Remember my password’ then these credentials are not stored in Credential Manager and .NET will not be able to use these credentials.&lt;/P&gt;
&lt;P&gt;The .NET framework can use the currently logged on user’s credentials to authenticate but if you have a web site that requires different credentials you can use store these credentials in Credential Manager and .NET will use these credentials instead of the currently logged on user credentials.&amp;nbsp; To illustrate this I put together a real simple sample.&lt;/P&gt;
&lt;P&gt;The target web server in my sample is jpsandershv2003.&amp;nbsp; I only enabled Windows Integrated Authentication in IIS on that box.&amp;nbsp; I then created a User ID JPSGuest on that IIS machine.&amp;nbsp; Finally I wrote a real simple .NET console application to create an HttpWebRequest and get the response.&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;HttpWebRequest&lt;/SPAN&gt; aReq; &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;HttpWebResponse&lt;/SPAN&gt; aResp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp; aReq = &lt;SPAN style="COLOR: #2b91af"&gt;WebRequest&lt;/SPAN&gt;.Create(&lt;SPAN style="COLOR: #a31515"&gt;"&lt;A href="http://jpsandershv2003/" mce_href="http://jpsandershv2003/"&gt;&lt;FONT color=#0000ff&gt;http://jpsandershv2003/&lt;/FONT&gt;&lt;/A&gt;"&lt;/SPAN&gt;) &lt;SPAN style="COLOR: blue"&gt;as&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;HttpWebRequest&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp; aReq.UseDefaultCredentials = &lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;aResp = aReq.GetResponse() &lt;SPAN style="COLOR: blue"&gt;as&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;HttpWebResponse&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;aResp.Close();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;When you run this code it will first look in the credential manager first for the credentials for attaching to jpsandershv2003 and if found use those, otherwise the Currently Logged on User credentials will be used.&amp;nbsp; In my example since I was logged on as jpsanders to my machine I expect that the credentials used should be my domain credentials jpsanders.&amp;nbsp; I turned on logging and ensured the IIS log was logging the username and sure enough, jpsanders was authenticated in IIS.&lt;/P&gt;
&lt;P&gt;My next goal was to see if I could change this default behavior and make it log on using the jpsandershv2003\JPSGuest user credentials.&amp;nbsp; Using the command control keymgr.dll I was able to add the credential as a Windows logon credential:&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&amp;nbsp;&lt;/P&gt;&lt;IMG src="http://ko3ggw.blu.livefilestore.com/y1pVpjI_RKFEB2pkzsElIsdesEuvV2lOuZK3qpILB8pQ4CQiCEO5zGlw_hD7OSQb35-UPU6E8Ry90uVwx3GpIzUVxUhk_2OhOHW/CredManAdd.jpg"&gt; 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Now when I ran the console application I saw success in the IIS log!&amp;nbsp; I was logging in now as JPSGuest.&lt;/P&gt;
&lt;P&gt;Taking a fiddler (&lt;A href="http://fiddlertool.com/" mce_href="http://fiddlertool.com"&gt;http://fiddlertool.com&lt;/A&gt;) trace of Internet Explorer also confirmed I was using the stored credentials and these were NTLM credentials.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Domain: jpsandershv2003&lt;BR&gt;User: JPSGuest&lt;BR&gt;Host: JPSANDERS3&lt;/P&gt;
&lt;P&gt;Can I store credentials and have it use Kerberos?&amp;nbsp; In theory yes, simply type domain based credentials in.&amp;nbsp; However I could not test this because I only have one logon to my domain and you cannot save your currently logged on credentials in the Credential Manager.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;What about basic and digest?&amp;nbsp; NO, this would be a huge security hole.&amp;nbsp; Can you tell me why (it should be obvious)?&lt;/P&gt;
&lt;P&gt;Note that the credentials used are independent of the PORT used.&amp;nbsp; So if I change the server to bind HTTP traffic on port 8089 then change my code to access &lt;A href="http://jpsandershv2003:8089/" mce_href="http://jpsandershv2003:8089"&gt;http://jpsandershv2003:8089&lt;/A&gt; the code will still access the web site using the stored credentials.&lt;/P&gt;
&lt;P&gt;To revert back to the interactive user, simply delete the credentials stored for jpsandershv2003.&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Further observations&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;What is the second radio button for (A Web site or program credentials)?&amp;nbsp; This is for programs that are writing against the credentials API directly.&amp;nbsp; Some examples of this are Terminal Server (RDP) and Windows Live credentials.&amp;nbsp; Here are some great links about the APIs: &lt;BR&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/aa374789(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa374789(VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/aa374789(VS.85).aspx&lt;/A&gt;&lt;BR&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/aa480470.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa480470.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa480470.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;NOTE: Because the credentials are stored in the context of the logged on user, this technique will not work for non interactive user accounts such as the service accounts and ASP.NET applications.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Please send me&amp;nbsp;a quick note if you found this Blog helpful!&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9891052" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/WinInet/default.aspx">WinInet</category><category domain="http://blogs.msdn.com/jpsanders/archive/tags/Internet+Explorer/default.aspx">Internet Explorer</category><category domain="http://blogs.msdn.com/jpsanders/archive/tags/HttpWebRequest/default.aspx">HttpWebRequest</category></item><item><title>Using netsh to analyze WinInet problems in Windows 7</title><link>http://blogs.msdn.com/jpsanders/archive/2009/08/24/using-netsh-to-analyze-wininet-problems-in-windows-7.aspx</link><pubDate>Mon, 24 Aug 2009 22:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9882909</guid><dc:creator>jpsanders</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9882909.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9882909</wfw:commentRss><description>&lt;p&gt;There are some powerful tracing tools built into Windows 7 that can help you diagnose Internet Client issues.&amp;nbsp; This walk though shows you now to enable tracing when accessing a web site using Internet Explorer 8 or other WinInet based applications.&lt;/p&gt; &lt;p&gt;Network tracing in Windows 7 (ref: &lt;a href="http://msdn.microsoft.com/en-us/library/dd569136(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd569136(VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/dd569136(VS.85).aspx&lt;/a&gt;)&amp;nbsp; uses Event Tracing for Windows (ETW) (ref: &lt;a href="http://msdn.microsoft.com/en-us/library/bb968803(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb968803(VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/bb968803(VS.85).aspx&lt;/a&gt;) to enable you to see what is happening at the WinInet, Winsock, WebIO and TCP level.&amp;nbsp; By looking at a simple example, you can see how this may be useful when analyzing http traffic.&lt;/p&gt; &lt;p&gt;1. Open an elevated command prompt by going to ‘Start’, ‘All Programs’, ‘Accessories’, Right click on ‘Command Prompt’ and choose ‘Run as administrator’&lt;br&gt;2. Type this into the command prompt: netsh trace start scenario = InternetClient level=5 tracefile=protocols.etl&lt;br&gt;3. Open &lt;a href="http://www.microsoft.com/protocols" mce_href="http://www.microsoft.com/protocols"&gt;http://www.microsoft.com/protocols&lt;/a&gt; in Internet Explorer&lt;br&gt;4. After that page has rendered, stop tracing by typing into the command prompt window: netsh trace stop&lt;br&gt;5. Download and install the latest network monitor from &lt;a href="http://www.microsoft.com/downloads/en/results.aspx?freetext=netmon&amp;amp;displaylang=en&amp;amp;stype=s_basic" mce_href="http://www.microsoft.com/downloads/en/results.aspx?freetext=netmon&amp;amp;displaylang=en&amp;amp;stype=s_basic"&gt;http://www.microsoft.com/downloads/en/results.aspx?freetext=netmon&amp;amp;displaylang=en&amp;amp;stype=s_basic&lt;/a&gt; (version at the time of this publication is ‘Microsoft Network Monitor 3.3’)&lt;br&gt;6. Open the trace file in netmon from c:\windows\system32\protocols.etl&lt;br&gt;7. Install the full parsers in netmon by going to ‘Tools’, ‘Options’ then click on the ‘Parser Profiles’ tab, click on the ‘Microsoft Windows’ then choose ‘Set As Active’ and then ‘OK’ (see image below)&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/UsingnetshtoanalyzeWinInetproblemsinWind_A564/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/UsingnetshtoanalyzeWinInetproblemsinWind_A564/image_thumb.png" width="621" height="348"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;You should now be able to see WinInet, TCPIP and other traffic in the ‘Network Conversations’ window.&amp;nbsp; To find the conversations with ‘protocols’ in the description, type this in the display filter: &lt;em&gt;description.contains("protocols")&lt;/em&gt; and hit the Apply icon. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/UsingnetshtoanalyzeWinInetproblemsinWind_A564/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/UsingnetshtoanalyzeWinInetproblemsinWind_A564/image_thumb_1.png" width="619" height="198"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Here is where you can start to see the power of using netmon to analyze this data.&amp;nbsp; You should see a description similar to: WinINet_MicrosoftWindowsWinINet:WININET_SENDREQUEST_START - Request : 0x078B3EF0, AddressName : &lt;a href="http://www.microsoft.com/protocols" mce_href="http://www.microsoft.com/protocols"&gt;http://www.microsoft.com/protocols&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/UsingnetshtoanalyzeWinInetproblemsinWind_A564/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/UsingnetshtoanalyzeWinInetproblemsinWind_A564/image_thumb_2.png" width="621" height="85"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;If you right click on this and choose ‘Find conversations’, ‘NetEvent’ you will see that the ‘Network Conversations’ is now highlighting the conversation associated with that request.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/UsingnetshtoanalyzeWinInetproblemsinWind_A564/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/UsingnetshtoanalyzeWinInetproblemsinWind_A564/image_thumb_4.png" width="625" height="159"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Remove the Display filter now so that you are not filtering by the description anymore.&amp;nbsp; Once you do this you can see where there may be Cookie information, TCP information,&amp;nbsp; WinInet connection information, TCP information, Http response information and other internal WinInet information.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/UsingnetshtoanalyzeWinInetproblemsinWind_A564/image_12.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jpsanders/WindowsLiveWriter/UsingnetshtoanalyzeWinInetproblemsinWind_A564/image_thumb_5.png" width="667" height="560"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Although there seems to be a mountain of information, you can use this to see what is different between a successful and failed case fairly quickly.&amp;nbsp; The Description column is pretty good at describing what each of the frames are showing you.&amp;nbsp; This will even let you see activity down to the WinSock level!&lt;/p&gt; &lt;p&gt;Try clicking on the other WinInet traffic links in the Network Conversations pane to see what other WinInet activity is occurring.&amp;nbsp; You will see images being retrieved among other activity.&amp;nbsp; This will give you&amp;nbsp; very detailed look at what WinInet is doing during the time you took the trace.&lt;/p&gt; &lt;p&gt;Other tools are available to analyze the HTTP traffic.&amp;nbsp; Fiddler (ref: &lt;a href="http://fiddlertool.com"&gt;http://fiddlertool.com&lt;/a&gt; ) is an excellent tool that can also allow you to see SSL content as well as performance metrics.&amp;nbsp; You could also use Netmon directly to see network traffic.&amp;nbsp; ETW tracing lets you see into what WinInet is doing however and will allow you a finer grained troubleshooting view along with the network traffic.&amp;nbsp; You can use ETW tracing as another powerful tool in your arsenal to help with HTTP protocol troubleshooting.&amp;nbsp; You can use ETW tracing to analyze HTTPS traffic as well.&amp;nbsp; You cannot see all the content in clear text but you will notice the buffer in the WININET_HTTP_RESPONSE_HEADERS: HTTP Response Headers responses will show the beginnings of the data and show the headers in clear text.&lt;/p&gt; &lt;p&gt;Let me know if this post was useful to you!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9882909" width="1" height="1"&gt;</description></item><item><title>Writing an ISAPI Filter with .NET (Managed Code) will result in poor performance of you ASP.NET web applications</title><link>http://blogs.msdn.com/jpsanders/archive/2009/08/03/writing-an-isapi-filter-with-net-managed-code-is-not-supported-by-microsoft.aspx</link><pubDate>Mon, 03 Aug 2009 16:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9856216</guid><dc:creator>jpsanders</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9856216.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9856216</wfw:commentRss><description>&lt;P&gt;David Wang wrote an excellent post about this in 2006:&amp;nbsp; &lt;A href="http://blogs.msdn.com/david.wang/archive/2006/02/09/Can-I-write-an-ISAPI-Filter-using-Managed-Code.aspx" mce_href="http://blogs.msdn.com/david.wang/archive/2006/02/09/Can-I-write-an-ISAPI-Filter-using-Managed-Code.aspx"&gt;http://blogs.msdn.com/david.wang/archive/2006/02/09/Can-I-write-an-ISAPI-Filter-using-Managed-Code.aspx&lt;/A&gt;&lt;BR&gt;&lt;BR&gt;This includes writing ISAPI code that even USES managed components.&amp;nbsp; Anything that needs to load the CLR will result in poor performance of the ISAPI and worse, result in ASP.NET not functioning correctly.&lt;BR&gt;&lt;BR&gt;ASP.NET loads the CLR when it initializes.&amp;nbsp; During this loading it does many things to configure the CLR.&amp;nbsp; One example is that it creates on GC thread for each processor on the system.&amp;nbsp; It also sets up some defaults for the thread pools.&amp;nbsp; When you write your ISAPI in managed code or include a COM Visible .NET component through COM in your code, your ISAPI loads the CLR.&amp;nbsp; Since only one CLR can be loaded per process, ASP.NET will not create and configure the CLR and you are left with a severely crippled system.&lt;BR&gt;&lt;BR&gt;This problem can also occur if you write an ISAPI Extension.&amp;nbsp; Your Extension could load the CLR runtime if you hit a static file first, initialize the CLR in the ISAPI Extension by using .NET or a COM Visible .NET object and then hit your ASP.NET application after this initialization.&lt;BR&gt;&lt;BR&gt;You can clearly see this in a multi processor machine if you create a filter that uses a Managed code COM component.&amp;nbsp; Without your filter in place, hit an aspx page on the site and use DebugDiag to take a dump of the w3wp.exe process.&amp;nbsp; Then analyze this dump with DebugDiag.&amp;nbsp; You will see a GC thread initialized for each processor core installed on your server.&amp;nbsp; On my server I have a quad proc CPU and I see 4 threads with this in the call stack: mscorwks!SVR::gc_heap::gc_thread_function.&lt;BR&gt;&lt;BR&gt;Then I created a simple ISAPI filter from one of the existing Platform SDK samples and simply instantiated a COM Visible .NET component.&amp;nbsp; I installed the ISAPI filter and re-ran my test.&amp;nbsp; As expected, I saw only 1 thread with mscorwks!SVR::gc_heap::gc_thread_function.&lt;BR&gt;&lt;BR&gt;This problem manifests itself not only with the GC threads but all the information set by the processModel (see &lt;A href="http://msdn.microsoft.com/en-us/library/7w2sway1.aspx" mce_href="http://msdn.microsoft.com/en-us/library/7w2sway1.aspx"&gt;http://msdn.microsoft.com/en-us/library/7w2sway1.aspx&lt;/A&gt;).&amp;nbsp; In theory you could come up with some sort of scheme to read the machine.config file and parse and set this information, but this is untested and definitely not supported (read: you are on your own).&lt;BR&gt;&lt;BR&gt;If you really are in need of writing Managed Code, you should investigate the Managed Pipeline in IIS 7 and use that &lt;A href="http://msdn.microsoft.com/en-us/library/ms227673.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms227673.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms227673.aspx&lt;/A&gt;.&amp;nbsp; There are a couple of other workarounds you could explore like out of proc components etc... but these would all create performance issues for a Filter or Extension.&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;Please let me know if this blog post was useful to you!&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9856216" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/ISAPI/default.aspx">ISAPI</category><category domain="http://blogs.msdn.com/jpsanders/archive/tags/IIS+7/default.aspx">IIS 7</category></item><item><title>WinHttp Proxy configuration on Windows 2003 x64</title><link>http://blogs.msdn.com/jpsanders/archive/2009/07/21/winhttp-proxy-configuration-on-windows-2003-x64.aspx</link><pubDate>Tue, 21 Jul 2009 20:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9843601</guid><dc:creator>jpsanders</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9843601.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9843601</wfw:commentRss><description>&lt;P&gt;You may get an error similar to this when running your WinHttp application:&lt;/P&gt;
&lt;P&gt;Error:&amp;nbsp;The server name or address could not be resolved&lt;BR&gt;Code:&amp;nbsp;80072EE7&lt;BR&gt;Source: &amp;nbsp;WinHttp.WinHttpRequest&lt;/P&gt;
&lt;P&gt;The familiar &lt;A href="http://msdn.microsoft.com/en-us/library/aa384069(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa384069(VS.85).aspx"&gt;ProxyCfg&lt;/A&gt; application allows you to set the proxy settings for WinHttp.&amp;nbsp; However in this case, your&amp;nbsp; application is not picking up the proxy settings.&amp;nbsp; You verify this by setting the Proxy settings to the current user by typing "proxycfg -p myproxyhere" at the command line and you see from a Netmon trace that the proxy is not being utilized.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Further research shows your application is loading the 32 bit version of WinHttp.&amp;nbsp; In Windows 2003 x64, there is a directory for the 32 versions of the system components.&amp;nbsp; You need to run this version for your 32 bit application: c:\windows\sysWow64\proxycfg -p myproxyhere.&amp;nbsp; This fixes the issue.&amp;nbsp; In general, on this platform when using proxycfg.exe, you should run the version in system32 and the version in sysWow64 to ensure you set the proxy setting for both versions of WinHttp on the system.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Side note&amp;nbsp;on WinHttp COM registration on Windows 2003 x64&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;One thing interesting in the default installation of the 64 bit OS is that you will notice WinHttp.dll does not live in either the system32 or the sysWow64 directories.&amp;nbsp; Also, if you look in the registry under HKCR\CLSID you will see no entry for WinHttp.WinHttpRequest.5.1.&amp;nbsp; So how does a script succeed that calls CreateObject() on your progId?&amp;nbsp; The magic here is the SideBySide (SxS) registration of WinHttp.&amp;nbsp; You will notice there are WinHttp Dlls in the C:\WINDOWS\WinSxS\ subdirectories.&amp;nbsp; You will also see in C:\WINDOWS\WinSxS\Manifests there are manifest files and the file names contain WINHTTP in them.&amp;nbsp; Without going into a ton of detail, what happens is CLSIDFromProgID will take the name of the object you are creating and based on the Bitness of the application (64 or 32) there are internal system calls to find the latest version of winhttp and use that for the creation of the object.&lt;/P&gt;
&lt;P&gt;That is why you cannot find the ProgID in the registry!&lt;/P&gt;
&lt;P&gt;Let me know if this blog helped you out by dropping me a comment please!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9843601" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/WinHttp/default.aspx">WinHttp</category></item><item><title>WinInet used in Thread Impersonation</title><link>http://blogs.msdn.com/jpsanders/archive/2009/07/09/wininet-used-in-thread-impersonation.aspx</link><pubDate>Thu, 09 Jul 2009 22:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9827561</guid><dc:creator>jpsanders</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9827561.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9827561</wfw:commentRss><description>&lt;SCRIPT language=jscript&gt;
    function CopyCode(elemName) { var obj = document.getElementById(elemName); window.clipboardData.setData("Text", obj.innerText) }
&lt;/SCRIPT&gt;&lt;font color="#000000" size="2"&gt; &lt;p&gt;First and foremost, this is NOT supported for reasons stated in this article: &lt;a href="http://support.microsoft.com/default.aspx/kb/238425"&gt;http://support.microsoft.com/default.aspx/kb/238425&lt;/a&gt;. Primarily, problems occur because of information that is stored in the HKEY_CURRENT_USERS registry key and because of threading concerns.&amp;nbsp; Furthermore, due to security implications and the design of WinInet in Windows 7, this absolutely will not work in Windows 7.&amp;nbsp; Finally, in Vista, there is a Low IL cache as well as the normal (Medium IL) cache so this sample is ineffective at best.&amp;nbsp; This blog entry is mearly an excercise to help you understand how the Registry works with thread impersonation as I discovered when working on a WinInet problem.&lt;br&gt;&lt;br&gt;That said, if you have a service running in the Local System Account, you might be able to work around some of the problems by ensuring the registry is loaded with the currently logged on user's registry information.&amp;nbsp; If the currently logged on user has used the browser, most information should be populated in that user's registry.&lt;br&gt;&lt;br&gt;If running with UAC enabled and you attempt to enumerate the cache while running under the Local System account you will fail and GetLastError will return ERROR_INVALID_PARAMETER. This error is thrown because internally there are some registry settings missing that WinInet expects to be there for every user (again, WinInet is not designed, tested or supported when running under the System Account or when using thread impersonation).&amp;nbsp; I found however if you use thread impersonation and load the registry HKCU for the currently logged on user, you can access the cache.&amp;nbsp; I do not know if this will work in all scenarios and in future WinInet releases, but I was able to get it to work for me.&amp;nbsp; I used PsExec from Sysinternals to run my tests.&lt;br&gt;&lt;br&gt;&lt;strong&gt;Details&lt;br&gt;&lt;/strong&gt;I downloaded and installed PsExec from &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx" mce_href="http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx"&gt;http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx&lt;/a&gt;&lt;br&gt;&lt;br&gt;I created a new C++ Console application in Visual Studio and added code to:&lt;br&gt;1. Get the Currently Logged on user token in the SessionID from where this program was launched under the SYSTEM account using WTSQueryUserToken&lt;br&gt;2. Impersonate this user using ImpersonateLoggedOnUser&lt;br&gt;3. Load the impersonated HKU registry in HKCU by using RegDisablePredefinedCache&lt;br&gt;4. Iterate through the IE cache using FindFirstUrlCacheEntry and FindNextUrlCacheEntry&lt;br&gt;5. I added code that would also show the cache if the WTSQueryUserToken failed.&amp;nbsp; This will fail if you are running the program from the command line (no PsExec).&amp;nbsp; This allows you to see the case running in the context of the current user.&amp;nbsp; &lt;br&gt;&lt;br&gt;I then added the WinInet.lib and Wtsapi32.lib to the linker input files and built the project.&lt;br&gt;&lt;br&gt;I then tested the code with PsExec using: PsExec –i –s &amp;lt;&amp;lt;full path and program name&amp;gt;&amp;gt;.&amp;nbsp; I opened a command prompt with Administrator permissions to run the tests.&amp;nbsp; An interesting use of PsExec allows you to see the cache when running as an Low IL process:&amp;nbsp; PsExec –l &amp;lt;&amp;lt;full path and program name&amp;gt;&amp;gt;.&amp;nbsp; Note that this is a different set of values because the Low IL cache is in a different location then the Medium (normal) IL cache.&lt;br&gt;For details on protected mode cache see: &lt;a href="http://blogs.msdn.com/ie/archive/2006/02/09/528963.aspx" mce_href="http://blogs.msdn.com/ie/archive/2006/02/09/528963.aspx"&gt;http://blogs.msdn.com/ie/archive/2006/02/09/528963.aspx&lt;/a&gt;&lt;br&gt;&lt;/p&gt; &lt;p&gt;Here is the code for your enjoyment.&amp;nbsp; Of course you would need to add your code to test the success of calls, trap exceptions etc...&amp;nbsp; But it should get you started:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;C++ code listing for sample (&lt;a href="javascript:CopyCode('WinInetImpersonate1');"&gt;Copy Code&lt;/a&gt;):&lt;/strong&gt;&lt;/p&gt; &lt;div style="background-color: #e0e0e0" id="WinInetImpersonate1"&gt; &lt;p&gt;&lt;font color="#008000" size="2"&gt;// ImpersonateWinInet.cpp : Defines the entry point for the console application.&lt;br&gt;// &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#0000ff" size="2"&gt;#include &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;"stdafx.h"&lt;/font&gt;&lt;br&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;#include&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&amp;lt;windows.h&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;#include&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&amp;lt;WinInet.h&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;#pragma&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;comment&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;lib&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;, &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"WinInet.lib"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;#include&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&amp;lt;Wtsapi32.h&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;#pragma&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;comment&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;lib&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;, &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"Wtsapi32.lib"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;#include&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&amp;lt;iostream&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;#include&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&amp;lt;conio.h&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;// for _getch&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;int&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; showCache()&lt;br&gt;&lt;/font&gt;&lt;font size="2"&gt;{&lt;br&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // another gotcha... The actual cache hit here depends on the IL that the program is running under.&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // to see this run psexec with the -l option in a cmd prompt&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Local variables&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;DWORD cacheEntryInfoBufferSizeInitial = 0;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;DWORD cacheEntryInfoBufferSize = 0;&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;int&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; *cacheEntryInfoBuffer = 0;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;INTERNET_CACHE_ENTRY_INFO *internetCacheEntry;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;HANDLE enumHandle = NULL;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;BOOL returnValue = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;false&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;int&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; aiNumEntries=0;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;DWORD dwError;&lt;br&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // get the size of the buffer required&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;enumHandle = FindFirstUrlCacheEntry(NULL, 0, &amp;amp;cacheEntryInfoBufferSizeInitial);&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (enumHandle == NULL &amp;amp;&amp;amp; ERROR_NO_MORE_ITEMS == GetLastError())&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; aiNumEntries;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;cacheEntryInfoBufferSize = cacheEntryInfoBufferSizeInitial;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;internetCacheEntry = (INTERNET_CACHE_ENTRY_INFO *)malloc(cacheEntryInfoBufferSize);&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;enumHandle = FindFirstUrlCacheEntry(NULL, internetCacheEntry, &amp;amp;cacheEntryInfoBufferSizeInitial);&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (enumHandle == NULL)&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::cout &amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"could not get first URL entry. Error :"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &amp;lt;&amp;lt; GetLastError();&lt;br&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ERROR_INVALID_PARAMETER is thrown because of incorrect registry info&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; aiNumEntries;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;returnValue=&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;while&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;(1)&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;cacheEntryInfoBufferSizeInitial = cacheEntryInfoBufferSize; &lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (returnValue)&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (internetCacheEntry != NULL)&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::wcout&amp;lt;&amp;lt;(LPWSTR)((INTERNET_CACHE_ENTRY_INFO *)internetCacheEntry-&amp;gt;lpszSourceUrlName)&amp;lt;&amp;lt; _T(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"\r\n"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;);&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;returnValue = FindNextUrlCacheEntry(enumHandle, internetCacheEntry, &amp;amp;cacheEntryInfoBufferSizeInitial);&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;aiNumEntries++;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;else&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // this should not happen!&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;break&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;dwError = GetLastError();&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (!returnValue &amp;amp;&amp;amp; ERROR_NO_MORE_ITEMS == dwError)&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;break&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;; &lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;//now more items!&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // if buffer not big enough, grow it &lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (!returnValue &amp;amp;&amp;amp; cacheEntryInfoBufferSizeInitial &amp;gt; cacheEntryInfoBufferSize)&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;cacheEntryInfoBufferSize = cacheEntryInfoBufferSizeInitial;&lt;br&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // note test for buffer here (OOM condition)&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;internetCacheEntry = (INTERNET_CACHE_ENTRY_INFO *)realloc(internetCacheEntry, cacheEntryInfoBufferSize);&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;returnValue = FindNextUrlCacheEntry(enumHandle, internetCacheEntry, &amp;amp;cacheEntryInfoBufferSizeInitial); &lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;free(internetCacheEntry);&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::wcout&amp;lt;&amp;lt;_T(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"Number of entries processed: "&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)&amp;lt;&amp;lt;aiNumEntries&amp;lt;&amp;lt;_T(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"\r\n"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;);&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; aiNumEntries;&lt;br&gt;}&lt;/p&gt; &lt;p mce_keep="true"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;int&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; _tmain(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;int&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; argc, _TCHAR* argv[])&lt;br&gt;{&lt;br&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // note, this below will get the session id that this program was run from.&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;DWORD dwActiveSessionId = WTS_CURRENT_SESSION;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;HANDLE hUserToken = INVALID_HANDLE_VALUE;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;DWORD dwErr=0;&lt;/p&gt; &lt;p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //showCache();&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;BOOL bSuccess = WTSQueryUserToken(dwActiveSessionId, &amp;amp;hUserToken);&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (bSuccess)&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::cout &amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"Got User Token\r\n"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;bSuccess = ::ImpersonateLoggedOnUser(hUserToken);&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (bSuccess)&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::cout &amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"Impersonating\r\n"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This is necessary because we want to load the impersonated user registry into HKCU&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // comment this out whey running under the system acct and you will get ERROR_INVALID_PARAMETER&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;( ERROR_SUCCESS==RegDisablePredefinedCache())&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;showCache();&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;CloseHandle(hUserToken);&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;else&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::cout &amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"Failed Impersonation\r\n"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;else&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::cout &amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"Did not Get User Token\r\n"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;dwErr= ::GetLastError();&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::cout &amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"Error"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &amp;lt;&amp;lt; dwErr &amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"\r\n"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (ERROR_PRIVILEGE_NOT_HELD==dwErr)&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::cout &amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"To call WTSQueryUserToken successfully, the calling application must be running within the context of the LocalSystem account and have the SE_TCB_NAME privilege\r\n"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::cout &amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"Trying in the context of the user running this program...\r\n"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::cout &amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"Hit a key or enter to start"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;_getch();&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;showCache();&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;/p&gt; &lt;p&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;std::cout&amp;lt;&amp;lt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"Hit a key or enter to exit"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;br&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;_getch();&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 0;&lt;br&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt; &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font size="2"&gt;I hope this sample helps you out.&amp;nbsp; Please drop me a comment if you found this useful!&lt;/p&gt;&lt;/font&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9827561" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/WinInet/default.aspx">WinInet</category></item><item><title>Understanding Connection Limits and New Proxy Connection Limits in WinInet and Internet Explorer </title><link>http://blogs.msdn.com/jpsanders/archive/2009/06/29/understanding-connection-limits-and-new-proxy-connection-limits-in-wininet-and-internet-explorer.aspx</link><pubDate>Mon, 29 Jun 2009 18:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9808655</guid><dc:creator>jpsanders</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9808655.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9808655</wfw:commentRss><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Because of RFC 2616 section 8.1.4 (&lt;A href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html" mce_href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html"&gt;http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html&lt;/A&gt;) we have traditionally limited the number of persistent connections to 2 per server.&amp;nbsp; This is because of the strong language in this RFC: " A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy."&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Practically speaking with today's modern web servers, there is no reason for such a small number of client connections to a server.&amp;nbsp; This is especially true with the rich WebPages and WebBased applications hosted in WebPages.&amp;nbsp; Indeed, at times you can get into a situation where you are attempting to download resources for a WebPage and a script is executed to download additional data giving the appearance of a web browser.&amp;nbsp; The ability to download several resources simultaneously has huge advantages when it comes to downloading resources quickly and gives the ability to provide a more responsive web experience.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;While you could always change the number of connections WinInet (and Internet Explorer) used by default, in the past, you could not also control the number of Proxy Connections separately (also covered in RFC 2616).&amp;nbsp;&amp;nbsp;There is now a setting that will&amp;nbsp;allow you to set the&amp;nbsp;proxy connection limit independent from the&amp;nbsp;number of persistent connections to a server.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Here is a brief Q&amp;amp;A I put together to help you get your head around these settings:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;What does setting the max Server and Proxy connections do?&amp;nbsp; This limits the number of possible connection at one time to a given host either direct or through a proxy.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;What happens if I try to make 4 connections and the default number of persistent connections&amp;nbsp;(proxy or server) is set to 2?&amp;nbsp; Two connections will be made and two will be put in a queue to ‘wait’ for an available connection to be freed.&amp;nbsp; Once one of the first two connections gets a response, another ‘waiting’ connection will use that available connection in a FIFO manner.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;If my app has 2 requests to one host and 2 to another, does that mean only 2 connections at a time will be used total, and there will be two connections waiting?&amp;nbsp; No, this means that 2 connections per host will be used so in this example there will be no connections waiting.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Why limit the proxy connections in WinInet to begin with?&amp;nbsp; We always have as a function of limiting the HTTP connections to the end point server.&amp;nbsp; We did this because the RFC 2616 tells us to:&lt;BR&gt;&lt;A href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html" mce_href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html"&gt;http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html&lt;/A&gt;&amp;nbsp; (see 8.1.4 Practical Considerations)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Why add a new limit for the proxy connections?&amp;nbsp; In the event you need to customize the number of proxy connections.&amp;nbsp; The default is set to 4 which is enough to satisfy the defaults for WinInet which is 2 for HTTP 1.1 servers and 4 for HTTP 1.0 servers.&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;What was it before?&amp;nbsp; The value did not exist before so it is the same as the server settings.&amp;nbsp;&amp;nbsp;If the proxy was Http 1.0 it was 4.&amp;nbsp; If it was http 1.1 it was 2.&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;What if I want to have more server connections, should I also set the MaxConnections to proxy to follow this?&amp;nbsp; No!&amp;nbsp; The number of proxy connections will automatically follow the MaxConnections for the server, your application should probably do the same.&amp;nbsp; In most cases (unless your proxy has some other strange requirement) it should be the same as your server connections.&amp;nbsp; If for some reason you want this different then set the MaxConnectionsPerProxy manually.&amp;nbsp; If you do not have a reason for this to be different then do not use this setting.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;How do I set the MaxConnectionsPerProxy?&amp;nbsp; Either in Code (see this blog: &lt;A href="http://blogs.msdn.com/jpsanders/archive/2009/06/08/understanding-the-new-wininet-option-internet-option-max-conns-per-proxy.aspx" mce_href="http://blogs.msdn.com/jpsanders/archive/2009/06/08/understanding-the-new-wininet-option-internet-option-max-conns-per-proxy.aspx"&gt;http://blogs.msdn.com/jpsanders/archive/2009/06/08/understanding-the-new-wininet-option-internet-option-max-conns-per-proxy.aspx&lt;/A&gt;) or with this registry setting:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base: &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;322756&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;(&lt;A href="http://support.microsoft.com/kb/322756/" mce_href="http://support.microsoft.com/kb/322756/"&gt;&lt;FONT color=#0000ff&gt;http://support.microsoft.com/kb/322756/&lt;/FONT&gt;&lt;/A&gt;) How to back up and restore the registry in Windows&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;To change the number of files that you can download through your proxy at one time to 2, follow these steps:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN-LEFT: 0.5in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: Arial"&gt;&lt;SPAN style="mso-list: Ignore"&gt;1.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Start Registry Editor.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN-LEFT: 0.5in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: Arial"&gt;&lt;SPAN style="mso-list: Ignore"&gt;2.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Locate the following key in the registry:&lt;BR&gt;HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN-LEFT: 0.5in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: Arial"&gt;&lt;SPAN style="mso-list: Ignore"&gt;3.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;On the Edit menu, point to New, click DWORD Value, and then add the following registry values: &lt;BR&gt;Value name: MaxConnectionsPerProxy&lt;BR&gt;Value data: 2&lt;BR&gt;Base: Decimal&lt;BR style="mso-special-character: line-break"&gt;&lt;BR style="mso-special-character: line-break"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN-LEFT: 0.5in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: Arial"&gt;&lt;SPAN style="mso-list: Ignore"&gt;4.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Exit Registry Editor.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN-LEFT: 0.5in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;
&lt;P&gt;Let me know if this article was useful to you!&lt;/P&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9808655" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/WinInet/default.aspx">WinInet</category><category domain="http://blogs.msdn.com/jpsanders/archive/tags/Internet+Explorer/default.aspx">Internet Explorer</category></item><item><title>InfoPath form and other xml Office documents do not open from Internet Explorer - Raw XML displays instead</title><link>http://blogs.msdn.com/jpsanders/archive/2009/06/11/infopath-form-and-other-xml-office-documents-do-not-open-from-internet-explorer-raw-xml-displays-instead.aspx</link><pubDate>Thu, 11 Jun 2009 16:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9726619</guid><dc:creator>jpsanders</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9726619.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9726619</wfw:commentRss><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;I came across this problem.&amp;nbsp; The key to this was that the documents opened fine when clicking on them, so I knew the Office installation itself was fine.&amp;nbsp; Some rogue application on install or removal had apparently removed the appropriate Content Type registry key so Internet Explorer was unable to associate the XML file extension with any application.&amp;nbsp; Restoring the default OS registry entry allowed everything to start functioning again.&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Warning, modify the registry at your own risk.&amp;nbsp; Microsoft cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. Use Registry Editor at your own risk. &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Windows Registry Editor Version 5.00&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;[HKEY_CLASSES_ROOT\.xml]&lt;BR&gt;"Content Type"="text/xml"&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Why did this rogue deletion of this registry key affect IE but not the InfoPath application itself?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Since all the registry entries for the application were correct the associations in the registry for opening the file are in place.&amp;nbsp; The issue is that with the 'Content Type' entry missing, Internet Explorer (more precisely&amp;nbsp;Urlmon used by IE)&amp;nbsp;is unable to determine what to do with this particular Content Type (XML).&amp;nbsp;When this key is correct, this MIME type is found in the MIME Database registry location and the appropriate application can be invoked.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Since Office is installed the file will be passed to MSOXMLED.EXE which will determine the correct application to invoke by looking inside the XML for the appropriate entry indicating what application that particular&amp;nbsp;XML is associated with.&amp;nbsp; For example: &amp;lt;?mso-application progid="Word.Document"?&amp;gt; indicates that this is a Word Document.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Let me know if this&amp;nbsp;blog helped you by dropping me a note!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9726619" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/Internet+Explorer/default.aspx">Internet Explorer</category></item><item><title>Some .chm files do not work on Windows 7 - Process Monitor - Navigation to the webpage was canceled</title><link>http://blogs.msdn.com/jpsanders/archive/2009/06/10/some-chm-files-do-not-work-on-windows-7-process-monitor-navigation-to-the-webpage-was-canceled.aspx</link><pubDate>Wed, 10 Jun 2009 17:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9724264</guid><dc:creator>jpsanders</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9724264.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9724264</wfw:commentRss><description>&lt;P&gt;This took me a couple of minutes to find so I thought I would share this here.&lt;/P&gt;
&lt;P&gt;I downloaded ProcMon (process monitor) and could view the help file.&amp;nbsp; It would open but the right pane had a message: "Navigation to the webpage was canceled"&amp;nbsp; The left pane was functional however.&lt;/P&gt;
&lt;P&gt;I found the help file.&amp;nbsp; This is a .CHM file stored in the directory where Procmon was installed.&lt;/P&gt;
&lt;P&gt;To be able to use is, Right Click on the procmon.chm file and in the&amp;nbsp;general tab, click on Unblock!&lt;/P&gt;
&lt;P&gt;Works fine now!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Let me know if you found this useful by dropping me a note please!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9724264" width="1" height="1"&gt;</description></item><item><title>WWSAPI samples in Windows 7 SDK for RC: "Unable to add URL to HTTP URL group." </title><link>http://blogs.msdn.com/jpsanders/archive/2009/06/09/wwsapi-samples-in-windows-7-sdk-for-rc-unable-to-add-url-to-http-url-group.aspx</link><pubDate>Tue, 09 Jun 2009 16:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9715990</guid><dc:creator>jpsanders</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jpsanders/comments/9715990.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jpsanders/commentrss.aspx?PostID=9715990</wfw:commentRss><description>&lt;P&gt;I like to build and run&amp;nbsp;with&amp;nbsp;UAC on.&amp;nbsp; When&amp;nbsp;running the HttpCalculatorService example I got this error:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Failure: errorCode=0x80070005&lt;BR&gt;Unable to add URL to HTTP URL group.&lt;BR&gt;Access is denied.&lt;BR&gt;&lt;BR&gt;Running from an administrator command prompt I do not get the error!&lt;/P&gt;
&lt;P&gt;Obviously I do not have permissions to something.&amp;nbsp; Some investigation revealed that I need to add the user I wanted to run as to the urlacl (&lt;A href="http://msdn.microsoft.com/en-us/library/cc307223(vs.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/cc307223(vs.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/cc307223(vs.85).aspx&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;So this is the command that allowd me to run (replace myDOMAIN\myUSERNAME with the domain and user you wish to run the Service under): netsh http add urlacl url=http://+:80/example user=myDOMAIN\myUSERNAME.&lt;/P&gt;
&lt;P&gt;To do this in code you could use this API: &lt;A href="http://msdn.microsoft.com/en-us/library/aa364503(VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/aa364503(VS.85).aspx&lt;/A&gt;&amp;nbsp;but the code your are running would need to have the necessary permissions so you are in kind of a chicken and the egg situation!&lt;/P&gt;
&lt;P&gt;Drop me&amp;nbsp;a comment and let me know if this helped you please!&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9715990" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jpsanders/archive/tags/WWSAPI/default.aspx">WWSAPI</category></item></channel></rss>