Vb.net 使用管理员权限启动进程并重定向其输出
我想启动一个进程,它是一个控制台应用程序,请求管理员权限(Vb.net 使用管理员权限启动进程并重定向其输出,vb.net,process,console-application,uac,Vb.net,Process,Console Application,Uac,我想启动一个进程,它是一个控制台应用程序,请求管理员权限(level=“requireAdministrator”)。实际上,我必须将UseShellExecute属性设置为True,以显示UAC请求,但我还想重定向其输出。问题是,要重定向进程输出,我们必须将UseShellExecute属性设置为False 以下是我当前的代码: Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
level=“requireAdministrator”
)。实际上,我必须将UseShellExecute
属性设置为True
,以显示UAC请求,但我还想重定向其输出。问题是,要重定向进程输出,我们必须将UseShellExecute
属性设置为False
以下是我当前的代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim admin As Boolean
Using p As New Process With {
.StartInfo = New ProcessStartInfo With {
.FileName = "D:\Drarig29\Documents\Visual Studio 2013\Projects\AdminRightsConsole\Console\bin\Release\Console.exe",
.RedirectStandardOutput = True,
.UseShellExecute = False,
.WindowStyle = ProcessWindowStyle.Hidden,
.CreateNoWindow = True}}
p.Start()
Using s As StreamReader = p.StandardOutput
admin = s.ReadToEnd.Trim()
End Using
End Using
If Button1.Text = "Enable" Then
If admin Then
Button1.Text = "Disable"
End If
Else
If admin Then
Button1.Text = "Enable"
End If
End If
End Sub
如何显示UAC请求并同时重定向流程的输出
编辑:控制台应用程序在
标准输出中写入布尔值。如果它有管理员权限,它将返回True
,如果没有则返回False
。我不希望我的应用程序请求管理员权限…如果这就是stdio的全部用途,你可以使用退出代码而不是使用Good idea Proputix,但我找到了另一个解决方案!