简单检查java以查明是否以管理员身份运行
是否有一个简单、快速、非侵入性的 Windows 管理任务可以从 java 进程执行来验证当前进程是否以管理员身份运行?
我知道我们可以运行批处理命令来检查当前用户是否是管理员组的成员。但是跨 Vista 等的可移植性存在一些复杂性。
一个简单的例子是:
echo. 2> %SYSTEMROOT%\EmptyFile.txt
然而,这是侵入性的。我们不想创建文件
还有其他选择吗?
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?
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.
A simple example would be:
echo. 2> %SYSTEMROOT%\EmptyFile.txt
However, this is invasive. We dont want to create files
Any other option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您可能会发现检查特定权限比从角色分配中暗示权限是更好的选择。原因之一是在域环境中您可能有本地管理员和域管理员。它们不一定是等价的。此外,甚至可以更改管理员的权限或“调整”特定文件/目录权限,例如拒绝对“本地计算机\管理员”的访问。
检查特定权限可以保证,在给定特定用户凭据的情况下,该用户可以或不能执行某些操作,无论他们可能被分配到什么角色。
我知道这并不能回答您的问题,但它可能有助于阐明从角色获取权限的问题。
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.