1

I'm using visual basic 2013. I'm trying to make a program to run and give commands to admin cmd using vb. I wrote a code to do it using "runas". But still it says "You must run this command from a command prompt with administrator privilege." I tried setting "myprocess.StartInfo.UseShellExecute = True" also.Then it says "The Process object must have the UseShellExecute property set to false in order to redirect IO streams."

Here is my code.

Dim myprocess As New Process()
myprocess.StartInfo.FileName = "netsh"
myprocess.StartInfo.Arguments = "wlan start hostednetwork"
myprocess.StartInfo.Verb = "runas"
myprocess.StartInfo.CreateNoWindow = False
myprocess.StartInfo.UseShellExecute = False
myprocess.StartInfo.RedirectStandardOutput = True
myprocess.Start()
TextBox1.Text = (myprocess.StandardOutput.ReadToEnd())
DBM
  • 39
  • 8
  • Interesting as you have already tried the `runas`. Try adding a manifest file to the project and include this `` Also I believe `UseShellExecute` should be **True**, try that first. – Trevor Feb 13 '16 at 08:01
  • When I changed "UseShellExecute = True", It says "The Process object must have the UseShellExecute property set to false in order to redirect IO streams". – DBM Feb 13 '16 at 11:41
  • @codexer's intuitions are correct, you *must* set `UseShellExecute` to `True` if you are to use `runas` verbs (which you need to get elevation as an administrator). But you're also right, you lose the ability to redirect I/O streams when you do this. You'll need to embed a manifest in *your* application that requests elevation. That's the only way you can launch an elevated process *from* the application that redirects I/O. – Cody Gray - on strike Feb 13 '16 at 13:07
  • @CodyGray you are right about manifest, I did mention that. I overlooked the `redirect` in which it will require for the elevation... Thanks for your confirmation. – Trevor Feb 13 '16 at 14:17
  • I'm new to vb. So, tell me how to embed a manifest in my application. – DBM Feb 14 '16 at 06:28
  • You could try a search. LIke I did to find [this](http://stackoverflow.com/questions/1431948/how-to-add-uac-manifest-file-to-vb-net). – Cody Gray - on strike Feb 14 '16 at 14:17
  • Thanks Code Gray. It works. – DBM Feb 15 '16 at 11:10

0 Answers0