[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-05-16
5
Medium Priority
?
695 Views
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.

////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.
0
Comment
Question by:ANAT2403
  • 2
2 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 16691267
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
 
LVL 35

Accepted Solution

by:
YZlat earned 1000 total points
ID: 16691304
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

868 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