This should be very simple, but I can't get it to work
do
wscript.sleep 3000
shellobj.sendkeys "{F5}"
loop
Like this way :
Set ws = CreateObject("wscript.shell")
do
wscript.sleep 3000
ws.sendkeys "{F5}"
loop
Related
I am trying to use VBScript to open an external application and refresh it using Sendkeys. How can I pause code at sendkeys"R" line(Using to refresh data), and go to the next line after the refresh operation is completed?.
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Users\PC\Documents\CAP.pbix""")
do
WScript.Sleep 15000
objShell.AppActivate"CAP"
objShell.SendKeys"%{H}"
WScript.Sleep 1500
objShell.SendKeys"R"
WScript.Sleep 1500
objShell.SendKeys"%{H}"
WScript.Sleep 1500
objShell.SendKeys"PU"
WScript.Sleep 1500
objShell.SendKeys"{Enter}"
WScript.Sleep 1500
objShell.SendKeys"{Esc}"
WScript.Sleep 2500
loop
You can only sleep and hope that it is long enough. There's no other way to know if the application has completed the refresh.
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"
I have the following:
set wshshell=createobject("wscript.shell")
wshshell.run """C:\ReportName.pdf"""
This opens the named PDF. What code do I need to save that opened file as, like a SaveAs.. saving it as the same filename?
Thanks
Here is sample code
set wshshell=createobject("wscript.shell")
wshshell.run """C:\ReportName.pdf"""
wscript.sleep 2000 'sleep for 2 seconds to ensure file is open
wshshell.SendKeys "%{F}{A}" 'simulate ALT+F+A to open SaveAs dialog
wscript.sleep 5000 ' sleep for 5 seconds so that the save as dialog is open
wshshell.SendKeys "+{TAB}{ENTER}" 'simulate Shit+Tab so that the tab is moved backed to Choose a diff folder option
wscript.sleep 2000
wshshell.SendKeys "C:\NewFile.PDF{ENTER}"
wscript.sleep 3000
wshshell.SendKeys "%{F}{X}"
It sounds like you want to copy the file or move/rename the file. If so, use FileSystemObject:
Set fso = CreateObject("Scripting.FileSystemObject")
Call fso.CopyFile("C:\ReportName.pdf", "C:\NewReport.pdf")
' or
Call fso.MoveFile("C:\ReportName.pdf", "C:\NewReport.pdf")
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 500
WshShell.SendKeys "{BREAK}"
I want run as Pause|Break keys, How can I set it?
I wrote a VBScript a while back to make a task easier. It works, however it wont run as a scheduled task since it requires a command window to interact with. How would I change the script to allow it to run as a scheduled task?
dim filesys
Set objShell = WScript.CreateObject("WScript.Shell")
set filesys=CreateObject("Scripting.FileSystemObject")
WScript.Sleep 2000
objShell.SendKeys"dsdbutil"
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 2000
objShell.SendKeys("activate instance wap")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 2000
objShell.SendKeys("ifm")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 2000
objShell.SendKeys("create full c:\adldsbackup")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 30000
objShell.SendKeys("quit")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 2000
objShell.SendKeys("quit")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 2000
filesys.MoveFile "c:\adldsbackup\adamntds.dit", "\\vash\ibts_ts\Networking\Backups\ADLDS\adamntds_" & DatePart("m",Now()) & "_" & DatePart("d",Now()) & "_" & DatePart("YYYY",Now()) & ".dit"
objShell.SendKeys("exit")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
I have done something similar, scheduling a vbs. The solution is simple!
Create a batch file to run the vbs file and schedule this batch file. I prefer to use cscript in the batch files:
cscript.exe //nologo <ScriptNameWithFullPath>