以管理员身份运行Javafx应用程序
问题描述:
您好,我将以管理员身份在窗口上运行java程序。我怎么能做到这一点? 我累这https://github.com/rritoch/超级用户应用程序 但它只有自己的类。我不喜欢这个。以管理员身份运行java的最佳解决方案是什么?谢谢!以管理员身份运行Javafx应用程序
package com.vnetpublishing.java;
import com.vnetpublishing.java.suapp.SU;
import com.vnetpublishing.java.suapp.SuperUserApplication;
public class TestAdmin extends SuperUserApplication {
public static void main(String[] args) {
SU.run(new TestAdmin(), args);
}
public int run(String[] args) {
System.out.println("RUN AS ADMIN! YAY!");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return 0;
}
}
答
请使用lanuch4j并添加清单文件 你可以使用如下代码。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="highestAvailable" uiAccess="False" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
你可以参考这个答案[https://*.com/questions/27332003/how-do-i-request-uac-administrative-privileges-with-a-javafx-desktop-application/44564485 #44564485](https://*.com/questions/27332003/how-do-i-request-uac-administrative-privileges-with-a-javafx-desktop-application/44564485#44564485) –