Is this the correct way of taking input from the keyboard (CTRL+L)?
dim WshShell
set WshShell = CreateObject("WScript.Shell")
wait(2)
WshShell.SendKeys("^108")
wait(2)
or
dim WshShell
set WshShell = CreateObject("WScript.Shell")
wait(2)
WshShell.SendKeys("^l")
wait(2)
The correct way to send a CTRL-L using SendKeys is like this:-
WshShell.SendKeys("^l")
Here is the MSDN reference for the SendKeys method to get more information:
https://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx
Related
I'm trying to make a Vb script that restarts another vbs script the problem is I'm new to this and I don't know how to do this, someone suggested using WshShell I have tried a few websites on how to use it but nothing. Here is what I've got,
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("Test_To_Block.vbs")
Do
If NOT WshShell.Status = 1 then
WScript.Exec("Test_To_Block.vbs")
End If
WScript.Sleep(100)
Loop
Thanks,
Regards,
A Viper
Yes, you can use Exec method to run another VB Script, but you are likely to get a console window flash.
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Exec("CMD /C Test_To_Block.vbs")
Refer to SS64 site to learn about VB Script basics.
I have written below vb script to find an window and bring it to focus
Dim oShell
Set oShell = CreateObject("WScript.Shell")
'bring the window to front
'title must be exactly what you see in the titlebar of the window
oShell.AppActivate WScript.Arguments(0)
I am calling this vb script from java code :
Runtime.getRuntime().exec("cmd.exe /c activeWindow.vbs mywindowname");
Now sometimes it is throwing this below exception :
This is happening randomly.
Syntax for AppActivate :
objShell.AppActivate strApplicationTitle
Below code is working directly by passing title name
Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.AppActivate "Calculator"
Or Passing as argument "WScript.Arguments(0)". Save this code in VBS file
Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.AppActivate WScript.Arguments(0)
WScript.Quit 0
from cmd type wscript Sample.vbs Calculator
Code is working smoothly and Calculator screen is activating .
I can't figure out how to press Control A (HighLight everything) using VBS, what is it?
Set objShell = WScript.CreateObject("WScript.Shell")
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 500
object.SendKeys "^A"
I get this
Windows Script Host
Script: C:\Users\Shane own\Desktop\A.vbs
Line: 4
Char: 1
Error: Object required: 'object'
Code: 800A01A8
Source: Microsoft VBScript runtime error
OK
Any idea ?
SendKeys is a method of the WshShell class. You created two WshShell objects (objShell and WshShell). Just use one of those objects to call the SendKeys method.
objShell.SendKeys "^A"
Right im looking for a script that I can click on after I have logged in to open various programs just to save me a bit of time. I have managed to get a script to open one but as a bit of a newbie can someone provide advice.
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run """C:\Program Files (x86)\servicecenter\Run\scguiw32.exe "" ""-
express:dvla.servicecenter.fs.fujitsu.com.12680"""
Set objShell = Nothing
You might be overthinking it a bit to use VBScript or Powershell for this job. A batch file will work.
#echo off
start "c:\Program Files\Folder 1\program.exe"
start "c:\Program Files\Folder 2\program.exe" -switch -argument
exit
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("Path to program")
wscript.sleep (100)
objShell.Run("Path to program")
wscript.sleep (100)
wscript.quit
I do not have scguiw32.exe, so I created simple script which opens file in notepad and in word.
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run "C:\Windows\notepad.exe c:\dump.txt"
objShell.Run """C:\Program Files (x86)\Microsoft Office\Office14\winword.exe"" c:\dump.txt"
Set objShell = Nothing
BTW Instead of vbscript you can use now powershell, and powershell script is much more easy to understand. For example above one will be: Create run.ps1 with content
& 'C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE' c:\dump.txt
notepad.exe C:\dump.txt
Click it right-click and choose Run with Powershell
Here is how to use vbscript to create an array of programs you want to run and then execute each one.
'---Declare Variables
Dim objShell, strprogram1, strProgram2, colprograms, item
'---Create Scripting Shell Object
Set objShell = CreateObject("WScript.Shell")
'---Create Program Variables
strProgram1 = """C:\Program Files (x86)\servicecenter\Run\scguiw32.exe"" ""-express:dvla.servicecenter.fs.fujitsu.com.12680"""
strProgram2 = "C:\Windows\notepad.exe C:\Dump.txt"
'---Add Variables to an Array
colPrograms = Array(strProgram1,strProgram2)
'---Run each program in the array once
For Each item In colprograms
objShell.Run item
Next
WScript.Echo "Done."
Is there a way to simulate the enter key in VBScript? Ex.:
set shl = createobject("wscript.shell")
shl.sendkeys "SIMULATED ENTER"
try {ENTER}, ie
shl.SendKeys "{ENTER}"
here's my reference http://www.computerperformance.co.uk/ezine/ezine120.htm
The vbscript to press enter key working!
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "{ENTER}"