Batch file and task schedule - batch-file

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/

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"

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"

Run batch file when startup on Windows Server 2008

I would like to start a powershell script if the Server turns on. No dependency on the user and if a certain user logs out the program should continue working.
I tried an entry in the registry with the HKey_localMachine but my program won't continue working if a user logs off. Maybe there is a solution with the Task Scheduler?
Task scheduler is an option. Maybe run it with system-rights instead of admin
One shot in the dark is to have a scheduled task run a program/cmd.exe/powershell script as system on startup or user logon.
The command for starting on startup should be this:
schtasks /Create /TN taskName /SC onstart /TR powerShellScript.ext /RU system
Where powerShellScript.ext is replaced by whatever your script or other file is.
That should run whatever replaces powerShellScript.ext as system, thus preserving the process even if no users are logged on.
Another option is to launch the script once using a service as soon as it's started, but I don't have experience with that.
This might not work depending on how the file is launched. the most reliable method is to launch an executable and set the launch options to load whatever it is that you actually want.

Problem with schtasks command

This is the command i executed
schtasks /create /SC once /TN note /TR notepad /ST 17:00
WARNING: The Scheduled task "note" has been created, but may not run
because the account information could not be set.
What does that Warning mean.Why its not working?
According to Microsoft's documentation the warning means that its not allowing it to run under the user permissions.
"This warning indicates that the remote domain could not authenticate
the account specified by the /u parameter. In this case, the remote
domain could not authenticate the user account because the local
computer is not a member of a domain that the remote computer domain
trusts. When this occurs, the task job appears in the list of
scheduled tasks, but the task is actually empty and it will not run."
I would try using the user and password params and see if it runs then.

Resources