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:
Sub IpSwitch(ByVal IP As String, ByVal SM As String, ByVal DG As String) Dim CMD As New Process With CMD.StartInfo .FileName = "cmd.exe" .UseShellExecute = False .Verb = "runas" .RedirectStandardInput = True 'Set to false if not using stdin, and using sending keystrokes instead End With CMD.Start() 'Dim stdin As IO.StreamWriter 'stdin = CMD.StandardInput 'stdin.WriteLine("netsh interface ip set address ""Wireless Network Connection"" static " + IP + " " + SM + " " + DG + " 1") 'stdin.WriteLine("exit") 'Dim SetPoint As Date 'SetPoint = Now.AddMilliseconds(500) 'While Date.Compare(Now, SetPoint) < 0 ' Application.DoEvents() 'End While 'SendKeys.SendWait("netsh interface ip set address ""Wireless Network Connection"" static " + IP + " " + SM + " " + DG + " 1") 'SendKeys.SendWait(Chr(Keys.Enter)) 'SendKeys.SendWait("exit") 'SendKeys.SendWait(Chr(Keys.Enter)) 'SetPoint = Now.AddMilliseconds(500) 'While Date.Compare(Now, SetPoint) < 0 ' Application.DoEvents() 'End While 'Me.Focus() End Sub




Reply With Quote
