• Post Reply Bookmark Topic Watch Topic
  • New Topic

Catch non administrators  RSS feed

 
Meshulam Silk
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java program which creates a file on the computer.
This obviously only works on administrator accounts.
When on a normal account the program just quits.
I wanted to know if there was a way to use try/catch to know when the user running the program is not an admin.
Even better: is there a way to bypass this and make the computer think it's an admin?

Thanks
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In all probability, the program does not just quit, it throws an exception which is not caught (or, worse, is caught and forgotten about) and makes the program quit.

There are two ways a Java program might be denied access to a resource: by Java's SecurityManager or by the operating system. I don't think it is the first one you're encountering, but if you are, you could test the permissions first via the SecurityManager class itself.

If it's the OS which prevents you from doing something, you should still be able to check access rights, eg. by using File's canWrite() method (don't know whether this tests a file can be created, though), or at least handle the faults by catching the IOException which gets thrown whenever an IO operation fails.

In any case, there are no ways to trick the computer think you're an admin -- that would be a huge security hole, wouldn't it? On some systems (eg. Windows) it is possible to impersonate another user if you call corresponding system function and pass it that user's credentials, though this is immensely complicated to do even from a native application (you have to mess with SecurityDescriptors and all that) and in Java you'd probably be forced to do all admin operations by calling Windows API. In short, you're not going to do that.

 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The File class has some usefull methods that can help you here, like canExecute(), canRead() and canWrite().
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meshulam Silk wrote:I have a java program which creates a file on the computer.
This obviously only works on administrator accounts.

There's nothing obvious about it at all.

As the others have pointed out, this is almost certainly a restriction imposed by the operating system or by whoever created the file (or both).

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!