ActiveX 钩子屏蔽功能键

6 篇文章 0 订阅

//以备后用

// test.cpp : Implementation of CTestApp and DLL registration.

#include "stdafx.h"
#include "test.h"

//
//附加头

#include "winuser.h"

#define _WIN32_WINNT 0x0400
#define WH_KEYBOARD_LL 13

const byte LLKHF_ALTDOWN = 0x20;

/

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
//附加函数

HHOOK installhook(void); //钩子安装函数
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);//挂钩函数
BOOL uninstallhook(void); //拆卸钩子
BOOL limitcontrol(void);
BOOL unlimitcontrol(void);
/

CTestApp NEAR theApp;

const GUID CDECL BASED_CODE _tlid =
        { 0x30534bf3, 0x7263, 0x434c, { 0x95, 0xa9, 0x3, 0xc1, 0x10, 0xbd, 0xd2, 0xf } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;

//定义结构 变量

typedef struct {
    DWORD vkCode;
    DWORD scanCode;
    DWORD flags;
    DWORD time;
    ULONG_PTR dwExtraInfo;
} KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;

static HHOOK phk=NULL;


// CTestApp::InitInstance - DLL initialization

BOOL CTestApp::InitInstance()
{
    BOOL bInit = COleControlModule::InitInstance();

    if (bInit)
    {
        // TODO: Add your own module initialization code here.

        ::MessageBox(NULL,"Active 加载","提示",MB_OK);
        limitcontrol();
        installhook();

    //    system("C:\\PROGRA~1\\INTERN~1\\iexplore -k www.baidu.com");

    }

    return bInit;
}


// CTestApp::ExitInstance - DLL termination

int CTestApp::ExitInstance()
{
    // TODO: Add your own module termination code here.

    uninstallhook();
    unlimitcontrol();
    ::MessageBox(NULL,"Active 退出","提示",MB_OK);

    return COleControlModule::ExitInstance();
}

/
// DllRegisterServer - Adds entries to the system registry

STDAPI DllRegisterServer(void)
{
    AFX_MANAGE_STATE(_afxModuleAddrThis);
    ::MessageBox(NULL,"Active 注册","提示",MB_OK);

    if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
        return ResultFromScode(SELFREG_E_TYPELIB);

    if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
        return ResultFromScode(SELFREG_E_CLASS);

    return NOERROR;
}

/
// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServer(void)
{

    ::MessageBox(NULL,"Active 卸载","提示",MB_OK);

    AFX_MANAGE_STATE(_afxModuleAddrThis);

    if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
        return ResultFromScode(SELFREG_E_TYPELIB);

    if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
        return ResultFromScode(SELFREG_E_CLASS);

    return NOERROR;
}

HHOOK installhook()
{
    phk=SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)KeyboardProc,GetModuleHandle(NULL),0);

    if(phk==NULL)
        ::MessageBox(NULL,"键盘监控未启动","提示",MB_OK);
        ::MessageBox(NULL,"键盘监控启动","提示",MB_OK);
    return phk;
}

LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{

    if(HC_ACTION==nCode)
    {
          // ::MessageBox(NULL,"测试点","提示",MB_OK);
        switch(wParam)
        {
       case WM_KEYDOWN:    
       case WM_SYSKEYDOWN: 
       case WM_KEYUP:   
       case WM_SYSKEYUP: 

           PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam;

            if((p->flags & LLKHF_ALTDOWN)!=0) return 1;  //屏蔽 tab + alt / alt
            switch(p->vkCode)
                {
                case VK_LWIN:   //左右 win功能键
                case VK_RWIN:
                case VK_F5:   
                case VK_F4:
                case VK_ESCAPE:    //屏蔽 esc
                case VK_F11:
                case VK_APPS:
                case VK_F1:
                      return 1;
                }
                break;
       }
     }

     return CallNextHookEx( phk, nCode, wParam, lParam );
}

BOOL uninstallhook()
{
     if(phk)
         if(!UnhookWindowsHookEx(phk))
               ::MessageBox(NULL,"键盘无法正常监控关闭","提示",MB_OK);
               ::MessageBox(NULL,"键盘监控关闭","提示",MB_OK);
     return true;
}

BOOL limitcontrol(void)
{

   HKEY hKey;
   DWORD wt = 1;
   if( (RegCreateKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",&hKey)==0 )&&( RegSetValueEx(hKey,"DisableTaskMgr",0,REG_DWORD,(const BYTE*)&wt,4)==0) )
       ::MessageBox(NULL,"禁用任务管理器","提示",MB_OK);
    else
       ::MessageBox(NULL,"禁用任务管理器失败","提示",MB_OK);
    RegCloseKey(hKey);

    return true;
}

BOOL unlimitcontrol(void)
{

    HKEY hKey;

    if(RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",0,KEY_WRITE,&hKey)==0)
    {
        if(RegDeleteValue(hKey,"DisableTaskMgr")==0)
               ::MessageBox(NULL,"恢复任务管理器","提示",MB_OK);

        RegCloseKey(hKey);
         return true;
    }
          ::MessageBox(NULL,"任务管理器未有恢复","提示",MB_OK);

    return false;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值