一種可能的方式 -
system("C:\\Windows\\notepad.exe");
或
ShellExecute(NULL, "open", "C:\\Windows\\notepad.exe", NULL, NULL, SW_SHOWDEFAULT);
或使用CreateProcess
VOID startup(LPCTSTR lpApplicationName)
{
// additional information
STARTUPINFO si;
PROCESS_INFORMATION pi;
// set the size of the structures
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
// start the program up
CreateProcess(lpApplicationName, // the path
argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi) // Pointer to PROCESS_INFORMATION structure
)
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
你有什麼期望你程序要做到嗎?你發佈的代碼打開「C://Users/Jonte/Desktop/Skype.exe」文件,然後退出。 –
打開文件是一回事,試圖將文件作爲程序運行是另一回事。 – alk