0

I'm trying to get a batch file to automatically enter the password into the "runas" program, this code is working fine but it is not supported by SQL server agent. Here's my batch file so far:

@if (@CodeSection == @Batch) ‌@then
‌@echo off
‌start "" runas /user:testuser c:/path/to/my/program.exe
‌CScript //nologo //E:JScript "%~F0"
‌goto :EOF
‌@end
‌WScript.CreateObject("WScript.Shell").SendKeys("password{ENTER}");

Please suggest any method to enter a password automatically and it should support the SQL server agent job.

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • How is it not supported? Does `SQL server agent` not support emulated keypress or something? –  May 15 '17 at 11:41
  • 1
    may be you'll need to put the correct window on focus? – npocmaka May 15 '17 at 12:26
  • @npocmaka That's a good point, but right after the `start` command, the `sendkeys` command executes, and that would take about than 0.1 seconds, it shouldn't be enough for someone to switch window focus. –  May 15 '17 at 12:33

0 Answers0