Results 1 to 2 of 2
  1. #1
    danborgir is offline Member
    Join Date
    Jan 2011
    Rep Power

    Default Java and file Windows file permissions

    I am developing a program to block a web page in the hosts file in Windows. I am encountering an error on some systems where permission is not available to edit the file. Does Java have any file permission classes to ask user to either change the permission of a file or change to admin account etc...?

    I am sorry but I don't know exactly what I need to do :o



  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    The 'File' class has methods to check to see if you have read/write permission. If you don't you can pop up (JOptionPane) a message telling the user they don't have permission. But Java doesn't have anything in the API to let the user login as a different user. If you want that functionality, you'll have to execute whatever facility the operating system has for doing that.

    Windows does have an impersonation feature (runas) that allows a program to be executed as admin even from a non-admin account. What you could do is to check file permissions, and if they are inadequate, pop up an option pane that allows the user to 'runas' admin (they'll have to know the admin account and password of course). Then, use Runtime.exec to rerun your program through 'runas', following by System.exit on the calling instance. On windows, the subprocess will continue to run even if the parent process exits.

Similar Threads

  1. Reading mapped file MacOSX vs. Windows
    By CapsLoc in forum New To Java
    Replies: 6
    Last Post: 12-12-2010, 08:08 AM
  2. How to access driver in Windows like a file?
    By pthoonen in forum New To Java
    Replies: 6
    Last Post: 01-15-2009, 04:28 AM
  3. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 10:57 AM
  4. Replies: 7
    Last Post: 05-23-2008, 04:46 AM
  5. run a batch file as windows nt service
    By radhika123 in forum New To Java
    Replies: 0
    Last Post: 04-04-2008, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts