SysWow64 Redirection for cmd.exe
I have been trying to call 'qwinsta.exe' utility via command line using 32-bit application for detecting Remote Desktop connection. My problem is that when i invoke 'cmd.exe /s qwinsta /server' it is launching c:\Windows\SysWOW64\cmd.exe and is not able to find 'qwinsta.exe' as it is installed in c:\Windows\System32. I have tried copying qwinsta.exe from c:\Windows\System32 to c:\Windows\SysWOW64 and manifest qwinsta.exe.mui from the \en-US subfolder of \System32 to the same subfolder of \SysWOW64\ in order to get the command working. I want to know if the workaround that i have tried is safe or not?? Is there any other method of detecting a Remote Desktop session without resorting to the qwinsta.exe command line? Any ideas??
RE: SysWow64 Redirection for cmd.exe
32-bit applications is capable of accessing native system directory by substituting %windir%\Sysnative for %windir%\System32. Actually Sysnative is recognized by WOW64 as a special alias so that the file system doesnt redirect the access. Sysnative is kind of virtual directory, it's alias or pseudo-directory do not appear in Windows Explorer, directory listing. It doesn't even support native 64-bit processes that access %windir%\System32 folder. Sysnative cannot be used in applications user interface, it can only be used in file system calls.
Re: SysWow64 Redirection for cmd.exe
Copying qwinsta.exe from c:\Windows\System32 to c:\Windows\SysWOW64 doesn't seem to be a better idea. SysWOW64 is not meant for containing 64-bit executable. Anyways you can check out this "Programming Guide for 64-bit Windows" and this "Running 32-bit Applications". There are some API functions for disabling redirection temporarily and reverting redirection back after that. You can use below things:
- Disable redirection
- Call the utility
- Revert redirection back