LocalSystem Windows 서비스의CreateProcessAsUser가 사용자를 올바르게 설정하지 않습니다.
[DllImport(
"advapi32.dll",
EntryPoint = "CreateProcessAsUser",
SetLastError = true,
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall)]
private static extern bool CreateProcessAsUser(
IntPtr hToken,
string lpApplicationName,
string lpCommandLine,
ref SECURITY_ATTRIBUTES lpProcessAttributes,
ref SECURITY_ATTRIBUTES lpThreadAttributes,
bool bInheritHandle,
int dwCreationFlags,
IntPtr lpEnvironment,
string lpCurrentDirectory,
ref STARTUPINFO lpStartupInfo,
out PROCESS_INFORMATION lpProcessInformation);
bool result = CreateProcessAsUser(
hUserTokenDup,
null,
applicationName + " " + arguments,
ref sa, // pointer to process SECURITY_ATTRIBUTES
ref sa, // pointer to thread SECURITY_ATTRIBUTES
false, // handles are not inheritable
NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, // creation flags
IntPtr.Zero, // pointer to new environment block
null, // name of current directory
ref si, // pointer to STARTUPINFO structure
out procInfo); // receives information about new process
를 사용하여 GUI 응용 프로그램 호출. 사용자 화면에서 창이 나타나지만 프로세스 사용자는 여전히 LocalSystem입니다. 그것을 바꿀 방법이 있습니까?
PS 요청에 따라
hUserTokenDup
[DllImport("advapi32.dll", EntryPoint = "DuplicateTokenEx")]
private static extern bool DuplicateTokenEx(
IntPtr ExistingTokenHandle,
uint dwDesiredAccess,
ref SECURITY_ATTRIBUTES lpThreadAttributes,
int TokenType,
int ImpersonationLevel,
ref IntPtr DuplicateTokenHandle);
DuplicateTokenEx(
hPToken,
MAXIMUM_ALLOWED,
ref sa,
(int)SECURITY_IMPERSONATION_LEVEL.SecurityIdentification,
(int)TOKEN_TYPE.TokenPrimary,
ref hUserTokenDup);
hUserTokenDup을 어디에서 얻을 수 있습니까? 나는 그것이 그 문제의 핵심이라고 믿는다. –
@Josh 요청한 정보를 추가했습니다 –
'hPToken '은 어디에서 왔습니까? –