3 Mart 2020 Salı

CreateProcess metodu

Giriş
Açıklaması şöyle
CreateProcess creates a process that runs as the same user as the parent application and it runs in the same session. You must use CreateProcessAsUser/CreateProcessWithLogonW/ CreateProcessWithTokenW to create a process as another user.
Örnek
Şöyle yaparız
CreateProcess(NULL,   // No module name (use command line)
    L"C:\\Windows\\System32\\cmd.exe /C myfile.bat", // Call cmd.exe with /C flag
    NULL,           // Process handle not inheritable
    NULL,           // Thread handle not inheritable
    FALSE,          // Set handle inheritance to FALSE
    CREATE_NO_WINDOW,              // Use CREATE_NO_WINDOW!!!
    NULL,           // Use parent's environment block
    NULL,           // Use parent's starting directory 
    &si,            // Pointer to STARTUPINFO structure
    &pi )           // Pointer to PROCESS_INFORMATION structure
Hata kodu varsa yakalamak için şöyle yaparız
if( !CreateProcessA(...) )
{
  char msg[100];
  sprintf( msg, "CreateProcess() failed: %d", GetLastError() );
  OutputDebugStringA( msg );
}
Yeni uygulamanın bitmesini beklemek için şöyle yaparız
::WaitForSingleObject(pi.hProcess, INFINITE);

Hiç yorum yok:

Yorum Gönder