http://qs321.pair.com?node_id=626069

ethrbunny has asked for the wisdom of the Perl Monks concerning the following question:

Im trying to put together a script that will create a task scheduler entry that will reboot a machine 1x / week. I have it working where it will create the task scheduler entry but it's not getting formatted correctly in the resultant item. Since the command in question has spaces in it the task scheduler is putting quotes around the whole command. This is confusing the entry which uses 'perl -e' to run the command and requires quotes around its part. Confused yet? Here's the code:

#!/cygdrive/c/perl/bin/perl -w use Win32::TaskScheduler; use strict; my $taskName = "weekly reboot"; my $APP_NAME = q#c:\\perl\\bin\\perl.exe -MWin32 -e "Win32::InitiateSy +stemShutdown(' ','Rebooting',5,1,1);"#; my $ACCOUNT_NAME = "bob"; my $ACCOUNT_PW = "jones"; my $scheduler = Win32::TaskScheduler->New(); $scheduler->Activate( $taskName ); # # This adds a weekly schedule. my %taskTrigger = ( 'BeginYear' => 2007, 'BeginMonth' => 1, 'BeginDay' => 1, 'StartHour' => 1, 'StartMinute' => 0, 'TriggerType' => $scheduler->TASK_TIME_TRIGGER_WEEKLY, 'Type'=>{ 'WeeksInterval' => 1, 'DaysOfTheWeek +' => $scheduler->TASK_SUNDAY, }, ); $scheduler->NewWorkItem( $taskName, \%taskTrigger ); $scheduler->SetApplicationName( $APP_NAME ); # run forever $scheduler->SetMaxRunTime( $scheduler->INFINITE ); $scheduler->SetAccountInformation( $ACCOUNT_NAME, $ACCOUNT_PW ); $scheduler->Save();


I've tried various combinations of single and double quotes. If I create the task manually and put double quotes around the 'Win32::InitiateSystemShutdown' call it works.

addendum: task scheduler puts quotes around any command that has spaces in it... and doesn't work.. I tried putting 'shutdown.exe -r -t 5 -f' in there.