Enable schedule task using a batch file - batch-file

I need to enable a schedule task through a batch file, this schedule task is set to run every 2 mins once enabled.
Using SCHTASKS /Run -- run the task but only once it does not care about the schedule i.e to run every 2 mins
I need to do this through a batch file. I am using Windows 2003 server.
Please guide.

schtasks /change /tn "TaskNameGoesHere" /ENABLE

You can do it in Batch. You can use schtasks /? or visit http://ss64.com/nt/schtasks.html. You can get very granular with your options and there are many switches available to use. Customize to your heart's desires.

You can do this by at command
Example:
at 10AM every:SU "C:\Program Files\VideoLAN\VLC\vlc.exe"

Related

service to perform scheduled task operation

Is it possible to create a Windows Scheduled Task from a Windows batch file with another batchfile as a parameter:
For eg : schtasks.exe /create /tn "taskName" /tr "%Home%\bin\bootstrap.cmd" /sc DAILY /st 00:01:00 /ri 1 /du 0023:59 %schTaskAccountArgs%"
Background
The batch file 'bootstrap.cmd' in the script above has calls to other batchfiles and eventually an exe. It creates a scheduled task in the Microsoft console which triggers the same exe, but in my case due to a GPO policy, the scheduled task couldn't be created (policy being-not able to store passwords for the user that runs the scheduled job). As a workaround I want to create a service in the same Batch file by replacing the above by:
sc create "service for taskName" start= demand displayname= "service for taskName" binpath= "%Home%\bin\bootstrap.cmd"
is it a feasible method to create a service for this scenario.
Windows appears to not run .bat (and .cmd) files as services.
Here are some alternatives:
Create a scheduled task that runs at
startup.
Convert the .cmd into an executable. See How can a .bat
file be 'converted' to .exe without third party tools?
Use external tools (like NSSM featured here)

How to Automate Command Line taskkill without admin rights?

Tricky question but here's the thing.
I'm at work with a heinous security tool that blocks pretty much any ability to do anything.
I DO have permission to run /taskkill /F /IM someprocess.exe on the command line normally.
I want to do this daily because a certain software program --- only one person can access it at a time --- we work in different time zones. I usually close it every day manually, but there are misses. So I want to automate a task that kills it every night.
Here's the thing. ALL .bat files are blocked from running.
So my typical thought --- use Windows Task Scheduler to run a .bat file --- doesn't work.
So how else can I daily run this 'command line' command automatically? Is there no way? I do have access to do it manually of course (via command line directly). I can also do the regular end-task on windows task manager. I even have local admin rights of some sort (initially given so I stop pestering them with installs every week that require IT approval). But those can't seem to get around the .bat thing or 'highest privileges' in Windows Task Scheduler.
Another question --- I never log out of my computer, but the computer of course 'locks' nightly. The script would need to run while the computer is logged on to my account, but locked, nightly.
The easiest way is to go to IT, which I will do, but ... permissions every time I need to run a .bat file? There has to be a better way ... Also I'm not so sure if they will take a week to approve each time ...
taskkill /im process /f
Just schedule this command.
There is absolutely no need for CMD.exe or a bat file.
You can schedule for your own user account by ticking run only when user logged in.
To schedule
SCHTASKS /Create /SC DAILY /it /TN taskkill /TR "Taskkill /f /im program.exe"

Batch file and task schedule

I need to modify a job/task on different computers that I created as a task schedule. I created a batch file to do it (please see below). It uses that administrator account to run the job. The task is modified, but the task doesn't run because I can't set it to run whether the user is logged on or not. How can I set the job to run whether the user is logged on or not? I don't know how to add this code to the batch file. Please help.
{SchTasks /Create /TN MyWeeklyReboot /TR "C:\WINDOWS\RebootMyself.vbs" /ST 13:30 /SD 12/23/2014 /SC Weekly /D TUE /ru %computername%\Administrator }
Scheduled tasks will run regardless of whether or not the user is logged on.
If you add the /it option, the task will only run if the user the task runs under is logged on.
Source: http://technet.microsoft.com/en-us/library/cc772785(v=ws.10).aspx/

How to run a command or batch file on another computer without using remote connection?

I have a test that aimed to change my screen resolution, when the problem is that the test runs on setup X and my laptop is setup Y.
When using remote connection, my test fails as it is recognizing the "remote" and resolution changes must be done on the setup itself
Is there a way to run it on the computer without remote connection?
Thanks!
wmic /node:127.0.0.1 process call create "c:\windows\notepad.exe"
[Note remote programs run invisible]
another way as a comment noted is Scheduled Tasks.
SCHTASKS /Create /S ABC /U user /P password /RU runasuser /RP runaspassword /SC WEEKLY /TN report /TR notepad.exe
then
schtasks /run /tn report

Program to determine whether a Scheduled Task is running or not in .bat file?

I have 2 scheduled task say ABC and PQR,i want that if the scheduled task ABC is running then i want to stop it and run the scheduled Task PQR.
if ABC is stopped then just run the PQR.
to check if a task is running:
schtasks /query /TN ABC
if %errorlevel%==0 echo ABC is running
to delete the scheduled task use
schtasks /delete /TN ABC
(maybe, you need an additional /F (Force))
to create a scheduled task you need some parameters. See schtasks /create /?.
If you have any more problems, please come back with the needed parameters and your "best try code"

Resources