I have an ASP .NET web application on a 64-bit machine that needs to run a legacy 32-bit reporting application.
When I run the program with UseShellExecute = false
, the program exits with exit code:
-1073741502
I can't use Shell Execute because I have to run the process as a different user. Yet, when Shell Execute is true, the process will run fine (although I have to change the user that ASP .NET is executing under).
How can I start this 32-bit program using C# without use shell execute?
Here's the code I have right now:
var pxs = new ProcessStartInfo
{
Arguments = arguments,
CreateNoWindow = true,
Domain = ConfigurationManager.AppSettings["reportUserDomain"],
UserName = ConfigurationManager.AppSettings["reportUserName"],
Password = GetSecureString(ConfigurationManager.AppSettings["reportUserPassword"]),
LoadUserProfile = true,
FileName = ConfigurationManager.AppSettings["reportRuntime"],
UseShellExecute = false
};
var px = new Process
{
StartInfo = pxs
};
px.Start();
px.WaitForExit();
What if you surrounded your code, including
UseShellExecute = true
, with the windows native "LogonUser" method? I've used this successfully in a few projects to do something similar.Fresh Click Media did an article about this and wrote a sample Impersonate class: --> http://www.freshclickmedia.com/blog/2008/11/programmatic-impersonation-in-c/
But for completeness, here's my version of it:
Using it in your case would be: