선언:

C#

[DllImport("kernel32")]
public static extern Int32 DebugActiveProcessStop(Int32 ProcessId);


VB.NET

<DllImport("kernel32")> _
Public Shared Function DebugActiveProcess(ProcessId As Int32) As Int32
End Function




사용 예제:

C#

using System;
using System.Runtime.InteropServices;

namespace ApiReference {
    class ApiExample {
        [DllImport("kernel32")]
        public static extern Int32 DebugActiveProcess(Int32 ProcessId);
        [DllImport("kernel32")]
        public static extern Int32 DebugActiveProcessStop(Int32 ProcessId);
        
        public static void Main(string[] args) {
        EnterPID:
            Console.Write("디버그할 프로세스의 식별자(PID)를 입력하세요: ");
            Int32 pid;
            try {
                pid = Int32.Parse(Console.ReadLine());
            } catch (Exception) {
                Console.WriteLine("다시 입력하세요");
                goto EnterPID;
            }
            
            if ( DebugActiveProcess(pid) != 0 ) {
                Console.WriteLine("프로세스 디버그 성공!");
                Console.WriteLine("이제 디버그를 풀어보겠습니다...");
                if ( DebugActiveProcessStop(pid) != 0 )
                    Console.WriteLine("프로세스 디버그 풀기도 성공!");
                else
                    Console.WriteLine("프로세스 디버그 풀기 실패!.... 어떻하죠...");
            }
            else
                Console.WriteLine("프로세스 디버그 실패!");
                
            Console.ReadKey(true);
        }
    }
}


VB.NET

Imports System
Imports System.Runtime.InteropServices

Namespace ApiReference
    Class ApiExample
        <DllImport("kernel32")> _
        Public Shared Function DebugActiveProcess(ProcessId As Int32) As Int32
        End Function
        <DllImport("kernel32")> _
        Public Shared Function DebugActiveProcessStop(ProcessId As Int32) As Int32
        End Function

        Public Shared Sub Main(args As String())
            EnterPID:
            Console.Write("디버그할 프로세스의 식별자(PID)를 입력하세요: ")
            Dim pid As Int32
            Try
                pid = Int32.Parse(Console.ReadLine())
            Catch generatedExceptionName As Exception
                Console.WriteLine("다시 입력하세요")
                GoTo EnterPID
            End Try

            If DebugActiveProcess(pid) <> 0 Then
                Console.WriteLine("프로세스 디버그 성공!")
                Console.WriteLine("이제 디버그를 풀어보겠습니다...")
                If DebugActiveProcessStop(pid) <> 0 Then
                    Console.WriteLine("프로세스 디버그 풀기도 성공!")
                Else
                    Console.WriteLine("프로세스 디버그 풀기 실패!.... 어떻하죠...")
                End If
            Else
                Console.WriteLine("프로세스 디버그 실패!")
            End If

            Console.ReadKey(True)
        End Sub
    End Class
End Namespace




예제 실행 결과:




매개 변수 설명:

ProcessId - 디버그를 해제할 프로세스의 식별자를 입력합니다.




API 설명:

디버깅된 프로세스의 디버그를 해제합니다.




참고:

DebugActiveProcessStop (MSDN)




비고:

DebugActiveProcess API 혹은 다른 방법을 이용해 프로세스를 디버그한 경우, 반드시 디버그를 해제해야 좀비 프로세스로 남지 않습니다.



'API Reference' 카테고리의 다른 글

26. InitiateSystemShutdown  (0) 2014.10.08
25. GetCurrentProcessId  (0) 2014.10.07
23. SetWindowText  (0) 2014.10.06
22. GetWindowTextLength  (0) 2014.10.04
21. GetWindowText  (0) 2014.10.04

+ Recent posts