I am looking for a way to increase the privileges of a thread or process without popping up a UAC. The user who runs this process is admin, and I have his username and password.
I need to do this in order to do some administrative things, such as restarting the service and writing files to system directories. My application starts remotely and there is no interactive user to confirm the UAC dialog. Disabling UAC is not an option.
I tried to intercept LogonUser() , ImpersonateLoggedOnUser() , CreateProcessAsUser() and DuplicateTokenEx() for most or two days, but could not figure out the right combination, and if at all possible.
In particular, I tried this:
HANDLE token = 0; LogonUserA(user, NULL, pass, LOGON32_LOGON_NETWORK_CLEARTEXT, LOGON32_PROVIDER_DEFAULT, &token); HANDLE impToken = 0; DuplicateToken(token, SecurityImpersonation, &impToken); ImpersonateLoggedOnUser(impToken); CreateFileA("C:\\windows\\blabla.dll", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
the last call fails with the error GetLastError() = 1346: "Either the required impersonation level was not provided, or the provided impersonation level is invalid."
What am I doing wrong?
Note. This runs on Win2008 R2