Sandip's Programming Zen

An attempt to share tech/coding experiences

Resolved: “Access denied” error on System.Diagnostics.Process.Start

with 3 comments

Wrote a piece of code which would launch an application exe using Process.Start, on development machine it worked without a problem but when deployed on client machine it started giving “Access Denied” error.

It turned out that when the code runs in domain controlled user environement Process.Start needs a set of security credentials by default to run. Now, in practical scenario we can not just hard code any credentials or even prompt for input.

The solution, there is an attribute called UseShellExecute which needs to be set False , this will allow the exe to be launched without credentials.

Sample code goes like this :

System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = _path;
p.StartInfo.Arguments = string.Format(“\”{0}\” \”{1}\””, arg1, arg2);
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();

					
Advertisements

Written by Sandip

August 6, 2011 at 5:03 pm

Posted in .Net, Programming, Softwares

3 Responses

Subscribe to comments with RSS.

  1. I am running into a similar problem at a customer site but only when I try to start MS Office (2007) apps (Word, Excel). I have set UseShellExecute to false. Do you have any other ideas why this may be happening? Thanks.

    Scott Myers

    November 19, 2011 at 9:10 pm

    • First you need to determine whether it’s the security issue or something else. Try to run it by passing credentials first the machine, if that works then it’s certainly security issue as described in blog.
      You can also post your section of code so that I can see the context.

      Sandip

      November 21, 2011 at 11:57 am

  2. Thank you for your help. In working with the customer to gather diagnostics about this problem, he discovered that the path name to the Excel executable that he had provided my software was flawed. It had something to do with the fact that he was running Win 7 in a virtual partition and the C: drive had been assigned an alternate drive letter.

    As soon as he set the shortcut up in my software to match the shortcut he had for starting Excel from his desktop, it started working. I think that was an odd exception for the Process object to throw but now I know.

    Scott Myers

    November 23, 2011 at 3:47 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: