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());
        }
    }
}
            Asked
            
        
        
            Active
            
        
            Viewed 1,386 times
        
    0
            
            
        
        default locale
        
- 13,035
 - 13
 - 56
 - 62
 
        user3506644
        
- 3
 - 2
 
- 
                    have you tried adding "exit" as an argument. "exit" is the sytax to close CMD as i remember – Jonny Apr 07 '14 at 12:18
 - 
                    Why do you execute cmd.exe to run another program if you can run that program directly? – Adriano Repetti Apr 07 '14 at 12:19
 - 
                    yes but it is not working – user3506644 Apr 07 '14 at 12:19
 - 
                    possible duplicate of [Passing an argument to cmd.exe](http://stackoverflow.com/questions/5047171/passing-an-argument-to-cmd-exe) – Pekka Apr 07 '14 at 12:21
 
2 Answers
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