java getRuntime().exec需要UAC的exe [英] java getRuntime().exec an exe that requires UAC

查看:66
本文介绍了java getRuntime().exec需要UAC的exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我们有一个作为Windows服务运行的Java进程.它需要使用 Runtime.getRuntime().exec(command)执行命令.它执行的命令需要UAC.这是在Windows Server 2008上,听起来您无法为单个可执行文件禁用UAC,所以还有其他方法可以使这项工作吗?

So we have a java process that runs as a windows service. It needs to execute a command with Runtime.getRuntime().exec(command). The command it executes requires UAC. This is on windows server 2008 and sounds like you cannot disable UAC for a single executable so is there any other way to make this work?

推荐答案

如果您的Java应用程序作为Windows服务运行,则很可能在以下系统帐户之一下运行:SYSTEM(最有可能),LOCAL SERVICE或NETWORK SERVICE.因此,如果该服务在SYSTEM帐户下运行,则您从该服务启动的所有内容都将继承该帐户.无论如何,必须允许您的服务与桌面交互.

If your Java application runs as a windows service, it most likely runs under one of the system accounts: SYSTEM (most probable), LOCAL SERVICE, or NETWORK SERVICE. Thus if the service runs under SYSTEM account, everything you start from the service will inherit the account. Anyway your service must be allowed to interact with Desktop.

总而言之,如果您的进程以提升的方式运行,则从其启动的进程也将以提升的方式运行.

To summarize, if your process run as elevated, then processes started from it will also run elevated.

要提升,您必须使用 ShellExecute 或 ShellExecuteEx 函数API.如果您要启动的.exe在其清单中标有 level = requireAdministrator ,则外壳程序将显示UAC对话框.如果未标记,则可以使用 runas 动词/操作来强制执行UAC确认对话框.注意:Windows XP上的 runas 将显示以其他用户身份运行"对话框.

To elevate, you have to use ShellExecute or ShellExecuteEx functions of Windows API. If the .exe you're starting is marked with level=requireAdministrator in its manifest, the shell will display UAC dialog. If it's not marked, you can use runas verb/operation to force UAC confirmation dialog. Note: runas on Windows XP will show "Run as another user" dialog.

如果通过ShellExecute实现了 Runtime.getRuntime().exec(command),则可以使用适当的清单标记.exe;否则,将不起作用.如果 exec 使用 CreateProcess ,该过程将以当前用户权限开始,即不提升权限;此外,如果.exe清单中有 requireAdministrator ,则该过程将完全不会启动.

If Runtime.getRuntime().exec(command) is implemented via ShellExecute, then marking the .exe with appropriate manifest will work; if exec uses CreateProcess, the process will be started with current user privileges, i.e. not elevated; moreover the process will not be started at all if .exe has requireAdministrator in its manifest.

这篇关于java getRuntime().exec需要UAC的exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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