728x90
반응형
728x170
▶ Program.cs
using System;
using System.Diagnostics;
using System.Security.Principal;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
static class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
[STAThread]
private static void Main()
{
if(IsAdministratorRole())
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
else
{
MessageBox.Show("관리자 권한으로 프로그램을 다시 실행합니다.");
try
{
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.UseShellExecute = true;
processStartInfo.FileName = "TestProject.exe";
processStartInfo.WorkingDirectory = Environment.CurrentDirectory;
processStartInfo.Verb = "runas";
Process.Start(processStartInfo);
}
catch(Exception exception)
{
Console.WriteLine(exception.ToString());
}
return;
}
}
#endregion
#region 관리자 역할 여부 구하기 - IsAdministratorRole()
/// <summary>
/// 관리자 역할 여부 구하기
/// </summary>
/// <returns>관리자 역할 여부</returns>
private static bool IsAdministratorRole()
{
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
if(windowsIdentity != null)
{
WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity);
return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
}
return false;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] RichTextBox 클래스 : 이미지 캡처하기 (0) | 2020.12.25 |
---|---|
[C#/WINFORM] Bitmap 클래스 : 합성 이미지 만들기 (0) | 2020.12.25 |
[C#/WINFORM] 화면 보호기/절전 모드 방지하기/허용하기 (0) | 2020.12.21 |
[C#/WINFORM] Form 클래스 : CreateParams 속성을 사용해 작업 전환기(Tab Switcher)에서 애플리케이션 숨기기 (0) | 2020.12.19 |
[C#/WINFORM] SVG 이미지 사용하기 (0) | 2020.12.19 |
[C#/WINFORM] 화면 캡처 방지하기 (0) | 2020.12.17 |
[C#/WINFORM] Control 클래스 : WndProc 메소드를 사용해 데이터 수신하기 (0) | 2020.12.05 |
[C#/WINFORM] 특정 프로세스의 윈도우 핸들 구하기 (0) | 2020.12.05 |
[C#/WINFORM] 누겟 설치 : Microsoft.Windows.Shell (0) | 2020.11.17 |
[C#/WINFORM] TextBox 클래스 : 영숫자/통화/날짜/정수/마스크/숫자 입력하기 (0) | 2020.11.13 |
댓글을 달아 주세요