0

I've written a program in c# to change file and folder atributes in windows. I run this program from java, starting the program from windows all works great, in java just files can be changed when i try to change a folder it throws:

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

I've set the processbuilder directory to user.home thinking that problem could come because of that but doesn't work. My code:

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();
            }
4

2 回答 2

0

我认为根据this thread,您有两种可能性:

  • 您可以为您的 fileattr.exe添加清单
  • 您可以使用elevate.exe,使用以下命令运行二进制文件:ProcessBuilder pb = new ProcessBuilder("elevate", "fileattr");

我希望我回答了你的问题。

于 2013-08-22T19:08:43.363 回答
0

第一种可能性没有解决,我已经使用清单文件为 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 sugetion 应该可以工作,我只需要授予 JVM 用户权限就足以更改文件夹属性,我会尝试的。

重要的是,从 30 秒到 30 秒,一个线程会大量调用此方法,因此权限需要是永久的,否则将无法正常工作。

于 2013-08-23T14:35:31.563 回答