cmd.exe should run in impersonate account.

A

Arulraj Joseph

Hi All,

I am starting a new process from asp.net(cmd.exe). See the following
code,

System.Security.Principal.WindowsImpersonationContext
impersonationContext =
((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

ProcessStartInfo oProcessStartInfo = new ProcessStartInfo();
oProcessStartInfo.FileName = "c:\getUser.exe > c:\a.out";
oProcessStartInfo.Arguments = szCommand;
oProcessStartInfo.RedirectStandardOutput = true;
oProcessStartInfo.CreateNoWindow = false;
oProcessStartInfo.UseShellExecute = false;
Process oProcess = new Process();
oProcess.StartInfo = oProcessStartInfo;
oProcess.Start();
oProcess.WaitForExit();

impersonationContext.Undo();

When the process starts, it is running in the aspnet account and not
the impersonate account. How will I run in the impersonate
account(similar
to launching user concept to dcomcnfg.exe).

Note : getuser.exe will output a user name to c:\a.out the code for
getuser.exe is

using System;

namespace getuser
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
}
}
}

Help appreciated.

Thanks,
Arulraj Joseph.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top