检测Java应用程序是否作为Windows管理员运行 [英] Detect if Java application was run as a Windows admin
本文介绍了检测Java应用程序是否作为Windows管理员运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Java应用程序。无论如何,我可以判断该进程是否在Windows 7上以管理员权限运行。
I have a Java application. Is there anyway I can tell if the process was run with admin privileges, on Windows 7.
推荐答案
我在网上找到了这段代码片段,我认为会为你做这个工作。
I found this code snippet online, that I think will do the job for you.
public static boolean isAdmin() {
String groups[] = (new com.sun.security.auth.module.NTSystem()).getGroupIDs();
for (String group : groups) {
if (group.equals("S-1-5-32-544"))
return true;
}
return false;
}
它仅适用于Windows,并内置于核心Java包中。我刚刚测试了这段代码,它确实有效。它让我感到惊讶,但确实如此。
It ONLY works on windows, and comes built in to the core Java package. I just tested this code and it does work. It surprised me, but it does.
SID S-1-5-32-544是Windows操作系统中Administrator组的ID。
The SID S-1-5-32-544 is the id of the Administrator group in the Windows operating system.
这是链接,了解其工作原理的详细信息。
Here is the link for more details of how it works.
这篇关于检测Java应用程序是否作为Windows管理员运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文