Exemplo n.º 1
0
        public static bool CloseHandle(Process process, string HandleRegexPattern)
        {
            string handleName = "";
            bool   ret        = false;

            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(HandleRegexPattern);

            processHwnd = Win32Api.OpenProcess(Win32Api.ProcessAccessFlags.All, false, process.Id);
            List <Win32Api.SystemHandleInformation> handles = CustomApi.GetHandles(process);

            foreach (Win32Api.SystemHandleInformation handle in handles)
            {
                handleName = GetHandleName(handle);
                if (handleName != null && regex.IsMatch(handleName))
                {
                    IntPtr lol = IntPtr.Zero;
                    Win32Api.DuplicateHandle(processHwnd, handle.Handle, new IntPtr(handle.Handle), out lol, 0, false, 0x1);
                    ret = true;
                }
            }
            Win32Api.CloseHandle(processHwnd);
            return(ret);
        }
Exemplo n.º 2
0
        private void run()
        {
            Options.parse();

            bool ok = false;
            bool oktmp;

            List <System.Diagnostics.Process> processes = new List <System.Diagnostics.Process>();

            processes.AddRange(CustomApi.getProcesses("gw2"));
            processes.AddRange(CustomApi.getProcesses("gw2-64"));
            processes.AddRange(CustomApi.getProcesses("gw"));

            if (processes.Count == 0)
            {
                contenu.Items.Add("Aucun Guild Wars n'a été trouvé.");
            }
            foreach (System.Diagnostics.Process process in processes)
            {
                contenu.Items.Add("[" + process.Id + "] " + process.ProcessName + " ...");
                oktmp = CustomApi.CloseHandle(process, @"\\Sessions\\[0-9]\\BaseNamedObjects\\AN-Mutex-Window-Guild Wars");
                if (oktmp)
                {
                    contenu.Items.Add("\tOK");
                }
                else
                {
                    contenu.Items.Add("\tErreur");
                }
                ok = ok || oktmp;
            }

            if (Options.jeu.Equals("gw2") || Options.jeu.Equals("gw2-64") || Options.jeu.Equals("gw"))
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.WorkingDirectory = Options.chemin;
                startInfo.FileName         = System.IO.Path.Combine(Options.chemin, Options.jeu + ".exe");
                startInfo.Arguments        = Options.arguments;
                if (!Options.compteCourant)
                {
                    startInfo.LoadUserProfile = true;
                    startInfo.UseShellExecute = false;
                    startInfo.UserName        = Options.utilisateur;
                    SecureString pass = new SecureString();
                    foreach (char c in Options.pass)
                    {
                        pass.AppendChar(c);
                    }
                    startInfo.Password = pass;
                }
                contenu.Items.Add("Lancement de " + Options.jeu);
                Process.Start(startInfo);
            }
            if (ok)
            {
                quitter();
            }
            else
            {
                Timer.delay(quitter, new TimeSpan(0, 0, 2));
            }
        }