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();
            }
the_grandson
  • 15
  • 10

2 Answers2

0

I think according to this thread, you have two possibilities :

  • You can add a manifest for your fileattr.exe
  • You can use elevate.exe, run the binary using : ProcessBuilder pb = new ProcessBuilder("elevate", "fileattr");

I hope i answered you question.

Community
  • 1
  • 1
Vinz243
  • 9,654
  • 10
  • 42
  • 86
0

First possibility didn't solve, i've build the filleattr with the manifest file for two options of UAC level:

highestAvailable|requireAdministrator

Here's the manifest:

<security>
  <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    <requestedExecutionLevel level="highestAvailable" uiAccess="false" />
  </requestedPrivileges>
</security>

Second have an issue, i include both .exe files in java jar, when program starts extract .exe files and try to execute them, the problem, the extraction process is modifying something in executable, when i try to run the original file all works perfect, otherwise it throw's:

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.

Maybe @Templar sugestion should work, i just need to grant JVM user permission's that is enough to change folder atributtes, i'll try that.

Important to refer that from 30 and 30 seconds a thread call this method a large number of times, so the permission need's to be permanent otherwise it will not work properly.

the_grandson
  • 15
  • 10