Example #1
0
        public static bool RunElevated(string[] args = null, bool messageOnError = false, bool exitOnElevation = true)
        {
            Uac uac = new Uac();

            if (uac.IsRunAsAdmin())
            {
                return(true);
            }

            try
            {
                uac.RunAsAdmin(args);
                if (exitOnElevation)
                {
                    Application.Exit();
                }
            }
            catch
            {
                if (messageOnError)
                {
                    MessageBox.Show("This application can't run without administrative priviledges.", "Elevation failed", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }

            return(false);
        }
Example #2
0
		public static bool RunElevated(string[] args = null, bool messageOnError = false, bool exitOnElevation = true)
		{
			Uac uac = new Uac();
			
			if (uac.IsRunAsAdmin())
				return true;

			try
			{
				uac.RunAsAdmin(args);
				if (exitOnElevation)
					Application.Exit();
			}
			catch
			{
				if (messageOnError)
					MessageBox.Show("This application can't run without administrative priviledges.", "Elevation failed", MessageBoxButtons.OK, MessageBoxIcon.Stop);
			}
			
			return false;
		}