ANAT2403
asked on
Running a Dot Net Exe via System.Diagnostics.Process.Start
I need to start an exe that i wrote in C# from a WebSerivce which i also wrote.
The exe wraps a vb dll and needs read/write premissions so i am starting the exe with the following code.
////CODE in WEBSERVICE
ProcessStartInfo startPrint = new ProcessStartInfo();
System.Security.SecureStri ng spsw = new System.Security.SecureStri ng();
spsw.AppendChar('m');
spsw.AppendChar('y');
spsw.AppendChar('p');
spsw.AppendChar('s');
spsw.AppendChar('w');
startPrint.UserName = "myuser";
startPrint.Password = spsw;
startPrint.Domain = "mydomain";
//Get the exe folder and full path
startPrint.WorkingDirector y = @ConfigurationSettings.App Settings[" printexe_d irectory"] ;
startPrint.FileName = @ConfigurationSettings.App Settings[" printexe_n ame"];
startPrint.Arguments = string.Format("{0} {1}", FleetName, PackagePrintID.ToString()) ;
startPrint.CreateNoWindow = true;
startPrint.WindowStyle = ProcessWindowStyle.Hidden;
startPrint.UseShellExecute = false;
Process.Start(startPrint);
/////END IF CODE
if I set the UseShellExecute = false i get the following error (seen in the EventLogs)
The application, D:\WEB\idmr\NR\PrintInterO p\Debug\De bug\Window sApplicati on2.exe, generated an application error The error occurred on 05/16/2006 @ 10:14:18.740 The exception generated was c06d007e at address 77E55DEA (KERNEL32!RaiseException)
If I set the UseShellExecute = true then i can not set the user that i need the exe to run as and then the exe runs but it fails to create the files it needs.
how can i run a exe under a specific user account from within my webservice?
please help.
The exe wraps a vb dll and needs read/write premissions so i am starting the exe with the following code.
////CODE in WEBSERVICE
ProcessStartInfo startPrint = new ProcessStartInfo();
System.Security.SecureStri
spsw.AppendChar('m');
spsw.AppendChar('y');
spsw.AppendChar('p');
spsw.AppendChar('s');
spsw.AppendChar('w');
startPrint.UserName = "myuser";
startPrint.Password = spsw;
startPrint.Domain = "mydomain";
//Get the exe folder and full path
startPrint.WorkingDirector
startPrint.FileName = @ConfigurationSettings.App
startPrint.Arguments = string.Format("{0} {1}", FleetName, PackagePrintID.ToString())
startPrint.CreateNoWindow = true;
startPrint.WindowStyle = ProcessWindowStyle.Hidden;
startPrint.UseShellExecute
Process.Start(startPrint);
/////END IF CODE
if I set the UseShellExecute = false i get the following error (seen in the EventLogs)
The application, D:\WEB\idmr\NR\PrintInterO
If I set the UseShellExecute = true then i can not set the user that i need the exe to run as and then the exe runs but it fails to create the files it needs.
how can i run a exe under a specific user account from within my webservice?
please help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As [String], _
ByVal lpszDomain As [String], ByVal lpszPassword As [String], _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, _
ByRef phToken As IntPtr) As Boolean