+ Post New Thread
Results 1 to 6 of 6
Scripts Thread, Name mapped drives via script in Coding and Web Development; Hi All. I map all my drives via bat file, a seperate bat file for pupils and staff. Now a ...
  1. #1
    Bluetooth's Avatar
    Join Date
    Apr 2008
    Location
    Dewsbury
    Posts
    299
    Thank Post
    30
    Thanked 13 Times in 12 Posts
    Rep Power
    15

    Name mapped drives via script

    Hi All.

    I map all my drives via bat file, a seperate bat file for pupils and staff.

    Now a teacher expressed an idea that it would be good if i could change the names of the drives from the default path shown to something more friendly.

    So when you map a drive lets say to \\server\home\

    it will show up in my computer as a drive, with the above and the drive assignment.

    So is there a way to change it to something like "Childrens Work Area (H"?

  2. #2
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    Would renaming it via script do the trick?:

    Code:
    option explicit
    
    dim mdrive, oshell, fso
    
    set fso=createobject("Scripting.FileSystemObject")
    
    'Rename User Home Directory
    
    if fso.driveexists("H:") then
    
    mdrive = "H:\"
    Set oShell = CreateObject("Shell.Application")
    oShell.Namespace(mdrive).Self.Name = "Childrens Work Area"
    
    end if

  3. #3
    Bluetooth's Avatar
    Join Date
    Apr 2008
    Location
    Dewsbury
    Posts
    299
    Thank Post
    30
    Thanked 13 Times in 12 Posts
    Rep Power
    15
    Maybe!

    Would i put that in with the batch file or give each drive rename its own vbs script?

  4. #4
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Morecambe, Lancashire, UK.
    Posts
    281
    Thank Post
    39
    Thanked 36 Times in 26 Posts
    Rep Power
    25
    We use a vbscript that modifies the users registry with the name of the drive. In the example below the mapped drive is mapped and shows as 'Student Resources'. We also use a DFS namespace. Hope that helps.

    Code:
    Option Explicit
    On Error Resume Next
    Dim objFSO,objFILE,objShell,objNetwork
    set objFSO=CreateObject("Scripting.FileSystemObject")
    set objShell=CreateObject("Wscript.Shell")
    set objNetwork=CreateObject("Wscript.Network")
    
    Dim strHelpMsg, iErrorTimeout, blnShowError
    strHelpMsg="Contact QES IT Support Help Desk for further assistance."
    iErrorTimeout=10
    blnShowError=True
    
    'setup friendly names for mapped drives
    objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##queenelizabeth#data#StudentResources\_LabelFromReg", "Student Resources", "REG_SZ"
    
    
    'Map network drives
    MapIt "R:", "\\queenelizabeth\data\StudentResources"
    
    Sub MapIt(strDrive,strMap)
    	Const FORCE_REMOVE = True
    	Const UPDATE_PROFILE = True
    	Const NOT_PERSISTENT = False
    	Dim strMsg
    	
    	On Error Resume Next
    	If objFSO.DriveExists(strDrive) Then 
    		objNetwork.RemoveNetworkDrive strDrive, FORCE_REMOVE, UPDATE_PROFILE
    	End If
    	
    	objNetwork.MapNetworkDrive strDrive, strMap, NOT_PERSISTENT
    	
    	If Err.Number <> 0 And blnShowError Then
    		strMsg="There was a problem mapping drive " & UCase(strDrive) & " to " &_
    		strMap & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & hex(err.Number) &_
    		VbCrLf & Err.Description
    		objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation
    	End If
    
    End Sub

  5. #5
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    its vbscript so run it during logon (assume drive assignment happens during logon) but after the drives have been assigned.

    As for each drive, you just include that in the same script e.g. the script below has 2 drives renamed:

    Code:
    option explicit
    
    dim mdrive, oshell, fso
    
    set fso=createobject("Scripting.FileSystemObject")
    
    'Rename User Home Directory
    
    if fso.driveexists("H:") then
    
    mdrive = "H:\"
    Set oShell = CreateObject("Shell.Application")
    oShell.Namespace(mdrive).Self.Name = "Childrens Work Area"
    
    end if
    
    'Rename another directory
    
    if fso.driveexists("Z:") then
    
    mdrive = "Z:\"
    Set oShell = CreateObject("Shell.Application")
    oShell.Namespace(mdrive).Self.Name = "Some other Area"
    
    end if

  6. #6

    john's Avatar
    Join Date
    Sep 2005
    Location
    London
    Posts
    10,527
    Thank Post
    1,496
    Thanked 1,050 Times in 919 Posts
    Rep Power
    303
    If you have Server 2008 you can also do this as part of the Drive Mapping Process in GPOs

SHARE:
+ Post New Thread

Similar Threads

  1. mapped drives
    By silver in forum Hardware
    Replies: 2
    Last Post: 7th January 2009, 01:35 PM
  2. Drives not always being mapped?
    By techyphil in forum Windows
    Replies: 8
    Last Post: 16th October 2008, 10:03 PM
  3. VB Scrips and mapped drives
    By cookie_monster in forum Windows
    Replies: 4
    Last Post: 7th July 2008, 01:44 PM
  4. Mapped Drives - not so mapped!
    By LeonieCol in forum Windows
    Replies: 18
    Last Post: 12th March 2008, 03:36 PM
  5. Replies: 4
    Last Post: 7th December 2005, 08:09 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •