Schtasks backup - can't get the formatting right - cmd

I'm trying to schedule a task on a Windows 2008 server but can't get the formatting right.
Here's what I have:
schtasks /create /sc hourly /tn "Backup QB every hour" /tr wbadmin start backup -backupTarget:R:\QBBackups\ -include:D:\Quickbooks Data Files
Something tells me that the spaces in "Quickbooks Data Files" folder name is causing the issue. I can't tell for sure because the Last Run Result is 0xFFFFFFFF.
Ideally I'd like to save incremental versions by using the file date trick, but at this point I'd be happy to just get one scheduled task working.

Related

Unable to run my python script through windows task scheduler

I have installed the anaconda package and been running python notebooks and python scripts easily directly from console. I created a script and want it to run every day at particular time period but it did not work. So I created a simple test file to check what is wrong. This is my test file
print("enter the no to exit")
input()
When I run this program on command prompt it ask me for an input and then it exit.
I followed this tutorial to run this program daily using windows scheduler https://blogs.esri.com/esri/arcgis/2013/07/30/scheduling-a-scrip/
In action tab I wrote this
"C:\Anaconda3\python.exe"
And the argument as
"E:\test.py"
And when I run the task manually a black window pop up and automatically closed, I cannot figure out what is wrong. I see it say something like invalid directory. I don't know what am I doing wrong. Please help.
To run Python programs in Task Manager on Windows: In "Programs/Script" input path to python.exe In "Add Arguments"input script file name In "Additional Information" input path to location where file is saved
For example:
Path to Python: C:\Users\your_user_name\AppData\Local\Programs\Python\Python36-32\Python.exe
Script name ./script.py
Path to location where script is saved: C:/foldername/
Add the following command in beginning of the .bat file where all the configuration of python and python script written
CD /d %~dp0
In my case .bat file looks like
CD /d %~dp0
Call "C:\Python\Python37-32\python.exe" "D:\myProject\script.py"
pause
Have a look into this thread from stack overflow:
You can do it in the command line as follows:
schtasks /Create /SC HOURLY /TN PythonTask /TR "PATH_TO_PYTHON_EXE PATH_TO_PYTHON_SCRIPT"
That will create an hourly task called 'PythonTask'. You can replace HOURLY with DAILY, WEEKLY etc. PATH_TO_PYTHON_EXE will be something like: C:\python25\python.exe. Check out more examples by writing this in the command line:
schtasks /?
Otherwise you can open the Task Scheduler and do it through the GUI. Hope this helps.
This might solve your problem.
If it is still not working you may refer to this thread from esri.
This will get your job done.

Can't find file when trying to open via command line.

I wonder if someone can help, I want to run a schedule task and I discovered that I can put a command line command in there, which is good.
What I need to happen is for a PHP file to run a bit like a cronjob.
The system I am using recommends I do the below but it's not working, now I believe it's due to the file being on E and not C, but I have no idea how to correct this, if anyone could give me some pointers that would be great.
"C:\Program Files (x86)\PHP\v5.3\php.exe E:\pathtofile\tasks\frequently.php -f"
System info is win 7
You've got your quote characters all fouled up, but there are separate entries for the various parts of the command in Task Scheduler.
Try this:
When creating the new task, set the Action: dropdown to Start a program.
In the Program/Script: entry, use
"C:\Program Files (x86)\PHP\v5.3\php.exe"
In the Add arguments (optional) entry use
"E:\pathtofile\tasks\frequently.php" -f
I believe what you want to know is how to schedule the php program to process a php file via command prompt (Note that the -f needs to come immediately after the php.exe:
schtasks /Create /tn MyJob /tr #"C:\Program Files (x86)\PHP\v5.3\php.exe -f E:\pathtofile\tasks\frequently.php" /sc onlogon

Windows scheduled task

I have created a Windows 7 scheduled task:
schtasks /create /tn MyTask /tr C:\temp\test\MyScript.bat /sc MINUTE
Problem is that this task seems to get executed by Windows but I think it can not find the running BAT script. There is a quick flash window but can't read what the problem is.
On the other hand, if I place the script under Windows/System32 everything works fine.
schtasks /create /tn MyTask /tr C:\windows\system32\MyScript.bat /sc MINUTE
Anyone knows why the second schedule task works compared to the first one?
This whole thing is part of installing a program on a windows machine from a web page. So I would like to have the BAT file installed in its correct directory and not the System32.
Thanks for you help.
C:\temp is a temporary directory may be cleaned by the OS periodically. So you should first check to make sure that batch file is actually there, and then consider moving it to a more permanent location.
Second, have you tried running the task manually from its intended location? That should help you see what the output is. You can also add PAUSE to the bottom of the batch file (as suggested by commenters) to ensure that it stays up long enough for you to see the output.
Some likely problems are:
You're using some resource which is in %windir% via a relative path, which won't work when the batch file is run from a different location.
The scheduled task is running as a different user and doesn't have the proper permissions.
The task is doing something that requires elevation, but the task itself is not set to run elevated.
IIRC, schtasks does not load user profile: Most probably a variable is not set that you need.
Try to prepend your command line (after /tr) with cmd /K. It will make the console kept alive.
HTH

How to launch Windows Scheduler by command-line? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I mean to open the built-in Windows GUI from command line- not to launch by Schtasks
taskschd.msc is available in Windows Vista and later.
http://technet.microsoft.com/en-us/library/cc721871.aspx
I could have sworn I'd seen a little task scheduler GUI like you're talking about prior to Vista, but maybe I was thinking of the "Add Scheduled Task" wizard.
You might have to settle for opening the scheduled tasks explorer with this command:
control schedtasks
I couldn't find any way to launch the "Add Scheduled Task" wizard from the command line, unfortunately (there has to be a way!)
I'm using Windows 2003 on the server. I'm in action with "SCHTASKS.EXE"
SCHTASKS /parameter [arguments]
Description:
Enables an administrator to create, delete, query, change, run and
end scheduled tasks on a local or remote system. Replaces AT.exe.
Parameter List:
/Create Creates a new scheduled task.
/Delete Deletes the scheduled task(s).
/Query Displays all scheduled tasks.
/Change Changes the properties of scheduled task.
/Run Runs the scheduled task immediately.
/End Stops the currently running scheduled task.
/? Displays this help message.
Examples:
SCHTASKS
SCHTASKS /?
SCHTASKS /Run /?
SCHTASKS /End /?
SCHTASKS /Create /?
SCHTASKS /Delete /?
SCHTASKS /Query /?
SCHTASKS /Change /?
┌─────────────────────────────────────┐
│ Executed Wed 02/29/2012 10:48:36.65 │
└─────────────────────────────────────┘
It's quite interesting and makes me feel so powerful. :)
This launches the Scheduled Tasks MMC Control Panel:
%SystemRoot%\system32\taskschd.msc /s
Older versions of windows had a splash screen for the MMC control panel and the /s switch would supress it. It's not needed but doesn't hurt either.
Yes, the GUI is available in XP. I can get the list of scheduled tasks (but not the GUI) to open with the following command,
control.exe schedtasks
Then you can use the wizard to add a new scheduled task, for example.
In XP, you can find the Scheduler GUI from within Windows Help if you search for "Scheduled Tasks" then click on "Step by Step instructions" and open the scheduler GUI. Clicking on the last link executes the following command, which likely could be translatedinto something that would open the Scheduler GUI from the command line. Does anyone know how?
ms-its:C:\WINDOWS\Help\mstask.chm::/EXEC=,control.exe, schedtasks CHM=ntshared.chm FILE=alt_url_windows_component.htm
Here is an example I just used:
at 8am /EVERY:M,T,W,Th,F,S,Su cmd /c c:\myapp.exe
The result was:
Added a new job with job ID = 1
Then, to check my work:
at
You might want to have look at simple command line scheduler "at":
C:\Documents and Settings\mahendra.patil>at/?
The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.
AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] "command"
\computername Specifies a remote computer. Commands are scheduled on the
local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled
command.
/delete Cancels a scheduled command. If id is omitted, all the
scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further
confirmation is desired.
time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user
who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week or
month. If date is omitted, the current day of the month
is assumed.
/next:date[,...] Runs the specified command on the next occurrence of the
day (for example, next Thursday). If date is omitted, the
current day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.
You can make a new shortcut to:
control schedtasks
Name it something easy like "tsks.lnk" and then save it in c:\windows\system32.
You can now press Windows Key + R, then type "tsks" and press Enter and voila. No mouse necessary at that point.
Or in Windows Vista/7/2008, just press Windows Key, then type "tsks" and press Enter.
You can use either TASKSCHD.MSC or CONTROL SCHEDTASKS
Here are some more such commands.
I'm also running XP SP2, and this works perfectly (from the command line...):
start control schedtasks
If you’re asking what I think you’re asking, you can open it by executing this:
explorer.exe "C:\WINDOWS\Tasks\"

Schtasks.exe does not accept blank spaces when giving file path

I'm rolling out a new python script at the office and to make this run smooth I also made a batch file which will install it, and make it run on user logon.
I use schtasks.exe to schedule a task for this, so here is what i'm trying to run
schtasks /create /TN "fooname" /SC ONLOGON /TR "C:\foo - bar\fooscript.exe" /Delay 0005:00
The error I get is 0x80070002 which means the file cannot be found. After exporting the task I created, I can see that it separated the first and last bit of the path into
<Command>C:\foo</Command>
<Arguments>bar\fooscript.exe</Arguments>
I have tried microsofts own help article, but no luck. I wish to run this without any arguments regarding fooscript.exe.
As Magoo pointed out I was able to use the short name of the folder, which can be accessed with a
dir /x
tossing back a name like "FOO~1". Using this in my path made it work.
Thank you!
Sorry old thread but just found a workaround better than these here. Put the dir name in a prompt variable and then use the var in the command.
SET fname="c:\path with spaces\target.exe"
SchTasks [args] /TR %fname%

Resources