{"action":"created","issue":{"url":"https://api.github.com/repos/Squirrel/Squirrel.Windows/issues/267","labels_url":"https://api.github.com/repos/Squirrel/Squirrel.Windows/issues/267/labels{/name}","comments_url":"https://api.github.com/repos/Squirrel/Squirrel.Windows/issues/267/comments","events_url":"https://api.github.com/repos/Squirrel/Squirrel.Windows/issues/267/events","html_url":"https://github.com/Squirrel/Squirrel.Windows/issues/267","id":59975871,"number":267,"title":"Uninstalling leaves the rootAppDirectory behind if there is an in-use shell extension in it.","user":{"login":"theofanis","id":6344512,"avatar_url":"https://avatars.githubusercontent.com/u/6344512?v=3","gravatar_id":"","url":"https://api.github.com/users/theofanis","html_url":"https://github.com/theofanis","followers_url":"https://api.github.com/users/theofanis/followers","following_url":"https://api.github.com/users/theofanis/following{/other_user}","gists_url":"https://api.github.com/users/theofanis/gists{/gist_id}","starred_url":"https://api.github.com/users/theofanis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theofanis/subscriptions","organizations_url":"https://api.github.com/users/theofanis/orgs","repos_url":"https://api.github.com/users/theofanis/repos","events_url":"https://api.github.com/users/theofanis/events{/privacy}","received_events_url":"https://api.github.com/users/theofanis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-05T16:25:06Z","updated_at":"2015-03-06T10:13:07Z","closed_at":null,"body":"Obviously, since if the extension is loaded with explorer.exe before uninstalling, then it's in use so Squirrel fails to delete it, thus leaving the app install directory behind with the extension dll in it.\r\n\r\nOf course, this happens even when unregistering the dll on uninstall, because of the above reason.\r\n\r\nRefreshing the explorer does not work, as expected. Now you can tell me that I could kill and restart explorer.exe, but that would close any windows the user may have opened before. Imaging killing explorer.exe when a file move is ongoing.\r\n\r\nAny ideas how this could be handled better?"},"comment":{"url":"https://api.github.com/repos/Squirrel/Squirrel.Windows/issues/comments/77535922","html_url":"https://github.com/Squirrel/Squirrel.Windows/issues/267#issuecomment-77535922","issue_url":"https://api.github.com/repos/Squirrel/Squirrel.Windows/issues/267","id":77535922,"user":{"login":"theofanis","id":6344512,"avatar_url":"https://avatars.githubusercontent.com/u/6344512?v=3","gravatar_id":"","url":"https://api.github.com/users/theofanis","html_url":"https://github.com/theofanis","followers_url":"https://api.github.com/users/theofanis/followers","following_url":"https://api.github.com/users/theofanis/following{/other_user}","gists_url":"https://api.github.com/users/theofanis/gists{/gist_id}","starred_url":"https://api.github.com/users/theofanis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theofanis/subscriptions","organizations_url":"https://api.github.com/users/theofanis/orgs","repos_url":"https://api.github.com/users/theofanis/repos","events_url":"https://api.github.com/users/theofanis/events{/privacy}","received_events_url":"https://api.github.com/users/theofanis/received_events","type":"User","site_admin":false},"created_at":"2015-03-06T10:13:07Z","updated_at":"2015-03-06T10:13:07Z","body":"After going through squirrel's code once more, I see ```MoveFileEx``` with ```MOVEFILE_DELAY_UNTIL_REBOOT``` flag is used to do this.\r\n\r\nAFAIK, ```MoveFileEx```, which is used for this in Utility class, needs elevated privileges to write to ```HKLM```. Check documentation and especially remarks [here](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396):\r\n\r\n```\r\nIf the dwFlags parameter specifies MOVEFILE_DELAY_UNTIL_REBOOT, MoveFileEx fails if it cannot access the registry. The function stores the locations of the files to be renamed at restart in the following registry value:\r\nHKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\PendingFileRenameOperations\r\n```\r\nI don't see this key in my registry.\r\n\r\nSince my app, and slack for that matter, don't need elevated privileges, and when uninstalling I don't see the UAC dialog, ```MoveFileEx``` obviously fails.\r\n\r\nI see that ```Utility.DeleteDirectoryAtNextReboot``` does things in a correct order, it marks files in top level and in subdirectories for removal and then marks subdirectories and top directory for removal. I also see the comment that says this will blow up if the user is non-admin.\r\n\r\nSince, Squirrel advertises that it doesn't prompt any UAC dialogs, why is that there, since it obviously won't work for any non-admin user.\r\n\r\nBtw, interesting [article](http://marc.durdin.net/2011/09/why-you-should-not-use-movefileex-with-movefile_delay_until_reboot-2/) about ```MoveFileEx``` usage with an interesting comment:\r\n\r\n```\r\nRename the DLL file first (coolcorelibrary.old), and then mark it for deletion. You can rename a DLL while loaded into a process, and applications will continue using the original DLL until it is unloaded, while any new applications will use the new one.\r\n```\r\n"}}