Solved

Need help with Process.StartInfo.WorkingDirectory

Posted on 2007-03-27
7
278 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:brdrok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18800767
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?
0
 
LVL 7

Author Comment

by:brdrok
ID: 18800846
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
0
 
LVL 7

Author Comment

by:brdrok
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\"

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 67

Expert Comment

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

Author Comment

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

but it didn't make a difference.

0
 
LVL 25

Accepted Solution

by:
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)
0
 
LVL 7

Author Comment

by:brdrok
ID: 18802460
dstaneley,

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - SQL Timeout 9 50
How to repeat the data 4 30
How to reference a column by name when iterating through a GridView ? 1 32
Problem to copy file 14 47
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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