Windows 7 CreateProcess matter with Windows 7 SP1

Franck M

New Member
Joined
Apr 10, 2012
I have got an issue with Windows 7 Sp1 (v 6.1.7601).

This code display a console window with "dir" result. It work well on Windows 7 but not with SP1.

BOOL RunCommand(LPCTSTR szCommand)
{
TCHAR szComSpec[MAX_PATH];
TCHAR szCmd[2048];
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi = { 0 };
SECURITY_ATTRIBUTES sa;
int err;

sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = true;

sprintf(szCmd, "/c %s", szCommand);
GetEnvironmentVariable(TEXT("COMSPEC"), szComSpec, MAX_PATH);
if ( CreateProcess(szComSpec, szCmd, &sa, NULL, TRUE, NULL, NULL, NULL, &si, &pi) )
{
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return TRUE;
}
else
{
err = GetLastError();
}

return FALSE;
}

void main()
{
if (!RunCommand("dir |more"))
Application->MessageBoxA("CreatProcess Error", "Error", MB_OK);
}

On windows 7 SP1, no console is displayed and the process close automatically without any error message.

Is somebody can help me ?
Thank's in advance.
 
Back
Top Bottom