- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用Delphi 2010,我的程序想要获取系统的临时路径。我正在使用 TPath.GetTempPath 并且一切正常......至少对于我和我的同事来说。但在某些客户计算机上,此方法返回(当然)不存在的裁剪路径。我发现问题似乎是底层调用 GetLongPathName() 的结果。
完整的代码如下所示:
[...]
var
TmpDir : String;
Len : Integer;
begin
[... Call to GetTempPath succeeds and we have a valid temp directory in short "~" notation in var TmpDir ...]
Len := GetLongPathName(PChar(TmpDir), nil, 0); // Len = 37
SetLength(TmpDir, Len - 1); // We want to set the len of TmpDir to 37 - 1.
GetLongPathName(PChar(TmpDir), PChar(TmpDir), Len); // Only 32 (instead of 36) characters are copied - so we have a cropped path - But why?!
end;
[...]
这只发生在某些系统上,我不知道为什么。我找到了一个令人讨厌的解决方法,但我想知道这里发生了什么。
有人可以解释一下吗?
最佳答案
国土安全页面上有关于此 Windows API 函数的注释:
"The return buffer for GetLongPathName() and similar functions might return a truncated path and lead to hard-to-find errors."
https://buildsecurityin.us-cert.gov/bsi-rules/home/g1/753-BSI.html
如果您有源代码,您可以检查一下Delphi 2010实现中是否存在本文所述的问题。
关于Delphi TPath.GetTempPath 结果被裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3440492/
我在 Windows 8 上使用 MFC。当我得到 Temp 路径时,它包含指向不同用户帐户的路径: C:\Users\AACE~1\AppData\Temp 写入文件的权限已关闭,CFile 失
这个问题在这里已经有了答案: Defining buffer size correct "Stack around the variable String was corrupted" (1 个回答
我正在使用Delphi 2010,我的程序想要获取系统的临时路径。我正在使用 TPath.GetTempPath 并且一切正常......至少对于我和我的同事来说。但在某些客户计算机上,此方法返回(当
我有一个调用另一个可执行文件的 Web 服务,该可执行文件获取文件列表并将它们存储在临时位置,然后由 Web 服务读取。 我想我会使用系统的临时文件夹,发现我可以使用 System.IO.Path.G
我编写了一个调用 System.IO.Path.GetTempPath() 函数的程序。我阅读的所有文档 (like this one)表示该函数应返回从此列表中找到的第一条路径: TMP环境变量指定
我认为我在系统上遇到了一个关于环境变量 TMP 的特殊问题。 这个变量是这样定义的: TMP=c:\profiles\myUser\LOKALE~1\temp 无法通过 .net 应用程序写入此位置,
我试图在模拟下运行 ASP.net 2.0 站点,但似乎出了点问题。我撤消了对 ASP.Net IIS 配置小程序的更改。 但是现在我遇到了这个错误 System.UnauthorizedAccess
目前,我使用 Path.GetTempPath() 来确定将我的日志文件写入何处,但最近我遇到了一个用户的机器,其中返回的路径不是我预期的。 通常,返回的路径是C:\Documents and Set
我正在从 ftp 服务器下载文件并将其保存到 Path.GetTempPath() 中定义的目录;但是,我收到以下错误:找不到路径的一部分。 我已经确认返回的路径是正确的:C:\Users\[用户名]
我有一个调用 GetTempPathW 并尝试在返回的目录中创建临时文件的测试。当我直接运行测试时,GetTempPathW 返回 C:\Users\sgreens\AppData\Local\Tem
大多数使用我的加载项的应用程序返回“C:\Users\[用户名]\AppData\Local\Temp\”路径。但是一个应用程序返回“C:\Users\[用户名]\AppData\Local\Temp
我是一名优秀的程序员,十分优秀!