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

how to pull a username in vbscript (working on a login script)

Status
Not open for further replies.

Mizugori

Programmer
May 21, 2007
56
US
I am using Mark's login script as a base:


In mapping network drives, if each user has a directory named after them and I want to map it in the login script, how do I fill in the part of the path where their username goes?

Early on in the script he pulls the username:

'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

But so now when I map the drive, how do I fill in their username? I'm not very familiar with VBScript. For example, if I want to map userdrives\jsmith to L:, would it be something like:

WSHNetwork.MapNetworkDrive "L:", "\\servername\userdrives\"UserString

I tried this and it did not work (I'm not surprised it was a shot in the dark). Can anyone correct the statement for me so it will fill in the username as the last part of the path to be mapped?

Thanks!
 
Something like:
Code:
WSHNetwork.MapNetworkDrive "L:", "\\servername\userdrives\" & UserString
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
I am thinking you have not actually read my FAQ as that is one of the examples I give in it. :-(

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.
 
I don't know about your FAQ but I did read most of the text with the script, and I saw an example where you added shares using a switch statement but that's not what I wanted to do. I wanted it to map a folder with whatever their username is.

If I missed this exact example in your text, my mistake. but why be upset? hell i'm using your script, another happy customer so to speak, so be happy =)
 
From the FAQ:
Code:
'Map drives needed by all
[red]'Note the first command uses the user name as a variable to map to a user share.[/red]
'Note alternate mapping code in Add-In section that allows 
'friendly renaming of drive mappings

WSHNetwork.MapNetworkDrive "H:", "\\server\users\" & UserString,True

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