첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.01MB

▶ MainApplication.xaml.cs

using System.Diagnostics;
using System.Security.Principal;
using System.Windows;

namespace TestProject
{
    /// <summary>
    /// 메인 애플리케이션
    /// </summary>
    public partial class MainApplication : Application
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 시작시 처리하기 - OnStartup(e)

        /// <summary>
        /// 시작시 처리하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            if(!IsAdministratorRole())
            {
                string filePath = Process.GetCurrentProcess().MainModule.FileName;

                ProcessStartInfo processStartInfo = new ProcessStartInfo(filePath);

                processStartInfo.Verb      = "runas";
                processStartInfo.Arguments = "restart";

                Process.Start(processStartInfo);

                Shutdown();
            }

            base.OnStartup(e);
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 관리자 역할 여부 구하기 - IsAdministratorRole()

        /// <summary>
        /// 관리자 역할 여부 구하기
        /// </summary>
        /// <returns>관리자 역할 여부</returns>
        private bool IsAdministratorRole()
        {
            WindowsIdentity  identity  = WindowsIdentity.GetCurrent();
            WindowsPrincipal principal = new WindowsPrincipal(identity);

            return principal.IsInRole(WindowsBuiltInRole.Administrator);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요