WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Shell Windows

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Shell Windows Issue on Various Platforms

 Keywords:  Shell Windows Shell.Windows IShellWindows Problem Issue IE MSIE Internet Explorer InternetExplorer.application UAC on

Question:

My exe creates and controls IE browser objects using com when UAC is on in Vista and Win7.

When a browser object is opened by the exe, all works as expected for the first script. When the exe looks to see if there is already an existing browser with the correct url, the browser launched by the exe cannot be seen in the shell windows object list:

Shell = ObjectCreate("Shell.Application")
foreach objWindow In Shell.Windows
If I open the browser manually first, the shell function can see and use it repeatedly. Shell.Windows sees all browsers opened by the "user" and none opened by the exe. Is it a name space issue? Elevation issue? I have compiled and tested with all levels of execution and am using "highestAvailable". In Win7, there are 4 UAC levels.. 3 is the default. If it's set to 2, the problem is solved. In Vista - no deal. Other than that - behavior is the same in both OS's. My goal is to be compatible with default settings.

All code works fine with UAC off (or set to level 2 in Win7)- I have the digital cert and code signing all set.

Answer:

Interesting, we were able to reproduce the problem. It seems specifically related to any browser instances that were created using ObjectCreate AFTER Shell.Windows is called the first time...

Apparently the IShellWindows::Register Method registers an open window as a Shell window; the window is specified by handle. Use this method to register an open window. http://msdn.microsoft.com/en-us/library/cc836576%28VS.85%29.aspx

Here is some sample code that shows how to register the instance of IE with the windows shell. The only problem is that IE registers the first one on its own. So youc an end up with duplicates. See Code Comments:

objShell = ObjectCreate("Shell.Application")
lItems = ""
ForEach objWindow In objShell.Windows
   If lItems != "" Then lItems =lItems:@TAB
   lItems = lItems : objWindow.Name:"->":objWindow.locationurl
Next
AskItemlist('IE Objects Before Registering 2 More', lItems, @TAB, @UNSORTED, @SINGLE )

objWindow = 0
objIE = ObjectCreate('internetexplorer.application')
objIE.navigate('http://www.winbatch.com')
objIE.Visible = 1
While objIE.busy || objIE.readystate == 1
   TimeDelay(0.5)
EndWhile

; Add the new IE object to the shell windows object enum -redundant
SWC_BROWSER = 1
nCookie = ObjectType("I4", 0)
objShell.Windows.Register(objIe, objIe.hwnd, SWC_BROWSER, nCookie)

objIE = ObjectCreate('internetexplorer.application')
objIE.navigate('http://www.google.com')
objIE.Visible = 1
While objIE.busy || objIE.readystate == 1
   TimeDelay(0.5)
EndWhile

; Add the second IE object to the shell windows object enum.
nCookie = 0
objShell.Windows.Register(objIe, objIe.hwnd, SWC_BROWSER, nCookie)
objShell  = 0
objIE = 0

;; If no IE instances exist, I end up with 3 IE shell window
;; objects on my system because IE register  the first one on
;; its own too.
;; If UAC is turned off, I end up with 4 IE shell window objects.
objShell = ObjectCreate("Shell.Application")
lItems = ""
ForEach objWindow In objShell.Windows
   If lItems != "" Then lItems =lItems:@TAB
   lItems = lItems : objWindow.Name:"->":objWindow.locationurl
Next
AskItemlist('IE Objects After Registering 2 More', lItems, @TAB, @UNSORTED, @SINGLE )
Exit

Article ID:   W18192
Filename:   Shell Windows Issue on Various Platforms.txt
File Created: 2011:05:10:11:21:20
Last Updated: 2011:05:10:11:21:20