Where is the file if the Filename parameter is NULL in WritePrivateProfileString

huangapple go评论60阅读模式
英文:

Where is the file if the Filename parameter is NULL in WritePrivateProfileString

问题

当我使用winbase.h和windows.h来读写.ini文件时,我发现可以使用以下函数成功保存设置:

bool b = WritePrivateProfileStringA("App","key","test", NULL);

但是我找不到这个文件。它在哪里?

另一方面,我可以使用以下代码获取设置:

GetPrivateProfileStringA("App", "key", "default", s, 20,0);

而且它不需要管理员权限来写入文件,所以我认为它应该在用户目录中。

英文:

When I use winbase.h and windows.h to read/write .ini file, I found that I can use the function

bool b = WritePrivateProfileStringA("App","key","test", NULL);
successfully to save the settings.

But I can not found the file. Where is it?

On the other hand, I can use

GetPrivateProfileStringA("App", "key", "default", s, 20,0);

to get the setting.

And it did not need administrator privileges to write the file, so I think it should be in a user directory.

答案1

得分: 0

我找到了。它被写入了Windows注册表的HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\win.ini位置。它包含了应用程序名称的目标路径,不区分大小写。顺便提一下,USR代表的是HKEY_CURRENT_USER。

如果具有管理员权限,它会被写入到C:\Windows\win.ini文件中。

英文:

I found it. It was written to windows registry HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\win.ini It has the destination for appname which is case-insensitive, by the way USR means HKEY_CURRENT_USER.

If it has administrator privileges, it was written to C:\Windows\win.ini

huangapple
  • 本文由 发表于 2023年7月27日 17:44:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76778477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定