从Java程序写入C:\Program文件 [英] Write to C:\Program Files from Java program

查看:163
本文介绍了从Java程序写入C:\Program文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个包含自我更新程序的Java应用程序。自我更新程序从Web服务器加载新程序版本并替换应用程序文件。如果安装了应用程序(例如在用户主目录中,如果安装在C:\Program Files文件夹中,则在Windows计算机上失败。这是因为JVM是在用户帐户下执行的,该帐户对程序目录没有写访问权。
如果是本机程序,例如安装程序尝试写入程序文件夹时,通常会出现一个弹出窗口,要求用户允许写入操作。 Java应用程序不会发生这种情况。为什么?

I have written a Java application that includes a self updater. The self updater loads new program versions from a web server and replaces the application files. While this works perfectly if the application is installed e.g. in the users home directory, it fails on windows machines if it's installed in the C:\Program Files folder. This is because the JVM is executed under the user’s account which has no write access to the program directory. If a native program, e.g. an installer, tries to write to the program folder, usually a popup appears asking the user to permit the write operation. This doesn’t happen for java applications. Why?

有什么方法可以实现对受限文件夹的Java程序写操作会弹出安全弹出窗口,以便用户可以允许访问该文件夹?

Is there any way to achieve that a write operation of a Java program to a restricted folder brings up the security popup so that the user can permit access to that folder?

感谢您的回复。根据答案,我看到以下选项:

Thanks for your responses. According to the answers I see the following options:


  1. Java Web Start

    对我来说,这是不是最终用户的选择。我认为,没有人会期望普通的最终用户知道Java Web Start是什么,它有什么用处以及如何使用,例如我怀疑普通的Windows用户是否知道如何卸载Java Web Start应用程序。

  1. Java Web Start
    For me this is not an option for end users. I think that no one can expect from an ordinary end user to know what Java Web Start is, what it’s good for and how it’s used e.g. I doubt that an ordinary Windows user knows how to uninstall a Java Web Start application.

使用带有清单的exe启动器启动Java应用程序

据我了解,该解决方案是exe启动器可以在应用程序启动时请求扩展执行。这并不是我想要的,因为对于我的用例来说,如果有可用的更新,而不是在每个应用程序启动时,获取扩展权限就足够了。

Use an exe-launcher with manifest to launch the Java application
As far as I understand this solution the exe-launcher would request extended execution right at application start. This is not exactly what I want, cause for my use case it would be sufficient to get extended rights if an update is available and not on every application start.

通过调用本地可执行文件执行更新操作

可以调用本地可执行文件以使其执行更新操作。这样,应用程序仅在有可用更新时才请求扩展权限。听起来还不错,但其中包含Windows的一些本机编码,在其他平台上则无效。

Perform the update operation by calling a native executable
One could call a native executable to let it perform the update operation. In this way the application would only request extended rights if an update is available. This sounds not bad but includes some native coding for Windows and doesn’t work on other platforms.

在程序文件夹中安装启动器,并在用户home中安装应用程序

可以将启动器放置在程序文件夹中,该启动器安装在用户主目录中的应用程序。通过这种方式,可以更新用户主文件夹中的应用程序。
我使用InnoSetup在Windows上安装应用程序,据我所知,使用此安装程序以及其他安装程序很难实现拆分安装。

Install a launcher in program folder and the application in user home
One can place a launcher in the program folder that calls the application that is installed in the user’s home directory. In this way it would be possible to update the application in the user’s home folder. I use InnoSetup for installing my application on Windows and as far as I can see it a split installation is hard to achieve with this installer and probably with other too.

在用户的主目录中安装完整的应用程序

因为用户对其主目录具有写权限,所以完全没有问题。对我来说,这似乎是其简单性的最佳选择。

Install the complete application in the user’s home directory
Because the user has write access to his home directory there is no problem at all. For me this looks like the best option cause of its simplicity.


推荐答案

不幸的是,当您第一次启动计划,您以后就无法晋升。看起来像他们这样做的程序实际上是在幕后以更高的特权重新启动自己。

Unfortunately the increased permissions need to be requested when you first start the program, you cannot promote to them later. Programs that look like they do that are actually restarting themselves with the higher privs behind the scenes.

几年前,我在使用Java应用程序和最后,我将应用程序安装到用户数据文件夹中,而不是程序文件中,否则自动更新是一场噩梦。您仍然可以将其添加到开始菜单中,以便对用户而言,它看起来与任何其他程序完全一样。

I had a problem like this a few years ago with a Java app and in the end I installed the application to the user data folder instead of program files as otherwise the auto-updating was a nightmare. You can still add it to the start menu so to a user it looks exactly like any other program.

这篇关于从Java程序写入C:\Program文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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