Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script that gets username and password and brings up window.

Status
Not open for further replies.

snowy81

Technical User
Apr 17, 2008
2
0
0
US
I have a script I wrote that gets a users name and password and maps a network drive for them. It is all working except I can't get it to actually open up the share. Here is the code for my last attempt. I know this should be easy but I can't figure it out.

P.S (Everything up to and including the msgbox works.)

Set objNetwork = WScript.CreateObject("WScript.Network")
strPer = "FALSE"
strUsr = InputBox("Please Enter Your Username")
strPas = Enter your Password")
strLocalDrive = "h:"
strRemoteShare = "\\macx\user\" &strUsr
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
mDrive = "h:"
Set oShell = CreateObject("Shell.Application")
oShell.NameSpace(mDrive).Self.Name = strUsr & " on macx"

MsgBox "You have successfully mapped to your H: drive! Go forth, and be a better human

being."


Option Explicit

Const vbNormalFocus = 1
Const path = "\\macx\" & strUsr

WScript.CreateObject("WScriptShell").Run
"explorer.exe \n,\root,""" & path
 
is their any reason why you don't pull the user from AD

Code:
Set WshNetwork = CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strPer = "FALSE"
strUsr = InputBox("Please Enter Your Username")
strPas = InputBox("Enter your Password")
strLocalDrive = "h:"
strRemoteShare = "\\macx\user" & "\" & strUsr

'Create the folder 
				' Check that the strDirectory folder exists
					If objFSO.FolderExists(strRemoteShare) Then
					  Set objFolder = objFSO.GetFolder(strRemoteShare)
					Else
					  Set objFolder = objFSO.CreateFolder(strRemoteShare)
					  'WScript.Echo "Just created " & strDirectory
					End If
					
'map the drive
WshNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas

'renmae the drive to a better name
mDrive = "h:"
Set WshShell = CreateObject("Shell.Application")
WshShell.NameSpace(mDrive).Self.Name = strUsr & " on macx"

MsgBox "You have successfully mapped to your H: drive! Go forth, and be a better human being."
 
I posted an FAQ on building an input box that does not display the user's password in clear text when they type it.

faq329-6910



PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
There were lots of typos in the code



Const vbNormalFocus = 1
Const path = "\\macx\ & strUsr"

Set WshShell = WScript.CreateObject("WScript.Shell")
wshshell.Run "explorer.exe \n,\root,""" & path


Set objNetwork = WScript.CreateObject("WScript.Network")
strPer = "FALSE"
strUsr = InputBox("Please Enter Your Username")
strPas = InputBox("Enter your Password")
strLocalDrive = "h:"
strRemoteShare = "\\192.168.7.7\c"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
mDrive = "h:"
Set oShell = CreateObject("Shell.Application")
oShell.NameSpace(mDrive).Self.Name = strUsr & " on macx"

MsgBox "You have successfully mapped to your H: drive! Go forth, and be a better human
 
strUserName = WshShell.ExpandEnvironmentStrings("%username%")

i presume the user is not logged on the workstation (where this code will run from) in the same context as the username and password you are asking them to supply?
 
Thanks to everyone who helped but especially you jamesjames. I ended up using a modified version of yours. Here is the code:
Code:
Const vbNormalFocus = 1


Set objNetwork = WScript.CreateObject("WScript.Network")
strPer = "FALSE"
strUsr = InputBox("Please Enter Your Username")
strPas = InputBox("Enter your Password")
strLocalDrive = "h:"
strRemoteShare = "\\macx\user\"&strUsr
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
mDrive = "h:"
Set oShell = CreateObject("Shell.Application")
oShell.NameSpace(mDrive).Self.Name = strUsr & " on macx"

MsgBox "You have successfully mapped to your H: drive! Go forth, and be a better human" 

Set WshShell = WScript.CreateObject("WScript.Shell")
wshshell.Run   "explorer.exe \\macx\user\" & strUsr
 
Wow, that code is still a mess. Why are you declaring oShell and WshShell? You just need to use one and use the same naming convention throughout.

Likewise for strLocalDrive and mDrive.

Why do you use the message box? It creates an extra step for your users, they have to click OK to continue and I'm sure they can figure out if the drive mapped successfully or not by its existence.

Why do you prompt for username? Are you running this on MAC machines? If on PC then you can use WSHNetwork.Username to grab the user name. If the PC the user is on is a member of the same domain as the server you are mapping to, then there should be no reason to supply username and password to map the drive.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top