1 year ago
#197542
Arun
CreateProcess works differently on x64 and x86 platform
I am trying to install a driver using inf file through c++ program. The below program works fine in x64 platform and where as fails in x86 platform with GetLastError 2. What could be the difference here? The reason why I am trying this is, I am using one of the existing application created by my team which is 32 bit application.
void StartProcess(LPCTSTR pszTarget, LPCTSTR pszCommandLine, LPCTSTR pszFolder)
{
try
{
PROCESS_INFORMATION pi;
STARTUPINFO si;
TCHAR szCommandLine[1024];
SecureZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
SecureZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags |= STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
_tcscpy_s(szCommandLine, 1024, pszTarget);
_tcscat_s(szCommandLine, 1024, _T(" "));
_tcscat_s(szCommandLine, 1024, pszCommandLine);
auto bRetval = CreateProcess(NULL, szCommandLine, 0, 0, FALSE, 0, 0, pszFolder, &si, &pi);
if (bRetval)
{
WaitForSingleObject(pi.hProcess, INFINITE);
}
else
{
throw std::runtime_error("Installing driver failed. Error details - " + std::to_string(GetLastError()));
}
if (pi.hProcess)
{
CloseHandle(pi.hProcess);
}
if (pi.hThread)
{
CloseHandle(pi.hThread);
}
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
throw e;
}
}
int main()
{
std::string sWorkingFolder = "<inf folder path>";
std::string sBin = "pnputil.exe";
std::string sParams = "/add-driver \"<infpath>\" /install";
StartProcess(sBin.c_str(), sParams.c_str(), sWorkingFolder.c_str());
return 0;
}
c++
windows
createprocess
0 Answers
Your Answer