samedi 8 octobre 2016

How do I schedule a task at a random time via VBscrip file?

I am trying to write a .vbs scrip that will schedule a task to start at a random time.

When I double click the .vbs script it gets executed without any errors, but the task scheduler doesn't get populated with the new task.

sRndTime = Random2DigitNumber(08, 17) & ":" & Random2DigitNumber(0, 59) & ":" & Random2DigitNumber(0, 59)

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "SchTasks /create /tn New_Test_Task /sc WEEKLY /D MON,TUE /st " & sRndTime & " /TR ""C:\main_command.vbs"" /ru ""SYSTEM""", 1, True

Function Random2DigitNumber(iLower, iUpper)
Randomize
Random2DigitNumber = Right("00" & Int((iUpper - iLower + 1) * Rnd + iLower), 2)
End Function

I cannot see where is the issue with this code.

Any ideas what am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire