Modifying XY's Environment

Things you’d like to miss in the future...
Forum rules
When reporting a bug, please include the following information: your XYplorer version (e.g., v27.90.0047), your Windows version (e.g., Win 11), and your screen scaling percentage (e.g., 125%). We recommend adding your Windows version and screen scaling percentage to your profile or signature. This will make debugging much easier for us.
Post Reply
klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Modifying XY's Environment

Post 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.
Last edited by klownboy on 08 Feb 2015 20:19, edited 1 time in total.

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Increase scope of Permananet Variable

Post 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?

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Increase scope of Permananet Variable

Post 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.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Increase scope of Permananet Variable

Post 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Increase scope of Permananet Variable

Post 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.

binocular222
Posts: 1419
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

Re: Increase scope of Permananet Variable

Post 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?
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Modifying XY's Environment

Post 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.

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Modifying XY's Environment

Post 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

binocular222
Posts: 1419
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

Re: Modifying XY's Environment

Post 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.
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

admin
Site Admin
Posts: 64849
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Modifying XY's Environment

Post 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.

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Modifying XY's Environment

Post 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.

admin
Site Admin
Posts: 64849
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Modifying XY's Environment

Post by admin »

Made some experiments but no lock. Seems to be quite difficult. Lo prio I'm afraid.

MBaas
Posts: 654
Joined: 15 Feb 2016 21:08

Re: Modifying XY's Environment

Post 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:
_________________________________________________
Happy user with Screen scaling 100% and W11Pro 24H2 ;-)

admin
Site Admin
Posts: 64849
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Modifying XY's Environment

Post by admin »

No, the situation did not change with Windows 11.

MBaas
Posts: 654
Joined: 15 Feb 2016 21:08

Re: Modifying XY's Environment

Post by MBaas »

Too bad. Bloody windows. Hopefully twinBasic provides features to deal with that problem...
_________________________________________________
Happy user with Screen scaling 100% and W11Pro 24H2 ;-)

Post Reply