Reputation: 1
I am creating a Windows service in C++ in a specific user account in Windows 10. I need to launch a Windows application interactively from the service, but CreateProcessAsUser()
is failing with GetLastError()
code 1314.
Is there any way to launch a Windows application interactively from a Windows service in Windows 10?
STARTUPINFO StartInfo;
PROCESS_INFORMATION ProcInfo;
TOKEN_PRIVILEGES tp;
memset(&ProcInfo, 0, sizeof(ProcInfo));
memset(&StartInfo, 0, sizeof(StartInfo));
StartInfo.cb = sizeof(StartInfo);
HANDLE handle = NULL;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ALL_ACCESS, &handle)) printf("\nOpenProcessError");
if (!LookupPrivilegeValue(NULL, SE_TCB_NAME,
//SE_TCB_NAME,
&tp.Privileges[0].Luid)) {
printf("\nLookupPriv error");
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes =
SE_PRIVILEGE_ENABLED;//SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(handle, FALSE, &tp, 0, NULL, 0)) {
printf("\nAdjustToken error");
}
LPCWSTR username = L"EngBitrode"; // Replace with actual username
LPCWSTR domain = L"bc_stl";
LPCWSTR password = L"Eb02042020"; // Replace with actual password
BOOL bResult = LogonUserW(username, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &handle);
printf("\nLogonUser return : %d", bResult);
DWORD err = GetLastError();
printf("\nLogonUser getlast : %d", err);
if (!ImpersonateLoggedOnUser(handle)) printf("\nImpLoggedOnUser!");
BOOL success = CreateProcessAsUser(handle, CommServerPath(), NULL, NULL, NULL, true,
CREATE_UNICODE_ENVIRONMENT | NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, NULL,
&StartInfo, &ProcInfo);
printf("\nCreateProcessAsUser return : %d", success);
err = GetLastError();
printf("\nCreateProcessAsUser getlast : %d", err);
CloseHandle(handle);
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
return ProcInfo.dwProcessId;
This code launchs the application runs in background not interactively.But i need the application to run interactively.
Upvotes: -7
Views: 63