Internet explorer started from WScript.exe will not on appear on top - wsh

We have recently added a new feature on our application to be able to shell out to another application. One of the commands is WScript.exe
In one part of the script, I wanted to be able to show a dialogue, so I create an instance of Internet Explorer, inject my html, and then wait for a hidden input element to be updated.
The windows scripting file (containing VBS) then calls
Dim explorer
Set explorer = WScript.CreateObject("InternetExplorer.Application")
explorer.StatusBar = 0
explorer.ToolBar = 0
explorer.Navigate "about:blank"
Dim document
Set document = explorer.Document
document.open
document.write html
document.close
explorer.Visible = True
Do
WScript.Sleep 250
Loop Until document.getElementById("myValue") <> ""
This seems to work fine when I am debugging my main application. But when I run the application outside the debugger, the dialogue appears behind the application.
I believe that the problem is explained in the answer to this item:
WScript.Shell AppActivate doesn't work every time
Essentially, this was working because I was developing this in debug mode. When out of debug mode, the instance of iexplore.exe was not directly started by wscript.exe - the iexplore.exe process is actually started by an instance of svchost.exe. This meant that the implicit SetForegroundWindow() does not work.
Can anyone suggest a way I can put this internet explorer windows in the foreground?
Or is there another way I can create a dialogue, without having to distribute any more components?

Related

Visual Studio 2022 find the next line of code to execute

I am learning a new ASP.NET MVC app that uses some approaches I am not used to / familiar with. Without having to deal with the client side scripts (because there appear to be over a thousand), I want Visual Studio to go into break mode / stop at the first line of code executed on the server.
Is there a way to do that?
For example, I click a button in the web site that run a script that shows a dialog box (I don't believe any server code has executed at this point in this series of events). Then I fill in some fields and click a button in the dialog box that I know sends data back to the server. I want the sever to stop at the first line of code it attempts to execute as a result of the button being clicked.
I thought you used to be able to put the app in Break mode, then you could use the Step Into button to take you to the next line of code but this no longer seems to work.
Any ideas?
You can use my Runtime Flow tool to find out what code is executed on the server when you click a button in the web site. Though you need to manually configure Runtime Flow to monitor your web application as described here https://vlasovstudio.com/runtime-flow/documentation/quick_start.html

Is there a way in LeanFT / UFT Developer to get active element on OS level?

My automation Framework consists of the following: UFT developer V15.0 (previously LeanFT) + Java + Maven + Junit.
UI Tests are executed by Jenkins on a dedicated VM (OS = Windows 10).
Many of my test cases include actual keyboard press, as this is a requirement of the AUT which is a web application.
My problem is that if tests are executed while user is not actually logged in - the cases which require to focus on the browser and press the keyboard - will fail.
When i use RDP to log in to the VM and minimize - tests will still fail.
when I use RDP, login to the VM and keep the screen open - test will focus successfully on relevant field and will pass.
I tried to disconnect using tscon using the below script, but still no use:
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
)
As per my understanding - the problem seems to be focus.
To try and understand the source of the problem, i would like to try and get the actual active element which is currently in Focus on the OS level, just like getting the active element on browser ("document.activeElement.id").
As UFT developer is able to interact with Windows elements - is there a way to retrieve such info from the OS?
Or alternatively , solution to the original problem (keeping the focus on the running browser) would be great.

Detecting Quick Access command state

We have an application that is using Windows Ribbon Framework for an UI. The app itself is written in Delphi and uses Windows Ribbon Framework for Delphi to interface with the ribbon API.
Our ribbon XML places few commands into the Quick Access toolbar. Use can then remove/add commands either by using the built-in ribbon mechanism (selecting the drop/down button and clicking on a command name) or by selecting More commands command which opens the configuration dialog.
The problem I've encountered is that I cannot find a way to get the current state of commands in the QA collection (whether they are visible or not).
In the example above (picture) I would like to detect that first five commands are checked and that the last is not so I can prepare the configuration dialog accordingly.
I have no problems enumerating the IUICollection and accessing the items stored inside. I can also get the UI_PKEY_CommandId for each item. I cannot, however, find a way to read the checked/unchecked state. I tried reading UI_PKEY_BooleanValue and UI_PKEY_Enabled for all items in the collection, but they do not return that state.
I have also tried to monitor IUICommandHandler.UpdateProperty but it doesn't get called when such item is checked/unchecked (except that it is called with the UI_PKEY_Label key).
Does ribbon API even support this functionality?

COM-Addin does not load in Outlook 2010x64 (LoadBehavior set to 2). How to debug "runtime error"?

I have an addin that is written in Delphi XE3/XE4, using the Add-in-Express framework (i.e. not .NET, no VSTO). It is running fine in all 32bit-versions of Outlook as well as the 64bit-version of Outlook 2013. However, under the 64bit-version of Outlook 2010 it simply will not load: The COM-Addin manager tells me "Not loaded. A runtime error occurred during the loading of the COM-Add-in." (i.e. the LoadBehavior-value in the registry got set to 2).
Is there any way to find out what that "runtime error" might be?
I have already put OutputDebugStrings all over my code as well as the VCL and ADX code and not a single one of those appears to ever be reached at all before Outlook unloads the DLL again.
When running in the debugger (via PAServer) any breakpoints I set (e.g. on the begin of the DPR-file or in the initialization of the Classes unit) do not even ever get enabled. Seems to me the DLL is never even loaded into the debugger (this does work fine with Outlook 2013x64).
I also already wrote a dummy host EXE that would instantiate my COM server and call the appropriate methods on the IDTExtensibility2-interface to simulate the actual Outlook host but no errors occur in that case either.
Looking at things with Process Monitor, the addin DLL gets loaded briefly but then immediately gets unloaded again and then the LoadBehavior value is reset.
I checked the Application logs and enabled logging in Outlook itself but so far no hints to the nature of the supposed "runtime error".
All latest updates and service packs were applied to all of Delphi, Add-in-Express, Outlook, Windows. The Windows version is 7 Pro. No other addins are installed.
Any more ideas on what to check?
Add an environment variable VSTO_SUPPRESSDISPLAYALERTS value 0 to that PC that is causing the problem.
Then u can reload the addin from outlook >> options >> Addins >> Manage.
So outlook will try reloading this addin and u will get a popup window with details of the prob...

Is it REALLY an activex control?

I have a fairly simple block of code.
Sub Run(Name)
on error resume next
Set objShell = CreateObject("WScript.Shell")
if Err.Number = 429 then
alert("Invalid Security Level.")
exit sub
end if
objShell.Run Name
if Err.Number <> 0 then
Alert("Please verify your Operating System Choice")
end if
Set objShell = Nothing
End Sub
I'm using this with links on the website to allow the user to defrag their hard drive via:
Defrag Windows Vista<br>
Defrag Windows Server 2003 SE or Windows XP
As you can probably guess.. using:
Set objShell = CreateObject("WScript.Shell")
Is causing a bit of a problem, and it is throwing an error that the object cannot be created. I can go into IE security and change the security setting for,
"Initialize and script ActiveX
controls not marked as safe for
scripting"
to "Prompt", and it will actually prompt me and run when I click yes.
My question at this point is;
Since this is not a seperate block of code coming from an asp server (htm page w/ no code behind). Do I really need to spend $20 to get it signed, and how would I do that in the first place on a vbscript in an htm page?
Also.. the site that this will be implemented into DOES have an SSL cert. Is it possible to integrate into the existing cert in some way shape or form?
All I want to do is have links that are like...
"If you want to defrag your computer,
click here"
"If you want to run a disk scan, click
here"
And telling all our customers to go in and change their security settings is not an option.
Your code isn't the problem. When you create the "WScript.Shell" object, IE asks that control if it is safe for scripting. The object returns "No". That's why your code doesn't work. As long as you use "WScript.Shell" you will have the problem.
One way around this is to create your own ActiveX control that is marked as "safe for scripting", but then you would have to get all of your users to install it.

Resources