Solved

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

Posted on 2004-03-22
16
1,811 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:Roebuck1967
[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
  • 7
  • 5
  • 4
16 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10648766
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 10648785
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
 

Author Comment

by:Roebuck1967
ID: 10649866
sirbounty,

I tried your VB script and nothing happened.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 67

Expert Comment

by:sirbounty
ID: 10649953
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
 

Author Comment

by:Roebuck1967
ID: 10651704
Nothing pops up.  No GUI, nothing happens.
0
 
LVL 11

Expert Comment

by:YohanShminge
ID: 10652678
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
 

Author Comment

by:Roebuck1967
ID: 10652718
YohanShminge,

Almost works.  I received a prompt but the drive was not mapped.  It needs to be the path of the current share.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10652732
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
 
LVL 11

Expert Comment

by:YohanShminge
ID: 10652769
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
 

Author Comment

by:Roebuck1967
ID: 10652885
Looks good.  Is this mapping permanent?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10652914
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
 
LVL 11

Accepted Solution

by:
YohanShminge earned 500 total points
ID: 10652929
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
 

Author Comment

by:Roebuck1967
ID: 10653012
Very cool thanks... 500 points to YohanShminge
0
 
LVL 11

Expert Comment

by:YohanShminge
ID: 10653044
Thanks for the points! ...AGAIN!
0
 

Author Comment

by:Roebuck1967
ID: 10687478
YohanShminge - Posting a new question for you today 3/26/04
0
 

Author Comment

by:Roebuck1967
ID: 10854761
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Suggested Courses

690 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