Andrey Balaguta
Andrey Balaguta

Reputation: 1308

Elevated process in Vista does not overwrite files

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__The_Definitive_Guide.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.

Upvotes: 1

Views: 457

Answers (2)

Kirill V. Lyadvinsky
Kirill V. Lyadvinsky

Reputation: 99695

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}"/>
      <!--The ID below indicates application support for Windows 8 -->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
    </application>
  </compatibility>

Upvotes: 3

Andrey Balaguta
Andrey Balaguta

Reputation: 1308

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!

Upvotes: 0

Related Questions