Loading user profile from a service <p>In a service, I try to use the following code to launch a program :</p> <pre><code>HANDLE hPipe; HANDLE hToken; PROFILEINFO stProfileInfo; char szUserName[64]; DWORD dwUserNameSize = 64; // Take the identity of the client ImpersonateNamedPipeClient(hPipe); // Retrieve the user name (DOMAIN\USER) GetUserNameEx(NameSamCompatible,szUserName,&amp;dwUserNameSize); // Get the impersonation token OpenThreadToken(GetCurrentThread(),TOKEN_ALL_ACCESS,TRUE,&amp;hToken); // Load the user's profile ZeroMemory(&amp;stProfileInfo,sizeof(PROFILEINFO)); stProfileInfo.dwSize = sizeof(PROFILEINFO); stProfileInfo.dwFlags = PI_NOUI; stProfileInfo.lpUserName = szUserName; LoadUserProfile(hToken,&amp;stProfileInfo); </code></pre> <p>Unfortunately, the call to <code>LoadUserProfile</code> fail with <code>GetLastError=5 (access denied)</code>. In userenv.log, I can find this :</p> <pre><code>USERENV LoadUserProfile: Yes, we can impersonate the user. Running as self USERENV LoadUserProfile: Entering, hToken = &lt;0xc8&gt;, lpProfileInfo = 0xb30aa4 USERENV LoadUserProfile: lpProfileInfo-&gt;dwFlags = &lt;0x1&gt; USERENV LoadUserProfile: lpProfileInfo-&gt;lpUserName = &lt;MYDOMAIN\USERNAME&gt; USERENV LoadUserProfile: NULL central profile path USERENV LoadUserProfile: NULL default profile path USERENV LoadUserProfile: NULL server name USERENV LoadUserProfile: Failed to enable the restore privilege. error = c0000022 USERENV LoadUserProfile: Returning FALSE. Error = 5 </code></pre> <p>Of course, I checked that my service (running as SYSTEM) has the <code>SE_RESTORE_NAME</code> (and <code>SE_BACKUP_NAME</code>) privileges enabled.</p> <p>Any help would be greatly appreciated !</p>