#197417 - 2010-01-18 07:45 PM
Couple script issues.
|
Tsguy
Getting the hang of it
Registered: 2010-01-18
Posts: 67
Loc: Oregon
|
Hello Kix folks.
Am trying a fairly simple check in script for the existence of two files, I get the feeling my syntax is wrong as the script just runs right through it, or if $variable1 exists it displays the messagebox.
Script sample:
$variable1="c:\@userid1.txt" $variable2="c:\@userid2.txt" $Message="You have both files"
IF EXIST ("$variable1") AND ("variable2") Mesasgebox ("$message", "***You have both files***",0,10) Exit ENDIF
END script sample
There's a variety of other things going on in this script, but the result of this file check is important for the rest of the script processing.
Additionally, I have another minor problem with trying to use "RUN" to launch a CMD script. The CMD script has a "wait" in it, and that in turn is keeping the Kix script which launched it open.
To quote the manual....
This behavior is different from the MS‑DOS – based version of KiXtart, where the RUN command also terminates the script. If you want to emulate the MS‑DOS – based version, you must add an EXIT command after the RUN command
So if I'm using:
RUN "c:\scripts\file.cmd" Exit
where does the Exit fit in? I have it the line after and it's not being picked up.
Thanks much,
TS
|
Top
|
|
|
|
#197421 - 2010-01-18 10:33 PM
Re: Couple script issues.
[Re: Glenn Barnas]
|
Tsguy
Getting the hang of it
Registered: 2010-01-18
Posts: 67
Loc: Oregon
|
Thanks for the feedback Glenn.
The brief background on what I'm trying to accomplish:
We launch an application for end users via a Kix script which makes environment (prod / qa / dev) type modifications to an INI file before running the app EXE.
We've found out that several staff are running up to 4 copies of the application EXE, and I've gotten authorization to limit them to only 2 copies of the EXE.
So what I'm looking to do with the Kix script mods is essentially EXE count tracking. By creating a txt file each time a user launches the application EXE, and deleting the created txt file each time a user closes the EXE.
The script logic for creation of the txt files and checking for existing txt files prior to launching the application EXE was what I was looking to get sorted out with the 'EXIST / AND' statements. I'm actually going to redo that section in 'select - case' format as it seems a better fit than 'IF'.
With regards to the RUN issue, my problem is this logic:
If $File1 = 1 AND $File2 = 0
copy "c:\scripts\session.txt" "$variable2"
RUN "c:\scripts\session2.cmd" EXIT
ENDIF
The CMD file being referenced has the following in it:
Start "Application" /wait C:\application\app.exe \\servername\share\app.ini
del \\servernameb\share\session2.txt /q
exit
I'm using the '/wait' in order to keep the CMD file running so that once the EXE is closed the DEL will trigger and clear the session tracker txt.
I know a CMD will be open under the user session because of this, what I've found in /debug however is that using RUN to call the CMD file doesn't exit out the kix script as I would have expected. The kix script is instead waiting for the CMD file that's been called complete before it exits.
This is not a huge problem, however I would prefer that the kix script call the CMD file used the run the app, and then close out without waiting for it to end.
Thanks,
TS
|
Top
|
|
|
|
#197422 - 2010-01-18 11:52 PM
Re: Couple script issues.
[Re: Tsguy]
|
Tsguy
Getting the hang of it
Registered: 2010-01-18
Posts: 67
Loc: Oregon
|
By the way I've tried the modification you mentioned and am seeing the same behavior in /debug. The RUN command calls the script properly, but the Kix script waits for the batch script to finish processing before it closes out.
SELECT
Case $File1 = 1 AND $File2 = 0
Copy "c:\scripts\session.txt" "$variable2"
RUN $CMD2
Exit 0
END SELECT
The rest of the script works very well. Thanks for the assistance.
TS
|
Top
|
|
|
|
#197423 - 2010-01-19 01:29 AM
Re: Couple script issues.
[Re: Tsguy]
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Yo TS,
Well.. There is somebody from my neck of the woods..
For one conditional check, why are you using a SELECT..CASE?
If you need to do a conditional check and need to to find the first true condition, then I can see the point.. This should work for you..
IF $File1 = 1 AND $File2 = 0
Copy "c:\scripts\session.txt" "$variable2"
RUN $CMD2
Exit 0
ENDIF
HTH,
Kent
|
Top
|
|
|
|
#197425 - 2010-01-19 02:33 AM
Re: Couple script issues.
[Re: Kdyer]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
In a word.. ugh!
Using files to track system processes is like herding cats - possible, but you don't really want to.
I'll dig up some code I have and post it in a bit, but here's something to consider:
- Use a process-list UDF to determine how many processes are running
- If the number of processes is 0 or 1, allow the new process to start
- If the number of processes is 2, display a warning and exit
- No file cleanup, no mess if the ap terminates abnormally, and totally dynamic
I have an application that allows up to 25 sub-processes to run to communicate with remote systems. Any number of the 160+ servers can requests service, but only 25 at a time are allowed to run. I take it a step further and correlate which process is used to communicate with which server, and check every few seconds to see if a process has ended. If it is no longer in the list, I perform some wrap-up, and allow another process to start if any are in the queue. It sounds like what you want to do is 23 times simpler. $aProcessList = WMIProcessList('appname')
If UBound($aProcessList) < 1
Run 'app.exe args'
Else
'Sorry - can only run two instances of "appname"!' @CRLF
EndIf is really about all you'd need.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#197434 - 2010-01-19 05:24 PM
Re: Couple script issues.
[Re: Glenn Barnas]
|
Tsguy
Getting the hang of it
Registered: 2010-01-18
Posts: 67
Loc: Oregon
|
Glenn you da man!
I was initially looking to do a process count directly but couldn't see a way to do it, so I came up with the text file creation / deletion plan.
I'll get the posted code tested shortly.
Kyder, sorry for any confusion. I posted only the first portion of the select / case structure.
TS
|
Top
|
|
|
|
#197435 - 2010-01-19 05:37 PM
Re: Couple script issues.
[Re: Tsguy]
|
Tsguy
Getting the hang of it
Registered: 2010-01-18
Posts: 67
Loc: Oregon
|
K well that didn't work so well on first test.
$AppTracking = WMIProcessList ('appname.exe')
If UBound ($AppTracking) < 1
Run "C:\appname\app\app.exe $app\app.ini"
exit
Else
MessageBox ("$Message"," ***You are not allowed to run more than two App sessions*** ",0,10)
ENDIf
allowed me to launch 3 exes.
TS
|
Top
|
|
|
|
#197441 - 2010-01-19 06:50 PM
Re: Couple script issues.
[Re: Tsguy]
|
Tsguy
Getting the hang of it
Registered: 2010-01-18
Posts: 67
Loc: Oregon
|
I have tried the newest release of Kix and receive the same line error.
I should probably mention that the server this is being tested on is a windows 2003 terminal server. So the EXE being looked for will be running under multiple user sessions:
If you specify a name, all processeses matching that name will be returned,
That comment from the remarks of the UDF concerns me, as it sounds like the script would return all EXE's under all user sessions, vs just the EXE's run by the user executing the script.
From command line the following does get the output specific to the EXE I want and only the user that runs it, I just couldn't figure out how to parse the results within Kix.
tasklist /FI "Imagename eq app.exe"
|
Top
|
|
|
|
#197459 - 2010-01-20 06:12 PM
Re: Couple script issues.
[Re: Glenn Barnas]
|
Tsguy
Getting the hang of it
Registered: 2010-01-18
Posts: 67
Loc: Oregon
|
Glenn,
Thanks again for the major assist here, feels like we're close. Tried the last bit of code and it steps right through debug no probs, but after two exe's are running it doesn't hit the "ELSE" condition, it just launches a third.
Full script code below (some comments removed, all code posted). The latest code is added at the bottom of the script. I did make some minor adjustments.
SetConsole("HIDE")
; Declaring variables
;
; PZB = defines what PZB path will be set within CER.ini
; CER = defines where our user's CER.ini file is saved too, and looked for
; PFX = defines the value for PFX for claimsview
; MENU = defines the value for Menu for Claimsview
;
$pzb="\\root\Production$$"
$cer="\\root\userconfigs$$\@userid\Production"
$pfx="0001"
$Menu="Y"
;
;
$Message=" You are not allowed to run more than two copies of OurApp. "
; Checking for Cer.ini, copying it if it's not there.
;
IF NOT Exist ("\\root\userconfigs$$\@userid")
MD "\\root\userconfigs$$\@userid"
EndIf
;
IF NOT Exist ("$cer\cer.ini")
MD "$cer"
Copy "\\root\cer$$\cer.ini" "$cer"
writeprofilestring ("$cer\cer.ini", "System", "PzbPath", "$pzb")
EndIf
;
writeprofilestring ("$cer\cer.ini", "CLAIMVIEW", "PFX", "$pfx")
writeprofilestring ("$cer\cer.ini", "ClAIMVIEW", "MENU", "$menu")
;
;
$MaxSess=2
$Tasklist='tasklist /FI "Username eq %USERDOMAIN%\%USERID%" /FI "Imagename eq App.exe"'
$aResult=WshPipe($Tasklist)
;
If UBound($aResult) < ($MaxSess +1)
Run "C:\appname\app\app.exe $cer\cer.ini"
Else
MessageBox ("$Message"," ***You are not allowed to run more than two App sessions*** ",0,10)
EndIf
;
Exit
TS
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 980 anonymous users online.
|
|
|