Solved

getobject and IE

Posted on 2003-12-03
19
6,609 Views
Last Modified: 2011-10-03
this is from a VB script file

'script start
Dim IE
Set IE = GetObject("C:\Program Files\Internet Explorer\IEXPLORE.EXE","InternetExplorer.application")

'script ends
it fails giving an error file name or class name not found during automation operation: GetObject

but
this works
Dim IE
Set IE = CreateObject("InternetExplorer.application")
in both cases IE instance is running.
any clues?
0
Comment
Question by:bhagyesht
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
19 Comments
 
LVL 17

Expert Comment

by:rstaveley
ID: 9873508
This is odd, isn't it?

You can use:
--------8<--------
Dim IE
Set IE = GetObject("","InternetExplorer.Application")
IE.visible = true
--------8<--------

...but this is effectively the same as doing a CreateObject("InternetExplorer.application")

0
 
LVL 9

Author Comment

by:bhagyesht
ID: 9873561
It certainly is odd, my purpose is to get an object I could create an object infact it just defeats the purpose of my application if i create an object.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 9873904
I just tried a couple of experiments with VB .NET (I'm not a VB programmer!) and found that GetObject only works when the object has been created by the current process.

The toggle program listed below was expected to create and make visible an instance of InternetExplorer.Application, if one was not already running and to hide it if there was one already running. However, I find that GetObject only works if the object has been created by toggle.exe itself.

If you have VB .NET, you can try the following code to see it for yourself. NB: the odd looking syntax for GetObject isn't a mistake. That's how you get it to reference an existing instance of the application.

toggle.vb:
--------8<--------
Imports System
Imports Microsoft.VisualBasic

Module toggle

      Sub Main

            Dim exApp As Object ' late binding

            On Error Resume Next ' ignore errors
            exApp = GetObject(,"InternetExplorer.Application")
            ' Reference an existing application instance
            If exApp Is Nothing Then ' No existing application is running
                  ' Create a new application instance
                  exApp = CreateObject("InternetExplorer.Application")
                  ' Make it show
                  exApp.Visible = true
                  Console.WriteLine("New instance created and made visible")

                  exApp = GetObject(,"InternetExplorer.Application")
                  If exApp Is Nothing Then
                        Console.WriteLine("Unable to use GetObject to get it")
                  Else
                        Console.WriteLine("GetObject is OK")

                        System.Threading.Thread.Sleep(3000)
                        ' Make it show
                        exApp.Visible = false
                        Console.WriteLine("Existing instance hidden")

                        System.Threading.Thread.Sleep(3000)
                        ' Make it show
                        exApp.Visible = true
                        Console.WriteLine("Existing instance shown again")
                  End If

            Else
                  ' Hide it
                  exApp.Visible = false
                  Console.WriteLine("Existing instance hidden")
            End If
      End Sub

End Module
--------8<--------
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 9

Author Comment

by:bhagyesht
ID: 9873968
well i am not using vb i am using wsh or vbs anyway it doesnt work either
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 9874325
I expect that it is the same issue.

My guess is that you cant use GetObject to get an application instantiated by another process, but I can't see any documentation to confirm.
0
 
LVL 9

Author Comment

by:bhagyesht
ID: 9879815
thats the same case no where its documented. probably another MS hidden stuff. ;-)
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 9880735
It may be a change of heart. It seems to me that MS started with a philosophy of indescriminate empowerment and it has gradually come round to the realisation that script kiddies need to be prevented from doing things.
0
 
LVL 9

Author Comment

by:bhagyesht
ID: 9880814
kiddies.....?
well the same doesnt work in vb script or VB either.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 9881541
> kiddies

Sorry, I didn't mean to take a poke at everyone who writes code using script technologies. I depend heavily on scripting on both Microsoft and UN*X platforms, myself. I only used VB in the example above, because it is easier to debug.

By "script kiddies", I meant those, who use COM to propagate Intenet worms through script embedded in inocuous looking e-mailed documents. Microsoft's security fixes are of course applicable to compiled code and script alike, but I reckon it is the script kiddies who brought about the change in attitude.
0
 
LVL 9

Author Comment

by:bhagyesht
ID: 9894440
well I work in script as well but mainly for automation purposes which is what i want to do here. I need to synchronise 2 browsers running on different PC to show the same data. Its not i am restricted to scripts if need be I can use VB or VC++ too, since I have been working in them for the past couple of years. Its not that I need it for Linux hence DCOM serves the purpose. I agree VB is easier to debug and that what I prefer too.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 9895890
Would it be a solution to have a DCOM server on the PC being controlled by the user? The DCOM server starts the browser via local CreateObject (i.e. by COM) and thus the browser "belongs" to the DCOM server, which is then able to monitor which URL is being displayed. A remote client has its browser created by COM CreateObject. The remote client shadows the browser being controlled by the user. The remote client polls the DCOM server by DCOM, which informs it which URL is current in its browser, and the DCOM client should then be able to put the appropriate URL into its browser by COM.
0
 
LVL 9

Author Comment

by:bhagyesht
ID: 9895956
thats what i though i will do and hence i wanted the getobject working to get the browser's object so that using createobject's server parameter i could get a similar browser running on another pc.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 9896061
If your DCOM server created the instance of the browser, GetObject should work, because I can see GetObject working when the object has been created by the same process. Having said that, you could equally retain the handle returned by CreateObject and use that instead. The point is that the browser window needs to "belong" to your DCOM server. It cannot have been started up independently.

Disclaimer: I believe that this is true, but I'm not 100% confident, because I've not done this myself! :-)
0
 
LVL 9

Author Comment

by:bhagyesht
ID: 9901815
hmmm. if it was created by my process then i dont need getobject since i have created it and i have the object of it what functionality would getobject provide?
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 9902698
Yes, keeping the handle from CreateObject makes GetObject unnecessary. GetObject doesn't really provide you with any functionality that you need, as I see it.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 10002642
PAQed, with points refunded (125)

Computer101
E-E Admin
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10238669
Well you are right, but you can get around it with this....Assuming you know the title of the internet explorer that has already been created, of course you could modify it to accept any title with a valid .Document.Body.innerhtml (or anything else)

Function FindIE(WhatTitle)
On Error Resume next
Dim sha
Dim sh
Set sha=CreateObject("Shell.Application")
For Each sh In sha.Windows
      loc=InStr(1,sh.Document.Title,WhatTitle,1)
      If Err.Number Then
            Err.Clear
            loc=0
      End If
      If Loc<>0 Then Exit for
Next
If Loc=0 Then 'Looped all windows and didn't find it
      FindIE=False
 Else
       set FindIE=sh
End If
End Function
0
 
LVL 9

Author Comment

by:bhagyesht
ID: 10250332
Kavar: thanks for the answer, but that wouldnt work since the title is changing besides I wouldnt be able to manuplate the stuff. I tried it as soon as i couldnt get using getobject.

Bhagyesh Trivedi
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Introduction to Processes
Starting up a Project

696 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