-1

I am trying to create an updater which will replace the files in the folder without needing an installer. As part of this process, I need to be able to delete old files and replace them by new files. I tried it and got an UnAuthorizedException. I am runing the updater as administrator. I tried the following a. Setting the file and folder attribute to Normal [Access to the path is denied when trying to delete a certain directory b. Taking ownership of the folder and files contained in it [Taking ownership of a file or folder c. Changing the permissions and giving all users full control over the folder and files [Using a custom action in the installer] [How to give Read/Write permissions to a Folder during installation using .NET d. Running the updater from a windows service

There is no difference in the results. I keep getting the access denied error. What do I do so that the updater can delete the files?

Sagar Kapadia
  • 105
  • 1
  • 9
  • 1
    Please try to give path access to "Everyone" with "FullControl" – gulshan arora Sep 10 '18 at 06:40
  • You can try this: https://superuser.com/questions/1031275/windows-allow-normal-non-elevated-programs-to-write-to-program-files-director – Nhan Phan Sep 10 '18 at 06:44
  • Thanks @gulshanarora and Nhan Phan. It worked. The files which did not get deleted were those in use by the application – Sagar Kapadia Sep 10 '18 at 08:55
  • Thanks ! Can you please "Vote up " for my answer so that it will help to others. – gulshan arora Sep 10 '18 at 09:43
  • Just for the record: replacing in-use files and performing elevated operations such as replacing files under `%ProgramFiles%` are key functionalities supported by MSI packages (Windows Installer) and other package types as well. Advanced functionality such as [Restart Manager](https://stackoverflow.com/a/50935008/129130) exist to handle in-use files and any required reboots. And there are many other issues: disk space checking, transaction & rollback, etc... Using this functionality will help you in the long run. Just my 2 cents from experience. It all depends how big your product is I guess. – Stein Åsmul Sep 10 '18 at 10:02

1 Answers1

1

It's not clear exactly what you mean by "running as administrator", but being logged in as administrator and running a program does not mean that the program is running with elevated privilege, which is what it really needs. But clearly the updater program is not running elevated.

So the issue might be that this updater program of yours needs an elevation manifest so that when you run it, it will ask for elevation with a UAC prompt.

Having said that, simply replacing files that were installed with a Windows installer MSI is not supported. The files must be replaced with a Windows Installer update such as a patch .msp file or an upgraded MSI file. Windows Installer keeps track of every file installed, and it's version and whether it's been updated or not, as well as a filehash. Replacing a file without using Windows Installer can result in unexpected demands for the original MSI file in order that Windows can restore the files to their original installed state. You might find that going to Programs&Features (or right-clicking the MSI file) and choosing repair will also restore them.

PhilDW
  • 20,260
  • 1
  • 18
  • 28