0

I would like to know, is there out there any library, any, that can make it possible that when i run processes that require the administrator in windows, that window called UAC (User Access Control) pops up.

For example, i want to install my java application in a computer that will be used by multiple users, this program needs to store settings using the Java Preferences API inside windows registry, I can access individual prefs, but i cannot access system prefs from any user account.

Please and please, do not tell me to change the user from standard to administrator, let us just say i am to there where the computer client is and the user knows nothing about changing their account, the system will require elevation per user. Please help and thank you in advance. And if u do not know any library, please don't say it is not possible.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Maposa Takalani
  • 338
  • 1
  • 5
  • 17

1 Answers1

1

Windows does not let "parts" of an application run as an administrator. Either the entire process runs as an administrator, or the entire process runs as a standard user.

If your standard-rights users need to be able to access something, which by default only Administrators can access, then you have two choices:

1. During install, change permissions on these system-wide settings, so that all users can access them.

You've said that all users should be allowed to modify these Java settings. So you should modify permissions controlling access to these application settings so that all users can modify them. I don't know where Java stores things, but i assume it is in a file somewhere.

2. Create a button to temporarily allow users to modify these settings.

You say that all users should be allowed to modify these machine-wide settings. But i assume you're nervous about actually allowing that. In which case you actually don't want all users to modify these machine-wide settings. That is why you can have your application function most of the time as normal.

But when it comes time to do something that requires administrative access, you can use the Windows function ShellExecuteEx to launch a copy of your application as an administrator by using the runas verb, and passing a command line parameter indicating that the program should jump right to modifying the admin-only stuff:

    ShellExecute(0, "MyApp.exe", "runas", "/configureMachineWideStuff")

Then during application startup look for the /configureMachineWideStuff command line switch, and bring the user straight to the spot where they can alter the admin-only stuff.

You can even get fancy, and detect if the user is an administrator or not. And if not, use the Windows API to programatically add the UAC shield icon to your configure button:

SendMessage(button.Handle, BCM_SETSHIELD, 0, 1);

enter image description here

But to answer your question

No, there is no library. What you are asking to do is not possible on any computer running any operating system.

But i strongly urge you to think:

What do you do on Windows XP?

What do you do when the user is a standard user running on Windows XP? What do you want if the UAC is disabled on Windows Vista/7/8/8.1? Is the user simply stuck; unable to run your application? Does it crash horribly when it cannot read the machine-wide values? Who alters the values then?

The UAC is a convenience feature; it's only there to make your user's lives easier. The alternative is that the user must logoff and login as an Administrator.

And since you've said that the only are a standard user, then they don't know the credentials of any administrator.

So you're back to using Option #1: Alter NTFS permissions, or registry permissions, during application install. If Users need Full Control, then give Users the Full Control privileges.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219