Need help with Process.StartInfo.WorkingDirectory

Posted on 2007-03-27
Last Modified: 2010-04-16

I have the following code:

Process p = new Process();
string myIP = "\\" + ipAddress[0].ToString() + "." + ipAddress[1].ToString() + "." + ipAddress[2].ToString() + "." + ipAddress[3].ToString();
p.StartInfo.WorkingDirectory = myIP +  "\\C$\\SomeFolder1\\SomeFolder2\\SomeFolder3\\";
p.StartInfo.FileName = "someExecutable.exe";
p.StartInfo.CreateNoWindow = true;
p.Start();  <===== generating error "The system cannot find the file specified"

When I look stop and examine the myIP variable, I have the following:


I suspect that it may have something to do with those escape characters but I don't know for sure.  Hopefully someone knows how to make this work.

Question by:brdrok
  • 4
  • 2
LVL 67

Expert Comment

ID: 18800767
p.StartInfo.WorkingDirectory = myIP +  "\\C$\\SomeFolder1\\SomeFolder2\\SomeFolder3\\";

will resolve to


What if you reconfigure it to resolve to


Does that work?

Author Comment

ID: 18800846

I tried the following with the same error message:

p.StartInfo.WorkingDirectory = myIP +  @"\C$\SomeFolder1\SomeFolder2\SomeFolder3\";

When I step through the code, and examine
p,.StartInfo.WorkingDirectory", I notice that those "\\" appear again.  I don't understand why WorkingDirectory insists on using double "\" let alone how to make it smart enough to recognize single "\".


Author Comment

ID: 18800879
I just tried the following:
p.StartInfo.WorkingDirectory = Path.Combine(myIP ,  @"\C$\SomeFolder1\SomeFolder2\SomeFolder3\)";

but the "WorkingDirectory" folder will only contain "\\C$\SomeFolder1\SomeFolder2\SomeFolder3\"

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

LVL 67

Expert Comment

ID: 18800930
Do any of the 'somefolders' contain spaces?  You'll need to enclose it in quotes, if so...

Author Comment

ID: 18800985
No, no spaces for the folder names.  

I looked at the MSND article and they have the following.  Perhaps it makes more sense to you than to me.
If the directory is already part of the system path variable, it is not necessary to repeat the directory's location in this property.

The WorkingDirectory property behaves differently when UseShellExecute is true than when UseShellExecute is false. When UseShellExecute is true, the WorkingDirectory property specifies the location of the executable. If WorkingDirectory is an empty string, the current directory is understood to contain the executable.

When UseShellExecute is false, the WorkingDirectory property is not used to find the executable. Instead, it is used by the process that is launched and only has meaning within the context of the new process.


I tried the following:

p.StartInfo.UseShellExecute = true;
p.StartInfo.UseShellExecute = false;

but it didn't make a difference.

LVL 25

Accepted Solution

dstanley9 earned 500 total points
ID: 18801009
string myIP = "\\" + ipAddress[0].ToString() + "." + ipAddress[1].ToString() + "." + ipAddress[2].ToString() + "." + ipAddress[3].ToString();

UNC patch should start with double-slashes, but this will only start with a single slash.  try

string myIP = @"\\" + ipAddress[0].ToString() + "." + ipAddress[1].ToString() + "." + ipAddress[2].ToString() + "." + ipAddress[3].ToString();

The rest of the path will turn the double-slashes to single slashes, so it should be fine (assuming of course that you have permissions to that share when running the app)

Author Comment

ID: 18802460

the @"\\" seems to do the trick.  Thanks.

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
List<PaisEntity> - show some 1 28
Expression Evaluater 3 38
VS2013 publish C# application Created folder -- where is it??? 10 27
Need a simple RegEx to search for two words 27 45
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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