You try to execute the program query.exe which is located in the system directory, in most cases it is c:\windows\system32. You are using 32 bit application and that causes a redirection to c:\windows\SysWOW64. In this folder, there is no query.exe application. You can either temporarily disable the redirection by calling Wow64DisableWow64FsRedirection and Wow64RevertWow64FsRedirection functions. Be careful with these functions. They affect all file operations of the current thread.
The other way is to point directly to the system32 folder with %windir%\Sysnative.
In your case, the command "cmd /c %windir%\Sysnative\query user" should work in both 32bit and 64bit.