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

2

8

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

Sowers answered 11/11, 2015 at 23:48 Comment(0)
S
16

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

Reference

Seymourseys answered 12/11, 2015 at 1:31 Comment(0)
R
1

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 .

Request answered 12/11, 2015 at 11:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.