#203814 - 2011-11-21 06:24 PM
printer problem..
|
cividan
Fresh Scripter
Registered: 2011-11-18
Posts: 25
Loc: Quebec, Canada
|
Hi all, I'm new to scripting but I read around a bit and now I have a problem with the printers part of my login script, I even set event logging to see and track what is going on but I can't figure out why it doesn't work. My problem are listed after my script. So here is the printer part of my script:
If InGroup("domain users")
if not primapstate("\\server\HP LaserJet P4014P4015 PCL6")
ADDPRINTERCONNECTION ("\\server\HP LaserJet P4014P4015 PCL6")
Else ? "HP 4014 exist"
$RC = LogEvent( 4 , 1 , "HP P4014P4015 exist")
EndIf
if not primapstate("\\server\HP LaserJet M3035 mfp PCL6")
ADDPRINTERCONNECTION ("\\server\HP LaserJet M3035 mfp PCL6")
Else ? "HP 3035 MFP exist"
$RC = LogEvent( 4 , 1 , "HP M3035 exist")
EndIf
if not primapstate("\\server\HP LaserJet P4014 PCL 6 - letter only")
ADDPRINTERCONNECTION ("\\server\HP LaserJet P4014 PCL 6 - letter only")
Else ? "HP 4014-letter only exist"
$RC = LogEvent( 4 , 1 , "HP P4014 letter only exist")
EndIf
EndIf
If InGroup("Default_printer_hp_mfp3035")
SETDEFAULTPRINTER ("\\server\HP LaserJet M3035 mfp PCL6")
$RC = LogEvent( 4 , 1 , "HP M3035 set as default printer")
EndIf
sleep 4
If InGroup("default_CSR_printer_letter_only")
SETDEFAULTPRINTER ("\\server\HP LaserJet P4014 PCL 6 - letter only")
$RC = LogEvent( 4 , 1 , "HP4014 letter only set as default printer")
EndIf
the primapstate function is defined in the end of the script.
First problem I have is this:
I log on the computer with a user who is member of the default_csr printer group, now what I get when no printer are already installed, my 3 printer get installed then I see the default printer being defined as the HP mfp but the default printer doesn't switch to HP 4014 letter only even if the script goes into it as I get into the event log the message I set in the scrip that the 4014 letter only is set as default printer but the actual default printer never change. I see a couple of zero in my screen then I think I see a 2 just before the script window close( it goes fast at that point). I even added a sleep time between the 2 default printer command in case that was the problem but it didn't help.
Second problem I have is when all printer already exist in the computer, I see in my event log only the "HP mfp 3035 exist" message so the script does not recognize the primapstate for the other 2 printers. And again I see the message for the default printer change that also doesnt get changed to the HPO4014 - letter only. Any advice would be welcome.
Edit: forgot to mention my client are win 7 machine and server is 2008 R2 in case that matter. Also I'm using kixStart 4.62.
I guess I should also post my primapstate function so here it is:
;================================================
;Define udf function here
;================================================
;FUNCTION PriMapState
;AUTHOR Lonkero (Jooel.Nieminen@gwspikval.com)
;ACTION Checks for existent networkprinter connection
;VERSION 1.1.1
;SYNTAX PriMapState(PRINTER)
;PARAMETERS PRINTER
; to be checked Printer's name
;
;RETURNS 1 if printer connected
; 2 if printer is default
; nothing if not connected
;EXAMPLE
; if not PriMapState('\\server\printer1')
; "printer1 not connected!"
; endif
;
;CODE
function PriMapState($_Pri)
if @inwin=1
if len(readvalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri))
if split(readvalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]=$_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
Edited by cividan (2011-11-21 06:31 PM)
|
|
Top
|
|
|
|
#203817 - 2011-11-21 07:51 PM
Re: printer problem..
[Re: cividan]
|
cividan
Fresh Scripter
Registered: 2011-11-18
Posts: 25
Loc: Quebec, Canada
|
One more question, how would I delete the old printer that has a different name than the share name, I tried putting the printer name on the remove line but it doesnt work either.
if primapstate("\\server\HP LaserJet P4014 PCL6")
$RC=delprinterconnection("HP LaserJet P4014/P4015 PCL6")
Endif
The share name is: "\\server\HP LaserJet P4014 PCL6" and the printer name is: "HP LaserJet P4014/P4015 PCL6"
|
|
Top
|
|
|
|
#203818 - 2011-11-21 08:47 PM
Re: printer problem..
[Re: cividan]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Try this...
if primapstate("\\server\HP LaserJet P4014 PCL6")
$RC=delprinterconnection("\\server\HP LaserJet P4014/P4015 PCL6")
Endif
|
|
Top
|
|
|
|
#203820 - 2011-11-21 09:26 PM
Re: printer problem..
[Re: Lonkero]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Honestly I don't remember either. I thought by his wording that he had tried the share, but I may have just misread it. Is the SetDefaultPrinter() the only printer function that uses the printer name? And AddPrinterConnection() /DelPrinterConnection() uses share name? Either way, one of the below should work I would think.
If primapstate("\\server\HP LaserJet P4014 PCL6")
$RC=delprinterconnection("\\server\HP LaserJet P4014/P4015 PCL6")
Endif orIf primapstate("\\server\HP LaserJet P4014 PCL6")
$RC=delprinterconnection("\\server\HP LaserJet P4014 PCL6")
Endif
|
|
Top
|
|
|
|
#203823 - 2011-11-21 09:39 PM
Re: printer problem..
[Re: ShaneEP]
|
cividan
Fresh Scripter
Registered: 2011-11-18
Posts: 25
Loc: Quebec, Canada
|
I had tried the share string before and both of the option dont delete the printer.
? "check if printer on server exist"
if primapstate("\\server\HP LaserJet P4014 PCL6") > 0
$RC=delprinterconnection("\\server\HP LaserJet P4014 PCL6")
? "HP 4014/4015 on server deleted"
Else ? "printer not found"
? @error
EndIf
? "check if printer on server exist check 2"
if primapstate("\\server\HP LaserJet P4014 PCL6")
$RC=delprinterconnection("\\server\HP LaserJet P4014/P4015 PCL6")
? "HP 4014/4015 on server deleted"
Else ? "printer not found on check 2"
? @error
Endif
Edited by cividan (2011-11-21 09:47 PM)
|
|
Top
|
|
|
|
#203824 - 2011-11-21 10:31 PM
Re: printer problem..
[Re: cividan]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Try adding the below code to see what error it is giving you on the "result: ..." line.
? "checking if printer on server exist"
If primapstate("\\server\HP LaserJet P4014 PCL6") > 0
$RC=delprinterconnection("\\server\HP LaserJet P4014 PCL6")
? "result: "+@Error+" - "+@SError
Else
? "printer not found"
EndIf
? "checking if printer on server exist check 2"
If primapstate("\\server\HP LaserJet P4014 PCL6")
$RC=delprinterconnection("\\server\HP LaserJet P4014/P4015 PCL6")
? "result 2: "+@Error+" - "+@SError
Else
? "printer not found on check 2"
Endif
|
|
Top
|
|
|
|
#203825 - 2011-11-22 03:27 PM
Re: printer problem..
[Re: ShaneEP]
|
cividan
Fresh Scripter
Registered: 2011-11-18
Posts: 25
Loc: Quebec, Canada
|
it doesn't even go into that part of the code, the primapstate return false and goes into the else part and I see on screen both message of printer not found. The printer is really on my computer... I even tried this way and still end up with printer not found:
? "checking if printer on server exist check 2"
If primapstate("\\server\HP LaserJet P4014/P4015 PCL6")
$RC=delprinterconnection("\\server\HP LaserJet P4014/P4015 PCL6")
? "result 2: "+@Error+" - "+@SError
Else
? "printer not found on check 2"
Endif any more suggestion welcome
|
|
Top
|
|
|
|
#203826 - 2011-11-22 06:18 PM
Re: printer problem..
[Re: cividan]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
What error do you get if you try to delete it without checking first?
$RC=delprinterconnection("\\server\HP LaserJet P4014 PCL6")
? "result: "+@Error+" - "+@SError
$RC=delprinterconnection("\\server\HP LaserJet P4014/P4015 PCL6")
? "result 2: "+@Error+" - "+@SError
|
|
Top
|
|
|
|
#203829 - 2011-11-22 09:44 PM
Re: printer problem..
[Re: ShaneEP]
|
cividan
Fresh Scripter
Registered: 2011-11-18
Posts: 25
Loc: Quebec, Canada
|
I had looked at that thread before and that's where I got the hint to use primapstate. Now for the result: if I bypass the primapstate check the printer gets deleted. So I guess primapstate doesn't like the fact that the printer have a different share name than the printer name. I did some further test with the printer name changed to match the share name and the exact same code works when the printer name is exactly the same as the share name. So I guess I will have to forget the primapstate to delete the old printer unless anyone have an idea how to fix the primapstate function
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 774 anonymous users online.
|
|
|