外壳ShellExecute函数截取扩展

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
{-----------------------------------------------------------------------------
Unit Name: ShellExecuteHookObj
Author: hubdog
Purpose: 外壳ShellExecute函数截取扩展
History: 2001-05-01
-----------------------------------------------------------------------------}
 
unit ShellExecuteHookObj;
interface
uses
Windows, ActiveX, ComObj, ShlObj, ShellAPI;
type
TTShellExecuteHook = class(TComObject, IShellExecuteHook)
protected
function Execute(var ShellExecuteInfo: TShellExecuteInfo): HResult; stdcall;
end;
const
Class_TShellExecuteHook: TGUID = '{935FA400-243D-11D3-B06E-857B2AE2BE64}';
implementation
resourcestring
sCreateRegKeyError = '创建注册表项失败';
type
TShellExComObjectFactory = class(TComObjectFactory)
public
procedure UpdateRegistry(Register: Boolean); override;
end;
{ TShellExComObjectFactory }
function TTShellExecuteHook.Execute(var ShellExecuteInfo: TShellExecuteInfo): HResult;
var
FileName: string;
begin
Result := S_FALSE;
with ShellExecuteInfo do
begin
FileName := UpperCase(ExtractFileName(lpFile));
if Pos('NOTEPAD', FileName) = 1 then
begin
Result := S_OK;
hInstApp := 32;
MessageBox(Wnd, '不允许记事本运行!', '错误', MB_OK or MB_ICONERROR);
end;
end;
end;
procedure TShellExComObjectFactory.UpdateRegistry(Register: Boolean);
const
hellExecuteHooksKey = 'SOFTWARE';
var
Handle: HKey;
Status, Disposition: Integer;
ClassID: string;
begin
ClassID := GUIDToString(Class_TShellExecuteHook);
if Register then
begin
Status := RegCreateKeyEx(HKEY_LOCAL_MACHINE, PChar(ShellExecuteHooksKey), 0, '',
REG_OPTION_NON_VOLATILE, KEY_READ or KEY_WRITE, nil, Handle, @Disposition);
if Status = 0 then
begin
Status := RegSetValueEx(Handle, PChar(ClassID), 0, REG_SZ,
PChar(Description), Length(Description) + 1);
RegCloseKey(Handle);
end;
end else
begin
Status := RegOpenKeyEx(HKEY_LOCAL_MACHINE, PChar(ShellExecuteHooksKey), 0,
KEY_READ or KEY_WRITE, Handle);
if Status = 0 then
begin
Status := RegDeleteValue(Handle, PChar(ClassID));
RegCloseKey(Handle);
end;
end;
if Status <> 0 then raise EOleError.Create(sCreateRegKeyError);
inherited UpdateRegistry(Register);
end;
initialization
TShellExComObjectFactory.Create(ComServer, TTShellExecuteHook, Class_TShellExecuteHook,
'TShellExecuteHook', 'ShellExecute hook sample', ciMultiInstance, tmApartment);
end.
 

Similar threads

S
回复
0
查看
700
SUNSTONE的Delphi笔记
S
S
回复
0
查看
694
SUNSTONE的Delphi笔记
S
I
回复
0
查看
646
import
I
后退
顶部