我想使用CreateProcess()函數做一個簡單的應用程序控制器。該程序接收程序的路徑,該程序將由套接字執行並將其存儲到char []變量中,稍後將該變量發送給將執行該變量的函數。C++ CreateProcess失敗從Windows 7上的套接字接收路徑(64)
我發現了錯誤是
Client: Received data is: C:\Windows\System32\calc.exe
Server: Bytes received: 30.
CreateProcess failed (123).
(2)= ERROR_FILE_NOT_FOUND
我tryed與雙牀斜線(//)和i接收錯誤(123)
Client: Received data is: C:\\Windows\\System32\\calc.exe
Server: Bytes received: 33.
CreateProcess failed (123).
(123)= ERROR_INVALID_NAME
接收程序執行路徑的函數:
bytesRecv = recv(m_socket, recvbuf, 200, 0);
if (bytesRecv == SOCKET_ERROR)
printf("Server: recv() error %ld.\n", WSAGetLastError());
else
{
printf("\nClient: Received data is: %s\n", recvbuf);
printf("Server: Bytes received: %ld.\n", bytesRecv);
NewProcess(1,LPWSTR(recvbuf)); // <---- Call to NewProcess function with path
}
,誰啓動過程中的作用:
void NewProcess(int count,LPWSTR cmd)
{
LPTSTR concatenation = _T(" ");
LPTSTR cmdArgs = NULL;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW;
// Start the child process.
if(!CreateProcess(NULL, // Program full path
cmd, // Arguments
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
)
{
printf("CreateProcess failed (%d).\n", GetLastError());
return;
}
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
printf("\nProcess ID: %d Terminated!",pi.dwProcessId);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
你能告訴我什麼是錯的,我supose是一些有關變量的類型,但我無法找出錯誤。
在此先感謝。
在調用CreateProcess()之前調試'cmd'參數的輸出,可能會中斷 – 2014-09-04 08:37:02