using System;
using System.Diagnostics;
using System.Security.Principal;
using System.Windows.Forms;
namespace HelloWorld
{
static class Program
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
if (IsAdministrator() == false)
{
try
{
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.UseShellExecute = true;
processInfo.FileName = Application.ExecutablePath;
processInfo.WorkingDirectory = Environment.CurrentDirectory;
processInfo.Verb = "runas";
Process.Start(processInfo);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MonitoringForm());
}
/// <summary>
/// 관리자모드 실행 확인
/// </summary>
/// <returns></returns>
public static bool IsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
if (null != identity)
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
return false;
}
}
}
'Programming > C#' 카테고리의 다른 글
[C#] 확장메소드 (0) | 2017.07.20 |
---|---|
[C#] Code 에서 Debuging mode 확인하기 (0) | 2012.10.30 |
[C#] 네트워크 연결 확인하기(System.Net) (0) | 2012.10.25 |
[C#] Stream string으로 변환하기 (0) | 2012.07.31 |
[C#] string 문자열 MemoryStream으로 변환 하기 (0) | 2012.07.31 |
[C#] Excel Template 가져오기 (0) | 2012.02.03 |
[C#] SMTP 사용해서 Email 보내기 (0) | 2010.08.07 |
[C#] Invoke (0) | 2010.06.21 |
[C#] 크로스 스레드와 Control.Invoke (0) | 2010.06.21 |
[C#] [스크랩] Invoke , BeginInvoke, MethodInvoker (0) | 2010.06.09 |