728x90
반응형
728x170
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Dispatcher 클래스 : BeginInvoke 메소드 사용하기 (0) | 2021.04.30 |
---|---|
[C#/WPF] ScrollViewer 클래스 : 애니메이션 스크롤 뷰어 사용하기 (0) | 2021.04.28 |
[C#/WPF] UWP API 사용하기 (0) | 2021.04.26 |
[C#/WPF] TOTP(Time-based One-Time Password) 사용하기 (0) | 2021.04.26 |
[C#/WPF] Dispatcher 클래스 : Invoke 메소드를 사용해 UI 업데이트 하기 (0) | 2021.04.22 |
[C#/WPF] 가상 키보드 사용하기 (0) | 2021.03.27 |
[C#/WPF] HTML을 XAML로 변환하기 (0) | 2021.03.20 |
[C#/WPF] LogicalTreeHelper 클래스 : GetChildren 정적 메소드를 사용해 논리적 자식 열거 가능형 구하기 (0) | 2021.03.20 |
[C#/WPF] ListBox 엘리먼트 : 마우스 진입시 애니메이션 사용하기 (0) | 2021.03.07 |
[C#/WPF] ListBox 클래스 : 항목 선택시 슬라이딩 리스트 박스 사용하기 (0) | 2021.03.07 |
댓글을 달아 주세요