Tuesday 15 July 2014

c++ - Conditional Windows administrator prompt -


I am writing C + + DLL to connect to a MySQL database. Among other things, it tries to add an exception to the Windows Firewall list, so that it can connect to the telecommunications MySQL server via TCP (port 3306). When I try to add the port, I get the HRESULT of E_ACCESSDENIED , as long as I run the program as an administrator.

I want to point out an Administrator password for the user, but only when the port is not already in the Exception list. This means that I can not just create one, because the setting of level = "requireAdministrator" always indicates an administrator password, as far as I can tell. Can I Conditionally Get An Administrator Prompt?

According to your request, I am giving an answer to my comments.


The correct way to do this is to let users in your DLL handle the situation themselves. As an API developer, definitely your job is not to no to worry about things like firewall: either the API user and / or end-user made sure that it works, or You fail honestly. As the other people have said, the interval user can not be able to answer UAC requests (eg on the headless server), so you should not rely on your DLL which is being used in an interactive context. This is not your responsibility.


If you actually your original idea (which, I will again walk with stress, a bad idea IMHO) will be my best bet.

  • And a different .exe
  • Code> with a manifest that requires administrator privileges , Which can only be run by your DLL when it is needed.

    Just make this a requirement so that both of them are stored in the same directory so that you can easily get your DLL (and thus with GetModuleFileName .exe 's) directory.

    Others have indicated runas or rundll (which are equally valid answers IMO) but I am more of a UNIX-V type So I have a different binary suggestion. I feel much easier to maintain it for a long time.


    A solution is "in the middle" that your DLL does not bother with the firewall at all (as it should be) but you should provide a completely different device (. Exe with the manifest) that helps your users set up the firewall correctly, this may be the best solution: clean design (separating responsibility) and still you can provide users with all the necessary tools Areas are.

  • No comments:

    Post a Comment