管理员权限请求

发布于 2024-08-19 19:26:09 字数 479 浏览 5 评论 0原文

如果我不“以管理员身份”运行程序,则会出现错误 访问冲突 ...在模块中...等...

尝试使用我的 ini 文件时出现错误。 如何避免错误或请求管理员权限。

(使用 C++Builder6 ,但 Delphi 代码对我来说也是可读的)

默认使用 ini

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

添加:

我认为我需要在安装应用程序后为文件夹添加规则 我用 Inno Setup 制作安装包...希望这是真的。

*****添加: *****

如何将我的文件放入应用程序数据中?

I've got error if I don't run my program "As Administrator"
Access violation ... in module ... etc...

Got error when trying to work with my ini file.
How to avoid error or make a request Administrator rights.

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

working with ini by default

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

Added :

I think I need add rules for folder after install application
I make install pack with Inno Setup ... Hope that's real.

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

How to put my file into app data ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

咽泪装欢 2024-08-26 19:26:09

不要将 ini 文件放在应用程序中/除非确实需要/。普通用户,甚至管理员/当应用程序未明确提升时/无权写入 Program Files 文件夹。
如果要写入可供所有用户访问的 ini,请使用环境变量 %ProgramData%;如果要写入仅当前用户可访问的用户特定数据,请使用环境变量 %USERPROFILE%\AppData\Roaming。
您还可以按顺序使用“SHGetFolderPath”通过API获取这些文件夹。

Don't put the ini file along the application /unless you really have to/. The common user, even the administrator /when app not explicitly elevated/ has no right to write into the Program Files folder.
Use environment var %ProgramData% if you want to write the ini accessible for all users, and use env var %USERPROFILE%\AppData\Roaming if you want to write user specific data accessible only by the current user.
You can use also "SHGetFolderPath" in order to obtain these folder via API.

怪我闹别瞎闹 2024-08-26 19:26:09

这是我编写的用于在 C++Builder 中获取应用程序数据文件夹的函数。

如果您使用旧版本的 C++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's 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;
}

Here's a function I wrote to get the Application Data folder in C++Builder.

If you're using older versions of C++Builder, you might find you have to change this to use AnsiStrings instead of Unicode (replace the "UnicodeString"s with "AnsiString"s, and change the call to "SHGetSpecialFolderPathW" to read "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's 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;
}
森罗 2024-08-26 19:26:09

尝试对其进行硬编码,访问冲突可能来自于向系统询问用户可能有权或可能无权了解的文件信息。如果您需要更动态的解决方案,请尝试使用引用文件或用户“主”文件夹位置的环境变量

Try hard coding it, the access violation is probably coming from asking the system for information about a file that the user may or may not have permissions to know about. if you need a more dynamic solution try using an environment variable that refers to the location of the file or the users "home" folder

疯了 2024-08-26 19:26:09

有什么理由支持/反对将您的应用程序配置存储在注册表中?我并不是建议您重做提出问题的代码,只是对我自己未来的项目感到好奇。

Any reasons for/against storing your app configuration in the registry? I'm not suggesting you redo the code that brought up the question, just curious for my own future projects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文