Click here to Skip to main content
16,004,991 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
General#include <stl.h> Pin
Anonymous26-Feb-03 6:38
Anonymous26-Feb-03 6:38 
GeneralRe: #include <stl.h> Pin
Maximilien26-Feb-03 6:45
Maximilien26-Feb-03 6:45 
GeneralRe: #include <stl.h> Pin
Nitron26-Feb-03 7:51
Nitron26-Feb-03 7:51 
GeneralGetting the access token of the logged-on user Pin
Neflyte26-Feb-03 6:22
Neflyte26-Feb-03 6:22 
GeneralRe: Getting the access token of the logged-on user Pin
Garth J Lancaster26-Feb-03 10:32
professionalGarth J Lancaster26-Feb-03 10:32 
GeneralRe: Getting the access token of the logged-on user Pin
Neflyte26-Feb-03 10:42
Neflyte26-Feb-03 10:42 
GeneralRe: Getting the access token of the logged-on user Pin
Garth J Lancaster26-Feb-03 10:58
professionalGarth J Lancaster26-Feb-03 10:58 
GeneralRe: Getting the access token of the logged-on user Pin
Garth J Lancaster26-Feb-03 11:20
professionalGarth J Lancaster26-Feb-03 11:20 
this is reply #2 Smile | :)

maybe this will help - I did a quick search for 'enumerate logged on users' through google .. :-

You'll have to get access to the user's desktop. The easiest way to do this is to 'impersonate' the security context of the logged-on user using one of the user's process token. Some 'pseudocode' to illustrate it:


HANDLE GetTokenOfLoggedOnUser()
{
HANDLE hToken;
HANDLE hProcess;
DWORD dwPID;
// find PID of 'explorer.exe'
// HOWTO: Enumerate Applications in Win32
// http://support.microsoft.com/support/kb/articles/Q175/0/30.ASP

hProcess = OpenProcess ( PROCESS_ALL_ACCESS,
TRUE,
dwPID
);

if ( !OpenProcessToken ( hProcess,
TOKEN_QUERY | TOKEN_IMPERSONATE,
&hToken
)
) return ( INVALID_HANDLE_VALUE);

return ( hToken);
}

//Error checking & 'CloseHandle()' omitted for brevity Wink | ;-)


DWORD dwThreadId;
HWINSTA hwinstaSave;
HDESK hdeskSave;
HWINSTA hwinstaUser;
HDESK hdeskUser;
int result;

/*
* Ensure connection to service window station and desktop, and
* save their handles.
*/
GetDesktopWindow();
hwinstaSave = GetProcessWindowStation();
dwThreadId = GetCurrentThreadId();
hdeskSave = GetThreadDesktop(dwThreadId);

/*
* Impersonate the client and connect to the User's
* window station and desktop.
*/
InpersonateLoggedOnUser ( GetTokenOfLoggedOnUser();
hwinstaUser = OpenWindowStation(lpszWindowStation, FALSE, MAXIMUM_ALLOWED);
if (hwinstaUser == NULL) {
RevertToSelf();
return 0;
}
SetProcessWindowStation(hwinstaUser);
hdeskUser = OpenDesktop(lpszDesktop, 0, FALSE, MAXIMUM_ALLOWED);
RevertToSelf();
if (hdeskUser == NULL) {
SetProcessWindowStation(hwinstaSave);
CloseWindowStation(hwinstaUser);
return 0;
}
SetThreadDesktop(hdeskUser);

/*
* Display message box (for example's sakes) or enumerate the windows
*/
dwGuiThreadId = dwThreadId;
result = MessageBox(NULL, lpszText, lpszTitle, fuStyle);
dwGuiThreadId = 0;

/*
* Restore window station and desktop.
*/
SetThreadDesktop(hdeskSave);
SetProcessWindowStation(hwinstaSave);
CloseDesktop(hdeskUser);
CloseWindowStation(hwinstaUser);

RevertToSelf();
}

To elaborate: You can't 'simply' acces the user's desktop, as it is a secured object. But 'ImpersonateLoggedOnUser()' provides a way to get the same credentials as the user that 'owns' the desktop, so you'll be able to access it. All you need is the access token of a process running in the context of the logged-on user, so 'OpenProcessToken()' will do the job for you...
GeneralRe: Getting the access token of the logged-on user Pin
Garth J Lancaster26-Feb-03 12:32
professionalGarth J Lancaster26-Feb-03 12:32 
GeneralRe: Getting the access token of the logged-on user Pin
Neflyte26-Feb-03 16:41
Neflyte26-Feb-03 16:41 
GeneralRe: Getting the access token of the logged-on user Pin
Garth J Lancaster27-Feb-03 2:43
professionalGarth J Lancaster27-Feb-03 2:43 
GeneralGot the token, but can't Impersonate... Pin
Neflyte27-Feb-03 5:19
Neflyte27-Feb-03 5:19 
GeneralRe: Got the token, but can't Impersonate... Pin
Garth J Lancaster27-Feb-03 9:55
professionalGarth J Lancaster27-Feb-03 9:55 
GeneralCWnd * pParent in CReate() Pin
ns26-Feb-03 6:09
ns26-Feb-03 6:09 
GeneralRe: CWnd * pParent in CReate() Pin
Nitron26-Feb-03 7:54
Nitron26-Feb-03 7:54 
GeneralRe: CWnd * pParent in CReate() Pin
ns26-Feb-03 8:01
ns26-Feb-03 8:01 
GeneralRe: CWnd * pParent in CReate() Pin
Nitron26-Feb-03 8:04
Nitron26-Feb-03 8:04 
Questionhow can i see the source code? Pin
wildelf26-Feb-03 6:07
wildelf26-Feb-03 6:07 
AnswerRe: how can i see the source code? Pin
Jim A. Johnson26-Feb-03 6:11
Jim A. Johnson26-Feb-03 6:11 
GeneralRe: It's gone. Pin
wildelf26-Feb-03 6:40
wildelf26-Feb-03 6:40 
GeneralRe: It's gone. Pin
Maximilien26-Feb-03 6:46
Maximilien26-Feb-03 6:46 
GeneralRe: It's gone. Pin
wildelf26-Feb-03 6:52
wildelf26-Feb-03 6:52 
GeneralRe: It's gone. Pin
Valera24117626-Feb-03 11:11
Valera24117626-Feb-03 11:11 
GeneralRe: It's gone. Pin
Willem B27-Feb-03 0:43
Willem B27-Feb-03 0:43 
GeneralOnOK and delete this Pin
ns26-Feb-03 5:59
ns26-Feb-03 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.