Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27379

VS 2012 Running cmd.exe as admin failing?

$
0
0
This is my code trying to run cmd.exe with admin priviligies. However, I get the request operation requires elevation. if I run cmd.exe with "Run as Admin" through my windows, it works, however, through vb, it doesn't. This is my code.

vb Code:
  1. Try
  2.             Dim process As New Process()
  3.             process.StartInfo.FileName = "cmd.exe "
  4.             process.StartInfo.Verb = "runas"
  5.             process.StartInfo.UseShellExecute = False
  6.             process.StartInfo.RedirectStandardInput = True
  7.             process.StartInfo.RedirectStandardOutput = True
  8.             process.StartInfo.RedirectStandardError = True
  9.             process.StartInfo.CreateNoWindow = True
  10.  
  11.             process.Start()
  12.             process.StandardInput.WriteLine("route add 8.31.99.141 mask 255.255.255.255 " & cmdorder)
  13.             process.StandardInput.WriteLine("exit")
  14.             Dim input As String = process.StandardOutput.ReadToEnd
  15.             process.Close()
  16.             Dim regex As Regex = New Regex("(ok)+", RegexOptions.IgnoreCase) ' wa requested
  17.             ' txtLog.AppendText(input)
  18.             Return regex.IsMatch(input)

Thanks.

Viewing all articles
Browse latest Browse all 27379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>