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());
}
}
}
答案 0 :(得分:1)
使用命令行argument /c
而不是/k
来执行命令,然后终止命令shell。
答案 1 :(得分:1)
尝试/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