Running a Dot Net Exe via System.Diagnostics.Process.Start

Posted on 2006-05-16
Last Modified: 2012-05-05
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.

            ProcessStartInfo startPrint = new ProcessStartInfo();

            System.Security.SecureString spsw = new System.Security.SecureString();

            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;
/////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.
Question by:ANAT2403
    LVL 35

    Expert Comment

    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
    LVL 35

    Accepted Solution


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now