기타 [vb.net] 필요한 경우에만 권한을 높이는 방법 / 필요한 경우에만 관리자 권한으로 실행
페이지 정보
본문
Imports System
Imports System.Linq
Imports System.Reflection
Imports System.Diagnostics
Imports System.Security.Principal
Imports System.Windows.Forms
Namespace WindowsFormsApp1
Friend Module Program
Private Class Form1
Inherits Form
Friend Sub New()
Dim button = New Button With {
.Dock = DockStyle.Fill
}
AddHandler button.Click, Sub(sender, args) RunAsAdmin()
Controls.Add(button)
ElevatedAction()
End Sub
End Class
<STAThread>
Friend Sub Main(ByVal arguments As String())
If arguments?.Contains("/run_elevated_action") = True Then
MsgBox(Join(arguments))
ElevatedAction()
Return
End If
Application.Run(New Form1())
End Sub
Private Sub RunAsAdmin()
Dim path = Assembly.GetExecutingAssembly().Location
Using P = Process.Start(New ProcessStartInfo(path, "/run_elevated_action") With {.Verb = "runas"})
P?.WaitForExit()
End Using
End Sub
Private Sub ElevatedAction()
MessageBox.Show($"IsElevated: {IsElevated()}")
End Sub
Private Function IsElevated() As Boolean
Using identity = WindowsIdentity.GetCurrent()
Dim principal = New WindowsPrincipal(identity)
Return principal.IsInRole(WindowsBuiltInRole.Administrator)
End Using
End Function
End Module
End Namespace
첨부파일
-
WindowsApp1.zip (58.1K)
4회 다운로드 | DATE : 2022-10-19 11:39:59
- 이전글[C#,VB.net] 네이버 로그인 소스 22.10.28
- 다음글[vb.net] Create Animated Gif 22.10.05
댓글목록
등록된 댓글이 없습니다.