• Question

• I''m trying to setup a vbs script to prompt a user to enter their username & password to map through to a third party network. I've come up with the script below which prompts correctly, however i'm unsure if i'm storing the entered details correctly and then how to use these when mapping the network drive.

Set objNetwork = WScript.CreateObject("WScript.Network")

Any information on achieve this would be really appreciated.

Thanks

Monday, October 6, 2014 1:00 PM

http://www.westmesatech.com/misctools.html

The script would look like this:

@echo off
setlocal enableextensions

set USER=
set /p "USER=Enter user name: "
if {%USER%}=={} goto :END

net use l: \\192.168.68.48\test /user:%USER% %PASSWORD%
net use s: \\192.168.68.48\test /user:%USER% %PASSWORD%
net use p: \\192.168.68.48\test /user:%USER% %PASSWORD%

:END
endlocal


But I still don't see the point in mapping three different drive letters to the same path.

-- Bill Stewart [Bill_Stewart]

Tuesday, October 7, 2014 6:12 PM

All replies

• ¯\_(ツ)_/¯

Monday, October 6, 2014 1:57 PM
• I've already read through that - To be honest this is my first attempt at any VBS so struggling a bit. Could anyone help with an example of how I map it with the credentials the user's enter in the inputbox?

Thanks

Monday, October 6, 2014 2:13 PM
• Just follow the examples in the description.

You need to add the username and password AFTER the Boolean that sets it to be persistent.

This is designed to be used for Windows shares and not for third party authentication which may not be Windows compatible.

¯\_(ツ)_/¯

Monday, October 6, 2014 2:20 PM
• Searching is also a good way to learn how to do things:

¯\_(ツ)_/¯

Monday, October 6, 2014 2:21 PM
• I appreciate your trying to help but to be honest that's not very useful. I have searched and have no problems getting it to map with a predefined username and password.

Programming doesn't come naturally to some people so trying to interpret can prove difficult. I've created the script above, but as I said i'm struggling with passing through the entered information.

If you only want to point me to google can you at least advise if i'm on the right track or if i've got this completely wrong.

Set objNetwork = WScript.CreateObject("WScript.Network")

Monday, October 6, 2014 2:33 PM
• the two first items listed were complete and working examples.  I can do no better than that.  There is nothing else to know or tell you.  Just follow the examples.   You are not even close in your attempt so look at how other people have done it.

You can also learn how to write scripts here: http://technet.microsoft.com/en-us/scriptcenter/dd772284

This forum is not here to fix scripts or write scripts.  It is for technical professionals who are using or learning script and who can read the examples and implement them.

¯\_(ツ)_/¯

Monday, October 6, 2014 2:45 PM
• VBScript can't natively prompt for a hidden password using a GUI prompt. Don't use the InputBox function because it doesn't hide the password.

If you specify the net use command with a * parameter for the password, the program will prompt for credentials in the console window. This is by far the most secure way to do what you are asking.

net use S: \\servername\sharename /user:fabrikam\kendyer *

This will map drive S: to the specified path using the specified user name. You can do this all from a shell script (batch file):

@echo off
setlocal enableextensions
set USER=
set /p "USER=Enter user name: "
if {%USER%}=={} goto :END
net use S: \\servername\sharename /user:%USER% *
:END
endlocal


This short shell script (batch file) will prompt you to enter a user name. If the user enters something, then the script run the net use command using the username the user entered, and it will prompt for the password to map the drive.

-- Bill Stewart [Bill_Stewart]

Monday, October 6, 2014 3:16 PM
• Thanks for your help Bill - unfortunately i need the same credentials to be used to map 5 different network drives and as we know people won't like having to enter these 5 times.

I've found that I can * the Password when this is entered so saw this as a workaround to this issue.

Monday, October 6, 2014 3:21 PM
• So what's your question, then?

-- Bill Stewart [Bill_Stewart]

Monday, October 6, 2014 3:22 PM
• I was just looking for guidance with the script i've written above.

It prompts for username and password and allows these to be entered, but i'm unsure how I use these when mapping the network drives.

Using /user:" & strUsername &  /pass:" & strPassword throws up errors so wanted guidance on the right use case to map with the entered information.

Monday, October 6, 2014 3:36 PM
• Using /user:" & strUsername &  /pass:" & strPassword throws up errors so wanted guidance on the right use case to map with the entered information.
You haven't mentioned what errors you're receiving, so that's hard for us to help with.

Monday, October 6, 2014 3:44 PM

• http://social.technet.microsoft.com/Forums/getfile/541110
• Edited by Monday, October 6, 2014 3:56 PM
Monday, October 6, 2014 3:56 PM
• Which is the exact example you are asking for.  You obviously didn't event take the time to read it.  Why?

¯\_(ツ)_/¯

Monday, October 6, 2014 4:02 PM
• Thanks for your help Bill - I modified your batch file slightly and this is now doing exactly what I want.

@echo off
setlocal enableextensions
set USER=
set /p "USER=Enter user name: "
if {%USER%}=={} goto :END
net use l: \\192.168.68.48\test /user:%USER% %Password%
net use s: \\192.168.68.48\test /user:%USER% %Password%
net use p: \\192.168.68.48\test /user:%USER% %Password%
:END
endlocal

Tuesday, October 7, 2014 12:42 PM
• You should not use set /p to get a password because it's not masked on the screen (not secure).

-- Bill Stewart [Bill_Stewart]

Tuesday, October 7, 2014 12:48 PM
• How to securely attach drives:

$cred=Get-Credential new-psdrive -name L -root \\omega1\scritps -PSProvider FileSystem -Credential$cred -Persist
new-psdrive -name M -root \\omega2\scritps -PSProvider FileSystem  -Credential $cred -Persist new-psdrive -name N -root \\omega3\scritps -PSProvider FileSystem -Credential$cred -Persist


All passwords will been encrypted and masked.  No passwords will be written to disk.  The credentials will be saved in the secure password store if the drives are persisted.

¯\_(ツ)_/¯

• Edited by Tuesday, October 7, 2014 12:57 PM
Tuesday, October 7, 2014 12:53 PM
• I also don't see the point of mapping all three drives to the same path.

-- Bill Stewart [Bill_Stewart]

Tuesday, October 7, 2014 4:50 PM

http://www.westmesatech.com/misctools.html

The script would look like this:

@echo off
setlocal enableextensions

set USER=
set /p "USER=Enter user name: "
if {%USER%}=={} goto :END

net use l: \\192.168.68.48\test /user:%USER% %PASSWORD%
net use s: \\192.168.68.48\test /user:%USER% %PASSWORD%
net use p: \\192.168.68.48\test /user:%USER% %PASSWORD%

:END
endlocal