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)
Related
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"
I have created a batch file startservice.bat to start a windows service and scheduling this batch files using task scheduler on windows server 2012 R2.
startservice.bat
NET START myservice
But after scheduler runs a cmd pop up comes but service is not actually started.
If I run this batch file manually then service starts.
On my 2012 R2 server, I attempted to reproduce the problem you describe. The batch file always starts the service when I run via a scheduled task and I never get a cmd pop up.
Your question did not specify scheduled task settings. You may need to enable the "Run with highest privileges" option on the General tab of your scheduled task.
Your action should call the batch file directly or you can call CMD. Either way, make sure you call the full path of the batch file.
cmd /c C:\startservice.bat
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/
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.
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"