Solved

Changing a path to a UNC path

Posted on 2007-03-20
9
245 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
Comment Utility
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
Comment Utility
sounds like it might work.
how do i do that tho?
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Correction this line...since it's an array...

Dim strResults()=ps.StandardOutput.ReadToEnd.Split(vbNewLine)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thats great thanx, thats exactly what i needed :)
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Happy to help - thanx for the grade! :^)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now