Need a VB script that will prompt user for mapped drive.

Would like to have a VB script setup on a network share that once executed by the user would automatically prompt them what letter drive they would like to have the share mapped to.

So for example:
-      User initially browses to a share lets say \\servername\myshare
-      Once in the myshare folder there would be a VB script  lets call it mapdrive.vbs
-      The user would double click mapdrive.vbs and be promped “what letter drive would you like to map this?”
-      User would enter a letter  “S”
-      Every time the user logons on the “S” drive would be automatically mapped to \\servername\myshare
Roebuck1967Asked:
Who is Participating?
 
YohanShmingeConnect With a Mentor Commented:
Great.  And no, you'd have to add a switch to the end of the "net use" command, like this: "net use X: \\server\sharename /Persistent:YES" So the entire code, to make a permanent connection, looks thus:

Set SH = CreateObject("WScript.Shell")

resp = InputBox("Which drive letter would you like to map?")
drvLtr = Asc(UCase(resp))

SH.Run "net use " & Chr(drvLtr) & ": \\server\sharename /Persistent:YES", 0, true
0
 
sirbountyCommented:
Aside from error-checking, this should work:

Private Sub Form_Load()
resp = InputBox("Which drive letter would you like to map?")
drvLtr = Asc(UCase(resp))
Shell ("net use " & Chr(drvLtr) & ": " & FileSystem.CurDir)
Unload Me
End Sub
0
 
sirbountyCommented:
Try this to check for an appropriate drive letter, beginning with F:

Private Sub Form_Load()
resp = InputBox("Which drive letter would you like to map?")
If InStr(1, "FGHIJKLMNOPQRSTUVWXYZ", UCase(resp)) < 1 Then
    MsgBox "You must enter a valid drive letter (F thru Z)"
    Exit Sub
End If
drvLtr = Asc(UCase(resp))
Shell ("net use " & Chr(drvLtr) & ": " & FileSystem.CurDir)
Unload Me
End Sub
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
Roebuck1967Author Commented:
sirbounty,

I tried your VB script and nothing happened.
0
 
sirbountyCommented:
Could you provide a little more detail?
The script should bring up an inputbox allowing the user to enter a drive letter...
Is it making it this far?

One other minor adjustment that may be necessary is to replace the Shell line with

Shell ("cmd /c net use " & Chr(drvLtr) & ": " & FileSystem.CurDir)
0
 
Roebuck1967Author Commented:
Nothing pops up.  No GUI, nothing happens.
0
 
YohanShmingeCommented:
VBScript is slightly different from pure VB.  Do you need the script to recognize the path to the current share?  If not, then this code should do it simply.  Also, would you like the user to be able to see the DOS window?  Its the only way they could diagnose any errors with the net use command...

************

Set SH = CreateObject("WScript.Shell")

resp = InputBox("Which drive letter would you like to map?")
drvLtr = Asc(UCase(resp))

SH.Run "net use " & Chr(drvLtr) & ": \\server\sharename", 0, true
0
 
Roebuck1967Author Commented:
YohanShminge,

Almost works.  I received a prompt but the drive was not mapped.  It needs to be the path of the current share.
0
 
sirbountyCommented:
Hi Roebuck1967 - using VB - which version?
Can you place the project/form on a remote share and run it by pressing F8 to step through it?
If nothing else, you should receive an Input Box requesing the drive letter...
Post back with where it stops.
0
 
YohanShmingeCommented:
sirbounty, this is VBscript we're talking about. ;-)

And Roebuck1967, I'll keep looking, but I think you'll have to enter the share path manually, unless theres another way for the script to get it.  The problem is that functions like "FileSystem.CurDir" return the LOCAL path, not the share path, so when the script is executed, it will be very difficult for it to determine the share name for the current directory.  In this line at the end of the script above:

SH.Run "net use " & Chr(drvLtr) & ": \\server\sharename", 0, true

Just change "\\server\sharename" to what it should be for your network.
0
 
Roebuck1967Author Commented:
Looks good.  Is this mapping permanent?
0
 
sirbountyCommented:
Hmm - I've tried this under VBscript and get the input box and the shell command (with the remote share, not the local file system drive)...
not sure why it's not working for you...
0
 
Roebuck1967Author Commented:
Very cool thanks... 500 points to YohanShminge
0
 
YohanShmingeCommented:
Thanks for the points! ...AGAIN!
0
 
Roebuck1967Author Commented:
YohanShminge - Posting a new question for you today 3/26/04
0
 
Roebuck1967Author Commented:
YohanShminge,

Posted a new question that deal with the script below

Set SH = CreateObject("WScript.Shell")

resp = InputBox("Which drive letter would you like to map?")
drvLtr = Asc(UCase(resp))

SH.Run "net use " & Chr(drvLtr) & ": \\taking-fp01\Test - Share /Persistent:YES", 0, true

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.