Sunday, December 16, 2018

TIP: C# Process.Start(...); causes "directory name is invalid"

by / Thursday, 16 September 2010 / Published in Blog

Recently I was doing some coding in C#, which featured launching processes as another user. I've set all the necessary parameters in ProcessStartInfo object that I passed as an argument to Process.Start(... method. However, it was constantly causing an error - 'The directory name is invalid'.

ProcessStartInfo ps = new ProcessStartInfo(@"X:\anotherapp.exe");
ps.UserName = username;
ps.Password = passwordSecureString;
ps.UseShellExecute = false;
Process p = System.Diagnostics.Process.Start(ps);

Some time later I've found a solution. It was really simple - it's necessary to specify working directory for the process, so the code in C# must look like this:

ProcessStartInfo ps = new ProcessStartInfo(@"X:\anotherapp.exe");
ps.UserName = username;
ps.Password = passwordSecureString;
ps.UseShellExecute = false;
ps.WorkingDirectory = userdir;
Process p = System.Diagnostics.Process.Start(ps);

Hope this small note will help anybody expericencing the same problem ;)

Read 1976 times

Do you like this? Please share!

Simon Tushev

Simon is IT professional with interests in web design, electronics, photography and astronomy. He writes about PHP, Yii, Joomla!, Arduino and several other topics.

Welcome!

Here I publish articles related to my areas of interest, my brief notes that may save some time to others, as well as some of my works.

This site is a work in progress. I will add more sections in the future, such as

  • More photos to photogallery
  • More Joomla!-related articles
  • ...

 

themeforest

New Posts

Using dynamic GeoIP module with nginx (CentOS)

nginx introduced dynamic module support in v. 1.9.11. This brief article provides step-by-step procedure...

13-04-2016 in Linux, BSD, Unix

READ MORE

Visual difference between pseudo and true random data

This is is "random" image generated using PHP rand() function: And this is an image...

20-11-2015 in Blog

READ MORE

Best EEPROM practices

(this article is a work in progress). My own advice will be added later...   Having...

12-10-2015 in Arduino

READ MORE
Scroll to top

We use cookies, just to track visits to our website, we store no personal details Privacy policy