Page 1 of 2 12>
Topic Options
#209535 - 2014-10-20 09:30 AM Setting Default Printer from partial name
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
Hi all. It's been a while since i've been here.
My problem is as follows:

We are testing Citrix system in our company. We had a lot of problems with the printers. Finally we mange to find a solution to our printing problems but we stumbled into another one. Once the user log in to the Citrix, a new Citrix Generic printer is created. The printer name is as follows:"Citrix Universal Generic (From TC2) in session 3". I need to make that printer a default. The problem is that the name of the printer changes from user to user depends on it's workstation name and session number. The only thing that's not changing is the beginning of the printer name "Citrix Universal Generic".
Is there a way in Kix like in Windows systems that i can put something like Asterisk which will replace the changing parts of the printer name?

Thanks in advance \:\)


Edited by ddady (2014-10-20 09:30 AM)

Top
#209536 - 2014-10-20 10:13 AM Re: Setting Default Printer from partial name [Re: ddady]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
As far as I know there is no way to use a wildcard for setting the default printer but there must be a different solution to get it going.

You could use the SessionType() UDF to see if it is an ICA (citrix) session,check %CLIENTNAME% to get the name of the user's workstation and use the GetSessionID() UDF from the code below (could not find it in the UDF section) to get the session ID.

With all of this you should be able to construct the printer name like show below. Be careful because the code below is untested.

 Code:
Break on

If SessionType() = "ICA"
	;User is in an ICA session.

	;Get session number
	$session = GetSessionID()
	;Get client name
	$client = ExpandEnvironmentVars(%clientname%)
	;Set printer name
	$printer = "Citrix Universal Generic (From " + $client + ") in session " + $session
	;Set default printer
	$rc = SetDefaultPrinter($printer)
	;Check for errors
	If $rc <> 0
		? "There was an error."
		? @ERROR
		? @SERROR
	Else
		? "All is ok"
		? @ERROR
		? @SERROR
	EndIf
	Sleep 5	
EndIf

;FUNCTION      GetSessionID()
; 
;ACTION        Returns the Terminal Server session id 
; 
;AUTHOR        pearly 
; 
;CONTRIBUTORS  Richard H. (I'm almost reluctant to claiming this function as my own.  Thank you!) 
; 
;VERSION       1.0 
; 
;DATE CREATED  2005/03/06 
; 
;DATE MODIFIED 2005/03/06 
; 
;KIXTART       KiXtart 4.20 
; 
;SYNTAX        GetSession() 
; 
;PARAMETERS    None. 
; 
;RETURNS       Integer. 
; 
;REMARKS       Uses %TEMP% environment variable. 
; 
;DEPENDENCIES  None. 
; 
;EXAMPLE       Dim $session 
;			   $session = GetSessionID() 
; 
;KIXTART BBS    
; 
Function GetSessionID()
	Dim $s_sessionid
	Dim $iIndex
	$GetSessionID = 0
	$s_sessionid = SubStr(%TEMP%, 1 + InStrRev(%TEMP%, "\"))
	While $s_sessionid <> ""
		$iIndex = InStr("0123456789ABCDEF", Left($s_sessionid, 1))
		If $iIndex
			$GetSessionID = $GetSessionID * 16 + (CInt($iIndex - 1))
			$s_sessionid = SubStr($s_sessionid, 2)
		Else
			$GetSessionID = 0
			$s_sessionid = ""
		EndIf
	Loop
EndFunction
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#209538 - 2014-10-20 10:44 AM Re: Setting Default Printer from partial name [Re: Mart]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
Thank you Mart for the fast reply.
I will check the code today and will return with results.

Top
#209540 - 2014-10-20 03:06 PM Re: Setting Default Printer from partial name [Re: ddady]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
If you get a list of printers you should be able to figure out the printer with an instr() and set it that way.

PrinterList() -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84385#Post84385

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
#209541 - 2014-10-20 03:58 PM Re: Setting Default Printer from partial name [Re: Allen]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
Mart, i can't thank you enough.
The script works like a charm.
I only had to change the SessionType which is "CtxMtHost" and not "ICA". We are testing Citrix XenDesktop system.

Again, Thank you Mart and also to Allen :-)

Top
#209542 - 2014-10-20 04:05 PM Re: Setting Default Printer from partial name [Re: ddady]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Since you are using Xendesktop, would you be willing to test out another UDF, ClientName().

As far as I know this has never been tested in that environment, and it would be great to add that as something that also works.

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

Top
#209543 - 2014-10-20 04:40 PM Re: Setting Default Printer from partial name [Re: ddady]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Thanks. Happy to help where I can.

So CtxMtHost is what you get for XenDesktop? If so then I'll update the UDF to support that one to. Do you also have XenApp or is that the same? If you do, what does it return on XenApp?

I don't use Citrix anymore so I'm not up to speed on all the products and versions.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#209545 - 2014-10-21 06:42 AM Re: Setting Default Printer from partial name [Re: Allen]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
 Originally Posted By: Allen
Since you are using Xendesktop, would you be willing to test out another UDF, ClientName().

As far as I know this has never been tested in that environment, and it would be great to add that as something that also works.

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


Hi Allen,

I'll gladly test the ClientName() UDF and i will return with results.

Top
#209546 - 2014-10-21 07:25 AM Re: Setting Default Printer from partial name [Re: Mart]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
 Originally Posted By: Mart
Thanks. Happy to help where I can.

So CtxMtHost is what you get for XenDesktop? If so then I'll update the UDF to support that one to. Do you also have XenApp or is that the same? If you do, what does it return on XenApp?

I don't use Citrix anymore so I'm not up to speed on all the products and versions.


Hi Mart,
Yes, CtxMtHost is what i get when connecting to XenDesktop.
I'll just give a short brief how XenDesktop works. Actually, we have 2 Host Session servers which creates a load balancing. Users login in into Citrix with a Citrix Reciever. There are 2 options to work with XenDesktop (as far as i know):
1) RDS
2) VDI

We decided to work with RDS which is actually Citrix Remote Desktop (equivalent to Microsoft's Remote Desktop 'RDP'). The two Host Session servers are equivalent to Microsoft TS Servers.

The VDI option is very different. It creates a full virtual machine for each user. This way requires more resources and fits to users who have special requirements such as heavy duty software and etc.

As far as i know, XenApp is a server that holds apps but users not actually open a session on it in order to work with the apps. Users still connect to the Host Session servers and there (in their session)they have an area like "Apps Store" which they can choose apps to work with.

Right now i'm learning the system so i'm not a 100% familiar with it. I will be glad to add more info about it as i go.

Top
#209547 - 2014-10-21 08:08 AM Re: Setting Default Printer from partial name [Re: Allen]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
 Originally Posted By: Allen
Since you are using Xendesktop, would you be willing to test out another UDF, ClientName().

As far as I know this has never been tested in that environment, and it would be great to add that as something that also works.

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


Hi Allen,

Just finished testing the function.
I replaced in Mart's script:
 Code:
$client = ExpandEnvironmentVars(%clientname%)

with
 Code:
$client = ClientName()
.

It works like a charm :-)

Top
#209549 - 2014-10-21 09:33 AM Re: Setting Default Printer from partial name [Re: ddady]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Hi ddady,

Can you give the code below a go and see if it provides correct results?
I added XenDesktop supoort but cannot test this myself.

 Code:
Break on

SessionType()

Sleep 5



;Function	SessionType()
;
;Contributors:
;		Inspired by 
;			http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=195460
;
;Action:
;		Gets the session type of the current user.
;
;Syntax:
;		SessionType()
;
;Version:
;		1.0 August 20th 2009.
;			Initial post.
;
;Parameters:
;		None.
;
;Returns:
;		String value holding the session type.
;		Currently supports Console, RDP and ICA.
;
;Dependencies
;		No known dependencies
;
;KiXtart:
;		Developed and tested KiXtart 4.60 and Windows Vista Business SP2.
;
;Example(s):
;		Break on
;		$rc = SessionType()
;		$rc
;		Sleep 5
;
;Code:
Function SessionType()
	
	Dim $sessionname
	
	$sessionname = ExpandEnvironmentVars(%sessionname%)
	
	Select
		Case Left($sessionname, 3) = "Con"
			$sessiontype = "Console session"
		Case Left($sessionname, 3) = "RDP"
			$sessiontype = "Remote desktop session"
		Case Left($sessionname, 3) = "ICA"
			$sessiontype = "Citrix ICA session"
		Case Left($sessionname, 9) = "CtxMtHost"
			$sessiontype = "Citrix XenDesktop session"
		Case 1
			$sessiontype = "Unknown session type"
	EndSelect
EndFunction
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#209551 - 2014-10-21 11:00 AM Re: Setting Default Printer from partial name [Re: Mart]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
I get "Citrix ICA session".

Ok, I understand why. I got confused between the Process Name and the Session Name. The Session Name goes like this: "ICA-CGP#43" (the number at the end changes from user to user). The Process Name is the "CtxMtHost".

That makes me wonder how come the script still works fine?!

Top
#209552 - 2014-10-21 11:50 AM Re: Setting Default Printer from partial name [Re: ddady]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
LOL ok then I will not update the UDF in the UDF section as it is actually correct.

Why your script still works? I don’t know. Can you post what you have running?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#209553 - 2014-10-21 12:16 PM Re: Setting Default Printer from partial name [Re: Mart]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
That's the script i'm running:

 Code:
Break on

If SessionType() = "CtxMtHost"
	;User is in an ICA session.

	;Get session number
	$session = GetSessionID()
	;Get client name
	$client = ExpandEnvironmentVars(%clientname%)
	;Set printer name
	$printer = "Citrix UNIVERSAL Printer (from " + $client +") in session " + $session
	;Set default printer
	$rc = SetDefaultPrinter($printer)
	;Check for errors
	If $rc <> 0
		? "There was an error."
		? @ERROR
		? @SERROR
	Else
		? "All is ok"
		? @ERROR
		? @SERROR
	EndIf
	Sleep 5	
	
EndIf

;FUNCTION      GetSessionID()
; 
;ACTION        Returns the Terminal Server session id 
; 
;AUTHOR        pearly 
; 
;CONTRIBUTORS  Richard H. (I'm almost reluctant to claiming this function as my own.  Thank you!) 
; 
;VERSION       1.0 
; 
;DATE CREATED  2005/03/06 
; 
;DATE MODIFIED 2005/03/06 
; 
;KIXTART       KiXtart 4.20 
; 
;SYNTAX        GetSession() 
; 
;PARAMETERS    None. 
; 
;RETURNS       Integer. 
; 
;REMARKS       Uses %TEMP% environment variable. 
; 
;DEPENDENCIES  None. 
; 
;EXAMPLE       Dim $session 
;			   $session = GetSessionID() 
; 
;KIXTART BBS    
; 
Function GetSessionID()
	Dim $s_sessionid
	Dim $iIndex
	$GetSessionID = 0
	$s_sessionid = SubStr(%TEMP%, 1 + InStrRev(%TEMP%, "\"))
	While $s_sessionid <> ""
		$iIndex = InStr("0123456789ABCDEF", Left($s_sessionid, 1))
		If $iIndex
			$GetSessionID = $GetSessionID * 16 + (CInt($iIndex - 1))
			$s_sessionid = SubStr($s_sessionid, 2)
		Else
			$GetSessionID = 0
			$s_sessionid = ""
		EndIf
	Loop
EndFunction

Top
#209554 - 2014-10-21 03:43 PM Re: Setting Default Printer from partial name [Re: ddady]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Thanks for the feedback! \:\)
Top
#209555 - 2014-10-21 03:52 PM Re: Setting Default Printer from partial name [Re: ddady]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Hmmmm....not sure why this works if SessionType returns ICA. I see as good as no changes to my code. You did include the the SessionType UDF right?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#209563 - 2014-10-22 06:42 AM Re: Setting Default Printer from partial name [Re: Mart]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
 Originally Posted By: Mart
Hmmmm....not sure why this works if SessionType returns ICA. I see as good as no changes to my code. You did include the the SessionType UDF right?


Actually, i didn't \:o
That makes it even more strange.


Edited by ddady (2014-10-22 06:43 AM)

Top
#209572 - 2014-10-23 12:49 AM Re: Setting Default Printer from partial name [Re: ddady]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Wtf? Something is not right here...
_________________________
!

download KiXnet

Top
#209574 - 2014-10-23 09:21 AM Re: Setting Default Printer from partial name [Re: Lonkero]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
It should throw an error on If SessionType() = "CtxMtHost" if the UDF is not included or called earlier in the script. Somehow it returns CtxMtHost and continues the script. Unfortunately I cannot test anything Citrix related anymore. I also do not see anything in the code that may cause this.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#209575 - 2014-10-23 09:55 AM Re: Setting Default Printer from partial name [Re: Mart]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
I'll try running it on debug mode and see if i can find something.

Edited by ddady (2014-10-23 09:57 AM)

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 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.064 seconds in which 0.024 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