工作问题积累(一)win7系统下copyfile(..,..false)函数失效问题[权限问题]

       这个问题出现在自己管理的项目中,之前上线了半年没出现过问题,直到最近有个用户装的是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

 

  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值