Solved

Unable to set a hook to a process created in winlogon

Posted on 2004-10-18
7
520 Views
Last Modified: 2013-12-03
Hi,

I am having a problem not being able to hook into a process created by CreateProcess:

    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    si.lpDesktop = "Winsta0\\Winlogon";
    ZeroMemory( &pi, sizeof(pi) );

    if(!CreateProcess( NULL,
        TEXT("Notepad.exe"),
        NULL,
        NULL,
        TRUE,
        0,
        NULL,
        NULL,
        &si,
        &pi )
    )
    return false;

    if(!g_hHook_Keyboard)
    {
      g_lpHookProc_Keyboard = (HOOKPROC) HookProcKeyboard;
      b_Success_Keyboard = (NULL != (g_hHook_Keyboard = ::SetWindowsHookEx (WH_KEYBOARD, g_lpHookProc_Keyboard, (HINSTANCE)pi.hProcess, NULL)));
    }

It returns "false" for "b_Success_Keyboard"

Any help will be appreciated..
Thanks a lot.
0
Comment
Question by:ewong_111
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 12343463
You need to change your process'/threads window station and desktop using the appropriate APIs ('SetProcessWindowStation()'/'SetThreadDesktop()') to the one the process that you want to hook is using, otherwise it won't work.
0
 
LVL 2

Author Comment

by:ewong_111
ID: 12349287
jkr..

I have inserted the follow code before the "if(!g_hHook_Keyboard)"

      HWINSTA h_Winsta = OpenWindowStation((LPCTSTR)"Winsta0", TRUE, GENERIC_ALL);
      if (!SetProcessWindowStation(h_Winsta)) AfxMessageBox("SetProcessWindowStation Failed");

      HDESK h_Desk = OpenDesktop((LPCTSTR)"Winlogon", 0, TRUE, GENERIC_ALL);
      if (!SetThreadDesktop(h_Desk)) AfxMessageBox("SetThreadDesktop Failed");

but unfortunately it still returns "false" for "b_Success_Keyboard"

      if (b_Success_Keyboard) AfxMessageBox("Success on Keyboard Hook");
      else AfxMessageBox("Failed on Keyboard Hook");

but now the AfxMessageBox is showing up in the "Winlogon" desktop now.
Any more ideas?
Thanks a lot.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 12349343
Ay, wasn't paying attention to the term 'Keyboard Hook' - you will not be allowed to install such a hook on the winlogon desktop for security reasons, since that would enable you to grab the passwords that are entered there...
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:ewong_111
ID: 12349361
so, what kind of hook will be allowed there?
and is it true for Screen-saver also?
Thanks again..
0
 
LVL 86

Expert Comment

by:jkr
ID: 12354378
Actually, what is it that you have to hook the logon desktop for? To know the purpose might help to find a suggestion around that :o)
0
 
LVL 2

Author Comment

by:ewong_111
ID: 12360615
jkr,

Thanks a lot for your help, but you have already answered this question in another question I posted.
http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_21174306.html
I guess you just have too many questions each day to answer that you didn't notice it right?
Thanks again for your motivation for helping..

:D
0
 
LVL 86

Expert Comment

by:jkr
ID: 12360863
Well, I thought these were two completely separate issues :o)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Nest Related files not working in Visual Studio 4 80
Example of WebAPI 7 33
Having a different time zone on your task bar 3 71
Please explain "Multi-Tenant Services" 5 99
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question