Win32Processes.GetHandles不存在

时间:2014-07-22 15:56:48

标签: c#

我正在尝试编译此源

class Program
{
    static void Main(string[] args)
    {

        String MutexName = "TibiaPlayerMutex";
        String ProcessName = "tibia";

        int i = 0;

        do
        {
            try
            {
                Process process = Process.GetProcessesByName(ProcessName)[0];
                var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\1\\BaseNamedObjects\\" + MutexName);
                if (handles.Count == 0) throw new System.ArgumentException("NoMutex", "original");
                foreach (var handle in handles)
                {
                    IntPtr ipHandle = IntPtr.Zero;
                    if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE))
                        Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error());

                    Console.WriteLine("Mutex was killed");
                }
            }
            catch { }
        } while (i == 0);
    }
}

我得到以下

  

名称' Win32Processes'在当前上下文中不存在d:\ users \ yorick grijseels \ documents \ visual studio 2013 \ Projects \ WindowsFormsApplication4 \ WindowsFormsApplication4 \ Program.cs 32 35 WindowsFormsApplication4

我用谷歌搜索了一下,但我找不到解决这个问题的方法,我错过了什么?

1 个答案:

答案 0 :(得分:0)

你错过了使事情有效的重要部分。 Delete a mutex from another process的问题部分包含您需要的课程(Win32APIWin32Processes)。