;DFS Network Drive Mappings
If InGroup("Domain Users")
Use * /delete /persistent
Use z: "\\domain.local\Shared$\Users\%username%" /persistent
EndIf
If InGroup("Executive")
Use j: "\\domain.local\Shared$\Executive" /persistent
EndIf
If InGroup("Operations")
Use k: "\\domain.local\Shared$\Operations" /persistent
EndIf
If InGroup("Finance")
Use l: "\\domain.local\Shared$\Finance" /persistent
EndIf
If InGroup("Technology")
Use m: "\\domain.local\Shared$\Technology" /persistent
EndIf
If InGroup("Sales")
Use n: "\\domain.local\Shared$\Sales" /persistent
EndIf
If InGroup("Editorial")
Use o: "\\domain.local\Shared$\Editorial" /persistent
EndIf
If InGroup("Marketing")
Use p: "\\domain.local\Shared$\Marketing" /persistent
EndIf
:Exit
;Delete all Network Printers Only -- Local Printers will not be deleted
$key = "HKEY_CURRENT_USER\Printers\Connections"
$printers = ArrayEnumKey($key)
For Each $printer in $printers
$rc = DelKey($key + "\" + $printer)
Next
Function arrayenumkey($regsubkey)
Dim $retcode, $subkeycounter, $currentsubkey, $subkeyarray
If Not KeyExist($regsubkey)
Exit 87
EndIf
$subkeycounter=0
Do
$currentsubkey=EnumKey($regsubkey,$subkeycounter)
If Not @ERROR
ReDim preserve $subkeyarray[$subkeycounter]
$subkeyarray[$subkeycounter]=$currentsubkey
$subkeycounter=$subkeycounter+1
EndIf
Until @ERROR
$arrayenumkey=$subkeyarray
Exit 0
EndFunction
:Exit
;Get Default Printer
function GetDefaultPrinter()
$GetDefaultPrinter = join(split(readvalue("HKEY_USERS\"+@sid+"\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
endfunction
; Make Printer List
Function PrinterList(optional $remotepc, optional $displaymode)
dim $service,$printer,$printers,$printerdesc[0],$counter,$portname,$printername
if $remotepc=""
$remotepc="."
endif
$Service = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
if @error
exit @error
endif
$Printers=$service.execquery ('select * from Win32_Printer')
for each $printer in $printers
redim preserve $printerdesc[$counter]
if $displaymode & 1
$portname = "," + $printer.portname
endif
select
case $displaymode & 4 ;remote printers
if left($printer.portname,2)="\\" or left($printer.name,2)=="\\"
$printername=$printer.name
endif
case $displaymode & 2 ;local printers
if left($printer.portname,2)<>"\\" and left($printer.name,2)<>"\\"
$printername=$printer.name
endif
case 1 ; all printers
$printername=$printer.name
endselect
if $printername<>""
$printerdesc[$counter]=$printername + $portname
$counter=$counter + 1
$printername=""
endif
next
$PrinterList=$printerdesc
endfunction
for each $printer in printerlist(,2)
if $printer=getdefaultprinter()
$localdefault=1
endif
next
;Map and Set Printer per Room #
If InGroup("P1005") = 1 "Mapping Network Printers"
$RC=addprinterconnection("\\dc01\Printer 1005")
if $localdefault<>1
$RC=SetDefaultPrinter("\\dc01\Printer 1005")
endif
EndIf
If InGroup("P1013") = 1 "Mapping Network Printers"
$RC=addprinterconnection("\\dc01\Printer 1013")
if $localdefault<>1
$RC=SetDefaultPrinter("\\dc01\Printer 1013")
endif
EndIf
If InGroup("P1021") = 1 "Mapping Network Printers"
$RC=addprinterconnection("\\dc01\Printer 1021")
if $localdefault<>1
$RC=SetDefaultPrinter("\\dc01\Printer 1021")
endif
EndIf
If InGroup("P1029") = 1 "Mapping Network Printers"
$RC=addprinterconnection("\\dc01\Printer 1029")
if $localdefault<>1
$RC=SetDefaultPrinter("\\dc01\Printer 1029")
endif
EndIf
If InGroup("P1031") = 1 "Mapping Network Printers"
$RC=addprinterconnection("\\dc01\Printer 1031")
if $localdefault<>1
$RC=SetDefaultPrinter("\\dc01\Printer 1031")
endif
EndIf
:Exit
; All Printers for all rooms
If InGroup("All Printers") = 1 "Mapping Network Printers"
$RC=addprinterconnection("\\dc01\Printer 1005")
$RC=addprinterconnection("\\dc01\Printer 1013")
$RC=addprinterconnection("\\dc01\Printer 1021")
$RC=addprinterconnection("\\dc01\Printer 1029")
$RC=addprinterconnection("\\dc01\Printer 1031")
EndIf
:Exit