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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing IP address in Windows7

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
0
0
AU
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?

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
 
What did'nt work, what error message did you get?

>1. Standard prompt does not work. How does one get to an "elevated prompt?"

To run any program elevated you right click its .exe file, or a ShortCut to it and select the 'Run as Administator' option; when that is done you will get a UAC prompt for yes/no confirmation when using an Admin account; when using a limited account you will be prompted to enter an Administrator's credentials before you are allowed to confirm the action.

In the case of the Command Prompt (cmd.exe) window it will have the caption 'Command Prompt' when not elevated and the caption 'Administrator Command Prompt' when it is.

Programs you make yourself can be made so that they will automatically prompt for elevation when run without need to right click them. The proper way to do this is to use a program manifest however it is possible to cheat by including the magic word 'setup' (there are some others) in the .exe file name. Cheating is not recommended but may serve to demonstrate.

 
>there are still some people that want to run computers as a device NOT connected to the internet

Then perhaps Windows is not the OS you should be using ... (yes. yes. I knopw - it isn't for you to choose; the point is that there's no use complaining that a hammer cannot be used as a spoon and that that's the hammer maker's fault)
 
Unless you enabled the true "Administrator" account, you are NOT an administrator, and strongm explained why earlier. If you want no password and no security, I imagine you could just enable the Administrator account and disable User Account Control and be done with it. Normally I would never recommend that, but in your environment maybe this would work.
 
Thanks you all for your interest but this seems to be a circular discussion thus avoiding the simple answer to my question.

I have found on another forum how to run the Elevated Prompt and will investigate this further.

 
>a circular discussion

Only because you seem to keep focussing on how nobody seems to understand your specific requirements and ignoring the actual suggestions. For example, I'll repeat - again - did you try the WMI solution? Or take on board guitarzan's suggestion of simply enabling the real W7 Administrator account and running under that, just as you currently do for XP?

>have found on another forum how to run the Elevated Prompt

Typically the etiquette on this forum would be for you to post the solution that you found (or at least a link to it) so that others coming to this thread later looking for a similar solution know where to find it.

 
Your advice is appreciated.
My interpretation of the answers was that they were explaining the problem but not the answer so I couldn't try out or know how to try some of the suggestions.

>simply enabling the real W7 Administrator account
How do you suggest that I do just that?

Sorry I didn't post the info about Elevated Prompt as it appeared you all already knew how to do this.
The original reason why I didn't know how to do it was I didn't even know it existed and thus didn't know that I didn't know about it!(My great great grandma was Irish by the way).
I only bought Win7 a few weeks ago.

Win7 Elevated cmd prompt is reached by typing cmd into the Search box of the START WINDOW and holding shift+control and hitting enter.
It will be elevated if "Administrator" appears at the top of the cmd window and you have logged on as an administrator.

<It sounds as if you are just copying a file with the IP address then.
No. The IP of EVERY computer involved is on a text file in every computer.
The number you change in another INI file when you change a computer, simply points to the line of text desired and so retrieves the correct IP - simple.
All computers are therefore interchangeable by changing 1 number.
You don't have to reboot the computer for the new IP to take effect.

>Does the same stuff work if you type in the two 'DOS' commands manually from;
No I get an error saying The following command was not found (then repeats the command)
If I say only 'local' instead of 'Local area connection', it says "Failed to configure the DHCP service Interface may be disconnected, Cant find the file"

Changing IP to IPv4 makes no difference.
I obviously have the wrong syntax even though it is as recommended by Microsoft for Win2000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top