Page 1 of 2 12>
Topic Options
#203814 - 2011-11-21 06:24 PM printer problem..
cividan Offline
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:

 Code:
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:
 Code:
;================================================
;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
#203815 - 2011-11-21 06:42 PM Re: printer problem.. [Re: cividan]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Are your printers named the same as their share names?
Top
#203816 - 2011-11-21 07:33 PM Re: printer problem.. [Re: ShaneEP]
cividan Offline
Fresh Scripter

Registered: 2011-11-18
Posts: 25
Loc: Quebec, Canada
Thanks for the hint, sometimes little thing can screw the bigger one for small detail. Setting the share name EXACTLY the same as the printer name fixed the problem.
Top
#203817 - 2011-11-21 07:51 PM Re: printer problem.. [Re: cividan]
cividan Offline
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.

 Code:
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 Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Try this...

 Code:
if primapstate("\\server\HP LaserJet P4014 PCL6")
	$RC=delprinterconnection("\\server\HP LaserJet P4014/P4015 PCL6")
Endif

Top
#203819 - 2011-11-21 09:20 PM Re: printer problem.. [Re: ShaneEP]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm... I might be asking silly here, but wouldn't you remove the connection to the share and not the printer?

did not test and dont remember... so, just a thought.
_________________________
!

download KiXnet

Top
#203820 - 2011-11-21 09:26 PM Re: printer problem.. [Re: Lonkero]
ShaneEP Moderator Offline
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.

 Code:
If primapstate("\\server\HP LaserJet P4014 PCL6")
   $RC=delprinterconnection("\\server\HP LaserJet P4014/P4015 PCL6")
Endif
or
 Code:
If primapstate("\\server\HP LaserJet P4014 PCL6")
   $RC=delprinterconnection("\\server\HP LaserJet P4014 PCL6")
Endif

Top
#203821 - 2011-11-21 09:37 PM Re: printer problem.. [Re: ShaneEP]
cividan Offline
Fresh Scripter

Registered: 2011-11-18
Posts: 25
Loc: Quebec, Canada
edit: nvm I put my preference to flat mode so I dont double post.

Edited by cividan (2011-11-21 09:46 PM)

Top
#203823 - 2011-11-21 09:39 PM Re: printer problem.. [Re: ShaneEP]
cividan Offline
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.


 Code:
? "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 Moderator Offline
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.

 Code:
? "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 Offline
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:
 Code:
? "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 Moderator Offline
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?

 Code:
   $RC=delprinterconnection("\\server\HP LaserJet P4014 PCL6")
   ? "result: "+@Error+" - "+@SError

   $RC=delprinterconnection("\\server\HP LaserJet P4014/P4015 PCL6")
   ? "result 2: "+@Error+" - "+@SError

Top
#203827 - 2011-11-22 06:27 PM Re: printer problem.. [Re: ShaneEP]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4563
Loc: USA
This sounds vaguely familiar to a post a few weeks ago... see the last post.

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=203377#Post203377

I wonder if something is up with primapstate.

Top
#203828 - 2011-11-22 06:37 PM Re: printer problem.. [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Thats what Im thinking, just wanted to make sure by deleting them straight forward. Probably a new registry key or something for Windows7.
Top
#203829 - 2011-11-22 09:44 PM Re: printer problem.. [Re: ShaneEP]
cividan Offline
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
#203830 - 2011-11-22 09:45 PM Re: printer problem.. [Re: ShaneEP]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmmm....

nope. windows 7 seems to work just the same.
what matters is the printer port-name in:
key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\printerNAME
value: port

if the printer is mapped via ip or something.
anyways, I don't have connected printers with unc map, I can't see how they show up.
_________________________
!

download KiXnet

Top
#203831 - 2011-11-22 10:07 PM Re: printer problem.. [Re: Lonkero]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
I have a printer connected by unc and it does not show up in that registry key at all. And I'm using WinXP Home.
Top
#203832 - 2011-11-22 10:12 PM Re: printer problem.. [Re: cividan]
cividan Offline
Fresh Scripter

Registered: 2011-11-18
Posts: 25
Loc: Quebec, Canada
More information if it can help, when I look in my registry under:

"HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices"

I see this key for my printer with the wrong share name:

\\server\HP LaserJet P4014/P4015 PCL6

the value on that key is: winspool,Ne03:

under "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"

the key has this value: \\server\HP LaserJet P4014/P4015 PCL6,winspool,Ne03:

since it's a network printer on the current user it's not listed under

"HKLM\System\CurrentControlSet\control\Print\Printers"


Edit: forgot to mention in my first post that the printer gets deleted from the code with the share name not the printer name.


Edit 2: the printer gets deleted from both code depending on wich one I put first in the script.


Edited by cividan (2011-11-22 10:32 PM)

Top
#203833 - 2011-11-22 10:27 PM Re: printer problem.. [Re: cividan]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
just to make sure, the value or the key?
primapstate does not care about the key-name, just the port value.
_________________________
!

download KiXnet

Top
#203834 - 2011-11-22 10:30 PM Re: printer problem.. [Re: Lonkero]
cividan Offline
Fresh Scripter

Registered: 2011-11-18
Posts: 25
Loc: Quebec, Canada
I don't know wich key you speak of but I listed the value for all the key where my printer appear.
I just changed my post to put the value in red, the key name is underlined.


Edited by cividan (2011-11-22 10:31 PM)

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 1179 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.077 seconds in which 0.027 seconds were spent on a total of 14 queries. Zlib compression enabled.

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