I eventually want to get it to the point that it does not run on a server and Win95 (setdefaltprinter and addprinter do not run). I also want it to check the current state of the printer and map if not map, and set default if already mapped. Do nothing if mapped and default.
So, using the previous posted script that I still am working on:
code:
;********** Prevent script from running on servers and Win95 *********
If not instr(@producttype,'Workstation') and not
instr(@producttype,'Professional') and not
instr(@producttype,'95')
quit
endif
;********** Beginning of printer mapping *********
$WS = GetObject("WinNT://" + @domain + "/" + @wksta + "$$")
if @error
? @serror
else
for each $grp In $WS.Groups
$GrpName = $grp.Name
if left($GrpName,8) = "Printer_"
$printer = substr($GrpName,9)
$printer = join(split($printer,"_"),"\")
if not PriMapState("\\" + $printer")
? "Status - Printer not connected"
? @serror
$S=AddPrinterConnection("\\" + $printer)
endif
if PriMapState("\\" + $printer)
$S=SetDefaultPrinter ("\\" + $printer)
? "Status - Default Printer set"
? @serror
endif
endif
next
endif
;********** Beginning of Function *********
;FUNCTION PriMapState v1.1
;
;AUTHOR Lonkero (Jooel.Nieminen@gwspikval.com)
;
;ACTION Checks for existent networkprinter connection
;
;SYNTAX PriMapState(PRINTER)
;
;PARAMETERS PRINTER
; Printers name to be checked
;
;RETURNS 1 if printer connected
; 2 if printer is default
; nothing if not connected
;
;REMARKS code for w9x adapted from BrianTX
;
;DEPENDENCIES none
;
;EXAMPLE if not PriMapState('\\server\printer1')
; "printer not connected!"
; endif
;
;CODE
function PriMapState($_Pri)
if @inwin=1
if len(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows
NT\CurrentVersion\Devices",$_Pri))
if instr(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows
NT\CurrentVersion\Windows","Device"),$_Pri)
$PriMapState=2
else
$PriMapState=1
endif
endif
else
dim $_Root,$_C,$_C2 $_Root="HKLM\System\CurrentControlSet\control\Print\Printers"
for $_C=0 to 259
$_C2=enumkey($_Root,$_C)
If instr(READVALUE($_Root+"\"+$_C2,"Port"),$_Pri)
If instr(READPROFILESTRING("%windir%\win.ini","windows","device"),$_Pri)
$PriMapState = 2
Else
$PriMapState = 1
Endif
Endif
if $_C2=259 $_C=$_C2 endif
next
endif
endfunction
[ 09. October 2003, 05:07: Message edited by: tjcarst ]