Page 4 of 4 <1234
Topic Options
#46735 - 2003-10-23 09:22 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: Lincoln, NE
My computer has the following printers:

q-mis2-color on MRH-01 (set as default)
q-mis2 on MRH-01

My groups indicate that q-mis2 on MRH-01 is actually the default. This script should change the q-mis2 printer to be default but does not.

I return the status to the screen and q-mis2 is the default printer returned based upon group membership and 2 is returned as the PriMapState.

This $rc<>2 should return a 1 as
q-mis2 is installed, but not as default q-mis2-color is default. It should then set q-mis2 as default.

code:
$rc=PriMapState("\\" + $defprinter)
? $defprinter
? $rc
if $rc<>2
$nul=SetDefaultPrinter("\\" + $defprinter)
? "Status - Default Printer set \\" + $defprinter
? @serror ?
else
exit 0
endif



[ 23. October 2003, 21:34: Message edited by: tjcarst ]

Top
#46736 - 2003-10-23 09:37 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: Lincoln, NE
Found it. I was bitten by the 21 character lenght of the printer group name.

Now I will have to figure out a new naming scheme for printer groups and redo my scripts.

D = default
MRH-01 = server name
q-mis2-color = printer share

D_MRH-01_q-mis2-color

tjcarst

Top
#46737 - 2003-10-23 09:44 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: Lincoln, NE
Considering following print group names. This is the longest printer name I have:

D01_q-research-color

D = Default printer
01 = First print server, in my case MRH-01
q-research-color = printer share

tjcarst

Top
#46738 - 2003-10-23 10:31 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: Lincoln, NE
Okay I have re-created the printer groups after modifying the script. I now have updated the script that maps the printers based upon the printer groups.

I would like to know if there is a way to map the printer group name code to a server name without re-writing this code for each combination. An Array? This would remove the hard coded A01, PS1, in my script.

For example print server names

PS1=MRH-01
PS2=MRH-02

Printer group names

D01=Default printer on PS1
D02=Default printer on PS2
A01=Default printer on PS1
A02=Default printer on PS2

etc.

code:
call @ScriptDir+'\PriMapState.udf'

;********** Prevent script from running on a server or Win95*********
if @userid = administrator
call @Scriptdir+'\osid.udf'
$os=osid()
if $os[1]='Win95' or $os[2]<>'Workstation'
exit 0
endif
endif

;********** Prevent script from running on Medrec pcs *********
if InGroup ("Medrec Group")
exit 0
endif

;********** Beginning of printer mapping *********
$WS = GetObject("WinNT://" + @domain + "/" + @wksta + "$$")

if @error
? @serror
else

$ps1="mrh-01"


for each $grp In $WS.Groups
$GrpName = $grp.Name

;--- Add and set default printer ---

if left($GrpName,4) = "D01_"
$defprinter = substr($GrpName,5)
$defprinter = $ps1+"\"+$defprinter
$defprinter = "\\" + $defprinter
? "Default Printer: "$defprinter

if not PriMapState($defprinter)
? "Status - Printer not connected "+$defprinter
$nul=AddPrinterConnection($defprinter)
? "Status: Printer added "+ $defprinter
? @serror ?

$nul=SetDefaultPrinter($defprinter)
? "Status: Default Printer set " +$defprinter
? @serror ?
endif

if PriMapState($defprinter)<>2
; $rc=PriMapState($defprinter)
; ? $rc
; if $rc<>2
$nul=SetDefaultPrinter($defprinter)
? "Status: Default Printer set " + $defprinter
? @serror ?
else
exit 0
endif

endif

endif


;--- Add additional printers ---

if left($GrpName,4) = "A01_"
$addlprinter = substr($GrpName,5)
$addlprinter = $ps1+"\"+$addlprinter
$addlprinter = "\\"+$addlprinter
? "Additional printer(s): "$addlprinter

if not PriMapState($addlprinter)
? "Status: Printer not connected " + $addlprinter
$S=AddPrinterConnection($addlprinter)
? "Status: Printer added " + $addlprinter
? @serror ?
endif

endif

next

endif



[ 27. October 2003, 18:28: Message edited by: tjcarst ]

Top
#46739 - 2003-10-24 09:44 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: Lincoln, NE
Another problem arose.

I have the following printers

\\mrh-01\q-mis2
\\mrh-01\q-mis2-color
\\mrh-01\q-research-color

Assigned to the following printer groups
D01_q-mis2
A01_q-mis2-color
A01_q-research-color

Using the script posted above, if I set the color printer to default in my computer to test if the script correctly catches the wrong printer is default and changes to q-mis2, it fails to do so.

However, if I set it in my computer to q-research-color, it correctly sets the default back to q-mis2.

Is there a problem because the two mis2 printers start with the same name and have another dash in them? It isn't the length.

q-mis2
q-mis2-color

tjcarst

[ 27. October 2003, 18:03: Message edited by: tjcarst ]

Top
#46740 - 2003-10-27 06:02 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: Lincoln, NE
I am still stuck on this one. Any ideas?

Default printer group D01_q-mis2-color
Actual printer set as default on pc q-mis2-color (to test if script detects and sets to q-mis2)

When I return the value of Primapstate, it returns a value of 2. Even though the default printer is not set correctly.

I have q-mis2-color set as the default, yet my group membership sets q-mis2 as the default printer.

If I change the default printer in control panel, printers, to q-mis1, the group membership correctly sets q-mis2 as the default printer.

What's up with q-mis2-color?

Top
#46741 - 2003-10-27 08:00 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: Lincoln, NE
PriMapState returns incorrect value if based upon registry entry for default printer.

Script I am running:
code:
;********** Prevent script from running for administrator on a server or Win95*********
if @userid = administrator
call @Scriptdir+'\osid.udf'
$os=osid()
if $os[1]='Win95' or $os[2]<>'Workstation'
exit 0
endif
endif

;********** Prevent script from running on Medrec pcs *********
if InGroup ("Medrec Group")
exit 0
endif

;********** Beginning of printer mapping *********
$WS = GetObject("WinNT://" + @domain + "/" + @wksta + "$$")

if @error
? @serror
else

$ps1="mrh-01"

for each $grp In $WS.Groups
$GrpName = $grp.Name

;--- Add additional printers ---

if left($GrpName,4) = "A01_"
$addlprinter = substr($GrpName,5)
$addlprinter = $ps1+"\"+$addlprinter
$addlprinter = "\\"+$addlprinter
? "Additional Printer(s): "$addlprinter

if not PriMapState($addlprinter)
? "Status: Printer not connected " + $addlprinter
$S=AddPrinterConnection($addlprinter)
? "Status: Printer added " + $addlprinter
? @serror ?
endif

endif

; next

;--- Add and set default printer ---

if left($GrpName,4) = "D01_"
$defprinter = substr($GrpName,5)
$defprinter = $ps1+"\"+$defprinter
$defprinter = "\\" + $defprinter
? "Default Printer from computer group membership: "$defprinter
? $def=readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device")
? "Default printer in registry: "$def
?

if not PriMapState($defprinter)
? "Status - Printer not connected "+$defprinter
$nul=AddPrinterConnection($defprinter)
? "Status: Printer added "+ $defprinter
? @serror ?
$nul=SetDefaultPrinter($defprinter)
? "Status: Default Printer set " +$defprinter
? @serror ?
endif


$rc=PriMapState($defprinter) ; if PriMapState($defprinter)<>2
? "Value returned by PriMapState: "$rc
?
if $rc=1
$nul=SetDefaultPrinter($defprinter)
? "Status: Default Printer set " + $defprinter
? @serror ?

endif ; endif

endif

next

;end


;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

Results of above script at command prompt:
----------------------------------
W:\>kix32 printers

Default Printer from computer group membership: \\mrh-01\q-mis2

Default printer in registry: \\mrh-01\q-mis2-color,winspool,Ne03:

Value returned by PriMapState: 2

Additional Printer(s): \\mrh-01\q-research
Additional Printer(s): \\mrh-01\q-research-color
Additional Printer(s): \\mrh-01\q-mis1
Additional Printer(s): \\mrh-01\q-mis2-color
W:\>
----------------------------------
tjcarst

Top
Page 4 of 4 <1234


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 131 anonymous users online.
Newest Members
dimi575, Drecksnacken, Nlill, webtools321, multiman
17734 Registered Users

Generated in 0.033 seconds in which 0.014 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org