Solved

Sample code for IShellExecuteHook

Posted on 2000-05-04
6
1,933 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…

733 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