How can I make a vbs file which can press arrow keys? - vbscript

I'm using a voice command software and its still in its beta but really good
The only thing that I find a big problem is navigation in folders and files
So i thought i'll make a vbs script with gets triggered to my voice.
eg: I say left the vbs file which presses left arrow gets pressed
I just need the code for the keystrokes
Once again, move the highlighted folder by pressing arrow keys it what i'm trying to do
Plz somebody help me make a code for this
Thank you

may this will help you to create script
'create shell script object which key stork and move arround the screen
set WshShell = WScript.CreateObject("WScript.Shell")
Set shell = wscript.CreateObject("Shell.Application")
shell.Open "C:\export\script"
WshShell.SpecialFolders("C:\export\script")
WshShell.specialFolders.item(0)
WshShell.SendKeys "{LEFT}"
WScript.Sleep 1000
WshShell.SendKeys "{LEFT}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{DOWN}"
WScript.Sleep 1000
WshShell.SendKeys "{DOWN}"
WScript.Sleep 1000
WshShell.SendKeys "{DOWN}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{LEFT}"
WScript.Sleep 1000
WshShell.SendKeys "{UP}"
WScript.Sleep 1000

Related

How to run an application and wait for it to close to run the rest of the code

I was wondering how can I call an exe and wait for it to close and then execute the rest of the code.
This is the code I have:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run("C:\Users\HP8200\Desktop\SolitRepoeTEM\SolitRepoeTEM\bin\Debug\WindowsFormsApp12.exe")
WshShell.SendKeys "{d}"
WshShell.SendKeys "{o}"
WshShell.SendKeys "{c}"
WshShell.SendKeys "{u}"
WshShell.SendKeys "{m}"
WshShell.SendKeys "{e}"
WshShell.SendKeys "{n}"
WshShell.SendKeys "{t}"
WshShell.SendKeys "{o}"
WshShell.SendKeys "{-}"
WshShell.SendKeys "{e}"
WshShell.SendKeys "{n}"
WshShell.SendKeys "{t}"
WshShell.SendKeys "{enter}"
WshShell.SendKeys "{enter}"
WshShell.SendKeys "{r}"
WshShell.SendKeys "{e}"
WshShell.SendKeys "{p}"
WshShell.SendKeys "{o}"
WshShell.SendKeys "{e}"
WshShell.SendKeys "{t}"
WshShell.SendKeys "{e}"
WshShell.SendKeys "{m}"
WshShell.SendKeys "{enter}
When in doubt, read the documentation.
Run Method (Windows Script Host)
Runs a program in a new process.
Syntax
object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])
Arguments
[...]
bWaitOnReturn
Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program. If set to false (the default), the Run method returns immediately after starting the program, automatically returning 0 (not to be interpreted as an error code).
If that doesn't work because the executable returns immediately try running the application from CMD via the start command.
WshShell.Run "cmd /c start """" /wait /b ""C:\User...App12.exe""", 0, True
If that still doesn't work you need to check the process list for your application. Do a WMI query against the Win32_Process class in a loop until the process doesn't show up anymore.

Automating IE SaveAs Dialogue using vbscript

I am trying to create a scheduled automation in windows server using vbscript.
Following is the script i am using to automate the Save As dialogue. It is working fine when the server is connected to a display (using RDC) but failing when its scheduled to run headless. Am I missing something here.
Dim ReportPath
Dim oShell
ReportPath = WScript.Arguments(0)
if len(ReportPath) = 0 then
WScript.Quit
end if
Set oShell = CreateObject("WScript.Shell")
oShell.AppActivate("Internet Explorer")
msgbox
WScript.Sleep 2000
oShell.SendKeys "{TAB}"
WScript.Sleep 2000
oShell.SendKeys "{TAB}"
WScript.Sleep 2000
oShell.SendKeys "{Enter}"
WScript.Sleep 2000
oShell.SendKeys ReportPath
WScript.Sleep 2000
oShell.SendKeys "{Enter}"
' Return status of script execution
' WScript.StdOut.Write(returnVal)

I want to set IE as default browser in windows 10 by vb.net code or any exe. I have used below VBS script. But it is not working

I have tried below script but not working. If it run manually, focus is correct. But if it is run through registry it is not taking focus to desired window. U can also suggest me if there is any other way to keep focus on desired window. The window opened through this code is control panel settig window and it is not found under proccess in task magager.
So please give solution.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\system32\control.exe /name
Microsoft.DefaultPrograms /page pageDefaultProgram\pageAdvancedSettings?
pszAppName=Internet%20Explorer"
'Give Default Programs time to load
WScript.Sleep 500
WshShell.AppActivate "Set Program Associations"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys " "
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys " "
Msgbox "Default Browser: Internet Explorer"
WScript.Quit
function Set-IEAsDefaultBrowser {
Add-Type -AssemblyName 'System.Windows.Forms'
Start-Process $env:windir\system32\control.exe -ArgumentList '/name Microsoft.DefaultPrograms /page pageDefaultProgram\pageAdvancedSettings?pszAppName=Internet%20Explorer'
Sleep 2
[System.Windows.Forms.SendKeys]::SendWait("{TAB} {TAB}{TAB} ")
}
Set-IEAsDefaultBrowser
I tried to run this script in windows powershell for set Internet Explorer as default Browser. It's works fine.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\system32\control.exe /name Microsoft.DefaultPrograms /page pageDefaultProgram\pageAdvancedSettings?pszAppName=Internet%20Explorer"
WScript.Sleep 1500
WshShell.SendKeys "{TAB}"
WshShell.SendKeys " "
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys " "
Msgbox "Default Browser: Internet Explorer"
WScript.Quit
it works fine for me.

How Can i open an cmd prompt and set an path to open an .bat file in Vb Script..?

I need to Automate the Whole Process, So the Cmd Prompt opens and path is set there for the .bat file to open
I have tried with Window Shell Commands to do this .. they work fine .. But i need some other way to open and set the path to run the file ..can anyone help me
Thanks In Advance
Here you go
Set WshShell = wscript.CreateObject("wscript.Shell")
WshShell.Run "cmd"
WScript.Sleep 100
WshShell.AppActivate "C:\Windows\system32\cmd.exe"
WScript.Sleep 100
wshshell.sendkeys "c:\path"
wshshell.sendkeys "{ENTER}"
wshshell.sendkeys "SET PATH=%PATH%;c:\tmp"
wshshell.sendkeys "{ENTER}"
wshshell.sendkeys "batch.cmd"
wshshell.sendkeys "{ENTER}"

Loop IP address substitution in prewritten code

I have code set up to telnet into a switch and tftp the startup-config to a server. This code works perfect if I hard code the IP address into the script.
What I would like to do is pass a list of IP addresses (one after the other) to the script so that I can copy all switch configs on the network. I have included some code below, this is the code I used to create the script. All I want to be able to do is replace the "telnet xx.xx.xx.xx" xx.xx.xx.xx entry with a list of IP addresses.
Thanks in advance!
Here is a copy of code I used:
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet xx.xx.xx.xx"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "5"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
WScript.Quit
Try this, mostly your code with just a few lines inserted to loop through a list of IP addresses in plain text format. Please let me know if this works for you. Doing it this way opens a new command window for each telnet host and then closes it when its done. It would probably be easy to modify to use the same command window.
Option Explicit
On Error Resume Next
Dim WshShell
Dim objFSO
Dim objInputFile
Dim strIP
set WshShell=CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("IPFilelist.txt", 1)
Do Until objInputFile.AtEndofStream
strIP = objInputFile.ReadLine
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet " & strIP
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "5"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
Loop
WScript.Quit

Resources