BOOL bSuccess=FALSE;
HANDLE hToken=NULL;
HANDLE hTokenDup=NULL;
Do
{
If (OpenProcessToken (GetCurrentProcess (), TOKEN_ALL_ACCESS, & amp; HToken))
{
If (DuplicateTokenEx (hToken TOKEN_ALL_ACCESS, NULL, SecurityIdentification TokenPrimary, & amp; HTokenDup))
{
DWORD dwSessionId=WTSGetActiveConsoleSessionId ();
if(! SetTokenInformation (hTokenDup TokenSessionId, & amp; DwSessionId, sizeof (DWORD)))
{
BSuccess=FALSE;
break;
}
STARTUPINFO si;
PROCESS_INFORMATION PI;
ZeroMemory (& amp; Si, sizeof (STARTUPINFO));
ZeroMemory (& amp; PI, sizeof (PROCESS_INFORMATION));
Si. Cb=sizeof (STARTUPINFO);
SECURITY_ATTRIBUTES sa={0};
Sa. NLength=sizeof (sa);
LPVOID pEnv=NULL;
DWORD dwCreationFlag=NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT;
if(! CreateEnvironmentBlock (& amp; PEnv hTokenDup, FALSE))
{
If (pEnv!=NULL)
DestroyEnvironmentBlock (pEnv);
BSuccess=FALSE;
break;
}
TCHAR lpszClientPath [MAX_PATH];
If (GetModuleFileName (NULL, lpszClientPath MAX_PATH))
{
PathRemoveFileSpec (lpszClientPath);
}
STD: : wstring NotifyWndPath (lpszClientPath);
STD: : wstring NotifyWndName=NotifyWndPath;
NotifyWndName. Append (L "\ \ KuaiApp exe");
STD: : wstring ComdLine=NotifyWndName;
ComdLine. Append (L "KuaiServiceNotify");
LPWSTR lpComdline=new would [ComdLine. The size () + 1);
Wcscpy (lpComdline, ((LPCTSTR) ComdLine c_str ()));
if(! CreateProcessAsUser (hTokenDup, NULL, lpComdline, & amp; Sa, & amp; Sa, FALSE, dwCreationFlag, pEnv, NotifyWndPath c_str (), & amp; Si, & amp; PI))
{
BSuccess=FALSE;
break;
}
If (pEnv)
{
The CloseHandle (PI. HProcess);
The CloseHandle (PI. HThread);
DestroyEnvironmentBlock (pEnv);
}
}
The else
{
BSuccess=FALSE;
break;
}
}
The else
{
BSuccess=FALSE;
break;
}
} while (0);
If (hTokenDup!=NULL & amp; & HTokenDup!=INVALID_HANDLE_VALUE)
The CloseHandle (hTokenDup);
If (hToken!=NULL & amp; & HToken!=INVALID_HANDLE_VALUE)
The CloseHandle (hToken);
Return bSuccess;
CodePudding user response:
Have specific apis, like he's going to pass the user's user name and passwordService is super administrator privileges