java 管理员身份运行cmd,以管理员身份从java启动命令提示符(CMD)

这篇博客介绍了如何在Windows平台上为Java项目赋予管理员权限来执行需要管理员权限的系统进程。推荐了两种方法:一是使用`runas`程序,二是通过JNA库调用标准的Windows登录对话框。这两种方法可以解决Java程序在运行时需要管理员权限的问题,提高用户体验。
摘要由CSDN通过智能技术生成

I am working on a java project. This project need admin privileges to execute some process in the system. For this is there any way to give admin privileges while starting the project? Is there any way to start command prompt with admin privileges from java?

解决方案

Disclaimer: I assume you are asking this specifically for the Windows platform

There are two ways I'd recommend:

Use the runas program

This is the easiest way and since you actually want a console window the password prompt doesn't look awkward. On the other hand a user might find it suspicious to enter his password into a console window.

This requires you to use a Win32 Java library. (I'd recommend JNA). It is a little more work but it might lead to a better user experience because of the standard Windows login dialog.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值