Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Join Date
    Nov 2003
    Posts
    13

    Unanswered: Cannot get the COM Object working

    Hello,

    I am trying to instantiate browser Internet Explorer and open the browser with a default url. I can create a new Object but cannot make it visible or make it navigate to a the default url.

    Here is the code.

    declare @rc int
    declare @obj int
    declare @name varchar(255)
    declare @url varchar(5000)
    declare @source varchar(255), @description varchar(255)

    set @url = 'http://www.hotmail.com'

    exec @rc = sp_OAcreate 'InternetExplorer.Application', @obj out
    If @rc <> 0 begin
    PRINT '*** InternetExplorer Object Creation failed'
    EXEC sp_OAGetErrorInfo @obj, @source out, @description out
    print @source
    print @description
    RETURN
    END


    exec @rc = sp_OAgetProperty @obj, 'Name', @name out
    If @rc <> 0 begin
    PRINT '*** Get Property Failed'
    EXEC sp_OAGetErrorInfo @obj, @source out, @description out
    print @source
    print @description
    RETURN
    END
    else
    print @name

    exec @rc = sp_OAsetProperty @obj, 'Visible', 'True'
    If @rc <> 0 begin
    PRINT '*** Set Property Failed'
    EXEC sp_OAGetErrorInfo @obj, @source out, @description out
    print @source
    print @description
    RETURN
    END

    exec @rc = sp_OAgetProperty @obj, 'Visible', @name out
    If @rc <> 0 begin
    PRINT '*** Get Property Failed'
    EXEC sp_OAGetErrorInfo @obj, @source out, @description out
    print @source
    print @description
    RETURN
    END
    else
    print @name

    exec @rc = sp_OAgetProperty @obj, 'Width', @name out
    If @rc <> 0 begin
    PRINT '*** Get Property Failed'
    EXEC sp_OAGetErrorInfo @obj, @source out, @description out
    print @source
    print @description
    RETURN
    END
    else
    print @name

    exec @rc = sp_OAgetProperty @obj, 'Height', @name out
    If @rc <> 0 begin
    PRINT '*** Get Property Failed'
    EXEC sp_OAGetErrorInfo @obj, @source out, @description out
    print @source
    print @description
    RETURN
    END
    else
    print @name



    exec @rc = sp_oaMethod @obj, 'Navigate', @url
    If @rc <> 0 begin
    PRINT '*** Navigation Method Failed'
    EXEC sp_OAGetErrorInfo @obj, @source out, @description out
    print @source
    print @description
    RETURN
    END
    else
    print @name

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    All OLE objects are automatically destroyed at the end of each batch. So if it were possible the object would be destroyed and you would never see it.

  3. #3
    Join Date
    Nov 2003
    Posts
    13
    If the object was destroyed after the first batch then all the getProperty executions would fail as well. But thats not the case. All my getProperty calls return correct results. Its just the Method i.e. Navigate method fails.

    You can actually copy this code and paste in Query Analyser and it will work i.e. you will get the results for all the getProperty calls.

    Thanx for responding.

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    How will the object be displayed if it is destroyed ? What are you considering as a batch ? Yes - you can retrieve the properties - but once this code is done the object is destroyed.

  5. #5
    Join Date
    Nov 2003
    Posts
    13
    I got confused by the term batch used in your first reply but now I understand what u mean by the term batch (all the T-sql statements).

    Coming back to your first reply..I am not sure If the browser object is destroyed..How do I check if the object is destroyed or does exist

    All this would be simple I can execute some Vbscript from T-sql (trigger) because creating a browser object and navigating it to a default url works fine.

    Is there anyway wheuere I can execute a Vbscript from Sql Server ?

  6. #6
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    could you use xp_cmdshell to do it? just create a vbs file and execute it?

  7. #7
    Join Date
    Nov 2003
    Posts
    13
    Originally posted by rokslide
    could you use xp_cmdshell to do it? just create a vbs file and execute it?
    Have never used xp_cmdShell....any tips on this would be helpful.

    Thanx

  8. #8
    Join Date
    Feb 2002
    Posts
    2,232
    Yes it is destroyed - look at bol.

    Can you describe in detail what you are trying to do ? Why do you want to invoke ie ?

  9. #9
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Executes a given command string as an operating-system command shell and returns any output as rows of text. Grants nonadministrative users permissions to execute xp_cmdshell.

    eg.
    xp_cmdshell 'dir *.exe', NO_OUTPUT

    so in your case you'd be after something like...

    xp_cmdshell 'openhotmail.vbs', NO_OUTPUT

    I think

  10. #10
    Join Date
    Nov 2003
    Posts
    13
    I tried creating a .vbs file as posted below and tried executing the script from Query Analyzer. Same Result. I dont see a new instance of the browser.

    My T-sql script is:
    DECLARE @result int

    execute @result = master.dbo.xp_cmdShell 'C:\WINNT\Temp\test.vbs'
    If @result = 0
    print 'Success'
    Else
    print 'Failure'

    My .vbs file look like
    set Wshell = Wscript.CreateObject("Wscript.Shell")
    Wshell.Run("http://www.yahoo.com")
    set Wshell = nothing

    In Query Analyzer I get a Success message but no new browser pointing to www.yahoo.com


    Thanx for the help

  11. #11
    Join Date
    Nov 2003
    Posts
    13
    Originally posted by rnealejr
    Yes it is destroyed - look at bol.

    Can you describe in detail what you are trying to do ? Why do you want to invoke ie ?
    I have to execute a cgi-script running on a real time system from an asp page. This asp page has to be called when an event like customer deactivation occurs.

    The event handler (trigger) will call the asp page which does the needful on the realtime system.

  12. #12
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    try this instead...

    set Wshell = Wscript.CreateObject("Wscript.Shell")
    Wshell.Run("iexplore.exe http://www.yahoo.com")
    set Wshell = nothing

  13. #13
    Join Date
    Nov 2003
    Posts
    13
    Originally posted by rokslide
    try this instead...

    set Wshell = Wscript.CreateObject("Wscript.Shell")
    Wshell.Run("iexplore.exe http://www.yahoo.com")
    set Wshell = nothing
    Tried the code posted by you but no luck. Do you think theres some kind fo security issue or some kind of OS (Windows 2000 SP4) issue

  14. #14
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Well I just had a little play.... and did this...

    DECLARE @result int

    execute @result = master.dbo.xp_cmdShell 'calc.exe'
    If @result = 0
    print 'Success'
    Else
    print 'Failure'

    I am doing this remotely eg. the server is not the same box as I am running the query on.

    On the server I can see the calc process but I am not sure who "owns" it. I was logged in as admin at the time.

    The process was probably created under the account used to run sql.

    Perhaps this is what you are seeing (or not seeing). Your IE thread is owned by someone else??

    What you could try is rather than calling your cgi script directly using IE create an instance of the XML parser what has a HTTP object in it and do a http post to the page you want. In theory this should trigger the cgi script (I think).

  15. #15
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    So effectively you would call a vbs again... but it would look something like....

    Dim HttpReq
    Set HttpReq = CreateObject("MSXML2.XMLHTTP40")
    HttpReq.open "GET", "http://XMLSampleServer/CatalogServer.asp", False
    HttpReq.send
    set HttpReq = nothing

    but pointing to your cgi script....

    in theory the request should get sent and when it returns your vbs will complete and return back to the query analyzer...

    of course I haven't tried this before so.... no promises.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •