Solved

Changing a path to a UNC path

Posted on 2007-03-20
9
249 Views
Last Modified: 2011-09-20
Hi all,

I have a text box in my app where the user can specify a datapath. However if they put in a mapped network drive I need something that will automatically change the contents of the text box to the full network path.
Can someone tell me how I can do this?

Thanks
0
Comment
Question by:kiranboi
  • 6
  • 3
9 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18756086
Hmm - without knowing the server?

I wonder if you could redirect the output of a net use 'drive letter' to get at it...
0
 

Author Comment

by:kiranboi
ID: 18756143
sounds like it might work.
how do i do that tho?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18756171
Dim ps As New Process
Dim psi As New ProcessStartInfo
With psi
  .FileName="cmd"
  .Arguments="/c net use " & strDrive ' Perhaps use TextBox1.Text.SubString(0,2) for this
  .UseShellExecute=False
  .RedirectStandardOutput=True
  .WindowStyle=ProcessWindowStyle.Hidden
End With
With ps
  .StartInfo=psi
  .Start()
  .WaitForExit()
  .Close
End With
Dim strResults=ps.StandardOutput.ReadToEnd.Split(vbNewLine)
strPath=strResults(1) 'I 'think' it's the first element anyway...if that doesn't work, let me know...


0
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

by:sirbounty
ID: 18756188
Correction this line...since it's an array...

Dim strResults()=ps.StandardOutput.ReadToEnd.Split(vbNewLine)
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18756203
Looks like the first element (strResults(1)) will hold:

Remote name     \\server\share

So
TextBox2.Text=strResults(1).SubString(strResults(1).IndexOf("\"))

should do it...
0
 

Author Comment

by:kiranboi
ID: 18756814
Ive tried that and the line
   Dim strResults()=ps.StandardOutput.ReadToEnd.Split(vbNewLine)
is giving me the following error
   StandardOut not started or the process hasnt started yet

Any ideas?
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18756931
Slight modification - and this one's tested...

Dim ps As New Process
Dim psi As New ProcessStartInfo
With psi
  .FileName="cmd"
  .Arguments="/c net use " & strDrive 'strDrive must have the colon (F:)
  .UseShellExecute=False
  .RedirectStandardOutput=True
  .WindowStyle=ProcessWindowStyle.Hidden
End With
With ps
  .StartInfo=psi
  .Start()
  .WaitForExit()
End With
Dim strResults()=ps.StandardOutput.ReadToEnd.Split(vbNewLine)
TextBox2.Text=strResults(1).SubString(strResults(1).IndexOf("\"))
0
 

Author Comment

by:kiranboi
ID: 18772254
thats great thanx, thats exactly what i needed :)
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18772275
Happy to help - thanx for the grade! :^)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

789 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