以具有完全权限的管理员身份运行 Java 文件 [英] Run Java file as Administrator with full privileges

查看:75
本文介绍了以具有完全权限的管理员身份运行 Java 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个 Java 应用程序,并在我的个人电脑和我的个人电脑上对其进行了测试,到目前为止一切顺利...但是这个应用程序是给我另一个有迪斯科舞厅的朋友的,当我在他的电脑(Windows Vista 32 位)上安装"我的应用程序时,它没有工作,然后我去搜索和搜索,我发现问题是权限...我安装了一个 vista 32 位和 xp 32 位的虚拟机来做一些测试,但我无法以完全管理员权限运行我的应用程序.

I have made a Java Application and I tested it in my pc and my coined pc, so far so good... But this application is for another friend of mine that have a disco, when I "installed" my application on his pc (Windows Vista 32 bits) it didn't work, then i go searching and searching and I find out that the problem as the privileges... I installed a virtual machine of vista 32 bits and xp 32 bits to do some tests and I'm not able to run my application with full administrator privileges.

有什么方法可以创建批处理文件或允许我以所有权限运行我的应用程序的东西吗?我的意思是所有因为我需要连接到计算机的 COM 端口以从设备获取一些数据并且我需要存储一些文件,并且由于我使用的是外部库我可能需要一些我不知道的权限...我已经试过了,但没有任何效果:

Is there any way to create a batch file or something that would allow me to run my application with all privileges? I mean all because I need to connect to a COM port of the computer to get some data from a device and I need to store some files, and since I'm using an external library I might need some privileges that I don't know... I have tried this and nothing works:

elevate "c:Program FilesJavajreinjava.exe" -jar "%CD%installer.jar"

使用微软的提升脚本,我还创建了一个批处理文件

using the elevate scripts from microsoft, I also created a batch file with

runas /user:Administrator myjar.jar

但没有任何效果:有任何想法吗?提前致谢

but nothing worked : Any ideas? thank you in advance

推荐答案

这个答案适用于那些愿意为其 jars 或 java 类提供管理权限的人.成功开发一个exe来编辑保存在admin中的文件后.受限目录,我已经为您制定了这些步骤,希望这可以帮助您:需要了解的事情:1) jars 不会直接用特权编译,你必须用一些其他的 mainfest 文件把它们包装起来,最后才能有 exe 文件能够在 windows xp/vista/或更高版本的特权上运行.实际上,直到现在可能的答案是,在运行之前,exe 强制用户授予管理员权限,这与以前期望用户知道如何以不友好的管理员权限运行 jar 不同.

This answer is for those who are wiling to provide administrative privileges to their jars or java classes. After successfully developing an exe to edit files kept in admin. restricted directories, I have developed these steps to follow for you, hope this may help you: Things to understand: 1) Jars won't be directly compiled with privileges rather, you have to wrap them with some other mainfest file to finally have exe files capable of running on windows xp/ vista/ or higher version with privileges. Actually the possible answer uptil now is that before running, exe forces user to give admin rights unlike before where user is expected to know how to run jar with admin rights which isn't friendly.

现在的简单步骤:

  1. 像try2.jar一样创建包含一些mainifest文件的jar文件——像往常一样My1.mf.所以,jar文件的绝对路径是C: ry.jar.

  1. Create your jar file like try2.jar containing some mainifest file-- My1.mf as like always.So, the absolute path of the jar file would be C: ry.jar.

现在你需要下载一个软件Launch4j"来帮助你打包jar文件.它的下载链接是:http://sourceforge.net/projects/launch4j/files/launch4j-3/3.1.0-beta2/

Now you need to download a software "Launch4j" which will help you to wrap jar files.Its download links is : http://sourceforge.net/projects/launch4j/files/launch4j-3/3.1.0-beta2/

现在拿出 5 分钟.并观看本教程:http://www.youtube.com/watch?v=mARUFRknTYQ ;这将告诉您 Launch4j 的基本功能.但是这里并不清楚如何为您的 exe 创建清单文件.

Now take out 5 min. and watch this tutorial: http://www.youtube.com/watch?v=mARUFRknTYQ ;this will tell you basic functions of Launch4j. But here it won't be clear how to create a manifest file for your exe.

学完这个,然后创建一个清单文件,它是一个简单的文本文件,扩展名为.manifest".但是这里需要注意一些事情:首先,您的 mainfest 文件必须与要创建的最终 exe 的名称相同.就我而言,我的 exe 的名称应该是Launchme.exe",因此,我的清单文件必须命名为Launchme.manifest".其次,在清单文件中复制此内容:

After learning this, then create a manifest file, it is a simple text file with extension ".manifest" saved. But here certain things to be taken care of: Firstly, your mainfest file has to have same name as that of your final exe to be created. In my case, name of my exe was supposed to be "Launchme.exe" thus, my manifest file had to be named as "Launchme.manifest". Secondly, in manifest file just copy this content:

<?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>  

将上述代码复制到您的清单文件中.这里第 6 行是整个问题的关键.然后保存并关闭它.

copy the above code into your manifest file. here line 6 is the key of whole issue. Then save it and close it.

  1. 现在启动 Launch4j,根据您的条件像在视频中一样填充所有教过的文本字段.在 Wrapper mainfest 列中添加此文件清单文件.然后单击保存配置"选项,然后单击-- Build Wrapper.

现在你有包含你的 jar 的 exe,它要求用户在执行前给予管理员权限.现在用户除了点击之外什么都不知道!

Now you have exe containing your jar which requests user to give admin rights before executing. Now user is free from knowing anything other than clicks!

这篇关于以具有完全权限的管理员身份运行 Java 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆