Does A_ComSpec point to 32-bit cmd or 64-bit cmd?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Does A_ComSpec point to 32-bit cmd or 64-bit cmd?

15 Aug 2019, 11:10

Hello,

Code: Select all

msgbox % A_ComSpec              ; C:\Windows\System32\cmd.exe
Run %A_ComSpec% /k              ; Will open C:\Windows\SysWOW64\cmd.exe
Why is the output above different on 64-bit Winodws?
What should I do if I want to run a 64-bit cmd?

Thank you.
Last edited by afe on 16 Aug 2019, 04:28, edited 3 times in total.
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: Does A_ComSpec point to 32-bit cmd or 64-bit cmd?

15 Aug 2019, 11:43

https://www.howtogeek.com/326509/whats-the-difference-between-the-system32-and-syswow64-folders-in-windows/ wrote:On 64-bit versions of Windows, you have two separate Program Files folders. But it doesn’t end there. You also have two separate system directories where DLL libraries and executables are stored: System32 and SysWOW64. Despite the names, System32 is full of 64-bit files and SysWOW64 is full of 32-bit files.
Btw, I can't reproduce your result above in the Run case. What are you exactly running?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Does A_ComSpec point to 32-bit cmd or 64-bit cmd?

15 Aug 2019, 12:05

If you run 32-bit AHK on a 64-bit PC, you need to disable file redirection, otherwise when you specify the path to the 64-bit version, it opens the 32-bit version:

Code: Select all

;note: on 64-bit PCs:
;C:\Windows\System32 contains 64-bit files (yes, *64*-bit/system*32*)
;C:\Windows\SysWOW64 contains 32-bit files (yes, *32*-bit/wow*64*)
;note: 'WoW64' stands for: Windows 32-bit on Windows 64-bit

;test file redirection
;note: this script assumes that you run 32-bit AHK on a 64-bit PC

;vPath := "C:\Windows\System32\notepad.exe"
vPath := A_ComSpec ;C:\Windows\System32\cmd.exe

DllCall("kernel32\Wow64DisableWow64FsRedirection", "Ptr*",0)
FileGetSize, vSize64, % vPath
DllCall("kernel32\Wow64RevertWow64FsRedirection", "Ptr*",0)
FileGetSize, vSize32, % vPath
MsgBox, % "32-bit: " vSize32 "`r`n" "64-bit: " vSize64
return
Link:
File System Redirector - Windows applications | Microsoft Docs
https://docs.microsoft.com/en-us/windows/win32/winprog64/file-system-redirector
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: Does A_ComSpec point to 32-bit cmd or 64-bit cmd?

16 Aug 2019, 04:40

gregster wrote:
15 Aug 2019, 11:43
Btw, I can't reproduce your result above in the Run case. What are you exactly running?
On 64-bit Windows, the result of the first command will be "C:\Windows\System32\cmd.exe" , but the second command will open "C:\Windows\SysWOW64\cmd.exe" .
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: Does A_ComSpec point to 32-bit cmd or 64-bit cmd?

16 Aug 2019, 11:33

afe wrote:
16 Aug 2019, 04:40
On 64-bit Windows, the result of the first command will be "C:\Windows\System32\cmd.exe" , but the second command will open "C:\Windows\SysWOW64\cmd.exe" .
Not on my system 🤷‍♂️
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Does A_ComSpec point to 32-bit cmd or 64-bit cmd?

16 Aug 2019, 11:45

@gregster: Here's a test script. I'd expect the paths to differ. If you get both paths the same, it might be interesting to know what OS you're using. Thanks.

Code: Select all

;test file redirection (requires 64-bit PC, 32-bit AHK)

if !A_Is64bitOS
{
	MsgBox, % "error: you must test the script on a 64-bit PC"
	return
}
if (A_PtrSize = 8)
{
	MsgBox, % "error: you must test the script with 32-bit AHK"
	return
}

vPath := "C:\Windows\System32\notepad.exe"
vPath := A_ComSpec ;C:\Windows\System32\cmd.exe
Run, % vPath,,, vPID
WinWait, % "ahk_pid " vPID
WinGet, vPPath, ProcessPath, % "ahk_pid " vPID
MsgBox, % vPath "`r`n" vPPath
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: Does A_ComSpec point to 32-bit cmd or 64-bit cmd?

16 Aug 2019, 12:17

Ah, I see , it's redirected to the 32 bit cmd.exe - I was tricked by the path in the wintitle of the cmd window that didn't reflect that.
Thanks for the hint!
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Does A_ComSpec point to 32-bit cmd or 64-bit cmd?

17 Aug 2019, 20:31

What should I do if I want to run a 64-bit cmd?
This is the easiest way.

Code: Select all

try Run %A_WinDir%\SysNative\cmd.exe
catch
    Run %A_ComSpec%
SysNative is an alias of the real System32, but is available only on Wow64 (i.e. for 32-bit programs running on 64-bit Windows).

As an alternative to try, you can use FileExist to check for SysNative\cmd.exe.

You can use SysNative in other programs as well, although it is hidden. For instance, I use it to load 64-bit system dll files into PEBrowsePro, which is 32-bit.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Google [Bot], Nerafius, RandomBoy and 194 guests