<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David&#039;s Blog</title>
	<atom:link href="http://www.davidmoore.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidmoore.info</link>
	<description>Computer says no</description>
	<lastBuildDate>Thu, 26 Jan 2012 21:49:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Creating a machine account login for SQL Server</title>
		<link>http://www.davidmoore.info/2012/01/27/creating-a-machine-account-login-for-sql-server/</link>
		<comments>http://www.davidmoore.info/2012/01/27/creating-a-machine-account-login-for-sql-server/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 21:49:25 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Entertainment]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/2012/01/27/creating-a-machine-account-login-for-sql-server/</guid>
		<description><![CDATA[<p>You can create a machine account login for SQL Server with the <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2012/01/27/creating-a-machine-account-login-for-sql-server/">Creating a machine account login for SQL Server</a></span>]]></description>
			<content:encoded><![CDATA[<p>You can create a machine account login for SQL Server with the following command:</p>
<pre style="padding-bottom: 0px; line-height: normal; width: auto; font-family: ; background: white; color: ; overflow: visible"><font face="Consolas"><span style="color: "><font color="#0000ff">CREATE</font></span>&#160;<span style="color: "><font color="#ff00ff">USER</font></span>&#160;<span style="color: "><font color="#008080">[MACHINENAME]</font></span>&#160;<span style="color: "><font color="#0000ff">FOR</font></span>&#160;<span style="color: "><font color="#0000ff">LOGIN</font></span>&#160;<span style="color: "><font color="#008080">[DOMAIN\MACHINENAME$]</font></span>&#160;<span style="color: "><font color="#0000ff">WITH</font></span>&#160;<span style="color: "><font color="#0000ff">DEFAULT_SCHEMA</font></span><span style="color: "><font color="#808080">=</font></span><span style="color: "><font color="#008080">[dbo]</font></span>
</font></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2012/01/27/creating-a-machine-account-login-for-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deleting and purging items from Team Foundation Server</title>
		<link>http://www.davidmoore.info/2011/08/08/deleting-and-purging-items-from-team-foundation-server/</link>
		<comments>http://www.davidmoore.info/2011/08/08/deleting-and-purging-items-from-team-foundation-server/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 23:32:00 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[destroy]]></category>
		<category><![CDATA[purge]]></category>
		<category><![CDATA[tfs]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/2011/08/08/deleting-and-purging-items-from-team-foundation-server/</guid>
		<description><![CDATA[<p>When you delete an item from TFS, it’s not actually permanently gone.</p>
<p>You can view deleted items by going to Tools &#62; Options &#62; Source Control &#62; Visual Studio Team Foundation Server and checking the Show deleted items in the Source Control Explorer option:</p>
<p></p>
<p>You can then see folders and files that have been deleted, which allows you <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2011/08/08/deleting-and-purging-items-from-team-foundation-server/">Deleting and purging items from Team Foundation Server</a></span>]]></description>
			<content:encoded><![CDATA[<p>When you delete an item from TFS, it’s not actually permanently gone.</p>
<p>You can view deleted items by going to <strong>Tools</strong> &gt; <strong>Options</strong> &gt; <strong>Source Control</strong> &gt; <strong>Visual Studio Team Foundation Server</strong> and checking the <strong>Show deleted items in the Source Control Explorer</strong> option:</p>
<p><a href="http://www.davidmoore.info/wp-content/uploads/2011/08/image.png" ><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://www.davidmoore.info/wp-content/uploads/2011/08/image_thumb.png" border="0" alt="image" width="244" height="143" /></a></p>
<p>You can then see folders and files that have been deleted, which allows you to right click on them to choose <strong>Undelete</strong> (or go to <strong>File</strong> &gt; <strong>Source Control</strong> &gt; <strong>Undelete</strong>).</p>
<p>It&#8217;s useful to show deleted items by default, but you may find that your source tree ends up a bit clogged with all the deleted files and folders.</p>
<p>You can purge items you want to delete permanently by using the TFS command-line tools.</p>
<p><strong>TF.EXE</strong> is found with Visual Studio 2010 under <strong>C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE</strong> for 64 bit machines, and <strong>C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE</strong> on 32 bit.</p>
<p>You might find it useful to add that path to your command line.</p>
<p>The commandlet you want to use is <strong>destroy</strong>, which tf.exe can give us info on:</p>
<blockquote><p><code>C:\Windows\System32&gt;tf help destroy<br />
TF - Team Foundation Version Control Tool, Version 10.0.30319.1<br />
Copyright (c) Microsoft Corporation.  All rights reserved.</p>
<p>Destroys, or permanently deletes, version-controlled items from Team<br />
Foundation version control.</p>
<p>tf destroy [/keephistory] itemspec1 [;versionspec]<br />
[itemspec2...itemspecN] [/stopat:versionspec] [/preview]<br />
[/startcleanup] [/noprompt] [/silent]<br />
[/login:username,[password]]<br />
[/collection:TeamProjectCollectionUrl]</p>
<p>Versionspec:<br />
Date/Time         D"any .Net Framework-supported format"<br />
or any of the date formats of the local machine<br />
Changeset number  Cnnnnnn<br />
Label             Llabelname<br />
Latest version    T<br />
Workspace         Wworkspacename;workspaceowner</code></p></blockquote>
<p>To run the command, you have to specify the collection URL. An easy way to get this is open your Team Explorer window in Visual Studio (<strong>View</strong> &gt; <strong>Team Explorer</strong>), select the root server node and look in the Properties window at the <strong>Url </strong>property.</p>
<p>Now you need the server name of the folder or file you want to purge. Locate the file or folder in the <strong>Source Control Explorer</strong>, right click and choose <strong>Properties&#8230;</strong></p>
<p>The <strong>Server Name:</strong> value is what you want and can be selected and copied to the clipboard.</p>
<p>Now you can run the command:</p>
<blockquote><p><code>tf destroy <strong>$/MyProject/Main/Bin</strong> /collection:http://servername:8080/tfs/myproject<br />
Do you want to destroy $/MyProject/Main/Bin and all of its children? (Yes/No) y<br />
Destroyed: $/MyProject/Main/Bin;X3601<br />
Destroyed: $/MyProject/Main/Bin/Native;X3601</code></p></blockquote>
<p>Now if you refresh in Solution Explorer, the purged items won&#8217;t even show up anymore.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2011/08/08/deleting-and-purging-items-from-team-foundation-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manually schedule a disk check at next restart</title>
		<link>http://www.davidmoore.info/2011/08/04/manually-schedule-a-disk-check-at-next-restart/</link>
		<comments>http://www.davidmoore.info/2011/08/04/manually-schedule-a-disk-check-at-next-restart/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 00:02:00 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[chkdsk]]></category>
		<category><![CDATA[disk]]></category>
		<category><![CDATA[fsutil]]></category>
		<category><![CDATA[scan]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/?p=445</guid>
		<description><![CDATA[<p>You can schedule a chkdsk at reboot time for a drive by using the Windows command line utility fsutil.</p>
<p>You do this by setting the &#8220;dirty&#8221; flag for a drive, which marks the drive for a chkdsk when you next reboot.</p>
<p>Usage:</p>

fsutil dirty query &#60;volume pathname&#62;

<p>e.g.</p>

fsutil dirty set C:

<p>You can check if a drive has been marked as <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2011/08/04/manually-schedule-a-disk-check-at-next-restart/">Manually schedule a disk check at next restart</a></span>]]></description>
			<content:encoded><![CDATA[<p>You can schedule a chkdsk at reboot time for a drive by using the Windows command line utility <a title="FSUtil @ microsoft.com" href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/fsutil.mspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.microsoft.com');">fsutil</a>.</p>
<p>You do this by setting the &#8220;dirty&#8221; flag for a drive, which marks the drive for a chkdsk when you next reboot.</p>
<p>Usage:</p>
<blockquote>
<pre>fsutil dirty query &lt;volume pathname&gt;</pre>
</blockquote>
<p>e.g.</p>
<blockquote>
<pre>fsutil dirty set <strong>C:</strong></pre>
</blockquote>
<p>You can check if a drive has been marked as dirty by using the query command:</p>
<blockquote>
<pre>fsutil dirty query &lt;volume pathname&gt;</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2011/08/04/manually-schedule-a-disk-check-at-next-restart/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Debugging MSBuild scripts</title>
		<link>http://www.davidmoore.info/2011/07/28/debugging-msbuild-scripts/</link>
		<comments>http://www.davidmoore.info/2011/07/28/debugging-msbuild-scripts/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 02:20:40 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[msbuild]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/2011/07/28/debugging-msbuild-scripts/</guid>
		<description><![CDATA[<p>If you want to debug an MSBuild script from without Visual Studio, you need to use the /debug command line option.</p>
<p>The trick is that this option is not normally available; you need to set a registry key to enable it.</p>
Enable the MSBuild Debugger
<p>Under the HKLM\Software\Microsoft\MSBuild\4.0 key, create a string value called EnableDebugger with a value of <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2011/07/28/debugging-msbuild-scripts/">Debugging MSBuild scripts</a></span>]]></description>
			<content:encoded><![CDATA[<p>If you want to debug an MSBuild script from without Visual Studio, you need to use the /debug command line option.</p>
<p>The trick is that this option is not normally available; you need to set a registry key to enable it.</p>
<h2>Enable the MSBuild Debugger</h2>
<p>Under the <strong>HKLM\Software\Microsoft\MSBuild\4.0</strong> key, create a string value called <strong>EnableDebugger</strong> with a value of “<strong>true</strong>”.</p>
<p>If you’re on a 64 bit system, you’ll also want to set the same value under the key <strong>HKLM\Software\Wow6432Node\Microsoft\MSBuild\4.0</strong>.</p>
<h2>Verify</h2>
<p>If you then run msbuild /help, you should now see the documentation on the /debug switch:</p>
<blockquote>
<pre>/debug
                    Causes a debugger prompt to appear immediately so that
                    Visual Studio can be attached for you to debug the
                    MSBuild XML and any tasks and loggers it uses.</pre>
</blockquote>
<h2>Debugging</h2>
<p>Now you can pass the<strong> /debug</strong> option to MSBuild when running it. This will immediately break into the debugger, which will usually give you a prompt to select your JIT debugger:</p>
<p><a href="http://www.davidmoore.info/wp-content/uploads/2011/07/image1.png" ><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://www.davidmoore.info/wp-content/uploads/2011/07/image_thumb1.png" border="0" alt="image" width="225" height="244" /></a></p>
<p>The debug session will then start at the very top of the root MSBuild project file, and you can go from there.</p>
<p>You can set breakpoints in your MSBuild project files from within the IDE, and inspect the MSBuild variables using Locals and Watch.</p>
<p>Some more tips:</p>
<ul>
<li>Your breakpoints may not show up to be hit yet until the project file they’re contained in actually loads. If you continue on, the project will get loaded and the breakpoint will get hit.</li>
<li>To prevent yourself breaking into framework code that you don’t have source for, you can check the <strong>Enable Just My Code (Managed only)</strong> option under <strong>Debug</strong> &gt; <strong>Options and Settings</strong> &gt; <strong>Debugging</strong> &gt; <strong>General</strong>.</li>
<li>From the Immediate window to evaluate conditions using EvaluateCondition:</li>
</ul>
<blockquote>
<pre>Immediate input: EvaluateCondition("'$(MyProperty)' == ''")
Immediate output: false</pre>
</blockquote>
<ul>
<li>From the Immediate window you can evaluate expressions using EvaluateExpression (remember to escape slashes):</li>
</ul>
<blockquote>
<pre>Immediate input: EvaluateExpression("C:\\$(MyFolderName)")
Immediate output: C:\MyFolder</pre>
</blockquote>
<p>Original article and full details (recommended reading) is here: <a title="http://blogs.msdn.com/b/visualstudio/archive/2010/07/06/debugging-msbuild-script-with-visual-studio.aspx" href="http://blogs.msdn.com/b/visualstudio/archive/2010/07/06/debugging-msbuild-script-with-visual-studio.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/blogs.msdn.com');">http://blogs.msdn.com/b/visualstudio/archive/2010/07/06/debugging-msbuild-script-with-visual-studio.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2011/07/28/debugging-msbuild-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating a type library for Visual Basic 6 ActiveX Components</title>
		<link>http://www.davidmoore.info/2011/07/18/generating-a-type-library-for-visual-basic-6-activex-components/</link>
		<comments>http://www.davidmoore.info/2011/07/18/generating-a-type-library-for-visual-basic-6-activex-components/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 02:12:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Entertainment]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/2011/07/18/generating-a-type-library-for-visual-basic-6-activex-components/</guid>
		<description><![CDATA[<p>When generating setup code or isolation code (for Side by Side assemblies and Registration-free COM), VB6 ActiveX Components can be a little troublesome.</p>
<p>ActiveX exes in particular can be difficult, with the WiX heat tool and various SxS tools not being able to harvest COM registration information from them properly.</p>
<p>A good way of avoiding these problems is <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2011/07/18/generating-a-type-library-for-visual-basic-6-activex-components/">Generating a type library for Visual Basic 6 ActiveX Components</a></span>]]></description>
			<content:encoded><![CDATA[<p>When generating setup code or isolation code (for Side by Side assemblies and Registration-free COM), VB6 ActiveX Components can be a little troublesome.</p>
<p>ActiveX exes in particular can be difficult, with the WiX heat tool and various SxS tools not being able to harvest COM registration information from them properly.</p>
<p>A good way of avoiding these problems is to generate a type library (.tlb) from the VB6 component, and then pointing the code generation tools at the type library.</p>
<p>In VB6, you can generate a Type Library (.tlb) file for an ActiveX component:</p>
<ol>
<li><strong>Project</strong> &gt; <strong>&lt;Project Name&gt; Properties…</strong></li>
<li>Go to the <strong>Component</strong> tab</li>
<li>Check <strong>Remote Server Files</strong></li>
<li>Click <strong>OK</strong> and build the project</li>
</ol>
<p><a href="http://www.davidmoore.info/wp-content/uploads/2011/07/image.png" ><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidmoore.info/wp-content/uploads/2011/07/image_thumb.png" width="234" height="244" /></a></p>
<p>You should now see a <strong>.tlb</strong> and <strong>.vbr</strong> file next to your binary.</p>
<p>The .vbr file is a text file containing registry information, which will be very helpful if the type library is still missing information you want to use for your isolation or installation authoring.</p>
<h2>Reference</h2>
<p><a href="http://support.microsoft.com/kb/161272" onclick="javascript:pageTracker._trackPageview('/outbound/article/support.microsoft.com');">How To Make a Typelib (.TLB) File for ActiveX Components @ MSDN</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2011/07/18/generating-a-type-library-for-visual-basic-6-activex-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When System.Diagnostics.Process creates a process, it inherits inheritable handles from the parent process.</title>
		<link>http://www.davidmoore.info/2011/06/21/when-system-diagnostics-process-creates-a-process-it-inherits-inheritable-handles-from-the-parent-process/</link>
		<comments>http://www.davidmoore.info/2011/06/21/when-system-diagnostics-process-creates-a-process-it-inherits-inheritable-handles-from-the-parent-process/#comments</comments>
		<pubDate>Tue, 21 Jun 2011 04:06:13 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Entertainment]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/?p=421</guid>
		<description><![CDATA[<p>This post covers the cause of a bug I ran into at work.</p>
<p>Our application would check for available updates when it started, and if they were found, it would launch the installer directly and exit the application immediately, so that the installer could run without encountering file locks.</p>
<p>The installer was complaining our executable was still locked, <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2011/06/21/when-system-diagnostics-process-creates-a-process-it-inherits-inheritable-handles-from-the-parent-process/">When System.Diagnostics.Process creates a process, it inherits inheritable handles from the parent process.</a></span>]]></description>
			<content:encoded><![CDATA[<p>This post covers the cause of a bug I ran into at work.</p>
<p>Our application would check for available updates when it started, and if they were found, it would launch the installer directly and exit the application immediately, so that the installer could run without encountering file locks.</p>
<p>The installer was complaining our executable was still locked, meaning it had to schedule the overwrite of the old file with the new one after a reboot.</p>
<p>After quite a bit of troubleshooting, it looked like while the application was launching msiexec and closing down successfully, msiexec was still grabbing the same lock handle to the exe for no good reason.</p>
<p>So what was happening?</p>
<h2>System.Diagnostics.Process</h2>
<p>When you create a new process from a .NET application, you would use the classes in the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">System.Diagnostics</a> namespace. Specifically, <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">Process</a> and <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">ProcessStartInfo</a>. As we were in this case.</p>
<p>These wrap the Windows API function <a href="http://msdn.microsoft.com/en-us/library/ms682425(v=vs.85).aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">CreateProcess</a> and its alternatives and supporting types.</p>
<p>If we look at the CreateProcess definition, there’s a boolean argument in there called bInheritHandles:</p>
<blockquote><p>BOOL WINAPI CreateProcess(<br />
__in_opt     LPCTSTR lpApplicationName,<br />
__inout_opt  LPTSTR lpCommandLine,<br />
__in_opt     LPSECURITY_ATTRIBUTES lpProcessAttributes,<br />
__in_opt     LPSECURITY_ATTRIBUTES lpThreadAttributes,<br />
<strong>__in         BOOL bInheritHandles</strong>,<br />
__in         DWORD dwCreationFlags,<br />
__in_opt     LPVOID lpEnvironment,<br />
__in_opt     LPCTSTR lpCurrentDirectory,<br />
__in         LPSTARTUPINFO lpStartupInfo,<br />
__out        LPPROCESS_INFORMATION lpProcessInformation<br />
);</p></blockquote>
<p>What does the Windows API documentation say about this?</p>
<blockquote><p>If this parameter is TRUE, each inheritable handle in the calling process is inherited by the new process. If the parameter is FALSE, the handles are not inherited. Note that inherited handles have the same value and access rights as the original handles.</p></blockquote>
<p>Inheritable handles?</p>
<blockquote><p><a title="Handle Inheritance" href="http://msdn.microsoft.com/en-us/library/ms724466(v=vs.85).aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">Handle Inheritance</a></p>
<p>A child process can inherit handles from its parent process. An inherited handle is valid only in the context of the child process. To enable a child process to inherit open handles from its parent process, use the following steps.</p>
<ol>
<li>Create the handle with the bInheritHandle member of the SECURITY_ATTRIBUTES structure set to TRUE.</li>
<li>Create the child process using the CreateProcess function, with the bInheritHandles parameter set to TRUE.</li>
</ol>
</blockquote>
<p>Well if we look at the internals of .NET, and look at how the Process class is calling CreateProcess, we find that it’s passing bInheritHandles as TRUE.</p>
<p>So this means if we start a process using the System.Diagnostics classes, the child process will inherit our inheritable handles.</p>
<p>What was happening is the locked file handle to wsClient.exe was being inherited from the parent process to the Windows Installer, so the executable was remaining locked even when the parent process exited.</p>
<h2>Solution</h2>
<p>One solution is to avoid System.Diagnostics in this particular instance, and use CreateProcess manually when we launch our child process, to ensure it doesn’t inherit handles.</p>
<p>I would recommend you use the System.Diagnostics classes in any other case.</p>
<h2>Code</h2>
<pre style="padding-bottom: 0px; line-height: normal; width: auto; background: #fdf6e3; overflow: visible;"><span style="font-family: &amp;amp;amp;"><strong><span><span style="color: #859900;">using</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">System</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
</span><span><span style="color: #859900;">using</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">System</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">Runtime</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">ConstrainedExecution</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
</span><span><span style="color: #859900;">using</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">System</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">Runtime</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">InteropServices</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
</span><span><span style="color: #859900;">using</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">System</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">Security</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
</span><span><span style="color: #859900;">using</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">System</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">Security</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">Permissions</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
</span><span><span style="color: #859900;">using</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">System</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">Text</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
</span><span><span style="color: #859900;">using</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">Microsoft</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">Win32</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">SafeHandles</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;

</span><span><span style="color: #859900;">namespace</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">CreateProcessTest</span></span>
</strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">{
    [</span><span><span style="color: #00008b;">StructLayout</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">LayoutKind</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Sequential</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)]
    </span><span><span style="color: #859900;">internal</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">class</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">ProcessInformation</span></span>
</strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">    {
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">hProcess</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">hThread</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">dwProcessId</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">dwThreadId</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
    }

    [</span><span><span style="color: #00008b;">StructLayout</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">LayoutKind</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Sequential</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)]
    </span><span><span style="color: #859900;">internal</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">class</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">StartupInfo</span></span>
</strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">    {
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">cb</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">lpReserved</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">lpDesktop</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">lpTitle</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">dwX</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">dwY</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">dwXSize</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">dwYSize</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">dwXCountChars</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">dwYCountChars</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">dwFillAttribute</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">dwFlags</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">short</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">wShowWindow</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">short</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">cbReserved2</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">lpReserved2</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeFileHandle</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">hStdInput</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeFileHandle</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">false</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeFileHandle</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">hStdOutput</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeFileHandle</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">false</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeFileHandle</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">hStdError</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeFileHandle</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">false</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);

         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">StartupInfo</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">()
         {
             </span><span><span style="color: #800080;">dwY</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #2aa198;">0</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
             </span><span><span style="color: #800080;">cb</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">SizeOf</span></span><span style="color: #586e75;">(</span><span><span style="color: #859900;">this</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);
         }

         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">void</span></span><span style="color: #586e75;"> </span><span><span style="color: #008b8b;">Dispose</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">()
         {
             </span><span><span style="color: #93a1a1;">// close the handles created for child process</span></span>
<span style="color: #586e75;">            </span><span><span style="color: #859900;"> if</span></span><span style="color: #586e75;"> (</span><span><span style="color: #800080;">hStdInput</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">!=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">null</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">&amp;&amp;</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">!</span></span><span><span style="color: #800080;">hStdInput</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">IsInvalid</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)
             {
                 </span><span><span style="color: #800080;">hStdInput</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">Close</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">();
                 </span><span><span style="color: #800080;">hStdInput</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">null</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
             }

             </span><span><span style="color: #859900;">if</span></span><span style="color: #586e75;"> (</span><span><span style="color: #800080;">hStdOutput</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">!=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">null</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">&amp;&amp;</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">!</span></span><span><span style="color: #800080;">hStdOutput</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">IsInvalid</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)
             {
                 </span><span><span style="color: #800080;">hStdOutput</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">Close</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">();
                 </span><span><span style="color: #800080;">hStdOutput</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">null</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
             }

             </span><span><span style="color: #859900;">if</span></span><span style="color: #586e75;"> (</span><span><span style="color: #800080;">hStdError</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">==</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">null</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">||</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">hStdError</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">IsInvalid</span></span><span style="color: #586e75;">) </span><span><span style="color: #859900;">return</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;

             </span><span><span style="color: #800080;">hStdError</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">Close</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">();
             </span><span><span style="color: #800080;">hStdError</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">null</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         }
     }

     [</span><span><span style="color: #00008b;">StructLayout</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">LayoutKind</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Sequential</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)]
     </span><span><span style="color: #859900;">internal</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">class</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SecurityAttributes</span></span>
</strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">     {
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">nLength</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #2aa198;">12</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeLocalMemHandle</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">lpSecurityDescriptor</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeLocalMemHandle</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">false</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);
         </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">bool</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">bInheritHandle</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
     }

     [</span><span><span style="color: #00008b;">SuppressUnmanagedCodeSecurity</span></span><span style="color: #586e75;">, </span><span><span style="color: #00008b;">HostProtection</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">SecurityAction</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">LinkDemand</span></span><span style="color: #586e75;">, </span><span><span style="color: #800080;">MayLeakOnAbort</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">true</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)]
     </span><span><span style="color: #859900;">internal</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">sealed</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">class</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeLocalMemHandle</span></span><span style="color: #586e75;"> : </span><span><span style="color: #00008b;">SafeHandleZeroOrMinusOneIsInvalid</span></span>
</strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">     {
         </span><span><span style="color: #859900;">internal</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeLocalMemHandle</span></span><span style="color: #586e75;">() : </span><span><span style="color: #00008b;">base</span></span><span style="color: #586e75;">(</span><span><span style="color: #859900;">true</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">) { }

         [</span><span><span style="color: #00008b;">SecurityPermission</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">SecurityAction</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">LinkDemand</span></span><span style="color: #586e75;">, </span><span><span style="color: #800080;">UnmanagedCode</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">true</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)]
         </span><span><span style="color: #859900;">internal</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeLocalMemHandle</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">existingHandle</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">bool</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">ownsHandle</span></span><span style="color: #586e75;">) : </span><span><span style="color: #00008b;">base</span></span><span style="color: #586e75;">(</span><span><span style="color: #657b83;">ownsHandle</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)
         {
             </span><span><span style="color: #008b8b;">SetHandle</span></span><span style="color: #586e75;">(</span><span><span style="color: #657b83;">existingHandle</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);
         }

         [</span><span><span style="color: #00008b;">DllImport</span></span><span style="color: #586e75;">(</span><span><span style="color: #2aa198;">"advapi32.dll"</span></span><span style="color: #586e75;">, </span><span><span style="color: #800080;">CharSet</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">CharSet</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Auto</span></span><span style="color: #586e75;">, </span><span><span style="color: #800080;">SetLastError</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">true</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)]
         </span><span><span style="color: #859900;">internal</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">static</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">extern</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">bool</span></span><span style="color: #586e75;"> </span><span><span style="color: #008b8b;">ConvertStringSecurityDescriptorToSecurityDescriptor</span></span><span style="color: #586e75;">(</span><span><span style="color: #859900;">string</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">stringSecurityDescriptor</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
             </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">stringSDRevision</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">out</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SafeLocalMemHandle</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">pSecurityDescriptor</span></span><span style="color: #586e75;">, </span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">securityDescriptorSize</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);

         [</span><span><span style="color: #00008b;">ReliabilityContract</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">Consistency</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">WillNotCorruptState</span></span><span style="color: #586e75;">, </span><span><span style="color: #00008b;">Cer</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Success</span></span><span style="color: #586e75;">), </span><span><span style="color: #00008b;">DllImport</span></span><span style="color: #586e75;">(</span><span><span style="color: #2aa198;">"kernel32.dll"</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)]
         </span><span><span style="color: #859900;">private</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">static</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">extern</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #008b8b;">LocalFree</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">hMem</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);

         </span><span><span style="color: #859900;">protected</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">override</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">bool</span></span><span style="color: #586e75;"> </span><span><span style="color: #008b8b;">ReleaseHandle</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">()
         {
             </span><span><span style="color: #859900;">return</span></span><span style="color: #586e75;"> (</span><span><span style="color: #008b8b;">LocalFree</span></span><span style="color: #586e75;">(</span><span><span style="color: #800080;">handle</span></span><span style="color: #586e75;">) </span><span><span style="color: #008b8b;">==</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);
         }
     }

     </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">static</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">class</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">Test</span></span>
</strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">     {
         </span><span><span style="color: #859900;">const</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #800080;">normalPriorityClass</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #2aa198;">0x0020</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;

         [</span><span><span style="color: #00008b;">DllImport</span></span><span style="color: #586e75;">(</span><span><span style="color: #2aa198;">"Kernel32"</span></span><span style="color: #586e75;">, </span><span><span style="color: #800080;">CharSet</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">CharSet</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Auto</span></span><span style="color: #586e75;">, </span><span><span style="color: #800080;">SetLastError</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">true</span></span><span style="color: #586e75;">, </span><span><span style="color: #800080;">BestFitMapping</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">false</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)]
         </span><span><span style="color: #859900;">internal</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">static</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">extern</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">bool</span></span><span style="color: #586e75;"> </span><span><span style="color: #008b8b;">CreateProcess</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">(
             [</span><span><span style="color: #00008b;">MarshalAs</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">UnmanagedType</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">LPTStr</span></span><span style="color: #586e75;">)]</span><span><span style="color: #859900;">string</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">applicationName</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
             </span><span><span style="color: #00008b;">StringBuilder</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">commandLine</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
             </span><span><span style="color: #00008b;">SecurityAttributes</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">processAttributes</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
             </span><span><span style="color: #00008b;">SecurityAttributes</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">threadAttributes</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
             </span><span><span style="color: #859900;">bool</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">inheritHandles</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
             </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">creationFlags</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
             </span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">environment</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
             [</span><span><span style="color: #00008b;">MarshalAs</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">UnmanagedType</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">LPTStr</span></span><span style="color: #586e75;">)]</span><span><span style="color: #859900;">string</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">currentDirectory</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
             </span><span><span style="color: #00008b;">StartupInfo</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">startupInfo</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
             </span><span><span style="color: #00008b;">ProcessInformation</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">processInformation</span></span>
</strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">        );

        </span><span><span style="color: #859900;">public</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">static</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">void</span></span><span style="color: #586e75;"> </span><span><span style="color: #008b8b;">Main</span></span><span style="color: #586e75;">(</span><span><span style="color: #859900;">string</span></span><span style="color: #586e75;">[] </span><span><span style="color: #657b83;">args</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">)
        {
            </span><span><span style="color: #93a1a1;">// We can use the string builder to build up our full command line, including arguments</span></span>
<span style="color: #586e75;">            </span><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">sb</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">StringBuilder</span></span><span style="color: #586e75;">(</span><span><span style="color: #2aa198;">"notepad.exe"</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);
            </span><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">processInformation</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">ProcessInformation</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">();
            </span><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">startupInfo</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">StartupInfo</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">();
            </span><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">processSecurity</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SecurityAttributes</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">();
            </span><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">threadSecurity</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">SecurityAttributes</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">();

            </span><span><span style="color: #657b83;">processSecurity</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">nLength</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">SizeOf</span></span><span style="color: #586e75;">(</span><span><span style="color: #657b83;">processSecurity</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);
            </span><span><span style="color: #657b83;">threadSecurity</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">nLength</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">SizeOf</span></span><span style="color: #586e75;">(</span><span><span style="color: #657b83;">threadSecurity</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">);

            </span><span><span style="color: #859900;">if</span></span><span style="color: #586e75;"> (</span><span><span style="color: #008b8b;">CreateProcess</span></span><span style="color: #586e75;">(</span><span><span style="color: #859900;">null</span></span><span style="color: #586e75;">, </span><span><span style="color: #657b83;">sb</span></span><span style="color: #586e75;">, </span><span><span style="color: #657b83;">processSecurity</span></span><span style="color: #586e75;">, </span><span><span style="color: #657b83;">threadSecurity</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">false</span></span><span style="color: #586e75;">, </span><span><span style="color: #800080;">normalPriorityClass</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">,
                 </span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">null</span></span><span style="color: #586e75;">, </span><span><span style="color: #657b83;">startupInfo</span></span><span style="color: #586e75;">, </span><span><span style="color: #657b83;">processInformation</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">))
            {
                </span><span><span style="color: #93a1a1;">// Process was created successfully</span></span>
<span style="color: #586e75;">                </span><span><span style="color: #859900;">return</span></span></strong></span><span style="font-family: &amp;amp;amp;"><strong><span style="color: #586e75;">;
            }

            </span><span><span style="color: #93a1a1;">// We couldn't create the process, so raise an exception with the details.</span></span>
<span style="color: #586e75;">            </span><span><span style="color: #859900;">throw</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">GetExceptionForHR</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">GetHRForLastWin32Error</span></span></strong><span style="color: #586e75;"><strong>());
         }
     }
}</strong></span></span></pre>
<h2>Utilities</h2>
<p>I used the invaluable <a href="http://technet.microsoft.com/en-nz/sysinternals/bb842062" onclick="javascript:pageTracker._trackPageview('/outbound/article/technet.microsoft.com');">SysInternals</a> tools Process Monitor, Process Explorer and Handle to diagnose what was going on.</p>
<h2>References</h2>
<p><a href="http://msdn.microsoft.com/en-us/library/ms724466(v=vs.85).aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">Handle Inheritance @ MSDN</a></p>
<p><a href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/94ba760c-7080-4614-8a56-15582c48f900/" onclick="javascript:pageTracker._trackPageview('/outbound/article/social.msdn.microsoft.com');">Child process keeps parent’s socket open – Diagnostics.Process and Net.TcpListene @ social.msdn.microsoft.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2011/06/21/when-system-diagnostics-process-creates-a-process-it-inherits-inheritable-handles-from-the-parent-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET Decompilers</title>
		<link>http://www.davidmoore.info/2011/06/20/net-decompilers/</link>
		<comments>http://www.davidmoore.info/2011/06/20/net-decompilers/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 02:55:03 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Entertainment]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/2011/06/20/net-decompilers/</guid>
		<description><![CDATA[Reflector history
<p>The de facto .NET decompiler has been Reflector for what seems like forever.</p>
<p>Reflector was originally developed by Lutz Roeder, and made freely available to the community.</p>
<p>It was acquired by Red Gate Software in August 2008, who promised to maintain it as a free product.</p>
<p>They reneged on this promise in February 2011, stating that Reflector would <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2011/06/20/net-decompilers/">.NET Decompilers</a></span>]]></description>
			<content:encoded><![CDATA[<h2>Reflector history</h2>
<p>The de facto .NET decompiler has been Reflector for what seems like forever.</p>
<p>Reflector was originally developed by Lutz Roeder, and made freely available to the community.</p>
<p>It was acquired by Red Gate Software in August 2008, who promised to maintain it as a free product.</p>
<p>They reneged on this promise in February 2011, stating that Reflector would become a commercial product.</p>
<p>This created a community backlash, culminating in creation and/or promotion of several free rival products through open source or offered by other vendors.</p>
<p>Red Gate backpedalled in April 2011 by saying that the final 6.8 version of Reflector would continue to be free, while future releases of Reflector (moving forward with version 7.x) would be paid for.</p>
<h2>List of .NET Decompilers</h2>
<table border="0" cellspacing="2" cellpadding="2" width="860">
<tbody>
<tr>
<td valign="top" width="116">Name</td>
<td valign="top" width="109">Company</td>
<td valign="top" width="115">License</td>
<td valign="top" width="93">Language Support</td>
<td valign="top" width="83">Rating</td>
<td valign="top" width="328">Comments</td>
</tr>
<tr>
<td valign="top" width="126"><a href="http://wiki.sharpdevelop.net/ilspy.ashx" onclick="javascript:pageTracker._trackPageview('/outbound/article/wiki.sharpdevelop.net');">ILSpy</a></td>
<td valign="top" width="119">SharpDevelop</td>
<td valign="top" width="125">Open Source</td>
<td valign="top" width="102">C# 4 except for expression trees, dynamic, fixed fields</td>
<td valign="top" width="81">&nbsp;</td>
<td valign="top" width="312">ILSpy development was started directly as a result of Red Gate’s announcement that Reflector would be paid for.</td>
</tr>
<tr>
<td valign="top" width="131"><a href="http://www.devextras.com/decompiler/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.devextras.com');">CodeReflect</a></td>
<td valign="top" width="123">DevExtras</td>
<td valign="top" width="129">Free (Commercially supported)</td>
<td valign="top" width="107">MSIL, C#, VB.NET</td>
<td valign="top" width="81">&nbsp;</td>
<td valign="top" width="306">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="133"><a href="http://www.telerik.com/products/decompiling.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.telerik.com');">JustDecompile</a></td>
<td valign="top" width="125">Telerik</td>
<td valign="top" width="131">Free (Commerically supported)</td>
<td valign="top" width="109">&nbsp;</td>
<td valign="top" width="80">&nbsp;</td>
<td valign="top" width="300">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="138"><a href="http://www.jetbrains.com/decompiler/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.jetbrains.com');">dotPeek</a></td>
<td valign="top" width="125">JetBrains</td>
<td valign="top" width="131">Free (Commercially supported)</td>
<td valign="top" width="109">C#</td>
<td valign="top" width="80">&nbsp;</td>
<td valign="top" width="298">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="140"><a href="http://www.red-gate.com/MessageBoard/viewtopic.php?t=13307" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.red-gate.com');">Reflector 6.8</a></td>
<td valign="top" width="125">Red Gate</td>
<td valign="top" width="131">Free</td>
<td valign="top" width="109">MSIL, C#, VB.NET, more through plugins</td>
<td valign="top" width="80">&nbsp;</td>
<td valign="top" width="298">Any future versions (7.x) are paid for. You need to be an existing Reflector user, and allow your Reflector to update to version 6.8.</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2011/06/20/net-decompilers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to check if the current user is an Administrator (even if UAC is on)</title>
		<link>http://www.davidmoore.info/2011/06/20/how-to-check-if-the-current-user-is-an-administrator-even-if-uac-is-on/</link>
		<comments>http://www.davidmoore.info/2011/06/20/how-to-check-if-the-current-user-is-an-administrator-even-if-uac-is-on/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 23:23:47 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Entertainment]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/2011/06/20/how-to-check-if-the-current-user-is-an-administrator-even-if-uac-is-on/</guid>
		<description><![CDATA[<p>There may be a scenario where you want to determine from code if the current user is an Administrator.</p>
<p>One example of this which I have had to deal with is checking for software updates.</p>
<p>Say your application contacts a service to see if there is a newer version of the application available; if so, you can download <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2011/06/20/how-to-check-if-the-current-user-is-an-administrator-even-if-uac-is-on/">How to check if the current user is an Administrator (even if UAC is on)</a></span>]]></description>
			<content:encoded><![CDATA[<p>There may be a scenario where you want to determine from code if the current user is an Administrator.</p>
<p>One example of this which I have had to deal with is checking for software updates.</p>
<p>Say your application contacts a service to see if there is a newer version of the application available; if so, you can download and run the installer.</p>
<p>Imagine that the installer requires admin privileges; you don’t want to run the installer if the current user does not have administrative privileges.</p>
<p>So how can we check if the user is an admin or not?</p>
<h2>In VB6, C++ etc</h2>
<p>There is a Windows API function you can use very easily to see if the current user is an admin: <a href="http://msdn.microsoft.com/en-us/library/bb776463(v=vs.85).aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">IsUserAnAdmin</a>.</p>
<blockquote><p>BOOL IsUserAnAdmin(void);</p></blockquote>
<h3>Visual Basic 6 Declaration</h3>
<blockquote><p><span style="font-family: &amp;amp;quot;"><span style="line-height: 12pt;"><span style="color: #00007f;"><span style="font-size: 10pt;">Private</span></span></span><span style="font-size: 10pt;"><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Declare</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Function</span></span><span style="line-height: 12pt;"> IsUserAnAdmin </span><span style="line-height: 12pt;"><span style="color: #00007f;">Lib</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #7f007f;">&#8220;Shell32&#8243;</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Alias</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #7f007f;">&#8220;#680&#8243;</span></span><span style="line-height: 12pt;"> () </span><span style="line-height: 12pt;"><span style="color: #00007f;">As</span></span><span style="line-height: 12pt;"> </span></span><span style="line-height: 12pt;"><span style="font-size: 10pt; color: #00007f;">Integer</span></span></span></p></blockquote>
<p>While you can still use this, it is actually deprecated, and the documentation recommends you call the <a href="http://msdn.microsoft.com/en-us/library/aa376389(v=vs.85).aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">CheckTokenMembership</a> function instead (which IsUserAnAdmin is a wrapper for).</p>
<h2>.NET</h2>
<h3>C#.NET</h3>
<p><span style="font-family: &amp;amp;quot;"><strong><span><span style="color: #859900;">using</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">System</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">;<br />
</span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span><span style="color: #859900;">using</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">System</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">Security</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #00008b;">Principal</span></span><span style="color: #586e75;">;</span></strong></span></p>
<pre style="padding-bottom: 0px; line-height: normal; width: auto; background: #fdf6e3; overflow: visible;"><span style="font-family: &amp;amp;quot;"><strong><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">identity</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">WindowsIdentity</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">GetCurrent</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">();
</span><span><span style="color: #859900;">if</span></span><span style="color: #586e75;"> (</span><span><span style="color: #657b83;">identity</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">==</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">null</span></span><span style="color: #586e75;">) </span><span><span style="color: #859900;">throw</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">InvalidOperationException</span></span><span style="color: #586e75;">(</span><span><span style="color: #2aa198;">"Couldn't get the current user identity"</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">);
</span><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">principal</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">WindowsPrincipal</span></span><span style="color: #586e75;">(</span><span><span style="color: #657b83;">identity</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">);</span>
<span><span style="color: #859900;">return</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">principal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">IsInRole</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">WindowsBuiltInRole</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Administrator</span></span><span style="color: #586e75;">)</span><span style="color: #586e75;">;</span></strong></span></pre>
<h2>User Account Control (UAC)</h2>
<p>A problem arises when you use any of the above code on a machine that has UAC enabled, and the process is not elevated.</p>
<p>While the user may be an administrator, when the process is not elevated yet, the user has a split token &#8211; which doesn’t have the administrator privileges.</p>
<p>A way around this is to use the <a href="http://msdn.microsoft.com/en-us/library/aa446671(v=VS.85).aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">GetTokenInformation</a> API call to inspect the token to see if it’s a split token. In <em>most</em> cases this will mean that UAC is on and the current user is an administrator.</p>
<p><em>This is not 100% reliable</em> (see References) but it’s probably the best we can do for now.</p>
<h3>C#.NET</h3>
<p>This code is slightly easier in .NET, as there’s already a fair amount of code we don’t have to write to get the current process’s token.</p>
<p>First, we’ll need some code to support the GetTokenInformation API call:</p>
<pre style="padding-bottom: 0px; line-height: normal; width: auto; background: #fdf6e3; overflow: visible;"><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">[</span><span><span style="color: #00008b;">DllImport</span></span><span style="color: #586e75;">(</span><span><span style="color: #2aa198;">"advapi32.dll"</span></span><span style="color: #586e75;">, </span><span><span style="color: #800080;">SetLastError</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">true</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">)]
</span><span><span style="color: #859900;">static</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">extern</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">bool</span></span><span style="color: #586e75;"> </span><span><span style="color: #008b8b;">GetTokenInformation</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">tokenHandle</span></span><span style="color: #586e75;">, </span><span><span style="color: #00008b;">TokenInformationClass</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">tokenInformationClass</span></span><span style="color: #586e75;">, </span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">tokenInformation</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">tokenInformationLength</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">out</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">returnLength</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">);

</span><span style="color: #93a1a1;"><span style="background-color: #eee8d5;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">///</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;"> </span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">&lt;summary&gt;</span></span></span>
<span style="color: #93a1a1;"><span style="background-color: #eee8d5;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">///</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;"> Passed to </span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">&lt;see cref=</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">"GetTokenInformation"</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">/&gt;</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;"> to specify what</span></span></span>
<span style="color: #93a1a1;"><span style="background-color: #eee8d5;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">///</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;"> information about the token to return.</span></span></span>
<span style="color: #93a1a1;"><span style="background-color: #eee8d5;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">///</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;"> </span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">&lt;/summary&gt;</span></span></span>
<span><span style="color: #859900;">enum</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">TokenInformationClass</span></span>
</strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">{
     </span><span><span style="color: #800080;">TokenUser</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #2aa198;">1</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenGroups</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenPrivileges</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenOwner</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenPrimaryGroup</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenDefaultDacl</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenSource</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenType</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenImpersonationLevel</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenStatistics</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenRestrictedSids</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenSessionId</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenGroupsAndPrivileges</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenSessionReference</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenSandBoxInert</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenAuditPolicy</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenOrigin</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenElevationType</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenLinkedToken</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenElevation</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenHasRestrictions</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenAccessInformation</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenVirtualizationAllowed</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenVirtualizationEnabled</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenIntegrityLevel</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenUiAccess</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenMandatoryPolicy</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">TokenLogonSid</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
     </span><span><span style="color: #800080;">MaxTokenInfoClass</span></span>
</strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">}

</span><span style="color: #93a1a1;"><span style="background-color: #eee8d5;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">///</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;"> </span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">&lt;summary&gt;</span></span></span>
<span style="color: #93a1a1;"><span style="background-color: #eee8d5;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">///</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;"> The elevation type for a user token.</span></span></span>
<span style="color: #93a1a1;"><span style="background-color: #eee8d5;"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">///</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;"> </span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%;">&lt;/summary&gt;</span></span></span>
<span><span style="color: #859900;">enum</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">TokenElevationType</span></span>
</strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">{
    </span><span><span style="color: #800080;">TokenElevationTypeDefault</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #2aa198;">1</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
    </span><span><span style="color: #800080;">TokenElevationTypeFull</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">,
    </span><span><span style="color: #800080;">TokenElevationTypeLimited</span></span>
<span style="color: #586e75;">}</span></strong></span></pre>
<p><span style="font-family: &amp;amp;quot;"><strong><span><span style="color: #859900;"> </span></span></strong></span></p>
<p>Then, the actual code to detect if the user is an Administrator (returning true if they are, otherwise false).</p>
<pre style="padding-bottom: 0px; line-height: normal; width: auto; background: #fdf6e3; overflow: visible;"><span style="font-family: &amp;amp;quot;"><strong><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">identity</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">WindowsIdentity</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">GetCurrent</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">();
</span><span><span style="color: #859900;">if</span></span><span style="color: #586e75;"> (</span><span><span style="color: #657b83;">identity</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">==</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">null</span></span><span style="color: #586e75;">) </span><span><span style="color: #859900;">throw</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">InvalidOperationException</span></span><span style="color: #586e75;">(</span><span><span style="color: #2aa198;">"Couldn't get the current user identity"</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">);
</span><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">principal</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">WindowsPrincipal</span></span><span style="color: #586e75;">(</span><span><span style="color: #657b83;">identity</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">);

</span><span><span style="color: #93a1a1;">// Check if this user has the Administrator role. If they do, return immediately.</span></span>
<span><span style="color: #93a1a1;">// If UAC is on, and the process is not elevated, then this will actually return false.</span></span>
<span><span style="color: #859900;">if</span></span><span style="color: #586e75;"> (</span><span><span style="color: #657b83;">principal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">IsInRole</span></span><span style="color: #586e75;">(</span><span><span style="color: #00008b;">WindowsBuiltInRole</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Administrator</span></span><span style="color: #586e75;">)) </span><span><span style="color: #859900;">return</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">true</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">;

</span><span><span style="color: #93a1a1;">// If we're not running in Vista onwards, we don't have to worry about checking for UAC.</span></span>
<span><span style="color: #859900;">if</span></span><span style="color: #586e75;"> (</span><span><span style="color: #00008b;">Environment</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">OSVersion</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Platform</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">!=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">PlatformID</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Win32NT</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">||</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">Environment</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">OSVersion</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Version</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Major</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">&lt;</span></span><span style="color: #586e75;"> </span><span><span style="color: #2aa198;">6</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">)
{
     <span><span style="color: #93a1a1;">// Operating system does not support UAC; skipping elevation check.
</span></span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">     </span><span><span style="color: #859900;">return</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">false</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">;
}

</span><span><span style="color: #859900;">int</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">tokenInfLength</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">SizeOf</span></span><span style="color: #586e75;">(</span><span><span style="color: #859900;">typeof</span></span><span style="color: #586e75;">(</span><span><span style="color: #859900;">int</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">));
</span><span><span style="color: #00008b;">IntPtr</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">tokenInformation</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">AllocHGlobal</span></span><span style="color: #586e75;">(</span><span><span style="color: #657b83;">tokenInfLength</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">);

</span><span><span style="color: #859900;">try</span></span>
</strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">{</span><span><span style="color: #859900;">
    var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">token</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">identity</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Token</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">;
</span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span><span style="color: #859900;"><span style="color: #586e75;">    </span>var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">result</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #008b8b;">GetTokenInformation</span></span><span style="color: #586e75;">(</span><span><span style="color: #657b83;">token</span></span><span style="color: #586e75;">, </span><span><span style="color: #00008b;">TokenInformationClass</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">TokenElevationType</span></span><span style="color: #586e75;">, </span><span><span style="color: #657b83;">tokenInformation</span></span><span style="color: #586e75;">, </span><span><span style="color: #657b83;">tokenInfLength</span></span><span style="color: #586e75;">, </span><span><span style="color: #859900;">out</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">tokenInfLength</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">);

    </span><span><span style="color: #859900;">if</span></span><span style="color: #586e75;"> (</span><span><span style="color: #d33682;">!</span></span><span><span style="color: #657b83;">result</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">)
    {
        </span><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">exception</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">GetExceptionForHR</span></span><span style="color: #586e75;">( </span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">GetHRForLastWin32Error</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">() );
        </span><span><span style="color: #859900;">throw</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">new</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">InvalidOperationException</span></span><span style="color: #586e75;">(</span><span><span style="color: #2aa198;">"Couldn't get token information"</span></span><span style="color: #586e75;">, </span><span><span style="color: #657b83;">exception</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">);
    }

    </span><span><span style="color: #859900;">var</span></span><span style="color: #586e75;"> </span><span><span style="color: #657b83;">elevationType</span></span><span style="color: #586e75;"> </span><span><span style="color: #d33682;">=</span></span><span style="color: #586e75;"> (</span><span><span style="color: #00008b;">TokenElevationType</span></span><span style="color: #586e75;">)</span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">ReadInt32</span></span><span style="color: #586e75;">(</span><span><span style="color: #657b83;">tokenInformation</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">);
</span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span><span style="color: #859900;"><span style="color: #586e75;">    </span>
    switch</span></span><span style="color: #586e75;"> (</span><span><span style="color: #657b83;">elevationType</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">)
    {
     </span><span><span style="color: #859900;">   case</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">TokenElevationType</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">TokenElevationTypeDefault</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">:
            </span><span><span style="color: #93a1a1;">// TokenElevationTypeDefault - User is not using a split token, so they cannot elevate.</span></span>
<span style="color: #586e75;">            </span><span><span style="color: #859900;">return</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">false</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">;
        </span><span><span style="color: #859900;">case</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">TokenElevationType</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">TokenElevationTypeFull</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">:
            </span><span><span style="color: #93a1a1;">// TokenElevationTypeFull - User has a split token, and the process is running elevated. Assuming they're an administrator.</span></span>
<span style="color: #586e75;">            </span><span><span style="color: #859900;">return</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">true</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">;
        </span><span><span style="color: #859900;">case</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">TokenElevationType</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">TokenElevationTypeLimited</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">:
            </span><span><span style="color: #93a1a1;">// TokenElevationTypeLimited - User has a split token, but the process is not running elevated. Assuming they're an administrator.</span></span>
<span style="color: #586e75;">            </span><span><span style="color: #859900;">return</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">true</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">;
        </span><span><span style="color: #859900;">default</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">:
            </span><span><span style="color: #93a1a1;">// Unknown token elevation type.</span></span>
<span style="color: #586e75;">            </span><span><span style="color: #859900;">return</span></span><span style="color: #586e75;"> </span><span><span style="color: #859900;">false</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">;
     }
}
</span><span><span style="color: #859900;">finally</span></span>
</strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">{    
</span><span><span style="color: #859900;">    if</span></span><span style="color: #586e75;"> (</span><span><span style="color: #657b83;">tokenInformation</span></span><span style="color: #586e75;"> </span><span><span style="color: #008b8b;">!=</span></span><span style="color: #586e75;"> </span><span><span style="color: #00008b;">IntPtr</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #800080;">Zero</span></span></strong></span><span style="font-family: &amp;amp;quot;"><strong><span style="color: #586e75;">) </span><span><span style="color: #00008b;">Marshal</span></span><span><span style="color: #d33682;">.</span></span><span><span style="color: #008b8b;">FreeHGlobal</span></span><span style="color: #586e75;">(</span><span><span style="color: #657b83;">tokenInformation</span></span></strong><span style="color: #586e75;"><strong>);
}</strong></span></span></pre>
<h3>Visual Basic 6 (VB6)</h3>
<p>For Visual Basic 6, there’s some additional code, as we need to get the token for the current process, and use more calls to also get the operating system version.</p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">Type</span></span></span><span><span style="font-size: 10pt;"> OSVERSIONINFO</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">dwOSVersionInfoSize </span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span><span> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">dwMajorVersion </span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span><span> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">dwMinorVersion </span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">dwBuildNumber </span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">dwPlatformId </span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">szCSDVersion </span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">As</span></span><span> </span><span><span style="color: #00007f;">String</span></span><span> * </span><span><span style="color: #007f7f;">128</span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">End</span></span></span><span style="font-size: 10pt;"><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Type</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt; color: #007f00;">&#8216; dwPlatformId values</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">Public</span></span></span><span style="font-size: 10pt;"><span> </span><span><span style="color: #00007f;">Const</span></span><span> VER_PLATFORM_WIN32s = </span></span><span><span style="font-size: 10pt; color: #007f7f;">0</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">Public</span></span></span><span style="font-size: 10pt;"><span> </span><span><span style="color: #00007f;">Const</span></span><span> VER_PLATFORM_WIN32_WINDOWS = </span></span><span><span style="font-size: 10pt; color: #007f7f;">1</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">Public</span></span></span><span style="font-size: 10pt;"><span> </span><span><span style="color: #00007f;">Const</span></span><span> VER_PLATFORM_WIN32_NT = </span></span><span><span style="font-size: 10pt; color: #007f7f;">2</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span> </span></span></p>
<p><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">Public</span></span></span><span style="font-size: 10pt;"><span> </span><span><span style="color: #00007f;">Declare</span></span><span> </span><span><span style="color: #00007f;">Function</span></span><span> GetVersionEx </span><span><span style="color: #00007f;">Lib</span></span><span> </span><span><span style="color: #7f007f;">&#8220;kernel32&#8243;</span></span><span> </span><span><span style="color: #00007f;">Alias</span></span><span> </span><span><span style="color: #7f007f;">&#8220;GetVersionExA&#8221;</span></span><span> (</span><span><span style="color: #00007f;">ByRef</span></span><span> lpVersionInformation </span><span><span style="color: #00007f;">As</span></span><span> OSVERSIONINFO) </span><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt; color: #007f00;">&#8216; These functions are for getting the process token information, which IsUserAnAdministrator uses to</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt; color: #007f00;">&#8216; handle detecting an administrator that&#8217;s running in a non-elevated process under UAC.</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">Private</span></span></span><span style="font-size: 10pt;"><span> </span><span><span style="color: #00007f;">Const</span></span><span> TOKEN_READ </span><span><span style="color: #00007f;">As</span></span><span> </span><span><span style="color: #00007f;">Long</span></span><span> = </span></span><span><span style="font-size: 10pt; color: #007f7f;">&amp;H20008</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">Private</span></span></span><span style="font-size: 10pt;"><span> </span><span><span style="color: #00007f;">Const</span></span><span> TOKEN_ELEVATION_TYPE </span><span><span style="color: #00007f;">As</span></span><span> </span><span><span style="color: #00007f;">Long</span></span><span> = </span></span><span><span style="font-size: 10pt; color: #007f7f;">18</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span style="line-height: 12pt;"><span style="color: #00007f;"><span style="font-size: 10pt;">Private</span></span></span><span style="font-size: 10pt;"><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Declare</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Function</span></span><span style="line-height: 12pt;"> IsUserAnAdmin </span><span style="line-height: 12pt;"><span style="color: #00007f;">Lib</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #7f007f;">&#8220;Shell32&#8243;</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Alias</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #7f007f;">&#8220;#680&#8243;</span></span><span style="line-height: 12pt;"> () </span><span style="line-height: 12pt;"><span style="color: #00007f;">As</span></span><span style="line-height: 12pt;"> </span></span><span style="line-height: 12pt;"><span style="font-size: 10pt; color: #00007f;">Integer</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">Private</span></span></span><span style="font-size: 10pt;"><span> </span><span><span style="color: #00007f;">Declare</span></span><span> </span><span><span style="color: #00007f;">Function</span></span><span> CloseHandle </span><span><span style="color: #00007f;">Lib</span></span><span> </span><span><span style="color: #7f007f;">&#8220;kernel32&#8243;</span></span><span> (</span><span><span style="color: #00007f;">ByVal</span></span><span> hObject </span><span><span style="color: #00007f;">As</span></span><span> </span><span><span style="color: #00007f;">Long</span></span><span>) </span><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">Private</span></span></span><span style="font-size: 10pt;"><span> </span><span><span style="color: #00007f;">Declare</span></span><span> </span><span><span style="color: #00007f;">Function</span></span><span> OpenProcessToken </span><span><span style="color: #00007f;">Lib</span></span><span> </span><span><span style="color: #7f007f;">&#8220;advapi32.dll&#8221;</span></span><span> (</span><span><span style="color: #00007f;">ByVal</span></span><span> ProcessHandle </span><span><span style="color: #00007f;">As</span></span><span> </span><span><span style="color: #00007f;">Long</span></span><span>, </span><span><span style="color: #00007f;">ByVal</span></span><span> DesiredAccess </span><span><span style="color: #00007f;">As</span></span><span> </span><span><span style="color: #00007f;">Long</span></span><span>, TokenHandle </span><span><span style="color: #00007f;">As</span></span><span> </span><span><span style="color: #00007f;">Long</span></span><span>) </span><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: 13pt; margin: 0cm 0cm 10pt;"><span style="font-family: &amp;amp;quot;"><span style="line-height: 12pt;"><span style="color: #00007f;"><span style="font-size: 10pt;">Private</span></span></span><span style="font-size: 10pt;"><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Declare</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Function</span></span><span style="line-height: 12pt;"> GetTokenInformation </span><span style="line-height: 12pt;"><span style="color: #00007f;">Lib</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #7f007f;">&#8220;advapi32.dll&#8221;</span></span><span style="line-height: 12pt;"> (</span><span style="line-height: 12pt;"><span style="color: #00007f;">ByVal</span></span><span style="line-height: 12pt;"> TokenHandle </span><span style="line-height: 12pt;"><span style="color: #00007f;">As</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Long</span></span><span style="line-height: 12pt;">, </span><span style="line-height: 12pt;"><span style="color: #00007f;">ByVal</span></span><span style="line-height: 12pt;"> TokenInformationClass </span><span style="line-height: 12pt;"><span style="color: #00007f;">As</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Long</span></span><span style="line-height: 12pt;">, TokenInformation </span><span style="line-height: 12pt;"><span style="color: #00007f;">As</span></span><span style="line-height: 12pt;"> Any,_<span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"><span style="line-height: 12pt;"><span style="color: #00007f;"> ByVal</span></span><span style="line-height: 12pt;"> TokenInformationLength </span><span style="line-height: 12pt;"><span style="color: #00007f;">As</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Long</span></span><span style="line-height: 12pt;">, ReturnLength </span><span style="line-height: 12pt;"><span style="color: #00007f;">As</span></span><span style="line-height: 12pt;"> </span><span style="line-height: 12pt;"><span style="color: #00007f;">Long</span></span><span style="line-height: 12pt;">) </span><span style="line-height: 12pt;"><span style="color: #00007f;">As</span></span><span style="line-height: 12pt;"> </span></span><span style="line-height: 12pt;"><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="color: #00007f;"><span style="font-size: 10pt;">Public</span></span></span><span style="font-size: 10pt;"><span> </span><span><span style="color: #00007f;">Function</span></span><span> IsUserAnAdministrator() </span><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Boolean</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">On</span></span><span> </span><span><span style="color: #00007f;">Error</span></span><span> </span><span><span style="color: #00007f;">GoTo</span></span></span><span><span style="font-size: 10pt;"> IsUserAnAdministratorError</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">IsUserAnAdministrator = </span></span><span><span style="font-size: 10pt; color: #00007f;">False</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">If</span></span><span> IsUserAnAdmin() </span></span><span><span style="font-size: 10pt; color: #00007f;">Then</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">IsUserAnAdministrator = </span></span><span><span style="font-size: 10pt; color: #00007f;">True</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Exit</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Function</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">End</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">If</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span><span style="font-size: 10pt; color: #007f00;">&#8216; If we&#8217;re on Vista onwards, check for UAC elevation token</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span><span style="font-size: 10pt; color: #007f00;">&#8216; as we may be an admin but we&#8217;re not elevated yet, so the</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span><span style="font-size: 10pt; color: #007f00;">&#8216; IsUserAnAdmin() function will return false</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Dim</span></span><span> osVersion </span><span><span style="color: #00007f;">As</span></span></span><span><span style="font-size: 10pt;"> OSVERSIONINFO</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">osVersion.dwOSVersionInfoSize = </span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Len</span></span></span><span><span style="font-size: 10pt;">(osVersion)</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">If</span></span><span> GetVersionEx(osVersion) = </span><span><span style="color: #007f7f;">0</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Then</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Exit</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Function</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">End</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">If</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">If</span></span><span> osVersion.dwPlatformId &lt;&gt; VER_PLATFORM_WIN32_NT </span><span><span style="color: #00007f;">Or</span></span><span> osVersion.dwMajorVersion &lt; </span><span><span style="color: #007f7f;">6</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Then</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span><span style="font-size: 10pt; color: #007f00;">&#8216; If the user is not on Vista or greater, then there&#8217;s no UAC, so don&#8217;t bother checking.</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Exit</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Function</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">End</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">If</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Dim</span></span><span> result </span><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Dim</span></span><span> hProcessID<span style="mso-spacerun: yes;"> </span></span><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Dim</span></span><span> hToken<span style="mso-spacerun: yes;"> </span></span><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Dim</span></span><span> lReturnLength<span style="mso-spacerun: yes;"> </span></span><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Dim</span></span><span> tokenElevationType </span><span><span style="color: #00007f;">As</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Long</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span><span style="font-size: 10pt; color: #007f00;">&#8216; We need to get the token for the current process</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">hProcessID = GetCurrentProcess()</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">If</span></span><span> hProcessID &lt;&gt; </span><span><span style="color: #007f7f;">0</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Then</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">If</span></span><span> OpenProcessToken(hProcessID, TOKEN_READ, hToken) = </span><span><span style="color: #007f7f;">1</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Then</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">result = GetTokenInformation(hToken, TOKEN_ELEVATION_TYPE, tokenElevationType, </span></span><span style="font-size: 10pt;"><span><span style="color: #007f7f;">4</span></span></span><span><span style="font-size: 10pt;">, lReturnLength)</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">If</span></span><span> result = </span><span><span style="color: #007f7f;">0</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Then</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span><span style="font-size: 10pt; color: #007f00;">&#8216; Couldn&#8217;t get token information</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Exit</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Function</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">End</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">If</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">If</span></span><span> tokenElevationType &lt;&gt; </span><span><span style="color: #007f7f;">1</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Then</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">IsUserAnAdministrator = </span></span><span><span style="font-size: 10pt; color: #00007f;">True</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">End</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">If</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">CloseHandle hToken</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">End</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">If</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span><span style="font-size: 10pt;">CloseHandle hProcessID</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">End</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">If</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"><span style="font-size: 10pt;"> </span></span></span><span style="font-size: 10pt;"><span><span style="color: #00007f;">Exit</span></span><span> </span></span><span><span style="font-size: 10pt; color: #00007f;">Function</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="mso-spacerun: yes;"><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;"> </span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span><span style="font-family: &amp;amp;quot;"><span style="font-size: 10pt;">IsUserAnAdministratorError:</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;amp;quot;"><span><span style="mso-spacerun: yes;"> </span></span><span><span style="font-size: 10pt; color: #007f00;"> &#8216; Handle errors</span></span></span></p>
<p class="MsoNormal" style="line-height: 13pt; margin: 0cm 0cm 10pt;"><span style="font-family: &amp;amp;quot;"><span style="line-height: 12pt;"><span style="color: #00007f;"><span style="font-size: 10pt;">End</span></span></span><span style="font-size: 10pt;"><span style="line-height: 12pt;"> </span></span><span style="line-height: 12pt;"><span style="font-size: 10pt; color: #00007f;">Function</span></span></span></p>
<h2>References</h2>
<p><a href="http://blogs.msdn.com/b/cjacks/archive/2006/10/09/how-to-determine-if-a-user-is-a-member-of-the-administrators-group-with-uac-enabled-on-windows-vista.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/blogs.msdn.com');">Blog Post by Chris Jackson: How to Determine if a User is a Member of the Administrators Group with UAC Enabled on Windows Vista</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2011/06/20/how-to-check-if-the-current-user-is-an-administrator-even-if-uac-is-on/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Error building project when referencing native assembly dependency in app.manifest</title>
		<link>http://www.davidmoore.info/2011/01/14/error-building-project-when-referencing-native-assembly-dependency-in-app-manifest/</link>
		<comments>http://www.davidmoore.info/2011/01/14/error-building-project-when-referencing-native-assembly-dependency-in-app-manifest/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 20:45:38 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[manifest]]></category>
		<category><![CDATA[sxs]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/?p=404</guid>
		<description><![CDATA[<p>If you&#8217;re using an app.manifest, and defining assembly dependencies (i.e. for SxS / Side by side / Reg-free COM etc), you may encounter this error when you build the project:</p>
<p style="padding-left: 30px;">Could not find file &#8216;AssemblyName, Version=x.x.x.x, PublicKeyToken=xxxxxxxxxxx, ProcessorArchitecture=x86, Type=win32&#8242;.</p>
<p>This is even when the native assembly is in place where the project can find it.</p>
Example
<p>For example, <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2011/01/14/error-building-project-when-referencing-native-assembly-dependency-in-app-manifest/">Error building project when referencing native assembly dependency in app.manifest</a></span>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using an app.manifest, and defining assembly dependencies (i.e. for SxS / Side by side / Reg-free COM etc), you may encounter this error when you build the project:</p>
<p style="padding-left: 30px;"><span style="color: #ff0000;">Could not find file &#8216;AssemblyName, Version=x.x.x.x, PublicKeyToken=xxxxxxxxxxx, ProcessorArchitecture=x86, Type=win32&#8242;.</span></p>
<p>This is even when the native assembly is in place where the project can find it.</p>
<h2>Example</h2>
<p>For example, your<strong> app.manifest</strong> may contain this fragment:</p>
<p class="MsoNormal" style="tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; color: blue; mso-fareast-language: EN-NZ;">&lt;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; color: #a31515; mso-fareast-language: EN-NZ;">dependency</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; color: blue; mso-fareast-language: EN-NZ;">&gt;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-NZ;"><br />
<span style="color: blue;"> &lt;</span><span style="color: #a31515;">dependentAssembly</span><span style="color: blue;">&gt;</span><br />
<span style="color: blue;"> &lt;</span><span style="color: #a31515;">assemblyIdentity</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">Native.Custom</span>&#8220;<span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">1.0.0.0</span>&#8220;<span style="color: blue;"> </span><span style="color: red;">processorArchitecture</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">x86</span>&#8220;<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">win32</span>&#8220;<span style="color: blue;"> </span><span style="color: red;">publicKeyToken</span><span style="color: blue;">=</span>&#8220;<span style="color: blue;">12345678</span>&#8220;<span style="color: blue;">/&gt;</span><br />
<span style="color: blue;"> &lt;/</span><span style="color: #a31515;">dependentAssembly</span><span style="color: blue;">&gt;</span><br />
<span style="color: blue;"> &lt;/</span><span style="color: #a31515;">dependency</span><span style="color: blue;">&gt;</span></span></p>
<p>This manifest is available to the project, with the manifest file in the project directory or in a subdirectory called &#8220;Native.Custom&#8221;.</p>
<p>In this case, I have a sub directory called Native.Custom, which contains my Native.Custom.manifest file.</p>
<h2>Solution</h2>
<p>The problem may be because the ClickOnce manifests are being generated.</p>
<ol>
<li>Open your project file in a text editor (or right click it in Visual Studio and choose <strong>Edit Project</strong>)</li>
<li> Find the  <strong>GenerateManifests</strong> element and set it to false:</li>
<li> <span style="color: blue;">&lt;</span><span style="color: #a31515;">GenerateManifests</span><span style="color: blue;">&gt;</span>false<span style="color: blue;">&lt;/</span><span style="color: #a31515;">GenerateManifests</span><span style="color: blue;">&gt;</span></li>
<li> Save the project and reload it.</li>
</ol>
<p>Now you should hopefully be able to build.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2011/01/14/error-building-project-when-referencing-native-assembly-dependency-in-app-manifest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running .NET 2 Runtime applications under the .NET 4 Runtime</title>
		<link>http://www.davidmoore.info/2010/12/17/running-net-2-runtime-applications-under-the-net-4-runtime/</link>
		<comments>http://www.davidmoore.info/2010/12/17/running-net-2-runtime-applications-under-the-net-4-runtime/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 21:38:31 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[NetFx40_LegacySecurityPolicy]]></category>
		<category><![CDATA[startup]]></category>
		<category><![CDATA[supportRuntime]]></category>
		<category><![CDATA[useLegacyV2RuntimeActivationPolicy]]></category>

		<guid isPermaLink="false">http://www.davidmoore.info/?p=381</guid>
		<description><![CDATA[<p>In some situations, you might want to run a .NET 2 Runtime application (.NET 2, 3.0, 3.5 SP1 etc) under the .NET 4 Runtime &#8211; without recompiling.</p>
<p>You can configure your app to execute under the .NET 4 runtime by adding these lines to the executable&#8217;s configuration file, under the root  configuration element:</p>
&#60;startup&#62;
  &#60;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/&#62;
&#60;/startup&#62;
<p>Because the security <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.davidmoore.info/2010/12/17/running-net-2-runtime-applications-under-the-net-4-runtime/">Running .NET 2 Runtime applications under the .NET 4 Runtime</a></span>]]></description>
			<content:encoded><![CDATA[<p>In some situations, you might want to run a .NET 2 Runtime application (.NET 2, 3.0, 3.5 SP1 etc) under the .NET 4 Runtime &#8211; without recompiling.</p>
<p>You can configure your app to execute under the .NET 4 runtime by adding these lines to the executable&#8217;s configuration file, under the root  <strong>configuration</strong> element:</p>
<pre><span style="color: blue;">&lt;</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">  &lt;</span><span style="color: #a31515;">supportedRuntime</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">v4.0</span>"<span style="color: blue;"> </span><span style="color: red;">sku</span><span style="color: blue;">=</span>"<span style="color: blue;">.NETFramework,Version=v4.0</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span></pre>
<p>Because the security framework has changed in the .NET 4 runtime, you will likely encounter some exceptions containing a message similar to:</p>
<blockquote><p>System.NotSupportedException: This method explicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility reasons, please use the NetFx40_LegacySecurityPolicy configuration switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information.</p></blockquote>
<p>To avoid this, you  have to enable the legacy support by adding a runtime element :</p>
<pre><span style="color: blue;">&lt;</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">  &lt;</span><span style="color: #a31515;">supportedRuntime</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">v4.0</span>"<span style="color: blue;"> </span><span style="color: red;">sku</span><span style="color: blue;">=</span>"<span style="color: blue;">.NETFramework,Version=v4.0</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span>
<strong><span style="color: blue;">&lt;</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">  &lt;</span><span style="color: #a31515;">NetFx40_LegacySecurityPolicy</span><span style="color: blue;"> </span><span style="color: red;">enabled</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;</span></strong></pre>
<p>If your application also uses mixed assemblies that contain both managed and native code (such as System.Data.SQLite.dll), you&#8217;ll see an error message like this:</p>
<blockquote><p>Mixed mode assembly is built against version &#8216;v2.0.50727&#8242; of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.</p></blockquote>
<p>You will need to enable the legacy activation to allow these to be loaded also:</p>
<pre><span style="color: blue;">&lt;</span><span style="color: #a31515;">startup</span><span style="color: blue;"> </span><strong><span style="color: red;">useLegacyV2RuntimeActivationPolicy</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"</strong><span style="color: blue;">&gt;</span>
<span style="color: blue;">  &lt;</span><span style="color: #a31515;">supportedRuntime</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">v4.0</span>"<span style="color: blue;"> </span><span style="color: red;">sku</span><span style="color: blue;">=</span>"<span style="color: blue;">.NETFramework,Version=v4.0</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">&lt;</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">  &lt;</span><span style="color: #a31515;">NetFx40_LegacySecurityPolicy</span><span style="color: blue;"> </span><span style="color: red;">enabled</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;

</span></pre>
<h3>References</h3>
<p><a href="http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">&lt;startup&gt; Element @ MSDN</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/w4atty68.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">&lt;supportedRuntime&gt; Element @ MSDN</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/dd409253.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">&lt;NetFx40_LegacySecurityPolicy&gt; Element @ MSDN</a></p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">
<pre style="font-family: consolas;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">startup</span><span style="color: blue;"> </span><span style="color: red;">useLegacyV2RuntimeActivationPolicy</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">        &lt;</span><span style="color: #a31515;">supportedRuntime</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">v4.0</span>"<span style="color: blue;"> </span><span style="color: red;">sku</span><span style="color: blue;">=</span>"<span style="color: blue;">.NETFramework,Version=v4.0</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">    &lt;/</span><span style="color: #a31515;">startup</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">    &lt;</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">        &lt;</span><span style="color: #a31515;">NetFx40_LegacySecurityPolicy</span><span style="color: blue;"> </span><span style="color: red;">enabled</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">    &lt;/</span><span style="color: #a31515;">runtime</span><span style="color: blue;">&gt;</span></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.davidmoore.info/2010/12/17/running-net-2-runtime-applications-under-the-net-4-runtime/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

