Solved

Sample code for IShellExecuteHook

Posted on 2000-05-04
6
1,909 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

20 Experts available now in Live!

Get 1:1 Help Now