How to set a script to set schedule tasks?
-
mercredi 15 février 2012 14:41
I would like to set schedule tasks under Window XP SP3 for following conditions, which scripts could be coded under PowerShell or Batch file.
Run C:\Program\terminal.exe at 9 am on every weekday
Run C:\Program\terminal.exe at 2:15 pm on every weekday
Does anyone have any suggestions?
Thanks in advance for any suggestions
Thanks in advance for any suggestions
Toutes les réponses
-
mercredi 15 février 2012 14:47
BR
MadsPlease remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
-
mercredi 15 février 2012 15:03
If you prefer using batch files you can also call schtasks.exe. More information can be found here:
http://technet.microsoft.com/en-us/library/cc725744(v=ws.10).aspx
This would create the two jobs you gave as an example:
schtasks /create /tn "Terminal 9am" /tr c:\program\terminal.exe /sc daily /st 09:00:00 /d MON,TUE,WED,THU,FRI schtasks /create /tn "Terminal 2.15pm" /tr c:\program\terminal.exe /sc daily /st 14:15:00 /d MON,TUE,WED,THU,FRI
- Proposé comme réponse BigteddyMicrosoft Community Contributor mercredi 15 février 2012 15:07
- Marqué comme réponse oem7110 mercredi 15 février 2012 23:15
-
mercredi 15 février 2012 15:07
WMI would work as suggested by Mads. You could also look at using the native command-line tools as well:
AT
SchtasksI would've posted links but copy/paste isn't working for me at the moment. Just google "at technet", "at scheduled tasks", "schtasks" to get the msdn/technet/microsoft articles describing their usage.
-
mercredi 15 février 2012 15:24
I find following coding, but get no idea on how to modify and apply it for my case.
Do you have any suggestions?
Thanks you very much for any suggestions
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objNewJob = objWMIService.Get("Win32_ScheduledJob") errJobCreated = objNewJob.Create _ ("Cleanup.exe", "********123000.000000-420", _ True , 1 OR 4 OR 16, , , JobID) Wscript.Echo errJobCreated
The preceding script schedules a hypothetical program named Cleanup.exe to run at 12:30 PM every Monday, Wednesday, and Friday.
Thanks in advance for any suggestions
- Modifié oem7110 mercredi 15 février 2012 15:24
-
mercredi 15 février 2012 15:25
Similarly, you can use the AT command in Powershell, which has the advantage of being able to set a task on a remote machine. To set this task on multiple machines, you could use a script like this:
foreach ($computer in (Get-Content $computers)) { at \\$computer 9:00 /every:M`,T`,W`,Th`,F C:\Program\terminal.exe at \\$computer 14:15 /every:M`,T`,W`,Th`,F C:\Program\terminal.exe }Grant Ward, a.k.a. Bigteddy
-
mercredi 15 février 2012 15:41
I get following error, when I run it on my computer, if I would like to set this task only on my local machines, do you have any suggestions on how to modify the code?
Thanks everyone very much for any suggestions

Thanks in advance for any suggestions
-
mercredi 15 février 2012 15:51
Just like this:
at \\$computer 9:00 /every:M`,T`,W`,Th`,F C:\Program\terminal.exe
at \\$computer 14:15 /every:M`,T`,W`,Th`,F C:\Program\terminal.exe
Grant Ward, a.k.a. Bigteddy
-
mercredi 15 février 2012 16:11
When I run it, it requires to activate schedule service first, do you have any suggestions?
Furthermore, when there is space on path, do I need to apply quote shown as following?
Does anyone have any suggestions?
Thanks everyone very much for any suggestions
at \\$computer 9:00 /every:M`,T`,W`,Th`,F "C:\Program\My Folder\terminal.exe"
at \\$computer 14:15 /every:M`,T`,W`,Th`,F "C:\Program\My Folder\terminal.exe"
Thanks in advance for any suggestions
-
mercredi 15 février 2012 16:15Modérateur
Hi,
It seems you are really asking questions about how to schedule tasks?
I would suggest you first learn how to schedule a task on one computer. Once that is working, you can then expand that knowledge to make it work on multiple computers.
Bill
-
mercredi 15 février 2012 16:23
Use this code. No, do not put the program path in quotes.
$computer = 'localhost' net start "Task Scheduler" at \\$computer 9:00 /every:M`,T`,W`,Th`,F C:\Program\My Folder\terminal.exe
at \\$computer 14:15 /every:M`,T`,W`,Th`,F C:\Program\My Folder\terminal.exe
Grant Ward, a.k.a. Bigteddy
What's new in Powershell 3.0 (Technet Wiki)
- Modifié BigteddyMicrosoft Community Contributor mercredi 15 février 2012 16:24
-
mercredi 15 février 2012 16:29
I get following massages,
Already Start required service
Detailed option, please input NET HELPMSG 2182.
The value within option is not correct.
AT command ....
Do you have any suggestions on this error?
Thanks everyone very much for any suggestions
Thanks in advance for any suggestions
- Modifié oem7110 mercredi 15 février 2012 16:29
-
mercredi 15 février 2012 16:33Modérateur
Hi,
Please ask about it in a general Windows forum.
Bill
-
mercredi 15 février 2012 16:37
Will it be a script question? a long time ago, I have tried asked some script question about window on Windows forum before, but they redirect me to ask any related script question on this forum.
Do you have any suggestions?
Thanks everyone very much for any suggestions
Thanks in advance for any suggestions
-
mercredi 15 février 2012 16:38I agree with Bill. If you are not going to run this against multiple machines, then why script it at all? A task only has to be created once. You could have created your scheduled tasks 10 times over in the time you've taken on this question.
Grant Ward, a.k.a. Bigteddy
-
mercredi 15 février 2012 16:41
Because I need to restore my window very often, so everytime, after I restore my window, and need to reset schedule again and again. This script will help me a lot for this managing task.
Does anyone have any suggestions?
Thanks everyone very much for any suggestions
Thanks in advance for any suggestions
-
mercredi 15 février 2012 16:48What isn't working for you right now, AT and Schtasks seem to be perfect for what you require. Can you explain where you are stuck now?
-
mercredi 15 février 2012 16:54
The simplest would be the batch file option. Take either JBrasser's code or this, and stick it in a batch file.
net start "Task Scheduler" at \\localhost 9:00 /every:M,T,W,Th,F C:\Program\My Folder\terminal.exe at \\localhost 14:15 /every:M,T,W,Th,F C:\Program\My Folder\terminal.exe
Grant Ward, a.k.a. Bigteddy
What's new in Powershell 3.0 (Technet Wiki)
- Modifié BigteddyMicrosoft Community Contributor mercredi 15 février 2012 16:55
-
mercredi 15 février 2012 17:03
Please see following image for detailed error on each step.
Does the code miss the name for this scheduled task? when I manually set a schedule task, I need to give a name for this task, but I see no name for following task.
Does anyone have any suggestions?
Thanks everyone very much for any suggestions
net start "Task Scheduler"
at \\localhost 9:00 /every:M,T,W,Th,F C:\Program\My Folder\terminal.exe
at \\localhost 14:15 /every:M,T,W,Th,F C:\Program\My Folder\terminal.exe
Thanks in advance for any suggestions
-
mercredi 15 février 2012 17:12
The AT command doesn't take a name parameter, it just called the tasks At1, At2, etc. That is a disadvantage of this method. I'm not sure about shchtasks.
You keep asking for suggestions, and my suggestion remains that you use a batch file, not Powershell.
Grant Ward, a.k.a. Bigteddy
-
mercredi 15 février 2012 17:18
I run it on batch file, it seems to me that Task Scheduler cannot start under batch file.
Do you have any suggestions?
Thanks everyone very much for any suggestions
net start "Task Scheduler" at \\localhost 9:00 /every:M,T,W,Th,F C:\Program\My Folder\terminal.exe at \\localhost 14:15 /every:M,T,W,Th,F C:\Program\My Folder\terminal.exe

Thanks in advance for any suggestions
-
mercredi 15 février 2012 17:20Run with elevated priveliges (as Administrator).
Grant Ward, a.k.a. Bigteddy
-
mercredi 15 février 2012 17:26
I am assigned as Administrator.
Do you have any suggestions?
Thanks everyone very much for any suggestions

Thanks in advance for any suggestions
-
mercredi 15 février 2012 17:48Modérateur
Hi,
Also:
at \\localhost 9:00 /every:M,T,W,Th,F C:\Program\My Folder\terminal.exe
This command won't work because the program to excute contains spaces in its name and it is not enclosed in quotes. It should be
at \\localhost 9:00 /every:M,T,W,Th,F "C:\Program\My Folder\terminal.exe"
Bill
- Proposé comme réponse BigteddyMicrosoft Community Contributor mercredi 15 février 2012 18:57
-
mercredi 15 février 2012 22:24
I try it, but still get the same error as shown from above testing.
Something is wrong with "/EVERY:m,t,w,th,f", when I remove it, it works.
Working sample
at \\localhost 9:00 /every:1 "C:\Program\My Folder\terminal.exe"
Not working sample
at \\localhost 9:00 /every:M,T,W,Th,F "C:\Program\My Folder\terminal.exe"
Does anyone have any suggestions?
Thanks everyone very much for any suggestions
Thanks in advance for any suggestions
-
mercredi 15 février 2012 22:26Modérateur
Hi,
I can't read your language, sorry. You will need to ask your question in a Windows support forum in your language.
Bill
-
mercredi 15 février 2012 22:40
Hi,
I can't read your language, sorry. You will need to ask your question in a Windows support forum in your language.
Bill
Since I am so good at cyphers I was able to decode the message:
C:\Program Files\Windows Resource Kits\Tools>net helpmsg 2182
The requested service has already been started.
EXPLANATION
You tried to start a service that is already running.
ACTION
To display a list of active services, type:
NET START
Bill's previous message is the reason for the other errors.
'at' cannot schdule certain things because it runs at too low a privilege level.
¯\_(ツ)_/¯
- Modifié jrvMicrosoft Community Contributor mercredi 15 février 2012 22:42
-
mercredi 15 février 2012 22:49
Also th eformat is wromin two other respects.
This:
at \\localhost 9:00 /every:M,T,W,Th,F "C:\Program\My Folder\terminal.exe"Should be:
at 9:00 /every:"M,T,W,Th,F" "C:\Program\My Folder\terminal.exe"
1. you cannot use \\localhost this only works with remote machines
2. You must quote out the M,T,W, string because commas ae delimiters on the copmmand line just like spaces. Thsy need quotes.Most programs will not run under the AT scheduler. You should use SchTasks to run this. (JBrasser post above)
This has nothing to do with scripting. It is about basic WIndows operations and should be posted in teh Windows new users forum for XP.
¯\_(ツ)_/¯
-
mercredi 15 février 2012 23:12
schtasks /create /tn "Terminal 9am" /tr c:\program\terminal.exe /sc weekly /st 09:00:00 /d MON,TUE,WED,THU,FRI
It works now.
Thanks everyone very much for suggestions
Thanks in advance for any suggestions
- Modifié oem7110 mercredi 15 février 2012 23:13
-
jeudi 16 février 2012 23:20
schtasks /create /tn "Terminal 9am" /tr "c:\program\My Folder\terminal.exe" /sc weekly /st 09:00:00 /d MON,TUE,WED,THU,FRI
When I run above script, it works on creating schedule task, but this task cannot be run, because of missing quote of the path, which show c:\program\My Folder\terminal.exe only without quote.
Does anyone have any suggestions on how to add quote on above coding? so it would create the path and display
"c:\program\My Folder\terminal.exe" instead of c:\program\My Folder\terminal.exe within the path of schedule task.
Thanks everyone very much for any suggestions
Thanks in advance for any suggestions
-
jeudi 16 février 2012 23:28
Changeschtasks /create /tn "Terminal 9am" /tr "c:\program\My Folder\terminal.exe" /sc weekly /st 09:00:00 /d MON,TUE,WED,THU,FRI
"c:\program\My Folder\terminal.exe"
to
""""c:\program\My Folder\terminal.exe"""" -
jeudi 16 février 2012 23:42
In a dos command line with SchTasks yu need to escape the quotes.
Here is how:
/tr "\"c:\program\My Folder\terminal.exe\""
Notice the extra \". Thisis the escaped quote that will be kept in the string when it is used. It results in a quotes string. Be sure that yu also have both outer quotes.
quote slash quote --------- slash quote quote
¯\_(ツ)_/¯
- Marqué comme réponse oem7110 vendredi 17 février 2012 01:55
-
vendredi 17 février 2012 01:56Thanks everyone very much for suggestions
Thanks in advance for any suggestions
-
vendredi 17 février 2012 06:54
"DOS command"? I thought that we saw the last of DOS with WinME? Or do you refer to every black command console as "DOS", including those included with Unix? ;-)In a dos command line with SchTasks yu need to escape the quotes.
-
vendredi 17 février 2012 07:37
"DOS command"? I thought that we saw the last of DOS with WinME? Or do you refer to every black command console as "DOS", including those included with Unix? ;-)
If I remember correctly, DOS didn't have FOR. I'm not sure that much else has changed from DOS to cmd.exe.Grant Ward, a.k.a. Bigteddy
-
vendredi 17 février 2012 07:40
I also think cmd.exe needs a better name. That's probably why jv called it DOS. What do you call it?
Batch? Well, that's not very specific, batch is a generic term for a set of commands.
Command? Ditto.
Grant Ward, a.k.a. Bigteddy
-
vendredi 17 février 2012 09:25
I also think cmd.exe needs a better name. That's probably why jv called it DOS. What do you call it?
Batch? Well, that's not very specific, batch is a generic term for a set of commands.
Command? Ditto.
Grant Ward, a.k.a. Bigteddy
"cmd.exe" is usually referred to as the "Command Processor" because it processes commands in a console environment.
Batch files, as you suggest, started off as a collection of console commands such as copy, cd, del. Over the various versions of DOS and Windows they acquired a limited degree of intelligence and flexibility such as the "for" command or the ability to accept user input. Because most of these add-ons were not initially planned, batch files lack elegance and robustness. They are highly effective for simple tasks and about as graceful as a wart hog.
- Modifié OberwaldMicrosoft Community Contributor vendredi 17 février 2012 10:05
-
vendredi 17 février 2012 12:44Who remembers NDOS? Norton DOS. This was a replacement/shell that ran on top of DOS, but replaced command.exe. It gave one a great deal more "intelligence" as you call it. If I remember correctly, you could solicit user input and all sort of things, that the DOS of the day lacked.
Grant Ward, a.k.a. Bigteddy
-
vendredi 17 février 2012 14:26
"DOS command"? I thought that we saw the last of DOS with WinME? Or do you refer to every black command console as "DOS", including those included with Unix? ;-)In a dos command line with SchTasks yu need to escape the quotes.
Shh! I was trying to be nice.
¯\_(ツ)_/¯
-
vendredi 17 février 2012 14:29
I also think cmd.exe needs a better name. That's probably why jv called it DOS. What do you call it?
Batch? Well, that's not very specific, batch is a generic term for a set of commands.
Command? Ditto.
Grant Ward, a.k.a. Bigteddy
'Command shell', CLI, "The Original Legacy App".
Ther eis not good name.
It has traditionally been called teh 'Console' but now we have Powershell whcich can be called a console. It i sgood tehat PowerSHell actually has a name.
Ar least in Unix we have names for all of the shells.
¯\_(ツ)_/¯
-
vendredi 17 février 2012 14:33
Who remembers NDOS? Norton DOS. This was a replacement/shell that ran on top of DOS, but replaced command.exe. It gave one a great deal more "intelligence" as you call it. If I remember correctly, you could solicit user input and all sort of things, that the DOS of the day lacked.
Grant Ward, a.k.a. Bigteddy
4DOS, DoubleDos, DOS-TO-GO,
We have had them all.
ALl of those DOS switchers that synthsized multitasking.
What about the biggest DOS of them all - OS2.
Remember. Install OS2 from 30+ disks. NOw install Windows 1.0 into OS2 so you have a GUI.
OS2 was just multitasking DOS hosting a copy of Windows.
¯\_(ツ)_/¯
-
vendredi 17 février 2012 14:42
Look at me, calling it command.exe! It was called command.com, and I should remember, I've seen enough missing Command.com problems. How time flies.
Grant Ward, a.k.a. Bigteddy
What's new in Powershell 3.0 (Technet Wiki)
Edit: Do .com files still run in Windows?
- Modifié BigteddyMicrosoft Community Contributor vendredi 17 février 2012 14:43
-
vendredi 17 février 2012 15:14Modérateur
NDOS was modified version of 4DOS, which was a replacement for command.com on MS-DOS/Windows 9x. I believe 4DOS is now available for free.
Maybe I'm a bit pedantic, but it bothers me when the cmd.exe command window gets called "DOS". DOS was an operating system, not a command shell. The term "batch file" is a bit antiquated also; I prefer "shell script" (a more accurate description). Just my $0.02.
Bill
-
vendredi 17 février 2012 15:24
You see, that's my point: It lacks a name. It's not "Powershell" script, it's " shell" script.I prefer "shell script" (a more accurate description). Just my $0.02.
Bill
Grant Ward, a.k.a. Bigteddy
What's new in Powershell 3.0 (Technet Wiki)
Edit: I'd fill the blanks in with "Command". Hence "CommandShell script".
- Modifié BigteddyMicrosoft Community Contributor vendredi 17 février 2012 15:26
-
vendredi 17 février 2012 15:49
You see, that's my point: It lacks a name. It's not "Powershell" script, it's " shell" script.I prefer "shell script" (a more accurate description). Just my $0.02.
Bill
Grant Ward, a.k.a. Bigteddy
What's new in Powershell 3.0 (Technet Wiki)
Edit: I'd fill the blanks in with "Command". Hence "CommandShell script".
Yes - PowerShell can also be easily called a 'shell' as well as 'console' or CLI.
DOS has always been understood by all as incorrect as it may be.
It desiplay by default as 'COmmand Shell' but now that can be eaily applied to PowerShell.
MS support and others always say 'go to a command prompt'. Today I would end up ata PowerSHell prompt if that is asked of me.
The shell in NT3.1 through W2K dispalyed on the desktop as a DOS icon.
Command.com stillexisits on WS2003 and is tagged in the system as MS-DOS Aplication even though it just launches CMD.EXE.
I am in favor of calling a DOS a DOS.
Or .. "A DOS by any other name..."
Or ... "If it looks like a DOS and it quacks like a DOS it must be..."
¯\_(ツ)_/¯

