**DONOTDELETE**
(Lurker)
2005-03-16 10:57 AM
Shorten PC-Name and set to variable

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


MightyR1
(MM club member)
2005-03-16 01:22 PM
Re: Shorten PC-Name and set to variable

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="+$



**DONOTDELETE**
(Lurker)
2005-03-16 01:48 PM
Re: Shorten PC-Name and set to variable

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


LonkeroAdministrator
(KiX Master Guru)
2005-03-16 02:26 PM
Re: Shorten PC-Name and set to variable

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.



**DONOTDELETE**
(Lurker)
2005-03-16 02:59 PM
Re: Shorten PC-Name and set to variable

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?


LonkeroAdministrator
(KiX Master Guru)
2005-03-16 03:13 PM
Re: Shorten PC-Name and set to variable

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.


Richard H.Administrator
(KiX Supporter)
2005-03-16 04:03 PM
Re: Shorten PC-Name and set to variable

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


bene
(Fresh Scripter)
2005-03-16 04:17 PM
Re: Shorten PC-Name and set to variable

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


bene
(Fresh Scripter)
2005-03-16 04:35 PM
Re: Shorten PC-Name and set to variable

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?


Les
(KiX Master)
2005-03-16 04:40 PM
Re: Shorten PC-Name and set to variable

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.


bene
(Fresh Scripter)
2005-03-16 04:56 PM
Re: Shorten PC-Name and set to variable

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


Les
(KiX Master)
2005-03-16 05:09 PM
Re: Shorten PC-Name and set to variable

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


bene
(Fresh Scripter)
2005-03-16 05:38 PM
Re: Shorten PC-Name and set to variable

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?


LonkeroAdministrator
(KiX Master Guru)
2005-03-16 05:42 PM
Re: Shorten PC-Name and set to variable

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


bene
(Fresh Scripter)
2005-03-16 05:54 PM
Re: Shorten PC-Name and set to variable

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


NTDOCAdministrator
(KiX Master)
2005-03-16 05:59 PM
Re: Shorten PC-Name and set to variable

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




Les
(KiX Master)
2005-03-16 06:13 PM
Re: Shorten PC-Name and set to variable

Would not the line:
If $Admin
return true regardless of 'Yes' or 'No'?


NTDOCAdministrator
(KiX Master)
2005-03-16 06:23 PM
Re: Shorten PC-Name and set to variable

Yes, you're correct Les. Thanks

I corrected the code above.


bene
(Fresh Scripter)
2005-03-17 03:12 PM
Re: Shorten PC-Name and set to variable

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


LonkeroAdministrator
(KiX Master Guru)
2005-03-17 04:12 PM
Re: Shorten PC-Name and set to variable

what version of kix you have, btw?
in some newer version there was problem with the set...


bene
(Fresh Scripter)
2005-03-17 04:52 PM
Re: Shorten PC-Name and set to variable

i had 4.22, since yesterday i use 4.23. perhaps, that was an other problem ...