Page 1 of 1

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

Posted: 15 Aug 2019, 11:10
by afe
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.

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

Posted: 15 Aug 2019, 11:43
by gregster
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?

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

Posted: 15 Aug 2019, 12:05
by jeeswg
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

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

Posted: 16 Aug 2019, 04:40
by afe
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" .

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

Posted: 16 Aug 2019, 11:33
by gregster
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 🤷‍♂️

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

Posted: 16 Aug 2019, 11:45
by jeeswg
@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

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

Posted: 16 Aug 2019, 12:17
by gregster
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!

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

Posted: 17 Aug 2019, 20:31
by lexikos
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.