How to give administrator rights in Java code for tasks

374 views Asked by At

There was such a problem. With the help of FileReader I run on the system file and try to change the lines in it. But I can not do this if my application is not running on behalf of the administrator.

private BufferedReader fileReader(String path) {
   FileReader fileReader = null;
   try {
       fileReader = new FileReader(path);
   } catch (FileNotFoundException e) {
       e.printStackTrace();
   }
   BufferedReader bufferedReader = new BufferedReader(fileReader);
   return bufferedReader;
}

private String fileWriter(String path) {
   try {
       BufferedReader bR = fileReader(filePath);
       while ((line = bR.readLine()) != null) {
          ...
          ...
       }
   } catch (Exception e) {
       e.printStackTrace();
   }
   return result;
}

Help me how to request elevation of the rights in the code so that when using my program, not on behalf of the administrator, I did not need to restart it with elevated privileges for correct work?

OS: Windows

But I would like to get a General solution, if there is one, because the application is used on different platforms

0

There are 0 answers