Page 1 of 1 1
Topic Options
#210283 - 2015-05-23 12:33 AM Set Default Printer Issue
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
Hello,
I have searched for others with my problem, but was unable to find a solution that worked for me so I am sorry if I missed it.

A little background:
I have been using this basic code for 7 years now with no real issues. Our computers are frozen so upon reboot, all changes/profiles are deleted. There are no local printers installed. We implemented RDP servers 2 years ago (not frozen) and the dynamics of the user base seems to have changed in the last year.

When i first implemented the Kix script, I was unable to get the "setdefaultprinter" portion of my code to work (not sure if i was using it correctly back then or not), but I did notice that the first printer that was added became the default printer. This worked out back then so I saw no reason to pursue diagnosing the issue any farther. Since the RDP migration, users profiles are not deleted and network printers are added but never removed. In my script, I add the printer according to the location of the computer (closest printer). The problem with this is my user base (Students/Teachers) are moving around the buildings and printing to other printers... I understand checking to make sure your printing to the correct printer before you print, but all i am getting is complaints because items are not printing to where they are supposed to.

I am showing my code below in hopes someone can point out what i am doing wrong. I removed a lot of my code for other locations, but it looks identical to the locations that are listed.

Thanks to the alternate eyes on this \:\)

 Code:
;This script adds printers based on the computer names
;nameing convention is 8 charecters.
;shs-lib-
;shs-libm
;shs-205-
;sms-101-
;sms-lab-
;sms-p2-l
;$CompName = the workstation name
;$location = the first thru eigth character of the workstation name

;Turn Debug mode on or off
;DEBUG ON

;Turn off CTL-C Breaking of scripts
BREAK OFF

;Changes the display state of the command-prompt window in which kixtart is running
SETCONSOLE ("HIDE")


If @TSSESSION=1
	$CompName = %CLIENTNAME%

else
	$CompName = @WKSTA

ENDIF




If LEN($CompName) > 7
	$Location = SUBSTR($CompName, 1, 8) 
	
	SELECT

;RDP


	CASE $Location = "GES-COW-"
		ADDPRINTERCONNECTION ("\\Husky-Reader\GES_COW_YELLOW")
		ADDPRINTERCONNECTION ("\\Husky-Reader\GES_COW_WHITE")
	CASE $Location = "SES-COW-"
		ADDPRINTERCONNECTION ("\\Cougar-Reader\SES_COW_YELLOW")
		ADDPRINTERCONNECTION ("\\Cougar-Reader\SES_COW_WHITE")
		ADDPRINTERCONNECTION ("\\Cougar-Reader\SES_COW_GREEN")
		ADDPRINTERCONNECTION ("\\Cougar-Reader\SES_COW_RED")
	CASE $Location = "SHS-COW-"
		ADDPRINTERCONNECTION ("\\Turk-Reader\SHS_COW_YELLOW")
		ADDPRINTERCONNECTION ("\\Turk-Reader\SHS_COW_WHITE")
		ADDPRINTERCONNECTION ("\\Turk-Reader\SHS_COW_GREEN")
		ADDPRINTERCONNECTION ("\\Turk-Reader\SHS_COW_RED")
	CASE $Location = "SMS-COW-"
		ADDPRINTERCONNECTION ("\\Skyhawk-Reader\SMS_COW_YELLOW")
		ADDPRINTERCONNECTION ("\\Skyhawk-Reader\SMS_COW_WHITE")



;OPS

	CASE $Location = "training"
		ADDPRINTERCONNECTION ("\\Lex\Tech_lab_Main")
		SETDEFAULTPRINTER ("\\Lex\Tech_lab_Main")

	CASE $Location = "tech-lab"
		ADDPRINTERCONNECTION ("\\Lex\Tech_lab_Main")
		SETDEFAULTPRINTER ("\\Lex\Tech_lab_Main")

	CASE $Location = "tech-dus"
		ADDPRINTERCONNECTION ("\\Lex\Tech_lab_Main")
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_P04")
		SLEEP 10
		SETDEFAULTPRINTER ("\\turk-reader\SHS_P04")

;SHS


	CASE $Location = "shs-kit-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_Kitchen")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_Kitchen")

	CASE $Location = "shs-con-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_CareerKiosk")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_CareerKiosk")

	CASE $Location = "shs-lib-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_LibraryMain")
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_LibraryLab")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_LibraryMain")
	
	CASE $Location = "shs-libm"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_LibraryLab")
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_LibraryMain")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_LibraryLab")

	CASE $Location = "shs-off-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_Office_Main")
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_Office_Copy")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_Office_Main")

	CASE $Location = "shs-voc-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_VocWood")
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_vocMetal")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_VocWood")

	CASE $Location = "shs-P01-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_LabP01")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_LabP01")

	CASE $Location = "shs-P02-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_LabP02")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_LabP02")

	CASE $Location = "shs-P03-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_P03")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_P03")

	CASE $Location = "shs-P04-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_P04")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_P04")

	CASE $Location = "shs-P05-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_P04")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_P04")

	CASE $Location = "shs-P06-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_P06")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_P06")

	CASE $Location = "shs-P07-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_P07")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_P07")

	CASE $Location = "shs-P08-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_P08")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_P08")

	CASE $Location = "shs-P09-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_P09")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_P09")

	CASE $Location = "shs-101-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_Lab101")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_Lab101")

	CASE $Location = "shs-102-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_Lab102")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_Lab102")

	CASE $Location = "shs-140-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_140")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_140")

	CASE $Location = "shs-201-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_201")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_201")

	CASE $Location = "shs-202-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_202")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_202")

	CASE $Location = "shs-203-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_203")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_203")

	CASE $Location = "shs-204-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_204")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_204")

	CASE $Location = "shs-301-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_MathWorkRoom")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_MathWorkRoom")

	CASE $Location = "shs-302-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_MathWorkRoom")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_MathWorkRoom")

	CASE $Location = "shs-303-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_ScienceWorkRoom")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_ScienceWorkRoom")

	CASE $Location = "shs-304-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_ScienceWorkRoom")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_ScienceWorkRoom")

	CASE $Location = "shs-305-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_Diamond")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_Diamond")

	CASE $Location = "shs-306-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_Diamond")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_Diamond")

	CASE $Location = "shs-307-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_Diamond")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_Diamond")

	CASE $Location = "shs-308-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_Diamond")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_Diamond")

	CASE $Location = "shs-401-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_401")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_401")

	CASE $Location = "shs-402-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_402")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_402")

	CASE $Location = "shs-404-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_MathWorkRoom")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_MathWorkRoom")

	CASE $Location = "shs-406-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_MathWorkRoom")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_MathWorkRoom")

	CASE $Location = "shs-car-"
		ADDPRINTERCONNECTION ("\\turk-reader\SHS_CareerKiosk")
		SETDEFAULTPRINTER ("\\turk-reader\SHS_CareerKiosk")


	CASE 1
	ENDSELECT
EndIf

Top
#210284 - 2015-05-23 02:19 AM Re: Set Default Printer Issue [Re: David_H]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I would like to know if they are logging out of the RDC from the current pc before they log into it from another. If not, your login script isn't even running.

Also... I see many things that can be optimized.

Top
#210285 - 2015-05-23 08:50 AM Re: Set Default Printer Issue [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
If I remember correctly, setdefaultprinter uses the actual printer name, and not the share name. If they are not named the same as the share, that could be an issue. Just a thought.
Top
#210286 - 2015-05-23 08:51 AM Re: Set Default Printer Issue [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Also, I would add something like '$nul = ' in front of all the printer function, to catch the return values. That way they wont try to display to the console. You could then remove the SETCONSOLE ("HIDE") command, and no console should ever be displayed if you're using wkix32.exe.
Top
#210287 - 2015-05-23 06:21 PM Re: Set Default Printer Issue [Re: ShaneEP]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
You could also start your scripts printer section like:
 Code:
If ingroup("students")
  $=delprinterconnection("")
Endif


Because it is better to inconvenience the students than waste paper.
_________________________
!

download KiXnet

Top
#210292 - 2015-05-27 07:47 PM Re: Set Default Printer Issue [Re: Allen]
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
I would be safe to say that the people that log out compared to the ones that stay logged in about 90% logout and 10 don't. To solve some of this, the RDP servers are rebooted every night. I know that does not fix the ones that are not logging out, but the first troubleshooting step that the teachers are given is to log out and back it to see if the problem is fixed.
Top
#210293 - 2015-05-27 07:51 PM Re: Set Default Printer Issue [Re: ShaneEP]
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
Should my script for the default printer be more like below so I am not using the share name?

CASE $Location = "training"
ADDPRINTERCONNECTION ("\\Lex\Tech_lab_Main")
SETDEFAULTPRINTER ("Tech_lab_Main")

Top
#210295 - 2015-05-27 08:23 PM Re: Set Default Printer Issue [Re: Lonkero]
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
 Originally Posted By: Lonkero
You could also start your scripts printer section like:
 Code:
If ingroup("students")
  $=delprinterconnection("")
Endif


Because it is better to inconvenience the students than waste paper.


I like where your going with this. I know very little scripting so fogive me for my next question, i know how basic it will seem. What does the $= in your script do?

Top
#210297 - 2015-05-27 08:56 PM Re: Set Default Printer Issue [Re: David_H]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
$ is shortened variable, just without the word following, like $nul or $value. Lonk is a kix golfer and should know better than to use that on the board ;\)

Functions like DelPrinterConnection, AddprinterConnection, SetDefaultPrinter all have output that helps diagnose problems. Putting the $variable in front of these functions basically silences that output, however you can always check the value later.




Top
#210299 - 2015-05-28 05:44 AM Re: Set Default Printer Issue [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
 Quote:
Should my script for the default printer be more like below so I am not using the share name?

CASE $Location = "training"
ADDPRINTERCONNECTION ("\\Lex\Tech_lab_Main")
SETDEFAULTPRINTER ("Tech_lab_Main")

No not necessarily. I believe you still have to include the server. But there are two names to every shared printer. The name it has when it is created, and the name that you assign to it for the share. SETDEFAULTPRINTER uses the original printer name, not the share name. For example, I could theoretically create a printer on a server named HP Color LaserJet CM3230. But could share it as ShanesPrinter. Therefore the code would be...

 Code:
$nul = ADDPRINTERCONNECTION("\\Server\ShanesPrinter")
$nul = SETDEFAULTPRINTER("\\Server\HP Color LaserJet CM3230")

Does that make sense? We used to avoid this problem by always making sure the printer had the same name as it was shared as. At least this is how it used to be when I did login scripts.

Top
#210302 - 2015-05-28 04:19 PM Re: Set Default Printer Issue [Re: ShaneEP]
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
That is funny and kinda sad for me... I have always named the printers and the shares the same. It never occurred to me that printers could show up as something else than the shared name.
Top
#210303 - 2015-05-28 04:29 PM Re: Set Default Printer Issue [Re: David_H]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
You might find the following User Defined Function (UDF) helpful, as you can completely manage your printers with the share name.

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
#210305 - 2015-05-28 05:54 PM Re: Set Default Printer Issue [Re: Allen]
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
So here is my first update after testing the ideas put forth to me.

The first thing I tried was to add the code to remove all networked printers. $=delprinterconnection("") I change my test code to:

CASE $Location = "tech-dus"
$=delprinterconnection("")
ADDPRINTERCONNECTION ("\\turk-reader\SHS_Kitchen")
ADDPRINTERCONNECTION ("\\turk-reader\SHS_P04")
SETDEFAULTPRINTER ("\\turk-reader\SHS_P04")

I replaced the first printer that went to our lab printer to a printer at the SHS location. I only wanted to effect the one computer I am using for testing so I hope this is a correct way to use this code. But unfortunately, it did not delete the previously added lab printer or set the default printer to SHS_P04. Any ideas on that?

As I was writing this, I had a thought. I am RDP'ing into Server 2008 R2. Could that have something to do with why this portion of the code is not working?

Top
#210307 - 2015-05-28 07:25 PM Re: Set Default Printer Issue [Re: David_H]
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
Allen,

I am looking at the functions you posted and we can do alot more with kix than I thought was possible. Thanks for the links!!!

I see you wrote the function on retrieving the Clientname from the RDP session. Is there a reason to separate the code by the type of server you are connecting to? It looks like a lot of well thought out work, I am just failing to see a need for all that code when this seems to work. What am I missing?

If @TSSESSION=1
$CompName = %CLIENTNAME%
else
$CompName = @WKSTA
ENDIF

Top
#210308 - 2015-05-28 08:29 PM Re: Set Default Printer Issue [Re: David_H]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
To be completely honest, on the clientname UDF, I only posted the code. However, the code was created by other Kixtart.org members to accommodate getting the clientname from more than just RDP AND for when it is not so simple as to get it the way you are. If you look at the code, the very first test is the way you are doing it.

There is nothing wrong with the way you are doing it, until one day it doesn't work. Then you might have a need for this UDF. \:\)

By the way, please put your code inside the Code Tags. Its the "#" button above the box where you type your message. (Normal Reply, not the Quick Reply box below)

Top
#210319 - 2015-05-28 10:46 PM Re: Set Default Printer Issue [Re: Allen]
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
I will do that from now on. I read one of the posting rules and it had said to only put the code tags on if it was lots of code. Not sure if you want to get that changed or not. Let me know and I will try to find that welcome message again.
Top
#210320 - 2015-05-28 10:47 PM Re: Set Default Printer Issue [Re: David_H]
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
I am going to try to update to the latest version of Kixtart tonight to see if that fixes the problems. I am currently running v4.53
Top
#210324 - 2015-05-29 07:07 AM Re: Set Default Printer Issue [Re: David_H]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
And you're positive that the $location is being set correctly? Maybe some error checking would help...

 Code:
CASE $Location = "tech-dus"
   $nul = messagebox("tech-dus", "location", 0)
   $rc = delprinterconnection("")
   If $rc = 0
      $nul = messagebox("successfully deleted printers", "delprinterconnection", 0)
   Else
      $nul = messagebox("error deleting printers: "+$rc, "delprinterconnection", 0)
   Endif
   $rc = ADDPRINTERCONNECTION ("\\turk-reader\SHS_Kitchen")
   If $rc = 0
      $nul = messagebox("successfully added printer", "SHS_Kitchen", 0)
   Else
      $nul = messagebox("error adding printer: "+$rc, "SHS_Kitchen", 0)
   Endif
   $rc = ADDPRINTERCONNECTION ("\\turk-reader\SHS_P04")
   If $rc = 0
      $nul = messagebox("successfully added printer", "SHS_P04", 0)
   Else
      $nul = messagebox("error adding printer: "+$rc, "SHS_P04", 0)
   Endif
   $rc = SETDEFAULTPRINTER ("\\turk-reader\SHS_P04")
   If $rc = 0
      $nul = messagebox("successfully set printer default", "SHS_P04", 0)
   Else
      $nul = messagebox("error setting printer default: "+$rc, "SHS_P04", 0)
   Endif

Top
#210326 - 2015-05-29 06:04 PM Re: Set Default Printer Issue [Re: ShaneEP]
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
 Originally Posted By: ShaneEP
And you're positive that the $location is being set correctly? Maybe some error checking would help...

I know it is set correctly because the printers are being added.

Although this might help with figuring out why the printers are not being deleted.


Edited by David_H (2015-05-29 06:08 PM)

Top
#210327 - 2015-05-29 06:07 PM Re: Set Default Printer Issue [Re: David_H]
David_H Offline
Fresh Scripter

Registered: 2015-05-22
Posts: 11
Loc: USA, WA
Good news, updating Kixtart from 4.53 to 4.64 fixed setting the default printer.

Still having issues with removing the printers, but this might nullify the need to delete them.

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
0 registered and 1183 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.053 seconds in which 0.014 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