偶写了个全局钩子dll,用一个exe调用,效果正常。
现在在一个service的dispatcher里开一个thread做这个exe做的事情,结果就无效果了看了一下,好像是Redirect IAT的时候扫描不到之类。

解决方案 »

  1.   

    另外,程序的运行有Window Stations, and Desktops的区别,在一个Desktops下的进程不能Hook另外Desktops下的进程,以下是Jerry Richter的原文:
    A desktop consists of a logical display surface and a set of user objects: windows, menus, and hooks. Threads are also associated with desktops. (See the SetThreadDesktop and GetThreadDesktop functions in the Platform SDK documentation.) If a thread associated with one desktop attempts to send a message to a window created on another desktop, the system fails the call. This is the security mechanism at work. Likewise, a thread can't install a hook on a thread that's part of another desktop.我估计就是这个原因。
      

  2.   

    haocb_jia(独孤一笑)说的有道理。
      

  3.   

    是在同一个桌面下,不是haocb_jia(独孤一笑)说的那种情况。难道windows故意限制在服务中使用全局钩子?
      

  4.   

    愿闻其详?事实上偶在dispatcher中直接运行那个exe都不行,ft......
      

  5.   

    试试在服务程序的源代码中加入代码:HDESK hdesk=OpenDesktop("Default",0,0,DESKTOP_SWITCHDESKTOP);
    SwitchDesktop(hdesk);
      

  6.   

    搞错了,应该是
    HDESK hdeskUser = OpenDesktop("Default",0,FALSE,MAXIMUM_ALLOWED);
    SetThreadDesktop(hdeskUser); 或者,在使用CreateService创建服务时dwServiceType参数设为SERVICE_INTERACTIVE_PROCESS