Skip to content

Ignore RmGetList() error 5: Access is denied.#42

Merged
domsleee merged 1 commit intomainfrom
fix-rmgetlist-returns-error-5
May 31, 2024
Merged

Ignore RmGetList() error 5: Access is denied.#42
domsleee merged 1 commit intomainfrom
fix-rmgetlist-returns-error-5

Conversation

@domsleee
Copy link
Owner

@domsleee domsleee commented May 31, 2024

The RestartManager API can throw error 5: Access is denied.. It should be ignored, sometimes the user wants to ignore files owned by the administrator, for example.

Previous behaviour

❯ forceops rm .\aaa.txt
Unhandled exception: System.ComponentModel.Win32Exception (5): Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
   at LockCheck.Windows.RestartManager.GetLockingProcessInfos(String[] paths) in /_/LockCheck/Windows/RestartManager.cs:line 72
   at LockCheck.LockManager.GetLockingProcessInfos(String[] paths, LockManagerFeatures features) in /_/LockCheck/LockManager.cs:line 21
   at ForceOps.Lib.FileAndDirectoryDeleter.<>c__DisplayClass4_0.<DeleteFile>b__0() in /_/ForceOps.Lib/src/FileAndDirectoryDeleter.cs:line 58
   at ForceOps.Lib.FileAndDirectoryDeleter.KillProcessesAndLogInfo(Boolean isDirectory, Int32 attemptNumber, String fileOrDirectoryPath, Func`1 getProcessesLockingFileFunc) in /_/ForceOps.Lib/src/FileAndDirectoryDeleter.cs:line 78
   at ForceOps.Lib.FileAndDirectoryDeleter.DeleteFile(FileInfo file) in /_/ForceOps.Lib/src/FileAndDirectoryDeleter.cs:line 59
   at ForceOps.Lib.FileAndDirectoryDeleter.DeleteFileOrDirectory(String fileOrDirectory, Boolean force) in /_/ForceOps.Lib/src/FileAndDirectoryDeleter.cs:line 30
   at ForceOps.ForceOps.<>c__DisplayClass8_0.<DeleteCommand>b__0() in /_/ForceOps/src/ForceOps.cs:line 94
   at ForceOps.ForceOps.RunWithRelaunchAsElevated(Action action, Func`1 buildArgsForRelaunch, Boolean disableElevate) in /_/ForceOps/src/ForceOps.cs:line 133
   at ForceOps.ForceOps.DeleteCommand(String[] filesOrDirectoriesToDelete, Boolean force, Boolean disableElevate, Int32 retryDelay, Int32 maxRetries) in /_/ForceOps/src/ForceOps.cs:line 86

New behaviour

❯ forceops rm .\aaa.txt
[22:48:45 WRN] Ignored exception: Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
[22:48:45 INF] Could not delete file "C:\Users\user\aaa.txt". Beginning retry 1/10 in 50ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].
[22:48:45 WRN] Ignored exception: Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
[22:48:45 INF] Could not delete file "C:\Users\user\aaa.txt". Beginning retry 2/10 in 50ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].
[22:48:45 WRN] Ignored exception: Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
[22:48:45 INF] Could not delete file "C:\Users\user\aaa.txt". Beginning retry 3/10 in 50ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].
[22:48:46 WRN] Ignored exception: Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
[22:48:46 INF] Could not delete file "C:\Users\user\aaa.txt". Beginning retry 4/10 in 50ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].
[22:48:46 WRN] Ignored exception: Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
[22:48:46 INF] Could not delete file "C:\Users\user\aaa.txt". Beginning retry 5/10 in 50ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].
[22:48:46 WRN] Ignored exception: Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
[22:48:46 INF] Could not delete file "C:\Users\user\aaa.txt". Beginning retry 6/10 in 50ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].
[22:48:46 WRN] Ignored exception: Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
[22:48:46 INF] Could not delete file "C:\Users\user\aaa.txt". Beginning retry 7/10 in 50ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].
[22:48:46 WRN] Ignored exception: Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
[22:48:46 INF] Could not delete file "C:\Users\user\aaa.txt". Beginning retry 8/10 in 50ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].
[22:48:46 WRN] Ignored exception: Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
[22:48:46 INF] Could not delete file "C:\Users\user\aaa.txt". Beginning retry 9/10 in 50ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].
[22:48:46 WRN] Ignored exception: Failed to get entries (retry 0). (RmGetList() error 5: Access is denied.)
[22:48:46 INF] Could not delete file "C:\Users\user\aaa.txt". Beginning retry 10/10 in 50ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].
[22:48:46 INF] Exceeded retry count of 10. Failed. ForceOps process is not elevated.
[22:48:46 INF] Unable to perform operation as an unelevated process. Retrying as elevated and logging to "C:\Users\user\AppData\Local\Temp\tmpgkkdu1.tmp".
[22:48:47 INF] Successfully deleted as admin

@domsleee domsleee force-pushed the fix-rmgetlist-returns-error-5 branch 2 times, most recently from d901698 to 1818b79 Compare May 31, 2024 12:46
@domsleee domsleee force-pushed the fix-rmgetlist-returns-error-5 branch from 1818b79 to 4c37ce3 Compare May 31, 2024 12:51
@domsleee domsleee changed the title Handle RmGetList() error 5: Access is denied. Ignore RmGetList() error 5: Access is denied. May 31, 2024
@domsleee domsleee merged commit b3c99bd into main May 31, 2024
@domsleee domsleee deleted the fix-rmgetlist-returns-error-5 branch May 31, 2024 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant