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.WorkingDirecto ry = myIP + "\\C$\\SomeFolder1\\SomeFo lder2\\Som eFolder3\\ ";
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
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.WorkingDirecto
p.StartInfo.FileName = "someExecutable.exe";
p.StartInfo.CreateNoWindow
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
ASKER
SirBounty,
I tried the following with the same error message:
p.StartInfo.WorkingDirecto ry = myIP + @"\C$\SomeFolder1\SomeFold er2\SomeFo lder3\";
When I step through the code, and examine
p,.StartInfo.WorkingDirect ory", 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
I tried the following with the same error message:
p.StartInfo.WorkingDirecto
When I step through the code, and examine
p,.StartInfo.WorkingDirect
thanks
ASKER
I just tried the following:
p.StartInfo.WorkingDirecto ry = Path.Combine(myIP , @"\C$\SomeFolder1\SomeFold er2\SomeFo lder3\)";
but the "WorkingDirectory" folder will only contain "\\C$\SomeFolder1\SomeFold er2\SomeFo lder3\"
p.StartInfo.WorkingDirecto
but the "WorkingDirectory" folder will only contain "\\C$\SomeFolder1\SomeFold
Do any of the 'somefolders' contain spaces? You'll need to enclose it in quotes, if so...
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.UseShellExecut e = true;
and
p.StartInfo.UseShellExecut e = false;
but it didn't make a difference.
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.UseShellExecut
and
p.StartInfo.UseShellExecut
but it didn't make a difference.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
dstaneley,
the @"\\" seems to do the trick. Thanks.
the @"\\" seems to do the trick. Thanks.
will resolve to
\\xxx.xxx.xx.xx\\c$\\SomeF
What if you reconfigure it to resolve to
\\xxx.xxx.xx.xx\c$\SomeFol
Does that work?