+ Post New Thread
Results 1 to 10 of 10
Scripts Thread, Mapping Network Drives ? in Coding and Web Development; I have this script , I have tried to alter the script so that strusername = objNetwork.UserName and at the ...
  1. #1

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,763
    Thank Post
    3,273
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365

    Mapping Network Drives ?

    I have this script , I have tried to alter the script so that strusername = objNetwork.UserName and at the minute I have it so that strusername = objNetwork.ComputerName.

    I have made it a startup script in gpo and have applied this to an ou that only my machine is in and made it apply to everyone that is in the Machines OU, my machine is in there, I have done a gpupdate on the server and a gpupdate /force on my machine and restarted and logged back in and no success with mapping the drives.

    Here is the script :

    Code:
    Option Explicit
    Dim StrUserName, objNetwork, user, pass, strprofile
    
    const marketing = "\\server\Marketing"
    const FDrive = "\\server\company"
    const creative = "\\server\creativeserver"
    const mitn = "\\server\MITN_shared"
    
    Set objNetwork = CreateObject("Wscript.Network")
    strUserName = objNetwork.ComputerName
    
    Select Case strUserName
    
    Case "Comp1":
    
    Call check("M:",marketing)
    Call check("F:",FDrive)
    Call cs("S:",creative,false,"user","pass")
    Call check("Z:",mitn)
    
    Case "Comp2":
    
    Call check("M:",marketing)
    Call check("F:",FDrive)
    Call cs("S:",creative,false,"user","pass")
    Call check("Z:",mitn)
    
    
    Case "MyComp":
    
    Call check("K:",FDrive)
    Call cs("S:",creative,false,"user","pass")
    Call check("Z:",mitn)
    
    Case Else:
    
    Call check("F:",FDrive)
    Call cs("S:",creative,false,"user","pass")
    Call check("Z:",mitn)
    
    End Select
    
    Public Function check(ByRef strDriveLetter, ByRef strRemotePath)
    Set objNetwork = CreateObject("Wscript.Network")
    Dim CheckDrive, AlreadyConnected, intDrive 
    Set CheckDrive = objNetwork.EnumNetworkDrives() 
    ' This section deals with a For ... Next loop
    ' See how it compares the enumerated drive letters
    ' with strDriveLetter
    On Error Resume Next
    AlreadyConnected = False 
    For intDrive = 0 To CheckDrive.Count - 1 Step 2 
    If CheckDrive.Item(intDrive) = strDriveLetter Then 
    AlreadyConnected = True
    End If
    Next 
    ' This section uses the If = then, else logic
    ' This tests to see if the Drive is already mapped.
    ' If yes then disconnects
    Select Case AlreadyConnected
    Case "True":
    objNetwork.RemoveNetworkDrive strDriveLetter 
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath 
    Case "False":
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath 
    End Select
    End Function
    
    Public Function cs(ByRef strDriveLetter, ByRef strRemotePath, ByRef prof, ByRef User, ByRef Pass)
    Set objNetwork = CreateObject("Wscript.Network")
    Dim CheckDrive, AlreadyConnected, intDrive 
    Set CheckDrive = objNetwork.EnumNetworkDrives() 
    ' This section deals with a For ... Next loop
    ' See how it compares the enumerated drive letters
    ' with strDriveLetter
    On Error Resume Next
    AlreadyConnected = False 
    For intDrive = 0 To CheckDrive.Count - 1 Step 2 
    If CheckDrive.Item(intDrive) = strDriveLetter Then 
    AlreadyConnected = True
    End If
    Next 
    ' This section uses the If = then, else logic
    ' This tests to see if the Drive is already mapped.
    ' If yes then disconnects
    Select Case AlreadyConnected
    Case "True":
    objNetwork.RemoveNetworkDrive strDriveLetter 
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strprofile, user, pass
    Case "False":
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strprofile, user, pass 
    End Select
    End Function
    Can someone shed some light on what I am doing wrong or what needs to be fixed so that I can get this to work correctly, do I need to do a wscript.sleep for 15 seconds before it runs so it gives the machine a chance to load or what exactly ?

    Thanks

  2. #2
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    3,017
    Thank Post
    304
    Thanked 288 Times in 200 Posts
    Rep Power
    120

    Re: Mapping Network Drives ?

    usually it runs straight away, mine are in the netlogon folder.

    this works fine, but am soon wanting it to be user specific too...

    Code:
    ' Setting the parameters
    
    On error resume next
    
    		Set wshnetwork = CreateObject("WScript.Network")
    		Set ADSysInfo = CreateObject("ADSystemInfo")
    		Set CurrentUser = GetObject("LDAP://" & ADSysInfo.Username)
    		Set Drives = wshnetwork.EnumNetworkDrives
    		set fso = CreateObject("Scripting.FileSystemObject")
    		strGroups = LCase(CurrentUser.MemberOf)
    		strGroups = LCase(Join(CurrentUser.MemberOf))
    
    ' Setting the groups of departments with the member of settings in AD
    
    	Const Staff 		= "cn=staff"
    	Const Maths 		= "cn=mathematics"
    	Const PowerStaff 	= "cn=powerstaff"
    	Const ITTeach 		= "cn=information technology"
    	Const ITAdmin 		= "cn=admin"
    	Const DesignTechnology	= "cn=design technology"
    	Const H2L		= "cn=special needs"
    	Const Careers		= "cn=careers"
    
    ' admin settings
    	
    	Const AdminStaff	= "cn=generaladmin"
    	Const OfficeGroup	= "cn=Office Group"
    	
    
    		
    ' All general users
    
    
    ' Delete all network drives
    		
    		If right(item,1) = ":" then
    			wshnetwork.removenetworkdrive item
    
    	end if
    
    ' Adding the Drives for the specific groups
    
    'Staff group		
    
    If Instr(strGroups,staff) Then
    On Error Resume Next
    			wshnetwork.RemoveNetworkDrive "p:"
    			wshnetwork.RemoveNetworkDrive "s:"
    			wshnetwork.RemoveNetworkDrive "v:"
    			wshnetwork.RemoveNetworkDrive "q:"			
    
    			wshNetwork.MapNetworkDrive "p:","\\hades\upublic"
    			wshNetwork.MapNetworkDrive "s:","\\hades\business"
    			wshNetwork.MapNetworkDrive "v:","\\hades\uapps"
    			wshnetwork.mapnetworkdrive "q:","\\seth\users\home\administration"
    
    
    'ITAdmin Group	
    	If Instr(strGroups,ITAdmin) Then
    
    			wshnetwork.RemoveNetworkDrive "n:"
    			wshnetwork.RemoveNetworkDrive "w:"
    			wshnetwork.RemovenetworkDrive "y:"
    			wshnetwork.RemoveNetworkDrive "x:"
    
    			wshNetwork.MapNetworkDrive "n:","\\chaos\notes"
    			wshNetwork.MapNetworkDrive "w:","\\hades\apps"
    			wshnetwork.MapnetworkDrive "y:","\\hades\profiles"
    			wshnetwork.mapnetworkdrive "x:","\\seth\users\home"
    
    		End If 'ITAdmin
    
    
    ' Powerstaff group	
    	If Instr(strGroups,powerstaff) Then
    	
    			wshNetwork.MapNetworkDrive "x:","\\Seth\users\home"
    
    		End If 'Powerstaff
    
    
    ' ITTeach Group	
    	If Instr(strGroups,itteach) Then
    
    			wshnetwork.RemoveNetworkDrive "o:"
    
    			wshNetwork.MapNetworkDrive "o:","\\seth\ITStaff"
    	
    		End If 'ITTeach
    
    
    ' Maths Group
    	If Instr(strGroups,Maths) Then
    
    			wshNetwork.MapNetworkDrive "m:","\\seth\users\home\MathsStaff"
    
    		End If 'Maths
    
    	
    
    ' DesignTechnology Group
    	If Instr(strGroups,designtechnology) Then
    
    			wshnetwork.mapnetworkdrive "m:","\\seth\users\home\destech"
    
    		End If 'designtechnology
    
    
    ' H2L Group	
    	If Instr(strGroups,H2L) then
    				
    			wshnetwork.mapnetworkdrive "m:","\\seth\users\home\h2lstaff"
    
    		End if 'H2L
    
    
    ' Careers Group
    	If Instr(strGroups,Careers) then
    	
    			wshnetwork.mapnetworkdrive "t","\\seth\user\wxpnet"
    
    		End if 'Careers
    
    
    ' AdminStaff Group
    	If Instr(strGroups,adminstaff) then
    				
    			wshnetwork.mapnetworkdrive "f:","\\server\apps"
    			wshnetwork.mapnetworkdrive "L:","\\server\public"
    			wshnetwork.mapnetworkdrive "q:","\\seth\users\home\administration"
    
    		End if 'adminstaff
    
    
    ' OfficeGroup Group
    	If Instr(strGroups,Officegroup) then
    				
    			wshnetwork.mapnetworkdrive "k:","\\server\common"
    
    		End if 'officegroup
    
    
    End If 'Staff

  3. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,763
    Thank Post
    3,273
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365

    Re: Mapping Network Drives ?

    now it adds all my network drives but it tells me they are all disconnected and they still show up in my computer but I cant disconnect them , when I try to disconnect them it just tells me that there are no network drives to disconnect :-S

    ok what do I do to fix that ?

  4. #4

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,763
    Thank Post
    3,273
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365

    Re: Mapping Network Drives ?

    Network drives screenshot of it saying they are disconnected yet they still work, why is it telling me they are disconnected ?
    Last edited by mac_shinobi; 27th August 2008 at 02:46 PM.

  5. #5
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    3,017
    Thank Post
    304
    Thanked 288 Times in 200 Posts
    Rep Power
    120

    Re: Mapping Network Drives ?

    what are you trying to do, just map network drives for individuals or user groups?

  6. #6
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    3,017
    Thank Post
    304
    Thanked 288 Times in 200 Posts
    Rep Power
    120

    Re: Mapping Network Drives ?


  7. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,763
    Thank Post
    3,273
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365

    Re: Mapping Network Drives ?

    What I did was put the users I want the mapped drives into an ou and then made it a logon script because there are several mappings that are available and not all the users have all of them , they have specific ones mapped to them dependant upon there needs / requirements.

    So the vbscript does all that.

    That way I dont get the disconnected text in front of the mapping as per the screen shot.

    Will be a work in progress because there is more to do to the script to get it how I want but it works as in it maps the relevant drives and there is no disconnected message in front of the mapping anymore.

  8. #8

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,763
    Thank Post
    3,273
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365

    Re: Mapping Network Drives ?

    ok now I am getting the error message that the drives could not be re connected, yet if you click on the yellow prompt in the system tray or open up my computer the drives that I want mapped are mapped and connected and nothings wrong with it that I can tell.

    Aside from it giving me the error message, how do I get rid of that or why is it telling me that they could not be re connected when they are connected ?

  9. #9

    Join Date
    Sep 2006
    Location
    Essex
    Posts
    781
    Thank Post
    1
    Thanked 32 Times in 30 Posts
    Rep Power
    24

    Re: Mapping Network Drives ?

    Do you have any shortcuts on the desktop that link to files on the network drives? If so, change the shortcuts to point to the UNC path and not the mapped drive letter.

  10. #10

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,763
    Thank Post
    3,273
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365

    Re: Mapping Network Drives ?

    no, only things I have on my desktop are actual files or folders that aren't linked to any unc path or any mapped drives.

    I have assigned the script via a logon script in the user config of GPO on the OU as I clicked on link and create a gpo on the main ou for each group ie marketing has one gpo that has a vbscript assigned as a logon script and internal OU has another one etc.

    I thought it was maybe that I needed to use wscript.sleep 5000 or make it wait longer to give it time to disconnect the mapped drives before hand but that didnt work.

    I also tried enabling slow network connection on the system --> logon of gpo as well as enabling synchronised scripts.

    As per this google article ( aside from the fact that I did it using group policy for the OU and not on the local machine )

    1. Click Start, and click Run.
    2. Type "gpedit.msc" in the text box, and click OK.
    3. Locate the [Computer Configuration\Administrative
    Templates\System\Logon\Always wait for the network at computer startup and
    logon], and select "Enabled", and click OK.
    4. Locate the [User Configuration\Administrative
    Templates\System\Scripts\Run logon scripts synchronously], and select
    "Enabled", and click OK.
    5. Reboot computer to test this issue again.

    found here :

    http://groups.google.co.uk/group/mic...c35b840d00cb2e

SHARE:
+ Post New Thread

Similar Threads

  1. Mapping Home Drives with wierd results
    By sreiach in forum Wireless Networks
    Replies: 12
    Last Post: 11th April 2011, 02:26 PM
  2. mapping drives
    By rjsmith in forum *nix
    Replies: 2
    Last Post: 14th November 2007, 05:42 PM
  3. mapping drives
    By chrbb in forum Wireless Networks
    Replies: 3
    Last Post: 3rd November 2007, 03:18 PM
  4. Network Mapping
    By enjay in forum Network and Classroom Management
    Replies: 17
    Last Post: 14th September 2007, 01:21 PM
  5. Issues with two new Dell PC's mapping drives.
    By tosca925 in forum Wireless Networks
    Replies: 1
    Last Post: 18th January 2007, 12:13 AM

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
  •