?
Solved

Sample code for IShellExecuteHook

Posted on 2000-05-04
6
Medium Priority
?
1,952 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 600 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
Industry Leaders: 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 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