“全局快捷键”与“锁定电脑”的相关问题! ( 积分: 200 )

  • 主题发起人 主题发起人 zheng
  • 开始时间 开始时间
Z

zheng

Unregistered / Unconfirmed
GUEST, unregistred user!
使用RegHotKey设置全局快捷键,常规状态可以成功响应,但在电脑被锁定(rundll32.exe user32.dll,LockWorkStation)时,快捷键就不能够响应,我就是因为很多时候需要锁定电脑,防止任何人使用电脑,但这时媒体播放软件设置的快捷键不能响应(老板键),而想自己做一个可以替换媒体播放软件设置的快捷键,这样电脑播放媒体时,如果老板来了,而电脑也处于锁定状态,仍然可以轻松应付。
 
使用RegHotKey设置全局快捷键,常规状态可以成功响应,但在电脑被锁定(rundll32.exe user32.dll,LockWorkStation)时,快捷键就不能够响应,我就是因为很多时候需要锁定电脑,防止任何人使用电脑,但这时媒体播放软件设置的快捷键不能响应(老板键),而想自己做一个可以替换媒体播放软件设置的快捷键,这样电脑播放媒体时,如果老板来了,而电脑也处于锁定状态,仍然可以轻松应付。
 
据说以下代码可以屏蔽Ctrl + Alt + Del,原理是利用:API hook,把进程注入winlogon.exe,然后把WlxLoggedOnSAS函数的地址修改为自己的函数入口(在XP下无法使用的),但我不知道怎样运行这个DLL,是在注册表中设置启动项就可以了,还是必须再做一个调用的程序(这样就很不爽)。谁能告诉我怎样调用以下代码吗?<br><br>library insertdll;<br>uses<br> Windows,<br> Messages,<br> SysUtils;<br><br>{$R *.RES}<br><br>type<br> TCode5 = packed record<br> &nbsp; siJmp : ShortInt;<br> &nbsp; dwAddr : DWORD;<br> end;<br> TThunkFunc = (tfWlxLoggedOnSAS);<br> TThunkFuncName = packed record<br> &nbsp; strMod &nbsp; &nbsp; &nbsp; &nbsp;: string; &nbsp;// 系统模块名称<br> &nbsp; strSysProc &nbsp; &nbsp;: string; &nbsp;// 系统DLL中的名字<br> &nbsp; strThunkProc &nbsp;: string; &nbsp;// 你替换的函数的名字,必须在DLL的引出表中<br> end;<br> TThunkCode = packed record<br> &nbsp; codeBak &nbsp; &nbsp; &nbsp; : TCode5; &nbsp;// 系统函数的代码的前5个字节<br> &nbsp; codeThunk &nbsp; &nbsp; : TCode5; &nbsp;// 跳转到你的代码的5个字节<br> &nbsp; addr_sys &nbsp; &nbsp; &nbsp;: Pointer; // 系统函数的地址<br> &nbsp; addr_thunk &nbsp; &nbsp;: Pointer; // 替换函数的地址<br> &nbsp; bInstalled &nbsp; &nbsp;: boolean; // 安装了吗?<br> end;<br><br>const<br> ThunkFuncNameArr : array[TThunkFunc] of TThunkFuncName = (<br> &nbsp; (strMod : 'msgina.dll'; &nbsp;strSysProc : 'WlxLoggedOnSAS'; &nbsp; &nbsp;strThunkProc : 'GanLoggedOnSAS')<br> );<br>var<br> ThunkCodeArr : array[TThunkFunc] of TThunkCode;<br> hProc : THandle;<br><br>procedure InitThunkCode;<br>var<br> tfType : TThunkFunc;<br> hMod : HMODULE;<br> pSysFunc, pThunkFunc : Pointer;<br>begin<br> for tfType := LOW(TThunkFunc) to HIGH(TThunkFunc) do begin<br> &nbsp; // clear to zero<br> &nbsp; FillChar(ThunkCodeArr[tfType], sizeof(TThunkCode), 0);<br><br> &nbsp; // fill it by right value<br> &nbsp; hMod := 0;<br> &nbsp; hMod := GetModuleHandle(PChar(ThunkFuncNameArr[tfType].strMod));<br> &nbsp; if hMod = 0 then continue;<br><br> &nbsp; pSysFunc := nil;<br> &nbsp; pSysFunc := GetProcAddress(hMod,<br> &nbsp; &nbsp; PChar(ThunkFuncNameArr[tfType].strSysProc));<br> &nbsp; if pSysFunc = nil then continue;<br><br> &nbsp; pThunkFunc := nil;<br> &nbsp; pThunkFunc := GetProcAddress(hInstance,<br> &nbsp; &nbsp; PChar(ThunkFuncNameArr[tfType].strThunkProc));<br> &nbsp; if pThunkFunc = nil then continue;<br><br> &nbsp; // now fill it!<br> &nbsp; ThunkCodeArr[tfType].addr_sys := pSysFunc;<br> &nbsp; ThunkCodeArr[tfType].addr_thunk := pThunkFunc;<br><br> &nbsp; ThunkCodeArr[tfType].codeThunk.siJmp := ShortInt($E9); &nbsp;// jmp ____<br> &nbsp; ThunkCodeArr[tfType].codeThunk.dwAddr :=<br> &nbsp; &nbsp; DWORD(pThunkFunc) - DWORD(pSysFunc) - 5;<br><br> &nbsp; ThunkCodeArr[tfType].codeBak.siJmp := PByte(pSysFunc)^;<br> &nbsp; ThunkCodeArr[tfType].codeBak.dwAddr := PDWORD(DWORD(pSysFunc)+1)^;<br> end;<br>end;<br><br>procedure InstallThunkFunc(tfType : TThunkFunc);<br>var<br> nCount : DWORD;<br>begin<br> if ThunkCodeArr[tfType].bInstalled then exit;<br> if (hProc=0) or (ThunkCodeArr[tfType].addr_sys=nil) then exit;<br> WriteProcessMemory(hProc,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ThunkCodeArr[tfType].addr_sys,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@(ThunkCodeArr[tfType].codeThunk),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nCount);<br> ThunkCodeArr[tfType].bInstalled := True;<br>end;<br><br>procedure UnInstallThunkFunc(tfType : TThunkFunc);<br>var<br> nCount : DWORD;<br>begin<br> if not ThunkCodeArr[tfType].bInstalled then exit;<br> if (hProc=0) or (ThunkCodeArr[tfType].addr_sys=nil) then exit;<br> WriteProcessMemory(hProc,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ThunkCodeArr[tfType].addr_sys,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@(ThunkCodeArr[tfType].codeBak),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nCount);<br> ThunkCodeArr[tfType].bInstalled := false;<br>end;<br><br>const<br> WLX_SAS_ACTION_NONE = 2;<br><br>function GanLoggedOnSAS(pWlxContext:pointer;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwSasType : DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pReserved : Pointer):Integer;stdcall;<br>begin<br> result := WLX_SAS_ACTION_NONE;<br>end;<br><br>var<br> hThreadHandle : THANDLE;<br><br>procedure DllMain(dwReason : DWORD);<br>var<br> dwThreadID : DWORD;<br>begin<br> case dwReason of<br> &nbsp; DLL_PROCESS_ATTACH :<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; InitThunkCode;<br> &nbsp; &nbsp; &nbsp; InstallThunkFunc(tfWlxLoggedOnSAS);<br> &nbsp; &nbsp; end;<br> &nbsp; DLL_PROCESS_DETACH :<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; UninstallThunkFunc(tfWlxLoggedOnSAS);<br> &nbsp; &nbsp; &nbsp; CloseHandle(hProc);<br> &nbsp; &nbsp; end;<br> &nbsp; DLL_THREAD_ATTACH :<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; end;<br> &nbsp; DLL_THREAD_DETACH :<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; end;<br> end;<br>end;<br><br>exports<br> GanLoggedOnSAS;<br><br>begin<br> DLLProc := @DLLMain;<br> hProc := OpenProcess(PROCESS_ALL_ACCESS,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FALSE,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetCurrentProcessID());<br> DLLMain(DLL_PROCESS_ATTACH);<br>end.
 
關注.............................
 
谁能告诉怎样使用上面“library insertdll”的代码吗?
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部