Results 1 to 2 of 2

Thread: OpenProcess returns DLL error 5

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    Question 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

  2. #2
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,294

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width