How to use SendKeys as Pause break? - vbscript

Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 500
WshShell.SendKeys "{BREAK}"
I want run as Pause|Break keys, How can I set it?

Related

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)

How to use VBScript to open notepad and paste current date in it?

How to use VBScript to open notepad and paste current date in it?
This is all I have for now:
Set WshShell = WScript.CreateObject("WScript.Shell")
Call WshShell.Run("%windir%\system32\notepad.exe")
Dim aDate
aDate = Date()
WScript.Sleep 2000
Now, how do I paste the date?
Use SendKeys to send keystrokes to the active window.
Usage:
WshShell.SendKeys aDate
You may need to ensure that the focus is in the window you want to send keystrokes to. For this, use AppActivate method.
Using window title in this case:
WshShell.AppActivate "Untitled - Notepad"
You can also use
WshShell.SendKeys "{F5}"
I know i am late, but try the following code, it works:
Set wshshell = wscript.CreateObject("WScript.Shell")
Wshshell.run "Notepad"
wscript.sleep 100
dim aDate
aDate = Date()
wscript.sleep 2000
wshshell.sendkeys aDate
wscript.sleep 1000
Make sure the extension of the file is ".vbs"

Object required:'WshShell'

Hey Everyone I'm trying to make a simple VBS script and I keep getting Error bject required:'WshShell'
Here is the script
CreateObject("WScript.Shell").Run "C:\DEXIS\DEXsync.exe"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Quit()
I have also attached the error message. can someone please help I feel like i'm taking crazy pills
error message
You'll need to set that WshShell variable you are using to a new Wscript.Shell object. Try something like this instead:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "C:\DEXIS\DEXsync.exe"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Quit()

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

Simulate Enter Key

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

Resources