retrieving variable from system

Apr 1, 2013
22
0
#1
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?

John
 
Apr 1, 2013
22
0
#5
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.

John
 

samintz

Scott Mintz
May 20, 2008
1,294
11
Solon, OH, USA
#6
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).
 
Apr 1, 2013
22
0
#7
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.
John
 

samintz

Scott Mintz
May 20, 2008
1,294
11
Solon, OH, USA
#8
You can use FFIND to filter the output. For example to find all the System environment variables that begin with VC:
Code:
set /s | ffind /e"^VC" /v
Using a similar approach you can assign a local variable:
Code:
set aaa=%@execstr[set /s | ffind /e"^aaa=" /v /km]
 
#10
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.
 
Apr 1, 2013
22
0
#12
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]
...

John