Rudy
Rudy

Reputation: 41

Schedule taks with schtask.exe gives error invalid syntax in script

I want to create a scheduled task using C:\Windows\System32\schtasks.exe in a perl script. I'm using the following script:

use strict;
my $createScheduleTask = `SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN \"updater\" /TR \"\\\\network\\shared\\updater.bat\" /ST 19:00`;

But I get the following response:

ERROR: Invalid syntax.
Type "SCHTASKS /?" for usage.

When I run the same command in the CLI it works fine (I did remove the escape '\'-s.) I've tried about every possible combination of escape characters, but I cannot find out what is wrong.

So does anybody know what is wrong or does anybody know how to debug it?

Thanks
Rudy
PS I don't want to use Win32::TaskScheduler since it is not installed on all clients.

Upvotes: 2

Views: 1234

Answers (1)

Simpler
Simpler

Reputation: 1369

This is likely due to the shell that you are running the command from.

I had this problem when running from a bash shell, but when I opened a standard Windows command prompt it runs fine.

Upvotes: 1

Related Questions