Page 1 of 2 12>
Topic Options
#25886 - 2002-07-25 10:46 PM Problems with ReadLine @WKSTA
WeakLink Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 37
Loc: San Diego
Hi All, it's me again.

I have been tasked with converting a logon.bat into KIX (which I am a novice at best). The login.bat currently checks a txt file to see if a PC exists in this file. If it does, it exits....if it doesn't exist, it runs the bat file. It also sends email if the user selects not to run the bat file (I found some info that Bryce posted for BLAT that I will try).

So here's what I have tried:

FIRST TRY
;Open(3, @WKSTA + "\uk-scripts\exclude.txt", 3) = 0
;If @ERROR=0
;$X=ReadLine(3)
;IF $X = @WKSTA
; GOTO END
; ELSE
; $Message = "It works!"
; ENDIF
;:END
SECOND TRY
$Value = "\uk-scripts\exclude.txt" + @WKSTA"
If Open(1, $Value) = 0
$Read = ReadLine(1)
CLOSE(1)
IF $Value = $Read
GOTO END
ENDIF
ELSE
$Message = "It works!"
ENDIF
:END
THIRD TRY
IF Open(1, "\uk-scripts\exclude.txt") = 0
$x = Readline(1)
WHILE @ERROR = 0
IF InStr($x, @WKSTA)
CLOSE(1)
GOTO END
ENDIF
ELSE
$Message = "It works!"
ENDIF
:END

I'm sure this is simple enough, but I'm at my wits end and don't have any hair left.

Top
#25887 - 2002-07-25 10:57 PM Re: Problems with ReadLine @WKSTA
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What's not clear is the location of the "exclude.txt" file. Is its content just the WKSTA name on the first line?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25888 - 2002-07-25 11:05 PM Re: Problems with ReadLine @WKSTA
Donald_99a Offline
Fresh Scripter

Registered: 2002-03-02
Posts: 6
Loc: Karlsruhe, Germany
I think the rigt way is :

IF Open(1, "\uk-scripts\exclude.txt") = 0 ; better is the complete URL like \\SHARENAME\XX
$x = Readline(1)
WHILE @ERROR = 0
IF $x = "@WKSTA"
CLOSE(1)
GOTO END
EndIf
$x = Readline(1)
LOOP
ELSE
$Message = "It works!"
ENDIF
:END

You can write in the textfile a List with Workstations

-- Donald --

Top
#25889 - 2002-07-25 11:06 PM Re: Problems with ReadLine @WKSTA
WeakLink Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 37
Loc: San Diego
Les,

If you are asking for the "physical" location of the file, it is located in the netlogon\uk-scripts directory.

I suspect though you are asking if the file contains only one line....the file looks like this:

PC-1
PC-2
PC-3
etc.

So no, the @WKSTA is not necessarily on the first line.

Top
#25890 - 2002-07-25 11:06 PM Re: Problems with ReadLine @WKSTA
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm...
about that user deciding not to run.
normally, if kix is stopped forcebly it logs out the user so dunno if it's needed to send mail as it's allways run on logon.
_________________________
!

download KiXnet

Top
#25891 - 2002-07-25 11:10 PM Re: Problems with ReadLine @WKSTA
WeakLink Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 37
Loc: San Diego
Sorry Lonkero, I wasn't clear. Within the script the user has a choice of either running the script (yes) or not (no). The script will then send an email to the administrator stating the user refused to run the script.
Top
#25892 - 2002-07-25 11:16 PM Re: Problems with ReadLine @WKSTA
WeakLink Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 37
Loc: San Diego
The suggestion Donald had didn't seem to work either. Could it be the batch file that's calling the kix file?

%0\..\kix32.exe %0\..\uk-scripts\test.kix

Top
#25893 - 2002-07-25 11:24 PM Re: Problems with ReadLine @WKSTA
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm...
donalds suggestion was pretty good.

something like:
$nul=open(1,@ldrive+"\uk-scripts\exclude.txt")
$machine=readline(1)
while @error = 0
if @wksta = trim($machine)
"wksta is to be excluded, quitting..."
exit 0
endif
$machine=readline(1)
loop

this continues execution if not in list of excluded machines. if in the file, exits.

cheers.
_________________________
!

download KiXnet

Top
#25894 - 2002-07-25 11:34 PM Re: Problems with ReadLine @WKSTA
WeakLink Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 37
Loc: San Diego
Okay guys, IF this script is working, I should get a message "wksta is to be excluded, quitting..."
IF the @WKSTA is NOT in the file, correct?

Top
#25895 - 2002-07-25 11:50 PM Re: Problems with ReadLine @WKSTA
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
no, when it's in the file, you get the message.

to be more specific, if there is line which has only the machine name in it, you get the message and script execution stops.

[ 25 July 2002, 23:52: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#25896 - 2002-07-25 11:59 PM Re: Problems with ReadLine @WKSTA
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Convert your text file into an .INI fiel and use READPROFILESTRING, it'll greatly reduce the lines of code and make it easier to code.

For example:
code:
;exclude.ini
; exclude the PC if value=1
[Exclude]
PC-1=1
PC-2=1
PC-3=1
PC-4=0

code:
IF VAL(READPROFILESTRING(@ldrive+'\uk-scripts\exclude.ini','Exclude',@WKSTA))=1
; this computer gets excluded
; exit the script gracefully
EXIT 0
ELSE
; do what needs to be done
ENDIF



[ 25 July 2002, 23:59: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#25897 - 2002-07-26 05:56 PM Re: Problems with ReadLine @WKSTA
WeakLink Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 37
Loc: San Diego
Okay, first I would like to thank everyone for their input, I do appreciate it.

I tried the solution Sealeopard suggested:

IF VAL (READPROFILESTRING(@LDRIVE+'\uk-scripts\exclude.ini','Exclude',@WKSTA)) = 1
EXIT 0
ELSE
"It works!"
ENDIF

and now at least I get the message, but I get it regardless of if the PC is excluded or not. I created the exclude.ini, added the PC's with = 1. The bat file that calls it goes:

@echo off

%0\..\kix32 %0\..\test.kix

pause

Could it be the version of kix that I'm running? 3.62?

Any help would be appreciated. Again, thx all!

Top
#25898 - 2002-07-26 06:04 PM Re: Problems with ReadLine @WKSTA
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
no, the version should not matter as those are really old functions you are using.
%0-call does not work properly for xp but that also is another thing.

what I would change is your @ldrive.
it may have some problem.
I would go for @scriptdir instead.
the value checking can also be problematic and I would go other way. changing the exclude to either zero or even string similar to yes.
so the if line would get to:
IF READPROFILESTRING(@LDRIVE+'\uk-scripts\exclude.ini','Exclude',@WKSTA)) = "yes"

cheers...
_________________________
!

download KiXnet

Top
#25899 - 2002-07-26 06:40 PM Re: Problems with ReadLine @WKSTA
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If you just do a READPROFILESTRING(@LDRIVE+'\uk-scripts\exclude.ini','Exclude',@WKSTA), what is the return value?
_________________________
There are two types of vessels, submarines and targets.

Top
#25900 - 2002-07-26 08:04 PM Re: Problems with ReadLine @WKSTA
WeakLink Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 37
Loc: San Diego
When I tried READPROFILESTRING(@LDRIVE+'\uk-scripts\exclude.ini','Exclude',@WKSTA), I didn't get a response at all.

I ran it from the command line and received: script error : unable to find/open script !

And calling it from a bat file produced nothing

Top
#25901 - 2002-07-26 08:10 PM Re: Problems with ReadLine @WKSTA
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
[Confused] [Confused] [Confused]

What I wanted to know is what the return value of the READPROFILESTRING is before you even do the IF comparison. Therefore, the modified script would be something like this:
code:
$a=READPROFILESTRING(@ldrive+'\uk-scripts\exclude.ini','Exclude',@WKSTA)
IF @ERROR
? 'Error encountered : '+@ERROR+' - '+@SERROR
ELSE
? 'Value = '+$a
ENDIF
IF VAL($a)=1
; this computer gets excluded
; exit the script gracefully
EXIT 0
ELSE
; do what needs to be done
ENDIF

I hope this makes it more clear.

[ 26 July 2002, 20:10: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#25902 - 2002-07-26 08:41 PM Re: Problems with ReadLine @WKSTA
WeakLink Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 37
Loc: San Diego
Lonkero,

I tried your solution and still get the same result: "It works!" is the reply I get whether it value is true or not. I tried 1, 0, yes and it was all the same result. I also subbed the @scriptdir with the same results.

SeaLeopard,

I tried your solution and the value = it works!

$a=READPROFILESTRING(@ldrive+'\uk-scripts\exclude.ini','Exclude',@WKSTA)
IF @ERROR
? 'Error encountered : '+@ERROR+' - '+@SERROR
ELSE
? 'Value = '+$a
ENDIF
IF VAL($a)=1
EXIT 0
ELSE
"It works!"
ENDIF

Top
#25903 - 2002-07-26 09:30 PM Re: Problems with ReadLine @WKSTA
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
this means that the wksta name wasn't in there...
_________________________
!

download KiXnet

Top
#25904 - 2002-07-26 09:41 PM Re: Problems with ReadLine @WKSTA
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Run this code:
code:
$a=READPROFILESTRING(@ldrive+'\uk-scripts\exclude.ini','Exclude','')
$a=split($a,chr(10))
for each $comp in $a
$b=READPROFILESTRING(@ldrive+'\uk-scripts\exclude.ini','Exclude',$comp)
? 'Computer = '+$comp+' and has assigned value ='+$b
next

This will give you the list of computers in the .INI file and their associated values.

BTW, these scripts are so simple that I really have no idea what you can do wrong except maybe have spelling errors. Thus, check for spelling errors, since the code does work for me.

[ 26 July 2002, 21:41: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#25905 - 2002-07-26 10:33 PM Re: Problems with ReadLine @WKSTA
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Maybe the INI file's not right. Show us the INI contents.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

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 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.239 seconds in which 0.158 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