Solved

getobject and IE

Posted on 2003-12-03
19
6,598 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
19 Comments
 
LVL 17

Expert Comment

by:rstaveley
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 9

Author Comment

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

Expert Comment

by:rstaveley
Comment Utility
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
Comment Utility
thats the same case no where its documented. probably another MS hidden stuff. ;-)
0
 
LVL 17

Expert Comment

by:rstaveley
Comment Utility
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
Comment Utility
kiddies.....?
well the same doesnt work in vb script or VB either.
0
 
LVL 17

Expert Comment

by:rstaveley
Comment Utility
> 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 9

Author Comment

by:bhagyesht
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed, with points refunded (125)

Computer101
E-E Admin
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
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
Comment Utility
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

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.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 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

10 Experts available now in Live!

Get 1:1 Help Now