Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a Yes parameter to overwrite a schedule from command line in vb.net

I'm developing and application and I'm creating scheduled tasks from command line using vb.net.

When I'm trying to create an existing schedule the command line window come asking if we want to overwrite the existing schedule tasks, My question is:

How Can I send automatically that parameter if I ask it using a message box, if the user answer yes, it will replace automatically the schedule task.

This is how I'm doing that:

Dim KeyToSend as string = " /Create /SC MONTHLY /D 11 /TN "SFTP_FILE_Javier" /TR "\"C:\Users\salasfri\Documents\Visual Studio 2012\Projects\prjFileTrans20151102\prjFileTrans\prjFileTrans\bin\Debug\prjFileTrans.exe\" SFTP_FILE" /ST 16:44"
taskProcess.StartInfo = New ProcessStartInfo(Environment.SystemDirectory + "\SchTasks.exe", KeyToSend)
taskProcess.Start()      

When the line come to the line taskProcess.Start() the command prompt windows appear asking if we want to replace the schedule task and we have to input Y/N depending if we want to do it.

I want to do that automatically

I tried with using taskProcess.StartInfo.Arguments = "Y" but it didn't work

any idea?

Thanks

like image 215
Javier Salas Avatar asked Nov 11 '15 23:11

Javier Salas


2 Answers

You may use schtasks.exe /Query to check if the task already exist and then /F flag to force delete / replace without warnings.

Reference

like image 60
jack3694078 Avatar answered Oct 01 '22 11:10

jack3694078


Declare a boolean as False , then use if statement

Dim  Value as Boolean = false
if (condition)  
      value = true
 else
      value = false
End if 
if (value = true)
'' start you application 

i think you are searching for this .

like image 37
TOM Avatar answered Oct 01 '22 11:10

TOM