Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Batch/VBScript : Disable Windows tasks

Hello experts,

I have a window task which is located in more than 20 servers. The name of this task is the same. I am declared as administrator in the various servers.

I was wondering if there is a command in order to disable this task automatically by reporting the name of the windows task and the various servers in which I need to disable it.

If you have questions, please contact me.
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luis Diaz

ASKER

@Bill: By task I refer to a windows task used in the windows scheduler tool.
I am going to check psexec. Thank you very much for this proposal.
@oBdA:

I tested your proposal and it works perfectly! Thank you again for your help!
@oBdA:
Just one remark, how should we revise the script in order to be able to report multiple tasks in the variable
Set taskname?
Example Set Taskname:Task1;Task2;Task3?

Thank you very much for your help.
Avatar of oBdA
oBdA

Tasks containing spaces must be enclosed in double quotes in the list.
@echo off
setlocal
set TaskName="Some Task 1" "Some Task 2"
set ServerList=C:\Temp\servers.txt
for /f %%a in ('type "%ServerList%"') do (
	echo Processing %%a ...
	for %%t in (%TaskName%) do (
		echo   - disabling '%%~t' ...
		ECHO schtasks.exe /change /s %%a /tn "%%~t" /disable
	)
)

Open in new window

Thank you very  much for this proposal!