#210283 - 2015-05-23 12:33 AM
Set Default Printer Issue
|
David_H
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 
;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
|
|
|
|
#210295 - 2015-05-27 08:23 PM
Re: Set Default Printer Issue
[Re: Lonkero]
|
David_H
Fresh Scripter
Registered: 2015-05-22
Posts: 11
Loc: USA, WA
|
You could also start your scripts printer section like:
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
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
|
|
|
|
#210303 - 2015-05-28 04:29 PM
Re: Set Default Printer Issue
[Re: David_H]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
|
|
Top
|
|
|
|
#210308 - 2015-05-28 08:29 PM
Re: Set Default Printer Issue
[Re: David_H]
|
Allen
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
|
|
|
|
#210324 - 2015-05-29 07:07 AM
Re: Set Default Printer Issue
[Re: David_H]
|
ShaneEP
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...
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1183 anonymous users online.
|
|
|