Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run a scheduled task via command line via command line
#1
hello  Wink

i want start a Run a scheduled task via command line like this:

Code:
%SystemRoot%\system32\taskschd.msc /Run /TN "RegIdleBackup"

when i run the cmd in the prompt as admin the shedular task GUI pop up but the task not start.
i want make a registry backup on demand from cmd

Is there a solution?
Reply

#2
Take a look at this and make changes

Code:
schtasks /Run [/S <system> [/U <username> [/P [<password>]]]] /TN <taskname>


Code:
schtasks /Run /?


Run a Task on Demand


Here is a list of Parameters you can use


Parameters
<left><form action="https://www.paypal.com/cgi-bin/webscr" method="post">If you are satisfied with my help, consider a donation. Thank you so much for your continued support! 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y4ZDLXGFS4F8Q">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="0" height="0">
</form>

   </div></left> 
Reply

#3
thanks for fast reply.

I use windows 10 x64 and i have tryed a lot of command line sequence without success.

I have no idea what can i do.   Undecided
Reply

#4
I will take a look at it and see if it works.
<left><form action="https://www.paypal.com/cgi-bin/webscr" method="post">If you are satisfied with my help, consider a donation. Thank you so much for your continued support! 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y4ZDLXGFS4F8Q">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="0" height="0">
</form>

   </div></left> 
Reply

#5
identical post here? posted 3 hours ago
<left><form action="https://www.paypal.com/cgi-bin/webscr" method="post">If you are satisfied with my help, consider a donation. Thank you so much for your continued support! 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y4ZDLXGFS4F8Q">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="0" height="0">
</form>

   </div></left> 
Reply

#6
Backup and restore scheduled tasks from Task Scheduler's root folder

Credit goes to Rob van der Woude's Scripting Page

This was created for Windows 7, but I supposed it could be edited or adapted to run on Windows 10

Code:
@ECHO OFF
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
IF NOT "%~4"=="" GOTO Syntax
IF NOT "%~1"=="" IF /I NOT "%~1"=="/Backup" IF /I NOT "%~1"=="/Restore" GOTO Syntax
ECHO.%* | FIND "/?" >NUL && GOTO Syntax
SCHTASKS /?  >NUL  2>&1  || GOTO Syntax
IF "%~1"=="" GOTO BackupAll
IF /I "%~1"=="/Backup" (
    IF "%~2"=="" (
        GOTO Syntax
    ) ELSE (
        CALL :Backup "%~2"
    )
)
IF /I "%~1"=="/Restore" (
    IF "%~2"=="" (
        ECHO Please specify an XML file
        ECHO.
        GOTO Syntax
    ) ELSE (
        IF EXIST "%~2" (
            FOR %%X IN (%2) DO (
                CALL :Restore "%%~fX" %3
            )
        ) ELSE (
            ECHO File^(s^) not found: "%~2"
            ECHO.
            GOTO Syntax
        )
    )
)
GOTO:EOF


:Backup
SETLOCAL
SET TaskName=%~1
IF "%TaskName:~0,1%"=="\" SET TaskName=%TaskName:~1%
SCHTASKS /Query /TN "%Taskname%" >NUL 2>&1
IF ERRORLEVEL 1 (
    ECHO Task not found: "%TaskName%"
    ECHO.
    GOTO Syntax
) ELSE (
    SCHTASKS /Query /TN "%TaskName%" /XML > "SCHTASKS.%ComputerName%.Backup.%TaskName%.xml"
)
ENDLOCAL
GOTO:EOF


:BackupAll
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "tokens=1*" %%T IN ('SCHTASKS /Query /FO list ^| FINDSTR /R /B /C:"TaskName: " ^| FINDSTR /R /V /C:"\\.*\\."') DO (
    CALL :Backup "%%~U"
)
ENDLOCAL
GOTO:EOF


:Restore
SETLOCAL ENABLEDELAYEDEXPANSION
SET CurrentUser=%ComputerName%\%UserName%
SET XMLFile=%~f1
FOR /F "tokens=3* delims=." %%T IN ("%~n1") DO SET TaskName=%%U
IF NOT EXIST "%XMLFile%" (
    ECHO File not found: "%XMLFile%"
    ECHO.
    GOTO Syntax
)
SET Runas=
SET RunasUser=
FOR /F "tokens=3 delims=<>" %%R IN ('TYPE "%XMLFile%" ^| FIND /I /V "<UserId>%CurrentUser%</UserId>" ^| FIND /I /V "<UserId>SYSTEM</UserId>" ^| FIND /I "<UserId>"') DO (
    SET RunasUser=%%R
)
IF NOT "%RunasUser%"=="" (
    IF "%~2"=="" (
        SET /P RunasPassword=Please enter the password for %RunasUser%:
        SET Runas=/RU %RunasUser% /RP !RunasPassword!
        CLS
    ) ELSE (
        SET Runas=/RU %RunasUser% /RP %2
    )
)
echo SCHTASKS /Create /TN "%TaskName%" /XML "%XMLFile%" %Runas%
SCHTASKS /Create /TN "%TaskName%" /XML "%XMLFile%" %Runas%
ENDLOCAL
GOTO:EOF


:Syntax
ECHO.
ECHO BackupScheduledTasks.bat,  Version 1.02
ECHO Backup and restore scheduled tasks in Task Scheduler's root folder
ECHO.
ECHO Usage:  Backup all: BACKUPSCHEDULEDTASKS
ECHO         Backup one: BACKUPSCHEDULEDTASKS /Backup "taskname"
ECHO         Restore:    BACKUPSCHEDULEDTASKS /Restore "xmlfiles" [ password ^| /Q ]
ECHO.
ECHO Where:  "taskname" is the name of the scheduled task to be backed up
ECHO         "xmlfiles" XML file^(s^) ^(wildcards allowed^) created by this batch
ECHO                    file's backup command or exported in Task Scheduler's GUI
ECHO         "password" is the password for the task's "runas" user
ECHO         /Q         restores the task, but without the "runas" user's password
ECHO                    ^(must be set manually afterwards^)
ECHO.
ECHO Notes:  Only tasks in the Task Scheduler's root folder will be backed up.
ECHO         Each scheduled task in the Task Scheduler's root folder is saved as an
ECHO         XML file in the current directory, with the task's name for file name.
ECHO         When restoring a scheduled task configured for a user other than the
ECHO         current user or SYSTEM, and neither /Q is specified nor a password
ECHO         provided, then you will be prompted for the "runas" user's password.
ECHO         Note that this password will NOT be masked while being entered.
ECHO         Tested in Windows 7 only.
ECHO.
ECHO Written by Rob van der Woude
ECHO https://www.robvanderwoude.com

IF "%OS%"=="Windows_NT" EXIT /B 1

Source code for backupscheduledtasks.bat


SCHTASKS: Command line front-end for Windows' Task Scheduler
<left><form action="https://www.paypal.com/cgi-bin/webscr" method="post">If you are satisfied with my help, consider a donation. Thank you so much for your continued support! 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y4ZDLXGFS4F8Q">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="0" height="0">
</form>

   </div></left> 
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 Melroy van den Berg.