Solved

close the favorites window in internet explorer + delphi

Posted on 2006-07-03
14
278 Views
Last Modified: 2010-04-05
hi there experts,

this is my problem

1) i open the internet explorer application
2) i click the ""Favorites" button on the standard buttons menu
3) the favorites menu appears on the left hand side.

i want to be able to close that  "Favorites" window using delphi

procedure ClosefavWindow;
var
th:thandle;
  begin
    th:=FindWindow('IEFrame',nil);
//using findwindowex somewhere here
    SendMessage(th, wm_close, 0, 0);
end;  



thanks
0
Comment
Question by:nikolaosk
  • 9
  • 5
14 Comments
 
LVL 16

Expert Comment

by:CodedK
Comment Utility
Hi nikolaosk...

What about this :

procedure TForm1.Button3Click(Sender: TObject);
begin
 SetForegroundWindow(FindWindow('IEFrame',nil));
 Application.ProcessMessages;

 keybd_event(VK_CONTROL,0,0,0);       //Hold Ctrl
 keybd_event(ord('I'),0,0,0);                //Press I

 keybd_event(ord('I'),0,KEYEVENTF_KEYUP,0);             //Release I
 keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);   //Release Ctrl
end;

This will sent the Ctrl+I to the IExplorer window.
0
 
LVL 16

Expert Comment

by:CodedK
Comment Utility
You can also try a different approach through the registry :

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Toolbar\WebBrowser\ITBarLayout

Disabled :
HKU\Software\Microsoft\Internet Explorer\Toolbar\WebBrowser\ITBarLayout:

11 00 00 00 4C 00 00 00 00 00 00 00 34 00 00 00 1F 00 04 00 57 00 00 00 01 00 00 00 20 07 00 00 A0
0F 00 00 05 00 00 00 62 05 00 00 26 00 00 00 02 00 00 00 21 07 00 00 A0 0F 00 00 04 00 00 00 21 01
00 00 A0 0F 00 00 03 00 00 00 20 03 00 00 00 00 00 00 08 00 00 00 60 05 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 39 35 83 47 C5 D0 25 41 9F A8 08 19 E2 EA AC 93 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

Enabled :

11 00 00 00 4C 00 00 00 00 00 00 00 34 00 00 00 1F 00 04 00 57 00 00 00 01 00 00 00 20 07 00 00 A0
0F 00 00 05 00 00 00 62 05 00 00 26 00 00 00 02 00 00 00 21 07 00 00 A0 0F 00 00 04 00 00 00 21 01
00 00 A0 0F 00 00 03 00 00 00 20 03 00 00 00 00 00 00 08 00 00 00 60 05 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 39 35 83 47 C5 D0 25 41 9F A8 08 19 E2 EA AC 93 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 61 4E A2 EF 78 B0 D0 11 89 E4 00 C0 4F C9 E2 6E 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00

Hope this helps.
0
 

Author Comment

by:nikolaosk
Comment Utility
hi there CodedK,

your code works. but there is an obvious problem. i want to send the ctrl+I, only when the favorites button on the standard button toolbar is enabled.only then. if it is not enabled-pressed then by sending the ctrl+I has the oppossite effect than the one i want.so i want to check first if the favorites button is enabled and then use your code

thanks
0
 
LVL 16

Expert Comment

by:CodedK
Comment Utility
Thats true ...
Well try that:

This is the unit:
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Registry, StrUtils;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function ReadRegBinary(Key: HKEY; Name: string; var Buffer; BufSize: Integer): integer;
var
  DataType: Integer;
  Status: integer;
begin
  result := -1;
  DataType := REG_NONE;
  try
    // return the size of the buffer required
    if BufSize = 0 then begin
    // get data type and buffer size
      Status := RegQueryValueEx(Key, PChar(Name), nil, @DataType, nil, @BufSize);
      if Status  = ERROR_SUCCESS then begin
        result := BufSize;
      end;
    end else begin
      // get data
      if RegQueryValueEx(Key, PChar(Name), nil, @DataType, PByte(Buffer),
         @BufSize) = ERROR_SUCCESS then result := BufSize
      else result := -1;
    end;
  except
    result := -1;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  Key: HKEY;
  buf: array of byte;
  size: integer;
  i,loop: integer;
  s: string;
begin
  Memo1.Clear;
  if RegOpenKeyEx
  (HKEY_CURRENT_USER, 'Software\Microsoft\Internet Explorer\Toolbar\WebBrowser', 0, KEY_READ, Key)
  = ERROR_SUCCESS then
  try
    size := ReadRegBinary(Key, 'ITBarLayout', buf, 0);
    if size <> -1 then begin
      SetLength(buf, size);
      ReadRegBinary(Key, 'ITBarLayout', buf, size);
    end;
  finally
    RegCloseKey(Key);
  end;

  s := '';
  for i := 0 to High(buf) do begin
    s := s + IntToHex(buf[i],2);
  end;
  Memo1.Lines.Add(s);

  for i:=0 to Memo1.Lines.Count-1 do
  if AnsiContainsStr(Memo1.Lines[i],'614EA2EF78B0D01189E400C04FC9E26E')
  then
   begin
     SetForegroundWindow(FindWindow('IEFrame',nil));
     Application.ProcessMessages;

     keybd_event(VK_CONTROL,0,0,0);
     keybd_event(ord('I'),0,0,0);

     keybd_event(ord('I'),0,KEYEVENTF_KEYUP,0);
     keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
   end;
end;

end.
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-



This is the form 'dfm' ... DONT FORGET to put both scroll bars in memo1.....
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
object Form1: TForm1
  Left = 437
  Top = 400
  Width = 216
  Height = 98
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 72
    Top = 16
    Width = 89
    Height = 25
    Caption = 'Send command'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Memo1: TMemo
    Left = 8
    Top = 8
    Width = 25
    Height = 25
    ScrollBars = ssBoth
    TabOrder = 1
    Visible = False
  end
end

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

:)
0
 
LVL 16

Expert Comment

by:CodedK
Comment Utility
Above i just check the registry if it contains the value :
'614EA2EF78B0D01189E400C04FC9E26E'

inside the key : 'ITBarLayout'

Path :
"HKEY_CURRENT_USER --->  Software\Microsoft\Internet Explorer\Toolbar\WebBrowser"

If thats true it will send Ctrl+I to Internet Explorer.
The code is little big for the "read registry" part coz data is in binary !

So i hope you'll be happy :)
0
 

Author Comment

by:nikolaosk
Comment Utility
thanks but is there any other way to check that the favorites button is enabled other than reading the registry?

wy do i need the memo1 in your code?
0
 
LVL 16

Expert Comment

by:CodedK
Comment Utility
I store the value from the registry inside the memo....
Its too big to store in a string.
I told you to put both scrolls so i can find the value = 614EA2EF78B0D01189E400C04FC9E26E.

I'd guess that it could be done with the class of the favorites window BUT
even if i tried with several child classes that belong to that window ... I couldnt send the
commands !!!

Anyway there is always another way :)

Its not too big, its just the function plus 10 lines and the Send Ctrl+I commands.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:nikolaosk
Comment Utility
if you are telling me that the this registry key will be in the same path for all computers running windows xp and windows 2000 like below

inside the key : 'ITBarLayout'

Path :
"HKEY_CURRENT_USER --->  Software\Microsoft\Internet Explorer\Toolbar\WebBrowser"

then i i will use your code.

i am going to use that code in a dll. so i can not have memo objects and buttons

i need the function as it is

function ReadRegBinary(Key: HKEY; Name: string; var Buffer; BufSize: Integer): integer;


but i need the other to be a dll function

somthing like this

function sendmessagetofavorites

//if favorites is eabled then


begin
     SetForegroundWindow(FindWindow('IEFrame',nil));
     Application.ProcessMessages;

     keybd_event(VK_CONTROL,0,0,0);
     keybd_event(ord('I'),0,0,0);

     keybd_event(ord('I'),0,KEYEVENTF_KEYUP,0);
     keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
end function



thanks a lot
0
 
LVL 16

Expert Comment

by:CodedK
Comment Utility
:/
I dont have a pc with win2k that i can experiment BUT i can tell you
that even if you go with the class method you should take this under consideration too :

Next version of IExplorer is on the way.
Next Windows version is on the way.

I'll keep on searching for the right class :)
0
 
LVL 16

Expert Comment

by:CodedK
Comment Utility
As for WinXP i am sure that this solution will work in every pc.
0
 

Author Comment

by:nikolaosk
Comment Utility
thanks for your effort. let me know if the classname approach works.otherwise we will have to go from the registry

0
 
LVL 16

Expert Comment

by:CodedK
Comment Utility
Give me one or two days :)
0
 

Author Comment

by:nikolaosk
Comment Utility
okey.thanks
0
 
LVL 16

Accepted Solution

by:
CodedK earned 250 total points
Comment Utility
:) :) :)

Okey ! I found it !   :) :)
(It took me some hours and i think that i'm happier than you !)

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
procedure TForm1.Button1Click(Sender: TObject);
begin
 If FindWindowex(FindWindow('IEframe',nil),0,'BaseBar',nil)<>0 then
  If IsWindowVisible(FindWindowex(FindWindow('IEframe',nil),0,'BaseBar',nil)) then
    Begin
      SetForegroundWindow(FindWindow('IEFrame',nil));
      Application.ProcessMessages;

      keybd_event(VK_CONTROL,0,0,0);
      keybd_event(ord('I'),0,0,0);

      keybd_event(ord('I'),0,KEYEVENTF_KEYUP,0);
      keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
   end;
end;
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

The only thing that could reduce the code now is to directly send the command to the handle of the child window
to close... But if you close it Explorer things that it crashed and it close itself !

So i should just set it to invisible...
If i find how... i'll post :)

Hope that would do :)

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

6 Experts available now in Live!

Get 1:1 Help Now