pahlevan
pahlevan

Reputation: 43

Create thread with specific privilege c++

I have multi-thread application that I want to create a thread with different user privilege (for example : multi domain admin privilege).

but I can't find any Win32 API CreateThread to do that.

How to create thread with specific user privileges?

thanks.

Upvotes: 2

Views: 2856

Answers (2)

Kalle
Kalle

Reputation: 21

Call this from the thread that you want to have the specific user privileges, by logging on the thread as the specified user:

HANDLE hToken;
BOOL bRet = LogonUser("username","domain","password",
    LOGON32_LOGON_INTERACTIVE,
    LOGON32_PROVIDER_DEFAULT,&hToken);
if(!bRet)
    // Add your own fault handling here
    return MessageBox(NULL,"Could not log on","Error",MB_OK|MB_ICONSTOP);
bRet = ImpersonateLoggedOnUser(hToken);
if(!bRet)
    // Add your own fault handling here
    return MessageBox(NULL,"Could not impersonate","Error",MB_OK|MB_ICONSTOP);

Upvotes: 2

sharptooth
sharptooth

Reputation: 170489

Call CreateThread() with CREATE_SUSPENDED flag, then call SetThreadToken(), then ResumeThread().

Upvotes: 6

Related Questions