[英]Java execute .exe with user previlege
我已經用C#編寫了一個程序來更改Windows中的文件和文件夾屬性。 我從Java運行此程序,從Windows啟動該程序的效果都很好,在Java中,當我嘗試更改其拋出的文件夾時,只能更改文件:
Problem signature: Problem Event Name: CLR20r3 Problem Signature 01: fileattr.exe Problem Signature 02: 1.0.0.0 Problem Signature 03: 5203a06f Problem Signature 04: mscorlib Problem Signature 05: 4.0.30319.18052 Problem Signature 06: 5173c144 Problem Signature 07: 43cf Problem Signature 08: 13c Problem Signature 09: System.UnauthorizedAccess OS Version: 6.1.7601.2.1.0.256.48
我已經將processbuilder目錄設置為user.home,以為可能會因此而出現問題,但不起作用。 我的代碼:
try { ProcessBuilder pb = new ProcessBuilder("fileattr", "+t", "\"".concat(path).concat("\"")); pb.environment().put("fileattr", pathToApp); pb.directory(new File(System.getenv("WINDIR") + "\\system32")); Process p = pb.start(); p.waitFor(); p.destroy(); } catch (Throwable t) { t.printStackTrace(); }
我認為根據這個線索,您有兩種可能性:
ProcessBuilder pb = new ProcessBuilder("elevate", "fileattr");
elevate ProcessBuilder pb = new ProcessBuilder("elevate", "fileattr");
我希望我回答了你的問題。
第一種可能性沒有解決,我用清單文件為UAC級別的兩個選項構建filleattr:
highestAvailable|requireAdministrator
這是清單:
<security> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> </requestedPrivileges> </security>
第二個問題,我在Java jar中同時包含兩個.exe文件,當程序開始提取.exe文件並嘗試執行它們時,問題是,提取過程正在修改可執行文件中的某些內容,當我嘗試運行原始文件時,完美,否則拋出:
This version of C:\\Users\\Luis\\SyncData\\Elevate.exe is not compatible with th e version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.
也許@Templar建議應該起作用,我只需要授予JVM用戶許可權就足以更改文件夾屬性,我將嘗試這樣做。
重要的是要指出,在30到30秒內,線程會多次調用此方法,因此權限需要是永久的,否則它將無法正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.