Wy doesn't my VBScript do the same thing on Windows 10 as it does on Windows 7? - vbscript

I've created a batch file that runs some VBScript which works fine in Windows 7 but not in Windows 10. Why doesn't it not work on both?
The batch file does 6 things which are listed below. On Windows 7 all 6 things happen. On Windows 10 all but item 5 take place and the window title is not changed.
opens Internet Explorer
brings the window to the foreground
navigates to a webpage
waits 1.5 seconds to allow the webpage to load
changes the window title from "MultiSmart" to "Community MultiSmart"
exits
Here is the the batch file.
<!-- :
#echo off
cscript //nologo "%~f0?.wsf" %*
exit /b
-->
<job>
<script language="VBScript">
Set ie = WScript.CreateObject("InternetExplorer.Application")
'ie properties
ie.ToolBar = 0
ie.StatusBar = 0
ie.Width = 816
ie.Height = 519
ie.Visible = 1
ie.Resizable = 0
'bring window to foreground
CreateObject("WScript.Shell").AppActivate "Internet Explorer"
'navigate to Stony Mountain Lift Station's Multismart
ie.Navigate("http://192.168.0.11/")
'wait for page to load into browser
Wscript.Sleep 1500
'change window title
ie.document.title="Community MultiSmart"
</script>
</job>

I would double check that the webpage is fully loaded.
Change this line:
Wscript.Sleep 1500
to
While IE.ReadyState < 4
Wscript.Sleep 250
Wend
It's unclear as to whether npocmaka's comment of:
"...Add metadata to force old browser behavior on windows 10."
worked for you or not. If not, then consider this alternative:
Check your security settings in IE.
Warning: This answer provides suggestions that may lower your system's security settings. It is advised that you fully understand the risks involved before proceeding and be proactive with using alternative protective measures. (Or, just stop automating in IE ☺)
Go to IE > Internet Options > Security Tab
(Optional) Add the website to your 'Trusted Sites' zone if you trust the site (which will make the next step easier on you)
Whichever zone you decided to keep site in (either 'Internet' or 'Trusted Sites'), uncheck the box: Enable Protected Mode (requires restart). Warning: This is obviously going to reduce the security of IE.
Click Apply then OK
Close out of ALL IE BROWSERS to ensure that the change takes effect
Double check Task Manager (Ctrl-Shift-Esc) to ensure no hidden iexplore.exe processes exist in the Processes tab.
Test the end result
If still doesn't work, ensure you reverse any settings.
Scripting can obviously be dangerous to any system, which is why Protected mode may severely limit what you can do with automation. I believe that IE didn't enable protected mode in IE by default until Windows 8(.1)?, but I don't have a source for my suspicions; if this is the case, that would be why it works on Windows 7 and not Windows 10.
You can still do simple things with protected mode enabled, but it's severely limited. For example, you can still navigate to web pages, but many of IE's other properties and methods are disabled.

I'm re-posting npocmaka's comment which answered my question as an answer.
because it depends on the internet explorer version
The versions were different. What worked on IE 11.0.966.18920 did not on IE 11.461.16299.0.

Related

Error::SessionNotCreatedError: Unexpected error launching Internet Explorer

Unable launch Internet Explorer using my script it gives this error
Selenium::WebDriver::Error::SessionNotCreatedError: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones.
I researched a lot to get work around for this and found few solutions https://stackoverflow.com/a/29453294/1976848, but I am unable to change my IE browser settings, The checkbox to "Enable Protected mode" is disabled for all the zones here
Also, tried to override this with desired capabilities here is the code but not getting any success:
caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer(
:ignoreProtectedModeSettings => true,
:javascriptEnabled => true,
)
Watir::Browser.new :ie, http_client: client,:desired_capabilities => caps
I am using Cucumber with Ruby and Watir and Browser is Internet Explorer 11.
Please suggest some workaround for this.
The issue gets resolved after doing continuous research around it,
Most of the Stackoverflow and Github answers shows to change the settings from Internet Options but those are not working from me due to permission limitation
One of the blog posts from LinkedIn https://www.linkedin.com/pulse/automation-using-internet-explorer-11-pritam-maske. Suggested to modify the registry specific to internet explorer, but that too I am unable to edit due to permission limitations.
Taking the points from registry modification, then I found a way to edit it via PowerShell script and found few solutions to reset the Internet Explorer Preferences from Microsoft power shell script repositories
How to reset all Internet Explorer settings for a different user profile?
With this got 1 step success but main problem remains same i.e. my IE 11 not launched, then searched for to "Enable the Protected Mode for all Zones" and got few post with a good description around it
a. Powershell – IE zones Protected Mode state
b. IE Browser - Powershell script to add a site to trusted sites list, disable protected mode & make all zones security level low
At last, after doing tweaks in the Powershell script it works and my script is working fine for IE browser.

Start Outlook 2016 (64 Bit) automatically minimised to Windows 10 (64 Bit) system tray - No active Explorer object found

I have an issue with an auto start of Outlook 2016 at boot/log on which is intended to start Outlook minimised to the Windows system tray, such that once invoked at Windows 10 launch mail will be collected by the mail account(s) (NB. All POP in this case.) whilst the program resides in the system tray remaining invisible until required by the user.
The .vbs script below does function as required but much of the time it introduces two unwelcome issues.
The Outlook icon in the System Tray displays a 'cog' overlay with the message "Another program is using Outlook. To disconnect programs and exit Outlook, click the Outlook icon and then click Exit Now".
Attempts to open Outlook from the 'Open Outlook' context menu (right click Outlook icon in the tray) item causes a dialogue box to appear reporting "No active explorer object found". Clicking the "OK" option in response launches Outlook (though issue 1 - cog overlay) remains.
Neither issue is present when Outlook is started normally from the desktop so it would appear that the .vbs script is in someway responsible. I have used this script successfully (see also below: https://superuser.com/questions/467809/start-outlook-automatically-in-tray) in the past both as a startup menu shortcut and a hkcu 'run' registry entry.
Can anyone suggest the cause or alternately a suitable code revision to achieve correct function? In case it is significant, Windows 10 is 64 bit Pro and the version of Office (including Outlook) installed is also 64 bit.
This is the code invoked by the .vbs script:
OPTION EXPLICIT
OPTION EXPLICIT
CONST PATH_TO_OUTLOOK = """C:\Program Files\Microsoft Office\Office16\OUTLOOK.EXE"""
CONST SHOW_MAXIMIZED = 3
CONST MINIMIZE = 1
DIM shell, outlook
SET shell = WScript.CreateObject("WScript.Shell")
' Open Outlook
shell.Run PATH_TO_OUTLOOK, SHOW_MAXIMIZED, FALSE
ON ERROR RESUME NEXT
' Grab a handle to the Outlook Application and minimize
SET outlook = WScript.CreateObject("Outlook.Application")
WScript.Sleep(100)
outlook.ActiveExplorer.WindowState = SHOW_MAXIMIZED
' Loop on error to account for slow startup in which case the
' process and/or the main Outlook window is not available
WHILE Err.Number <> 0
Err.Clear
WScript.Sleep(100)
SET outlook = NOTHING
SET outlook = WScript.CreateObject("Outlook.Application")
outlook.ActiveExplorer.WindowState = MINIMIZE
WEND
ON ERROR GOTO 0
SET outlook = NOTHING
SET shell = NOTHING
Having spent a number of hours on this issue over the weekend I thought that I had resolved the issues and got everything functioning as intended.
Working from similar samples of code I compiled a new script (see below) which I applied both as a shortcut in the Startup folder and also as an entry into the 'run' branch of the HKCU registry.
Now for the issue! Testing the script on two separate Windows 10 Pro (both 64 Bit architecture) systems both with Outlook 2016 64 Bit installed as part of a 64 Bit Office suite I found that whereas on one system the script runs flawlessly on the other I receive the following runtime error:
Script: D:\Neil's Files\Neil's Filing Cabinet\Neil's Emails\Start Outlook Minimised to Tray\Start Outlook 2016 Minimised To Tray.vbs
Line: 11
Char: 5
Error: ActiveX component can't create object: 'GetObject'
Code: 800A01AD
Source: Microsoft VBScript runtime error
This has me perplexed as the script file and it's related shortcut are both physical copies of each other given that the revised script below contains no path references (as these are handled directly by the code in respect of Outlook.exe) which are identified by the placement of either the shortcut or as the data element of the registry string whichever format is used.
The Systems do have some differences however and for comparative purposes I will summarise those I feel to be relevant here:
System 1: (The problem system) is an X58 Asus P6T7, Intel i720 mature PC with many programs installed and specifically the Outlook 2016 has the same 12 addins installed but in addition has two related programs which launch at boot, the enterprise editions of 4team's Sync2 for Microsoft Outlook and Safe PST Backup. The boot times are quite lengthy (but acceptable) as is the Outlook Startup with it's various addins.
System 2: Is a current generation Asus X99-Deluxe, i7 5930 new build pc with little installed as yet save MS Office, Adobe CC and some utilities.
In the case of System 1, Outlook auto-starts as intended however during it's loading splash screen (whilst it is loading up the addins) the runtime error is displayed although Outlook continues to open fully but fails to minimise.....
This suggests to me that the faulting code is the section which activates the window however the above error message refers to "ActiveX component can't create object: 'GetObject'" which suggests instead an issue with the code line "Set OLObj = GetObject("","Outlook.Application")"??
Hopefully somebody can test the code on a similar setup and report back? Or alternately, give me a pointer as to what is going on and how I might resolve it. I would of course also welcome any suggested improvements to the code!
** Quick Update ** Now tested on HP Elitebook 8440P Laptop - Windows 10 Pro 64 Bit with Office 64 Bit + same 12 Outlook Addons - Functions as intended.....
** Further Update ** Tested on a second HP Elitebook 8440P Laptop - Windows 10 Pro 64 Bit with Office 64 Bit + same 12 Outlook Addons - Above RunTime error experienced once again.......struggling to comprehend why these results are occurring?? Any thoughts anybody???
The code below is offered "as is" for the benefit of anyone else seeking the same Outlook auto start criteria. The testing with System 2 indicates that it works so I hope others enjoy similar success until the outstanding issues are sorted.
NB: To adjust the Outlook Launch Window Size (during its 10 second pause prior to automated minimising) to reflect personal preferences change the numeric value in the following line of code:
WshShell.Run "OUTLOOK.EXE" , 3, false
For a maximised window size change the value to 3 For a restored window size change the value to 2
OPTION EXPLICIT
Dim WshShell
Dim OLObj
Set WshShell = WScript. CreateObject ( "Wscript.Shell" )
'Open Outlook: Note that inspite of the launch options, it will open the program in a normal window.
'The file location path is not necessary as Windows 10 correctly identifies Outlook's location.
WshShell.Run "OUTLOOK.EXE" , 3, false
'This will mimimise it to the system tray after a 10 second pause to allow for mail collection on Outlook launch.
WScript.Sleep (10000)
Set OLObj = GetObject("","Outlook.Application")
'Activates the window
OLObj.ActiveExplorer.Activate
'Sends the command to minimise
OLObj.ActiveExplorer.WindowState = 1
'Outlook does not immediately minimise to the system tray so that 'Send/Receive' can initiate mail collection.
Thanks to jrv from Microsoft's "The Scripting Guys" forum who kindly offered a revised (simplified) code which is below. I can report that as with the original code it works flawlessly on the same 2 systems as before, whilst faulting once more on the other two......very much perplexed!!
The Runtime Error:
Script: D:\Neil's Files\Neil's Filing Cabinet\Neil's Emails\Start Outlook Minimised to Tray\Start Outlook 2016 Minimised To Tray.vbs
Line: 3
Char: 5
Error: ActiveX component can't create object: 'Outlook.Application'
Code: 800A01AD
Source: Microsoft VBScript runtime error
The revised code:
Set WshShell = CreateObject ( "Wscript.Shell" )
WshShell.Run "OUTLOOK.EXE" , 3, False
Set ol = CreateObject("Outlook.Application")
ol.ActiveExplorer.Activate
ol.ActiveExplorer.WindowState = 1
You can use like file *.reg:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Outlook"="C:\\Windows\\system32\\cmd.exe /c \"start \"\" /min \"C:\\Program Files\\Microsoft Office\\Office16\\OUTLOOK.EXE\"\""
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Preferences]
"MinToTray"=dword:00000001
I have an answer that works well with Office 2013 on Windows 7, and I hope it works for you too.
Essentially, this solution bypasses the issue with trying to force Outlook to minimize after loading. Instead, it relies on using a shortcut that's already configured to load the program in a minimized state.
Copy a shortcut to Outlook into the directory containing your script.
Right click the shortcut and open Properties.
In the Shortcut tab, change the Run mode to Minimized. Press OK.
Then, all you need to do in your VBScript file is to execute the shortcut like so:
Dim sh : Set sh = CreateObject("WScript.Shell")
sh.run "Outlook.lnk"
Note that because this solution uses a shortcut, you could potentially remove the VBScript part entirely by putting the shortcut into the All Users Startup folder.
It's me again! I have an answer that should bypass any issues with VBScript by using third-party software, DisplayFusion. I don't know how you'll feel about that, but I tested it and it works over here. I use this at home and at work to manage multiple monitors and various other things. It may even help solve problems with other programs you use and render various VBS hacks redundant.
In your case, there is a feature called 'Triggers'. Note that while there is a free version of DF, you'll have to activate a 30 day trial for the Pro version to use Triggers, and after that, it's up to you to decide if it's worth your while.
Firstly, after installing DF, you'll want to open up its settings window (right-click desktop and go to DisplayFusion > Settings).
Go to the Triggers tab and click Add.
Set up the trigger for when a window is created. Tell the trigger to activate only once per process ID so it won't also try to minimize subsequent windows, such as when composing a new email. Find the path to your outlook.exe. Then, add an action on the right-hand side to minimize the window.
Click OK twice and then see if it works by loading Outlook. For me, the splash screen appears as normal, then the main window is minimized as soon as it appears.
DF runs as a system service with admin privileges and has been tested with tonnes of software packages, so if this method also fails for you, it could indicate bigger issues with your system/Office configuration.

Is it possible to disable "Display hidden-mode notification tooltip" programmatically on UFT?

I'm trying to run some automation tests in my application but the UFT Hidden-mode notification tooltip is coming in front of the objects in the screen, preventing my tests to run.
I know I can un-check the option "Display hidden-mode notification tooltip" in Remote Agent Settings to fix this issue and it works fine on my machine after I do this, but these tests are executed in other machines, by other users in my company, and it would be a real effort to tell each and everyone of them to change this setting on their machine.
Is it a way to disable this checkbox programmaticaly instead?
EDIT:
Here is a little more detail on where this is affecting me:
I'm testing a Web application and in some of my test cases I need to download a file from this application. I do that by clicking on "Save As" in the context menu which is displayed on a notification bar at the bottom of the browser.
Following is the portion of code to perform such operation:
Dim brwBottom
Set brwBottom = Browser("brw_Bottom_Save_As")
If brwBottom.WinObject("wo_Notification").WinButton("wb_Selector").Exist Then
brwBottom.WinObject("wo_Notification").WinButton("wb_Selector").Click
brwBottom.WinMenu("wm_Selector").Select "Save As"
End If
This works fine on my machine because UFT notification is not being displayed, but in other machines where the UFT Notification is displayed, it overlaps the menu and my script is unable to select the "Save As" option. So, in case it is not possible to programmatically close this notification at runtime, is there any alternative solution to click on the "Save As" button, even with this notification overlapping it?
I managed to identify the UFT Notification tooltip and close it. With this, there is no more objects in front of the button I need to click and my script can be executed successfully.
Following is the code used. I'm not marking this as the acceptable answer yet because I am still waiting for my team to accept the solution, but this works.
Dim brwBottom
Set brwBottom = Browser("brw_Bottom_Save_As")
' To close UFT Notification Tooltip, if exists
If Window("regexpwndtitle:=NotificationWindow").Exist(2) Then
If InStr(Window("regexpwndtitle:=NotificationWindow").GetROProperty("nativeclass"),"UFTRemoteAgent") > 0 Then
Window("regexpwndtitle:=NotificationWindow").Close
End If
End If
If brwBottom.WinObject("wo_Notification").WinButton("wb_Selector").Exist Then
brwBottom.WinObject("wo_Notification").WinButton("wb_Selector").Click
brwBottom.WinMenu("wm_Selector").Select "Save As"
End If
Create UFT GUI test and include these three lines:
extern.Declare micLong, "WritePrivateProfileString", "kernel32.dll", "WritePrivateProfileString", micString, micString, micString, micString
extern.WritePrivateProfileString "RemoteAgent", "ShowBallon", "0", Environment("ProductDir") + "\bin\mic.ini"
systemutil.CloseProcessByName "UFTRemoteAgent.exe"
From ALM, run it on all your UFT machines.
Notes:
This will switch the flag that controls such tooltip to be off, so next time Remote Agent launches will read it and won't display the tooltip anymore.
The third line will kill UFT's remote agent for GUI testing which is in charge of the communication between UFT and ALM Client and this will cause an error in ALM's Automatic Runner (The RPC server is unavailable)... just ignore it. We need to kill it so it is re-launched next time we try to run a test from ALM (as mentioned above, new value for tooltip will be read)
EDIT:
I just found something interesting: this flag is actually saved in two locations:
mic.ini
RemoteAgentGUISettings.xml
but the one that actually makes the change effective is RemoteAgentGUISettings.xml (it seems they're switching from .ini files to .xml... which makes sense). In this case, the code will change a little, but the idea is the same:
filePath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%appdata%") + "\Hewlett-Packard\UFT\Persistence\Dialogs\RemoteAgentGUISettings.xml"
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.load filePath
Set nNode = xmlDoc.selectsinglenode ("//SettingsViewModel/IsShowBalloon")
nNode.text = "false"
strResult = xmldoc.save(filePath)
systemutil.CloseProcessByName "UFTRemoteAgent.exe"
This time I made sure it works ;)
I totally understand your pain because my projects also need to interact with IE download bar. Usually, I use SendKeys to handle download activity in different projects.
When download bar comes out, you can send ALT+N first to set focus on download bar, then send some tab keys to select on Save, and some Down Arrow key to select SaveAs.
In this way, you don't need to bother handle UFT notifications...
Sample SendKeys codes can be easily Googled.
Can you activate the desired browser with the following, and then try to do Save as
hwnd = Browser("title:=.*").GetROProperty("hwnd")
Window("hwnd:=" & hwnd).Activate

Disable Firefox auto update requests

Hope I'm writing that in the relevant platform..
I'm working on a script that analyzing requests while browsing sites with Firefox.
I always see requests to aus4.mozilla.org, even after I changed the "Auto-Update" option in the browser to 'Disable' mode.
Does anybody faced with this problem before? How can I turn it off?
Here is how you can turn off Auto Updates on Firefox from Windows:
Run Regedit in windows (Must have admin right)
Expand HKEY_LOCAL_MACHINE > SOFTWARE > Policies
If the 2 folders Mozilla and Firefox don't exist under 'Policies'. Create them as per the following:
-Right click on "Policies" folder, Select New > Key then enter "Mozilla"
-Right click on "Mozilla" folder, Select New > Key then enter "Firefox"
-Right click on "Firefox" folder, Select New > DWORD (32 bit) value then enter "DisableAppUpdate"
-Double-click on "DisableAppUpdate" to modify Value data to 1 (hexadecimal). This will stop mozilla from downloading and updating Firefox;
It will show "Updates disabled by your system administrator"
To allow Firefox to update again; Modify the Value Data to 0 .
Weird, the option should work.
Double check that the app.update.auto and app.update.enabled configuration options are set to false (you can do that from about:config).
I would suggest using a better method to automate Firefox, for example Selenium. There are bindings for many programming languages, e.g. for Node.js.
Nowadays (65.0.2) disabling updates is relatively complicated. Here's the Windows solution:
In the firefox.exe directory, create one named distribution.
Inside distribution, place a filed named policies.json containing the following:
{
"policies": {
"DisableAppUpdate": true
}
}
Sources:
https://support.mozilla.org/en-US/questions/1232918
https://github.com/mozilla/policy-templates/blob/master/README.md

Having problems running WatiN on Windows 7 with IE 8

When I run any WatiN test on Windows 7 with IE8(note that all tests pass on Vista with IE8), the browser displays the first page but does not go any further. The following exception is displayed after a few seconds:
WatiN.Core.Exceptions.TimeoutException: Timeout while Internet Explorer state not complete
at WatiN.Core.UtilityClasses.TryFuncUntilTimeOut.ThrowTimeOutException(Exception lastException, String message)
at WatiN.Core.UtilityClasses.TryFuncUntilTimeOut.HandleTimeOut()
at WatiN.Core.UtilityClasses.TryFuncUntilTimeOut.Try(DoFunc1 func)
at WatiN.Core.WaitForCompleteBase.WaitUntil(DoFunc1 waitWhile, BuildTimeOutExceptionMessage exceptionMessage)
at WatiN.Core.Native.InternetExplorer.WaitForComplete.WaitWhileIEReadyStateNotComplete(IWebBrowser2 ie)
at WatiN.Core.Native.InternetExplorer.IEWaitForComplete.DoWait()
at WatiN.Core.DomContainer.WaitForComplete(IWait waitForComplete)
at WatiN.Core.IE.WaitForComplete(Int32 waitForCompleteTimeOut)
at WatiN.Core.DomContainer.WaitForComplete()
at WatiN.Core.Browser.GoTo(Uri url)
at WatiN.Core.IE.FinishInitialization(Uri uri)
at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, Boolean createInNewProcess)
at WatiN.Core.IE..ctor(String url)
at CCS.iPS.ST.Tests.UIWithDBVerification.Tests.DCC_Offered_Completed_ThreeDS_And_Authorisation_Completed() in Tests.cs: line 18
Make sure you are running as an Administrator. Seems to be an issue where Watin can't access the DOM in IE unless the application is running with System Administrator privileges.
I know this is an ancient thread, but I've found found a workaround for WatiN under Windows 7 that doesn't require you to run as an administrator (which isn't allowed in my company :S) If you disable protected mode in Internet Explorer it should run fine: -
1 - Open internet explorer.
2 - Click on Tools menu and select Internet Options.
3 - Select Security Tab in the Internet options windows.
4 - Select Internet from the zone settings.
5 - Uncheck Enable Protected Mode option to disable the protection from Security for this zone.
6 - Hit Apply and Ok

Resources