• 쇼핑몰
  • 커뮤니티
  • 북마크

vb.net




[기타] [vb.net] 관리자 권한으로 실행하기

하나를하더라도최선을
2019.07.13 08:48 1,122 0

본문




Imports System.Security.Principal
 
Module Program
 
    Sub Main()
        If IsAdministrator() = False Then
            Try
                Dim procInfo As New ProcessStartInfo()
                procInfo.UseShellExecute = True
                procInfo.FileName = Application.ExecutablePath
                procInfo.WorkingDirectory = Environment.CurrentDirectory
                procInfo.Verb = "runas"
                Process.Start(procInfo)
 
            Catch ex As Exception
                MessageBox.Show(ex.Message.ToString())
            End Try
            Return
        End If
 
        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)
        Dim F As Form = TGauge.Main
        F.ShowDialog()
    End Sub
 
    Public Function IsAdministrator() As Boolean
        Dim identity As WindowsIdentity = WindowsIdentity.GetCurrent()
        If identity IsNot Nothing Then
            Dim principal As New WindowsPrincipal(identity)
            Return principal.IsInRole(WindowsBuiltInRole.Administrator)
        End If
        Return False
    End Function
 
End Module




댓글목록 0

등록된 댓글이 없습니다.