- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 Delphi,如何访问 .NET 的 System.Environment.SpecialFolder.LocalApplicationData 变量(适用于任何版本的 Windows)的等效变量?我以为我可以这样做:
dir := GetEnvironmentVariable('LOCALAPPDATA');
这适用于 Vista,但 XP 似乎没有默认设置该环境变量,至少在我的测试机器上是这样。
最佳答案
在Delphi中,特殊的系统文件夹路径常量在ShlObj.DCU中定义,并以CSIDL_后跟符号名的形式引用。示例:
这是一个快速函数,当给定符号名称时,它将返回适当的特殊文件夹路径。确保在 USES 语句中包含 SHLOBJ.DCU 单元,并使用以下内容:
function GetSpecialFolderPath(Folder: Integer; CanCreate: Boolean): string;
// Gets path of special system folders
//
// Call this routine as follows:
// GetSpecialFolderPath (CSIDL_PERSONAL, false)
// returns folder as result
//
var
FilePath: array [0..255] of char;
begin
SHGetSpecialFolderPath(0, @FilePath[0], FOLDER, CanCreate);
Result := FilePath;
end;
================================================== =================
作为引用,常量如下:
CSIDL_DESKTOP = $0000; { <desktop> }
CSIDL_INTERNET = $0001; { Internet Explorer (icon on desktop) }
CSIDL_PROGRAMS = $0002; { Start Menu\Programs }
CSIDL_CONTROLS = $0003; { My Computer\Control Panel }
CSIDL_PRINTERS = $0004; { My Computer\Printers }
CSIDL_PERSONAL = $0005; { My Documents. This is equivalent to CSIDL_MYDOCUMENTS in XP and above }
CSIDL_FAVORITES = $0006; { <user name>\Favorites }
CSIDL_STARTUP = $0007; { Start Menu\Programs\Startup }
CSIDL_RECENT = $0008; { <user name>\Recent }
CSIDL_SENDTO = $0009; { <user name>\SendTo }
CSIDL_BITBUCKET = $000a; { <desktop>\Recycle Bin }
CSIDL_STARTMENU = $000b; { <user name>\Start Menu }
CSIDL_MYDOCUMENTS = $000c; { logical "My Documents" desktop icon }
CSIDL_MYMUSIC = $000d; { "My Music" folder }
CSIDL_MYVIDEO = $000e; { "My Video" folder }
CSIDL_DESKTOPDIRECTORY = $0010; { <user name>\Desktop }
CSIDL_DRIVES = $0011; { My Computer }
CSIDL_NETWORK = $0012; { Network Neighborhood (My Network Places) }
CSIDL_NETHOOD = $0013; { <user name>\nethood }
CSIDL_FONTS = $0014; { windows\fonts }
CSIDL_TEMPLATES = $0015;
CSIDL_COMMON_STARTMENU = $0016; { All Users\Start Menu }
CSIDL_COMMON_PROGRAMS = $0017; { All Users\Start Menu\Programs }
CSIDL_COMMON_STARTUP = $0018; { All Users\Startup }
CSIDL_COMMON_DESKTOPDIRECTORY = $0019; { All Users\Desktop }
CSIDL_APPDATA = $001a; { <user name>\Application Data }
CSIDL_PRINTHOOD = $001b; { <user name>\PrintHood }
CSIDL_LOCAL_APPDATA = $001c; { <user name>\Local Settings\Application Data (non roaming) }
CSIDL_ALTSTARTUP = $001d; { non localized startup }
CSIDL_COMMON_ALTSTARTUP = $001e; { non localized common startup }
CSIDL_COMMON_FAVORITES = $001f;
CSIDL_INTERNET_CACHE = $0020;
CSIDL_COOKIES = $0021;
CSIDL_HISTORY = $0022;
CSIDL_COMMON_APPDATA = $0023; { All Users\Application Data }
CSIDL_WINDOWS = $0024; { GetWindowsDirectory() }
CSIDL_SYSTEM = $0025; { GetSystemDirectory() }
CSIDL_PROGRAM_FILES = $0026; { C:\Program Files }
CSIDL_MYPICTURES = $0027; { C:\Program Files\My Pictures }
CSIDL_PROFILE = $0028; { USERPROFILE }
CSIDL_SYSTEMX86 = $0029; { x86 system directory on RISC }
CSIDL_PROGRAM_FILESX86 = $002a; { x86 C:\Program Files on RISC }
CSIDL_PROGRAM_FILES_COMMON = $002b; { C:\Program Files\Common }
CSIDL_PROGRAM_FILES_COMMONX86 = $002c; { x86 C:\Program Files\Common on RISC }
CSIDL_COMMON_TEMPLATES = $002d; { All Users\Templates }
CSIDL_COMMON_DOCUMENTS = $002e; { All Users\Documents }
CSIDL_COMMON_ADMINTOOLS = $002f; { All Users\Start Menu\Programs\Administrative Tools }
CSIDL_ADMINTOOLS = $0030; { <user name>\Start Menu\Programs\Administrative Tools }
CSIDL_CONNECTIONS = $0031; { Network and Dial-up Connections }
CSIDL_COMMON_MUSIC = $0035; { All Users\My Music }
CSIDL_COMMON_PICTURES = $0036; { All Users\My Pictures }
CSIDL_COMMON_VIDEO = $0037; { All Users\My Video }
CSIDL_RESOURCES = $0038; { Resource Directory }
CSIDL_RESOURCES_LOCALIZED = $0039; { Localized Resource Directory }
CSIDL_COMMON_OEM_LINKS = $003a; { Links to All Users OEM specific apps }
CSIDL_CDBURN_AREA = $003b; { USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning }
CSIDL_COMPUTERSNEARME = $003d; { Computers Near Me (computered from Workgroup membership) }
CSIDL_PROFILES = $003e;
关于delphi - 访问 Delphi 中的 LocalApplicationData 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/471123/
有没有办法为我的 WCF 服务设置我的 app.config,以便它输出到 LocalApplicationData folder无需硬编码任何东西? %LOCALAPPDATA% 在 XP 下不起作
我正在查看具有枚举的特殊文件夹,例如 LocalApplicationData。在我的 Windows 7 机器上,我看到了那里的内容,首先我看到了几个 GUID 的子文件夹。我不知道它们是什么,并假
Visual Studio 中的所有内容似乎都会导致将数据文件与应用程序一起放置。app.config 就在那里,当我创建 .XML 数据文件时,有一个“复制到输出”属性,该属性会自动将该文件复制到e
使用 Delphi,如何访问 .NET 的 System.Environment.SpecialFolder.LocalApplicationData 变量(适用于任何版本的 Windows)的等效变
Documentation for Xamarin说您可以使用以下内容读取文本文件: File.ReadAllText(Path.Combine(Environment.GetFolderPath(E
总结:几个不同的用户将在特定机器上使用我的应用程序。我希望应用程序将其数据存储在这台机器上的单个公共(public)文件中,而不管哪个用户正在运行该应用程序。 为了实现我想要的,我想知道这个问题是否相
这可能应该很简单,但它一直让我头疼。基本上我正在创建一个应用程序来下载包含 html、css、javascript 等的 zip 文件。它解压内容并将其存储在 LocalApplicationData
在我的系统上,%AppData%导致 ApplicationData这是 C:\Users\\AppData\Roaming 但是还有C:\Users\\AppData\Local 还有一些困惑D:\
我收到错误“访问路径‘LocalApplicationData\MyProgram\’被拒绝。”尝试为我的日志文件创建目录时。这是我以非管理员用户身份运行程序的时候。 Directory.Create
我是一名优秀的程序员,十分优秀!