Sysmon Uninstall successful but leaving locked executable

Chris Smith 6 Reputation points
2022-12-21T16:55:27.197+00:00

Using the command "Sysmon -u force", I am able to uninstall Sysmon successfully with a return code of 0, however I'm finding it sometimes leaves the Sysmon.exe executable in C:\Windows. When trying to delete this executable, via cmd shell or Powershell, up to and including "Remove-item -force", I'm finding that the executable is locked by the Windows Event Log service and unable to be deleted. Has anyone else seen this before, and is there a way to handle this without rebooting? I'm not having any luck with Stop-service -name EventLog either, due to the service dependencies.

Windows for business | Windows Server | User experience | PowerShell
Sysinternals
Sysinternals
Advanced system utilities to manage, troubleshoot, and diagnose Windows and Linux systems and applications.
1,260 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,346 Reputation points
    2022-12-21T17:38:45.56+00:00

    Without rebooting? Probably not. If you tell Windows to delete a file and that file is still in use by another process then it can get into a state where the file is permanently locked until reboot. Windows Explorer is notorious for this in my experience.

    In theory you could use Process Explorer or perhaps Handles to search for any running processes that have a handle to this file and then try to stop the process but in my experience some of those processes are system processes and cannot be terminated, hence a reboot is needed.

    Is it a really big deal if the file remains around until a reboot? What most uninstall code does is attempt to delete the file and, if that fails, add the file to the list of files to be removed at next reboot. The file remains around until the next reboot and is then removed early in the boot process. The downside is that you cannot put a new copy of the file in that same location but this might not be an issue for you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.