MikeKrausnick
(Just in Town)
2017-10-18 10:43 PM
Determine if specific network printer is mapped on workstation

I am moving all server print queues to a new print server. I read some threads here about that which refer to primapstate(). I tried this code:

 Code:
if primapstate("\\MyServer\Konica Bizhub C554E")
  ? "Printer Exists"
else
  ? "Printer does not exist"
endif


I tried the same thing with "PrinterConnection". Same result.


It returns the printer name supplied and "Printer Exists" no matter what I put in the string. My server is not named "MyServer" and it still displayed "Printer Exists".

Other posts indicate this is possible, so I must be missing something. Thoughts?


AllenAdministrator
(KiX Supporter)
2017-10-18 11:01 PM
Re: Determine if specific network printer is mapped on workstation

I basically stole the primapstate code and added a bunch of other functionality to a new function call printerconnection. It really couldn't be easier to move network printer servers. I did this for one of my customers where I had an INI file that read the old name, looked for it, if it found it, read the new name, and then removed and reconnected. The printerconnection function also has the ability to determine if the printer is the default.

See the examples and if you need any help, post your code.

PrinterConnection() -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=203840#Post203840

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1




Mart
(KiX Supporter)
2017-10-19 09:21 AM
Re: Determine if specific network printer is mapped on workstation

Just tried your code and it works fine for me.
The only thing I did is add the PriMapState() UDF. Without the UDF I get the same incorrect results. When using a UDF it should always be included or called.

 Code:
Break on

If primapstate("\\MyServer\Konica Bizhub C554E")
	? "Printer Exists"
Else
	? "Printer does not exist"
EndIf

Sleep 5


;FUNCTION	PriMapState 
; 
;AUTHOR		Lonkero (Jooel.Nieminen@gwspikval.com) 
; 
;ACTION		Checks for existent networkprinter connection 
; 
;VERSION	1.1.1 
; 
;CHANGES	1.1.1	- 01. november 2003 
;		 Fixed buggie descriped in: 
;		 http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=008079 
;		1.1	- 02. July 2002 
;		 added support for win9x 
;		1.0	- 01. July 2002 
;		 initial release 
; 
;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
; 
;REMARKS	code for w9x adapted from BrianTX
; 
;DEPENDENCIES	none
; 
;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