Share via


Schtasks Syntax Hidden

Question

Saturday, December 16, 2017 1:58 AM

Hi,
when opening the task scheduler for creating a scheduled task, I can chose a option called hidden.
If using command prompt though, I easily can create a task, f.e.

"SchTasks /Create /SC DAILY /TN “My Task” /TR “C:RunMe.bat” /ST 09:00" ,

but I do not get how to achieve to get it run in a hidden way, I checked https://technet.microsoft.com/en-us/library/bb490996.aspx and searched for results on different sites, but there does not seem to be a solution.

Is there a way to achieve this or is it impossible?

All replies (6)

Monday, December 18, 2017 8:41 AM ✅Answered

Hi,

I try to use tool to catch the registry of hidden, but there is no changed registry key for hidden according to my test. According to my search, there is not any official article about hidden task scheduler with command line. 

As the workaround, we could export the task scheduler as .xml file and modify the hidden to true like this:     <Hidden>true</Hidden>

Then import the .xml file to task scheduler. Or we need to change it manually through GUI.

Bests,

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Monday, December 18, 2017 10:58 PM ✅Answered | 2 votes

And here is basically the script I used, not a really nice solution but gets the job done.

@echo off

::Execute path to bat path
cd %~dp0

::Create Task (not hidden)
SchTasks /Create /SC DAILY /TN "MyTaskname" /TR "%~dp0\MyBatch.bat" /ST 00:00

::Export xml
SchTasks /Query /XML /TN "MyTaskname" > "MyTaskname.xml"

::Edit xml
powershell -Command "(gc MyTaskname.xml) -replace '<Settings>', '<Settings> <Hidden>true</Hidden>' | Out-File MyTaskname.xml"

::Delete Task
schtasks /delete /tn "MyTaskname" /f

::Import xml
schtasks /Create /XML "MyTaskname.xml"  /TN "MyTaskname"

::Delete xml
del "MyTaskname.xml"

Sunday, December 17, 2017 9:08 PM

In Task Scheduler if I right click Microsoft and New Task.. there is a Hidden option on the first page, does that do what you want?


Monday, December 18, 2017 12:47 AM

Sorry, not really.

I know that option hidden, my problem is basically that I would like to create a task in the task scheduler with out opening it by using command prompt.

This can be in general done by using "schtasks" and furter attributes, but the task is visible, microsoft technet article does not show any attribute for the hidden option.

Thats why I try to find a way to get this solved. 


Monday, December 18, 2017 8:20 PM

That is actually my plan b I thought about, but I need to achieve this .xml edit by using batch / powershell, which means that I need to afford some time to get this done due I am not that fit especially in Powershell.
But if there is no suffix for schtasks I afraid there is no different way, thank you for clarifying this.


Tuesday, December 19, 2017 1:31 AM

Hi,

Thank you for your sharing.
I think it would be very useful for other customers. If it is convenient for you, please mark any useful reply as an answer.
Bests,

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].