1

When my java program is executing it's creating a directory in "Program Files". But access denied "Program Files" folder to create a folder. According to my knowledge the application is running with current user and it should be executed with Administrator privileges. How can acquire Administrator privileges when creating folder or files via java code ?

This is what I have used code and directory_location is as follows

C:/Program Files/

public int createDirectory(String directory_location) {
        int done = 0;

        try {
            Files.createDirectories(Paths.get(directory_location));
            done = 1;
        } catch (IOException ioEx) {
            Log.getInstance().writeMethodeException(FileSystemConfig.rootFolder, ioEx);
        }
        return done;
    }
Chaminda Bandara
  • 2,067
  • 2
  • 28
  • 31
  • 6
    Start your program as administrator – Ferrybig Jan 26 '16 at 08:43
  • If you run the java program with administrator rights you should be able to do that – ParkerHalo Jan 26 '16 at 08:43
  • 1
    If you ever launch your java program from a DOS console, you may want to open the console with administrator rights : _Start > cmd > right click > run as administrator._ – Arnaud Jan 26 '16 at 08:46
  • 3
    The question really is why? Even as administrator, you may not be able to create directories in the Program Files directory, particularly under Windows 8 and 10, as running the way the security mechanisms have changed and you may run into other issues you wouldn't otherwise expect. If you're just trying to write configuration, then write it to the `{user.home}\AppData\{Local or Roaming}\{program}` directory – MadProgrammer Jan 26 '16 at 09:05
  • 1
    [check this answer](http://stackoverflow.com/a/26706333/4101906) – Rahmat Waisi Jan 26 '16 at 09:24
  • Thank you for your valuable consultation @MadProgrammer and I want to create configuration files and log files then you prefer to do that in AppData . – Chaminda Bandara Jan 26 '16 at 09:38
  • @ChamindaBandara Convention would suggest this as been the preferred way – MadProgrammer Jan 26 '16 at 20:22

0 Answers0