繁体   English   中英

如何关闭命令提示符?

[英]How to close command prompt?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApplication4
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            var psi = new ProcessStartInfo();

            psi.UseShellExecute = true;
            psi.Verb = "runas";
            psi.FileName = @"C:\Windows\System32\cmd.exe";

            psi.Arguments = "/env /user:" + "Administrator" + @" %windir%\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f";

            Process.Start(psi);
            System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "\\DllRegister.bat");
            /// need to close the command prompt over here ????????????????

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

使用命令行参数 /c而不是/k来执行命令,然后终止命令shell。

尝试/C修饰符而不是/K

psi.Arguments = "/env /user:" + "Administrator" + @" %windir%\System32\cmd.exe /C %windir%\System32\reg.exe ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f";

这两者之间的差异如下

/C  Carries out the command specified by string and then terminates
/K  Carries out the command specified by string but remains

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM