1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Support' started by mathewsdw, Jan 16, 2013.

  1. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    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?
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,777
    Likes Received:
    29
    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.
     
  3. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    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...
     
  4. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    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.
     
  5. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    638
    Likes Received:
    6
    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
     
  6. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    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.
     

Share This Page