如何获得管理权限以在java中打开Windows vista/7 C盘中的目录
我尝试用java代码打开c驱动器中的目录,但失败了。它会抛出异常,因为访问被拒绝。我使用的是Windows 7。我怎样才能打开该目录。任何建议。
I tried to open a directory present in c drive in java code, but failed. It throws an exception as Access denied. I am using windows 7. How can I open that directory. Any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是一个UAC问题。
UAC(用户访问控制)是自 Windows Vista 以来集成的新 Microsoft Windows 系统,并试图类似于 Linux 的“sudo”命令。
微软最终意识到让所有进程以管理权限运行是一种安全隐患,并添加了此功能。
作为 Win7 用户,您可能已经注意到,当您尝试安装某些内容时,您会收到一条提示,询问您是否允许该进程在管理员级别运行。这就是适合您的 UAC。
问题是没有办法将正在运行的进程提升到管理员级别,并且软件必须从一开始就在管理员级别运行(右键单击->以管理员身份运行)。
还可以转到程序可执行文件的属性并将其设置为需要管理权限才能运行。
如果您只需要在提升模式下完成一个小操作,您可以使用提升模式生成一个新进程来为您执行一个小任务。查看 Java API/Google 以了解如何做到这一点。
This is a UAC issue I think.
UAC (User Access Control) is a new Microsoft Windows system integrated since Windows Vista and tries to resemble the Linux "sudo" command.
Microsoft finally realized that having ALL processes running with Administrative privileges is a security hazard and added this feature.
As a Win7 user you probably have noticed that when you try to install something you get a prompt asking you if you would allow the process to run at Admin level. That's UAC for you.
The problem is that there is no way to ELEVATE a running process to Admin level, and the software must be ran at Admin level from the very start (right-click -> Run As Administrator).
It is also possible to go to the program executables' properties and set it to require Administrative privileges to run.
If you only need a small operation done in Elevated mode you could spawn a new process with Elevation to do a small task for you. Look at the Java API/Google to find how to do that.