Jump to content

Deleting persistant drives


Recommended Posts

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?

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...