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

SignUp Now!

retrieving variable from system

I use set /s /e aaa=1234 to store aaa as system so it persists eg after stopping & restarting. This also puts it into current environment. So far, so good. But I cannot see how, if the value in current environment is lost or zapped to retrieve the value of aaa from the system eg so that echo %aaa gives 1234 because only set seems to have the /s switch. Did I miss something?

Thanks - you were right - finger trouble. It is a fix - thanks again!

It is rather ugly fix imo & not documented eg under set so impossible to find w/o forum/you. Looks as if there ought to be a another eg /g for get switch on set so set /g /s xx gets xx from system, then it could be logically documented under set.

Keep in mind John, that each process gets its own copy of the environment created by merging the System, User, and Volatile environments from the registry. SET /S (or /V or /U) modify the registry but don't do anything for existing processes. Adding the /E switch forces an update of the local environment.

If the Update Environment on System Change configuration option is set, TCC will monitor the WM_SETTINGCHANGE message and update the environment from the User, Volatile, and System registry entries. The update is done whenever TCC displays the prompt (to prevent the environment from changing in the middle of a command).
Thanks for info.

There is another small problem with use of set aaa=%@execstr[set /s aaa]
If the variable isn't in the /s environment it creates the message 'aaa not in environment'.

1) I'd like to get rid of that message and flag the error - don't think %_? works
2) the value aaa gets in this case is whatever value it may have in the /e environment not nul as one might expect so this is a bit dangerous
3) can't tell what variables are in the /s environment ie no equivalent to set xx which shows all variables starting with xx

Any ideas to fix these welcome.
You can use FFIND to filter the output. For example to find all the System environment variables that begin with VC:
set /s | ffind /e"^VC" /v

Using a similar approach you can assign a local variable:
set aaa=%@execstr[set /s | ffind /e"^aaa=" /v /km]
Thanks for info.

There is another small problem with use of set aaa=%@execstr[set /s aaa]
If the variable isn't in the /s environment it creates the message 'aaa not in environment'.

How about ...

set aaa=%@execstr[set /s aaa >&> nul]
No, normally there are too few variables to bother with filtering. SET /S, however, works, and displays ALL system variables. You can filter it a a second step.

There is a full solution to your issue, the @GEV function in Vincent Fatica's plug-in 4UTILS.DLL; you can download it as ftp://lucky.syr.edu/4plugins/4utils.zip. Once you expanded the zip file and loaded it as a plug-in, type uhelp @gev.
Plain old HELP works too.
v:\> help @gev
@GEV[name[,s|u|v|d]] = value of [registry] environment variable

v:\> set /u foo=bar

v:\> echo %@gev[foo,u]
Thanks to you all for the help - I've implemented the filtering with set /s suggested, and modified it to enable selective deletions from /s

Just like to pass on this - to get rid of the not in environment message & detect w/o using the filtering whether the /s variable is there avoiding the issue that if not there the value is left at whatever the current value is - dangerous!

rem ^ is separator
rem this removes the message but removes the answer too in case of error!
set /s x=%@execstr[set /s aaa > & nul^echo err:%_?]

rem error so ensure x is null or some other error value
if x==err:2 (set x=^echo -var not in /s)

rem we know aaa is there so get it!
if x ne err:2 set /s x=%@exec[set /s aaa]