I'm trying to write a program to change my static IP. I am successful in opening a command prompt, sending keystrokes to it, and closing it again. That seems messy, so I want to use stdin. If I try using stdin, the command prompt just opens and closes really quickly... Help me!

The first block of commented out code is what fails.
The second block of commented out code is successful.
Code Code:
  1. Sub IpSwitch(ByVal IP As String, ByVal SM As String, ByVal DG As String)
  2.         Dim CMD As New Process
  3.         With CMD.StartInfo
  4.             .FileName = "cmd.exe"
  5.             .UseShellExecute = False
  6.             .Verb = "runas"
  7.             .RedirectStandardInput = True 'Set to false if not using stdin, and using sending keystrokes instead
  8.         End With
  9.         CMD.Start()
  10.  
  11.         'Dim stdin As IO.StreamWriter
  12.         'stdin = CMD.StandardInput
  13.         'stdin.WriteLine("netsh interface ip set address ""Wireless Network Connection"" static " + IP + " " + SM + " " + DG + " 1")
  14.         'stdin.WriteLine("exit")
  15.  
  16.         'Dim SetPoint As Date
  17.         'SetPoint = Now.AddMilliseconds(500)
  18.         'While Date.Compare(Now, SetPoint) < 0
  19.         '    Application.DoEvents()
  20.         'End While
  21.         'SendKeys.SendWait("netsh interface ip set address ""Wireless Network Connection"" static " + IP + " " + SM + " " + DG + " 1")
  22.         'SendKeys.SendWait(Chr(Keys.Enter))
  23.         'SendKeys.SendWait("exit")
  24.         'SendKeys.SendWait(Chr(Keys.Enter))
  25.         'SetPoint = Now.AddMilliseconds(500)
  26.         'While Date.Compare(Now, SetPoint) < 0
  27.         '    Application.DoEvents()
  28.         'End While
  29.         'Me.Focus()
  30.     End Sub