众所周知,在最新版本的 Windows 中通过 TaskScheduler 启动任务时,如果任务是“无论用户是否登录都运行”,则该任务将不会交互运行 - 即它不会启动 UI。
仅供引用,这是根据Microsoft ,并已在此 SuperUser question 中突出显示还有这个StackOverflow question :
You can specify that a task should run even if the account under which the task is scheduled to run is not logged on when the task is triggered. To do this, select the radio button labeled Run whether user is logged on or not . If this radio button is selected, tasks will not run interactively. To make a task run interactively, select the Run only when user is logged on radio button.
但是,我的问题是由此衍生的。
TaskScheduler 启动的任务是一个 Java 客户端应用程序,它 可以指示运行进程 - 这些进程通过 ProcessBuilder 运行 在客户端应用程序中。因此,这个客户没有问题 应用程序被隐藏/不启动 UI - 事实上,没有 UI。
但是,如果如上所述通过 TaskScheduler 启动客户端应用程序以“无论用户是否登录都运行”,则客户端应用程序中由 ProcessBuilder 启动的任何进程也无法交互运行/无法运行显示用户界面。这是一个问题,因为客户端启动的一些进程是 UI 应用程序。
我不确定为什么会出现这种情况,但实际上我正在尝试找出是否有解决方法 - 例如可以添加一些环境变量或属性来让(不可见)客户端启动可见进程。
有什么想法吗?
最佳答案
因此,我找到的解决方法是停止使用 TaskScheduler,而是创建一个脚本来启动我的应用程序,并在“开始”菜单 >“程序”>“启动”文件夹中添加该脚本的快捷方式。
感谢 HowToGeek 上的这篇文章:
On Windows 7 and earlier versions of Windows, the Start menu contained a “Startup” folder to make this easy.
This folder is no longer as easily accessible on Windows 8, 8.1, and 10, but it’s still accessible. To access it, press Windows Key + R, type “shell:startup” into the Run dialog, and press Enter.
Shortcuts you add to the “shell:startup” folder will only launch when you log in with your user account. If you’d like a shortcut to launch itself whenever any user logs in, type “shell:common startup” into the Run dialog instead.
由于我希望我的应用程序在系统启动时启动,而不是用户登录,因此我使用了“shell:commonstartup”链接。
以这种方式启动的应用程序 - 或者在我的例子中,由以这种方式启动的应用程序启动的应用程序 - 通过其 UI 可见和/或交互。
关于java - 使用 Java ProcessBuilder 从 TaskScheduler 启动的进程运行可见应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41015796/