简单检查java以查看是否以管理员身份运行 [英] Simple check in java to find out if running as administrator

查看:53
本文介绍了简单检查java以查看是否以管理员身份运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个简单、快速、非侵入性的 Windows 管理任务可以从 Java 进程执行以验证当前进程是否以管理员身份运行?

Is there a simple, quick, non-invasive windows admin task that can be performed from a java process to validate if the current process is running as administrator?

我知道我们可以运行批处理命令来检查当前用户是否是管理员组的成员.但是在 Vista 等平台上存在可移植性的复杂性.

I know we could run batch commands to check if current user is member of administrator group. But there are complications of portability across Vista etc.

一个简单的例子是:

echo. 2> %SYSTEMROOT%\EmptyFile.txt

然而,这是侵入性的.我们不想创建文件

However, this is invasive. We dont want to create files

还有其他选择吗?

推荐答案

一般来说,您可能会发现检查特定权限是更好的选择,而不是暗示来自角色分配的权限.原因之一是在域环境中,您可能有本地管理员域管理员.它们不一定是等价的.此外,甚至可以更改管理员权限或调整"特定文件/目录权限,例如拒绝访问localmachine\administrators".

In general, you may find it a better choice to check for a specific permission rather than implying permissions from role assignments. One reason for this is that in a domain environment you may have local administrators and domain administrators. They are not necessarily equivalent. Also, even an administrator's permissions can be altered or specific file/directory permissions be "tweaked" to, for example, deny access to "localmachine\administrators".

检查特定权限可确保在给定特定用户凭据的情况下,该用户可以或不能执行某些操作,而不管他们可能被分配给什么角色.

Checking for a specific permission guarantees that, given specific user credentials, that user can or cannot perform some action, regardless of what roles they might be assigned to.

我知道这不能回答您的问题,但它可能有助于阐明从角色承担权限的问题.

I know that doesn't answer your question, but it may help shed some light on the problem of assuming permissions from roles.

这篇关于简单检查java以查看是否以管理员身份运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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