Пример #1
0
        private void btnCreateProcess_Click(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxUseWmi.Checked)
                {
                    _token.SetDefaultDacl(new Acl(IntPtr.Zero, false));
                    using (var imp = _token.Impersonate())
                    {
                        using (var managementClass = new ManagementClass(@"\\.\root\cimv2",
                                                                         "Win32_Process",
                                                                         new ObjectGetOptions()))
                        {
                            var inputParams = managementClass.GetMethodParameters("Create");

                            inputParams["CommandLine"] = txtCommandLine.Text;
                            var outParams = managementClass.InvokeMethod("Create",
                                                                         inputParams,
                                                                         new InvokeMethodOptions());
                            System.Diagnostics.Trace.WriteLine(outParams["ReturnValue"].ToString());
                        }
                    }
                }
                else
                {
                    using (var token = TokenUtils.CreateProcessForToken(txtCommandLine.Text, _token, checkBoxMakeInteractive.Checked))
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }