How to Automate Command Line taskkill without admin rights? - batch-file

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"

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)

Using Task Scheduler to run a batch file that contains the start /w command

I have a Windows XP virtual machine that I am using to run a legacy app. I am using a limited user account.
I have created a batch file that I'd like to:
Start the legacy app
Wait for the program in step 1 to close
Shut down the computer
So this is the code I am using (in this example, I am attempting to open notepad):
#ECHO OFF
start /w notepad
%windir%\system32\shutdown.exe -f -s -t 1
Because the legacy app needs to be run under an account with administrator privileges, I then manually created a scheduled task in Task Scheduler to run the batch file. The scheduled task is set to run using an account named Admin that has administrator privileges.
I am having a bit of an issue. When the scheduled task runs, nothing appears on the screen. However, I did notice that both cmd.exe and notepad.exe appear in Task Manager as processes running as the user Admin.
What am I doing wrong? How can I accomplish what I'd like to do? Thanks!
Sorry all, it was an issue with me not having Task Scheduler set up properly. I found this post which suggests to use the AT command to run the task interactively. This allows the Cmd window to be displayed when a batch file is run as a Scheduled Task.

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/

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.

Enable schedule task using a 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"

Resources