从Java作为管理员运行Windows命令行 - 创建.manifest文件 [英] Running Windows commandline from Java as an Administrator - Creating a .manifest file
问题描述
我正在运行Windows 7 Pro并在Eclipse中处理Java应用程序。我需要Eclipse向命令提示符发送用户指定的命令(例如'chkdsk C:'),然后输出到Eclipse中的控制台,不管命令提示符打印什么。我有发送命令工作和接收文本回来。但是,当我运行chkdsk我需要有管理员权限的命令会话。我在这里看到的线程:
I am running Windows 7 Pro and working on a Java application in Eclipse. I need Eclipse to send user-specified commands (such as 'chkdsk C:') to the command prompt and then output to the console in Eclipse whatever the command prompt would have printed. I have the sending commands working and the receiving text back. However, when I to run chkdsk I need to have admin privileges for the command session. I see from the thread here:
,一种方法是通过.manifest文件。但是,我无法理解如何为Java创建清单文件:
that one way to do this is through a .manifest file. However, I am having trouble understanding how to create a manifest file for Java:
.manifest文件是否只是进入Eclipse工作空间的.CLASS文件?
Does the .manifest file just go into the Eclipse workspace with the .CLASS files? If I put it there will it run automatically to start my program in admin mode whenever I run the program?
从上面的线程给出的链接:
The link given from the above thread:
http://msdn.microsoft.com /en-us/library/bb756929.aspx
似乎是Visual Studio特定的,示例代码是否适用于Java程序.manifest文件?我需要在Visual Studio中创建.manifest文件,还是只是一个文本文件?
seems to be Visual-Studio specific, will there example code work for a Java program .manifest file? Do I need to create the .manifest file in Visual Studio or is it just a text file?
此外,清单文件的名称是yourProgram.exe.manifest。 .. Java,因为我明白它不创建可执行文件的.exe品种呢?清单文件是否应该如上所述命名,或者它需要一个名称,如yourProgram.CLASS.manifest?
Also, the name of the manifest file is yourProgram.exe.manifest ... Java as I understand it doesn't create executables of the .exe variety does it? Should the manifest file be named as above or does it need a name like yourProgram.CLASS.manifest?
感谢您的帮助!
推荐答案
应用程序清单描述这里和Java清单文件(在META-INF / MANIFEST.MF的JAR文件中)是两个完全不同的概念,它们只共享一个名称。 META-INF / MANIFEST.MF中没有什么可以帮助Java可执行文件获取高程。
The application manifest described here, and the Java manifest file (in the JAR file at META-INF/MANIFEST.MF), are two completely separate concepts that share only a name. There's nothing in META-INF/MANIFEST.MF that will help a Java executable gain elevation.
此外,它的JVM需要提升,而不是类文件。将.manifest文件与所有类文件一起使用将无法实现任何内容。
Besides, its the JVM that needs the elevation, not the class files. Putting the .manifest file with all your class files will not achieve anything.
如果我不得不这样做,我首选的方法是使用一个程序,如 elevate.exe
调用 CHKDSK
。 elevate.exe
可在此博客文章链接到您提到的问题。我没有测试 elevate.exe
,作者最初写的Windows Vista,所以我不知道它在Windows 7上的工作情况。
If I had to do something like this, my preferred approach would be to use a program such as elevate.exe
to call CHKDSK
. elevate.exe
can be found at this blog article linked to in the question you've mentioned. I haven't tested elevate.exe
, and the author originally wrote it for Windows Vista, so I don't know how well it works on Windows 7.
似乎 CHKDSK
是您的应用程序中唯一需要提升的部分。如果是这样,从安全的角度来看,在没有大部分时间可以管理整个应用程序的时候,这是没有意义的。
It seems that CHKDSK
is the only part of your app that requires elevation. If so, it would make sense from a security point-of-view not to have the whole app elevated all of the time when most of the time it can manage without.
这篇关于从Java作为管理员运行Windows命令行 - 创建.manifest文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!