vbscript simple send key not working - vbscript

i have a simple vbscript that perform "Ctrl 2", the sendkey work perfectly in my PC, when i try it in another PC it's not working at all.
here is the code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^2"
tried to add parentheses and also i changed the UAC the the lowest but till not working.
i would like to add that the other PC is in French language if that can be the problem.
thank guys

Related

VBS Can't printscreen

I recently picked up VBScript and I was messing with the sendkey commands when I noticed that the {PRTSC} isn't working on my computer.
My Program: I made it so that it'll take a screenshot and paste it.
set objShell = CreateObject("WScript.Shell")
WScript.Sleep 1000
objShell.sendKeys "{prtsc}"
objShell.SendKeys "^V"
Is there something wrong with the code or am I not understanding something?
Thanks.
Note
You cannot send the PRINT SCREEN key {PRTSC} to an application.
From Help https://msdn.microsoft.com/fr-fr/library/8c6yea83(v=vs.84).aspx
Also Sendkeys is part of Windows Scripting Host not VBScript.

Create a VB script to send the keys to open up a program with specific settings

I am trying to create a VB script to send the keys to open up a program/application with specific settings. So, after the application has been started, choosing those very specific settings would involve pressing 2 buttons inside the application UI (1st button to choose specific set of options, and 2nd button to save those options).
I will then create a batch file to call the mentioned VB script on boot.
So far, I got this:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^%1"
I've searched and searched, but couldn't figure out how to be able choose/save options once the app has been started, if it's even possible?
Thank you in advance for helping out!
Disclaimer: I am not a technical person, so forgive me if noob question :)
Here's a script to start an application (notepad), then send some keystrokes to it:
'VBScript Example
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "c:\windows\notepad.exe"
' add delay here
WshShell.AppActivate "Notepad"
WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "abc"
WshShell.SendKeys "{CAPSLOCK}"
WshShell.SendKeys "def"
Perhaps this can be adapted to your needs?
The WshShell.AppActivate command is used to bring the program (with the specified window title) to the foreground.
You might want to add a delay to allow the program time to start before sending the keystrokes. This can be done by adding a sleep() call just after Wshell.Run:
' Sleep for 5 seconds (5000 msec)
WScript.Sleep(5000)
Also, here's a list of key-codes that you can use.

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

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.

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")

Windows 7 VBScript Choosing Window by Title

So it seems as though the following bit of code works with Windows XP, but does NOT work with Windows 7:
Dim objFileSys
Set objFileSys = CreateObject("Scripting.FileSystemObject")
If objShell.AppActivate("Query Express") Then
Else
objShell.run chr(34) & "I:\SQL-Queries\QueryExpress\QueryExpress.exe" & chr(34),1,False
End If
Basically, it checks to see if the window is already open. If it is NOT open, it opens it.
Pretty simple, eh? Well, this bit of code does not work as scripted in Windows 7. Can someone clue me in as to how to update it to work?
Thanks!

Resources