The project I am working on has 3 components:
launcher.exe. Is run by user, grants user "user1" access to window station and desktop. Opens a named pipe to...
service.exe. Running as local system account, it creates a process running as user "user1" but in the same session as launcher.exe called...
foo.exe. When this process runs, any API it attempts to hook fails with GetLastError of 0.
If I run foo.exe as the regular user, it hooks fine.
Here is how I am launching foo.exe from service.exe:
Code: Select all
HANDLE user;
PROFILEINFO userProfile;
ULONG sessionId;
STARTUPINFOA si = {0};
PROCESS_INFORMATION pi;
GetNamedPipeClientSessionId(pipe, &sessionId);
LogonUser("user1", ".", "password", LOGON32_LOGON_SERVICE, LOGON32_PROVIDER_DEFAULT, &user);
LoadUserProfile(user, &userProfile);
SetTokenInformation(user, TokenSessionId, &sessionId, sizeof(sessionId)); // removing this line allows HookAPI in foo.exe to work.
si.cb = sizeof(si);
CreateProcessAsUserA(user, 0, "foo.exe", 0, 0, FALSE, 0, 0, 0, &si, &pi);
Code: Select all
BOOL WINAPI createProcessAHook(LPCSTR, LPSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCSTR, LPSTARTUPINFOA, LPPROCESS_INFORMATION);
void main() {
InitializeMadCHook();
LPVOID hook = 0;
BOOL rc = HookAPI("kernel32.dll", "CreateProcessA", createProcessAHook, &hook, 0); // fails with GetLastError() 0
}
I can replicate this problem on 32bit XP and 64bit Windows 7.
Any way I can get detailed information on why HookAPI is failing?
Thanks