小编The*_*ter的帖子

复制后关闭句柄

我试图关闭外部进程的互斥体的句柄。因此,我尝试使用Win32API 中的 DuplicateHandle,如该线程所示。

关闭目标进程的句柄是有效的。将其复制到我当前的进程后将其关闭,但不会。奇怪的是,它似乎还重复了两次手柄!

public class Win32API
    {
        [DllImport("ntdll.dll")]
        public static extern int NtQueryObject(IntPtr ObjectHandle, int
            ObjectInformationClass, IntPtr ObjectInformation, int ObjectInformationLength,
            ref int returnLength);

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern uint QueryDosDevice(string lpDeviceName, StringBuilder lpTargetPath, int ucchMax);

        [DllImport("ntdll.dll")]
        public static extern uint NtQuerySystemInformation(int
            SystemInformationClass, IntPtr SystemInformation, int SystemInformationLength,
            ref int returnLength);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern IntPtr OpenMutex(UInt32 desiredAccess, bool inheritHandle, string name);

        [DllImport("kernel32.dll")]
        public static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] …
Run Code Online (Sandbox Code Playgroud)

.net c# winapi

3
推荐指数
1
解决办法
1727
查看次数

标签 统计

.net ×1

c# ×1

winapi ×1