Request Administrator Rights

I have an error if I do not run my program "As an administrator" Access violation ... in the module ... etc.

An error occurred while trying to work with my ini file. How to avoid an error or make an administrator rights request.

(using C ++ Builder6, but Delphi code is also readable for me)

works with ini by default

TIniFile *FormCllient;
        FormCllient = new TIniFile(ExtractFilePath(Application->ExeName)+"Inf\\MyIniFile.ini");
...

Added:

It seems to me that I need to add rules for the folder after installing the application. I am doing the installation package with Inno Setup ... I hope this is real.

***** Added: *****

How to put a file in application data?

+3
source share
4 answers

, , Application Data ++ Builder.

++ Builder, , AnsiStrings Unicode ( "UnicodeString" "AnsiString" s "SHGetSpecialFolderPathW" "SHGetSpecialFolderPath" ).

GetAppDataFolder.h:

#ifndef GetAppDataFolderH
#define GetAppDataFolderH

UnicodeString GetAppDataFolder(bool roaming = true);

#endif

GetAppDataFolder.cpp:

// Helper function to get the location of the current user Application Data folder (used for
// storing per-user application settings).

#include <vcl.h>
#pragma hdrstop


/*  roaming:    True for application data that can be accessed by the same user on different
                machines. If you have per-user settings that are only relevant to a particular
                computer, e.g., screen resolution, set 'roaming' to false.
*/
UnicodeString GetAppDataFolder(bool roaming /* = true */)
{
    UnicodeString retVal;
    int csidl = roaming ? CSIDL_APPDATA : CSIDL_LOCAL_APPDATA;
    wchar_t thePath[MAX_PATH];
    if (SHGetSpecialFolderPathW(NULL, thePath, csidl, 0) == TRUE) {
        retVal = thePath;
    }
    return retVal;
}
+2

ini /, /. , / / Program Files. var% ProgramData%, ini, , env var% USERPROFILE%\AppData\Roaming, , . SHGetFolderPath", API.

+3

, , , - . , , "home"

0
source

Any reasons to save your application configuration in the registry? I do not suggest you repeat the code that raised the question, just curious for my own future projects.

0
source

Source: https://habr.com/ru/post/1730829/


All Articles