使用 Java ProcessBuilder 从 TaskScheduler 启动的进程运行可见应用程序 [英] Running visible applications, using Java ProcessBuilder, from a process started by TaskScheduler

查看:43
本文介绍了使用 Java ProcessBuilder 从 TaskScheduler 启动的进程运行可见应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,在最新版本的 Windows 中通过 TaskScheduler 启动任务时,如果任务是无论用户是否登录都运行",那么该任务将不会以交互方式运行 - 即它不会启动 UI.

It's well known that when starting tasks via TaskScheduler in recent versions of Windows, that if the task is "run whether user is logged on or not", then the task will not run interactively - i.e. it will not start a UI.

作为参考,这是根据 Microsoft,并且有在这个SuperUser question和这个<一个 href="https://stackoverflow.com/questions/39736810/task-scheduler-cant-show-gui-of-the-application-after-logout-and-login-run-whehttp://">StackOverflow 问题:

For reference, this is according to Microsoft, and has been highlighted in this SuperUser question and this 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.

然而,我的问题是由此衍生出来的.

However, my problem is derivative of this.

  • TaskScheduler 启动的任务是一个 Java 客户端应用程序可以指示运行进程 - 这些是通过 ProcessBuilder 运行的在客户端应用程序中.因此,这个客户是可以的应用程序被隐藏/不启动 UI - 事实上,没有 UI.

  • The task started by TaskScheduler is a Java client application which can be instructed to run processes - these are run via ProcessBuilder in the client application. As such, it is okay that this client application is hidden / does not start a UI - indeed, there is no UI.

但是,如果客户端应用程序通过TaskScheduler启动为'无论用户是否登录都运行',那么在客户端应用程序中由ProcessBuilder启动的任何进程也无法交互运行/无法运行显示一个用户界面.这是一个问题,因为客户端启动的一些进程是 UI 应用程序.

However, if the client application is started via TaskScheduler to 'run whether user is logged on or not' as above, then any processes that are started by ProcessBuilder in the client application are also unable to run interactively / unable to show a UI. This is a problem, as some of the processes started by the client are UI applications.

我不知道为什么会这样,但我真的想弄清楚是否有解决办法 - 例如可以添加一些环境变量或属性来让(不可见的)客户端启动可见进程.

I'm not sure why this would be the case, but really I'm trying to work out if there is a work around - e.g. some environment variables or properties that could be added to get a visible process started by the (invisible) client.

有什么想法吗?

推荐答案

所以,我找到的解决方法是停止使用 TaskScheduler,而是创建一个脚本来启动我的应用程序并在开始"菜单中添加该脚本的快捷方式>程序 >启动文件夹.

So, the workaround that I found was to stop using TaskScheduler, but to create a script to start my application and added a shortcut to that script in the Start Menu > Programs > Startup folder.

感谢这篇关于 HowToGeek:

在 Windows 7 和更早版本的 Windows 上,开始"菜单包含一个启动"文件夹以简化此操作.

On Windows 7 and earlier versions of Windows, the Start menu contained a "Startup" folder to make this easy.

此文件夹在 Windows 8、8.1 和 10 上不再容易访问,但仍然可以访问.要访问它,请按 Windows 键 + R,在运行"对话框中键入shell:startup",然后按 Enter.

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.

您添加到shell:startup"文件夹的快捷方式只有在您使用您的用户帐户登录时才会启动.如果您想在任何用户登录时使用快捷方式自行启动,请改为在运行"对话框中键入shell:common startup".

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:common startup"链接.

Since I want my application to start on system startup, rather than user login, I used the "shell:common startup" link.

以这种方式启动的应用程序 - 或者在我的情况下,由以这种方式启动的应用程序启动的应用程序 - 通过其 UI 可见和/或交互.

Applications started in this way - or in my case, applications started by applications started in this way - are visible and/or interactive via their UIs.

这篇关于使用 Java ProcessBuilder 从 TaskScheduler 启动的进程运行可见应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆