Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? How to determine if this is the first time that...

May
855
0
TakeCommand/TCC has run after reboot.

I have a batch file that's run by TCStart.btm that I'd like to have do something different when it is run the first time a TCC session is created after system reboot than it does in later runs. Is there any way to accomplish this?
 
TakeCommand/TCC has run after reboot.

I have a batch file that's run by TCStart.btm that I'd like to have do something different when it is run the first time a TCC session is created after system reboot than it does in later runs. Is there any way to accomplish this?
You could check that something the batch file does has been done before. For example, if one of the chores is to start SHRALIAS, the batch file could check "ISAPP SHRALIAS.EXE"
You could check for the existence of (and SET /V if necessary) a flag in the volatile environment indicating that the batch file had been run. Variables in the volatile environment disappear upon logoff.
 
Use a zero-length file as a sentinel. Use TCSTART to check if it's older than the time since system start (see _WINTICKS) and if so, do your first-time job, then use TOUCH to change the file's time stamp. Now any further invocations of TCSTART will find the file newer than system start, so the job will not be repeated. The benefit (compared with Vince's method) that the file survives repeated logging on/off without system restart, while the volatile variable would force you to execute the task after each logout/login. OTOH that may be what you really want...
 
Steve, Vince's solution is exactly what I was looking for since what I wanted to know is whether this was the first time TCStart.btm has been executed since initial log on after (re-)boot (sleep and hibernate don't count). I had a bit of trouble with it because of my habit of using SetLocal/EndLocal and that both destroyed the environment variable ("/E" on the set command) and the volatile registry entry, and I don't really know how that is accomplished. However getting rid of the SetLocal/EndLocal made things work perfectly.
 
I had a bit of trouble with it because of my habit of using SetLocal/EndLocal and that both destroyed the environment variable ("/E" on the set command) and the volatile registry entry, and I don't really know how that is accomplished. However getting rid of the SetLocal/EndLocal made things work perfectly.

Not sure if this will help, but there are two ways that I know of to keep/set environment variables after exiting a SetLocal/EndLocal pair.

From the help for EndLocal;

Code:
setlocal
set test=abcd
endlocal test

Look in the help file for the DEFER command. Example;

Code:
setlocal
defer set test=abcd
endlocal

After the batch file ends, test will still equal abcd. Take a look at my BM.BTM batch file to see how I used DEFER.

Joe
 
Steve, Vince's solution is exactly what I was looking for since what I wanted to know is whether this was the first time TCStart.btm has been executed since initial log on after (re-)boot (sleep and hibernate don't count).
AFAIK Vince's solution (using a volatile registry variable) is for EACH login. In other words, if you log out after the initial login, and log in again, the volatile registry variable will not exist, and you will reexecute the process you wanted to run only once after system start. Depending on your practice, the two may be equivalent. For example, on my desktop I normally log in only once, after system start, and just stay logged in for many days. Only on my laptop, which is sometimes used by others, do I normally log out without turning the power off.
HTH.
 
Back
Top