Jump to content

Run(@ComSpec...) with schtasks


Vivaed
 Share

Recommended Posts

I have this button in an app I am building:

When you click it, it then opens a FileOpenDialog() I select and XML, then it asks for a name input, enter the name, then it should run the following code:

schtasks.exe /create /tn XXXX-task /XML C:\WBRESO~1\WB-LOO~1\TESTIN~1.XML

It works when I put it in the CMD and run it, I get SUCCESS! and the new task has been created in Task Scheduler.

C:\Users\vivaed>schtasks.exe /create /tn XXXX /xml C:\WBRESO~1\WB-LOO~1\TESTIN~1.XML
SUCCESS: The scheduled task "XXXX" has successfully been created.

But when I run it in:

(This is just a snippet of the code, there is a lot more)

#include <AutoItConstants.au3>

Global $wbResources = 'C:\"WB Resources"\WB-LoopChecker\'

Case $Button4
                $getXML = FileOpenDialog("Find task to import", $wbResources ,"XML (*.xml)")

                If @error Then
                    ; Display the error message.
                    MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")
                Else
                    Local $taskName = InputBox("Name this task","File: " & @CRLF & $getXML & @CRLF & "Name this task:" & @CRLF,"XXXX-task")
                    $schedTask = 'schtasks.exe /create /tn ' & $taskName & ' /XML ' & FileGetShortName($getXML)
                    Run(@ComSpec & " /c " & $schedTask, @SW_HIDE)
                    ConsoleWrite($wbResources & @CRLF)
                    ConsoleWrite($schedTask & @CRLF)
                EndIf

Here I dont get any errors but the when I refresh the Task Scheduler, there is no new task.... :(

 

Edited by Vivaed
Link to comment
Share on other sites

you either need #RequireAdmin at the top of your script, or you have a quotes issue in the string you pass to Run().

to troubleshoot the 2nd option i see you do a ConsoleWrite() to a part of the string. do that for the whole string, including the @ComSpec part - the exact complete string you pass to Run().

EDIT: how are you checking for errors for saying that you hare not getting any?

EDIT: perhaps this will be of some use to you:

 

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

  • Developers

Change the /c to /k and remove the @SW_HIDE so you can see the CMD window and the errors generated.

Jos

edit: Actually you have an error in your Run command. the second parameter should be the workdir, not the Window status!

Edited by Jos

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...