0

I'm trying to make daily backups of database in remote server, but there is a problem with WshShell.SendKeys not registering key presses.

I run batch file in TaskScheduler at specified time which runs "PressF5.vbs" file.

The problem is, when I am logged in in server and TaskScheduler stars task, every key gets pressed, everything works like charm. But when TaskScheduler starts task when i am logged off from RemoteServer, WshShell.SendKeys dont register as being pressed.

(By RemoteServer I mean RemoteDesktopConnection)

Code in batch file:

start /d "C:\BackUps\AutoBackups" MinimizeAll.vbs
TIMEOUT 3
start /d "C:\BackUps\AutoBackups" Create_backups_of_all_DB.sql
TIMEOUT 10
start /d "C:\BackUps\AutoBackups" PressF5.vbs
TIMEOUT 3600
start /d "C:\BackUps\AutoBackups" CreateRar.bat

Code in PressF5:

Option Explicit
Dim WshShell

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "{F5}"

EDIT 1

I am trying to achieve back up creation of databases in SQL Server 2014 Management Studio. There is auto backup creator (but only in full version), which I don't own. Then after creating all databases backups, I run batch file to compress backups to RAR and delete uncompressed leftovers. Then I move that RAR to other location.

Hope that explains a little bit more what I am trying to achieve.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tomas
  • 67
  • 1
  • 1
  • 8
  • SendKeys is mostly always a bad idea. And no you won't be able to use SendKeys with RDP. [Read this](https://stackoverflow.com/questions/1138606/alternative-to-sendkeys-when-running-over-remote-desktop). You should try other ways to backup your database with a scheduled task. There are obviously many other ways to do it, but you should explain everything in order to receive an alternative – Thomas G May 09 '18 at 08:39
  • Added some more information of what I am trying to accomplish. – Tomas May 09 '18 at 08:57
  • 1
    You have multiple solutions as planned : check the [vbscript posted here](https://stackoverflow.com/questions/23721062/how-to-create-copy-of-database-using-backup-and-restore) and the [C# application here](https://blogs.msdn.microsoft.com/sqlexpress/2007/03/20/backup-and-restore-with-user-instances/) and the [SQL server procedure here](https://www.mssqltips.com/sqlservertip/1070/simple-script-to-backup-all-sql-server-databases/). That's 3 diffrent ways to achive what you want to do, without SendKeys – Thomas G May 09 '18 at 09:04

0 Answers0