views:

12

answers:

0

Hi All,

I have a MFC application that uses ::CreateProcess() function for creating "cmd.exe" for executing the command with hidden window. The window name has been defined in the STARTUPINFO structure which is used with the ::CreateProcess() function. I am using ::FindWindow() API to get the handle of this window.

::FindWindow() API is unable to get the handle of the window due to which my application crashes in Windows Server 2008 R2 in WoW64 environment but the same works correctly in Windows XP in WoW64 & x64 environment.

Following is the code snippet:

PROCESS_INFORMATION l_CmdPI;

STARTUPINFO l_StartupInfo;

l_StartupInfo.cb = sizeof(STARTUPINFO);

l_StartupInfo.wShowWindow = SW_HIDE;

l_StartupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;

l_StartupInfo.lpTitle = _T("SampleWindow")

//USED IN WINDOWS XP (WOW64 & x64)

if(FALSE == ::CreateProcess(NULL,

(LPTSTR)_T(“cmd /c dir”),

NULL,

NULL,

TRUE,

CREATE_NO_WINDOW,

NULL,

NULL,

&l_StartupInfo,

&l_CmdPI))

{

return FALSE;

}

//MODIFIED IN WINDOWS SERVER 2008 R2 (WOW64)

if(FALSE == ::CreateProcess(NULL,

(LPTSTR)_T(“cmd /c dir”),

NULL,

NULL,

TRUE,

NULL,

NULL,

NULL,

&l_StartupInfo,

&l_CmdPI))

{

return FALSE;

}

If I change the process creation flag value to “NULL” instead of “CREATE_NO_WINDOW”, ::FindWindow() is able to get the window handle in Windows Server 2008 R2.

Can anybody please let me know that how does the same works in Windows XP in WoW64 & x64 environment with CREATE_NO_WINDOW flag and does not work in Windows Server 2008 R2 in WoW64 environment?

Thanks & Regards,

Ruhee Jaiswal