I want to write a Windows script (running in Windows 7) that runs every time when a new files has been created in a specified folder. It then checks weather the newly created file matches a certain naming convention and if so it moves it to a different folder.
How can I do the above?
If it doesn't have to be immediately after the files are created, then maybe simple task, checking the folder with interval and using robocopy to move the files will suffice? This can be accomplished with Task Scheduler:
schtasks /create /sc minute /mo 3 /tn FileCopy /tr ROBOCOPY C:\source_folder c:\destination_folder some_file_name*.* /MOV
/sc - Specifies the schedule frequency
/mo - Refines the schedule type to allow finer control over schedule recurrence. In this case it just specifies how many minutes until the task is run again
/tn - Name for the task that will be visible in task scheduler
/tr - Task to be executed /rl
You can also append /rl HIGHEST if you need more privileges to complete the task, and /ru SYSTEM to execute as SYSTEM user (you'll need admin privilege for that), so there won't be any console windows popping out every time tasks executes.
Related
I'm writing an updater for my application and want to change my "Windows Task Scheduler" task configured by:
schtasks /create /sc once /tn my_task /tr MyApp.exe /rl highest /st 00:00
The updater is running "with highest privileges" and I mainly want to change the path of MyApp.exe.
I've tried:
schtasks /Change /tn my_task /tr MyUpdatedApp.exe (But it asks: Please enter the run as password for... even though the script already runs as admin. And so is not user friendly or even working in my scripted update.)
A powershell script using Get-/Set-ScheduledJob (But it says: A scheduled job definition with Name my_task could not be found. The help text even states Although jobs that are created by using the Register-ScheduledJob cmdlet appear in Task Scheduler, Get-ScheduledJob gets only scheduled jobs. It does not get scheduled tasks created in Task Scheduler.)
How can I updated my scheduled task from my updater/script without user interaction?
I've resorted to exporting and recreating the task using an XML file with the following command:
schtasks /create /f /tn my_task /xml C:\somewhere\my_task.xml
I create the my_task.xml file by exporting it by hand in the GUI and storing it as part of my application.
I have a .vbs file which I execute using cscript. Now that the script is sable; I want to run in background all the time.
Hence, I want this .vbs file to run as a service.
How do I create (install) it?
Scripts are usually not prepared to run as a service (they don't provide the interfaces required for managing the service). You're probably better off creating a scheduled task that launches your script at system boot (or at logon).
schtasks /create /sc onstart /tn "name" /tr "cscript.exe C:\path\to\your.vbs" /ru SYSTEM
I am trying to become familliar with add task to task scheduler via the command prompt. I seem to be having difficuly with spaces.
This command works successfully in creating a task:
schtasks /create /tn \Daily\SOTask /tr "C:\Users\User Name\FolerWhereScriptIs\vbsScript.vbs" /sc daily /mo 1 /st 08:50
SUCCESS: The scheduled task "\Daily\SOTask" has successfully been created.
However, when I open the properties of this task in task scheduler i see in:
Program/script: C:\Users\User
Add arguments(optional): Name\FolerWhereScriptIs\vbsScript.vbs
Start in(optional): empty
this is obviously not what I want. ideally I would like:
Program/script: C:\Windows\System32\WScript.exe
Add arguments(optional): "C:\Users\User Name\FolerWhereScriptIs\vbsScript.vbs"
Start in(optional): C:\Users\User Name\FolerWhereScriptIs\
How do I achive this from the command line?
This lists all tasks in the Daily folder (so I can see the one I jst created)
schtasks /query /TN Daily\
NOTE: To get this far I ahve gotten help for here and here
EDIT1 I found help here and it mentions using a /V1 flag but todate I cannot get to work. Another Option would be to use XML, whcih I will investigate again. For now I will use the command for setting up my schedule and then go into task scheduler to set the Start in(optional): in directory.
This command should create a task that every minute runs the calculator windows application.
schtasks /Create /tn "mytask" /sc MINUTE /mo 1 /ru "myuser" /rp "mypassword" /tr "C:\Windows\System32\calc.exe"
It runs OK, the tasks gets added. The task looks right. The tasks shows as started in the schedular but the calculator does not get fired up. The exe exists, I can run it separately.
Anyone know why I don't see the calculator?
How to Create, Modify and Delete Scheduled Tasks from the Command Line
Windows XP/Server 2003 introduced us to the SchTasks command line tool which usurped the At tool offered in Windows 2000. This tool offers the ability to control every aspect of your Scheduled Tasks through calls to this command.
While the wizard Windows uses to help you graphically create Scheduled Tasks is very good, the command line tool is ideal for situations such as:
Manipulate tasks in batch scripts.
Control and create tasks on networked machines without having to login to them.
Mass create/sync task across multiple machines.
Use in custom applications to communicate with the Task Scheduler instead of having to make API calls.
Eg:
Create ‘My Task’ to run C:RunMe.bat at 9 AM everyday:
SchTasks /Create /SC DAILY /TN “My Task” /TR “C:RunMe.bat” /ST 09:00
Modify ‘My Task’ to run at 2 PM:
SchTasks /Change /TN “My Task” /ST 14:00
Create ‘My Task’ to run C:RunMe.bat on the first of every month:
SchTasks /Create /SC MONTHLY /D 1 /TN “My Task” /TR “C:RunMe.bat” /ST 14:00
Create ‘My Task’ to run C:RunMe.bat every weekday at 2 PM:
SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN “My Task” /TR “C:RunMe.bat” /ST 14:00
Delete the task named ‘My Task’:
SchTasks /Delete /TN “My Task”
Probably because the task isn't running interactively. Add the '/it' option:
/IT
A value that enables the task to run interactively only if the
/RU user is currently logged on at the time the task runs. The task
runs only if the user is logged on.
Without the /it option, tasks run in session 0, which doesn't allow interaction with the user. For more information, do a web search for "Session 0 isolation".
I've been trying to create a scheduled task from the command prompt. The task is created, but it runs hidden. Is there any way of running it in a non-hidden way? The process is very long and I would like to see what is going on...
I'm running it on a Vista, but the task is meant to run on pre-vista OS as well...
SCHTASKS /Create /RU \"NT AUTHORITY\SYSTEM\" /SC DAILY /ST 00:00 /TN Backup /TR \"C:\Sis\Backup\Backup.vbs\" /F /V1
Tks,
Filipe Scur
Running as NT AUTHORITY\SYSTEM means it is a system task and will run hidden.
Try run as a different username.