+ Post New Thread
Results 1 to 8 of 8
Scripts Thread, Map network drives in Coding and Web Development; i think i got this script off this site, but just need a little help... Code: Const Staff = "cn=staff" ...
  1. #1
    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

    Map network drives

    i think i got this script off this site, but just need a little help...

    Code:
    
    	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"
    
    ' admin settings
    	
    	Const AdminStaff	= "cn=generaladmin"
    	Const OfficeGroup	= "cn=Office Group"
    	
    
    		Set wshnetwork = CreateObject("WScript.Network")
    		Set ADSysInfo = CreateObject("ADSystemInfo")
    		Set CurrentUser = GetObject("LDAP://" & ADSysInfo.Username)
    		strGroups = LCase(Join(CurrentUser.MemberOf))
    
    
    ' general users
    
    			
    
    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"
    
    	
    	If Instr(strGroups,ITAdmin) Then
    In the part between ' general users and the first IF statement is there a string that i can add to remove all network drives apart form U: as this is the users userarea. Ive tried
    Code:
    wshnetwor.Removenetworkconnection <> "u:"
    but that didnt work. Can any one suggest anything??

    Thanks

    T

  2. #2

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: Map network drives

    Missing the letter 'k' before the first dot.


    but seriously what you have written would test the return value ot the removeConnection method agains the string literal "u:"

    I seem to remember that WSH or VBS had a drives collection.

    You could foreach through that and assign each letter to counter variable then remove connections if that variable isn't equal to "u:"

  3. #3
    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: Map network drives

    so something like
    Code:
    wshnetwork.removenetworkdrive <> "u:"
    but i get a syntax error with that <> sign.

    PS, there is a space between for and each lol

  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: Map network drives

    just use a select case so

    Dim drv as string
    drv = Instr(strGroups,staff)
    select case drv

    Case "u:":
    Case Else:
    wshnetwork.removenetworkdrive drv
    End Select

    Assuming that drv is the drive letter that you want removing, that way it wont do nothing to the U drive and will remove the rest, but will check it out later on if that does not work

  5. #5

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: Map network drives

    Quote Originally Posted by gecko
    just use a select case so

    Dim drv as string
    drv = Instr(strGroups,staff)
    select case drv

    Case "u:":
    Case Else:
    wshnetwork.removenetworkdrive drv
    End Select

    Assuming that drv is the drive letter that you want removing, that way it wont do nothing to the U drive and will remove the rest, but will check it out later on if that does not work
    The select case would only remove one drive if it's not u: (in which case it deletes nothing).

    You either have to put the select within a loop or reverse the test and explictly list all the drives you want deleted and then the Case Else will catch anthything that shouldn't be deleted.

  6. #6

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

    Re: Map network drives

    You will need to enumerate all mapped drive something like this

    Code:
    Set clPrinters = objNetwork.EnumPrinterConnections  
    		On Error Resume Next 
    		For i = 0 to clPrinters.Count - 1 Step 2 
    		objNetwork.RemovePrinterConnection clPrinters.Item(i+1), true 
    		Next
    This will delete all mapped drives so you would have to re-map U: after.

  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: Map network drives

    Quote Originally Posted by NetworkGeezer
    Quote Originally Posted by gecko
    just use a select case so

    Dim drv as string
    drv = Instr(strGroups,staff)
    select case drv

    Case "u:":
    Case Else:
    wshnetwork.removenetworkdrive drv
    End Select

    Assuming that drv is the drive letter that you want removing, that way it wont do nothing to the U drive and will remove the rest, but will check it out later on if that does not work
    The select case would only remove one drive if it's not u: (in which case it deletes nothing).

    You either have to put the select within a loop or reverse the test and explictly list all the drives you want deleted and then the Case Else will catch anthything that shouldn't be deleted.
    Yeah I wasnt sure that it would work cos it didnt seem right but I had to run off and carry on with work related stuff so didnt really have a chance to do it correctly.

    Ive just done a mapping network drives script and made a function to do the enumerating of mapped drives and remove them if they are already mapped and then map them etc

    I can post what I have done and you can just alter it to your needs , if thats of any use ?

  8. #8

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: Map network drives

    Tim has probably moved on to other things but post it none the less it might be useful to somebody as we getting all these new users.

SHARE:
+ Post New Thread

Similar Threads

  1. Hide mapped network drives
    By timbo343 in forum Windows
    Replies: 11
    Last Post: 2nd April 2012, 09:06 AM
  2. Map network drives on wireless network
    By woody in forum Windows
    Replies: 24
    Last Post: 1st December 2007, 06:27 PM
  3. Replies: 5
    Last Post: 26th November 2007, 06:40 PM
  4. Map network drives
    By netadmin in forum Scripts
    Replies: 17
    Last Post: 5th April 2007, 03:18 PM
  5. Mapping Network Drives ?
    By mac_shinobi in forum Scripts
    Replies: 9
    Last Post: 8th March 2007, 03:49 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
  •