Welcome!

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

SignUp Now!

TCC at Windows Startup

TCC 19 x64 on WIN 10 PRO x64. TCC (with a startup script [.btm]) is in the Windows Startup folder. Both .btm and .bat files are associated with TCC.

Windows (since at least 7), using Group Policy Editor, allows setting script files to run at startup, shutdown, logon, and logoff. I've been experimenting with these scripts, using .btm files, but the results are puzzling. A couple of ideas I have been playing with, as reason for using these files:

With these scripts, one can write to a log file, the date/time of startup, shutdown, logon, and logoff.

Windows (since 7?) no longer allows changing the startup sound, which is hard-coded into a .dll; one can turn it on/off only. There is a utility out on the web to change that hard-coded sound. But, without modifying any Windows files, one can turn off the built-in sound, and then use the startup script to play another sound of one's choice.

A little help would be appreciated:

1. Since these .btm files are associated with TCC, does this mean that Windows is running a transient TCC shell at startup (before logon), and at logon (before the startup folder starts the shell I see) (as well as at logoff and shutdown)? Or is it using CMD.EXE?

2. What commands should be available at these times; all external commands; as well as either TCC internal commands, or just CMD.EXE internal commands? I.e. should playsound be available? If so, would it be more desirable to run it synchronous or asynchronous?

3. Should any environment variables created by these scripts at startup/logon, be visible to the shell that runs from the startup folder? From what I am seeing, they are not.

An example with a current startup.btm:
Code:
:: Ping the NAS to begin spinning up.
ping DS410

:: playsound /a "C:\Windows\Media\Profile\Startup.wav"
C:\path\sWavPlayer.exe "C:\Windows\Media\Profile\Startup.wav"

set BOOTTIME=%_date %_time
set SYS_LOG=C:\path\logfile
echo %BOOTTIME System Startup >>! %SYS_LOG
Pinging the NAS, besides being useful, is at the top to use up some time. Changing the order, changes the results.

sWavPlayer is a free, small, zero-interface utility from somewhere on the web (I can find it again, if anyone wants to know). Trying to using playsound gives different results.

Depending on the order of script lines, the timestamp line may or may not appear in the logfile. In the version above, it does appear correctly, meaning that the environment variables were both successfully created and used; BUT those variables do not exist when the startup-folder shell starts. Also, since the timestamp is correct, it seems that %_date and %_time are available, so it must be TCC running?

With a logon script similar to the above in place, what happens is that both the startup timestamp and the logon timestamp appear in the logfile, and both the startup sound and the logon sound play. However, the logon sound plays before the startup sound, and the logon timestamp appears in the logfile before the startup timestamp. This I attribute to the few seconds delay caused by pinging the NAS.

But, if the timestamping is done first, it doesn't appear in the logfile; and if the sound is played first, it doesn't actually play. So there are timing issues which are not clear to me.

Any thoughts?
 
Here are the first few lines of my system startup file:
Code:
@echo off
rem File C:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Startup\SYSSTARTUP.BAT, 30-Jul-2016 00:03 EDT
if %@eval[2+2]==4 goto tccstarthere
"C:\Program Files\JPSoft\TCMD\tcc.exe" /isx /c %0 %*
exit /b %ERRORLEVEL%
:tccstarthere
I hope this helps.
 
Hmm... it's a bit puzzling: since 2 + 2 does = 4, it looks as though you will always jump to tccstarthere. If, on the other hand, the tcc.exe line were ever executed, it seems that it is looking for command line parameters to the batch file -- how does one pass parameters to the Windows startup batch file?

In the case of the Windows startup, shutdown, logon and logoff script files, does it make any difference whether they are .btm or .bat files?
 
If @[2+2] is not 4 that means it's running under CMD so he starts TCC.
 
Thank you! Makes perfect sense.

Since %_date and %_time are not available in CMD.EXE (is that correct?), that would confirm that in my case it is TCC that is running, which makes sense, since .btm and .bat are associated with TCC. Therefore, playsound should be available. But, better synchronous or asynchronous?

BUT, why are environment variables that are set in the Windows startup and logon scripts, not visible to other TCC shells which are started later? Are they not being set in Windows own environment, which should get passed to TCC when started in the Windows startup folder? Or, do we need shralias loaded in the Windows startup instance of TCC? EDIT: No, since shralias doesn't affect environment variables, so the question above still stands.
 
Last edited:
Right. They are not being set in any (permanent) Windows environment. Each process has its own environment, typically inherited from its parent process. Parentless processes (I'm guessing WINLOGON.EXE) get a combination of the system environment and the user environment (both kept in the registry). If you want to set variables at startup which will be seen by future TCCs (and all other processes) use "SET /S" or "SET /U". But that needs to be done only once (not at every startup or logon); it's equivalent to setting variables in ControlPanel\System\Advanced\EnvironmentVariables.

If you want variables that only TCCs see, that can be done in TCSTART.BTM.

For example, my PROMPT, PROMPT2, and TITLEPROMPT variables are (permanently) kept in the user environment.
 
Thank you. So, if I now:
SET /S BOOTTIME=something
SET /U LOGONTIME=somethingelse
this will create those variables in the registry, which will then be part of the permanent environment that gets passed to all shells;

and then in startup.btm
SET BOOTTIME=%_date %_time

and in logon.btm
SET LOGONTIME=%_date %_time

will the changes made by startup.btm/logon.btm be visible to future TCC shells?
 
Thank you. So, if I now:
SET /S BOOTTIME=something
SET /U LOGONTIME=somethingelse
this will create those variables in the registry, which will then be part of the permanent environment that gets passed to all shells;

and then in startup.btm
SET BOOTTIME=%_date %_time

and in logon.btm
SET LOGONTIME=%_date %_time

will the changes made by startup.btm/logon.btm be visible to future TCC shells?
Simply, SET /S BOOTTIME in startup.btm, SET /U LOGONTIME in logon.btm and they will be in the environment of every process.

You can also get that information any time you want it with @WMI.
Code:
v:\> echo %@wmi[.,"SELECT LastBootUpTime FROM Win32_OperatingSystem"]
20160901130136.471749-240

v:\> echo %@wmi[.,"SELECT StartTime FROM Win32_LogonSession"]
20160901130218.015957-240

And my 4UTILS plugin has these.
Code:
v:\> echo %@up[b]
2016-09-01 13:01:36

v:\> echo %_sesstime
2016-09-01 13:02:18
 
v:\> echo %@up 2016-09-01 13:01:36 v:\> echo %_sesstime 2016-09-01 13:02:18
Neither _SESSTIME nor @UP are listed in the 4UTILS.TXT in the current 4utils64.zip file, and HELP _SESSTIME has a typo 'cuttent' instead of 'current'.
 
Neither _SESSTIME nor @UP are listed in the 4UTILS.TXT in the current 4utils64.zip file, and HELP _SESSTIME has a typo 'cuttent' instead of 'current'.
Thanks. My mistake! They're in the SYSUTILS plugin.
 
Thanks guys.
If you want to set variables at startup which will be seen by future TCCs (and all other processes) use "SET /S" or "SET /U". But that needs to be done only once (not at every startup or logon); it's equivalent to setting variables in ControlPanel\System\Advanced\EnvironmentVariables.
Was confused by this, but then:
Simply, SET /S BOOTTIME in startup.btm, SET /U LOGONTIME in logon.btm and they will be in the environment of every process.
Got it. So this is now good.
You can also get that information any time you want it with @WMI.
Code:
v:\> echo %@wmi[.,"SELECT LastBootUpTime FROM Win32_OperatingSystem"]
20160901130136.471749-240

v:\> echo %@wmi[.,"SELECT StartTime FROM Win32_LogonSession"]
20160901130218.015957-240

And my 4UTILS plugin has these.
Code:
v:\> echo %@up[b]
2016-09-01 13:01:36

v:\> echo %_sesstime
2016-09-01 13:02:18
Good info! Guess I'm re-inventing the wheel as I learn.

So, I downloaded your x64 utilities [thanks for making them available to Canada; I saw an old post that your server was only available in U.S.] and will have a look at them.

Still having timing issues. An abbreviated shutdown.btm:
Code:
set STOPTIME=%_date %_time
echo %STOPTIME System Shutdown >>! %SYS_LOG

:: playsound "C:\Windows\Media\Master\Shutdown.wav"
C:\Applications\Utility\Console\sWavPlayer.exe "C:\Windows\Media\Master\Shutdown.wav"
was working fine. Yesterday, I commented sWavPlayer.exe, and uncommented playsound in all four files; this morning, in the logfile, there is no shutdown line from yesterday. Logoff is there, and this morning's startup and logon are there (in reverse order!). All four sounds played.

One other tiny thing I noticed: using set to display the environment, the variables are listed in alphabetical order; displaying with set /d /s /u or /v, they are not sorted. Would be nice if they were.
 

Similar threads

Back
Top