반응형
static class Program
{
[STAThread]
static void Main()
{
if (IsAdministrator() == false)
{
try
{
ProcessStartInfo procInfo = new ProcessStartInfo();
procInfo.UseShellExecute = true;
procInfo.FileName = Application.ExecutablePath;
procInfo.WorkingDirectory = Environment.CurrentDirectory;
procInfo.Verb = "runas";
Process.Start(procInfo);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static bool IsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
if (null != identity)
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
return false;
}
}
'Programing > C# ' 카테고리의 다른 글
Reflection 리플렉션 사용하기 (0) | 2012.12.12 |
---|---|
c# unicodeString to unicodevalue (0) | 2012.12.06 |
네트워크 드라이브 목록 가져오기 (0) | 2012.09.24 |
LineStyleComboBox(라인 스타일적용한 콤보박스) (0) | 2012.06.26 |
ColorComboBox 만들기 (0) | 2012.06.21 |