Question

Dim args As String
args="netsh wlan interface ip set address """+adptrname+""" dhcp"
Dim proc As New System.Diagnostics.Process()        
proc.StartInfo.FileName = "netsh"
proc.StartInfo.Verb="RunAs"
proc.StartInfo.CreateNoWindow = true
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.Arguments = args
proc.StartInfo.UseShellExecute = False
proc.Start()
My.Computer.FileSystem.WriteAllText(MainForm.filePath,proc.StandardOutput.ReadToEnd(), True)
proc.Close()
MsgBox(args)

i wrote the above piece of code to change my wlan adapter to obtain ip address automatically but it still remains on the old ip configuration inspite of the output saying that dhcp is enabled. Can someone please tell where I am going wrong.

Was it helpful?

Solution

OK i tried to do this on the comments, but i kept on finding errors... so here a corrected version of your code:

'Where does your adptrname come from?
Dim adptrname As String = "wlan0" 'i.E.

Dim args As String
' Note that i removed 'netsh' from args
' And the notation to add the addapter name (in VB we use & instead of +)
args="netsh int ipv4 set address name=""" & adptrname & """ source=dhcp"
Dim proc As New System.Diagnostics.Process()        
proc.StartInfo.FileName = "netsh"
proc.StartInfo.Verb="RunAs"
proc.StartInfo.CreateNoWindow = true
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.RedirectStandardError = True ' maybe you want to read this, too
proc.StartInfo.Arguments = args
proc.StartInfo.UseShellExecute = False
proc.Start()

' This is still bad, but we keep it for now
My.Computer.FileSystem.WriteAllText(MainForm.filePath, proc.StandardOutput.ReadToEnd(), True)
My.Computer.FileSystem.WriteAllText(MainForm.filePath, proc.StandardError.ReadToEnd(), True)


' Normally not necessery, but no way we do proc.close() here
proc.WaitForExit()

' ok, this shoud have shown you until now that it didn't work...
MsgBox(args)

Read the comments, try the corrections on your own code and see if it runs.

Edit on the Parameters

Also i am thinking it won't work with your arguments...

Try it like this instead:

netsh int ipv4 set address name="Wireless Connection" source=dhcp

I built this from the help and it works on my machine (Win7x64-en_US)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top