Process.Start and Impersonation

I need send 5 param to .exe application…and receive a value…

How i do this…help

Concerning the “Handle is Invalid” message that Rich and Julie mentioned, try this before starting the process:
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;

And to Marco, set p.StartInfo.Arguments to your list of arguments, separated by spaces (perhaps using String.Join).

I keep getting an invalid handle on childHandle = CreateFile(pipename, num1, 3, attributes3, 3, 0x40000080, NullHandleRef);
inside MyCreatePipe() any suggestions. The above suggestion does not change any input parameters. . . hmmm. thanks

see http://wiki.ittoolbox.com/index.php/HOWTO:Fix_%22Binding_handle_is_invalid%22_error_in_Visual_2005

You make it sound like this is a bad thing, to have an asp.net or web service run as the user who logged in. That would present security problems. Say I was a malicious programmer. If I detect that an admin or manager has logged into my system, If the asp.net process could used those credentials, I have free reign to access resources that I plainly should not be accessing.

Credentials are burned once logging into an asp.net page or web service for security reasons. If your application needs to access specific resources, either have internal credentials that have access rights to the specific services/resources you want, or give the local asp.net account access rights and roles.

@tiedyemark on December 22, 2005 06:07 PM:

InvokeMember on SetProcessHandle fails:
Method ‘System.Diagnostics.Process.SetProcessHandle’ not found.

How should the process handle be set?

hi all
I wish to use the win32 api CreateProcessWithLogonW function
in a c++ program, to lunch a remote desktop connection programatically. and send the password programatically without
the password popup window.

I am the client (in windows 2000 professional) remote desktop. using the ocx version of rdp client.

all samples force the developer to use vc.net , I wish not to use the .net or asp or any other compiler except vc6.0 (without this anoing .net package). I know this function is part of .net. but I wish to use it transparently by loading the api function from the dll in c++ program.

can it be done???

pleas reply to
kovacsio@hotmail.com

a

Hey, first of all, its a good thread.

I want to start an executable (which can’t be treated as a service-like application) from within my ASP.Net code, meaning it needs to open a window somehow. (I’ve tried to install the exe as a service, but that would result in the same). If I run my Webpage with a local server (e.g. visual) it works fine, probably because there is a profile active where to open the window in. If I run it with IIS it does not, allthough I am running the appl. under a different user.

Anyway, all I see is the exe under the right unser in my taskmanager, but the exe doesnt do anything. (emule…in case that helps)

Here is my code:

    Process p_exec_EMULE = new Process();

    string user = Membership.GetUser().UserName;
    string pass = ...;
    string dir = @...;

    p_exec_EMULE.StartInfo.FileName = dir + emule.exe;
    p_exec_EMULE.StartInfo.UseShellExecute = false;
    p_exec_EMULE.StartInfo.WorkingDirectory = dir;
    p_exec_EMULE.StartInfo.LoadUserProfile = true;
    p_exec_EMULE.StartInfo.UserName = user;
    p_exec_EMULE.StartInfo.Password = setSecureString(pass);
    if (!isRunning(user, emule.exe){
        p_exec_EMULE.Start();

As I said, works fine if the webserver runs within a logged on account…but not with IIS…even if User is logged on…

any ideas?

Realy amazing…

This below problem gives head ache for last 4 days. If you can could you please help.

Background:

      I have a web service which accept requests from different regions for task. Based on regions  ID, the web service submits a request to impersonate the regional service account inside a COM+ object then executes the task. This is what my requirement is. The COM object always runs under US regional service account. 

      if process is executed by the same user who executes the COM+, all works fine..even process gets started and file is getting executed..etc

If the executer is different from the COM+ users, the process is getting terminated prematurely. If I give the wrong user name or password or workingdirectory or file name exception is thrown out… but the moment i set all values right… nothing … none… no exception error… any idea? I checked user permissions… i even added user into administrative group and provided impersonate a client after authentication rights and allow log on locally on secpol… this code is residing inside a COM+ object and COM+ object is running under another administrative account. I am trying to execute an .exe file

I notice the process being started on process monitor but nothing happens after the process starts… the command is being closed in seconds.

try
{
SecureString passSecure = new SecureString();
char[] passwordChars = password.ToCharArray();
foreach (char c in passwordChars)
{
passSecure.AppendChar©;
}
process = new Process();
process.StartInfo.WorkingDirectory = brkWorkingDir.ToString();
process.StartInfo.FileName = brkFileName.ToString();
process.StartInfo.Arguments = argument.ToString();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UserName = userName;
process.StartInfo.Password = passSecure;
process.StartInfo.Domain = domain;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.StartInfo.LoadUserProfile = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.Start();
resultString = process.StandardError.ReadToEnd();
resultString = resultString + process.StandardOutput.ReadToEnd();
resultString = resultString.Replace(’, );
}
catch (Win32Exception e2)
{
resultString = loop CMP BB user - Work Order - Exceptional Error: +e2.Message+ +e2.StackTrace+ Native error code is: +e2.NativeErrorCode;
}
finally
{
if (null!=process)
{
process.Dispose();
}
}

Yeaa that is a real pain, I also observed the same as Durairaj:

…after setting all values right… nothing … none… no exception error… any idea?..

I wonder why no exception is thrown?

So there is no solution for ASP.net impersonate???