본문 바로가기

자료

[C#,VB.NET] 프로그램이 관리자 권한실행되고있는지 확인

728x90
 Imports System.Security.Principal '----네임스페이스 추가


        Dim user As WindowsIdentity = WindowsIdentity.GetCurrent()
        Dim pu As WindowsPrincipal = New WindowsPrincipal(user)
        If pu.IsInRole("Administrators") Then
            MessageBox.Show("관리자 권한")
        Else
            MessageBox.Show("관리자 권한이 아님")
            Dim p As New Process()
            p.StartInfo.FileName = Application.ExecutablePath
            p.StartInfo.UseShellExecute = True
            p.StartInfo.Verb = "runas" 'Verb를 runas로 (관리자 권한으로 실행 명령)
            p.Start()
            End
        End If
728x90

'자료' 카테고리의 다른 글

[VB.net/C#] 폴더/파일 유무 확인 및 생성  (0) 2020.08.05
파이썬 YOLO_MARK  (0) 2020.08.04
[C#/VB.net] set windowpos  (0) 2020.08.03
[C#/VB.net] EMGUCV를 사용해 OCR하는법  (0) 2020.08.03
[C#/VB.net] mouse_event  (0) 2020.08.03