【发布时间】:2020-03-11 17:36:08
【问题描述】:
我在这个主题中搜索了很多次,但没有运气,我在 WPF 上有一个使用 Click Once 发布的应用程序,因此我不能使用管理员权限,我需要在安装过程中执行一些操作,例如例如,重新启动 SQL 服务器,为此我需要管理员权限,因为一旦我必须立即删除管理员权限,我就开始使用 click 发布,我尝试使用以下代码重新启动我的应用程序以强制管理员权限,但没有工作
Public Function IsRunAsAdmin() As Boolean
Try
Dim id As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim principal As WindowsPrincipal = New WindowsPrincipal(id)
Return principal.IsInRole(WindowsBuiltInRole.Administrator)
Catch __unusedException1__ As Exception
Return False
End Try
End Function
Public Sub AdminRelauncher()
If Not IsRunAsAdmin() Then
Dim proc As ProcessStartInfo = New ProcessStartInfo()
Dim procExecuting As New Process
proc.UseShellExecute = True
proc.WorkingDirectory = Environment.CurrentDirectory
proc.FileName = Assembly.GetEntryAssembly().CodeBase
proc.Verb = "runas"
Try
procExecuting = Process.Start(proc)
Application.ExitThread()
Application.Exit()
Catch ex As Exception
Console.WriteLine("This program must be run as an administrator! " & vbLf & vbLf & ex.ToString())
End Try
End If
End Sub
我搜索后仍然收到错误“无法在计算机上打开 MSSQL$******”,当然我发现原因是需要管理员权限。 所以现在我正在研究代码签名证书,因为有人建议我这对我有用。 但我是个人,我的申请价格不足以购买付费证书,所以我想知道我是否可以制作一个自我代码签名证书并单击一次使用它。 谢谢。
【问题讨论】: