Link to home
Start Free TrialLog in
Avatar of brdrok
brdrok

asked on

Need help with Process.StartInfo.WorkingDirectory

Hi,

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"
p.WaitForExit();

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

\\xxx.xxx.xx.xx

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.

thanks
Avatar of sirbounty
sirbounty
Flag of United States of America image

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

will resolve to

\\xxx.xxx.xx.xx\\c$\\SomeFolder1\\SomeFolder2

What if you reconfigure it to resolve to

\\xxx.xxx.xx.xx\c$\SomeFolder1\SomeFolder2

Does that work?
Avatar of brdrok
brdrok

ASKER

SirBounty,

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 "\".

thanks
Avatar of brdrok

ASKER

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\"

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

ASKER

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;
and
p.StartInfo.UseShellExecute = false;

but it didn't make a difference.

ASKER CERTIFIED SOLUTION
Avatar of dstanley9
dstanley9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brdrok

ASKER

dstaneley,

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