Mapping printers on Computer Group Membership

Here is an example on how to use the group membership for a computer to control Default Printer

; Mapping Printers

; Deleting printers
$result=DelTree("HKEY_CURRENT_USERPrintersconnections")
; Adding Printers
$result=ADDPRINTERCONNECTION ("\Server01Printer1") 
$result=ADDPRINTERCONNECTION ("\Server01Printer2")
AT (16,21) "Setting default Printer...        "
If ComputerInGroup ("Group1") = 1 
    $ = SetDefaultPrinter ("\Server01Printer1")
EndIf
If ComputerInGroup ("Group2") = 1 
    $ = SetDefaultPrinter ("\Server01Printer2")
EndIf

; ***** UDF ComputerInGroup *****
Function ComputerInGroup($group,optional $Domain) 
   Dim $oGrp
   if not $domain $domain=@domain endif
   $oGrp = GetObject("WinNT://" + $domain + "/" + $group + ",group" )
   if @error exit 1 endif
   if $oGrp.IsMember("WinNT://" + $domain + "/" + @wksta + "$$" )
      $ComputerInGroup=1
   else
      $ComputerInGroup=0
   endif
endfunction

Links

http://www.adminscripteditor.com/forum/tm.asp?m=10925

Comments

Leave a Reply

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)