Solved

Sample code for IShellExecuteHook

Posted on 2000-05-04
6
1,904 Views
Last Modified: 2011-05-05
Hello,

I need the complete code for an small application (or DLL?) which use the IShellExecuteHook function.
(The best sample would be: Befor a application starts a messagebox should display with the question: "Should the file "notepade.exe" be executed?" [Yes] [No])

Thank you!

Kann
0
Comment
Question by:Kann
6 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 200 total points
ID: 2776756
I've digged in my download folder and found this extract. Perhaps it helps you.

unit StartRunHook;

interface

uses
  Windows, ActiveX, ComObj, ShlObj, ShellApi;

type
  TShellExecuteHook = class(TComObject, IShellExecuteHook)
  public
    function Execute(var ShellExecuteInfo: TShellExecuteInfo):HResult;stdcall;
  end;

const
  Class_ShellExecuteHook: TGUID = '{29F97553-FBD6-11D1-AFC1-00A024D1875F}';
implementation

uses ComServ, SysUtils, Registry;

function TShellExecuteHook.Execute(var ShellExecuteInfo: TShellExecuteInfo):HResult;
  begin
  ShellExecuteInfo.hinstapp := 33; // > 32
  // confirm operation
  Result := MessageBox(0, 'Fred',
    'IShellExecuteHook Shell Extension...' , MB_YESNOCANCEL);
end;

type
  TShellExecuteHookFactory = class(TComObjectFactory)
  public
    procedure UpdateRegistry(Register: Boolean); override;
  end;

procedure TShellExecuteHookFactory.UpdateRegistry(Register: Boolean);
var
  ClassID: string;
begin
  if Register then
    begin
      inherited UpdateRegistry(Register);
      ClassID := GUIDToString(Class_ShellExecuteHook);
      with TRegistry.Create do
        try
          RootKey := HKEY_LOCAL_MACHINE;
          OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions', True);
          OpenKey('Approved', True);
          WriteString(ClassID, 'Chameleon ShellExecute Hook');
          CloseKey;
          OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\ShellExecuteHooks\', True);
          WriteString(ClassID, '');
        finally
          Free;
        end;
      end
  else
    inherited UpdateRegistry(Register);
end;

initialization
  TShellExecuteHookFactory.Create(ComServer, TShellExecuteHook, Class_ShellExecuteHook, '',
    'Chameleon ShellExecute Hook', ciMultiInstance, tmApartment);
end.

Regards, Madshi.

P.S: Ehm, I'm quite sure that this API only hook ShellExecute(Ex) calls, but NOT CreateProcess calls. I hope, that's no problem for you...
0
 
LVL 3

Expert Comment

by:shenqw
ID: 2777190
function TShellExecuteHook.Execute(var ShellExecuteInfo: TShellExecuteInfo):HResult;
  begin
  ShellExecuteInfo.hinstapp := 33; // > 32
  // confirm operation
  Result := MessageBox(0, 'Fred',
    'IShellExecuteHook Shell Extension...' , MB_YESNOCANCEL);
end;

may be changed like this:

function TShellExecuteHook.Execute(var ShellExecuteInfo: TShellExecuteInfo):HResult;
  begin
  ShellExecuteInfo.hinstapp := 33; // > 32
  // confirm operation
  Result:=S_FALSE;
  if MessageBox(0, 'Go on?',
    'IShellExecuteHook Shell Extension...' , MB_YESNO)=IDNO then
    result:=S_OK;
end;


Good Luck.

shenqw


  Result:=S_FALSE;
  if MessageBox(0, 'Go on?',
    'IShellExecuteHook Shell Extension...' , MB_YESNO)=IDNO then
    result:=S_OK;
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2778859
Listening
0
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.

 
LVL 20

Expert Comment

by:Madshi
ID: 2787392
Kann?
0
 

Author Comment

by:Kann
ID: 2787598
Thank you for your help!



> P.S: Ehm, I'm quite sure that this API only hook ShellExecute(Ex) calls, but NOT CreateProcess
> calls. I hope, that's no problem for you...

Do you know any example for this (when does a program be started by CreateProcess?)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2787714
CreateProcess is often used, when one programs executes another one. E.g. if a starter application starts another application and waits until the other application is finished. You can't do this with ShellExecute (I mean wait for the other app to finish).

Regards, Madshi.
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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

15 Experts available now in Live!

Get 1:1 Help Now