In an old app running in XP I used the following vb6 module to change the IPaddress, subnet and gateway automatically when I started my app.
This was necessary in a particular fixed IP network application I did, the values being obtained from a different .ini file in each computer.
The properties had to be first set to Automatic.
The new values were global.
I find it now does not work at all in Windows 7
Any ideas would be appreciated?
This was necessary in a particular fixed IP network application I did, the values being obtained from a different .ini file in each computer.
The properties had to be first set to Automatic.
The new values were global.
I find it now does not work at all in Windows 7
Any ideas would be appreciated?
Code:
'Courtesy of the fine people at Tek-Tips
'Used to Change IP addresses
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, ByVal dwprocessID As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, _
lbExitCode As Long) As Long
'Constants
Const PROCESS_QUERY_INFORMATION = &H400
Const STILL_ACTIVE = &H103
Sub ChangeAddresses(NewIPGateSub As String)
ReturnValue = ShellAndWait("cmd.exe /c IPCONFIG /release", vbHide) 'release old address
ReturnValue = ShellAndWait("cmd.exe /c NETSH INTERFACE IP SET ADDRESS " & _
Chr(34) & "Local Area Connection" & Chr(34) & _
" static " & NewIPGateSub & " none", vbHide)
End Sub
Function ShellAndWait(ByVal PathName As String, Optional WindowState) As Double
Dim hProg As Long
Dim hProcess As Long, ExitCode As Long
If IsMissing(WindowState) Then WindowState = 1
hProg = Shell(PathName, WindowState)
'hProg is the process ID under Win32. To get the process handle -
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProg)
Do
'populate the ExitCode variable
GetExitCodeProcess hProcess, ExitCode
DoEvents
Loop While ExitCode = STILL_ACTIVE
ShellAndWait = 1
End Function