Page 1 of 2 12>
Topic Options
#135676 - 2005-03-16 10:57 AM Shorten PC-Name and set to variable
Anonymous
Unregistered


Hi@all,
we have a new network-environment. In our concept, we use 10 characters for the pc-name.
The problem is: our old enterprise-software has to identify the PC from a variable but can only handle 8 characters.

What i want to do is, to read the pc-name (10char), shorten 2 characters and write the new string (8char) to a environment-variable "term".
the name is e.g ROCDTWT012 and shoult be shortened to RODWT012. Is there a way to solve that problem?
I'm a noob in scripting and kixstart, so is there somebody who has a script or who can tell me how to do?
thanks a lot,
bene

Top
#135677 - 2005-03-16 01:22 PM Re: Shorten PC-Name and set to variable
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Howdie,

Q: is it always the 3rd and 5th char to be removed?

if so:
Code:

$=@WKSTA
$=SubSTR($,1,2)+SubSTR($,4,1)+SubSTR($,6)
Set "term="+$

_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#135678 - 2005-03-16 01:48 PM Re: Shorten PC-Name and set to variable
Anonymous
Unregistered


Hi Patrick,
thanks for the fast help.
Yes, it's always the same characters to be cut off.
Unfortunately, it doesn't work.
I added these lines to my loginscript:

; Set Term ID
IF INGROUP ("PO-TermID")
<tab>$=@WKSTA
<tab>$=SubSTR($,1,2)+SubSTR($,4,1)+SubSTR($,6)
<tab>Set "term="+$

, but the whole workstationname is set to term.

I dont understand line 2 of your script - would it be complicated to explain for me ( = bloody noob)

thx
Bene

Top
#135679 - 2005-03-16 02:26 PM Re: Shorten PC-Name and set to variable
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
substr() - returns a substring of string
RETURN_VALUE = substr(STRING_TO_CUT,START_POSITION,LENGTH_OF_SELECTION)

substr($,1,2)+SubSTR($,4,1)+SubSTR($,6)
is:
substring from $ (which is workstation-name) characters 1-2 and 4 and 6 and anything beyond.

so, character 3 and 5 are subtracted.

_________________________
!

download KiXnet

Top
#135680 - 2005-03-16 02:59 PM Re: Shorten PC-Name and set to variable
Anonymous
Unregistered


thank you, jooel!
sounds easy and logical.
but it still doesn't work. the whole pc-name with 10 letters is written to temp.
any ideas?

Top
#135681 - 2005-03-16 03:13 PM Re: Shorten PC-Name and set to variable
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, I bet that instead of writing it to term, the term never gets changed at all.

so, simply add after:
Set "term="+$

this:
"the Term should be: $
?
get $


with this you can debug what the outcome really is.
_________________________
!

download KiXnet

Top
#135682 - 2005-03-16 04:03 PM Re: Shorten PC-Name and set to variable
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Where are you going to use the environment variable?

If you are going to spawn a process using Shell or Run you may need to use "SetL" rather than "Set". The same applies if you intend to use %TERM% later in the KiXtart script

Top
#135683 - 2005-03-16 04:17 PM Re: Shorten PC-Name and set to variable
bene Offline
Fresh Scripter

Registered: 2005-03-16
Posts: 13
Loc: Germany
Seems, that I'm too stupid for that
At least, I arrived to register my name for that Board

I also tried to Print $ in a Message-Box with the command
MESSAGEBOX (Term is $,termvariable, 0)

I do not get any output from Kix. Is there a command like "pause" and "echo" in winnt-commandline?
I think I'll have to read a lot to understand, how kixstart is working. damn, i don't have the time for that - i thought, i could just add those two lines to our loginscript and thats it.

what should i do now?

@richard: our enterprise-software needs to identify the pc to send the printjobs to the right printer. the variable is easiest to be handled as environment-variable


Edited by bene (2005-03-16 04:22 PM)

Top
#135684 - 2005-03-16 04:35 PM Re: Shorten PC-Name and set to variable
bene Offline
Fresh Scripter

Registered: 2005-03-16
Posts: 13
Loc: Germany
Quote:

substr() - returns a substring of string
RETURN_VALUE = substr(STRING_TO_CUT,START_POSITION,LENGTH_OF_SELECTION)

substr($,1,2)+SubSTR($,4,1)+SubSTR($,6)




why not
substr($,1,2)+SubSTR($,4,1)+SubSTR($,6,5)

Is the command case-sensitive?

Top
#135685 - 2005-03-16 04:40 PM Re: Shorten PC-Name and set to variable
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It is not case sensitive.

Before trying to implement it into the logon script, try it first as a short scriptlet run from a DOS prompt.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135686 - 2005-03-16 04:56 PM Re: Shorten PC-Name and set to variable
bene Offline
Fresh Scripter

Registered: 2005-03-16
Posts: 13
Loc: Germany
Quote:

Before trying to implement it into the logon script, try it first as a short scriptlet run from a DOS prompt.




I tried to do so, but nothing happend. How can i test the basic funcionality of Kix?


I dont know if it's usefull: im running W2k SP4 as client w2k3 as server

Top
#135687 - 2005-03-16 05:09 PM Re: Shorten PC-Name and set to variable
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Create a KiX folder on the root of C:
Put a copy of KiX32.exe in it
In Notepad, write your scriptlet
Save the file as "C:\KiX\test.kix" ;make sure to put quotes around the name so it doesn't change ot to test.kix.txt
goto Start | Run | CMD
in the DOS box, enter the command:
CD\KiX
enter the command:
kix32 test.kix


Edited by Les (2005-03-16 05:15 PM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135688 - 2005-03-16 05:38 PM Re: Shorten PC-Name and set to variable
bene Offline
Fresh Scripter

Registered: 2005-03-16
Posts: 13
Loc: Germany
thats exactly what i did (from a network drive) - now i know that this doesn't work.
but on the local drive of the server it also didn't work

i did what you said. a tiny mistake in the script and now im getting a result.
$ is the name with the cut of letters (lines 1 and 2 are working), but the variable is not set.
the output from line 4 works.
now, the syntax of the script is:
"
$=@WKSTA
$=SubSTR($,1,2)+SubSTR($,4,1)+SubSTR($,6)
Set "term="+$
"the Term should be: "$
?
get $
@kix
"

is the command Set "term="+$ correct?

Top
#135689 - 2005-03-16 05:42 PM Re: Shorten PC-Name and set to variable
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it's correct.
read above, and check the manual.
it is depending where you want to see the env var should you use set or setL or setM
_________________________
!

download KiXnet

Top
#135690 - 2005-03-16 05:54 PM Re: Shorten PC-Name and set to variable
bene Offline
Fresh Scripter

Registered: 2005-03-16
Posts: 13
Loc: Germany
firstly, in Line 4, there was a " missing- there was no output, so i thought, the script wouldn't run at all.

then, i tried to run kix32 from a mapped network-drive.

and finaly, using a variable needs a logoff after creating it! => I am so stupid!

Thank you for all your help an patience, sorry for wasting your time!!!

I think, now I can test and implement that to my loginscript, myself.

Have a nice evening,
Bene

Top
#135691 - 2005-03-16 05:59 PM Re: Shorten PC-Name and set to variable
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Using the environment variable depends on when you're going to use it. Are you going to use it during the logon script or after?

From the manual
Quote:

SetL

Action: Sets environment variables in the local environment that you see when you start a program from within a KiXtart script.

Syntax: SETL "variable=string"

Remarks: This command does not affect the current environment. If you start KiXtart from a batch file, any commands in the batch file that are run after KiXtart exits do not see changes made by the SET or SETL commands. If you want to run batch files or programs that depend on settings set by KiXtart, start them from KiXtart using SHELL or RUN.
SETL sets the value of @ERROR.

See Also: Set, SetM





Here is some example code to allow you to use the environment AFTER the logon script completes.

Code:
Break On

Dim $PC,$Admin,$PCSet
$PC=@WKSTA
$PC=SubSTR($PC,1,2)+SubStr($PC,4,1)+SubStr($PC,6)
? 'The value for PC is: ' + $PC
; line above so you can see it displayed on the DOS Console
$Admin=IIf(InGroup(@WKSTA+'\'+SidToName('S-1-5-32-544'))-1+@INWIN=1,'Yes','No')
If $Admin='Yes'
$PCSet=WriteValue('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment','TERM',$PC,REG_SZ)
Else
$PCSet=WriteValue('HKCU\Volatile Environment','TERM',$PC,REG_SZ)
EndIf




Edited by NTDOC (2005-03-16 06:22 PM)

Top
#135692 - 2005-03-16 06:13 PM Re: Shorten PC-Name and set to variable
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Would not the line:
If $Admin
return true regardless of 'Yes' or 'No'?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135693 - 2005-03-16 06:23 PM Re: Shorten PC-Name and set to variable
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Yes, you're correct Les. Thanks

I corrected the code above.

Top
#135694 - 2005-03-17 03:12 PM Re: Shorten PC-Name and set to variable
bene Offline
Fresh Scripter

Registered: 2005-03-16
Posts: 13
Loc: Germany
Hi NTDOC,
thanks for your suggestions, but the variable will be set while first login after installation, the user needs it earliest after 3rd login. so i'll keep it as simple as possible.

I completed the script:
to work on terminalservers, I need to identify the name of the client-pc. we have old clients (name less than 8char) and new clients (exactly 10 char)
so for a user, i have to decide, wether he is working on terminalserver or localPC. if working on terminalservers i have to decide, wether a new pc (10char) or a old pc (<8char) is in use.
so the script is something like this:

If not "%Clientname%"=""

$="%Clientname%"
$x=len(%clientname%)
IF $x<9
Set "term="+$
Else
$=SubSTR($,1,2)+SubSTR($,4,1)+SubSTR($,6)
Set "term="+$
EndIF

Else
$=@WKSTA
$=SubSTR($,1,2)+SubSTR($,4,1)+SubSTR($,6)
Set "term="+$
EndIF


Perhaps not the best way to solve that, but it seems to work...
greetz from bavaria,
bene

Top
#135695 - 2005-03-17 04:12 PM Re: Shorten PC-Name and set to variable
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what version of kix you have, btw?
in some newer version there was problem with the set...
_________________________
!

download KiXnet

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

Generated in 0.091 seconds in which 0.038 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