Frosty555
asked on
VBScript send keys to window based on window title
I have a small VBScript that I use to execute some backup operations on my hard drive by calling DriveImage XML. Basically, the VBS file creates some folders and runs DriveImageXML in order to make an image of the C:\ drive. A scheduled task runs it every couple of weeks.
By the way, this code works. You guys can use it if you like! :D
Now, this is usually all automated, however recently I've developed a bad spot on my hard drive, so I get "Data Cyclic Redundency" popups at about the 30% mark of doing the image. I have to click "Ignore All" to make the warning go away and finish the backup.
I'd like to make the VBScript check for the presence of that error window, and send the "I" key to the window to make it go away. Is there any way to do that? I think SendKeys() will work, but I don't know how to check the title of the active window.
Attached in my VBSCript code.
By the way, this code works. You guys can use it if you like! :D
Now, this is usually all automated, however recently I've developed a bad spot on my hard drive, so I get "Data Cyclic Redundency" popups at about the 30% mark of doing the image. I have to click "Ignore All" to make the warning go away and finish the backup.
I'd like to make the VBScript check for the presence of that error window, and send the "I" key to the window to make it go away. Is there any way to do that? I think SendKeys() will work, but I don't know how to check the title of the active window.
Attached in my VBSCript code.
' Backup Script
' Performs a backup of C:\ using DriveImage XML.
Option Explicit
Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim cDir
cDir = "Z:\LatitudeImage-" & Year(Now()) & "-" & Month(Now()) & "-" & Day(Now())
// Create the directory
If Not oFSO.FolderExists(cDir) Then
oFSO.CreateFolder(cDir)
// Generate a file name
Dim cFile
cFile = cDir & "\Drive_C"
Dim cCmd
// This is the shell command to run diXML with appropriate command line params
cCmd = """C:\Program files\Runtime Software\DriveImage XML\dixml.exe"" /bc /t""" & cFile & """"
// GO!
ExecuteShellProgram(cCmd)
End If
Function ExecuteShellProgram(ByVal sFilename)
Dim poShell
Dim poProcess
Dim iStatus
// Create a shell instance
Set poShell = CreateObject("WScript.Shell")
// This is asynchronous. Script ends immediately.
Set poProcess = poShell.Exec(sFilename)
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It shouldnt throw an exception, it should just keep looping until it does. I wasnt sure if it would work with the exec method of the shell object. Maybe we should try with the run method? The reason I didnt use it at first is because there would then need to be a way to break the loop when the program is finished running.
One thing I always ran into problems with is using extra double quotes on cmd lines. I always found it best to use chr(34) instead in a lot of places to make sure they are passed to the run line properly. Can you show me the error you get?
One thing I always ran into problems with is using extra double quotes on cmd lines. I always found it best to use chr(34) instead in a lot of places to make sure they are passed to the run line properly. Can you show me the error you get?
I just tested that portion of the script and it worked fine for me. What OS are you using? and what is the window title? Can you provide a screenshot of the popup?
ASKER
Hmm... nevermind it does work!
That was surprising. Lol.
Thank you!
That was surprising. Lol.
Thank you!
ASKER
I threw those comments in just before posting. Must have used C style comments instead of VB style comments.
The only issue I see with your code is that AppActivate is a sub. It throws an exception if it fails to find a process with the appropriate window title.
Is there an equivalent to try...catch in VBscript we can use to catch that error?