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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.