OpenProcess returns DLL error 5
Hello!
I want to shut down a process (namely AnyDesk.exe).
AnyDesk.exe has 2 processes.
I can terminate one of them using this code below, but for the other, OpenProcess fails with error code 5 (ERROR_ACCESS_DENIED).
What do I have to do to be able to terminate this process, too?
Thank you very much!
Code:
Public Sub KillProcess(ByVal target_process_id As Long)
Dim target_process_handle As Long
target_process_handle = OpenProcess( _
SYNCHRONIZE Or PROCESS_TERMINATE, _
ByVal 0&, target_process_id)
If target_process_handle = 0 Then
MsgBox "Dll Error " & Err.LastDLLError & " occured while trying to open process."
Exit Sub
End If
If TerminateProcess(target_process_handle, 0&) = 0 Then
Debug.Assert False
'MsgBox "Error terminating process"
Else
' MsgBox "Process terminated"
End If
CloseHandle target_process_handle
End Sub
Re: OpenProcess returns DLL error 5
That’s probably an access denied error. I didn’t Google it explicitly though. The following thread had a couple good thoughts on it:
https://stackoverflow.com/questions/...-access-denied
If you haven’t done so already I would start with making sure your code is running as admin (this means the ide during development) and also adding code to enable the sedebug privledge
https://github.com/dzzie/libs/blob/b...sInfo.cls#L951