Strange behaviour with InternetExplorer.Application COM Object

Use this forum to ask questions after your subscription maintenance expires or before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
User avatar
raphaelgj
Posts: 23
Joined: Tue Jun 19, 2018 10:19 am

Strange behaviour with InternetExplorer.Application COM Object

Post by raphaelgj » Fri Jan 24, 2020 12:22 pm

A very strange thing is happening with InternetExplorer.Application COM Object

The following example works when designing the form in PowerShell studio and pressing RUN (F5) to run it (basically, open a web page and wait for READYSTATE to be 4 which is "page is done loading'"), it will print the $ie.ReadyState to console correctly while looping until page is done loading:

Code: Select all

$button1_Click={
	
	$ie = New-Object -ComObject 'InternetExplorer.Application'
	$ie.visible = $true
	$ie.navigate("http://ipl0000")
	$ie.fullscreen = $true
	
	while ($ie.ReadyState -ne 4)
	{
		
		Write-Host "$($ie.ReadyState)"
		Start-Sleep 3
		[System.Windows.Forms.Application]::DoEvents()
	}
	
	msg * DONE
	
}
However when i package the form to EXE or Simply "Export to file" (.ps1) , the $ie.ReadyState never equals 4 and the while loops forever. $ie.ReadyState is empty,null. However the page is clearly done loading. It works all the time if the form is ran via PowerShellStudio and it never works and gets stuck in infinite loop when saved. Any idea?

An interesting observation is that if i check the object $ie WHEN RAN FROM POWERSHELL STUDIO, it contains all the properties, including ReadyState:


Code: Select all

Application          : System.__ComObject
Parent               : System.__ComObject
Container            : 
Document             : mshtml.HTMLDocumentClass
TopLevelContainer    : True
Type                 : Document HTML
Left                 : 0
Top                  : 0
Width                : 1920
Height               : 1200
LocationName         : Lexmark MS621dn
LocationURL          : http://ipl0000/
Busy                 : False
Name                 : Internet Explorer
HWND                 : 1317918
FullName             : C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE
Path                 : C:\Program Files (x86)\Internet Explorer\
Visible              : True
StatusBar            : False
StatusText           : 
ToolBar              : 0
MenuBar              : True
FullScreen           : True
ReadyState           : 4
Offline              : False
Silent               : False
RegisterAsBrowser    : False
RegisterAsDropTarget : True
TheaterMode          : False
AddressBar           : False
Resizable            : False


Checking that exact some object using the exact same code but ran from a saved .ps1 or packaged .exe, that object (which should be the same) is actually empty, containing only:
System.__ComObject



Much appreciated!

User avatar
Alexander Riedel
Posts: 7210
Joined: Tue May 29, 2007 4:43 pm

Re: Strange behaviour with InternetExplorer.Application COM Object

Post by Alexander Riedel » Fri Jan 24, 2020 1:08 pm

Try specifying STA mode when packaging.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
raphaelgj
Posts: 23
Joined: Tue Jun 19, 2018 10:19 am

Re: Strange behaviour with InternetExplorer.Application COM Object

Post by raphaelgj » Mon Jan 27, 2020 8:08 am

I've tried using STA mode on and off and it still doesn't work unfortunatly. Any other ideas? That's a really strange thing to have that object "empty" like that!

User avatar
raphaelgj
Posts: 23
Joined: Tue Jun 19, 2018 10:19 am

Re: Strange behaviour with InternetExplorer.Application COM Object

Post by raphaelgj » Mon Jan 27, 2020 8:13 am

Alexander Riedel wrote:
Fri Jan 24, 2020 1:08 pm
Try specifying STA mode when packaging.
I've tried using STA mode on and off and it still doesn't work unfortunatly. Any other ideas? That's a really strange thing to have that object "empty" like that!

User avatar
raphaelgj
Posts: 23
Joined: Tue Jun 19, 2018 10:19 am

Re: Strange behaviour with InternetExplorer.Application COM Object

Post by raphaelgj » Mon Jan 27, 2020 8:22 am

I found the answer, I needed to embed a default manifest for elevation (program had to run AS ADMIN) otherwise the com object wouldn't work properly.