getobject and IE

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?
LVL 9
bhagyeshtAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rstaveleyCommented:
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
bhagyeshtAuthor Commented:
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
rstaveleyCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

bhagyeshtAuthor Commented:
well i am not using vb i am using wsh or vbs anyway it doesnt work either
0
rstaveleyCommented:
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
bhagyeshtAuthor Commented:
thats the same case no where its documented. probably another MS hidden stuff. ;-)
0
rstaveleyCommented:
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
bhagyeshtAuthor Commented:
kiddies.....?
well the same doesnt work in vb script or VB either.
0
rstaveleyCommented:
> 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
bhagyeshtAuthor Commented:
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
rstaveleyCommented:
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
bhagyeshtAuthor Commented:
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
rstaveleyCommented:
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
bhagyeshtAuthor Commented:
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
rstaveleyCommented:
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
Computer101Commented:
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KavarCommented:
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
bhagyeshtAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.