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

Mapped drives - what is wrong with this code snippet?

Status
Not open for further replies.

Callahan

Technical User
Nov 21, 2001
174
GB
Hi all,

Now first off I know as much about VB Scripting as I've learnt this morning. After the sucess I've had so far (up until this point) I'm really going to learn more about it.

Ok, so here's what I want to do. Upon user logon, the .vbs script will unmap all network drives on the client machine, remap them (this is to automate unmapping and mapping of new network shares in the future), then renames each of the drives.
Everything works up until the point of renaming the network drives. If I run the piece of code that renames the drives outside of this code it works so I'm guessing the mistake can only be minor.

Any suggestions grately received.

Option Explicit
Dim strDriveLetter1, strDriveLetter2, RemotePath1, RemotePath2
Dim objNetwork
Dim bForce, bUpdateProfile
Dim mDrive
bForce = "True"
bUpdateProfile = "True"

Set objNetwork = CreateObject("WScript.Network")
strDriveLetter1 = "F:"
strDriveLetter2 = "Y:"
RemotePath1 = "\\fpsl01\home"
RemotePath2 = "\\fpsl01\jbloggs"

' Removes all listed DriveLetters, with bForce, pUpdate Profile
On Error Resume Next
objNetwork.RemoveNetworkDrive strDriveLetter1, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter2, bforce, bUpdateProfile

' Maps the listed drives
objNetwork.MapNetworkDrive strDriveLetter1, RemotePath1
objNetwork.MapNetworkDrive strDriveLetter2, RemotePath2

' Section which actually (re)names the Mapped Drives
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter1).Self.Name = "test1"
objShell.NameSpace(strDriveLetter2).Self.Name = "test2"
Wscript.Echo "Success - All done"
Wscript.Quit
 
VBScript=forum329

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top