tags:

views:

229

answers:

2

Hello!

I'm trying to run elevated process, say, file_copier.exe, from another host process with ShellExecuteEx and lpVerb = "runas" on Vista. It shows UAC dialog and runs elevated, and copies files to "dangerous" folders, but it does not overwrite existing files (exe's).

I've read here: http://www.codeproject.com/KB/vista-security/UAC%5F%5FThe%5FDefinitive%5FGuide.aspx that UAC does not actually overwrite existing files but stores new files in a cache of some sort. But I can't figure out (if it is the case), how to make it actually overwrite existing files. Any help is appreciated.

+1  A: 

You are talking about virtualization of file system. To tell Windows that your program are aware of Windows rules you should change your manifest file.

Add to the manifest the following text:

  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!--The ID below indicates application support for Windows Vista -->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
      <!--The ID below indicates application support for Windows 7 -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
    </application>
  </compatibility>
Kirill V. Lyadvinsky
A: 

Sorry guys it was just my mistake. The code was like this:

ShellExecuteEx(file_copier.exe);
LaunchFreshVersionOfApplication();

Indeed, ShellExecuteEx returned before the file_copier.exe process finished. So the later process could not update running files. Thanks for your answer, Kirill!

Andy
Then why not give Kirill his deserved rep by giving him the checkmark?
Billy ONeal
With pleasure, but my reputation is only 9, and voting requires 15, sorry.
Andy