Page 1 of 2 12>
Topic Options
#41471 - 2003-06-13 02:06 AM Wildcard usage?
WhiteOnyx Offline
Fresh Scripter

Registered: 2003-06-13
Posts: 7
Loc: New Zealand
Hi there.

I'm new to this forum (and Kix scripting itself!) so Im sorry if I put this in the wrong area.

I work for a computer company that does work for a local high school. The school has one printer per room, and they wish for the login script to pick the printer that is in the room with any given machine, and make it the default.
A section of the script I have to do this is as follows:
code:
 
IF
@WKSTA = "D1-PC01" OR
@WKSTA = "D1-PC02" OR
@WKSTA = "D1-PC03" OR
@WKSTA = "D1-PC03" OR
@WKSTA = "D1-PC04" OR
@WKSTA = "D1-PC05" OR
@WKSTA = "D1-PC06" OR
@WKSTA = "D1-PC07" OR
@WKSTA = "D1-PC08" OR
@WKSTA = "D1-PC09" OR
@WKSTA = "D1-PC10" OR
@WKSTA = "D1-PC11" OR
@WKSTA = "D1-PC12" OR
@WKSTA = "D1-PC13" OR
@WKSTA = "D1-PC14" OR
@WKSTA = "D1-PC15" OR
@WKSTA = "D1-PC16" OR
@WKSTA = "D1-PC17" OR
@WKSTA = "D1-PC18" OR
@WKSTA = "D1-PC19" OR
@WKSTA = "D1-PC20" OR
@WKSTA = "LEAT 30"

$PrinterName = "\\TCW2KS01\D1-HP4Si"
CALL "@LSERVER\NetLogon\Scripts\dfltpntr.kix"
ENDIF

This is just for one classroom, and whilst it does work, its slow as hell! There are about 200 machine names in total and 80% of the time they start with (as in this case) "D1-(machine number)".
In order to speed up script execution, is there any way of using a wildcard after the 'D1-', and setting the printer from that IF? This way I would only have to go thru 20 lines of code as opposed to 200. I believe this would speed things up...is this likely to be the case, or am I barking up the wrong tree?

Hope you understand what Im getting at, and thanks for reading [Smile]

I look forward to any help you can give.

Thanks, Ben.

Top
#41472 - 2003-06-13 02:11 AM Re: Wildcard usage?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hi White, and welcome, the SUBSTR function might do yeah well here, example:

code:
IF SUBSTR(@WKSTA,1,2) = "D1" OR @WKSTA = "LEAT 30"
$PrinterName = "\\TCW2KS01\D1-HP4Si"
CALL "@LSERVER\NetLogon\Scripts\dfltpntr.kix"
ENDIF

-Shawn

Top
#41473 - 2003-06-13 02:14 AM Re: Wildcard usage?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Excellent quick post there Shawn.

WhiteOnyx,

Very bad idea having a computer name with a space in it. I'd rename the PC to remove the space if at all possible.

LEAT 30=LEAT30 would be better

Top
#41474 - 2003-06-13 02:21 AM Re: Wildcard usage?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I would heed NTDOC's advise White ... not only does Ron know what he's talking about, he has really big hammer and likes to smash things.
Top
#41475 - 2003-06-13 02:22 AM Re: Wildcard usage?
WhiteOnyx Offline
Fresh Scripter

Registered: 2003-06-13
Posts: 7
Loc: New Zealand
Thanks very much guys (or girls!), Ill give it a try & let yas know how it goes.

Regards, Ben.

Top
#41476 - 2003-06-13 02:23 AM Re: Wildcard usage?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
SUBSTR(@WKSTA,1,2) = "D1" ?

Left(@WKSTA,2) = "D1"

Is a better KixGolf score. [Big Grin]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#41477 - 2003-06-13 02:27 AM Re: Wildcard usage?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
What is in "dfltpntr.kix"?

Most likely it would be faster to include that code in your main script.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#41478 - 2003-06-13 02:27 AM Re: Wildcard usage?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
All right... I think WhiteOnyx is calling one of us out.

Which one of you is the GIRL? [Eek!]

Top
#41479 - 2003-06-13 02:42 AM Re: Wildcard usage?
WhiteOnyx Offline
Fresh Scripter

Registered: 2003-06-13
Posts: 7
Loc: New Zealand
haha...no no, not at all. Just trying to be politically correct!

If I include an EXIT statement here

code:
IF 
SUBSTR(@WKSTA,1,2) = "D1" OR @WKSTA = "LEAT 30"

$PrinterName = "\\TCW2KS01\D1-HP4Si"
CALL "@LSERVER\NetLogon\Scripts\dfltpntr.kix"
EXIT
ENDIF

will this exit the IF statement only, or the whole script?

In response to the 'what is dfltpntr.kix?', I really dont know. We are new to the school and are trying to make things work a little faster for the mean time. Im sure there will be more slim lining going on in time!

Ben

Top
#41480 - 2003-06-13 02:48 AM Re: Wildcard usage?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
It would exit the script.
Top
#41481 - 2003-06-13 02:50 AM Re: Wildcard usage?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You do not need an "EXIT" in the IF.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#41482 - 2003-06-13 03:12 AM Re: Wildcard usage?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Also, not a big time saver in this case, but would save where there are many calls to a MACRO
like you had in your original code.

Placing a macro into a var is better.


$w=@WKSTA
IF SUBSTR($w,1,2) = "D1" OR $w = "LEAT 30"
$PrinterName = "\\TCW2KS01\D1-HP4Si"
CALL "@LSERVER\NetLogon\Scripts\dfltpntr.kix"
ENDIF

Top
#41483 - 2003-06-13 03:35 AM Re: Wildcard usage?
WhiteOnyx Offline
Fresh Scripter

Registered: 2003-06-13
Posts: 7
Loc: New Zealand
Gah! So much to learn! [Razz]

The dfltpntr.kix script reads:

code:
; Searching for new printers
$Temp = SUBSTR($PrinterName,3,999)
$PrinterServer = SUBSTR($Temp,1,INSTR($TEMP,"\")-1)
$PrinterShare = SUBSTR($Temp,INSTR($TEMP,"\")+1,999)
$RegKey = ",,"+$PrinterServer+","+$PrinterShare

; Setting new printer as default
$Index = 0
WHILE @ERROR = 0
$ValueName = ENUMKEY( "HKEY_CURRENT_USER\Printers\Connections" , $Index )
If @ERROR = 0
IF INSTR($Valuename,$RegKey) <> 0
$PrinterType = SUBSTR($ValueName,INSTR($ValueName," - "),999)
$DeviceName = "\\"+$PrinterServer+"\"+$PrinterShare+$PrinterType+",winspool,Ne0"+$Index+":"
WRITEVALUE ("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device",$DeviceName,"REG_SZ")
ENDIF
ENDIF
$Index = $Index + 1
LOOP

Howard suggested putting this into the other script. Would it work as a straight cut and paste thing? Or is there a better way to do it still?

Top
#41484 - 2003-06-13 04:02 AM Re: Wildcard usage?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Have you looked at SetDefaultPrinter()?

If you have NT or higher you can use ADDPRINTERCONNECTION().
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#41485 - 2003-06-13 05:18 AM Re: Wildcard usage?
WhiteOnyx Offline
Fresh Scripter

Registered: 2003-06-13
Posts: 7
Loc: New Zealand
Apparently the last script was very long winded because for a time they were running mainly Win 98 machines, and they now use almost exclusively Win2k Pro.
If you are interested, I've changed the code so it reads thus
code:
IF 
SUBSTR(@WKSTA,1,2) = "D1" OR
@WKSTA = "LEAT 30"

$PrinterName = "\\TCW2KS01\D1-HP4Si"
SETDEFAULTPRINTER ($PrinterName)
IF
SETDEFAULTPRINTER ($PrinterName) <> 0
CALL "@LSERVER\NetLogon\Scripts\dfltpntr.kix"
ENDIF
EXIT
ENDIF

I put the CALL statement in incase everything turns pear shaped. Hope it all works out!

Thanks again for your help.

Happy scripting,
Ben.

Top
#41486 - 2003-06-13 05:24 AM Re: Wildcard usage?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Would be curious to know, if it works, how much (if any) boost in login speed you get. If you get the chance, please lets us know one way or the other ?

-Shawn

Top
#41487 - 2003-06-13 10:43 AM Re: Wildcard usage?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Save yourself some grief in the future and get used to providing a value with "EXIT".

Not only is it good practice to provide a status when EXITing (or QUITing), but some code will break if there is no value.

Use "Exit 0" for a success and "Exit n" where "n" is a posotive integer for a failure. Where possible use a valid DOS/Windows error number for the exit code which has a meaning close to the actual problem, as this will allow the @SERROR macro to report something meaningful.

Top
#41488 - 2003-06-13 11:31 AM Re: Wildcard usage?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Ben,

Try to remove that old printer kix file and just use the AddPrinterConnection( ) or one of these UDFs.

Here are some UDFs for printers

http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000109

http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000404

http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000236

http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000207

http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000174

Top
#41489 - 2003-06-13 01:19 PM Re: Wildcard usage?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Still don't know why you has the "EXIT" at the end of the IF statement. This should make any appreciable difference in execution time once you have properly constructed IF or Select...CASE...EndSelect constructs.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#41490 - 2003-06-13 02:06 PM Re: Wildcard usage?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hmmm, i kinda got into the habit of doing EXIT 1 meaning EXIT [TRUE] as oppposed to EXIT 0 meaning EXIT [FALSE]. Think Richard is right though, EXIT 0 would probably be best pratice and is more DOS like ...

-Shawn

[ 13. June 2003, 14:07: Message edited by: Shawn ]

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
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.076 seconds in which 0.029 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