Closed uguryanik closed 7 years ago
if (!CreateProcessAsUser(hUserToken,
appPath, // Application Name
cmdLine, // Command Line
IntPtr.Zero,
IntPtr.Zero,
false,
dwCreationFlags,
IntPtr.Zero,
workDir, // Working directory
ref startInfo,
out procInfo))
{
iResultOfCreateProcessAsUser = Marshal.GetLastWin32Error();
throw new Exception("StartProcessAsCurrentUser: CreateProcessAsUser failed. Error Code -" + iResultOfCreateProcessAsUser);
}
now i'm getting token but CreateProcessAsUser return false with error code -740, in console app it working fine, but in windows service getting error. Whats wrong?
@uurynk Hard to tell without knowing what you are doing. The demo service in the repo certainly works. What are you doing differently? The code you posted above is verbatim from the github project and it is known to work without issues. I also encourage you to re-read the thread I linked above and make sure your process is holding correct privileges - the elevation error you are citing suggesting that it is not.
EnableLUA resolved my problem. Thank you for your support.
if (WTSQueryUserToken(activeSessionId, ref hImpersonationToken) != 0) { // Convert the impersonation token to a primary token bResult = DuplicateTokenEx(hImpersonationToken, 0, IntPtr.Zero, (int)SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, (int)TOKEN_TYPE.TokenPrimary, ref phUserToken);
}
WTSQueryUserToken return 0 and it fails to start process.