Solved

limit the number of opened IE 7/8/9 tabs

Posted on 2011-09-26
9
352 Views
Last Modified: 2013-12-17
Is there reg key or value or a VB / VBS / C# code to limit the number of opened tabs in IE?

and if not, is there a way to close a specific IE tab using VB or C# ?
0
Comment
Question by:OrenRozen
  • 5
  • 4
9 Comments
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 500 total points
ID: 36602593
I don't know if there is a setting at all to limit tabs but you can try something like this...
Imports System.Runtime.InteropServices
Imports System.Threading

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TabBusting.BeginBust(3)
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        TabBusting.EndBust()
    End Sub
End Class

Public NotInheritable Class TabBusting

    Private Shared _shell As Object = Nothing
    Private Shared _windows As Object = Nothing
    Private Shared _timer As Threading.Timer = Nothing
    Private Shared _maxTabs As UInteger = 0

    Public Shared Sub BeginBust(ByVal maxTabs As UInteger)
        _shell = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"), True)
        _maxTabs = maxTabs
        ' Setup tab busting every second.
        _timer = New Threading.Timer(AddressOf BustWindows, Nothing, New TimeSpan(0, 0, 0), New TimeSpan(0, 0, 1))
    End Sub

    Public Shared Sub EndBust()
        _timer.Dispose()
        _timer = Nothing
        Marshal.FinalReleaseComObject(_shell)
        _shell = Nothing
    End Sub
   
    Private Shared Sub BustWindows(ByVal state As Object)
         
        Dim windowList As New List(Of Object)
        Dim i As Integer

        ' Populate window collection
        _windows = _shell.Windows

        ' Filters ShellView windows
        For Each obj As Object In _windows
            If obj.Document.GetType.Name.Contains("HTMLDocument") Then
                windowList.Add(obj)
            End If
        Next
         
        If windowList.Count >= _maxTabs Then
            For i = 0 To windowList.Count - 1
                If i >= _maxTabs Then
                    windowList(i).Quit() ' bust tabs above maximum allowed.
                End If
            Next i
        End If

        windowList.Clear()
        windowList = Nothing
        _windows = Nothing

    End Sub
End Class

Open in new window

0
 
LVL 3

Author Comment

by:OrenRozen
ID: 36711271
Thanks for the code. I'm trying to make it work but there is an error in line 41.
the object _shell does not contain a definition for windows.
Am I missing a reference?
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 36711937
Nope no reference required but I haven't got that error when I run the test.... You converted to C# or using VB? Is this a *real error* or only a warning?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 3

Author Comment

by:OrenRozen
ID: 36712157
converted to C#
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 36712252
Oh okay... In VB we can use late binding but in C# you probrably have to use reflection like InvokeMember()...
0
 
LVL 3

Author Comment

by:OrenRozen
ID: 36712299
do you have a c# code for that? or do you recommend for me to open a new question on the convertion?
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 36712329
You can test the example "as is" in VB.NET and if it does what you intend then someone could probably convert it for you. I just whipped it up quickly in VB because you listed all three ( VB, VBS or C#)... Give it a try first though
0
 
LVL 3

Author Comment

by:OrenRozen
ID: 36712725
working great in VB.
I didn't ask at the begining, but what I need is to run this application once on a terminal and monitor to close the tabs for ieplore ran by all users on that TS. I'd like to avoid running this application for every user.

0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 36713170
Hmmm... Not sure about terminal but here is a VBS example of the same concept if you can execute that someway under terminal.
Const MAX_TABS = 5 '// Set max tabs allowed opened.

Dim objShell
Dim objWindows

Call BeginBust


Sub BeginBust()

  Dim ieWindowCount
  Dim obj
  Dim i
  Dim arrBust(1024)

  Set objShell = Wscript.CreateObject("Shell.Application")
  


'//Do

  Set objWindows = objShell.Windows
  
  ieWindowCount = 0

  For Each obj In objWindows
    If InStr( 1, TypeName(obj.Document), "HtmlDocument", 1) <> 0 Then
      ieWindowCount = CLng((ieWindowCount + 1))
      Set arrBust(ieWindowCount) = obj
    End If
  Next

  If (ieWindowCount > MAX_TABS) Then
    For i = 0 To ieWindowCount - 1
      If (i >= MAX_TABS) Then
	arrBust(i).Quit '// Bust tabs.
      End If
    Next
   MsgBox "Busted Tabs!"
  End If

  Erase arrBust
  
  WScript.Sleep 1000

'//Loop

End Sub

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

828 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