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.
This topic is 4 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
raphaelgj
Posts: 23
Last visit: Thu Aug 17, 2023 8:41 am

Strange behaviour with InternetExplorer.Application COM Object

Post by raphaelgj »

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: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Strange behaviour with InternetExplorer.Application COM Object

Post by Alexander Riedel »

Try specifying STA mode when packaging.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
raphaelgj
Posts: 23
Last visit: Thu Aug 17, 2023 8:41 am

Re: Strange behaviour with InternetExplorer.Application COM Object

Post by raphaelgj »

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
Last visit: Thu Aug 17, 2023 8:41 am

Re: Strange behaviour with InternetExplorer.Application COM Object

Post by raphaelgj »

Alexander Riedel wrote: Fri Jan 24, 2020 12: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
Last visit: Thu Aug 17, 2023 8:41 am

Re: Strange behaviour with InternetExplorer.Application COM Object

Post by raphaelgj »

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.
This topic is 4 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.