WindowsIdentity.RunImpersonated not working?

1k views Asked by At

I have a website where I click a button and a process its supposed to start. The problem is that I have to start that new process with other user and its starting with the user currently running the site in IIS.

Even when I Log inside the RunImpersonated the current user, the log its correct with the user that I want but than in the task manager the username running the process that I start its the website one. I don't want to wait for the process to complete, just start the thing and go on with my life. Can anyone help me please? A little bit lost, don t know what to test anymore.

Thanks in advance

Here is the code:

UserCredentials credentials = new UserCredentials(specificTool.Username, specificTool.PlainPassword);
using (SafeAccessTokenHandle userHandle = credentials.LogonUser(LogonType.Batch))
{
    WindowsIdentity.RunImpersonated(userHandle, () =>
    {
        var teste = WindowsIdentity.GetCurrent().Name;
        LoggerStatic.Info(teste);
        var proc = new Process
        {
            StartInfo = new ProcessStartInfo
            {
                FileName = cmdToUse,
                Arguments = argsToUse,
                WindowStyle = ProcessWindowStyle.Hidden,
                WorkingDirectory = toolPath,
                UseShellExecute = false
            }
        };

        proc.Start();
    });
};
return true;
0

There are 0 answers