A_WinDir bug ... Topic is solved

Report problems with documented functionality
JBensimon
Posts: 22
Joined: 19 Nov 2017, 11:19

A_WinDir bug ...

Post by JBensimon » 08 Apr 2020, 10:12

... or so I'd consider it!

However AutoHotkey retrieves the Windows directory path to set A_WinDir (based on the result, I'm guessing it's via the GetWindowsDirectory API function) gives what is probably not the intended answer in Terminal Services (aka Remote Desktop Services) sessions running in the normal "Execute Mode", as opposed to the administrative "Install Mode": it returns the so-called "private" Windows directory path, which generally corresponds to %HomeDrive%%HomePath%\Windows (or to %HomeDrive%\Windows when the home directory is mapped to a drive letter). This private Windows directory is a legacy concept designed to capture INI files written/read via the WritePrivateProfileString/GetPrivateProfileString functions without a fully-qualified INI path. It contains no Windows executables, so any references to EXEs, DLLs, etc. using A_WinDir would fail in remote sessions.

The correct (in my view) function to retrieve the true Windows directory under all circumstances is GetSystemWindowsDirectory, as described in its documentation.

The current workarounds to this issue are, without #NoEnv, to use %WinDir% or %SystemRoot%, and with #NoEnv, to read the PathName entry at "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" or to explictly use the above-mentioned GetSystemWindowsDirectory.

See my long post in the old forums for more details about Terminal Services' Install vs. Execute modes and how they affect system behavior, including that of API functions like GetWindowsDirectory: https://autohotkey.com/board/topic/14700-terminal-server-awareness-flag-bad-idea/

JB

lexikos
Posts: 6968
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: A_WinDir bug ...

Post by lexikos » 10 Apr 2020, 20:09

I think it qualifies as a bug, and will be changing it.

If %WinDir% works without #NoEnv, wouldn't EnvGet be a much simpler workaround than reading from the registry?

JBensimon
Posts: 22
Joined: 19 Nov 2017, 11:19

Re: A_WinDir bug ...  Topic is solved

Post by JBensimon » 02 Aug 2020, 14:14

Yes, much simpler. I'm not yet fully converted to #NoEnv (lots of old code to worry about), so I sometimes forget about EnvGet.

I see this issue is fixed in v1.1.33.x, as is the FileGetShortcut/FileCreateShortcut icon resource ID issue. Thanks.

JB

Post Reply

Return to “Bug Reports”