internal void Restart(DTE dte, bool elevated)
        {
            var currentProcess = Process.GetCurrentProcess();

            var parser = new ArgumentParser(dte.CommandLineArguments);

            var builder = new RestartProcessBuilder()
                .WithDevenv(currentProcess.MainModule.FileName)
                .WithArguments(parser.GetArguments());

            var openedItem = GetOpenedItem(dte);
            if (openedItem != OpenedItem.None)
            {
                if (openedItem.IsSolution)
                {
                    builder.WithSolution(openedItem.Name);
                }
                else
                {
                    builder.WithProject(openedItem.Name);
                }
            }

            if (elevated)
            {
                builder.WithElevatedPermission();
            }

            const string commandName = "File.Exit";
            var closeCommand = dte.Commands.Item(commandName);

            CommandEvents closeCommandEvents = null;
            if (closeCommand != null)
            {
                closeCommandEvents = dte.Events.CommandEvents[closeCommand.Guid, closeCommand.ID];
            }

            // Install the handler
            var handler = new VisualStudioEventHandler(dte.Events.DTEEvents, closeCommandEvents, builder.Build());

            if (closeCommand != null && closeCommand.IsAvailable)
            {
                // if the Exit commad is present, execute it with all gracefulls dialogs by VS
                dte.ExecuteCommand(commandName);
            }
            else
            {
                // Close brutally
                dte.Quit();
            }
        }
        public static ArgumentTokenCollection Lookup(int processId)
        {
            string wmiQuery = string.Format("SELECT CommandLine FROM Win32_Process WHERE ProcessId = {0}", processId);
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
            ManagementObjectCollection retObjectCollection = searcher.Get();

            try
            {
                string commandLine = string.Empty;

                if (retObjectCollection.Count == 0 || retObjectCollection.Count > 1)
                {
                    return ArgumentTokenCollection.Empty;
                }

                using (var enumerator = retObjectCollection.GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        commandLine = enumerator.Current["CommandLine"].ToString();
                    }
                }

                var parser = new ArgumentParser(commandLine);
                return parser.GetArguments();
            }
            finally
            {
                if (searcher != null)
                {
                    searcher.Dispose();
                }

                if (retObjectCollection != null)
                {
                    retObjectCollection.Dispose();
                }
            }

            //foreach (ManagementObject retObject in retObjectCollection)
            //{
            //    return retObject["CommandLine"].ToString();
            //}
        }