[英]How to run a batch file as administrator from a java program
I am creating a hotspot software for which I need to run a batch file as administrator from a java program. 我正在创建一个热点软件,需要以管理员身份从Java程序运行一个批处理文件。 The batch file contains the following two commands:
批处理文件包含以下两个命令:
netsh wlan set hostednetwork mode=allow ssid=name key=password netsh wlan设置托管网络模式=允许ssid =名称键=密码
netsh wlan start hostednetwork netsh wlan启动托管网络
name and password are taken as input from the user. 用户输入名称和密码作为输入。
As capturesteve has written - run the app as administrator. 正如capturesteve所写-以管理员身份运行该应用程序。 You can use for example
cmd.exe
under Windows. 您可以在Windows下使用例如
cmd.exe
。 If you run the cmd.exe with administrator privileges, everything what will be started from this "administrator" cmd.exe will inherit the rights of his owner. 如果使用管理员权限运行cmd.exe,则将从该“管理员” cmd.exe启动的所有内容都将继承其所有者的权限。 It's a universal principle in Windows (and not only in Windows).
这是Windows中的通用原则(不仅限于Windows)。
Run the cmd.exe as administrator and start the java app from it: 以管理员身份运行cmd.exe并从中启动Java应用程序:
https://technet.microsoft.com/en-us/library/cc947813%28v=ws.10%29.aspx http://www.softwareok.com/?seite=faq-Windows-8&faq=7 https://technet.microsoft.com/zh-cn/library/cc947813%28v=ws.10%29.aspx http://www.softwareok.com/?seite=faq-Windows-8&faq=7
+ +
最好的方法是将Java应用程序本身作为sudo运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.