如何从 vb.net 中的命令行发送 Yes 参数以覆盖计划

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33662014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:33:20  来源:igfitidea点击:

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

vb.netcommandargumentslinewindows-task-scheduler

提问by Javier Salas

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

我正在开发和应用程序,我正在使用 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.

当该行到达 taskProcess.Start() 行时,会出现命令提示符窗口,询问我们是否要替换计划任务,我们必须根据是否要执行此操作输入 Y/N。

I want to do that automatically

我想自动做到这一点

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

我尝试使用 taskProcess.StartInfo.Arguments = "Y" 但它没有用

any idea?

任何的想法?

Thanks

谢谢

回答by Hyman3694078

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

您可以使用schtasks.exe /Query检查任务是否已经存在,然后/F标记以强制删除/替换而不发出警告。

Reference

参考

回答by TOM

Declare a boolean as False , then use if statement

将布尔值声明为 False ,然后使用 if 语句

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 .

我想你正在寻找这个。