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.SecureString spsw = new System.Security.SecureString();
            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.WorkingDirectory = @ConfigurationSettings.AppSettings["printexe_directory"];
            startPrint.FileName = @ConfigurationSettings.AppSettings["printexe_name"];
            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\PrintInterOp\Debug\Debug\WindowsApplication2.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.
ANAT2403Asked:
Who is Participating?
 
YZlatConnect With a Mentor Commented:
0
 
YZlatCommented:
use LogonUser API function

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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.