例如如下代码能使整个程序提升到管理员权限,但是必须重启程序。
Public Shared Function PrivilegesElevation(ByVal AppExePath As String) As Logical
' Elevate the process if it is not run as administrator.
If (Environment.OSVersion.Version.Major >= 6) Then
If (Not IsRunAsAdmin()) Then
' Launch itself as administrator
Dim proc As New ProcessStartInfo
proc.UseShellExecute = True
proc.WorkingDirectory = Environment.CurrentDirectory
proc.FileName = AppExePath
proc.Verb = "runas"
Try
Process.Start(proc)
Application.Exit()
Return true
Catch
' The user refused to allow privileges elevation.
' Do nothing and return directly ...
Return false
End Try
Else
Return False
End If
End If
Return Null
End Function
运行后程序若直接退出,然后再以管理员模式运行,而此时很多工作尚未保存。我见过有个帖子说可以通过发送arguments或者建立一个高权限线程来做到这一点,而程序不用重启。请问怎么做?谢谢!!
2 个解决方案
#1
#2
我也想知道。。。
#1
#2
我也想知道。。。