Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

Disable (or) Hide Internet Explorer (Preferably Disable Temporarily During Programs Session)

Hello All;

   In one of my long awaiting project. (Been messing with it off and on for about 4yrs now)
One of the things that I have searched for information about and have had no luck in finding.
Is to: Disable IE.

OK. When the program loads it will automatically [Disable] Internet Explorer during the Session.
Once the Program is closed, Then [Enable] Internet Explorer.

Some people have told me that it would be best to: [Hide] the Desktop & Toolbar Shortcuts.
This is fine, but if the person knows where the ie.exe is actually located at, then they can launch
It from there, thus making the program useless while IE is running.
(The program is a Decendent of IE. As in, using TEmbeddedWB).

So, any information on the [Disable] of IE?
Thank You
Carrzkiss
Avatar of CodedK
CodedK
Flag of Greece image

Hi Carrzkiss.

What to you think about this.

Timer1 Interval :=100 msecond.

Insert a timer in the form and onTimer event use this code :

Public variable
     ProcessHandle: THandle;

....
Your code
....

Procedure TForm1.Timer1Timer(Sender: TObject);
var
  pid,ExitCode : Cardinal;
begin
      Repeat
      begin
       GetWindowThreadProcessId(FindWindow('IEFrame', nil), @pid);
       ProcessHandle := OpenProcess($0001, FALSE, pid);
       GetExitCodeProcess(ProcessHandle, ExitCode);
       TerminateProcess(ProcessHandle, ExitCode);
       CloseHandle(ProcessHandle);
      end until FindWindow('IEFrame', nil)=0;
end;

Hope this helps.
For other programs you could use "TEmbeddedWB" instead of IEFrame depending
on the class or the name of the application you are expecting to block.
Avatar of Tueblo
Tueblo

What about getting the filename (iexplore.exe) and renaming it upon start and give it back the original name on closing your program. You can even rename, move and hide it, as long as you put it all back upon closing your program. Quick and easy.
You can assume iexplore.exe to be in the standard place (%program files%\Internet Explorer\iexplore.exe) or extract the path from the registry.

Regards !
Tueblo
Well, after renaming you can even place an own program named "iexplore.exe" at the original location, that pops a window saying "Internet Eplorer is temporarily out  of service.".

Just an idea.
Wayne,

Hopefully this does not sound like a stupid question, but what is the end purpose / goal (what effect is desired) of disabling IE while your program is running? Are you trying to limit browsing, etc?

It is helpful to keep in mind the fact that later OS's have the IE browser window embedded in them, eg: On XP, if you double click on "My Computer", then type "http://www.google.com" in the address bar and press enter, you are off and browsing without IE running, as the browser component is embedded in the Explorer window.

Trying to rename iexplore.exe is not such a good idea either, as it is now one of the files that is protected by windows (placed in C:\WINDOWS\system32\dllcache). Renaming or removing it results in Windows pulling a copy from the cache and replacing it again. Viola, instant repair

Now, if you are only interested in thehandling of  Explorer / IE windows, then the follwing can be used to supress them while your app is running. It uses the ShellWindows from SHdocVw to bind the register and revoke events that occur when an explorer or IE window is opened / closed:

---

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ActiveX, ShDocVw;

type
  TForm1            =  class(TForm)
     procedure      FormCreate(Sender: TObject);
  private
     // Private declarations
     FShellWindows: TShellWindows;
  protected
     // Protected declarations
     procedure      OnWindowRegistered(Sender: TObject; lCookie: Integer);
     procedure      OnWindowRevoked(Sender: TObject; lCookie: Integer);
  public
     // Public declarations
  end;

var
  Form1:            TForm1;

implementation
{$R *.DFM}

procedure TForm1.OnWindowRegistered(Sender: TObject; lCookie: Integer);
var  ovItem:        OleVariant;
     dwIndex:       Integer;
     hwndItem:      HWND;
begin

  // New window was registered
  for dwIndex:=0 to Pred(FShellWindows.Count) do
  begin
     // Get item
     ovItem:=FShellWindows.Item(dwIndex);
     // Check item
     if (TVariantArg(ovItem).vt = VT_DISPATCH) and  Assigned(TVariantArg(ovItem).pdispVal) then
     begin
        // Get window handle
        hwndItem:=ovItem.HWND;
        // Check
        if (hwndItem <> 0) then
        begin
           // Destroy window
           PostMessage(hwndItem, WM_CLOSE, 0, 0);
           PostMessage(hwndItem, WM_QUIT, 0, 0);
        end;
     end;
  end;

end;

procedure TForm1.OnWindowRevoked(Sender: TObject; lCookie: Integer);
begin
  // Window was revoked, do whatever
  beep;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FShellWindows:=TShellWindows.Create(Self);
  FShellWindows.OnWindowRegistered:=OnWindowRegistered;
  FShellWindows.OnWindowRevoked:=OnWindowRevoked;
  FShellWindows.Connect;
end;

end.

---

If you are interested in locking down inbound / outbound IP traffic, then I also have code that does that as well. It just depends on what you are trying to do (and the "WHY", so alternatives can be looked at as well). A little more info would help in the quest to find a solution that produces the desired effect you are looking for.

Best regards,
Russell
Youll have to disable 2 things for that too work because

explorer.exe
and
iexplore.exe

act as webbrowsers so couple of ideas...

1. Create a proccess list, when either of the 2 are launched, your program detectes this and kills the proccess
2. On the launching of your program find and rename the iexplore.exe to tempie.bak (or whatever) and when you program  
    has finished its run use onclose/ondestroy method to rename that file back to iexplore
3. Create a procedure to edit the following reg entries

###warning you do this at your own risk###

        [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies]

        [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
        "Btn_Search"=dword:00000002
        "NoBandCustomize"=dword:00000001

        [HKEY_CURRENT_USER\Software\Policies]

        [HKEY_CURRENT_USER\Software\Policies\Microsoft]

        [HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer]

        [HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Restrictions]
        "NoBrowserOptions"=dword:00000001
        "NoBrowserBars"=dword:00000001
        "NoFavorites"=dword:00000001
        "NoBrowserContextMenu"=dword:00000001
        "NoBrowserSaveAs"=dword:00000001
        "NoFileNew"=dword:00000001
        "NoFileOpen"=dword:00000001
        "NoFindFiles"=dword:00000001
        "NoSelectDownloadDir"=dword:00000001
        "NoTheaterMode"=dword:00000001
        "NoOpeninNewWnd"=dword:00000001
        "NoViewSource"=dword:00000001
        "NoNavButtons"=dword:00000001
        "NoPrinting"=dword:00000001
       
        [HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Toolbars]

        [HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Toolbars\Restrictions]
        "NoAddressBar"=dword:00000001
        "NoToolbarOptions"=dword:00000001

##########################

4. Restrict access to the Internet when using Internet Explorer and other Microsoft compatible products such as Office.
    http://www.winguides.com/registry/display.php/1288/

Hope this helps in some way

Peace Scay7
Avatar of Wayne Barron

ASKER

Hello Everyone.
Never thought that I would get this much response to this posting.

OK. A little more insight to what I am needing to do here, and "WHY"?

The program that I have been messing with for the last couple of year. (Russell you have assist me before
On manipulating IE PopupMenu Items a few years ago).

The program is for our "Children".
When the program is run, the program has listed sites that the children can go to
That are "Safe".

Lets say that a child uses the program, and well, a never child gets him/her to go to another site
That have stuff that is either "Unsafe" (or) "Adult ONLY".
If the program can somehow "Stop" IE from running, then the child will be unable to go to the site.

What if the child just closes the program, and then opens IE to browse to the site(s) that they
Should not be on?
Having an "Administration" in the program will help to solve that issue.

During the  OnClose event, a TForm will appear that will ask for a [Password] to be typed in.
(Not implemented yet) This [Password] is only known by the Parent and not by the Child.
So they are stuck using the program until a Parent (or) Guardian unlocks the program to finally
Allow it to close.

So having this Security involved into the program, will help the Parents to better monitor
Their Children while on the Computer.

--------------------------
I hope that this makes since to everyone.

I will test your codes out here in a few, to see what my findings are.

Thank you all;
Wayne

Got it, makes perfect sense.

Sample application that hooks events for all active IE and Explorer windows, and allows you to cancel navigation based on whatever criteria you want (the example uses a memo). The example is not polished, but it does provide the basics for allowing/denying navigation.

Russell

---

unit Unit1;

interface

//
// My source for IEEvents.pas can be obtained from
// http://www.swissdelphicenter.ch/torry/showcode.php?id=2058
//

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Contnrs, ActiveX, ShDocVw, IEEvents;

const
  WM_ONQUIT         =  WM_USER + 10;

type
  TForm1            =  class(TForm)
     Memo1:         TMemo;
     procedure      FormCreate(Sender: TObject);
     procedure      FormDestroy(Sender: TObject);
  private
     // Private declarations
     FShellWindows: TShellWindows;
     FWindows:      TList;
     FHandlers:     TObjectList;
  protected
     // Protected declarations
     procedure      OnQuit(Sender: TObject);
     procedure      OnBeforeNavigate(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant; var Flags: OleVariant; var TargetFrameName: OleVariant; var PostData: OleVariant; var Headers: OleVariant; var Cancel: WordBool);
     procedure      OnWindowRegistered(Sender: TObject; lCookie: Integer);
     procedure      WMOnQuit(var Message: TMessage); message WM_ONQUIT;
  public
     // Public declarations
  end;

var
  Form1:            TForm1;

implementation
{$R *.DFM}

procedure TForm1.OnQuit(Sender: TObject);
begin

  // Post message so we can clean the item from the list
  PostMessage(Handle, WM_ONQUIT, Integer(Pointer(Sender)), 0);

end;

procedure TForm1.WMOnQuit(var Message: TMessage);
var  dwIndex:       Integer;
begin

  dwIndex:=FHandlers.IndexOf(Pointer(Message.wParam));
  if not(dwIndex < 0) then
  begin
     FHandlers.Delete(dwIndex);
     FWindows.Delete(dwIndex);
  end;

end;

procedure TForm1.OnBeforeNavigate(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant; var Flags: OleVariant; var TargetFrameName: OleVariant; var PostData: OleVariant; var Headers: OleVariant; var Cancel: WordBool);
var  szURL:         String;
     dwIndex:       Integer;
     bAllow:        Boolean;
begin

  // Check URL
  szURL:=URL;

  // Check to see if http based
  if (Pos('http://', LowerCase(szURL)) = 1) then
  begin
     bAllow:=False;
     // Check to see if allowed
     for dwIndex:=0 to Pred(Memo1.Lines.Count) do
     begin
        // Check against memo item
        if (Pos(LowerCase(Memo1.Lines[dwIndex]), LowerCase(szURL)) > 0) then
        begin
           // Allow
           bAllow:=True;
           // Done checking
           break;
        end;
     end;
     // Set allow
     if not(bAllow) then Cancel:=True;
  end;

end;

procedure TForm1.OnWindowRegistered(Sender: TObject; lCookie: Integer);
var  ovItem:        OleVariant;
     dwIndex:       Integer;
     ieHandler:     TIEEvents;
     pvWeb2:        IWebBrowser2;
     hwndItem:      HWND;
begin

  // New window was registered
  for dwIndex:=0 to Pred(FShellWindows.Count) do
  begin
     // Get item
     ovItem:=FShellWindows.Item(dwIndex);
     // Check item
     if (TVariantArg(ovItem).vt = VT_DISPATCH) and  Assigned(TVariantArg(ovItem).pdispVal) then
     begin
        // Get window handle
        hwndItem:=ovItem.HWND;
        // Check
        if (hwndItem <> 0) then
        begin
           // Check window list
           if (FWindows.IndexOf(Pointer(hwndItem)) < 0) then
           begin
              // Create handler
              ieHandler:=TIEEvents.Create(nil);
              if (IDispatch(ovItem).QueryInterface(IWebBrowser2, pvWeb2) = S_OK) then
              begin
                 ieHandler.ConnectTo(pvWeb2);
                 ieHandler.OnQuit:=OnQuit;
                 ieHandler.BeforeNavigate2:=OnBeforeNavigate;
                 // Add to window list
                 FWindows.Add(Pointer(hwndItem));
                 // Add handler to list
                 FHandlers.Add(ieHandler);
              end;
           end;
        end;
     end;
  end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin

  // Create lists
  FWindows:=TList.Create;
  FHandlers:=TObjectList.Create(True);

  // Create shell window handler
  FShellWindows:=TShellWindows.Create(Self);

  // handle the OnWindowRegistered message
  FShellWindows.OnWindowRegistered:=OnWindowRegistered;

  // Connect
  FShellWindows.Connect;

  // Update the current list
  OnWindowRegistered(Self, 0);

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin

  // Free lists
  FWindows.Free;
  FHandlers.Free;

end;

end.

--- dfm ---
object Form1: TForm1
  Left = 285
  Top = 114
  Width = 326
  Height = 269
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    Left = 20
    Top = 16
    Width = 185
    Height = 173
    Lines.Strings = (
      'www.yahoo.com'
      'www.google.com')
    TabOrder = 0
  end
end



Hello Russell;

  I am checking out your Demo now.
How exactly does it work?
When I launch the project. I am still able to open IE and browse anywhere.
And what I need to do is to [Stop] IE from working at all.

My second demo does not stop the windows from opening (what if the user wanted to browse the file system??) It stops them from navigating to sites that are not in the memo. Use the first example if you want to close any IE/Explorer windows that the use tries to start up.

Russell
OK. Understand.

I like both example. How about this for example:

Lets say that instead of [Stopping] IE & Explorer from running.
How about having IE to Only open and display a page that is preset.

Example.
The program is running = True;
IE is launched = Load file \something .htm
Which resides on the clients computer, in the Install Directory.
------
This will allow for the user to still use "Explorer" but is unable to browse.
And if the user then tries to type in a URL into Explorer, it will redirect to the   \something.htm  file.

(Make since?)

What I originally wanted to do, was to write a "New Shell" for Windows to be in the program.
But that is a little too far from reach at the moment, and will delay the program again.
(As it is already 2 years past due for release)
ASKER CERTIFIED SOLUTION
Avatar of Russell Libby
Russell Libby
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works great.
Just what I was thinking of.

I up the points to 500.

Thanks Russell.

I might have some other "IE PopupMenu" Items that I might need your assistance with
In the near future.

I am going to be building my son a computer, of which he is only going to be allowed to use
The program that I am working on. (He is going to be my Beta Tester :)  )

I will let you know when I am ready to start on the MenuItems. I am basically
Needing to implement somewhat nearly everything that is available in IE's but through
The program's own Popup Menu. (This will give it a more customized look for the kids)

Take Care and once again; Thank you.

p.s.
Happy 4th, I am late I know, but I forgot to say it to you on the 4th.

Wayne
Forgot about something.
In the code provided by Russell.

There might be a Compile Error.
Undeclaired Identifier: EmptyParam

To fix this error add in the Variable

var EmptyParam: OleVariant;

So the code will look like this
===============================================
procedure TForm1.WMOnRedirect(var Message: TMessage);
var  dwIndex:       Integer;
       EmptyParam: OleVariant;  // Added to compile through.
begin

  dwIndex:=FHandlers.IndexOf(Pointer(Message.wParam));
  if not(dwIndex < 0) then
  begin
     TIEEvents(FHandlers[dwIndex]).Source.Navigate(RedirectURL, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
  end;

end;
===============================================
Take Care all, and once again, Thanks Russell.

Wayne

Happy 4th as well Wayne, and thanks for the pt increase. As to the EmptyParam, it is declared in D5 (which I use), but probably got bumped to the Variants unit in D6 and above (I hate that Borland did that). For those that get the compiler error:

1- Include the Variants unit in the uses clause.
2 - Follow what Wayne has given, but make sure to initialize to the following

  TVarData(EmptyParam).VType := varError;
  TVarData(EmptyParam).VError := $80020004; {DISP_E_PARAMNOTFOUND}

Hope to help in the future,
Russell
Speaking of Borland.

Have you tried the new D2005 (or) D2006?
D2005, I have it, but it is just basically sitting on the shelf.
I installed it once on a test system, and it is just too much for what I do.

Borland is releasing new versions of their programs faster then Microsoft is
Releasing their "Windows OS's" and their own Compilers.

Maybe one of these days, I might find a use for D2005, and reinstall it again.
But not right now.
I am happy with D6.02, as I have been using it since the day it was released as a Trial.
(After using D5 for about 6-months, which is the version that got me hooked to using
Delphi).

(I think that would make a good question for all Delphian's.
What made you decide to learn to do Windows Programming with "Delphi"
And What Version did you start with?)

I think I might open a post like that.

Take Care Russell.
Wayne

Tried D2005, but to be honest I use VS 2005 for my .Net work, which is in C# (not all that different from Delphi developement).

But, when it comes to Win32 dev, D5 if my bread and butter (my personal opinion is that the odd versions were always a bit more stable, but I never tried 6 or 7, so ....) Anyways, I have done work in VB, VBA, (M)Asm, C, C++, and for the Win32 work, the ease, power, and flexability of Delphi made it a no brainer. D1 was my first introduction, at which point I gave up VB3 and never went back.

Russell


Been in it a lot longer then myself.
Unfortunantly, I did not care too much about computers until the late 90's.
So I got a sort of late start in it.
But this old dog (35yrs old now) is always ready to learn new tricks.

I mainly got into Delphi, after downloading a program called: Pic2Web
Which I found out was made with Delphi, and I wanted to make it better then
What they had done.
That was the biggest reason why I got into it.
(Though I never did find all the information needed to do what I originally wanted.
But maybe one day, I can persue that "1st" programming dream of mine.
One day)

Wayne
Hello Russell;

If you have the time, could you take a look at the follow post please?
https://www.experts-exchange.com/questions/21921332/Extract-URL-Title-Description.html

The component set that the other person suggested, I am not going to use, as it is a Shareware
Download trial, and I am not really wanting to use it, if I can use simple code
Or already installed components.

To give you a run down of what I am needing to do.

On this link
http://directory.google.com/Top/Kids_and_Teens/Arts/

Where you see [Web Pages] (not where you see [Categories])
I am needing to grab the
<Title> | <URL> | <Description>

For each of the links that are available.

I thought that I have come up with a sollution, but I was incorrect.
(You can see what I did come up with in my Last post on the page)
Which my solution did not really work, as the Google page deals with a LOT of Tables.
5-Items Per-Table. IN the [Web Pages] area.
So, in order for me to deal with something like that, I tried to
WB1.OleObject.Document.all.tags('TABLE').item(9);
But I would have to do it for every Table in the area, and you never really know how many <table>
Are going to actually be on the page.
So, that blew that idea out of the water.

Plus I need to have all the information listed like such:

<Title> "," <URL> "," <Description>","
(or with   |  )
Right now, I can only get it to do it like so:
<Title> <URL>
<Description>

-------
Anyway, if you get an opertunity to take a look at this one, I will be mighty grateful.

Take Care
Wayne