Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Automation Error While Connecting To Running Instance Of IE

Hi I am using the following code to see if all the IE are busy or not..

Dim SWs As New SHDocVw.ShellWindows
Dim IE As SHDocVw.InternetExplorer

For Each IE In SWs

While IE.Busy



Every once in a while i get the Automation Error saying the client has been disconnected or the class name does not exist. IT is not consistent and happens randomly..

I read somewhere that the order of the References matter when you define the Project->References.

Inintially i had in the priority

MS HTML Object Library
MS Internet Controls
OLE Automation

And now changed it to

OLE Automation
MS Internet Controls
MS HTML Object Library

I am not sure if this will remove the error as i do not know the cause of the error in the first place...i would appreciate if some one could provide me some feedback on this one..


Edited by - vblearner123 on 9/4/2003 2:04:16 PM

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Automation Error While Connecting To Running Instance Of Internet Explorer
Hi I am using the following code to see if all the IE are busy or not..

Dim SWs As New SHDocVw.ShellWindows
Dim IE As SHDocVw.InternetExplorer

For Each IE In SWs

While IE.Busy



Every once in a while i get the Automation Error saying the client has been disconnected or the class name does not exist. IT is not consistent and happens randomly..

I read somewhere that the order of the References matter when you define the Project->References.

Inintially i had in the priority

MS HTML Object Library
MS Internet Controls
OLE Automation

And now changed it to

OLE Automation
MS Internet Controls
MS HTML Object Library

I am not sure if this will remove the error as i do not know the cause of the error in the first place...i would appreciate if some one could provide me some feedback on this one..


Connecting To A Certain Instance Of Autocad
It comes that I need to connect to a running instance of Autocad. I used GetObject method, but it grabs the firstly started Autocad session. I have the ProcessID of the Instance I want, and also the filename which is open in it.

Is there any way to force the GetObject to connect to a specified instance?

Is there any other way to accomplish this?

Many thanks

How To Get Only One Instance Running
if i have an app, how do i get it so only one instance of it can be run? for example the user runs app.exe, then a sec later trys to run app.exe but since an instance is already running nothing happends. how do i do that?

Instance Of App Still Running
Hi, this is probably a problem which has been sorted out in the past, however im having a great deal of trouble with it.

When i open my program all is good, if someone comes along and clicks the little x at the top right hand corner then the program closes (all seems good) however if i open the windows task manager i can see multiple instances of the program running.
Is there a way of ending the program when the x is clicked or a way of re-openning the already running instance?

Thanks in advance

Running Only 1 Instance
Good Morning !

I need to run only 1 instance of my application.

I'm betting I need to use app.PrevInstance. But it seems that I can't make it work... I guess I need to know which application is running..

Any help would be appreciated thanks


Get Instance Of MS Word Running

GetObject accept as parameter the path to opened file or the application name (Word.Application), but I need to get the control over a running instance of MS Word, that I know its window handle or window caption.

Is this possible ?

Thanks to everybody.


Excel Instance Still Running...
Hi guys! (many postings this week, deadline approaches....)

I have a rather common problem. Although I read some threads concearning it I couldn't fix it. Here is the scenario. I am creating a new excel sheet from scratch and I'm passing some data in it via ADO stetements. Everything works fine, but I can't terminate the Excel process properly (EXCEL.EXE process still appearing in Task Manager). Here is the code I use for...

...creating the sheet

Function create_new_excel()
'creates a new excel document

On Error GoTo errorhandler

Set mighty_Excel = Excel.Application
With mighty_Excel
'hide excel
.Visible = False
'create a workbook
'wrap text in cells
.Cells.WrapText = True
End With

Exit Function

apanthsh = MsgBox("Error with Excel!", vbCritical)
Exit Function

End Function

I do some work with it and then I'm trying to close it using...

Function finalize_new_excel()

'declare variables
Dim fName As String

On Error Resume Next
mighty_Excel.DisplayAlerts = False
'get the filename (opens the common dialog box)
fName = Application.GetSaveAsFilename( _
FileFilter:="Microsoft Excel Files (*.xls), *.xls")
Loop Until fName <> "False"
'save the workbook
ActiveWorkbook.SaveAs FileName:=fName
'finalize and free memory
Call work_mighty_Excel.Close(SaveChanges:=False)
Set work_mighty_Excel = Nothing
Set mighty_Excel = Nothing

End Function

I cannot figure out what is going on. Any help?

Only One Instance Of Application Running
Hi everyone!

Is there a way to prevent having more than one copy of your application running. If I double click my compiled executable it loads the program. If I double click it again it loads another copy of the program. How do I prevent this? How do I always ensure only one copy of my program is running at any time?

Any help/ideas/suggestions would be great!

Thanks SC

Running/previous Instance

Is there a way to detect if there's already an instance of application in other login user in windows xp? im using vb6.



Only Have 1 Instance Of Your Program Running
How can I only have 1 instance of my program running?

How To Know About Previous Instance Running Of An Exe

I have an exe (in VB6) which uses different comand line arguments so as to be used in different modules (to work differently). I want to know whether the exe is already running with the specific command line arguments. How can it be done ?
VB.App.PrevInstance just tells that the exe is already runnig, but how to know abt the command line arguments as the same exe is used for different modules.
Kindly please help me out as I am stuck with this issue.


Running Only One Instance Of The Application
How I restrict the user from running only one instance of my program?

Preventing More Than One Instance Of App Running
Hi there

Is there any way to prevent more than one instance of one's application to run at the same time? Is there any way to check when the application loads if an instance of the app is already running and if it is then don't load the application?

Microsoft seems to do this with Office applications.

Many thanks


Checking For Already Running Instance
Hello everybody

How can I check whether my application is already running?

thx, in advance

George Papadopoulos

Getting Handle On Running Instance Of Ie
New to vb here and have been issued with a task that is not exactly of 'hello world' level.
I need to get a handle on a running instance of internet explorer. The only app ive found that does anything similar gets a handle on a new instance that it starts up - using the following bit of code.

VB Code:
Dim WithEvents IE As InternetExplorer

VB Code:
Set IE = CreateObject("InternetExplorer.Application.1")

I am trying to use the getObject method with just the path of ie, but with no luck.

Limit App To One Running Instance
I know this topic has been dealt with before but I cannot find the topic in the searches that I am performing.

How do you limit an application to only run one instance on a PC.

Determining If An Instance If An EXE Is Already Running
Is there any API's that determine if an instance of an application(Im trying to open Outlook) is already open? I want to open outlook but not again if it's already open.

I've looked in my API ref book, but to no avail.

Checking If An Instance Of Your App Is Already Running
I have written an application for a customer and they have by mistake opened the package several times on there machine. How can i check to see if my app is already running and then activate it.

Running An Instance Of Access97.......
Hi Guys

I'm building a small app that will run various macros (for overnight reporting etc) from two or maybe three Access databases. I am then compacting each one ready for use next morning.

All the code for compacting is sorted, but can anyone tell me how to go about running a macro that is held within a database? I presume i need to open an instance in some way and then locate the individual macro object..........


Peter Gidden

How To Allow Only One Instance Of A Program Running
Lets say if your computer has a certain program like notepad.exe running.

I want to write a VB program to allow only one instance of notepad.exe (or some other program for that matter) open.
Is it possible to use app.prevInstance or sth like that in VB? to accomplish this?

Thanks in advance.

Get Object Of An Already Running Instance
Can anyone elaborate on how to access the object model of an already running instance of an application?  I found this old archived thread, but I need some more information to make this happen.  thread222-946494

Basically I have a non-microsoft program that supports VBA.  Normally, you start the application from a VB application and you have access to all of it's properties and methods and what not.  What I'm trying to do is get access to all those properties and methods by hooking into an already running instance of the aforementioned application.  It seems to be fairly easy to do with products like Excel and Word, using the GetObject method - but that just returns a "method not supported" error or something when I try to substitute in that code.

Thanks in advance!

Which Object Of The Running Instance
We have a VB activeX exe that is be used to create two running instances of the app. but they have different Window names. We can get the handle of a specific running instance by finding the window name.

Our objective is to sometimes connect to a specific running instance even if both are running using like GetObject. Since the running instances are different only by the window name being different is there a way to specify which running instnace that the GetObject will return? Is there some other way to conenct to a specific running instance?

Running Instance Problem...
i run an aplication with shellexecute giving a parameter
ex: clinic 23

but the parameter is in a loop
because i would like to call many times with different parameters
actually 23 is a person_id so
i have a loop through the database ,like this "select person_id ....."
do while not rs.eof
shellexecute "clinic" & " " & rs!person_id,.....

the problem is that the loop runs much faster ,so clinic.exe did not finish all his job.

so is there a solution ,to run the program,only after is not running anymore?

many thanks .

Conneting To A Running Instance Of An IE

I have a handle to the Internet Explorer Window. If I want to connect to that window/instance of IE from a VB 6 application and see if that Window is not busy downloading something, how do I do that. Please help.


Excel Instance Running In The Background

An Excel Instance keeps on "Running" in the Background i.e in Task Manager
I can see Excel instance still running

I tried two types of code to start an Excel through VB6,One works "OK" but other is with above stated problem.

If I use Set Wbk = ExlObj.Workbooks.add

the Excel closes fine but if I use

Set Wbk = ExlObj.Workbooks.Open("c: est.csv")

then the Excel Closes but an instance can be seen in Task Manager.

Any ideas what the difference in using with "ADD" and "OPEN" ?

Thanks in advance for all your inputs.

Excel Instance Running In The Background
I have few "csv" file which I want to save into "xls".I have created a VB program which goes through these "csv" files and opens "Excel" and format the file as required and save the file into "xls" format.
The problem is that the contral doesn't returns to the VB program,Though it completes the routine and creates the requried files.

I was not able to attach the files so i just copied the format as it is.

Here's what I'm doing:
------------------------------ ****** --------------------------------
Option Explicit
Public ExlObj As Excel.Application ' Create excel object
Public Wbk As Excel.Workbook
Public Wks As Excel.Worksheet
Dim i As Integer
Dim states(2) As String

Sub MAIN()
Province(0) = "HR"
Province(1) = "PB"

Set ExlObj = New Excel.Application ' Initialize the excel object

For i = 0 To 1


Call Wbk.Close(SaveChanges:=False) ' <-- ** or True **
Set Wbk = Nothing



On Error Resume Next
ExlObj.DisplayAlerts = False

Set ExlObj = Nothing

MsgBox i, vbOKOnly

End Sub

Sub Cd_Excel()
Dim ConPath As String
ConPath = App.Path & "" & "arp" & state(i) & "cb.csv"
Set Wbk = ExlObj.Workbooks.Open(ConPath)
Set Wks = ExlObj.ActiveSheet

Wks.Columns("A:S").ColumnWidth = 9

With Wks.Range("A1:S1")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom

.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With

With Wks.Range("A1:S1")

.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With

'Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("G2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom

'Selection.Subtotal GroupBy:=3, Function:=xlSum, TotalList:=Array(8, 9, 10, _
12, 13, 14, 15, 16, 17, 18, 19), Replace:=True, PageBreaks:=False, _

Wks.Range("D:D,F:F").NumberFormat = "mm/dd/yy"
Wks.Range("A1:S1").Font.Bold = True

With Wks.Rows("1:1")
.Insert Shift:=xlDown
End With

With Wks.Range("A1")
.FormulaR1C1 = "Monthly OCC Spread Sheet"
.Font.Name = "Arial"
.Font.Size = 10
.Font.Strikethrough = False
.Font.Superscript = False
.Font.Subscript = False
.Font.OutlineFont = False
.Font.Shadow = False
.Font.Underline = xlUnderlineStyleNone
.Font.ColorIndex = xlAutomatic
End With

With Wks.Range("A1:S1")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With

Wks.Range("A1:S1").RowHeight = 20
With Wks.Rows("3:3")
.Insert Shift:=xlDown
End With
Wks.Range("A1:S1").Font.Bold = True

Wbk.SaveAs FileName:=App.Path & "" & "arp" & state(i) & "cb.xls", FileFormat:=xlExcel9795, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub
The format of "arppbcb.csv" file is listed below:

/* --------- */

Metric ton,Charge,Total Pick,CC Rate,Total CC Vol.,S_Cost,CC_Rebate

Similarly there is one more file but with different values.

Can anyone tell me what I've done wrong with the code
Thanks for all suggestions in advance.

Interact With Running Instance Of Excel
Does anyone know how to instantiate or interact with and an already running instance of Excel? Using API calls I am able to find the specific instance I want to interact with (Class, Window Handle, Instance Handle etc.) and I am able to terminate it but I can't seem to interact with it unless I specifically opened/launched it from code (CreateObject or Shell).

Thanks in advance!

Making Sure Only One Instance Is Running @ A Time
How do you determine and make sure only one instance of a program is running at a time? If more than one running... a message should pop up letting you know program is all ready running without starting another instance of that program.

Prevent Running More Than One Instance Of A Program.

Could someone help me out? I need to prevent users from opening a second instance of my program if it is already running. Could someone give me code that checks for this?


How To Check An Instance Of Application Is Running Or Not
Can anybody please tell me how to check whether an instance of application is running or not???

Check For Running Instance Of An Application
I'm trying to keep from running multiple instances of the rundll32.exe (open with dialog.). I've read alot of topics on the forum and they all seem to be about app.prevInstance, but can't find one dealing with outside applications. Can anybody point me in the right direction? Thanks alot, Rick

Shell ("rundll32.exe shell32.dll,OpenAs_RunDLL " & strFullName)

Keeping Just One Instance Of My App Running(like Winamp)
I'd like to know how to keep just one instance of my app running
just like winamp, when you open another file, it'll stop the current playing file and plays the file you opened

Thanx in advance

How Can I Check For My Running Program Instance?
How can I check for my running program instance? Lets say I am running program prog1.exe, If I run it again, I want to have a messaga saying that the program is already running, How can Chech for this. Any hint is appretiated. Thanks.

Limit Instance Of A Running Program
How can I limit the number of instances of a program is being run?I need to limit the program to 1, sometimes 2.


How To Connect To A Running Instance Of Firefox
How to connect to a running instance of Firefox ...?

Prevent More Than One Instance Of Program Running?
I have an application that a few people in my office use.  One user is making us crazy, opening one instance after another of the program and constanly getting confused as to which she is working with.

I know there's a programmatical way to check if there's already an instance running and cancel the newly-started instance, but don't remember how to do it and it isn't in any of my books.  Can anyone help me out here?  Thanks.

Or if there's a switch in the compiler that will disallow that, that's good too.


Checking For Instance Of A Program Already Running
I want to check if an instance of a program is already running. A Command button starts up an application via the shell function. If the user presses this button again, I want to check if it already is running. If it is, then I want to set focus to other application. I have no control over the other application.

Acrobat Reader Running Instance
I would like to know how to detect through a Visual Basic Procedure if Acrobat Reader or Adobe Acrobat Professional is actually running.

Thanks a lot.

I'm Trying To Get The Current Running Instance Of Word Using VBA And VC++
Using VC++ Class wizard I create an automation class of Word 2000's Application and Document Class what when I call create Dispatch it creates a new instance of Word but what i want to do is connect to the current running Word.
Any help would be great.

Accessing A Running Instance Of An Activex Component
I designed a server-client application through remote automation.

In MSDN it says that you can use GetObject to access a currently running instance of a class.

Consider a class called Test in an activeX EXE called "TestEXE"

Consider that the class has a property called "HitCounter"

I open a client exe which is designed in such a way that whenever you click
a command button, the HitCounter property of the Test class is increased by 1 and its value is displayed in a messagebox

By using the button, i increased its value to 5. Now I open another Client application (while the first client is still running) and click the button. I want 6 to be displayed. Obviously I want to access the current instance of the EXE.

If I wanted to design a two-player game or something like a chatting application. This would be helpful.

How can I do it?

I have problems with GetObject. I donnot understand it. It always returns a new object or I get some kind of an error!

Running Single Instance Of Any Vb Program Exe File
plz tell me How can code any programme to be run single instance at time. that mean when i created any programs .exe file then i run it from that exe file. it runs. but if i again click on same .exe file then it starts second instance of that program at same time when first instance isstil running.
it can be done through a small coding. But i dont know that.
Plz help me . give that code sample.

Determine If Program Is Running Before Starting Another Instance Of It
I have been searching past posts to the forum, and there seem to be a lot of topic on determining if a program is running before starting another. (or something similar to that) Usually the program that is being checked is different than the one that is doing the checking.

I am looking for a way to see if the same program is already running. It is sort of a registration checking thing that is run in the background (invisible form) whenever certain programs are opened. If the user tries to open a few of the screens at the same time, I would like to have the invisible form run only once at a time. Is there a way to check in the form load to see if an instance is already running and only allow the remaining code to run when the previous instance is stopped? Would I need to do a count of some sort to check if the number of instances of the exe is > 1?

Thanks in advance for any help!

How To Stop An Application From Launching When An Instance Is Already Running?

I have an application which should not have multiple instances running, i.e. The user can launch it by double clicking the application, but the user when tries to launch it again when an instance is already open, the application should error out and exit. Does anyone know about this? Thank you very much...


Edited by - sri1025 on 8/25/2005 8:25:45 AM

Catching A Running Instance Of Internet Explorer
I know how to create a new instance of INternet Explorer, allowing to control it programmatically

set ie=new InternetExplorer

where ie has been declared as Private WithEvents....

but, how to "catch" an already up-and-running InternetExplorer (that I, for instance, have launched manually?


Open Text File In Running Instance Of TextPad

(I think this is the correct forum for this post. If not, please let me know.)

I need to programmatically open a text file in TextPad. In my scenario, TextPad is already running, and I have found its window with the following:

CODEhWnd = FindWindow("TextPad4", vbNullString)

Problem Binding To A Running Instance Of COM EXE Server Using GetObject()
Hi guys!
I am trying to bind to a running instance of a COM EXE Server application by using

This works at most of the places and many different machines. However, on one particular machine, I am unable to bind to the running instance using the above method. The problematic machine run exactly the same version of the application and OS as other machines. Reboot did not help.

I just get an error # 429.
"ActiveX Component cant create object"
OfCourse, I did register the application and walked through the REGISTRY and verified that its registered properly.

What can be the problem?

"Code To Check If There Is Another Instance Of Program Running Works On XP But Not O
Hi All i am facing an issue with Vista.
I have logged in as administrator also but the following line is generating an exception which was working correctly earlier in XP & 2000

" (Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) "

I know its due to the security features added by Vista because when I disable UAC in Vista its working perfectly.

Can anybody help me in this case

I am pasting the whole code

Public Const gsResourceNamespace As String = "NBXCAS"

If gbMultipleAppInstances(gsResourceNamespace) Then
psErrorMessage = "Not allowed to have multiple instances of: " & gsApplicationDisplayName
Call mDisplayStartupError(psErrorMessage, MsgBoxStyle.ApplicationModal + MsgBoxStyle.Exclamation)
End If

Public Function gbMultipleAppInstances(ByVal vsWindowCaption As String) As Boolean

Return (UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0)

End Function

If Multiple Word Sessions Running, How Do I Attach To Correct Instance
Client has system which allows indirect object calls via hidden ActiveX controls on the form. They want to embed a Word document in a report and call it one time for each row of the report that is generated.

I can launch Word hidden and then create a .doc file for the report to pick up. The problem is their system can't store an object reference so I am using CreateObject each time to instantiate Word.

To avoid the overhead of constantly opening and closing Word, I would like to leave Word hidden and then use GetObject to reattach to it. But how can I ensure that I have the one I want and not a session that maybe the user started while the report runs for a long time.

Are there any API calls that would help with this, or is this something simple to do?

I have done more VBA than VB so please forgive me if this is a really obvious question. Thanks for any help and/or suggestions you can give me!

Have a great day!

Connecting To An Access Database And Running Queries
Ok here is what I want to do. I have a form with 4 text boxes, each text box corresponds to a different attribute in a single table in an access 2003 database. What I want to do is when a command button is pressed the attritribute in the table is searched for a match on data that has been entered into the text boxes, but the attribute that the query looks at depends on which text box has been filled in on the form because each text box corresponds to a different attribute in the table. A match in data for that has been entered in the text box with the data in the attribute for that text box makes the matches display in a list box on the same form. From reading a few tutorials and with the help of a friend I have come up with the code below. However I need to change it so that for 1 of the text boxes 3 of the attributes need to be looked in, not just 1 attribute like the other 3 text boxes. What I also need to know if this code is correct and also which sub routine each bit of code goes under because I have got some of it muddled up.

Dim ADOCn As ADODB.Connection
Dim adoRS As ADODB.Recordset
Dim sSQL As String
Dim sWhere as string
Dim varValue as variant

ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:YourDB.mdb;"

Set ADOCn = New ADODB.Connection
ADOCn.Open ConnString

Set adoRS = New ADODB.Recordset

sSQL = "SELECT fieldname FROM tablename"
sWhere = ""
If Text1.Text <> "" THen sWhere = "fieldname1='" & Text1.Text & "'"
If Text2.Text <> "" Then
If sWhere = "" Then
sWhere = "fieldname2='" & Text2.Text & "'"
sWhere = sWhere & " AND fieldname2='" & Text2.Text & "'"
End if
End If
If Text3.Text <> "" Then
If sWhere = "" Then
sWhere = "fieldname3='" & Text3.Text & "'"
sWhere = sWhere & " AND fieldname3='" & Text3.Text & "'"
End if
End If
If Text4.Text <> "" Then
If sWhere = "" Then
sWhere = "fieldname4='" & Text4.Text & "'"
sWhere = sWhere & " AND fieldname4='" & Text4.Text & "'"
End if
End If

If sWhere <> "" Then sSQL = sSQL & " WHERE " & sWhere

adoRS.Open sSQL, ADOCn, adOpenForwardOnly, adLockReadOnly

Do Until adoRS.EOF
varValue = adoRS.Fields("fieldname").Value
ListBoxName.AddItem varValue 'this will add data to listbox

Set adoRS = Nothing
Set ADOCn = Nothing


Copyright 2005-08, All rights reserved