1

How can I create a process (a.exe) using CreateProcessWithLogonW that is realtime (note that I'm not an admin user but the one I'm using with CreateProcessWithLogonW is admin) and launch another process (b.exe) from a.exe using CreateProcess and have it realtime also?

Here is the code to launch a.exe:

PROCESS_INFORMATION pi = { 0 };
STARTUPINFO         si = { 0 };
if (!CreateProcessWithLogonW(argv[1], argv[2], argv[3], LOGON_NETCREDENTIALS_ONLY, NULL, _T("a.exe"),
REALTIME_PRIORITY_CLASS, NULL, NULL,
&si, &pi))
{
    cout << "Error!!!!\n";
}

Here is the code to launch b.exe from a.exe:

SECURITY_ATTRIBUTES   security_att;
STARTUPINFO           si;
PROCESS_INFORMATION   pi;
ZeroMemory(&security_att, sizeof(security_att));
security_att.nLength        = sizeof (SECURITY_ATTRIBUTES);
security_att.bInheritHandle = TRUE;

ZeroMemory(&si, sizeof(si));
si.cb          = sizeof(si);
si.dwFlags     = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_NORMAL;

if(!CreateProcess(NULL, "b.exe", &security_att, &security_att, FALSE, REALTIME_PRIORITY_CLASS, NULL, NULL, &si, &pi))
{
            cout << "Error!!!!\n";
}

Currently, a.exe will be realtime priority but b.exe is only high priority.

user3716892
  • 101
  • 7
  • when you use `LOGON_NETCREDENTIALS_ONLY` the `argv[1], argv[2], argv[3]` have no sense. you can use here `L"*", L"*", L"*"` for example. new process uses same token as your. and you try to say that `GetPriorityClass(pi.hProcess) != REALTIME_PRIORITY_CLASS;` ? – RbMm Jul 19 '17 at 22:04
  • One bug in your code is passing a constant string as `lpCommandLine` in the call to `CreateProcessWithLogonW`. I don't think this is causing your problem, but you should fix it anyway. I've done a bit of research, and though I can't find this documented anywhere, it seems you need admin privilege to set a process to real-time priority class. So *neither* `a.exe` or `b.exe` should be real-time priority. (You may have found a minor bug in `CreateProcessWithLogonW`!) – Harry Johnston Jul 19 '17 at 22:36
  • RbMm, changed it to LOGON_WITH_PROFILE to obtain the profile and it's still the same problem. GetPriorityClass(pi.hProcess) == 0 after starting b.exe – user3716892 Jul 19 '17 at 22:39
  • Harry Johnston, I'm getting the credentials of the LOGON_WITH_PROFILE who is admin. I'm guessing that's why a.exe succeeds. – user3716892 Jul 19 '17 at 22:42
  • No, that won't work either, because of UAC. The user may have administrative rights, but the process doesn't get them. See also [this answer](https://stackoverflow.com/a/39403260/886887) although you won't be able to use that solution because the original process doesn't have administrative rights. – Harry Johnston Jul 20 '17 at 01:38
  • ... I'm not sure whether there's any way for a non-administrative process to use administrator credentials to gain administrator access, without prompting the user. You might need to install a system service to launch the child process on your behalf. Or, if it is acceptable to prompt the user, [this answer](https://stackoverflow.com/a/32281170/886887) might help. – Harry Johnston Jul 20 '17 at 01:45
  • I decided to change the local policies instead. Under User Rights Assignment, add Users to "Increase scheduling priority". – user3716892 Jul 21 '17 at 13:16

0 Answers0