且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Windows上的后台运行命令?

更新时间:2023-11-13 12:03:58

我假设您要执行的命令是一个界面(可能是自动的?)。在Windows上,有许多您要寻找的选项:

I'm assuming what you want to do is run a command without an interface (possibly automatically?). On windows there are a number of options for what you are looking for:


  • ***:将程序编写为Windows服务。当没有人登录服务器时,这些将开始。他们允许您选择用户帐户(可以与您自己的用户帐户不同),并且如果失败,它们将重新启动。它们始终运行,因此您可以在特定时间或在其中定期执行自动化任务。有关如何编写Windows服务的更多信息,您可以在线阅读教程,例如( http://msdn.microsoft.com/en-us/library/zt39148a(v = vs.110).aspx )。

更好:启动命令并隐藏窗口。假设该命令是DOS命令,则可以为此使用VB或C#脚本。有关详情,请参见此处信息。一个示例是:

Better: Start the command and hide the window. Assuming the command is a DOS command you can use a VB or C# script for this. See here for more information. An example is:

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("C:\yourbatch.bat"), 0, True

您仍然必须开始手动命令或编写任务以启动命令。这是该策略最大的失败之一。

You are still going to have to start the command manually or write a task to start the command. This is one of the biggest down falls of this strategy.

希望有帮助!