java - 使用 Java ProcessBuilder 从 TaskScheduler 启动的进程运行可见应用程序

标签 java scheduled-tasks taskscheduler

众所周知,在最新版本的 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/

相关文章:

java - 无法使用 for 循环更新多次

linux - 如何创建一个在后台运行且在 L​​inux 中交互式的应用程序?

php - Laravel 任务 - 上次运行时存储

message-queue - 处理数百万条定时(预定)消息的解决方案?

c# - 通过 Task Scheduler 的 Entity Framework 连接作为 NTAuthority/Anonymous Logon 连接

java - 向右移动数组 - 作业

java - SQLite 连接和资源,良好实践

java - 将 Wordnet 加载到 Neo4j 中

c# - 除非使用 "run as admin",否则在 Windows 10 上以编程方式创建计划任务失败

c# - 是什么原因导致错误HRESULT : 0x800A03EC?