I'm writing windows service which consists three separated threads. When user logs in (is logged when service starts) I impersonate each thread (so it operates on same access rights as currently logged on user).
(Impersonation code without error handling)
/*Query Token */
WTSQueryUserToken(SessionId, &hUserToken)
/* Duplicate Token */
DuplicateToken(
hUserToken,
SecurityImpersonation,
&hDuplicateUserToken
)
/* Open Thread handle */
hThreadHandle = OpenThread(
THREAD_IMPERSONATE |
THREAD_QUERY_INFORMATION |
THREAD_SET_THREAD_TOKEN,
TRUE,
threadID
);
/* Assign the impersonation token to the thread */
SetThreadToken(&hThreadHandle, hDuplicateUserToken)
Later in the same thread I use COM (image factory) object to retrieve thumbnails for images (using many available APIs gives similar results)
/* com initialization */
CoInitializeEx(NULL, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
/* piece of code to retrieve a thumbnail */
hr = pImageFactory->GetImage(size, SIIGBF_BIGGERSIZEOK, &thumbNail);
When code to retrieve thumbnail is called from non impersonated thread or normal desktop application I receive thumbnails for both images and videos. When code is called from impersonated thread the only thing I receive is one icon for all images or not implemented hresult (for IThumbnail provider).
Is there anything I should do with impersonated thread prior calling COM APIs?