How do I launch an executable with supplied arguments if I'm running as network service? I've tried using ShellExecuteEx from within my program (which runs as Network Service):
try
{
DWORD dwErr;
TCHAR bufProgName[1000] = _T("");
TCHAR bufParameters[1000] = _T("");
::lstrcat(bufProgName,_T("C:\\NotMyFault\\x86\\NotMyFault.exe"));
::lstrcat(bufParameters,_T(" -help"));
SHELLEXECUTEINFO ShExecInfo;
ZeroMemory(&ShExecInfo,sizeof(ShExecInfo));
ShExecInfo.cbSize=sizeof(ShExecInfo);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = bufProgName;
ShExecInfo.lpParameters = bufParameters;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;
int res = ShellExecuteEx(&ShExecInfo);
if(!res)
{
dwErr = GetLastError();
return -1;
}
}
catch(...)
{
std::cout<<"ShellFail: " << dwError;
return -1;
}
But all this does is launch NotMyFault.exe running as user Network Service (I see this from Task Manager), but it doesn't bring up help. Same thing for other arguments (" -crash").
I know this is hastily written code, but I need to see if a process running as Network Service (like mine) can do this successfully. When I run it as another user (by double clicking the executable) it seems to work just fine.
CreateProcess?