1

I've created a scheduled task using the example in this question, but don't seem to be able to end it now. Getting the "Syntax error" when I run the following code found here

schtasks /delete /tn * /f

I also tried

schtasks /delete /tn "Execute Notepad by Hackoo" /f

I don't have admin rights and am wondering if that's why I can't delete the task.

Please let me know if you can help me stop Notepad from opening every minute.

Thanks!

ln29st
  • 83
  • 2
  • 11
  • "I don't have admin rights (probably for a reason)" - why don't you have local admin rights on your own machine? And what "reason" are you referring to? – Dai Jan 09 '20 at 23:18
  • Our company has very strict security policies, so only IT people have admin rights. I'm not one of them. Is there a way to delete the task by running .vbs? – ln29st Jan 09 '20 at 23:21
  • No, there isn't - otherwise anyone could get around not having admin-rights by running a script. – Dai Jan 09 '20 at 23:27
  • Thanks for your response! Why would it be possible to create tasks using vbscript but not delete them? seems illogical – ln29st Jan 09 '20 at 23:29
  • You are not required to be an administrator. If you are allowed to delete a task then you'll be allowed to. You can delete anything you create. Why would the second one work? You have a task with that name? –  Jan 09 '20 at 23:51
  • Actually, I just deleted it using the Command Prompt! I was running it as .vbs before...Schtasks /delete /TN "Execute Notepad by Hackoo" – ln29st Jan 09 '20 at 23:57

3 Answers3

2

EDIT :

Set objShell = Wscript.CreateObject("WScript.Shell")
Taskname="Test Task"
objShell.Run "Schtasks /delete /TN "&""""&Taskname&""""&" /F",0,True

If the code does not work for you,fix your access. See here = Link

So,test the code below :

Set objShell = Wscript.CreateObject("WScript.Shell")
objShell.Run "SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN ""Test Task"" /TR ""C:\CPU.cmd"" /ST 10:10", 0
'==> Check it.
Taskname="Test Task"
objShell.Run "Schtasks /delete /TN "&""""&Taskname&""""
' Or =
'objShell.Run "Schtasks /delete /TN "&""""&Taskname&""""&" /F",0,True
  • See my new changes. –  Jan 14 '20 at 13:25
  • 1
    Thanks, scientist_7! Both ways work. objShell.Run "Schtasks /delete /TN "&""""&Taskname&"""" opens cmd and asks if I'm sure I want to delete the task. objShell.Run "Schtasks /delete /TN "&""""&Taskname&""""&" /F",0,True just deletes it. – ln29st Jan 14 '20 at 15:34
1
schtasks /delete /tn * /f

You'll get a syntax error for this because schtasks.exe does not allow wildcards (*) to be used for the /TN option.

However...

schtasks /delete /tn "Execute Notepad by Hackoo" /f

...this command is valid, but you need elevated/administrative rights to delete a system-registered scheduled task.

This is documented in the help for schtasks /? (emphasis mine):

Enables an administrator to create, delete, query, change, run and end scheduled tasks on a local or remote system.

Dai
  • 141,631
  • 28
  • 261
  • 374
1

For noobs like me... You can delete a task you've created. Go to Command Prompt and run

Schtasks /delete /TN "taskname"

I was trying to run that thru .vbs

ln29st
  • 83
  • 2
  • 11
  • this doesn't work anymore on tasks I've created using vbscript. Getting "access is denied" in Command Prompt. – ln29st Jan 13 '20 at 16:16