WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Remove User from Printer Object

 Keywords: Remove Delete User Group Printer Object AD Active Directory ADSI

AddExtender("WWADS44I.DLL")
; Domain to search.
; (Could be the path to your OU.)
sAdsiPath = "LDAP://sample"

; Get all Domain printers
sSearch   = "(&(objectCategory=PrintQueue)(objectClass=printQueue))"
lPrinters = dsFindPath(sAdsiPath,  sSearch)

; Display the result.
sPrinterPath = AskItemlist("Printers", lPrinters, @TAB, @UNSORTED, @SINGLE)

sUser = "Mydomain\Myuser"    ; MODIFY TO FIT YOUR NEEDS

sPropertyName = "ntSecurityDescriptor"

;Get theSD and DACL
sd = dsGetProperty(sPrinterPath, sPropertyName)
acl = dsGetSecProp(sd, "DiscretionaryAcl")

; Get the number of ace in acl
Aces = dsAclGetAces(acl, 1)
n = ItemCount(Aces, @TAB)

For i=1 To n
   ace = ItemExtract(i, Aces, @TAB)
   trustee = dsGetSecProp(ace, "Trustee")
   Acetype = dsGetSecProp(ace, "AceType")
   Pause('Property values of security objects', "Trustee: " : trustee : @LF : "AceType: " : acetype )

   ; REMOVE ACE - Only if it's our user and it is an allow ACE.
   If StriCmp(trustee, sUser) == 0 && Acetype == 0
      ret = AskYesNo( 'Remove ACE?', 'Are you sure you want to remove?') )
      If ret == @YES Then dsAclRemAce(acl, ace)
   EndIf
Next

; Place the SD back in the object.
dsSetSecProp(sd, "DiscretionaryAcl", acl)
dsSetProperty(sPrinterPath, sPropertyName, sd)

Article ID:   W17552
Filename:   REmove User from Printer Object.txt
File Created: 2010:12:16:10:02:20
Last Updated: 2010:12:16:10:02:20