-1

I am trying to compile this source

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);
    }
}

Iam getting the following

The name 'Win32Processes' does not exist in the current context d:\users\yorick grijseels\documents\visual studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Program.cs 32 35 WindowsFormsApplication4

i googled a bit but i cant find a way to fix this am i missing something?

Christoph Fink
  • 22,727
  • 9
  • 68
  • 113
  • 1
    That's what happens when you copy-paste code from the web without understanding it ;). Where did you find that code? There's probably a Win32Processes class that comes with it. – Thomas Levesque Jul 22 '14 at 16:01
  • 1
    its because you are missing the static class called 'Win32Processes'. Bad copy and paste job I presume.... – Mo Patel Jul 22 '14 at 16:01
  • Yes iam pasting this from the internet i need to close a mutex that being generated by the process. source i have found here http://pastebin.com/DYnyF5Ei is is possible using some other code to solve the issue? – user3865404 Jul 22 '14 at 16:03
  • what exactly are you trying to do? – Mo Patel Jul 22 '14 at 16:06

1 Answers1

0

You are missing the important part that makes things work. The question part of Delete a mutex from another process contains the classes you will need (Win32API and Win32Processes).

Community
  • 1
  • 1
Gabe
  • 84,912
  • 12
  • 139
  • 238