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!

Network Drive Label 1

Status
Not open for further replies.

NEAXMAN

Technical User
May 21, 2014
50
US
Hello all,

I am having a bit of a problem trying to rename mapped network drives. We use a .bat logon script that maps our network drives using net use and then the batch script calls a vbscript that renames the network drives. The script vbscript looks like:

Set oShell = CreateObject("Shell.Application")
oShell.NameSpace("H:\").Self.Name = "Home"
oShell.NameSpace("I:\").Self.Name = "ProgramFiles"
oShell.NameSpace("P:\").Self.Name = "Public"
oShell.NameSpace("X:\").Self.Name = "Apps"

The problem is that we now would like to label the H: Drive with the %username% variable, so it shows the user's logon name. So for example Sue Water's H: Drive would show up as waterss (H:) in My Computer. How would I go about doing this?
 
Thanks for the reply. So in this case, what would my whole VBScript look like?
 
Assuming your initial code worked and made the H: drive show up as [highlight #FCE94F]Home (H:)[/highlight], then this should work (not tested):

Code:
Set wshShell = CreateObject( "WScript.Shell" )
username = wshShell.ExpandEnvironmentStrings( "%username%" )

Set oShell = CreateObject("Shell.Application")
oShell.NameSpace("H:\").Self.Name = [highlight #FCE94F]username[/highlight]
oShell.NameSpace("I:\").Self.Name = "ProgramFiles"
oShell.NameSpace("P:\").Self.Name = "Public"
oShell.NameSpace("X:\").Self.Name = "Apps"
 
Perfect!! Thank you so much! This works just as we had hoped. The H: Drive is labeled as the user's logon username. Thanks a million![bigsmile]
 
Neaxman, don't forget to click the Great Post link to give a star to Guitarzan's post.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
Given that users can modify environment variables, why not go with:

Code:
[blue]Set wshNetwork = CreateObject("WScript.Network")
username =  wshNetwork.UserName[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top