<?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>things &#38; stuff &#187; .Net</title>
	<atom:link href="http://www.curlybrace.com/words/category/technology/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.curlybrace.com/words</link>
	<description>Pictures.  Now with more words!</description>
	<lastBuildDate>Mon, 05 Jul 2010 21:47:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Run External Application as Another User in C#</title>
		<link>http://www.curlybrace.com/words/2009/06/04/run-external-application-as-another-user-in-c/</link>
		<comments>http://www.curlybrace.com/words/2009/06/04/run-external-application-as-another-user-in-c/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 22:33:09 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=737</guid>
		<description><![CDATA[An arbitrary external application can be executed from C# using System.Diagnostics.Process. If you want to run as another user, setting the System.Diagnostics.Process.StartInfo.Password field can be a bit confusing. Here is one way using System.Security.SecureString.AppendChar to avoid having to resort to unsafe code: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSRunAs { class Program [...]]]></description>
			<content:encoded><![CDATA[<p>An arbitrary external application can be executed from C# using <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx">System.Diagnostics.Process</a>.  If you want to run as another user, setting the System.Diagnostics.Process.StartInfo.Password field can be a bit confusing.  Here is one way using <a href="http://msdn.microsoft.com/en-us/library/system.security.securestring.appendchar(VS.85).aspx">System.Security.SecureString.AppendChar</a> to avoid having to resort to unsafe code:</p>
<pre>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSRunAs
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();

            // Domain and User Name:
            p.StartInfo.Domain = "optional_domain";
            p.StartInfo.UserName = "user_to_run_as";

            // Command to execute and arguments:
            p.StartInfo.FileName = "c:\\path\\to\\executable.exe";
            p.StartInfo.Arguments = "your argument string";

            // Build the SecureString password...
            System.String rawPassword = "your_password";
            System.Security.SecureString encPassword = new System.Security.SecureString();
            foreach (System.Char c in rawPassword)
            {
                encPassword.AppendChar(c);
            }

            p.StartInfo.Password = encPassword;

            // The UseShellExecute flag must be turned off in order to supply a password:
            p.StartInfo.UseShellExecute = false;

            p.Start();
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2009/06/04/run-external-application-as-another-user-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
