0
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());
        }
    }
}
default locale
  • 13,035
  • 13
  • 56
  • 62

2 Answers2

1

Use the command line argument /c instead of /k to your arguments to execute the command and then terminate the command shell.

Pekka
  • 3,529
  • 27
  • 45
1

Try /C modifier instead of /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";

The diffrence between these two is as follows

/C  Carries out the command specified by string and then terminates
/K  Carries out the command specified by string but remains
Microsoft DN
  • 9,706
  • 10
  • 51
  • 71