Hi
Firstly - yes, I was incorrectly remembering what I did last month, I forgot the magic "<".
The VBS script succeeds in placing a (new) value in the environment,
BUT the CMD script cannot afterwards see it.
Actually, the CMD script can see it, but not in its own lifetime - only when it is subsequently launched in another CMD instance with a fresh copy of the environment, i.e. with a desk-top short-cut to TIMESHOW.CMD, a double click launch from the desk-top gives me
TIME is "22:48:57.96". VBSCRIPT_TIME is "82114850"
82138440
TIME is "22:48:59.54". VBSCRIPT_TIME is "82114850"
Press any key to continue . . .
the first line shows that the environment holds 82114850 created earlier
the second line is SHOWTIME.VBS announcing a NEW value of 82138440
the third line shows that TIMESHOW.BAT still sees the old value of 82114850
I am sorry for the awkward 82114850 etc. numbers - I intended for VBS to use %TIME% but was unable to get that to work, so for something dynamic I pasted in a single line "FormatNumber(timer*1000,0,0,0,0)" given to me a few weeks ago.
The New value of 82138440 was correctly put in the environment ready for the next double-click launch, i.e.
TIME is "22:49:14.02". VBSCRIPT_TIME is "82138440"
82154410
TIME is "22:49:15.50". VBSCRIPT_TIME is "82138440"
Press any key to continue . . .
and again
TIME is "22:50:33.85". VBSCRIPT_TIME is "82154410"
82234210
TIME is "22:50:35.32". VBSCRIPT_TIME is "82154410"
Press any key to continue . . .
etc. etc.
My actual code is as below
NB I used "setlocal enabledelayedexpansion" just in case it would help, but it didn't
TIMESHOW.CMD :-
@echo off
setlocal enabledelayedexpansion
ECHO TIME is "!TIME!". VBSCRIPT_TIME is "!VBSCRIPT_TIME!"
cscript /nologo SHOWTIME.VBS
ECHO TIME is "!TIME!". VBSCRIPT_TIME is "!VBSCRIPT_TIME!"
pause
exit
SHOWTIME.VBS :-
Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("SYSTEM") '
WshEnv("VBSCRIPT_TIME") = FormatNumber(timer*1000,0,0,0,0)
WScript.Echo WshEnv("VBSCRIPT_TIME")
Wscript.Quit
Regards
Alan