How do you schedule a daily script run on Windows XP? - windows

I wrote a script in Ruby. I'd like to run it every day at a certain time. How do you do that on a Windows XP system?
I poked around on the machine and discovered the "scheduled tasks" control panel, but it doesn't seem to have anything to do with running scripts, as far as I can tell from the options offered by the "wizard".

Scheduled Tasks. Sometimes, you have to make a batch file call the script, and schedule the batch.
say you have "script.vbs" you want to run, you will have to create this batch:
cscript script.vbs
cscript is the windows script host which interprets the vbs script. I'm sure ruby has something similar.

You can do it with scheduled tasks, just browse for the program or script you want to run if it isn't listed (in this case, the ruby interpreter I guess, and add the name of the script to run as an argument).

Use the Windows task scheduler.
Under Control Panel > Schedule Tasks.
You can set it up to run any application or file executable from the command line.
Update: (1/15/09)
A good point from Wouter van Nifterick, remember to take care that the process finishes before the next one runs (in comments).
This can be done by going into the advanced options and adjust the allowed amount of time the task may run.
If the task is already configured open it and click the Settings tab. At the top of this tab you will see a checkbox followed by 'Stop the task if it runs for:' then there are two text boxes to enter hours and minutes. If your script runs once a day you will want this set to 23 hours or so.

The 'at' command is a nice command line version of a scheduler.

Related

Is it possible to run a batch file when a program is launched?

I have a batch file that toggles aero. Is there a way that when you open a certain program the batch file will run when it is launched and run again when the program is closed?
Well yes, but on the Properties for the program you can tick a checkbox to do this on the compatability tab.
Find out info on what the browser is doing. Sart your program and then use Task manager to find your game (it is a real game and not some jscript web thing?).
Compatability layers are scritable.
See http://support.microsoft.com/kb/286705
set __compatlayer=256Color (note wrong spelling)
Running a program will have same problem as setting compatability. You have to find something to run it on.
Windows can start a debugger automatically when a program is started. You can substitute any program that can start a program (as a batch can) for the debugger.
You can also run a script that triggers on program start. Task Scheduler can run tasks when certain events occur.
But you have to know what exact object to trap. Use task manager in the first instance.

cronJob on windows

i wanna to create a cron job on windows that daily delete files from a specific folder.
how can i do this??
Thanks in advance
Use Schedule tasks in windows. Check here. You can use del command to remove one or more files. Put it inside a batch script and schedule it as a task.
You want Scheduled Tasks.
With Scheduled Tasks, you can schedule
any script, program, or document to
run at a time that is most convenient
for you. Scheduled Tasks starts every
time that you start Windows XP and
runs in the background, and it starts
each task that you schedule at the
time that you specify when you create
the task.
Edit your question if you specifically need help with the deleting files bit, but typing in help del at a command prompt should tell you everything you need to know.
I use Cron for Windows, it's very easy to use if you are familiar with cron from *nix

Possible to only initiate scheduled task if shortcut/button clicked?

I've created 2 tasks in Task Scheduler on my Vista PC start uTorrent at 2am then close uTorrent (and shutdown PC) at 7am. However i'd like to only like this task to run if I've clicked a shortcut - ideally show something in the tray as well if possible. But not sure how?
Thanks in advance!
I managed to to something like this myself in windows 7, should be the same in Vista.
To do what you want you could create a scheduled task that starts utorrent, another to close it later and another to then shut down the pc, all timed to run every day at 2am. You would then create a task that runs a batch file to delete the other tasks every time you boot up.
You will have exported the first three tasks as XML files just after you created them and saved them somewhere.
The key is that you then create a batch file that, upon double clicking will create the scheduled tasks by importing the XML files. This will cause the tasks to run as before and shut down your pc afterwards. Next time you boot up your machine the tasks are deleted again by the first batch file.
Read up on batch files (simple command propt commands in a file that run when clicked) and the command-line interface for scheduled tasks.
Type schtasks /? at the command promt for more info.
Hope that makes sense.

Hourly cronjob on Windows

I just setup cron on my windows dev system in order to perform
an hourly run of a script.
I tried to edit crontab in order to run my script hourly, sadly
with no success.
Could anyone pls. drop me the crontab line which will execute
script.xy every hour?
If you're using Windows, why not use the built-in Scheduled Tasks (Accessories-System Tools)?
It may not show up immediately in the Wizard, but it is possible to set up tasks to be run hourly. Just add a daily task and then tick the "Open Advanced Properties" checkbox. Then go to the Schedule tab and again click "Advanced".
I figured it out: 0 * * * * C:\doSomeWork.script Makes the script run every full hour. Sometimes the easy way is the best... ;) thx anyway
I'd argue you probably don't want to be using Cron on Windows at all. Instead use a Scheduled Task (accessible through the Control Panel) and select your script.
Alternatively create a Windows service which runs your program hourly. I've never heard of people using Cron for Windows tasks in this way.
Can't you use the Windows Task Scheduler instead of crontab?
A commandline solution would look something like:
at 00:00 /EVERY:M,T,W,Th,F,S,Su yourScript.cmd
at 01:00 /EVERY:M,T,W,Th,F,S,Su yourScript.cmd
...
Notice that you have to schedule a new task for each hour.
Anyone got a better soluition for this using the at command?

How to troubleshoot Windows Scheduled Task not running?

In the process of deploying our .net app, I've got about 20 scheduled tasks set up on a server, all of which basically do the same thing: invoke a small .net console app that pulls data from a SQL db and posts it to a web service. Each task invokes a separate copy of the app, each copy having a different lookup ID value in its config file.
All but two of these tasks run reliably every night. Two of the tasks seem to sporadically stop running from time to time, and it's currently a mystery as to why. When they stop running, the scheduled task interface correctly shows their last run date, which is a day or more behind the other tasks, which have continued to run at the scheduled time. The tasks which stopped running do not run again on their own, despite being indicated as scheduled to run every night. There are no errors recorded in the event log or in the scheduled task interface itself. And here's the strangest part to us: If I manually kick off the scheduled task, it runs fine, it invokes the .net console app and everything finishes without anomaly. And then it continues to run fine at its scheduled time, for days or weeks at a time, only to eventually fail, seemingly out of the blue. It appears both tasks always start to fail on the same night.
There's a "Last Result" column that should give you a code related to the task itself running (it's not going to have any kind of exception data). 0 means the task completed without errors. Anything else you can look up and see why the task won't start. If the task still seems to not be running, but you still see a 0 for the Last Result, that means there's something broken in your code, but it's exiting gracefully.
Did you set "Start in" property?
If these .NET console apps need app.config or some files located into their path, you have to set "Start in" property to "c:\your\app\path\, otherwise they start as if they are in the system directory, and they cannot find files they need!
Taskscheduler assumes on 64 bits systems that the applicaiton is 64 bit.
If it is 32 bit launch it from the 32 bit command line, i.e. if you want to run c:\program files (x86)\Myprogram\Program.exe, tell taskscheduler to launch:
%systemroot%\Syswow64\cmd.exe /C "c:\program files (x86)\Myprogram\Program.exe"
This forces it to launch from the 32 bit command-prompt and hence with 32 bit emulation.
I found this super helpful link :https://windowsreport.com/windows-scheduled-tasks-not-running/ for thorough debugging steps for many use cases.
In my case user account with which scheduler was configured to run was locked that stopped execution of scheduled tasks without any logs or reporting problem.
One reason for Scheduled Tasks not running occurs when associating them with a password-less Windows user account: by default Scheduled Tasks are prevented from running with a blank password. If you want to run a Scheduled Task from an account with no password you have to disable a system variable:
Go to: Start > Administrative Tools > Local Security Policy > Security Settings > Local Policies > Security Options
Select: "Accounts: Limit local account use of blank passwords to console logon only"
Disable this variable
Disclaimer: It´s not recommended to have accounts with no password.
The answer to the below SO question may also be highly relevant to people reading this question (but, NB, it describes only one possible specific problem with Scheduled Tasks and I believe neither of these questions is a duplicate of the other):
Why is my Scheduled Task updating its 'Last Run Time' correctly, and giving a 'Last Run Result' of '(0x0)', but still not actually working?
The summary of the answer given to that other question is that Windows 2012 Scheduled Tasks do not see the correct environment variables, including PATH, for the account which the task is set to run as.
In terms of more general Scheduled Task troubleshooting (as asked about in this question), you can test for this particular issue (e.g. running SET > test.txt in the task, as suggested in that answer), and once you can see it happening, you can work around it if it is affecting you.
In my case, the scheduled task wouldn't run even though it said last run was successful (0). It turned out to be that the windows user account that was running the jobs had become locked out. I only realized this because I tried editing the existing scheduled task, set the user account to the same one, then hit OK and it gave me an error about the account being locked out.
Maybe they hung and were still running?
You can click on the extras-menu and choose the menu entry to view the log, then notepad will open a log file from the task planner
I found this page helpful when I was trying to trouble-shoot a misbehaving Scheduled Task:
http://support.microsoft.com/kb/308558
Select View->Details to show the additional information, like Last Run Time, and Status, and this page gave me the meaning of the status/error code:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx
I discovered a similar issue February 23 2023 but my logs reveal it started mid January 2023.
My tasks had been working for many months without issue. The I began seeing the same error: The system cannot find the file specified. After all day testing and searching I found that a Windows update on Jan 10 2023 changed the way white space is handled. Formerly only needed one set of quotes. The command line help explains:
C:\> schtasks /create /?
==> Spaces in file paths can be used by using two sets of quotes, one
set for CMD.EXE and one for SchTasks.exe. The outer quotes for CMD
need to be double quotes; the inner quotes can be single quotes or
escaped double quotes:
SCHTASKS /Create
/tr "'c:\program files\internet explorer\iexplorer.exe' \"c:\log data\today.xml\""

Resources