这是我的代码尝试运行具有管理权限的cmd.exe。但是,我得到请求操作需要提升。如果我通过我的窗口运行“Run as Admin”运行cmd.exe,它可以工作,但是,通过vb,它不会。这是我的代码。以管理员权限运行cmd.exe
Try
Dim process As New Process()
process.StartInfo.FileName = "cmd.exe "
process.StartInfo.Verb = "runas"
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardInput = True
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
process.StartInfo.CreateNoWindow = True
process.Start()
process.StandardInput.WriteLine("route add 8.31.99.141 mask 255.255.255.255 " & cmdorder)
process.StandardInput.WriteLine("exit")
Dim input As String = process.StandardOutput.ReadToEnd
process.Close()
Dim regex As Regex = New Regex("(ok)+", RegexOptions.IgnoreCase) ' wa requested
' txtLog.AppendText(input)
Return regex.IsMatch(input)
谢谢。
'runas' param使这个过程要求特权升级的权限。这是完全正确的行为。尝试从管理工具中使用'psexec'。 –