Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C# by z ( 12 years ago )
using System;
using Microsoft.Win32;
using System.Threading;

namespace disableLUA
{
    class Reader 
    {
        private static Thread inputThread;
        private static AutoResetEvent getInput, gotInput;
        private static string input;

        static Reader()
        {
            inputThread = new Thread(reader);
            inputThread.IsBackground = true;
            inputThread.Start();
            getInput = new AutoResetEvent(false);
            gotInput = new AutoResetEvent(false);
        }

        private static void reader()
        {
            while (true)
            {
                getInput.WaitOne();
                input = Console.ReadLine();
                gotInput.Set();
            }
        }

        public static string ReadLine(int timeOutMillisecs)
        {
            getInput.Set();
            bool success = gotInput.WaitOne(timeOutMillisecs);
            if (success)
                return input;
            else
                throw new TimeoutException();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string name = string.Empty;

            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine("z's LUA (UAC) Enabler/Disabler");

            Console.WriteLine();

            Console.WriteLine("Please pick an option from the following Menu or the Verify&Disable; LUA (UAC) function will automatically run in 10 seconds.");

            Console.WriteLine();

            Console.WriteLine("1 - Verify&Disable; LUA (UAC)");

            Console.WriteLine("2 - Verify&Enable; LUA (UAC)");

            Console.WriteLine("3 - Exit");

            Console.WriteLine();

            try
            {
               name = Reader.ReadLine(10000);

               Option(name);
            }
            catch (TimeoutException)
            {
                Console.WriteLine("Running automatic Verify&Disable; LUA (UAC) function.");

                Console.WriteLine();

                Option("1");
            }
        }

        static void Option(string picked)
        {
            switch (picked)
            {
                case "1": VerifyandDisable(); break;
                case "2": VerifyandEnable(); break;
                case "3": Environment.Exit(0); break;
                default: Console.Clear(); Main(null); break;
            }
        }

        static void VerifyandDisable()
        {
            RegistryKey key;

            Console.WriteLine();

            Console.WriteLine("Checking current EnableLUA Status!");

            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Cyan;

            key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", true);

            if (key.GetValue("EnableLUA").ToString() == "1")
            {
                Console.WriteLine();

                Console.Write("EnableLUA -> ");

                Console.ForegroundColor = ConsoleColor.Red;

                Console.Write(key.GetValue("EnableLUA").ToString());

                Console.WriteLine();

                Console.ResetColor();

                Console.ForegroundColor = ConsoleColor.Yellow;

                Console.WriteLine("This is the wrong parameter! Setting correct parameter...");
                    
                Thread.Sleep(3000);

                Console.ResetColor();

                try
                {

                    key.SetValue("EnableLUA", 0);

                    Console.ForegroundColor = ConsoleColor.White;

                    Console.WriteLine("Parameter set! Rebooting computer...");

                    key.Close();

                    key.Dispose();

                    Reboot();
                }

                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;

                    Console.WriteLine("An exception has occurred! -> " + ex.Message);

                    key.Close();

                    key.Dispose();

                    Console.WriteLine();

                    Console.ResetColor();

                    Console.ForegroundColor = ConsoleColor.Yellow;

                    Console.WriteLine("Please show this to the developer of the program! -> [email protected]");

                    Console.WriteLine("Press Enter key to exit.");

                    Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine();

                Console.Write("EnableLUA -> ");

                Console.ForegroundColor = ConsoleColor.Green;

                try
                {
                    Console.Write(key.GetValue("EnableLUA").ToString());

                    Console.WriteLine();

                    Console.WriteLine("This is the correct setting! Resuming normally...");

                    Thread.Sleep(3000);

                    key.Close();

                    key.Dispose();

                    return;
                }

                catch (Exception ex)
                {
                    Console.ResetColor();

                    Console.ForegroundColor = ConsoleColor.Red;

                    Console.WriteLine("An exception has occurred! -> " + ex.Message);

                    key.Close();

                    key.Dispose();

                    Console.WriteLine();

                    Console.ResetColor();

                    Console.ForegroundColor = ConsoleColor.Yellow;

                    Console.WriteLine("Please show this to the developer of the program! -> [email protected]");

                    Console.WriteLine("Press Enter key to exit.");

                    Console.ReadLine();
                }
            }
        }

        static void VerifyandEnable()
        {
            Console.WriteLine();

            Console.WriteLine("Checking current EnableLUA Status!");

            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Cyan;

            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", true);

            if (key.GetValue("EnableLUA").ToString() == "0")
            {
                Console.WriteLine();

                Console.Write("EnableLUA -> ");

                Console.ForegroundColor = ConsoleColor.Red;

                Console.Write(key.GetValue("EnableLUA").ToString());

                Console.WriteLine();

                Console.ResetColor();

                Console.ForegroundColor = ConsoleColor.Yellow;

                Console.WriteLine("This is the wrong parameter! Setting correct parameter...");

                Thread.Sleep(3000);

                Console.ResetColor();

                try
                {

                    key.SetValue("EnableLUA", 1);

                    Console.ForegroundColor = ConsoleColor.White;

                    Console.WriteLine("Parameter set! Rebooting computer...");

                    key.Close();

                    key.Dispose();

                    Reboot();
                }

                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;

                    Console.WriteLine("An exception has occurred! -> " + ex.Message);

                    key.Close();

                    key.Dispose();

                    Console.WriteLine();

                    Console.ResetColor();

                    Console.ForegroundColor = ConsoleColor.Yellow;

                    Console.WriteLine("Please show this to the developer of the program! -> [email protected]");

                    Console.WriteLine("Press Enter key to exit.");

                    Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine();

                Console.Write("EnableLUA -> ");

                Console.ForegroundColor = ConsoleColor.Green;

                try
                {
                    Console.Write(key.GetValue("EnableLUA").ToString());

                    Console.WriteLine();

                    Console.WriteLine("This is the correct setting! Resuming normally...");

                    Thread.Sleep(3000);

                    key.Close();

                    key.Dispose();

                    return;
                }

                catch (Exception ex)
                {
                    Console.ResetColor();

                    Console.ForegroundColor = ConsoleColor.Red;

                    Console.WriteLine("An exception has occurred! -> " + ex.Message);

                    key.Close();

                    key.Dispose();

                    Console.WriteLine();

                    Console.ResetColor();

                    Console.ForegroundColor = ConsoleColor.Yellow;

                    Console.WriteLine("Please show this to the developer of the program! -> [email protected]");

                    Console.WriteLine("Press Enter key to exit.");

                    Console.ReadLine();
                }
            }
        }

        static void Reboot()
        {
            try
            {
                System.Diagnostics.Process.Start("shutdown.exe", "-r -t 0");
            }

            catch (Exception ex)
            {
                Console.ResetColor();

                Console.ForegroundColor = ConsoleColor.Red;

                Console.WriteLine("An exception has occurred! -> " + ex.Message);

                Console.WriteLine();

                Console.ResetColor();

                Console.ForegroundColor = ConsoleColor.Yellow;

                Console.WriteLine("Please show this to the developer of the program! -> [email protected]");

                Console.WriteLine("Please reboot manually your computer.");

                Console.WriteLine("Press Enter key to exit.");

                Console.ReadLine();

            }
        }
    }
}

 

Revise this Paste

Your Name: Code Language: