<?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>Decrypt my World : Server 2008</title><link>http://blogs.msdn.com/alejacma/archive/tags/Server+2008/default.aspx</link><description>Tags: Server 2008</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>SubAuthentication package gets Zero LogonId</title><link>http://blogs.msdn.com/alejacma/archive/2009/09/01/subauthentication-package-gets-zero-logonid.aspx</link><pubDate>Tue, 01 Sep 2009 16:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9889842</guid><dc:creator>alejacma</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/9889842.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=9889842</wfw:commentRss><description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;The other day I worked on an issue related to a &lt;STRONG&gt;SubAuthentication package&lt;/STRONG&gt; that one of my customers had developed. One of the things that package was doing was getting the &lt;STRONG&gt;LogonId field&lt;/STRONG&gt; of the &lt;STRONG&gt;LogonInformation struct&lt;/STRONG&gt; being passed to &lt;STRONG&gt;Msv1_0SubAuthenticationFilter method&lt;/STRONG&gt; by the Authentication package.&lt;/P&gt;
&lt;P&gt;This SubAuth package had been working fine on i.e. Windows XP, but when doing interactive logon on a &lt;STRONG&gt;Windows Server 2003 Domain Controller&lt;/STRONG&gt;, &lt;STRONG&gt;LogonId&lt;/STRONG&gt; field was &lt;STRONG&gt;always set to Zero&lt;/STRONG&gt;. But doing i.e. Network logon on the same DC returned a valid LogonId value. Why?&lt;/P&gt;
&lt;P&gt;I debugged the issue and I found out what was going on.&lt;/P&gt;
&lt;P&gt;SubAuth packages can only get called by the following &lt;STRONG&gt;Authentication packages&lt;/STRONG&gt;: &lt;A href="http://msdn.microsoft.com/en-us/library/aa377942(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa377942(VS.85).aspx"&gt;Kerberos&lt;/A&gt; or &lt;A href="http://msdn.microsoft.com/en-us/library/aa378753(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa378753(VS.85).aspx"&gt;MSV1_0/NTLM&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;MSV1_0 (MICROSOFT_AUTHENTICATION_PACKAGE_V1_0) package will provide our SubAuth dll with LogonId info, while Kerberos package won’t. &lt;STRONG&gt;Kerberos ignores LogonId&lt;/STRONG&gt; on purpose. This is &lt;STRONG&gt;by design&lt;/STRONG&gt; and happens in &lt;STRONG&gt;all versions of Windows&lt;/STRONG&gt;. &lt;/P&gt;
&lt;P&gt;So every time we get a valid LogonId, it is because logon is taking place through MSV1_0 Auth package. Note that LogonId is just a local ID on the machine and it's not of actual use for SubAuth packages.&lt;STRONG&gt; The purpose of SubAuth packages is not for capturing or tracking logon activities&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;SubAuth package supplements part of the authentication and validation criteria used by the main Auth package. It can&lt;STRONG&gt; enforce additional restrictions to the authentication sequence&lt;/STRONG&gt; when the DLL is registered under Auth0 registry value for MSV1_0 or Kerberos.&lt;/P&gt;
&lt;P&gt;SubAuth package (Msv1_0SubAuthenticationFilter) will get called only after the corresponding Windows logon authentication is successful. The built-in Auth packages get first chance at logon authentication, before SubAuth DLL code gets invoked.&lt;/P&gt;
&lt;P&gt;For domain user logon authentication, SubAuth DLLs installed on the DCs of that domain will be called. For local user logon authentication, SubAuth DLLs installed on that member machine will be called.&lt;/P&gt;
&lt;P&gt;If you are simply &lt;STRONG&gt;tracking logon events&lt;/STRONG&gt;, you would need to &lt;STRONG&gt;enable Auditing Account Logon&lt;/STRONG&gt; and &lt;STRONG&gt;look for events logged in the Security Event Log&lt;/STRONG&gt;. Audit logon events and Audit account logon events provide tracking of logons at workstations, servers, and DCs (see &lt;A href="http://technet.microsoft.com/en-us/library/bb742435.aspx" mce_href="http://technet.microsoft.com/en-us/library/bb742435.aspx"&gt;Audit Account Logon Events&lt;/A&gt;&amp;nbsp;for details).&lt;/P&gt;
&lt;P&gt;Then an application may get those events programmatically with i.e. WMI and its &lt;STRONG&gt;Win32_NTLogEvent&lt;/STRONG&gt; class. I’ve seen people using this idea, for instance &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/0c1bded8-0cce-4260-bd28-4b4ffce0d27d" mce_href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/0c1bded8-0cce-4260-bd28-4b4ffce0d27d"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;There is one thing left to explain. &lt;STRONG&gt;Why is Kerberos always getting used on the DC when doing Interactive logon?&lt;/STRONG&gt; We've already seen the Auth packages that can get used, and according to MSDN: &lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/aa377942(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa377942(VS.85).aspx"&gt;Kerberos&lt;/A&gt;&lt;BR&gt;"&lt;BR&gt;The Kerberos authentication package is used when logging on to a network; local logons are handled by MSV1_0.&lt;BR&gt;"&lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/aa378753(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa378753(VS.85).aspx"&gt;MSV1_0&lt;/A&gt;&lt;BR&gt;"&lt;BR&gt;MSV1_0 also supports domain logons. MSV1_0 processes domain logons using pass-through authentication&lt;BR&gt;"&lt;/P&gt;
&lt;P&gt;Summing up, MSV1_0 deals with local logons and both MSV1_0 and Kerberos with network logons.&lt;/P&gt;
&lt;P&gt;Now, whether Negotiate/Kerberos or NTLM/MSV1_0 is used for network logon depends on the client machine and the component that is doing the authentication. Windows logon components will always attempt to use Kerberos if they can, if there is an SPN (&lt;A href="http://msdn.microsoft.com/en-us/library/ms677949(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms677949(VS.85).aspx"&gt;Service Principal Name&lt;/A&gt;) for the target name specified. For example,&amp;nbsp;if you are accessing a server say MYSERVER that requires windows authentication and you want to use Kerberos, you have to supply a name that matches an SPN defined on the server account such as MYSERVER.MYDOMAIN.COM. Just specifying MYSERVER may use NTLM if there is no matching SPN. If there is no matching SPN, Kerberos will fall-back to NTLM.&lt;/P&gt;
&lt;P&gt;So in my customer's environment we ended up using NTLM/MSV1_0 with network logons and most of local logons, thus getting a valid LogonId thanks to MSV1_0 Auth package.&lt;/P&gt;
&lt;P&gt;Now, the exception for local logons are the DCs. Local logon is for local accounts only and not for AD (Active Directory) accounts. &lt;STRONG&gt;Doing an Interactive logon on a DC is not considered a local logon.&lt;/STRONG&gt; Because of that we try to use Negotiate/Kerberos first as expected, and we just succeed. And we don't get LogonId because Kerberos Auth package won't provide us with it.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;BR&gt;Regards,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex (Alejandro Campos Magencio)&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;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9889842" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/Vista/default.aspx">Vista</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Server+2008/default.aspx">Server 2008</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/XP/default.aspx">XP</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Server+2003/default.aspx">Server 2003</category></item><item><title>Controls won't get resized once the nesting hierarchy of windows exceeds a certain depth (x64)</title><link>http://blogs.msdn.com/alejacma/archive/2009/08/11/controls-won-t-get-resized-once-the-nesting-hierarchy-of-windows-exceeds-a-certain-depth-x64.aspx</link><pubDate>Wed, 12 Aug 2009 01:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9129671</guid><dc:creator>alejacma</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/9129671.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=9129671</wfw:commentRss><description>&lt;P&gt;Hi all, welcome back,&lt;/P&gt;
&lt;P&gt;I've been working on an issue where &lt;STRONG&gt;WM_SIZE&lt;/STRONG&gt; events are &lt;STRONG&gt;not properly generated&lt;/STRONG&gt; once the &lt;STRONG&gt;nesting&lt;/STRONG&gt; &lt;STRONG&gt;hierarchy of windows&lt;/STRONG&gt; exceeds a certain depth. This issue only occurs on current &lt;STRONG&gt;x64 Windows&lt;/STRONG&gt;:&amp;nbsp;like XP, Server 2008 or the latest Windows 7. &lt;/P&gt;
&lt;P&gt;For ilustration purposes, let's imagine we have a &lt;STRONG&gt;C#&lt;/STRONG&gt; application which creates a hierarchy of &lt;STRONG&gt;nested panels&lt;/STRONG&gt;. Panels' OnSize handler resize their child panel so that it has the same size as the parent panel minus a border frame:&lt;/P&gt;&lt;PRE&gt;protected override void &lt;STRONG&gt;OnSizeChanged&lt;/STRONG&gt;(System.EventArgs ea)
{
  if (childPanel != null)
  {
    &lt;STRONG&gt;childPanel.Size = new Size&lt;/STRONG&gt;(
    this.ClientSize.Width - 2 * childPanel.Left,
    this.ClientSize.Height - 2 * childPanel.Top);
  }

  base.OnResize(ea);
}
&lt;/PRE&gt;
&lt;P&gt;We have around 30 nested panels. If we resize the main dialog, only the first 12-15 panels will get resized along with it. The &lt;STRONG&gt;OnSizeChanged&lt;/STRONG&gt; method of the smaller panels is &lt;STRONG&gt;not getting called&lt;/STRONG&gt; at all. On x86, all panels get resized, though.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, this behavior that we are experiencing is a &lt;STRONG&gt;design limitation on Windows kernel&lt;/STRONG&gt;.&amp;nbsp;Let's see this in greater detail.&lt;/P&gt;
&lt;P&gt;In this sample application, this is how the &lt;STRONG&gt;call stack&lt;/STRONG&gt; looks after several calls to &lt;STRONG&gt;WindowsApplication1!WindowsApplication1.Form1+MyPanel.OnSizeChanged&lt;/STRONG&gt;:&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE&gt;0:000&amp;gt; kL100
Child-SP RetAddr Call Site
00000000`002589f8 00000642`7605eb0b &lt;STRONG&gt;WindowsApplication1!WindowsApplication1.Form1+MyPanel.OnSizeChanged&lt;/STRONG&gt;(System.EventArgs)
00000000`00258a00 00000642`7605e77c System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds(Int32, Int32, Int32, Int32, Int32, Int32)+0x10b
00000000`00258a80 00000642`7606fcbc System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds()+0x2bc
00000000`00258ba0 00000642`7605d44b System_Windows_Forms_ni!System.Windows.Forms.Control.WmWindowPosChanged(System.Windows.Forms.Message ByRef)+0x3c
00000000`00258c10 00000642`7605d182 System_Windows_Forms_ni!System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)+0x27b
00000000`00258dc0 00000642`7605cff5 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc&lt;/STRONG&gt;(System.Windows.Forms.Message ByRef)+0x52
00000000`00258e10 00000642`76278bd9 System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)+0xb5
00000000`00258ec0 00000642`7f67945a System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(Int64, Int32, Int64, Int64)+0x29
00000000`00258f00 00000000`76f73ee2 mscorwks!UMThunkStubAMD64+0x7a
00000000`00258f90 00000000`76f7bf9b USER32!UserCallWinProcCheckWow+0x163
00000000`00259050 00000000`76f73789 USER32!DispatchClientMessage+0xc3
00000000`002590b0 00000000`770759a6 USER32!__fnINLPWINDOWPOS+0x2d
00000000`00259110 00000000`76f73a5a &lt;STRONG&gt;ntdll!KiUserCallbackDispatcherContinue&lt;/STRONG&gt;
00000000`002591b8 00000642`7f67b167 &lt;STRONG&gt;USER32!ZwUserSetWindowPos&lt;/STRONG&gt;+0xa
00000000`002591c0 00000642`7606fbd3 mscorwks!DoNDirectCall__PatchGetThreadCall+0x7b
00000000`00259280 00000642`76067ae1 System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, Int32, Int32, Int32, Int32, Int32)+0xa3
00000000`00259360 00000642`7606764e System_Windows_Forms_ni!System.Windows.Forms.Control.SetBoundsCore(Int32, Int32, Int32, Int32, System.Windows.Forms.BoundsSpecified)+0x251
00000000`00259470 00000642`76067423 System_Windows_Forms_ni!System.Windows.Forms.Control.SetBounds(Int32, Int32, Int32, Int32, System.Windows.Forms.BoundsSpecified)+0xae
00000000`002594e0 00000642`80150b74 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control.set_Size&lt;/STRONG&gt;(System.Drawing.Size)+0x33
00000000`00259520 00000642`7605eb0b &lt;STRONG&gt;WindowsApplication1!WindowsApplication1.Form1+MyPanel.OnSizeChanged&lt;/STRONG&gt;(System.EventArgs)+0x1d4
00000000`002595e0 00000642`7605e77c System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds(Int32, Int32, Int32, Int32, Int32, Int32)+0x10b
00000000`00259660 00000642`7606fcbc System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds()+0x2bc
00000000`00259780 00000642`7605d44b System_Windows_Forms_ni!System.Windows.Forms.Control.WmWindowPosChanged(System.Windows.Forms.Message ByRef)+0x3c
00000000`002597f0 00000642`7605d182 System_Windows_Forms_ni!System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)+0x27b
00000000`002599a0 00000642`7605cff5 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc&lt;/STRONG&gt;(System.Windows.Forms.Message ByRef)+0x52
00000000`002599f0 00000642`76278bd9 System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)+0xb5
00000000`00259aa0 00000642`7f67945a System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(Int64, Int32, Int64, Int64)+0x29
00000000`00259ae0 00000000`76f73ee2 mscorwks!UMThunkStubAMD64+0x7a
00000000`00259b70 00000000`76f7bf9b USER32!UserCallWinProcCheckWow+0x163
00000000`00259c30 00000000`76f73789 USER32!DispatchClientMessage+0xc3
00000000`00259c90 00000000`770759a6 USER32!__fnINLPWINDOWPOS+0x2d
00000000`00259cf0 00000000`76f73a5a &lt;STRONG&gt;ntdll!KiUserCallbackDispatcherContinue&lt;/STRONG&gt;
00000000`00259d98 00000642`7f67b167 &lt;STRONG&gt;USER32!ZwUserSetWindowPos&lt;/STRONG&gt;+0xa
00000000`00259da0 00000642`7606fbd3 mscorwks!DoNDirectCall__PatchGetThreadCall+0x7b
00000000`00259e60 00000642`76067ae1 System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, Int32, Int32, Int32, Int32, Int32)+0xa3
00000000`00259f40 00000642`7606764e System_Windows_Forms_ni!System.Windows.Forms.Control.SetBoundsCore(Int32, Int32, Int32, Int32, System.Windows.Forms.BoundsSpecified)+0x251
00000000`0025a050 00000642`76067423 System_Windows_Forms_ni!System.Windows.Forms.Control.SetBounds(Int32, Int32, Int32, Int32, System.Windows.Forms.BoundsSpecified)+0xae
00000000`0025a0c0 00000642`80150b74 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control.set_Size&lt;/STRONG&gt;(System.Drawing.Size)+0x33
00000000`0025a100 00000642`7605eb0b &lt;STRONG&gt;WindowsApplication1!WindowsApplication1.Form1+MyPanel.OnSizeChanged&lt;/STRONG&gt;(System.EventArgs)+0x1d4
00000000`0025a1c0 00000642`7605e77c System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds(Int32, Int32, Int32, Int32, Int32, Int32)+0x10b
00000000`0025a240 00000642`7606fcbc System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds()+0x2bc
00000000`0025a360 00000642`7605d44b System_Windows_Forms_ni!System.Windows.Forms.Control.WmWindowPosChanged(System.Windows.Forms.Message ByRef)+0x3c
00000000`0025a3d0 00000642`7605d182 System_Windows_Forms_ni!System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)+0x27b
00000000`0025a580 00000642`7605cff5 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc&lt;/STRONG&gt;(System.Windows.Forms.Message ByRef)+0x52
00000000`0025a5d0 00000642`76278bd9 System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)+0xb5
00000000`0025a680 00000642`7f67945a System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(Int64, Int32, Int64, Int64)+0x29
00000000`0025a6c0 00000000`76f73ee2 mscorwks!UMThunkStubAMD64+0x7a
00000000`0025a750 00000000`76f7bf9b USER32!UserCallWinProcCheckWow+0x163
00000000`0025a810 00000000`76f73789 USER32!DispatchClientMessage+0xc3
00000000`0025a870 00000000`770759a6 USER32!__fnINLPWINDOWPOS+0x2d
00000000`0025a8d0 00000000`76f73a5a &lt;STRONG&gt;ntdll!KiUserCallbackDispatcherContinue&lt;/STRONG&gt;
00000000`0025a978 00000642`7f67b167 &lt;STRONG&gt;USER32!ZwUserSetWindowPos&lt;/STRONG&gt;+0xa
00000000`0025a980 00000642`7606fbd3 mscorwks!DoNDirectCall__PatchGetThreadCall+0x7b
00000000`0025aa40 00000642`76067ae1 System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, Int32, Int32, Int32, Int32, Int32)+0xa3
00000000`0025ab20 00000642`7606764e System_Windows_Forms_ni!System.Windows.Forms.Control.SetBoundsCore(Int32, Int32, Int32, Int32, System.Windows.Forms.BoundsSpecified)+0x251
00000000`0025ac30 00000642`76067423 System_Windows_Forms_ni!System.Windows.Forms.Control.SetBounds(Int32, Int32, Int32, Int32, System.Windows.Forms.BoundsSpecified)+0xae
00000000`0025aca0 00000642`80150b74 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control.set_Size&lt;/STRONG&gt;(System.Drawing.Size)+0x33
00000000`0025ace0 00000642`7605eb0b &lt;STRONG&gt;WindowsApplication1!WindowsApplication1.Form1+MyPanel.OnSizeChanged&lt;/STRONG&gt;(System.EventArgs)+0x1d4
00000000`0025ada0 00000642`7605e77c System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds(Int32, Int32, Int32, Int32, Int32, Int32)+0x10b
00000000`0025ae20 00000642`7606fcbc System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds()+0x2bc
00000000`0025af40 00000642`7605d44b System_Windows_Forms_ni!System.Windows.Forms.Control.WmWindowPosChanged(System.Windows.Forms.Message ByRef)+0x3c
00000000`0025afb0 00000642`7605d182 System_Windows_Forms_ni!System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)+0x27b
00000000`0025b160 00000642`7605cff5 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc&lt;/STRONG&gt;(System.Windows.Forms.Message ByRef)+0x52
00000000`0025b1b0 00000642`76278bd9 System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)+0xb5
00000000`0025b260 00000642`7f67945a System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(Int64, Int32, Int64, Int64)+0x29
00000000`0025b2a0 00000000`76f73ee2 mscorwks!UMThunkStubAMD64+0x7a
00000000`0025b330 00000000`76f7bf9b USER32!UserCallWinProcCheckWow+0x163
00000000`0025b3f0 00000000`76f73789 USER32!DispatchClientMessage+0xc3
00000000`0025b450 00000000`770759a6 USER32!__fnINLPWINDOWPOS+0x2d
00000000`0025b4b0 00000000`76f73a5a &lt;STRONG&gt;ntdll!KiUserCallbackDispatcherContinue&lt;/STRONG&gt;
00000000`0025b558 00000642`7f67b167 &lt;STRONG&gt;USER32!ZwUserSetWindowPos+0xa&lt;/STRONG&gt;
00000000`0025b560 00000642`7606fbd3 mscorwks!DoNDirectCall__PatchGetThreadCall+0x7b
00000000`0025b620 00000642`76067ae1 System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, Int32, Int32, Int32, Int32, Int32)+0xa3
00000000`0025b700 00000642`7606764e System_Windows_Forms_ni!System.Windows.Forms.Control.SetBoundsCore(Int32, Int32, Int32, Int32, System.Windows.Forms.BoundsSpecified)+0x251
00000000`0025b810 00000642`76067423 System_Windows_Forms_ni!System.Windows.Forms.Control.SetBounds(Int32, Int32, Int32, Int32, System.Windows.Forms.BoundsSpecified)+0xae
00000000`0025b880 00000642`80150b74 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control.set_Size&lt;/STRONG&gt;(System.Drawing.Size)+0x33
00000000`0025b8c0 00000642`7605eb0b &lt;STRONG&gt;WindowsApplication1!WindowsApplication1.Form1+MyPanel.OnSizeChanged&lt;/STRONG&gt;(System.EventArgs)+0x1d4
00000000`0025b980 00000642`7605e77c System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds(Int32, Int32, Int32, Int32, Int32, Int32)+0x10b
00000000`0025ba00 00000642`7606fcbc System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds()+0x2bc
00000000`0025bb20 00000642`7605d44b System_Windows_Forms_ni!System.Windows.Forms.Control.WmWindowPosChanged(System.Windows.Forms.Message ByRef)+0x3c
00000000`0025bb90 00000642`7605d182 System_Windows_Forms_ni!System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)+0x27b
00000000`0025bd40 00000642`7605cff5 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc&lt;/STRONG&gt;(System.Windows.Forms.Message ByRef)+0x52
00000000`0025bd90 00000642`76278bd9 System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)+0xb5
00000000`0025be40 00000642`7f67945a System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(Int64, Int32, Int64, Int64)+0x29
00000000`0025be80 00000000`76f73ee2 mscorwks!UMThunkStubAMD64+0x7a
00000000`0025bf10 00000000`76f7bf9b USER32!UserCallWinProcCheckWow+0x163
00000000`0025bfd0 00000000`76f73789 USER32!DispatchClientMessage+0xc3
00000000`0025c030 00000000`770759a6 USER32!__fnINLPWINDOWPOS+0x2d
00000000`0025c090 00000000`76f73a5a &lt;STRONG&gt;ntdll!KiUserCallbackDispatcherContinue&lt;/STRONG&gt;
00000000`0025c138 00000642`7f67b167 &lt;STRONG&gt;USER32!ZwUserSetWindowPos&lt;/STRONG&gt;+0xa
00000000`0025c140 00000642`7606fbd3 mscorwks!DoNDirectCall__PatchGetThreadCall+0x7b
00000000`0025c200 00000642`76067ae1 System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, Int32, Int32, Int32, Int32, Int32)+0xa3
00000000`0025c2e0 00000642`7604fb99 System_Windows_Forms_ni!System.Windows.Forms.Control.SetBoundsCore(Int32, Int32, Int32, Int32, System.Windows.Forms.BoundsSpecified)+0x251
00000000`0025c3f0 00000642`7606d3bf System_Windows_Forms_ni!System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.SetBounds(System.Drawing.Rectangle, System.Windows.Forms.BoundsSpecified)+0x249
00000000`0025c490 00000642`76069f84 System_Windows_Forms_ni!System.Windows.Forms.Layout.DefaultLayout.ApplyCachedBounds(System.Windows.Forms.Layout.IArrangedElement)+0x24f
00000000`0025c580 00000642`76069d64 System_Windows_Forms_ni!System.Windows.Forms.Layout.DefaultLayout.xLayout(System.Windows.Forms.Layout.IArrangedElement, Boolean, System.Drawing.Size ByRef)+0x204
00000000`0025c6c0 00000642`76069ce6 System_Windows_Forms_ni!System.Windows.Forms.Layout.DefaultLayout.LayoutCore(System.Windows.Forms.Layout.IArrangedElement, System.Windows.Forms.LayoutEventArgs)+0x24
00000000`0025c700 00000642`76069b9d System_Windows_Forms_ni!System.Windows.Forms.Layout.LayoutEngine.Layout(System.Object, System.Windows.Forms.LayoutEventArgs)+0x26
00000000`0025c740 00000642`7604b182 System_Windows_Forms_ni!System.Windows.Forms.Control.OnLayout(System.Windows.Forms.LayoutEventArgs)+0xad
00000000`0025c780 00000642`76069278 System_Windows_Forms_ni!System.Windows.Forms.Form.OnLayout(System.Windows.Forms.LayoutEventArgs)+0x52
00000000`0025c800 00000642`760690d1 System_Windows_Forms_ni!System.Windows.Forms.Control.PerformLayout(System.Windows.Forms.LayoutEventArgs)+0x118
00000000`0025c8c0 00000642`7604bf98 System_Windows_Forms_ni!System.Windows.Forms.Control.OnResize(System.EventArgs)+0x141
00000000`0025c920 00000642`7604c0d2 System_Windows_Forms_ni!System.Windows.Forms.Form.OnResize(System.EventArgs)+0x18
00000000`0025c960 00000642`7605eb0b System_Windows_Forms_ni!System.Windows.Forms.Control.OnSizeChanged(System.EventArgs)+0x32
00000000`0025c9a0 00000642`7605e77c System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds(Int32, Int32, Int32, Int32, Int32, Int32)+0x10b
00000000`0025ca20 00000642`7606fcbc System_Windows_Forms_ni!System.Windows.Forms.Control.UpdateBounds()+0x2bc
00000000`0025cb40 00000642`7605d44b System_Windows_Forms_ni!System.Windows.Forms.Control.WmWindowPosChanged(System.Windows.Forms.Message ByRef)+0x3c
00000000`0025cbb0 00000642`7610e197 System_Windows_Forms_ni!System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)+0x27b
00000000`0025cd60 00000642`7605d182 System_Windows_Forms_ni!System.Windows.Forms.Form.WmWindowPosChanged(System.Windows.Forms.Message ByRef)+0x27
00000000`0025cda0 00000642`7605cff5 System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)+0x52
00000000`0025cdf0 00000642`76278bd9 System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)+0xb5
00000000`0025cea0 00000642`7f67945a System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(Int64, Int32, Int64, Int64)+0x29
00000000`0025cee0 00000000`76f73ee2 mscorwks!UMThunkStubAMD64+0x7a
00000000`0025cf70 00000000`76f7bf9b USER32!UserCallWinProcCheckWow+0x163
00000000`0025d030 00000000`76f73789 USER32!DispatchClientMessage+0xc3
00000000`0025d090 00000000`770759a6 USER32!__fnINLPWINDOWPOS+0x2d
00000000`0025d0f0 00000000`76f7ac4a ntdll!KiUserCallbackDispatcherContinue
00000000`0025d198 00000000`76f7ac94 USER32!ZwUserMessageCall+0xa
00000000`0025d1a0 00000000`76f7e026 USER32!RealDefWindowProcWorker+0xb1
00000000`0025d270 000007fe`fbfb30d6 USER32!RealDefWindowProcW+0x5a
00000000`0025d2b0 000007fe`fbfcddf2 uxtheme!DoMsgDefault+0x2a
00000000`0025d2e0 000007fe`fbfb6c8a uxtheme!OnDwpSysCommand+0x50
00000000`0025d310 000007fe`fbfb1711 uxtheme!_ThemeDefWindowProc+0x223
00000000`0025d3e0 00000000`76f7bb73 uxtheme!ThemeDefWindowProcW+0x11
00000000`0025d420 00000000`76f7d24a USER32!DefWindowProcW+0xe6
00000000`0025d470 00000000`76f7d80c USER32!UserCallWinProcCheckWow+0x1ad
00000000`0025d530 00000000`76f7d778 USER32!CallWindowProcAorW+0xdb
00000000`0025d580 00000642`7f67b382 USER32!CallWindowProcW+0x18
00000000`0025d5c0 00000642`7605e378 mscorwks!DoNDirectCallWorker+0x62
00000000`0025d660 00000642`760473f4 System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.DefWndProc(System.Windows.Forms.Message ByRef)+0xa8
00000000`0025d750 00000642`7605da52 System_Windows_Forms_ni!System.Windows.Forms.Form.DefWndProc(System.Windows.Forms.Message ByRef)+0x74
00000000`0025d840 00000642`7605d182 System_Windows_Forms_ni!System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)+0x882
00000000`0025d9f0 00000642`7605cff5 System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)+0x52
00000000`0025da40 00000642`76278bd9 System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)+0xb5
00000000`0025daf0 00000642`7f67945a System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(Int64, Int32, Int64, Int64)+0x29
00000000`0025db30 00000000`76f73ee2 mscorwks!UMThunkStubAMD64+0x7a
00000000`0025dbc0 00000000`76f7bf9b USER32!UserCallWinProcCheckWow+0x163
00000000`0025dc80 00000000`76f7c20d USER32!DispatchClientMessage+0xc3
00000000`0025dce0 00000000`770759a6 USER32!__fnDWORD+0x2d
00000000`0025dd40 00000000`76f7ac4a ntdll!KiUserCallbackDispatcherContinue
00000000`0025ddc8 00000000`76f7ac94 USER32!ZwUserMessageCall+0xa
00000000`0025ddd0 00000000`76f7e026 USER32!RealDefWindowProcWorker+0xb1
00000000`0025dea0 000007fe`fbfb30d6 USER32!RealDefWindowProcW+0x5a
00000000`0025dee0 000007fe`fbfcedf5 uxtheme!DoMsgDefault+0x2a
00000000`0025df10 000007fe`fbfb6c8a uxtheme!OnDwpNcLButtonDown+0x71
00000000`0025df50 000007fe`fbfb1711 uxtheme!_ThemeDefWindowProc+0x223
00000000`0025e020 00000000`76f7bb73 uxtheme!ThemeDefWindowProcW+0x11
00000000`0025e060 00000000`76f7d24a USER32!DefWindowProcW+0xe6
00000000`0025e0b0 00000000`76f7d80c USER32!UserCallWinProcCheckWow+0x1ad
00000000`0025e170 00000000`76f7d778 USER32!CallWindowProcAorW+0xdb
00000000`0025e1c0 00000642`7f67b382 USER32!CallWindowProcW+0x18
00000000`0025e200 00000642`7605e378 mscorwks!DoNDirectCallWorker+0x62
00000000`0025e2a0 00000642`760473f4 System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.DefWndProc(System.Windows.Forms.Message ByRef)+0xa8
00000000`0025e390 00000642`7605d7a0 System_Windows_Forms_ni!System.Windows.Forms.Form.DefWndProc(System.Windows.Forms.Message ByRef)+0x74
00000000`0025e480 00000642`7605d182 System_Windows_Forms_ni!System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)+0x5d0
00000000`0025e630 00000642`7605cff5 System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)+0x52
00000000`0025e680 00000642`76278bd9 System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)+0xb5
00000000`0025e730 00000642`7f67945a System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(Int64, Int32, Int64, Int64)+0x29
00000000`0025e770 00000000`76f7d24a mscorwks!UMThunkStubAMD64+0x7a
00000000`0025e800 00000000`76f7d39e USER32!UserCallWinProcCheckWow+0x1ad
00000000`0025e8c0 00000642`7f67b167 USER32!DispatchMessageWorker+0x389
00000000`0025e940 00000642`7607f1fd mscorwks!DoNDirectCall__PatchGetThreadCall+0x7b
00000000`0025e9e0 00000642`7607dfb4 System_Windows_Forms_ni!DomainBoundILStubClass.IL_STUB(MSG ByRef)+0x11d
00000000`0025eb60 00000642`7607d7de System_Windows_Forms_ni!System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32, Int32, Int32)+0x604
00000000`0025edb0 00000642`7607d20d System_Windows_Forms_ni!System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)+0x59e
00000000`0025ef00 00000642`80150178 System_Windows_Forms_ni!System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)+0x6d
00000000`0025ef60 00000642`7f67ba32 WindowsApplication1!WindowsApplication1.Program.Main()+0x58
00000000`0025efa0 00000642`7f4bc645 mscorwks!CallDescrWorker+0x82
00000000`0025efe0 00000642`7f4d0496 mscorwks!CallDescrWorkerWithHandler+0xe5
00000000`0025f080 00000642`7f5aee5f mscorwks!MethodDesc::CallDescr+0x306
00000000`0025f2b0 00000642`7f5d3ba4 mscorwks!ClassLoader::RunMain+0x23f
00000000`0025f510 00000642`7f59acfa mscorwks!Assembly::ExecuteMainMethod+0xbc
00000000`0025f800 00000642`7f5e16c3 mscorwks!SystemDomain::ExecuteMainMethod+0x492
00000000`0025fdd0 00000642`7f5c641c mscorwks!ExecuteEXE+0x47
00000000`0025fe20 00000642`7ee69ade mscorwks!_CorExeMain+0xac
00000000`0025fe80 00000000`76e5495d mscoree!_CorExeMain+0x3e
00000000`0025feb0 00000000`77058791 KERNEL32!BaseThreadInitThunk+0xd
00000000`0025fee0 00000000`00000000 ntdll!RtlUserThreadStart+0x1d
&lt;/PRE&gt;
&lt;P&gt;A call to &lt;A href="http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx"&gt;SetWindowPos&lt;/A&gt; API results in a &lt;STRONG&gt;kernel-to-usermode callback&lt;/STRONG&gt; to the target &lt;STRONG&gt;WndProc&lt;/STRONG&gt; in the case where the thread owns the target HWND. &lt;STRONG&gt;After enough nesting of multiple callbacks, the kernel will just stop making recursive calls to WndProcs&lt;/STRONG&gt; and window messages will be dropped.&lt;/P&gt;
&lt;P&gt;To understand this better, if we check previous call stack in more detail, we can see what we mean by "SetWindowPos results in a kernel-to-usermode callback":&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE&gt;0:000&amp;gt; kL100
Child-SP RetAddr Call Site
00000000`002589f8 00000642`7605eb0b &lt;STRONG&gt;WindowsApplication1!WindowsApplication1.Form1+MyPanel.OnSizeChanged&lt;/STRONG&gt;(System.EventArgs)
...
00000000`00258dc0 00000642`7605cff5 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc&lt;/STRONG&gt;(System.Windows.Forms.Message ByRef)+0x52
...
00000000`00259110 00000000`76f73a5a &lt;STRONG&gt;ntdll!KiUserCallbackDispatcherContinue&lt;/STRONG&gt;
00000000`002591b8 00000642`7f67b167 &lt;STRONG&gt;USER32!ZwUserSetWindowPos&lt;/STRONG&gt;+0xa
...
00000000`002594e0 00000642`80150b74 &lt;STRONG&gt;System_Windows_Forms_ni!System.Windows.Forms.Control.set_Size&lt;/STRONG&gt;(System.Drawing.Size)+0x33
00000000`00259520 00000642`7605eb0b &lt;STRONG&gt;WindowsApplication1!WindowsApplication1.Form1+MyPanel.OnSizeChanged&lt;/STRONG&gt;(System.EventArgs)+0x1d4
...
...
&lt;/PRE&gt;
&lt;P&gt;Basically, we get to &lt;STRONG&gt;OnSizeChanged&lt;/STRONG&gt; in parent panel. Parent panel calls &lt;STRONG&gt;set_Size&lt;/STRONG&gt; on its child panel. This produces a call to &lt;STRONG&gt;SetWindowsPos&lt;/STRONG&gt; API (&lt;STRONG&gt;USER32!ZwUserSetWindowPos&lt;/STRONG&gt;) which produces a &lt;STRONG&gt;kernel-to-usermode callback&lt;/STRONG&gt; (&lt;STRONG&gt;ntdll!KiUserCallbackDispatcherContinue&lt;/STRONG&gt;) to the &lt;STRONG&gt;WndProc&lt;/STRONG&gt; of the child panel which finally calls OnSizeChanged on that child panel. And so on. After enough nesting of these callbacks in the same thread, the kernel will just stop making recursive calls to WndProcs. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So why is this happening, if current &lt;STRONG&gt;default&lt;/STRONG&gt; &lt;STRONG&gt;nested window limit is 50 &lt;/STRONG&gt;on Windows platforms?&lt;/P&gt;
&lt;P&gt;The &lt;STRONG&gt;root cause &lt;/STRONG&gt;of the issue is &lt;STRONG&gt;available&lt;/STRONG&gt; &lt;STRONG&gt;kernel stack space&lt;/STRONG&gt;. In user mode, if recursive calls to a function are made enough times you will end up with a stack overflow exception. The same thing can happen in kernel mode. In this case, the application is calling SetWindowPos to resize a window. The window handles the WM_SIZE message by resizing its child windows. This operation is done recursively for however deep the window hierarchy is. &lt;/P&gt;
&lt;P&gt;A SetWindowPos call will transition into kernel mode in order to make changes to the specified window’s position. There is then a callback from kernel mode into user mode to call the window procedure of the window to process the WM_WINDOWPOSCHANGING/WM_WINDOWPOSCHANGED messages. Once the messages are handled, the SetWindowPos call returns.&lt;/P&gt;
&lt;P&gt;Ultimately what happens is that a &lt;STRONG&gt;stack overflow exception&lt;/STRONG&gt; is generated in &lt;STRONG&gt;kernel mode&lt;/STRONG&gt;. Rather than not handling the exception (which would "blue-screen" the machine) the window manager handles the exception and returns from the SetWindowsPos call. &lt;STRONG&gt;This problem is not limited to x64 Windows as it can also occur on x86 Windows&lt;/STRONG&gt;, although it would take a deeper window hierarchy for the problem to occur in x86 Windows. Why the difference? Well, the size of pointers doubled from 32-bit to 64-bit and the size of the kernel mode stack did not.&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this is &lt;STRONG&gt;not a bug&lt;/STRONG&gt;, but a limitation. The fact of the matter is that, even if we were to increase the kernel stack size in the future, applications do not have infinite kernel stack space available.&amp;nbsp;These are the only &lt;STRONG&gt;alternatives&lt;/STRONG&gt; we have to deal with this:&lt;/P&gt;
&lt;P&gt;1) Redesign the application to have &lt;STRONG&gt;less containers&lt;/STRONG&gt; and &lt;STRONG&gt;reduce the number of nesting levels&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;2) In order to workaround this limitation, the application has to &lt;STRONG&gt;break nesting by asynchronously setting sizes&lt;/STRONG&gt; on the child control from the last control which receives the message.&lt;/P&gt;
&lt;P&gt;2.1) In our sample application we can &lt;STRONG&gt;change OnSizeChanged&lt;/STRONG&gt; method above to:&lt;/P&gt;&lt;PRE&gt;protected void &lt;STRONG&gt;ChangeSize&lt;/STRONG&gt;()
{
  if (childPanel != null)
  {
    &lt;STRONG&gt;childPanel.Size = new Size&lt;/STRONG&gt;(
    this.ClientSize.Width - 2 * childPanel.Left,
    this.ClientSize.Height - 2 * childPanel.Top);
  }
}

protected override void &lt;STRONG&gt;OnSizeChanged&lt;/STRONG&gt;(System.EventArgs ea)
{
  if (this.Handle != null)
  {
    &lt;STRONG&gt;BeginInvoke(new MethodInvoker(ChangeSize))&lt;/STRONG&gt;
  }

  base.OnResize(ea);
}
&lt;/PRE&gt;
&lt;P&gt;All panels get their size changed. Thanks to &lt;STRONG&gt;BeginInvoke&lt;/STRONG&gt; &lt;STRONG&gt;only one call to OnSizeChanged&lt;/STRONG&gt; happens in the &lt;STRONG&gt;same thread &lt;/STRONG&gt;at a given time, and that breaks the nesting of multiple kernel-to-user mode callbacks within the same thread.&lt;/P&gt;
&lt;P&gt;2.2) &lt;STRONG&gt;Another way&lt;/STRONG&gt; I found to break the nesting of callbacks which may help but I haven't tried personally:&lt;/P&gt;
&lt;P&gt;1. Select a window with simple layout of children (for example: single child - a panel with DockStyle.Fill) which will be breaking your recursion . (Not necessarily the last window which receives the positioning message) &lt;/P&gt;
&lt;P&gt;2. Override WndProc for the window like this:&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE&gt;internal class MyTabPage : TabPage
{
private const int WM_WINDOWPOSCHANGING = 70;
private const int WM_SETREDRAW = 0xB;
private const int SWP_NOACTIVATE = 0x0010;
private const int SWP_NOZORDER = 0x0004;
private const int SWP_NOSIZE = 0x0001;
private const int SWP_NOMOVE = 0x0002;

[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(HandleRef hWnd, int msg, int wParam, int lParam);

[DllImport("User32.dll", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern bool SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter,
int x, int y, int cx, int cy, int flags);

[StructLayout(LayoutKind.Sequential)]
private struct WINDOWPOS
{
public IntPtr hwnd;
public IntPtr hwndInsertAfter;
public int x;
public int y;
public int cx;
public int cy;
public int flags;
};

private unsafe delegate void ResizeChildDelegate(WINDOWPOS * wpos);

private unsafe void ResizeChild(WINDOWPOS * wpos)
{
// verify if it's the right instance of MyPanel if needed
if ((this.Controls.Count == 1) &amp;amp;&amp;amp; (this.Controls[0] is Panel))
{
Panel child = this.Controls[0] as Panel;

// stop window redraw to avoid flicker
SendMessage(new HandleRef(child, child.Handle), WM_SETREDRAW, 0, 0);

// start a new stack of SetWindowPos calls
SetWindowPos(new HandleRef(child, child.Handle), new HandleRef(null, IntPtr.Zero),
0, 0, wpos-&amp;gt;cx, wpos-&amp;gt;cy, SWP_NOACTIVATE | SWP_NOZORDER);

// turn window repainting back on 
SendMessage(new HandleRef(child, child.Handle), WM_SETREDRAW, 1, 0);

// send repaint message to this control and its children
this.Invalidate(true);
}
}

protected unsafe override void WndProc(ref Message m)
{
if (m.Msg == WM_WINDOWPOSCHANGING)
{
WINDOWPOS* wpos = (WINDOWPOS*)m.LParam;

Debug.WriteLine("WM_WINDOWPOSCHANGING received by " + this.Name + " flags " + wpos-&amp;gt;flags);

if (((wpos-&amp;gt;flags &amp;amp; (SWP_NOZORDER | SWP_NOACTIVATE)) == (SWP_NOZORDER | SWP_NOACTIVATE)) &amp;amp;&amp;amp;
((wpos-&amp;gt;flags &amp;amp; ~(SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE)) == 0))
{
if ((wpos-&amp;gt;cx != this.Width) || (wpos-&amp;gt;cy != this.Height))
{
BeginInvoke(new ResizeChildDelegate(ResizeChild), new object[] { m.LParam });
return;
}
}
}

base.WndProc(ref m);
}
}
&lt;/PRE&gt;
&lt;P&gt;3. repeat for every 12-th or so window&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I hope this helps.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Alex (Alejandro Campos Magencio)&lt;BR&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9129671" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/Vista/default.aspx">Vista</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Server+2008/default.aspx">Server 2008</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/XP/default.aspx">XP</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Server+2003/default.aspx">Server 2003</category></item><item><title>NdrClientCall2 fails with RPC_S_ALREADY_LISTENING when using pipes over ncalrpc</title><link>http://blogs.msdn.com/alejacma/archive/2009/05/27/ndrclientcall2-fails-with-rpc-s-already-listening-when-using-pipes-over-ncalrpc.aspx</link><pubDate>Wed, 27 May 2009 12:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9644249</guid><dc:creator>alejacma</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/9644249.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=9644249</wfw:commentRss><description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I've been working on a &lt;A href="http://msdn.microsoft.com/en-us/library/aa378651(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa378651(VS.85).aspx"&gt;Microsoft Remote Procedure Call (RPC)&lt;/A&gt;&amp;nbsp;issue recently, where the &lt;STRONG&gt;first call&lt;/STRONG&gt; to a&amp;nbsp;specific&amp;nbsp;remote method &lt;STRONG&gt;fails&lt;/STRONG&gt; because the call to &lt;STRONG&gt;NdrClientCall2&lt;/STRONG&gt; function in the client stub returns &lt;STRONG&gt;RPC_S_ALREADY_LISTENING&lt;/STRONG&gt;&amp;nbsp;(&lt;EM&gt;"The server is already listening"&lt;/EM&gt;) error. But &lt;STRONG&gt;subsequent calls&lt;/STRONG&gt; to the very same method &lt;STRONG&gt;succeed&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;The following &lt;STRONG&gt;CONDITIONS &lt;/STRONG&gt;are required to reproduce the issue:&lt;/P&gt;
&lt;P&gt;1. Process has &lt;STRONG&gt;started&lt;/STRONG&gt; its own &lt;STRONG&gt;RPC server&lt;/STRONG&gt; (called &lt;A href="http://msdn.microsoft.com/en-us/library/aa378437(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa378437(VS.85).aspx "&gt;RpcServerListen&lt;/A&gt;) and&lt;BR&gt;2. The same process starts an &lt;STRONG&gt;outgoing RPC call&lt;/STRONG&gt; of a &lt;STRONG&gt;method&lt;/STRONG&gt; from an interface for which it has no own RPC server started and this method &lt;STRONG&gt;has an&lt;/STRONG&gt; &lt;STRONG&gt;"[in] pipe byte" parameter&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to better understand the issue, let's consider the following &lt;STRONG&gt;SCENARIO&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;- We have &lt;STRONG&gt;2 processes&lt;/STRONG&gt; which use&amp;nbsp;&lt;STRONG&gt;RPC&lt;/STRONG&gt;&amp;nbsp;for interprocess communication. We'll call them &lt;STRONG&gt;A&lt;/STRONG&gt; and &lt;STRONG&gt;B&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;- Process A and B both run on the &lt;STRONG&gt;same machine&lt;/STRONG&gt;. Protocol being used is &lt;A href="http://msdn.microsoft.com/en-us/library/aa374395(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa374395(VS.85).aspx"&gt;ncalrpc&lt;/A&gt; (&lt;STRONG&gt;Local procedure call&lt;/STRONG&gt;). Machine can be either &lt;STRONG&gt;Windows XP&lt;/STRONG&gt; or &lt;STRONG&gt;Server 2003&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;- We have a &lt;A href="http://msdn.microsoft.com/en-us/library/aa367091(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa367091(VS.85).aspx"&gt;MIDL&lt;/A&gt;-defined &lt;STRONG&gt;interface&lt;/STRONG&gt; that declares a method "rpcMethod" with "[in] &lt;STRONG&gt;pipe&lt;/STRONG&gt; byte" parameter like the following:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[&lt;BR&gt;uuid(ActualGuidHere), &lt;BR&gt;version(1.0), &lt;BR&gt;pointer_default(unique)&lt;BR&gt;]&lt;BR&gt;interface &lt;STRONG&gt;IMyInterface&lt;/STRONG&gt;&lt;BR&gt;{&lt;BR&gt;//other irrelevant methods here&lt;BR&gt;error_status_t &lt;STRONG&gt;rpcMethod&lt;/STRONG&gt;( [in] &lt;STRONG&gt;pipe&lt;/STRONG&gt; byte params );&lt;BR&gt;//more irrelevant methods here&lt;BR&gt;}&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;- An &lt;STRONG&gt;RPC server&lt;/STRONG&gt; that implements &lt;STRONG&gt;this interface&lt;/STRONG&gt; is &lt;STRONG&gt;started&lt;/STRONG&gt; in &lt;STRONG&gt;process B&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;- &lt;STRONG&gt;Process A starts&lt;/STRONG&gt; &lt;STRONG&gt;its&lt;/STRONG&gt; &lt;STRONG&gt;own RPC server&lt;/STRONG&gt; for another interface (not the same as process B). While doing this it certainly calls &lt;A href="http://msdn.microsoft.com/en-us/library/aa378437(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa378437(VS.85).aspx"&gt;RpcServerListen&lt;/A&gt;&amp;nbsp;API and that call succeeds.&lt;/P&gt;
&lt;P&gt;- Later on, &lt;STRONG&gt;process A&lt;/STRONG&gt; tries to &lt;STRONG&gt;invoke&lt;/STRONG&gt;&lt;EM&gt; IMyInterface::rpcMethod&lt;/EM&gt; &lt;STRONG&gt;in process B&lt;/STRONG&gt;, but call to &lt;STRONG&gt;NdrClientCall2&lt;/STRONG&gt; function &lt;STRONG&gt;fails&lt;/STRONG&gt; with &lt;STRONG&gt;RPC_S_ALREADY_LISTENING&lt;/STRONG&gt; error and it never reaches the server side.&amp;nbsp; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;This error should only be returned when we call RpcServerListen&amp;nbsp;twice on the same process&lt;/STRONG&gt;, but we are 100% sure that&amp;nbsp;we are only calling it once directly. What is going on then? Why is RPC runtime returning that error? Is it calling RpcServerListen under the hood? Why are the rest of the calls to &lt;EM&gt;IMyInterface::rpcMethod&lt;/EM&gt; succeeding?&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The &lt;STRONG&gt;EXPLANATION &lt;/STRONG&gt;is the following:&lt;/P&gt;
&lt;P mce_keep="true"&gt;When we&amp;nbsp;use &lt;STRONG&gt;pipes over ncalrpc&lt;/STRONG&gt;, &lt;STRONG&gt;NdrClientCall2&lt;/STRONG&gt; ends up&amp;nbsp;&lt;STRONG&gt;initializing&lt;/STRONG&gt; an &lt;STRONG&gt;ncalrpc&lt;/STRONG&gt; &lt;STRONG&gt;endpoint&lt;/STRONG&gt; (don't know what an endpoint is? Please check &lt;A href="http://msdn.microsoft.com/en-us/library/aa373819(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa373819(VS.85).aspx"&gt;Essential RPC Binding Terminology&lt;/A&gt;) for &lt;STRONG&gt;internal use&lt;/STRONG&gt; with &lt;A href="http://msdn.microsoft.com/en-us/library/aa378453(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa378453(VS.85).aspx"&gt;RpcServerUseProtseqEp&lt;/A&gt;&amp;nbsp;API and&amp;nbsp;&lt;STRONG&gt;calling&lt;/STRONG&gt; &lt;STRONG&gt;RpcServerListen&amp;nbsp;&lt;/STRONG&gt;to listen for remote procedure calls, but only if that endpoint has not&amp;nbsp;been initialized yet. &lt;/P&gt;
&lt;P mce_keep="true"&gt;The &lt;STRONG&gt;first time&lt;/STRONG&gt; we call a method with a pipe parameter, that &lt;STRONG&gt;endpoint&lt;/STRONG&gt; for internal use is &lt;STRONG&gt;not initialized&lt;/STRONG&gt; yet, so NdrClientCall2 initializes it and calls &lt;STRONG&gt;RpcServerListen&lt;/STRONG&gt;&amp;nbsp;which &lt;STRONG&gt;fails&lt;/STRONG&gt; because we already called it in the same process once before.&lt;/P&gt;
&lt;P mce_keep="true"&gt;The &lt;STRONG&gt;next time&lt;/STRONG&gt; we call a method with a pipe parameter, that &lt;STRONG&gt;endpoint&lt;/STRONG&gt; is already &lt;STRONG&gt;initialized&lt;/STRONG&gt;, so NdrClientCall2 doesn't call RpcServerUseProtseqEp or RpcServerListen. Additionally, we already &lt;STRONG&gt;called RpcServerListen successfully once&lt;/STRONG&gt; in that process, so this side is already listening for RPC calls. With the endpoint created and the process listening for RPC calls, &lt;STRONG&gt;everything works&lt;/STRONG&gt; just fine from that moment on.&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;It's very easy to &lt;STRONG&gt;WORKAROUND &lt;/STRONG&gt;this limitation: we can &lt;STRONG&gt;safely&lt;/STRONG&gt; &lt;STRONG&gt;ignore&lt;/STRONG&gt; the &lt;STRONG&gt;RPC_S_ALREADY_LISTENING&lt;/STRONG&gt; error of the first call to&amp;nbsp;a method with a pipe parameter and just &lt;STRONG&gt;repeat the call&lt;/STRONG&gt; immediately. The failed call won't have any effect and&amp;nbsp;it won't change the pipe state, so there is no need to reinitialize the pipe. There should be no performance impact either.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Note that this issue is related to the usage of &lt;STRONG&gt;pipes over ncalrpc&lt;/STRONG&gt;, and it doesn't matter if we use them &lt;STRONG&gt;synchronously&lt;/STRONG&gt; or &lt;STRONG&gt;asynchronously &lt;/STRONG&gt;(&lt;A href="pipeshttp://msdn.microsoft.com/en-us/library/aa373548(VS.85).aspx" mce_href="Pipeshttp://msdn.microsoft.com/en-us/library/aa373548(VS.85).aspx"&gt;Asynchronous Pipes&lt;/A&gt;), or the parameter is &lt;STRONG&gt;[in]&lt;/STRONG&gt; or &lt;STRONG&gt;[out]&lt;/STRONG&gt;. And of course, the same workaround applies. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Also note that using &lt;STRONG&gt;synchronous pipes over ncalrpc&lt;/STRONG&gt; protocol is &lt;STRONG&gt;deprecated&lt;/STRONG&gt; on &lt;STRONG&gt;Vista&lt;/STRONG&gt;. If you start an application which uses them on Vista, you will see a message like the following on the &lt;STRONG&gt;Event Log&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P mce_keep="true"&gt;"&lt;BR&gt;&lt;EM&gt;Application ("my program exe file name here" \service) (PID: 344) is using Windows functionality that is not present in this release of Windows. For obtaining an updated version of the application, please, contact the application vendor. The technical information that needs to be conveyed to the application vendor is this: "An RPC method using synchronous pipes has been called on on protocol sequence ncalrpc interface with unique identifier (actual UUID here). Usage and support of synchronous pipes on this protocol sequence has been deprecated for this release of Windows. For information on the deprecation process, please, see &amp;lt;&lt;/EM&gt;&lt;A href="http://go.microsoft.com/fwlink/?LinkId=36415"&gt;&lt;EM&gt;http://go.microsoft.com/fwlink/?LinkId=36415&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt;&amp;gt;." User Action Contact the application vendor for updated version of the application.&lt;/EM&gt;&lt;BR&gt;"&lt;/P&gt;
&lt;P&gt;We can still use &lt;STRONG&gt;asynchronous pipes over ncalrpc on Vista&lt;/STRONG&gt;,&amp;nbsp;and the RPC_S_ALREADY_LISTENING&amp;nbsp;&lt;STRONG&gt;issue won't happen&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An&amp;nbsp;&lt;STRONG&gt;ALTERNATE SOLUTION&lt;/STRONG&gt;&amp;nbsp;which we recommend and works on all supported versions of Windows is to switch protocols from ncalrpc to&amp;nbsp;&lt;A href="http://msdn.microsoft.com/en-us/library/aa374395(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa374395(VS.85).aspx"&gt;ncacn_np&lt;/A&gt; (&lt;STRONG&gt;Connection-oriented named pipes&lt;/STRONG&gt;). Windows components like EFS among others use &lt;STRONG&gt;synchronous pipes over ncacn_np&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;Note that&amp;nbsp;&lt;STRONG&gt;ncacn_np&lt;/STRONG&gt; transport is &lt;STRONG&gt;remotely accessible&lt;/STRONG&gt;, but ncalrpc is not. To keep parity with our existing thread model, we'll need to write our own &lt;STRONG&gt;security callback&lt;/STRONG&gt; function and register it with the server (&lt;A href="http://msdn.microsoft.com/en-us/library/aa378441(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa378441(VS.85).aspx"&gt;RpcServerRegisterIfEx&lt;/A&gt;). The security callback can simply check if the call is coming from local system or remote (&lt;A href="http://msdn.microsoft.com/en-us/library/aa378434.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa378434.aspx"&gt;RpcServerInqCallAttributes&lt;/A&gt;&amp;nbsp;and its IsClientLocal value), and rejects it if it's&amp;nbsp;a remote client. Or we can update our thread model to deal with remote clients instead.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Sample&lt;/STRONG&gt; code:&lt;/P&gt;&lt;PRE&gt;// Register the security callback with interface
status = &lt;STRONG&gt;RpcServerRegisterIfEx&lt;/STRONG&gt;(
  hRpcInterface,
  NULL, // MgrTypeUuid
  NULL, // MgrEpv; null means use default
  &lt;STRONG&gt;RPC_IF_ALLOW_LOCAL_ONLY&lt;/STRONG&gt;,
  RPC_C_LISTEN_MAX_CALLS_DEFAULT,
  (RPC_IF_CALLBACK_FN*)&lt;STRONG&gt;RpcSecurityCallback&lt;/STRONG&gt; 
);

RPC_STATUS RPC_ENTRY
&lt;STRONG&gt;RpcSecurityCallback&lt;/STRONG&gt;(
  IN RPC_IF_HANDLE* handle,
  IN void* pCtx)
{
  // You can use &lt;STRONG&gt;RpcServerInqCallAttributes&lt;/STRONG&gt; API here to find if the client is local or remote.
}
&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;BR&gt;Regards,&lt;/P&gt;
&lt;P&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9644249" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/Vista/default.aspx">Vista</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Server+2008/default.aspx">Server 2008</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/XP/default.aspx">XP</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Server+2003/default.aspx">Server 2003</category></item><item><title>How to create a certificate request with CertEnroll (ASP)</title><link>http://blogs.msdn.com/alejacma/archive/2009/02/20/how-to-create-a-certificate-request-with-certenroll-asp.aspx</link><pubDate>Fri, 20 Feb 2009 15:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9435923</guid><dc:creator>alejacma</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/9435923.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=9435923</wfw:commentRss><description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;The other day I posted a &lt;STRONG&gt;Javascript sample&lt;/STRONG&gt; which shows how to use &lt;A class="" href="http://msdn.microsoft.com/en-us/library/aa374863(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa374863(VS.85).aspx"&gt;&lt;FONT color=#006ff7&gt;CertEnroll&lt;/FONT&gt;&lt;/A&gt; COM component to &lt;STRONG&gt;create a certificate request&lt;/STRONG&gt; and &lt;STRONG&gt;install the response from the CA&lt;/STRONG&gt; (Certificate Authority): &lt;A class="" href="http://blogs.msdn.com/alejacma/archive/2009/01/28/how-to-create-a-certificate-request-with-certenroll-javascript.aspx" mce_href="http://blogs.msdn.com/alejacma/archive/2009/01/28/how-to-create-a-certificate-request-with-certenroll-javascript.aspx"&gt;How to create a certificate request with CertEnroll (JavaScript)&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The installation part of that sample assumed that we got a Base64 text&amp;nbsp;with the response from the CA. But what if we i.e. send the request to a server, the server gets a .p7b or .cer binary file with the response from the CA, and we want to install the response on the client who requested the cert on the first place? &lt;/P&gt;
&lt;P&gt;The following &lt;STRONG&gt;ASP sample&lt;/STRONG&gt; shows how to &lt;STRONG&gt;install on the client the .p7b/.cer binary file&lt;/STRONG&gt; that the server got with the &lt;STRONG&gt;response&lt;/STRONG&gt; from the &lt;STRONG&gt;CA&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;%
  ' Convert binary to Base64
  '
  Function &lt;STRONG&gt;BinaryToBase64&lt;/STRONG&gt;(binary)
      ' Create temporary node with Base64 data type  
      Set oXmlDom = CreateObject("&lt;STRONG&gt;microsoft.xmldom&lt;/STRONG&gt;")
      Set oElement = oXmlDom.createElement("tmp")
      oElement.dataType = "bin.base64"
      ' Set bytes, get encoded String 
      oElement.nodeTypedValue = binary
      BinaryToBase64 = oElement.text
  End Function 

  ' Read file into buffer
  '
  Function &lt;STRONG&gt;ReadBinaryFile&lt;/STRONG&gt;(FileName)
      Const adTypeBinary = 1
      'Create Stream object
      Dim BinaryStream
      Set BinaryStream = CreateObject("&lt;STRONG&gt;ADODB.Stream&lt;/STRONG&gt;")
      'Specify stream type - we want To get binary data.
      BinaryStream.Type = adTypeBinary
      'Open the stream
      BinaryStream.Open
      'Load the file data from disk To stream object
      BinaryStream.LoadFromFile FileName
      'Open the stream And get binary data from the object
      ReadBinaryFile = BinaryStream.Read
  End Function 

  ' Read binary file as Base64
  '
  FileName = "C:\temp\certnew.&lt;STRONG&gt;p7b&lt;/STRONG&gt;"
  'FileName = "C:\temp\certnew.&lt;STRONG&gt;cer&lt;/STRONG&gt;"
  sPKCS7 = &lt;STRONG&gt;BinaryToBase64&lt;/STRONG&gt;(&lt;STRONG&gt;ReadBinaryFile&lt;/STRONG&gt;(FileName))
  
  ' Be careful with &lt;STRONG&gt;line feeds&lt;/STRONG&gt; in Base64 string
  '
  strings = split(sPKCS7, chr(10))
  sPKCS7 = """"
  for i = 0 to ubound(strings) - 1
    sPKCS7 = sPKCS7 + strings(i) + """ + """
  next
  sPKCS7 = sPKCS7 + strings(i) + """"

%&amp;gt;

&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Certificate Request test&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt; 
    &amp;lt;object id="objCertEnrollClassFactory" classid="clsid:884e2049-217d-11da-b2a4-000e7bbb2b09"&amp;gt;&amp;lt;/object&amp;gt;    
    &amp;lt;script language="javascript"&amp;gt;
        
      function InstallCert() 
      {        
        document.write("&amp;lt;br&amp;gt;Installing certificate...");                      

        try {
          // Variables
          var objEnroll = objCertEnrollClassFactory.CreateObject("&lt;STRONG&gt;X509Enrollment.CX509Enrollment&lt;/STRONG&gt;")

          objEnroll.&lt;STRONG&gt;Initialize&lt;/STRONG&gt;(1); // ContextUser
          objEnroll.&lt;STRONG&gt;InstallResponse&lt;/STRONG&gt;(4, &amp;lt;%=sPKCS7%&amp;gt;, 1, ""); // AllowUntrustedRoot = 4, XCN_CRYPT_STRING_BASE64 = 1
        }
        catch (ex) {
          document.write("&amp;lt;br&amp;gt;" + ex.description);
          return false;
        }

        document.write("&amp;lt;br&amp;gt;Done!");                      

        return true;
      }

      InstallCert();
    
    &amp;lt;/script&amp;gt;
    
    
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;I hope this helps.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9435923" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/Vista/default.aspx">Vista</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Server+2008/default.aspx">Server 2008</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/CertEnroll/default.aspx">CertEnroll</category></item><item><title>Security Warning dialog box is displayed when you try to silently install a hotfix or an update</title><link>http://blogs.msdn.com/alejacma/archive/2008/06/27/security-warning-dialog-box-is-displayed-when-you-try-to-silently-install-a-hotfix-or-an-update.aspx</link><pubDate>Fri, 27 Jun 2008 12:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8660971</guid><dc:creator>alejacma</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/8660971.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=8660971</wfw:commentRss><description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;You may be trying to &lt;STRONG&gt;install&lt;/STRONG&gt; a &lt;STRONG&gt;hotfix&lt;/STRONG&gt; or &lt;STRONG&gt;update&lt;/STRONG&gt; &lt;STRONG&gt;silently&lt;/STRONG&gt;, but you keep getting a &lt;STRONG&gt;security warning dialog&lt;/STRONG&gt; because the file was &lt;STRONG&gt;downloaded&lt;/STRONG&gt; from the &lt;STRONG&gt;Internet&lt;/STRONG&gt;. The following article explains this situation: &lt;A class="" href="http://support.microsoft.com/default.aspx?scid=kb;EN-US;889815" mce_href="http://support.microsoft.com/default.aspx?scid=kb;EN-US;889815"&gt;889815 The Open File - Security Warning dialog box is displayed when you try to silently install a hotfix or an update by using a Visual Basic script in Windows XP Service Pack 2&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Attachment Execution Service (AES)&lt;/STRONG&gt; is responsible for this dialog. KB &lt;STRONG&gt;889815&lt;/STRONG&gt; suggests to use a script to set &lt;STRONG&gt;SEE_MASK_NOZONECHECKS&lt;/STRONG&gt; environment variable before installing the hotfix or update. Well, this will work on VBScript, but may not work in other scenarios.&lt;/P&gt;
&lt;P&gt;Alternatively you may set that environment variable in a &lt;STRONG&gt;batch job&lt;/STRONG&gt;, but it may not help in your scenario either.&lt;/P&gt;
&lt;P&gt;Are we out of luck&amp;nbsp;then? Well, not necessarily. Keep reading.&lt;/P&gt;
&lt;P&gt;Run the following command on the file you downloaded from the Internet which contains the patch you want to install:&lt;/P&gt;&lt;PRE&gt;notepad patch.exe:Zone.Identifier
&lt;/PRE&gt;
&lt;P&gt;This will show us the &lt;STRONG&gt;Zone.Identifier&lt;/STRONG&gt; &lt;STRONG&gt;Alternate Data Stream (ADS)&lt;/STRONG&gt; of our file. We will see the following contents:&lt;/P&gt;&lt;PRE&gt;[ZoneTransfer]
ZoneId=3
&lt;/PRE&gt;
&lt;P&gt;Value 3 means that the file was downloaded from the Internet and it's potentially unsafe. This makes the warning dialog to appear. We may edit &lt;STRONG&gt;ZoneId&lt;/STRONG&gt; value to make the warning disappear. A value of i.e. 2 may work in your environemnt. Change the value, save the ADS file and try installing the patch again.&lt;/P&gt;
&lt;P&gt;This is a very good post to understand how Attachment Execution Service (AES) works and the effects of changing the ZoneId value: &lt;A class="" href="http://community.bartdesmet.net/blogs/bart/archive/2005/08/19/3485.aspx" mce_href="http://community.bartdesmet.net/blogs/bart/archive/2005/08/19/3485.aspx"&gt;Demo of "Attachment Execution Service internals" in Windows XP SP2 and Windows Server 2003 SP1&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;This is a list of some possible values we can use as ZoneId:&lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://www.minasi.com/newsletters/nws0803.htm" mce_href="http://www.minasi.com/newsletters/nws0803.htm"&gt;How Windows Knows that a File Is from the Internet: Manipulating Alternate Data Streams&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;NoZone = -1
MyComputer = 0
Intranet = 1
Trusted = 2
Internet = 3
Untrusted = 4
&lt;/PRE&gt;
&lt;P&gt;A value of&amp;nbsp;6 may work for us, too.&amp;nbsp;This value should be the same as resetting the checkbox "don't ask again" in the warning dialog.&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8660971" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/Vista/default.aspx">Vista</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Server+2008/default.aspx">Server 2008</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/XP/default.aspx">XP</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Server+2003/default.aspx">Server 2003</category></item><item><title>CAPICOM support on Windows Server 2008</title><link>http://blogs.msdn.com/alejacma/archive/2008/03/06/capicom-support-on-windows-server-2008.aspx</link><pubDate>Thu, 06 Mar 2008 09:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8067431</guid><dc:creator>alejacma</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/8067431.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=8067431</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'; mso-fareast-font-family: 'Times New Roman'"&gt;Hi all, welcome back,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'; mso-fareast-font-family: 'Times New Roman'"&gt;If you remember all the confusion there was regarding &lt;A class="" href="http://blogs.msdn.com/alejacma/archive/2007/10/19/capicom-support-on-windows-vista.aspx" mce_href="http://blogs.msdn.com/alejacma/archive/2007/10/19/capicom-support-on-windows-vista.aspx"&gt;CAPICOM support on Vista&lt;/A&gt;, now everything seems much clearer on Windows Server 2008. Our documentation team has done its homework, as we can see in &lt;A class="" href="http://msdn2.microsoft.com/en-gb/library/aa375732.aspx" mce_href="http://msdn2.microsoft.com/en-gb/library/aa375732.aspx"&gt;CAPICOM Reference&lt;/A&gt;:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face=Tahoma&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face=Tahoma&gt;"CAPICOM is &lt;STRONG&gt;available&lt;/STRONG&gt; for use in the following operating systems: &lt;STRONG&gt;Windows Server 2008&lt;/STRONG&gt;, &lt;STRONG&gt;Windows Vista&lt;/STRONG&gt;, Windows XP, and Windows 2000. It may be altered or unavailable in subsequent versions. &lt;STRONG&gt;Instead, use the .NET Framework&lt;/STRONG&gt; to implement security features."&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Tahoma&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Tahoma&gt;I hope this helps.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Tahoma&gt;Cheers,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Tahoma&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Tahoma&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;BR&gt;&lt;/P&gt;&lt;/FONT&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8067431" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/CAPICOM/default.aspx">CAPICOM</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Server+2008/default.aspx">Server 2008</category></item></channel></rss>