Detect and close "Windows Update" dialog box - vbscript .vbs file - windows

I have the vbscript code to toggle between two windows:
Option Explicit
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Do
WScript.Sleep 20000
WshShell.AppActivate("Inbox - Microsoft Outlook")
' WshShell.SendKeys "% r"
WScript.Sleep 20000
WshShell.AppActivate("Firefox")
' WshShell.SendKeys "% r"
Loop
The problem is, I get "Windows Update" dialog box randomly and it shows up on screen. Is there a way to find that dialog box and close it through existing vbscript that I have? Below is the picture of dialog box:
Appreciate any help.
Thanks,
Richa

I'm not sure if that dialog can be touched by VBScript unless you were to run it with admin privileges.
I think the easiest solution it to prevent Windows from automatically installing updates. Open up Windows Update from the Control Panel, go to Change Settings, then set it to one of
Download updates but let me choose whether to install them
Check for updates but let me choose whether to download and install them
If you choose the first one, I believe you'll get a taskbar notification (balloon) when there are updates available, which won't steal focus but still let you know updates are ready.
Given that Win7 is probably only going to receive Windows Defender definition updates for the rest of its lifetime, you probably won't encounter this dialog often now.

Related

WScript.Shell SendKeys not working on Windows 8.1 x64

I'm having problems with the following VBScript.
I'm trying to send keystrokes to a web browser window, but nothing happens.
The first two lines in the following script works fine, but the third line with the SendKeys command, doesn't do anything.
Set objShell = CreateObject("WScript.Shell")
objShell.Run "http://someurl.com", 1
objShell.SendKeys "Some Text"
I've tried to run the script on two different Win 8.1 machines. On Win 8.1 Pro it works, but on Win 8.1 not-Pro it won't work. Is there any setting somewhere in Windows that needs to be set or anything other that can help me?
Update
New code tried (added sleep and running browser explicit), but still no luck
Set ObjShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Program Files\Internet Explorer\iexplore.exe""http://someurl.com/"
WScript.Sleep 5000
objShell.SendKeys "Some Text"
While its admittedly not a great programming technique, place a Sleep command after your objShell.Run line (as shown below) to give the OS some time to "catch up" and actually run the URL, activate the browser window to give it focus (you have to take note of the title in the Browser window and use that title exactly), because I have seen the browser window lose focus in some cases and then text cannot be piped into it, and finally it sends the text. Your mileage may vary, and you might even have to increase the sleep time in order to be successful. I've had to sleep up to 30 seconds, in some cases. Especially where, for whatever reason, the web page was slow to render - due to network latency, slow OS, etc.. I haven't faced this problem on Windows 8.1 because I haven't tried it on that platform. I don't think this has anything to do with the OS version; I have faced this same problem with SendKeys on other Windows OS versions where I've had to use the Sleep function like this. The SendKeys method has known limitations, and as it runs outside of the browser you have to wait for certain actions to complete before you can have it do more actions.
Set ObjShell = WScript.CreateObject("WScript.Shell")
objShell.Run "http://someurl.com", 1
WScript.Sleep 20000
objShell.appactivate("Welcome to SOMEURL.COM! - Mozilla Firefox")
WScript.Sleep 700
objShell.SendKeys "Some Text"
Also, you might try replacing line 2 in the above to the following, to see if you have better luck. In the example below, Firefox is the default web browser. Change the path accordingly to the browser of your choice:
objShell.Run("""C:\Program Files\Mozilla Firefox\firefox.exe""http://someurl.com")

How can I automatically cancel the Enter Network Password prompt in Outlook?

I have an unattended PC which does a very simple task : read emails from a POP server and run various tasks based the content of those emails... 24/7/365
The problem is that at least once a week "something" glitches and the processing stalls because Outlook is waiting for a user to confirm their password with the dreaded Enter Network Password dialog.
I have read so many articles in the past 6 months in an attempt to fix the root cause and nothing has worked. There's no WiFi involved and the email server is Google so it should be extremely reliable so I can only suspect that the broadband connection to my ISP is the culprit as I've read that "certain network conditions" can trigger the password prompt.
Yesterday, I gave up on the root cause approach and looked for an automated tool to cancel the annoying dialogue box when it appears. To my surprise, Windows can do this out-of-the-box via Windows Script Host. Here's how:
A. Open your preferred text editor.
B. Copy paste the following VB Script (you can also use JScript if you prefer but I'm not including the syntax here).
Set WshShell = WScript.CreateObject("WScript.Shell")
' Move focus to the network password dialog if it exists (if not, script continues)
If WshShell.AppActivate ("Enter Network Password") = True Then
' Suspend the script for 1/10th second to make sure the dialogue is in focus
WScript.Sleep 100
WshShell.SendKeys "{ESC}"
' Optionally save this event to a log file
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, file
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("C:\Temp", ForAppending, tristateFalse)
file.Write vbCrLf & Date & " " & Time
file.Close
End If
Set WshShell = Nothing
C. Save the file with a .vbs extension e.g. EscapePrompt.vbs
D. Next, open the Windows Task Scheduler (Click the Windows Start button and type "Task" and you should see Task Schedule appear at the top of the search result list, or just type "Task" from the Windows 8 tile view).
Create a new task that runs the script file above, every day, repeating every 5 minutes, indefinitely:
General tab : give the task a name and then check Run with highest privileges
New Trigger tab : click New and select Daily and then in the Advanced Settings, check Repeat task every: and choose 5 minutes. set the for a duration of: to Indefinitely. Check Enabled
Actions Tab : click New and then Browse to choose the script file you created above.
Conditions tab : Set any conditions as required by your environment.
Settings tab : I don't change anything here but you may want to.
Now, when the Enter Network Password prompt appears, there is a maximum delay of 5 minutes before it is automatically cancelled.
For more information on WScript and in particular, the SendKeys method, check out MSDN :
http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx
You may also be interested in our free VBA examples at:
http://youpresent.biz/category/blog/vba/
Microsoft outlook keeps prompting network password if there registry value and network password mismatches. If you change the password for your account in ISP or Control Panel.Then, configure and login outlook with the new password.Then ,it will not prompt for outlook password again and again.

How can you have a dialog box displayed when opening a program in windows xp?

Does anyone know how to have a dialog box with a custom message pop up any time that a specific program is opened? The computer is running Windows XP Professional 2002 with Service Pack 3. The program is used to operate a scientific instrument that keeps getting damaged by lab users who disregard printed instructions around it. Ideally, I could have a dialog box pop up that requires users to click an "OK" button before the program opens. I've spent some time browsing the web for ideas, but have so far come back empty-handed. The program is usually opened from a shortcut on the desktop.
Many thanks,
Jeremy
A user on another forum answered this question for me. I created a small shell script (text file saved with .vbs extension) to display the dialog box when the program is opened from a Desktop shortcut targeting the script file.
Here's the link to the post in the other forum for more details:
The script that worked for me is shown below:
startupMessage = MsgBox("...close the lid gently and only use the button to open it.", 0, "To prevent instrument damage...")
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim cmd
cmd = "C:\Program Files\InstrumentApplication.exe"
cmd = chr(34) & cmd & chr(34)
WshShell.Run(cmd)

Need a startup script in windows to send ALT+F11 keys?

We are using a shared desktop on thin clients. By default it comes with windowed screen, but by pressing the Alt + F11 keys it will restore to full screen. So, we want a script to execute at Windows log-on with some delay.
Hopefully a login vbscript will work for you. Either append this to an existing login script or save it as a ".vbs" file. Microsoft has some good tutorials if you are unfamiliar with login scripts.
Set WshShell = CreateObject("Wscript.Shell") 'Create wshell object
WScript.Sleep(5000) 'Lets wait 5 seconds
WshShell.AppActivate "EXACT TITLE OF THE WINDOW YOU WANT" 'EDIT THIS LINE!
'The line above selects the window so we make sure the keystrokes are sent to it
WshShell.SendKeys "%{F11}" 'Send ALT+F11
Wscript.Quit 'Quit the script

How to make this WSH script work? (details in message)

This script is supposed to open both Windows shell Status and Properties dialogs of the first found network connection which is enabled or connected. However, only the Properties dialog is opened. The verb for the Status dialog is already correct, which is "Stat&us". The script was tested and will be used under Windows XP Pro SP3 32-Bit. It was tested with a connected 3G dialup and a LAN Loopback. Both have the same problem.
dim a,b,c
set a=createobject("shell.application")
set b=a.namespace(0).parsename("::{7007ACC7-3202-11D1-AAD2-00805FC1270E}").getfolder
for i=0 to (b.items.count-1)
set c=b.items.item(i)
for j=0 to (c.verbs.count-1)
'only process connected/enabled
if (lcase(c.verbs.item(j)) = "disc&onnect") or (lcase(c.verbs.item(j)) = "disa&ble") then
'open status and properties dialogs
c.invokeverb("Stat&us") 'this doesn't work
c.invokeverb("P&roperties") 'this one works
msgbox "Press OK to close all and exit"
wscript.quit
end if
next
next
In Windows XP there is a bug whose effect requires the Status verb to be invoked from within the Explorer process. Since WScript/CScript is not a child of the Explorer process, any attempt to invoke the status verb with prove futile despite the lack of any apparent errors. This bug appears to have been fixed in later versions as the script below is tested and working in Vista x64.
Set objShell = CreateObject("Shell.Application")
Set objShellFolder = objShell.Namespace(0).ParseName("::{7007ACC7-3202-11D1-AAD2-00805FC1270E}").GetFolder
For Each objShellFolderItem in objShellFolder.Items
Set colShellFolderItemVerbs = objShellFolderItem.Verbs
For Each objShellFolderItemVerb in colShellFolderItemVerbs
strVerb = objShellFolderItemVerb.Name
If (strVerb = "C&onnect / Disconnect") Then
objShellFolderItem.InvokeVerb("Properties")
objShellFolderItem.InvokeVerb("Status")
MsgBox "Press OK to close and exit"
WScript.Quit(0)
End If
Next
Next
Option 1
Does that mean that you're out of luck? Not entirely. I have two different suggestions for you. The first uses a little trickery. Status is the default action for any network connection while it is in a connected state. Open up your network connections, right-click the connection your wish to monitor and choose Create Shortcut. You can place the shortcut anywhere you like. By default it will be named something like "Wireless Network Connection - Shortcut.lnk" on your Desktop. Typing that on the command line or via the Run or Exec methods in your script will do exactly what you need. I tried playing around with doing this all via scripting but ran into issues tryint to automate the Create Shortcut verb.
Option 2
A second option is also a bit of a workaround but may work if your 3G connection uses the dialup networking. The command line rundll32.exe rnaui.dll,RnaDial {name of connection to establish} will open the dialog to connect, however, if already connected, it opens the Status dialog for the connection. You could then try a script like this:
Set objShell = CreateObject("Shell.Application")
Set objShellFolder = objShell.Namespace(0).ParseName("::{7007ACC7-3202-11D1-AAD2-00805FC1270E}").GetFolder
For Each objShellFolderItem in objShellFolder.Items
strConnection = objShellFolderItem.Name
strCommandLine = "rundll32.exe rnaui.dll,RnaDial " & Chr(34) & strConnection & Chr(34)
Set colShellFolderItemVerbs = objShellFolderItem.Verbs
For Each objShellFolderItemVerb in colShellFolderItemVerbs
strVerb = objShellFolderItemVerb.Name
If (strVerb = "C&onnect / Disconnect") Then
objShellFolderItem.InvokeVerb("Properties")
CreateObject("WScript.Shell").Run strCommandLine
MsgBox "Press OK to close and exit"
WScript.Quit(0)
End If
Next
Next
Option 3
A final option would be to use WMI to display the information about your network connection. This is a more traditional scripting approach.
In any case, I hope this helps out. Don't forget to change the verbs as required. They do change from one version of Windows to the next.

Resources