Solved

Unable to set a hook to a process created in winlogon

Posted on 2004-10-18
7
499 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Author Comment

by:ewong_111
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Well, I thought these were two completely separate issues :o)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now