For development I use Code :: Blocks MinGW for Windows. My program requires administrator privileges.

How to programmatically request these rights from the user?

I read that for this you need a manifest, where you can register a mandatory launch with administrator rights. Where to add it and how to use it?

    2 answers 2

    <?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="xXx" type="win32"/> <description>xXx</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> </requestedPrivileges> </security> </trustInfo> </assembly> 

    and add something like this to the code:

     С++IDR_XPMANIFEST MANIFEST "xpmanifest.xml" 

    For the seven, the manifesto is as follows:

     <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <application> <!--The ID below indicates application support for Windows Vista --> <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> <!--The ID below indicates application support for Windows 7 --> <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> </application> </compatibility> </assembly> 
    • Answers can be edited using the edit button. - Nick Volynkin
    • if I am for C and not for pluses, is there no difference? - Corle
    1. Code :: Block is absolutely not suitable here. You can write the program even in a notebook.
    2. The USER can never, under any circumstances, give someone administrative rights.
    3. You did not specify the most important circumstance - in which OS are you going to do this? After all, the solution to the problem is entirely determined by the OS used.

    Judging by the fact that you mentioned MinGW, then we are talking about Windows. I’ll say that I don’t know the solution for this option. If we are talking about * NIX systems, then there you need to act as follows:

    1. A regular user creates an application.
    2. Root declares the executable file of this application its property.
    3. Root cocks the user ID change bit for this file.

    Then, when this application is started by an ordinary user, a valid ID will be set by the file master ID. And the owner of the file is root. Thus, within the framework of this application, an ordinary user gets root rights.

    In more detail you can read here:

    http://citforum.ru/operating_systems/unix/glava_15.shtml

    • How to understand, for example, let's take the Visual Studio IDE (yes, it’s about windows); by default, a project creates a manifest where you can set the program to run as an administrator. I think there is a solution in the codeblock - Corle
    • 2
      manifesto where you can register the launch of the program on behalf of the administrator - I fully admit. You can register anything. Manifesto is just an announcement of what we WISH. But in a real OS (even Windows), only the administrator can allow the launch of a user application with administrator rights. I fully admit that the manifesto somehow simplifies the task of the administrator. But, if indeed, an ordinary user can assign administrator rights to himself by writing a small text file, then I will be forced to repeat the favorite lyunixoid thesis: "Give me the Windows!" :-) - Sergey
    • @Sergey, the manifest allows the forced launch as administrator (as ПКМ → Запуск от имени администратора ). More precisely, it allows you to specify that, with limited privileges, the program will still not work (administrative utility, for example). Но, если и вправду, рядовой пользователь может присвоить себе права администратора путём написания небольшого текстового файла - if the user is not only working under an administrative account (by default), he also turned off UAC (the last line of defense) - he himself is an evil Buratin . - ߊߚߤߘ