问题描述
我的安装程序项目有一个自定义操作,它使用GetTempFileName在temp文件夹中创建临时文件。
My installer project has a custom action which is creating a temp file in the temp folder by using GetTempFileName.
GetTempFileName创建了一个空的临时文件。
GetTempFileName created a empty temp file.
但在此之后,它在写入临时文件时会抛出以下错误。
But after that it throws the following error when writing the temp file.
"访问c:\Users\xxxx \AppData \本地\\ \\ Temp\TBX4EDF.tmp已定义为"
"Access to c:\Users\xxxx\AppData\Local\Temp\TBX4EDF.tmp was defined"
此问题仅发生在我的客户端计算机上,即Windows 10。
The issue is happening at only my client machines which are windows 10.
管理员用户  ;或 使用"以管理员身份运行"的升级权限没有解决问题。
Administrator user or escalated privilege with "Run as Administrator" doesn't resolve the issue.
所以我不确定它是真正的权限问题还是一种MFC或c ++库。
So I'm not sure if it's a really permission issue or a kind of MFC or c++ libraries.
请参考下面的代码。
如果您有任何建议,我将不胜感激。
I will appreciate that if you have any suggestion.
TCHAR szTempPath[MAX_PATH];
if (GetTempPath(MAX_PATH, szTempPath) == 0)
{
return ERROR_INSTALL_FAILURE;
}
TCHAR szTempFile[MAX_PATH];
if (GetTempFileName(szTempPath, _T("TBX"), 0, szTempFile) == 0)
{
return ERROR_INSTALL_FAILURE;
}
CString sConfigPath;
sConfigPath.Format(_T("%s%s.config"), sDestDir, sProductName);
CString sLine;
TRY
{
CStdioFile fConfig(sConfigPath, CFile::modeRead);
CStdioFile fTemp(szTempFile, CFile::modeWrite);
while (fConfig.ReadString(sLine) != FALSE)
{
CString sTrim(sLine);
sTrim.Trim();
if (sTrim.Compare(_T("xxxxxxx")) == 0)
{
fTemp.WriteString(_T("yyyyyy"));
}
else
{
sLine.Append(_T("\n"));
fTemp.WriteString(sLine);
}
}
}
CATCH_ALL(e)
{
e->ReportError(); // shows what's going wrong
return ERROR_INSTALL_FAILURE;
}
END_CATCH_ALL
推荐答案
这篇关于通过GetTempFileName和GetTempPath创建的临时文件访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!