BOOL bThreadToken = FALSE; HANDLE hThreadToken1, hThreadToken2;//Save the current thread token if( OpenThreadToken(GetCurrentThread(), TOKEN_IMPERSONATE, FALSE, &hThreadToken1) ) { RevertToSelf(); bThreadToken = TRUE; }//Impersonate a user account //Insure the Sid associated with the process holds SE_TCB_NAME Privilege LogonUser(...); ImpersonateLoggedOnUser(...); //do user specific work here//Restore the original thread token if( bThreadToken ) { hThreadToken2 = GetCurrentThread(); SetThreadToken( &hThreadToken2, hThreadToken1 ); CloseHandle( hThreadToken1 ); }
HANDLE hThreadToken1, hThreadToken2;//Save the current thread token
if( OpenThreadToken(GetCurrentThread(), TOKEN_IMPERSONATE, FALSE, &hThreadToken1) )
{
RevertToSelf();
bThreadToken = TRUE;
}//Impersonate a user account
//Insure the Sid associated with the process holds SE_TCB_NAME Privilege
LogonUser(...);
ImpersonateLoggedOnUser(...);
//do user specific work here//Restore the original thread token
if( bThreadToken )
{
hThreadToken2 = GetCurrentThread();
SetThreadToken( &hThreadToken2, hThreadToken1 );
CloseHandle( hThreadToken1 );
}
调用LogOnUser()的时候,我的这个用户名为guest都不行。关注