Solved

Sample code for IShellExecuteHook

Posted on 2000-05-04
6
1,921 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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