Created
March 6, 2012 09:36
-
-
Save yoggy/1985321 to your computer and use it in GitHub Desktop.
How to use CreateProcess() function (WIN32)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// see also... | |
// | |
// CreateProcess (MSDN) | |
// http://msdn.microsoft.com/ja-jp/library/cc429066.aspx | |
// | |
#include <SDKDDKVer.h> | |
#include <windows.h> | |
int APIENTRY WinMain(HINSTANCE hInstance, | |
HINSTANCE hPrevInstance, | |
LPTSTR lpCmdLine, | |
int nCmdShow) | |
{ | |
#ifdef _DEBUG | |
const char *target_cmd = "TestConsoleAppD.exe"; | |
#else | |
const char *target_cmd = "TestConsoleApp.exe"; | |
#endif | |
STARTUPINFO startup_info; | |
PROCESS_INFORMATION process_info; | |
memset(&startup_info, 0, sizeof(STARTUPINFO)); | |
startup_info.cb = sizeof(STARTUPINFO); | |
memset(&process_info, 0, sizeof(PROCESS_INFORMATION)); | |
BOOL rv = ::CreateProcess( | |
target_cmd, // LPCTSTR lpApplicationName | |
NULL, // LPTSTR lpCommandLine | |
NULL, // LPSECURITY_ATTRIBUTES lpProcessAttributes | |
NULL, // LPSECURITY_ATTRIBUTES lpThreadAttributes | |
FALSE, // BOOL bInheritHandles | |
CREATE_NO_WINDOW, // DWORD dwCreationFlags | |
NULL, // LPVOID lpEnvironment | |
NULL, // LPCTSTR lpCurrentDirectory | |
&startup_info, // LPSTARTUPINFO lpStartupInfo | |
&process_info // LPPROCESS_INFORMATION lpProcessInformation | |
); | |
if (rv == FALSE) { | |
::MessageBox(NULL, "CreateProcess() failed...", "error", MB_OK); | |
return 0; | |
} | |
::CloseHandle(process_info.hThread); | |
::WaitForSingleObject(process_info.hProcess, INFINITE); | |
::CloseHandle(process_info.hProcess); | |
::MessageBox(NULL, "CreateProcess() finish", "error", MB_OK); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SDKDDKVer.h> | |
#include <stdio.h> | |
#include <time.h> | |
int main(int argc, char* argv[]) | |
{ | |
time_t t; | |
struct tm d; | |
char buf[128]; | |
FILE *fp = NULL; | |
time(&t); | |
localtime_s(&d, &t); | |
strftime(buf, 123, "%Y/%m/%d-%H:%M:%S", &d); | |
printf("TestConsoleApp.exe : touch _hoge.txt %s\n", buf); | |
fopen_s(&fp, "_hoge.txt", "w"); | |
fprintf(fp, "TestConsoleApp.exe : touch _hoge.txt %s\n", buf); | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
プロジェクト一式はこちら
https://github.com/yoggy/CreateProcess_CreateNoWindow_Test