简体   繁体   English

Runtime.exec 以非管理员身份运行

[英]Runtime.exec run as Non Admin

I have a Java App that can update itself.我有一个可以自我更新的 Java 应用程序。

The Java App run as a non-admin at first and if you want to update, it will execute a.lnk shortcut that I've created that points to another.jar file specifically just to update (but with admin access). Java 应用程序首先以非管理员身份运行,如果您想更新,它将执行我创建的指向另一个的.lnk 快捷方式。jar 文件专门用于更新(但具有管理员访问权限)。

The.lnk shortcut that points to the.jar updater asks for adminpermissions by using this answer here >> https://stackoverflow.com/a/30028948/1862452指向 .jar 更新程序的 .lnk 快捷方式通过在此处使用此答案请求管理员权限 >> https://stackoverflow.com/a/30028948/1862452

After updating the main jar, I want the.jar updater to run the main.jar again but I wanted it to be a non-admin.更新主 jar 后,我希望 .jar 更新程序再次运行 main.jar 但我希望它是非管理员。 How do I do this?我该怎么做呢? It is currently running as an admin because the updater jar is currently as running admin它当前以管理员身份运行,因为更新程序 jar 当前以管理员身份运行

I solved my problem in a different way.我以不同的方式解决了我的问题。

When the user wants to update the main.jar, it executes Runtime.exec() twice.当用户想要更新 main.jar 时,它会执行两次Runtime.exec() The first one where it calls cmd and executes the.lnk shortcut for the updater which request admin access.第一个调用 cmd 并为请求管理员访问权限的更新程序执行 .lnk 快捷方式。 The second is a watcher for the updater.jar window.第二个是更新程序的观察者。jar window。

The watcher.jar file executes a windows command tasklist /fi "Windowtitle eq <JAR UPDATER WINDOW NAME>" every so often (let's say every 1s) and count the lines of the output. The watcher.jar file executes a windows command tasklist /fi "Windowtitle eq <JAR UPDATER WINDOW NAME>" every so often (let's say every 1s) and count the lines of the output. It has 2 states它有2个状态

1) Detect Updater is running (line count of output > 1) 1)检测更新程序正在运行(output的行数> 1)
2) Detect Updater is dead (line count of output == 1) 2) Detect Updater is dead (output的行数== 1)

After the 2 states, it means that the main.jar has been updated and the updater is dead. 2个状态后,表示main.jar已经更新,更新器死机。 It then calls main.jar.然后它调用 main.jar。

Since this watcher.jar is called with a non-admin elevation, it will also call the main.jar as non-admin.由于这个 watcher.jar 是以非管理员身份调用的,因此它也会以非管理员身份调用 main.jar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM