Page 1 of 1 1
Topic Options
#212391 - 2017-03-30 12:10 PM Map Printer on TS based on client IP
Snickers Offline
Fresh Scripter

Registered: 2017-03-28
Posts: 15
Loc: uk
Hello

I have looked at a script that maps a printer based on your client IP address. It works but I don't think it will work in my set up.

We have Windows Terminal servers and Linux thin clients with reserved IP addresses.

After the thin clients boots the MS RDP client program starts. Students log on with their normal account. Is it at the log on process that a kix script would need to map the right printer based on the IP address of the linux client ?

Top
#212392 - 2017-03-30 01:59 PM Re: Map Printer on TS based on client IP [Re: Snickers]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
That is what I would do. Map the correct printer(s) when they logon to the terminal server.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#212393 - 2017-03-30 02:42 PM Re: Map Printer on TS based on client IP [Re: Mart]
Snickers Offline
Fresh Scripter

Registered: 2017-03-28
Posts: 15
Loc: uk
Can you give an example script please?

ps, Chuck Norris would never have had a film/tv career if it hadn't been for his part in one of Bruce Lee's films.

Top
#212395 - 2017-03-30 06:35 PM Re: Map Printer on TS based on client IP [Re: Snickers]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1865
Loc: Hilversum, The Netherlands
 Originally Posted By: Snickers
ps, Chuck Norris would never have had a film/tv career if it hadn't been for his part in one of Bruce Lee's films.


Chuck Norris allowed Bruce Lee to create a standard as Chuck's standard is too high for anyone ;\)

Top
#212396 - 2017-03-31 11:27 AM Re: Map Printer on TS based on client IP [Re: Arend_]
Snickers Offline
Fresh Scripter

Registered: 2017-03-28
Posts: 15
Loc: uk
can you help me with my script issue ?
Top
#212397 - 2017-03-31 12:10 PM Re: Map Printer on TS based on client IP [Re: Snickers]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
Below is an example. Obviously you know your environment better then we do so the script may need to be customized but the basics should give you an idea how to proceed.

Make sure you use the correct printer names for AddPrinterConnection and SetDefaultPrinter. The first takes the sharename of the printer and the second takes the name of the printer. I made it a habit to keep them the same so I never get issues with that.

 Code:
If Not @LOGONMODE
	Break on
EndIf

If SessionType() = "Remote desktop session"
	$rc = AddPrinterConnection("\\server\printer")
	;If you want the printer to become the default printer uncomment the line below
	;$rc = Setdefaultprinter("\\server\printer")
EndIf


;========BELOW IS A USER DEFINED FUNCTION AKA UDF========
;========THE CODE BELOW IS READY FOR USE========
;
;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, $session
	
	$sessionname = ExpandEnvironmentVars(%sessionname%)
	$session = Left($sessionname, 3)
	Select
	Case $Session = "Con"
	$sessiontype = "Console session"
	Case $session = "RDP"
	$sessiontype = "Remote desktop session"
	Case $session = "ICA"
	$sessiontype = "Citrix ICA session"
	Case 1
	$sessiontype = "Unknown session type"
	EndSelect
EndFunction


Off topic: Chcuk Noris actually can divide by zero.
Off topic2: Clint Eastwood: Chuck Norris? Never heard of her!
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#212398 - 2017-03-31 12:42 PM Re: Map Printer on TS based on client IP [Re: Mart]
Snickers Offline
Fresh Scripter

Registered: 2017-03-28
Posts: 15
Loc: uk
I think I understand what this script does.

It identifies what type of session has been created by the client and there are three possible types. Presumably you would map a different printer based on what kind of session is set up.

In our environment we only use one type of connection out of the possible three there are in the script - RDP.

So the script needs to map the right printer based on the client IP rather than the session type.

I want to map the printer that is in the same classroom as the linux-based thin clients.

Top
#212399 - 2017-03-31 01:09 PM Re: Map Printer on TS based on client IP [Re: Snickers]
Snickers Offline
Fresh Scripter

Registered: 2017-03-28
Posts: 15
Loc: uk
Can this be used when linux-based thin clients are used to RDP to a Windows 2008R2 Terminal server?
 Code:
If Left(@WKSTA, 6) = "be_105"
	;Delete the printer.
	$rc = DelPrinterConnection("printer_for_room_BE")
	;Connect the printer.
	$rc = AddPrinterConnection("\\printerserver\printer_for_room_BE")
	;Set the printer as default.
	$rc = SetDefaultPrinter("printer_for_room_BE")
Else
	;Do nothing.
EndIf

Taken from:

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


The clients do have unique hostnames.


Edited by Arend_ (2017-03-31 02:22 PM)
Edit Reason: Please use code tags

Top
#212400 - 2017-03-31 02:59 PM Re: Map Printer on TS based on client IP [Re: Snickers]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
I do not have any Linux to test with but below are some comments.

 Code:
If Left(@WKSTA, 6) = "be_105"
....


Will return the first 6 characters of the machine the script is running on. The TS in your case. If you need the client computername (the workstation the users is behind) you could use ExpandEnvironmentVars(%clientname%)instead of @WKSTA.

The else is not needed if there is no code required there. Deleting a printer connection, creating it and making it default is one way of getting it done. Depending on personal preference it is also an option to check if the printer is there and set it or not depending on the results. I use the function PriMapState for that. This function is available in the UDF library.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#212401 - 2017-03-31 03:00 PM Re: Map Printer on TS based on client IP [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
I'm not sure how and if it is posisble to get the client IP when starting up a TS session.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#212402 - 2017-04-03 08:30 AM Re: Map Printer on TS based on client IP [Re: Mart]
Snickers Offline
Fresh Scripter

Registered: 2017-03-28
Posts: 15
Loc: uk
I just tested this code on a linux thin client:

 Code:
;--------Start IF_ELSE.kix--------
If Left(@WKSTA, 1) = "e"
;Delete the printer.
$rc = DelPrinterConnection("PR2-A-E9-17")
;Connect the printer.
$rc = AddPrinterConnection("\\cur-prs\PR2-A-E9-17")
;Set the printer as default.
$rc = SetDefaultPrinter("\\cur-prs\PR2-A-E9-17")
Else
;Do nothing.
EndIf
;-------- end IF_ELSE.kix--------


It works. The printer is only mapped if the user logs on from a computer where the hostname begins with an "e".


Edited by Mart (2017-04-03 08:40 AM)
Edit Reason: Please use code tags when posting code.

Top
#212403 - 2017-04-03 04:56 PM Re: Map Printer on TS based on client IP [Re: Mart]
Snickers Offline
Fresh Scripter

Registered: 2017-03-28
Posts: 15
Loc: uk
Just seen that the printer only installs if you log on with an admin account. Is there a command for making the script run with an elevated status ?
Top
#212404 - 2017-04-03 06:15 PM Re: Map Printer on TS based on client IP [Re: Snickers]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4455
Loc: USA
If you are having the same problem I've seen lately, it could be the printer drivers themselves causing this problem. Microsoft changed something, especially in Windows 10 that causes printer drivers to prompt for admin perms. Unfortunately, some manufacturers are not replacing the drivers and there is no work around for what has worked for years.
Top
#212405 - 2017-04-04 08:46 AM Re: Map Printer on TS based on client IP [Re: Allen]
Snickers Offline
Fresh Scripter

Registered: 2017-03-28
Posts: 15
Loc: uk
the clients are linux thin clients. I will look into "runnas" and see if that can solve my problem.
Top
#212410 - 2017-04-04 07:48 PM Re: Map Printer on TS based on client IP [Re: Snickers]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2080
Loc: Tulsa, OK
I have not used TS in a long time. Does TS still have install mode vs execute mode? If I recall correctly, we used to install all printer drivers as an admin while in install mode, then they would work for users that logged in and mapped to them. I may be getting my wires crossed though. And it was also before UAC prompt crap.
Top
Page 1 of 1 1


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

Who's Online
0 registered and 175 anonymous users online.
Newest Members
gkustra, emnipetro, Hirze, thequeen, ameliaryan
17642 Registered Users

Generated in 0.04 seconds in which 0.011 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