Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows 7 oddity

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
Thanks to strongm I use this routine to (if necessary) change a computer to the right IP address, subnet & gateway when it is rebooted. It is used in a dedicated system and occasionally one computer has to be replaced and the IPaddress is changed automatically before it can be used.

The correct address, subnet & gateway are in a simple INI text file.

My problem is in Windows 7 (32b)it doesn't change the main IP address although it does change the subnet and gaterway!

XP & 2000 work fine

Any ideas?

Code:
'Used to Change IP addresses depending on the ClientNumber.txt file

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)

Screen1.Show
Screen1.Label1(0).Caption = "Changing Address " & vbCr _
& "to Client " & ClientName & vbCr _
& "IPAddr " & LocalIPAddress & vbCr _
& "Subnet " & SubNet & vbCr _
& "Gateway " & Gateway & vbCr _
& "Please Wait a minute . ."

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top