Đây là mã của tôi đang cố gắng chạy cmd.exe với quản trị viên. Tuy nhiên, tôi nhận được yêu cầu hoạt động đòi hỏi độ cao. nếu tôi chạy cmd.exe với "Chạy như quản trị" thông qua cửa sổ của tôi, nó hoạt động, tuy nhiên, thông qua vb, nó không. Đây là mã của tôi.Chạy cmd.exe với admin priviliges
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)
Cảm ơn.
tham số 'runas' làm cho quá trình này yêu cầu sự cho phép để leo thang đặc quyền. Đó là hành vi hoàn toàn chính xác. Hãy thử sử dụng 'psexec' từ các công cụ quản trị. –