texan Posted January 31, 2011 Share Posted January 31, 2011 I am using Run("schtasks /create /tn TaskName /s \\remotepc .... other schtasks flags", "", "@SW_HIDE") to add a scheduled task on a remote PC. This works fine when the TaskName does not currently exist, but, when the TaskName does exist it fails (as expected). If I manually try running the SchTasks command from a DOS window I get an error stating "The specified task name already exists in the system". I was expecting the RUN command to give me an error in this situation since the task failed but it returns a number instead. Is there a way to get the RUN command to return an error in this situation or maybe you know a better way of going about this? Link to comment Share on other sites More sharing options...
Developers Jos Posted January 31, 2011 Developers Share Posted January 31, 2011 tried RunWait() to see what it returns? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
texan Posted January 31, 2011 Author Share Posted January 31, 2011 Tested using RunWait. RunWait returns 0 and @error is 0 when the command is successful. RunWait returns 1 and @error is 0 when the command is not successful. The help file says RunWait should return 0 when there is a failure but I am getting the opposite. Documentation wrong by chance? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 1, 2011 Moderators Share Posted February 1, 2011 Success: Returns the exit code of the program that was run. RunWait succeeded both times, your exit code was returned from the program itself. You have to interpret it, eg... 0 = success, 1 = Failure in your specific case. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
ChrisL Posted February 1, 2011 Share Posted February 1, 2011 #include <Constants.au3> $foo = Run("SCHTASKS /Create /SC HOURLY /MO 5 /TN CalcTest /TR calc.exe /ST 12:00:00", "", @SW_HIDE, $STDOUT_CHILD) Local $line While 1 $line &= StdoutRead($foo) If @error Then ExitLoop Wend MsgBox(0, "STDOUT read:", $line) [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ChrisL Posted February 1, 2011 Share Posted February 1, 2011 (edited) actually, you could always query it first to see if the task exists.#include <Constants.au3> $foo = Run("SCHTASKS /Query", "", @SW_HIDE, $STDOUT_CHILD) Local $line While 1 $line &= StdoutRead($foo) If @error Then ExitLoop Wend MsgBox(0, "STDOUT read:", $line) ;all output If StringInStr($line,"CalcTest") then Msgbox(0,"","CalcTest already exists") ; Bit crude but works in the basic formYou'd need to parse through the $line value to see if your task already existed.Edit:Even better if the task doesn't exist then the $line is blank....#include <Constants.au3> $foo = Run("SCHTASKS /Query /TN CalcTest", "", @SW_HIDE, $STDOUT_CHILD) Local $line While 1 $line &= StdoutRead($foo) If @error Then ExitLoop Wend MsgBox(0, "STDOUT read:", $line)CREATE, QUERY and DELETE example just to show the output#include <Constants.au3> $foo = Run("SCHTASKS /Create /SC HOURLY /MO 5 /TN CalcTest /TR calc.exe /ST 12:00:00", "", @SW_HIDE, $STDOUT_CHILD) Local $line = "" While 1 $line &= StdoutRead($foo) If @error Then ExitLoop Wend MsgBox(0, "STDOUT read:", $line) $foo = Run("SCHTASKS /QUERY /TN CalcTest", "", @SW_HIDE, $STDOUT_CHILD) Local $line = "" While 1 $line &= StdoutRead($foo) If @error Then ExitLoop Wend MsgBox(0, "STDOUT read:", $line) $foo = Run("SCHTASKS /DELETE /TN CalcTest /F", "", @SW_HIDE, $STDOUT_CHILD) Local $line = "" While 1 $line &= StdoutRead($foo) If @error Then ExitLoop Wend MsgBox(0, "STDOUT read:", $line) Edited February 1, 2011 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now