1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Mapped Drives and vbscripts

Discussion in 'Networking (Hardware & Software)' started by jeffuk123, 2008/11/12.

  1. 2008/11/12
    jeffuk123

    jeffuk123 Inactive Thread Starter

    Joined:
    2006/04/03
    Messages:
    71
    Likes Received:
    0
    Hello

    If a vbscript is used to map network drives for users, but that script does not always run properly, will adding the mapped drives manually affect the script or causes any issues?

    Regards,
    Jeff
     
  2. 2008/11/13
    ReggieB

    ReggieB Inactive Alumni

    Joined:
    2004/05/12
    Messages:
    2,786
    Likes Received:
    2
    Yes, if you try to map to a drive letter that already exists, you'll get an error. However, you can catch it in your script before it happens.

    For example, I use this script:
    Code:
     '  Based on a VBScript by Guy Thomas February 2004.
    '  http://computerperformance.co.uk
    
    ' This line creates the Shell or environment for the commands - do not alter
    Set WshShell = WScript.CreateObject( "WScript.Shell ")
    
    ' The section sets the variables. Note the pattern variable = value
    ' You may change the variable names if you wish to check your understanding.
    
    Set objNet = WScript.CreateObject( "WScript.Network ")
    Set CheckDrive = objNet.EnumNetworkDrives()
    
    ' Be very carefull with the DriveLetter, the value must be a CAPITAL letter
    ' map drives
    
    MapThisDrive  "P: ",  "\\server\share1 "
    MapThisDrive  "Q: ",  "\\server\share2 "
    
    
    Sub MapThisDrive(DriveLetter,RemotePath)
    	' This sub routine does the work.
    
    	AlreadyConnected = False
    	For i = 0 To CheckDrive.Count - 1 Step 2
    		If CheckDrive.Item(i) = DriveLetter Then AlreadyConnected = True
    	Next
    	
    	' This tests to see if the Drive is already mapped, and if yes then disconnects it before reconnecting it
    	If AlreadyConnected = True then
    		objNet.RemoveNetworkDrive DriveLetter
    		objNet.MapNetworkDrive DriveLetter, RemotePath
    		
    	Else
    		objNet.MapNetworkDrive DriveLetter, RemotePath
    	
    	End if
    	
    End sub
    '  Script ends here  
    The subroutine is passed a drive letter and the share to be assign to it. It first checks to see if the drive letter mapping exists and if it does it removed it before creating a new one.
     

  3. to hide this advert.

  4. 2008/11/17
    jeffuk123

    jeffuk123 Inactive Thread Starter

    Joined:
    2006/04/03
    Messages:
    71
    Likes Received:
    0
    Thanks Reggie
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.