Page 1 of 1

Modifying XY's Environment

Posted: 08 Feb 2015 17:18
by klownboy
In the past, if I set an environmental variable either in the control panel or using the "setx" command I would see it under Help | Environmental Variables at least after a restart of XY. For example, the following code will set the environmental variable in the local environment (use the /m switch to set it in the system) and you'll see it immediately in the Control Panel.

Code: Select all

run "cmd /c /q set MYVAR= & setx MYVAR PizzaMan",,0,0; 
Take a look at what I reported back 2 years ago User Environmental Variable Refresh For some reason now I don't see those in XY's listing of environmental variables. Though it's clearly exists in the Control Panel's listing of environmental variables. It's there whether I make a local or system environmental variable, but it's not in XY's listing. I was curious this morning after seeing TheQwerty's post above so I started experimenting. It's quite easy to make a local or system environmental variable, but the issue was 2 years ago that XY wouldn't recognize it without a restart. Now for some reason it doesn't recognize them at all. I was hoping that a way to resolve this issue of using environmental variables throughout the system might be for Don to recognize newly set environmental variables by performing a environmental refresh cid #505 and not require a restart.

Edit : I noticed in the one line of code I had 2 different variables, the use of "set" clears the variable if it already exists, and the setx establishes a new one.

Re: Increase scope of Permananet Variable

Posted: 08 Feb 2015 18:02
by PeterH
Don't know: do I understand it correct? XY would not see all environment vars like %APPDATA% :?:

It seems my does: wrote a little test-script:

Code: Select all

 $set = RunRet("cmd /c set");

 $out = ""; $nr = 0;
 ForEach ($line, $set, <crlf>) {
   $var = GetToken($line, 1, "=");
   $val = Eval("%$var%");
   $out = "$out ".$nr++." $var = $val<tab>!! $line<crlf>";
 }
 Echo $out;
It seems to relay all %%-vars I'd think there are.
(Not really nicely formatted :roll: - make window < w i d e > )

Or do you think of something else?

Re: Increase scope of Permananet Variable

Posted: 08 Feb 2015 18:38
by klownboy
Very strange what was happening. Your script will provide the same information as the XY's Environmental Variables. I was closing XY normally and then restarting XY using a numpad key I have assigned using AutoHotkey to start XY if not already active. When I restarted XY that manner even though it was closed, the newly established environmental variable does not show up either using your script or in XY's Environmental Variables. If I restart XY normally using a taskbar button with no AutoHotkey involvement, the new environmental variable shows up just fine...very odd.

So all is well and thanks PeterH, but it would be a nice feature if XY would recognize newly established environmental variable via the Refresh Environmental Variable cid #505 without a restart. According to the Micorsoft site, these variables using setx are written to the registry. So XY obtains this information properly on a startup but not on the refresh Environmental Variables command. Too bad, it would be a nice addition if XY would recognize them without a restart. Thanks.

Re: Increase scope of Permananet Variable

Posted: 08 Feb 2015 18:43
by bdeshi
klownboy wrote:I was closing XY normally and then restarting XY using a numpad key I have assigned using AutoHotkey to start XY if not already active. When I restarted XY that manner even though it was closed, the newly established environmental variable does not show up either using your script or in XY's Environmental Variables. If I restart XY normally using a taskbar button with no AutoHotkey involvement, the new environmental variable shows up just fine...very odd.

Since the parent AHK instance did not refresh it's environment, XY opened by it still keep the old env. variables.

Usually a program takes up the environment of it's parent, it's a common OS feature (but not enforced, ed: I think).

EDIT: in turn, all (most) programs started from XY inherit it's current environment variables. This causes some trouble, especially when working with cmdline tools. :evil: I'm all for fixing the issue with #505.

Re: Increase scope of Permananet Variable

Posted: 08 Feb 2015 19:04
by klownboy
Thanks Sammay, I was figuring it was probably something along those lines. I'll have to investigate a bit further in the AHK help. There's probably an environmental parameter or setting for my AHK script I could use which would force it to refresh environmental variables. Though it probably doesn't matter unless XY is able recognize a newly established environmental variable after a "Refresh Environmental Variables" and not require a restart.

Re: Increase scope of Permananet Variable

Posted: 09 Feb 2015 11:23
by binocular222
@klownboy: My XY doen't show newly added system environment.
I tried adding via setx, via Control Panel-Advanced system setting
I tried #505 and restarted XY
Still no use. Anything tricky here?

Re: Modifying XY's Environment

Posted: 09 Feb 2015 12:59
by TheQwerty
Note: The above posts were originally in the thread: Increase scope of Permananet Variable.

-----

Keep in mind that using setx locally will not change the current environment but only future instances which when combined with most programs adopting their parent's environment can make it rather confusing to verify.

Re: Modifying XY's Environment

Posted: 09 Feb 2015 13:54
by klownboy
Hi binocular222, I was having the same problem myself and was it was driving me nuts trying to figure out why. I knew as you could see from the other post 2 years ago that when I used setx and restarted XY, I would see the new variable in XY's environment variable listing. I don't know if this will solve your problem or not, but I know you're an AHK user as well. Try starting XY directly by double clicking XYplorer.exe or on a task bar icon for it, one that does not involve AHK in any way. As Sammay had mentioned, AHK will use the same environment it read when it initially started so the XY started via AHK inherits the same environment. Let us know if that's the problem. There's probably an AHK setting/command that will start programs in the new environment.
Ken

Re: Modifying XY's Environment

Posted: 09 Feb 2015 14:08
by binocular222
Oh, got it, not involve AHK but #190 (Restart without saving) not work. I have to explicitly x-close XY then launch from double click.

Re: Modifying XY's Environment

Posted: 09 Feb 2015 14:36
by admin
Interesting. Looks like the process has to fully exit and restart to update the environment. XY's "Restart" starts the new process from within the old one, and it seems to inherit the old environment without updating it.

Re: Modifying XY's Environment

Posted: 09 Feb 2015 14:37
by klownboy
I doesn't seem to matter at all whether you save settings in XY. Which make sense since using setx on the environment doesn't require XY to be saved unless you have some other reason to save it. I've tried all the different SC 'exit' parameters including the restart ones and none of them will have the newest environmental variables. So all the exit and restarts only inherent the old set of environmental variables. As you know using environmental refresh also doesn't work. So currently for XYplorer to recognize the newly set system or local variable, se have to exit XY (with or without saving) and restart by executing the XYplorer.exe. So it boils down to, it would be great to have one restart or even better the "Environmental Refresh" that would actually reread the environment as XY does when started from scratch.

Re: Modifying XY's Environment

Posted: 09 Feb 2015 14:51
by admin
Made some experiments but no lock. Seems to be quite difficult. Lo prio I'm afraid.

Re: Modifying XY's Environment

Posted: 02 Feb 2025 13:19
by MBaas
Almost 10yrs have gone by and I only ran into this issue today!

Has anything happened meanwhile wrt refreshing XY's environment? I could use that now ;) :beer:

Re: Modifying XY's Environment

Posted: 02 Feb 2025 15:11
by admin
No, the situation did not change with Windows 11.

Re: Modifying XY's Environment

Posted: 02 Feb 2025 15:27
by MBaas
Too bad. Bloody windows. Hopefully twinBasic provides features to deal with that problem...