示例#1
0
        public static Process StartPowerPoint(string pptPath)
        {
            var success = FileUnblocker.Unblock(pptPath);

            if (!success)
            {
                throw new InvalidOperationException($"The specified file is blocked and can not be unblocked. {pptPath}");
            }

            if (powerPointPath == null)
            {
                powerPointPath = FindExtensionExe(Path.GetExtension(pptPath));
            }

            var processName       = Path.GetFileNameWithoutExtension(powerPointPath);
            var existingProcesses = Process.GetProcessesByName(processName);

            foreach (var item in existingProcesses)
            {
                var cmd = GetCommandLine(item);
                if (cmd?.Contains("/s", StringComparison.InvariantCultureIgnoreCase) == true)
                {
                    item.Kill();
                }
            }

            ProcessStartInfo psi = new ProcessStartInfo(powerPointPath);

            psi.ArgumentList.Add("/S");
            psi.ArgumentList.Add(pptPath);
            psi.UseShellExecute = true;
            using var process   = Process.Start(psi);
            process.WaitForInputIdle();
            Process powerPointProcess;
            int     maxTries = 50;

            do
            {
                maxTries--;
                if (!process.HasExited)
                {
                    Thread.Sleep(10);
                }
                powerPointProcess = WindowEnumerationHelper.GetProcesses(processName).FirstOrDefault(x => GetCommandLine(x)?.Contains(pptPath) == true);
                if (powerPointProcess == null)
                {
                    Thread.Sleep(10);
                }
            } while (powerPointProcess == null && maxTries > 0);

            return(powerPointProcess);
        }
示例#2
0
        private void comboBox1_DropDown(object sender, EventArgs e)
        {
            var processesWithWindows = from p in Process.GetProcesses()
                                       where !string.IsNullOrWhiteSpace(p.MainWindowTitle) && WindowEnumerationHelper.IsWindowValidForCapture(p.MainWindowHandle)
                                       select p;

            processes            = new ObservableCollection <Process>(processesWithWindows);
            comboBox1.DataSource = processes;
        }
示例#3
0
        private void InitWindowList()
        {
            var processesWithWindows = from p in Process.GetProcesses()
                                       where !string.IsNullOrWhiteSpace(p.MainWindowTitle) && WindowEnumerationHelper.IsWindowValidForCapture(p.MainWindowHandle)
                                       select p;

            processes               = new ObservableCollection <Process>(processesWithWindows);
            comboBox1.DataSource    = processes;
            comboBox1.ValueMember   = "MainWindowHandle";
            comboBox1.DisplayMember = "MainWindowTitle";

            comboBox1.SelectedIndex = -1;
            StopCapture();
        }