Link to home
Start Free TrialLog in
Avatar of kiranboi
kiranboi

asked on

Changing a path to a UNC path

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
Avatar of sirbounty
sirbounty
Flag of United States of America image

Hmm - without knowing the server?

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

ASKER

sounds like it might work.
how do i do that tho?
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...


Correction this line...since it's an array...

Dim strResults()=ps.StandardOutput.ReadToEnd.Split(vbNewLine)
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...
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?
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

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
thats great thanx, thats exactly what i needed :)
Happy to help - thanx for the grade! :^)