Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to using TaskScheduler to reboot Win32 machine by ethrbunny

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-26 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found