Page 1 of 1 1
Topic Options
#212768 - 2017-10-18 10:43 PM Determine if specific network printer is mapped on workstation
MikeKrausnick Offline
Just in Town

Registered: 2017-10-18
Posts: 1
Loc: Califirnia
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?

Top
#212769 - 2017-10-18 11:01 PM Re: Determine if specific network printer is mapped on workstation [Re: MikeKrausnick]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
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



Top
#212770 - 2017-10-19 09:21 AM Re: Determine if specific network printer is mapped on workstation [Re: MikeKrausnick]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.051 seconds in which 0.022 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