Пример #1
0
        public App()
        {
#if DEBUGELEVATED
            if (IsElevated())
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                else
                {
                    Debugger.Launch();
                }
            }
#endif

            string exeName    = GetParameter("appname");
            string guidString = GetParameter("guid");

            if (string.IsNullOrWhiteSpace(exeName))
            {
                exeName = Path.GetFileName(PermissionChecker.GetExe());
            }

            Guid guid;

            if (!string.IsNullOrWhiteSpace(guidString))
            {
                guid = Guid.Parse(guidString);
            }
            else
            {
                guid = Guid.NewGuid();
            }


            Console.WriteLine(@"Is Admin: " + UserIsAdmin());

            var result = PermissionChecker.EnsureAppPermissionsSet(exeName, guid);

            if (result == PermissionCheckResult.ElevationRequired)
            {
                if (IsElevated() || UserIsAdmin())
                {
                    result = PermissionCheckResult.ElevationInsufficient;
                }
                else
                {
                    result = LaunchCurrentAppAsAdmin(exeName, guid);
                }
            }

#if DEBUG
            if (!IsElevated())
            {
                Console.WriteLine(result);
                Console.ReadKey();
            }
#endif

            Environment.Exit((int)result);
        }