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

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

问题描述

所以,我做了一个Java应用程序,我测试了它在我的电脑和我的杜撰电脑,到目前为止好...
但是,这个应用程序是对我的另一位朋友有一间的士高,当我已安装我对他的PC应用程序(Windows Vista中32位)没有工作,那我走了寻寻觅觅,我找出了问题,因为特权......我安装了Vista 32位和XP 32位做一些测试,我无法运行我的完整的管理员权限的应用程序的虚拟机,有什么办法为创建一个批处理文件或东西,让我跑我的所有权限的应用程序?我的意思是一切,因为我需要连接到计算机的COM端口从一个设备的一些数据,我需要存储一些文件,因为即时通讯使用外部库,我可能需要一些特权,我不知道..我曾经尝试这样做并没有什么工作:

so, 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, there is any way for create a batch file or something that 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 im using an external library i might need some privileges that i don't know... I have tried this and nothing work:

elevate "c:\Program Files\Java\jre\bin\java.exe" -jar "%CD%\installer.jar"

使用微软的脚本ELEVATE

,我也创建

using the elevate scripts from microsoft, i also create a batch file with

runas /user:Administrator myjar.jar

但是毫无效果:\\
任何ideias?预先感谢您

but nothing worked :\ Any ideias? thank you in advance

推荐答案

这答案是为那些谁也愿意提供管理权限到他们的罐子或Java类。成功开发一个exe编辑后的文件保存在管理。受限目录,我已经开发了这些步骤,跟随你,希望这可以帮助你:
    事情就明白了:
1)罐子不会直接与特权编译相反,你必须与其他一些mainfest文件来包装他们终于有能力与权限运行在Windows XP / VISTA /或更高版本的exe文件。实际上,可能的答案uptil现在是运行前,EXE势力用户给管理员权限,不像以前在这里用户预计将知道如何与这是不友善管理员权限运行罐子。

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)创建一个包含一些mainifest file-- My1.mf像always.So你的jar文件一样try2.jar,jar文件的绝对路径是C:\\ try.jar

Now the simple steps: 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:\try.jar.

2)现在你需要下载一个软件Launch4j,这将帮助你换罐子files.Its下载链接是:<一href=\"http://sourceforge.net/projects/launch4j/files/launch4j-3/3.1.0-beta2/\">http://sourceforge.net/projects/launch4j/files/launch4j-3/3.1.0-beta2/

2) 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/

3)现在拿出5分钟。看着这个教程: http://www.youtube.com/watch?v=mARUFRknTYQ ;这将告诉你Launch4j的基本功能。但在这里就不是很清楚如何创建一个清单文件为您的EXE文件。

3) 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.

3)的学习之后,再创建一个清单文件,它与扩展的简单文本文件名为.manifest保存。但这里若干事情需要照顾的:首先,你mainfest文件必须具有相同的名称最终exe文件的创建。就我而言,我的exe文件的名字应该是Launchme.exe因此,我的清单文件必须被命名为Launchme.manifest。其次,在清单文件只是复制此内容:

3) 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>  

复制上面的code到您的清单文件。这里6号线是整个问题的关键。然后保存并关闭它。

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

4)现在启动Launch4j,补全教文本框像视频按你的条件。在包装mainfest列添加此文件清单文件。然后点击保存设置选​​项,然后click--建立包装。

4) Now start Launch4j, fill all the taught textfields as like in video as per your conditions. In Wrapper mainfest column add this file manifest file. Then click "save configuration" option and then click-- Build Wrapper.

现在您拥有一个包含罐子它要求用户在执行之前给管理员权限的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天全站免登陆