1. Create windows task scheduler using command prompt -
As per requirement, to create a windows task scheduler which will repeat after every three days.
Task scheduler through command prompt-
- Delete task scheduler, if it already exist -
- Create task scheduler which will repeat after every three days
schtasks /create /tn "TestScheduler" /sc DAILY /MO 3 /tr "\"C:\Windows\Notepad.exe" \"AUTOEXTRACTSCHEDULER\""
tn - Task name
sc - Schedule type
MO - Modifier
tr - Task run
and also we can include an command line argument at last, follow by \"<Argument>".
Check the below links for more detail -
2. Copy and paste required command into notepad file and create a batch file and save it into desktop. (ie. TestScheduler.bat)
3. Include batch file into setup file of window based applicatoin/WPF setup.
Follow the below steps -
- In the setup folder of windows application, right click and select view - [File system]
- Go to application folder and add cmd.exe (C:\Windows\System32\cmd.exe) and also batch file which you have created above(TestScheduler.bat).
- Once file is added to the application folder, again go back to application setup folder then right click and Go to view - [Custom actions]
- Requirement was to Create windows task in scheduler during installation and remove windows task during application un-install. So for that we created two batch file for create and delete task respectively.
- At installation - Under command actions go to commit, right click and add custom action, select cmd.exe file from application folder
- Right click on cmd.exe under commit, select property window -
- Replace /commit by /c "[TARGETDIR]\AutoExtraction.bat" in the argument section.
- Rebuild the solution and create new setup and install the application, windows task should be created under windows task library. In the same manner if you uninstall application then same windows task should be removed from windows task library. To apply the same follow the below steps -