Solved

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

Posted on 2004-03-22
16
1,798 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

What’s a web proxy server? A proxy server is a server that goes between clients and web servers, used in corporate to enforce corporate browsing policy and ensure security. Proxy servers are commonly used in three modes. A)    Forward proxy …
Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

18 Experts available now in Live!

Get 1:1 Help Now