Solved

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

Posted on 2011-09-26
9
349 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
 
LVL 3

Author Comment

by:OrenRozen
ID: 36712157
converted to C#
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Duplicate a row 2 33
Enable copy and pasting even when textbox is disabled 2 16
Round up to 100% in .NET 10 44
hp mini 3 17
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

13 Experts available now in Live!

Get 1:1 Help Now