I added a button to Internet Explorer's toolbar and pointed to the executable without any problems.

The executable modifies the registry value:

My.Computer.Registry.SetValue ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "GlobalUserOffline", 1)

This works if I restart IE or open a second instance of IE.

It doesn't work in the currently opened IE instance.

I want this button to work as if it's done from IE's File menu > Work Offline

Is it possible to accomplish and how

I looked in msdn library and found a Offline property:

"Offline Property

Sets or gets a value that indicates whether the object is operating in offline mode.

Syntax: object.offline = True/False"

If this offline property is what I should use, how do I do it

Many thanks,

e. rudder

Re: Internet Explorer Extension Development adding a button to work offline


Hi E (or is that H IE Rudder)

Its a bit strange. I have a number of machines with different versions of IE running. On my IE6 Sp1 machine there is no Work Offline menu option... well it could be a group policy setting on that machine. Nope a check rules that out... It just goes to show that you cannot rely on the menu layout between versions. I couldn't find any documentation on the Work-offline menu.. could not find any registry keys and regmon does not indicate any registry changes when the menu option is toggled.

The object.offline property refers to the WebBrowser object. Add a reference to IEFrame.dll in Visual Studio and use the Object Browser to inspect its properties and methods. You will see the offline property listed with a comment 'Property Offline as Boolean - Controls if the frame is offline (read from cache)'

For a command bar button to hook into the webbrowser instance, you need to get the top window handle (hwnd) which will be the IE window where the user has pressed the button (api GetForegroundWindow). Next you have to enum the IE windows and find which one has the same hwnd value... here is a vb snippet...

hwnd = GetForegroundWindow()

dim SWs as new shdocvw.ShellWindows

dim IE as shdocvw.InternetExplorer

Set myWB = Nothing ' this is your event sink to the web browser object

For i = SWs.count - 1 to 0 Step -1 ' start from the topmost for speed

Set IE = SWs.Item(i)

If Not IE Is Nothing then

If IE.hwnd = hwnd then

Set myWB = IE

'' then you can toggle the offline property

Either myWB.Offline = Not myWB.Offline

or IE.Offline = Not IE.Offline

exit the For once you have found the top window or loop through all open IE instances if you want to toggle the Offline property for them all.

You may like to consider a scripted button instead that will use sendkeys to toggle the menu option (if it exists and is enabled)

<script language="vbscript">
// IE7 Toggle Work Offline menu
set WshShell=createobject("wscript.shell")
WshShell.SendKeys "^FW"

In both solutions you will not be able to indicate the browser Offline state with the button state on the command bar button (hot and cold icon values)


Re: Internet Explorer Extension Development adding a button to work offline


Hi Rob,

Thanks for replying.

"Hi E (or is that H IE Rudder)" LOL

Just plain e for ed...would be nice if i could steer IE with a RUDDER.

In spite of my best efforts i couldn't get your code to work (I added ref. to MS Int. Controls), but kept getting PInvoke errors.

Please have a look at what i tried:

Public Class Form1

Declare Auto Function FindWindow Lib "USER32.DLL" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Declare Auto Function SetForegroundWindow Lib "USER32.DLL" (ByVal hWnd As IntPtr) As Boolean

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

Dim ieHandle As IntPtr = FindWindow("ieframe", vbNullString)

'check if IE is detected.
If ieHandle = 0 Then
MsgBox("IE is not running.") ' it works

' i believe it is here that i should insert commands.

End If

End Sub

End Class