这个问题出现在自己管理的项目中,之前上线了半年没出现过问题,直到最近有个用户装的是win7英文版的系统,项目里面的自动更新程序一直没法调用,花了4个多小时的调试,终于定位到了问题,copyfile()失效了!
【代码】:
while( !CopyFile( FileMisc::GetFullPath(kUpgradeExeName), strLiveUpdateExe , FALSE ) && -- retry ){//这个就是调用copyfile函数的地方
Sleep( 1000 );
}
if( !FileMisc::FileExist( strLiveUpdateExe) ){
LOG( INFO )<<"自动更新进程不存在:"<< strLiveUpdateExe;
return;
}
CString strCmdLine = GetUpgradeLobbyCommandLine( style,operation );
InvokeLiveUpdate( strLiveUpdateExe, _upgradeLobbyProcessID,strCmdLine );
【解析】:
原因是程序安装在了C盘下面,使用copyfile函数时由于不是管理员权限,该条语句就会执行失效.
方法:
添加manifest,在manifest文件中配置 requestedExecutionLevel 为 RequireAdministrator。
<requestedExecutionLevel level="asInvoker" uiAccess="false" /> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> <requestedExecutionLevel level="highestAvailable" uiAccess="false" />
具体操作参看:http://support.microsoft.com/kb/944276/zh-cn
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
processorArchitecture="x86"
version="5.1.0.0"
type="win32"
name="LiveUpdate"
/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
【参考链接】
http://www.cnblogs.com/mumuliang/p/3465359.html