Ask yourself if your setting really is for all users. Is it really for all users?
Carefully think about this question:
How did the software run under Windows XP as standard user?
- Did the software simply crash?
- Was configuring the option disabled?
- Did you tell your customers that they had to run as an administrator, and if they refused then you wouldn't support it?
Because if your software absoutely requires you to be an administrator, then simply add the manifest to the executable saying it needs to be run as an administrator:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="IsUserAdmin"
type="win32"/>
<description>Description of your application</description>
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
And presto, you're an administrator.
But i don't think you really need to be an administrator. The only time you need a local machine setting is if you're going to have users from multiple logins or sessions using the software. If it really is something that applies to every user, shouldn't the installation program have set it up?
We had the same question come up here. A surveillance system needs to configure which capture device will be used by the software. You could say that all surveillance operators will be using the same capture device, so once one picks it, that setting is global to all operators. But that's just not true in practice. Chances are there's only once capture device, and it's the one we use. If there's more than one, then the user can simply pick another device.
But there are a few ways to handle this
i) Have the settings saved in the registry, and have the installation program set the ACL on the key give all users Full Control.
ii) Have the settings saved in the
%APPDATA%\Surveillance\settings.ini
file. Have the installation program create the settings file, and ACL it to allow all users to have Full Control
iii) Store the settings in a the above mentioned registry key or ini file, and use
to add the UAC Shield to your Save/OK/Apply button. When the user pushes the button, you relaunch your app elevated (using RunAsAdmin), passing command line parameters indicating what you want to change.
iv) Do the same as 3, but do it before they can get into the screen that is used to edit the values.
v) Do the same as 4, but have the values initially read only, and if they want change them they have to elevate.
vi) Have the options disabled if the user is running as a standard user, and if they want to change them: right-click the executable and select
Run as administrator
If this is an option that a user was able to change whenever they liked (when you were running on Windows XP and the user was an administrator), then it seems that user's being able to edit the value at will is acceptable.
In this case you can just let the user type in the name of the server, as they were allowed to do before. If the user has permission to write to HKLM, then save the option there. Otherwise save it in HKCU. When reading which server to use, start with HKCU and move to HKLM if HKCU value is not there.