I know how to do it manually in XP, but i was wondering if i could automate the process from within my app. Any ideas?
Ill keep looking meanwhile.
Thanx in advance.
Ill keep looking meanwhile.

Thanx in advance.
#DIM ALL #Compile exe #Include "WIN32API.INC" Function PBMain() STATIC hConsole AS LONG, cWritten AS LONG LOCAL sOut, CommandLine AS STRING AllocConsole hConsole = GetStdHandle(%STD_OUTPUT_HANDLE) SetConsoleTitle "Netsh IP Test" ' Read current IP settings - sOut = "Getting Current IP settings:" + $CRLF WriteFile hConsole, BYVAL STRPTR(sOut), LEN(sOut), cWritten, BYVAL 0& CommandLine = "netsh interface ip show config" Shell (Environ$("comspec") & " /C " & CommandLine, 0) ' Set Static IP address - sOut = "Set Static IP (can take a few seconds!):" + $CRLF WriteFile hConsole, BYVAL STRPTR(sOut), LEN(sOut), cWritten, BYVAL 0& CommandLine = "netsh interface ip set address "+$Dq+"Local Area Connection"+$Dq+ _ " static 192.168.0.100 255.255.255.0 192.168.0.1 1" Shell (Environ$("comspec") & " /C " & CommandLine, 0) ' Confirm Settings - sOut = "New IP settings:" + $CRLF WriteFile hConsole, BYVAL STRPTR(sOut), LEN(sOut), cWritten, BYVAL 0& CommandLine = "netsh interface ip show config" Shell (Environ$("comspec") & " /C " & CommandLine, 0) ' Change to DHCP - sOut = "Change to DHCP:" + $CRLF WriteFile hConsole, BYVAL STRPTR(sOut), LEN(sOut), cWritten, BYVAL 0& CommandLine = "netsh interface ip set address "+$Dq+"Local Area Connection"+$Dq+" dhcp" Shell (Environ$("comspec") & " /C " & CommandLine, 0) ' Confirm Settings - sOut = "Wait 10 seconds for New IP settings:" + $CRLF ' may be longer?? WriteFile hConsole, BYVAL STRPTR(sOut), LEN(sOut), cWritten, BYVAL 0& Sleep 10000 CommandLine = "netsh interface ip show config" Shell (Environ$("comspec") & " /K " & CommandLine, 0) 'MsgBox "Close" 'instead of '/K' in last Shell command FreeConsole End Function '------------------/
#Dim All #Compile Exe #INCLUDE "WIN32API.INC" #Include "IPHLPAPI.INC" DECLARE FUNCTION inet_addr LIB "wsock32.dll" ALIAS "inet_addr" (cp AS ASCIIZ) AS DWORD ' in WSock32.inc ' Internet Protocol dotted address to proper address for the IN_ADDR structure DECLARE FUNCTION inet_ntoa LIB "wsock32.dll" ALIAS "inet_ntoa" (byval inn AS DWORD) AS DWORD ' returns ASCIIZ PTR Function ErrorMsg (ByVal ErrorCode As Dword) As String Local szMsg As Asciiz * 255 FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0, ErrorCode, 0, szMsg, SIZEOF(szMsg), ByVal 0 Function = Str$(ErrorCode) +" "+ szMsg End Function '------------------/ErrorMsg Function PbMain() Local i, Res As Long Local iSize As Long Local pIPADD As MIB_IPADDRTABLE Ptr ' contains table of MIB_IPADDRROW structures Local sBuffer, Msg As String Local IpAddr, IpMask, IfIndex As Dword Local Address As Dword Static NTEContext, NTEInstance As Dword Static pszIP, pszMask As Asciiz Ptr 'First call gets the required size for the table, ie the iSize result is set If GetIpAddrTable (ByVal 0, iSize, 0) = %ERROR_INSUFFICIENT_BUFFER Then sBuffer = Space$(iSize) 'Second call gets tha actual data - current IP info. If GetIpAddrTable (ByVal StrPtr(sBuffer), iSize, 0) = %NO_ERROR Then pIPADD = StrPtr(sBuffer) 'Pointer to a buffer that receives the interface–to–IP address mapping table as a MIB_IPADDRTABLE structure. For i = 0 To @pIPADD.dwNumEntries - 1 ' loop through number of IP address entries in the table IpAddr = @pIPADD.table(i).dwAddr IpMask = @pIPADD.table(i).dwMask IfIndex = @pIPADD.table(i).dwIndex pszIP = inet_ntoa (IpAddr) : Msg = "ADDRESS : " + @pszIP + $CRLF pszMask = inet_ntoa (IpMask) : Msg = Msg + "SUBNET : " + @pszMask + $CRLF MsgBox Msg ,,"TCP/IP Interface INDEX " + Str$(IfIndex) Next '// Add new IP Address = inet_addr("192.168.0.27") IPMask = inet_addr("255.255.255.0") IfIndex = @pIPADD.table(0).dwIndex ' Primary Interface? MsgBox "Entry; "+Str$(IfIndex) ' Variables where handles to the added IP will be returned NTEContext = 0 : NTEInstance = 0 Res = AddIPAddress(Address, IPMask, IfIndex, NTEContext, NTEInstance) If Res = %NO_ERROR Then MsgBox "IP address added." Else MsgBox ErrorMsg (Res), ,"Error Adding IP" End If '// Delete the IP we just added using the NTEContext created by AddIpAddress Res = DeleteIPAddress(NTEContext) If Res = %NO_ERROR Then MsgBox "Address Deleted." Else MsgBox ErrorMsg (Res), ,"Error Deleting IP" End If Else MsgBox "Error retrieving IP address table.",,"Error" End If Else MsgBox "Error getting the size needed to retrieve the IP address table.",,"Error" End If End Function '------------------/
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment