squirrelc0de

Deleting persistant drives

7 posts in this topic

#1 ·  Posted

Hi there, 

I have been racking my brain about how to get persitent drives to delete with a login script. My scenario is that Say a user is added to a network drive and its mapped persistently. If that user is moved out of that AD security group i want a piece of code to delete and remove the previously mapped persistent drive. 

I cant seem to get the sequence right for removing the drive, and thats what i need help with. 
Heres my code: 
 

#include <AD\AD.au3>

func mapdrives()
    _AD_Open()
if _AD_IsMemberOf("Security Group") Then
        MapDrive()
   EndIf

    _AD_Close()
EndFunc

;map drive functions
Func MapDrive()
    DriveMapDel("Q:")
    DriveMapAdd("Q:","\\server\mapdrive",$DMA_PERSISTENT)
 EndFunc

Do i need to add in a different else statement for drivemapdel to clear off the old persistent drive?

Share this post


Link to post
Share on other sites



#2 ·  Posted

Something like this?:

#include <AD\AD.au3>

Func mapdrives()
    _AD_Open()
    If _AD_IsMemberOf("Security Group") Then
        MapDrive($DMA_PERSISTENT)
    Else
        MapDrive($DMA_DEFAULT)
    EndIf

    _AD_Close()
EndFunc   ;==>mapdrives

;map drive functions
Func MapDrive($opt)
    DriveMapDel("Q:")
    DriveMapAdd("Q:", "\\server\mapdrive", $opt)
EndFunc   ;==>MapDrive

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted

Hi there, 

I tried that and that doesn't seem to delete the drive mapping. I've taken a test account out of the group and the mapped drive still shows up. 
Any other Ideas? 

Share this post


Link to post
Share on other sites

#4 ·  Posted

Try changing:

MapDrive($DMA_DEFAULT)

To

DriveMapDel("Q:")

Share this post


Link to post
Share on other sites

#5 ·  Posted

Hi there, So i have a couple of drives that dont want to map. I have the same code for 7 drives and 2 just dont want to map.  The script says its mapping them, but they dont show up. 

My user accounts have access to the shares but they dont show up in explorer. What could i possibly be doing wrong if all the other drives work but 2 dont map?

Thanks

Share this post


Link to post
Share on other sites

#6 ·  Posted

Hi there, 

I have a question as to how the drivemapdel and drivemapadd works. I am trying to remove a drive after setting it as persistent. When I added an else statement to delete a mapped drive after a user is removed out of an AD group, it seemed to remove the mapped drive even if a user was in a group. 

Could someone point out what i am doing wrong? 

#include <AD\AD.au3>

_AD_open()

if _AD_IsMemberOf("Security Group") Then
        MapDrive()
        Else
        DriveMapDel("T:")
   EndIf

    _AD_Close()
EndFunc

Func MapDrive()
    DriveMapDel("T:")
    DriveMapAdd("T:","\\server\fileshare",1)
Endfunc

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

It might be a timing issue.  You could try inserting a sleep delay between the DriveMapDel and DriveMapAdd functions.  

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now