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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Username and Password during drive mapping

Status
Not open for further replies.

roles40

MIS
Aug 20, 2003
21
US
I am a relative newbie @ VBS. I am in need of some help finding a function that gathers the password much like the username is gathered from the machine. Here is the code that I am using so far.

Set WSHNetwork = CreateObject("WScript.Network")
Set netobj=wscript.createobject("wscript.network")
username=netobj.username
Password = InputBox("Please Enter Your Network Password","Password?")
WSHNetwork.MapNetworkDrive "X:", "\\Server1\Filename",True,UserName,Password
WSHNetwork.MapNetworkDrive "Y:", "\\Server1\Home\" &username,True,UserName,Password

I am looking for something that essentially will do the same thing as "username=netobj.username", except for the password??

Also, are the first two lines of this code redundant??

Any suggestions, comments, snide remarks would be greatly appreciated.

Jamie
 
Hello roles40,

If you use WSHNetwork consistently later on, then the second line is not necessary and can be eliminated.

regards - tsuji
 
Hi Roles40,

There should be no need to specify the user ID and password while mapping the drive. Since you are grabbing the username fromt he login session, those credentials will be automatically used.

Here is the code I use all the time.

[script]
'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'
'==========================================================================


ON ERROR RESUME NEXT

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

'Edit the next line with your domain name
DomainString = "DomainName"
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\Server /set /y"

'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "F:"

'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300

'Map drives needed by all
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
WSHNetwork.MapNetworkDrive "X:", "\\server\executables",True

'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
'In this example below, ADMIN and WORKERB are groups.
Case "Admin"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
Case "WorkerB"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
End Select
Next


'Install Printers

WSHNetwork.AddWindowsPrinterConnection "\\Server\HP5si"

'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing

'Quit the Script
wscript.quit

[/script]

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top