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)