erebus Posted November 21, 2004 Share Posted November 21, 2004 (edited) Hello once again guys, I want some help of how to change my local computer's name and its NIC's IP address via AU3. What I want is to write a script that will decide which computer name to be used based on the private IP entered and vice versa (i.e. if ip = 192.168.1.10 then compname = Terminal-10). Ok I can use the Spy-n-Click method but is anyone aware of a more elite method to achieve it (via shell32.exe commands or something similar?) Thanks in advance, Edited November 21, 2004 by erebus Link to comment Share on other sites More sharing options...
erebus Posted November 22, 2004 Author Share Posted November 22, 2004 ...impossible? Link to comment Share on other sites More sharing options...
JSThePatriot Posted November 22, 2004 Share Posted November 22, 2004 Might have to google that one. I dont know of any DllCall() (because I havent gotten into that yet) JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
piccaso Posted November 22, 2004 Share Posted November 22, 2004 you can get the ip from @IPAdress1 - 4 macros and set compname using SetComputerName or SetComputerNameEx api functions CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
SlimShady Posted November 22, 2004 Share Posted November 22, 2004 (edited) If you can't find it in the help file, it means there's no AutoIt function that does what you want. So there are 2 things you can do. 1. do the actions manually and type them in a txt file (eg. Press Win key+PAUSE, Ctrl+Tab, ControlClick) 2. Search on www.Google.com for a command line tool that does what you want and run it using a batch file (or AutoIt) Edited November 22, 2004 by SlimShady Link to comment Share on other sites More sharing options...
this-is-me Posted November 22, 2004 Share Posted November 22, 2004 Check out something called PeNetCfg from http://www.geocities.com/pierremounir/Also, check out my personal struggle trying to automate it here: http://www.autoitscript.com/forum/index.php?showtopic=2643 Who else would I be? Link to comment Share on other sites More sharing options...
erebus Posted November 22, 2004 Author Share Posted November 22, 2004 (edited) @JSThePatriot: I already did my friend. However I couldn't find something easy-to-use/understand. @piccaso: I got the point but I know nothing of how to use these functions. Could you please give me an example? (mainly of which dll to call and with which parameters). I didn't check the link thoroughly so if the URL already answers that, please forgive me in advance. @this-is-me: This tool seems simple and easy-to-manipulate using AU3! Thank you very much for the work around, I suppose that I am going to use it (haven't tested it yet but I believe it will do the job). I would prefer to have some functions doing these though Thanks to all of you guys, you are great! Edited November 22, 2004 by erebus Link to comment Share on other sites More sharing options...
piccaso Posted November 23, 2004 Share Posted November 23, 2004 @piccaso: I got the point but I know nothing of how to use these functions. Could you please give me an example? (mainly of which dll to call and with which parameters). I didn't check the link thoroughly so if the URL already answers that, please forgive me in advance.<{POST_SNAPBACK}>here is your exampleexpandcollapse popupGlobal $API_ERROR_INVALID_PARAMETER = 87 Func API_SetComputerName($computername) Local $r $r = DllCall("Kernel32.dll", "long", "SetComputerNameA", "str", $computername) If IsArray($r) == 0 Or @error > 0 Then SetError(1); Error Calling Return 0;Failture EndIf If $r[0] = $API_ERROR_INVALID_PARAMETER Then SetError(2); characters are outside the standard character set Return 0;Failture EndIf If $r <> 0 Then Return 1; Success Else SetError(3); Other error Return 0;Failture EndIf EndFunc Func API_GetLastError() Local $r $r = DllCall("Kernel32.dll", "long", "GetLastError") If IsArray($r) == 0 Or @error > 0 Then SetError(1); Error Calling Return -256 EndIf Return $r[0] EndFunc ; Example Usage If API_SetComputerName("plumpsklo") Then MsgBox(0, "", "Sucess") Else If @error == 3 Then MsgBox(0, "", "Failture" & @CR & "GetLastError = " & API_GetLastError()) Else MsgBox(0, "", "Failture" & @CR & "@Error = " & @error) EndIf EndIfThis only sets netbios name to 'plumpsklo' for more options you will have to use SetComputerNameExyou can use enumerations by passing integersas for the COMPUTER_NAME_FORMAT enum type use1 for ComputerNameNetBIOS2 for ComputerNameDnsHostname3 for ComputerNameDnsDomainand so on...hope you get it CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
erebus Posted November 24, 2004 Author Share Posted November 24, 2004 Thank you very much my friend, great example! I will start coding this thing tomorrow and I will let you know of the results Link to comment Share on other sites More sharing options...
nobby Posted November 24, 2004 Share Posted November 24, 2004 The following command configures the interface named Local Area Connection with the static IP address 192.168.0.100, the subnet mask of 255.255.255.0, and a default gateway of 192.168.0.1:netsh interface ip set address name="Local Area Connection" static 192.168.0.100 255.255.255.0 192.168.0.1 1For the renaming, there is a support tool for Windows XP called NETDOM which allows you to rename PC from a command line. CheersNobby Link to comment Share on other sites More sharing options...
erebus Posted November 24, 2004 Author Share Posted November 24, 2004 @nobby: Thanks a lot, pretty useful information. Found netdom here. Link to comment Share on other sites More sharing options...
Chika95 Posted November 25, 2008 Share Posted November 25, 2008 Made a small utility for my work to change to a few set IP address in a system tray menu. As we support a few systems around our factory we often have to switch to the local IP address of the isolated network. This will allow us to quickly change the IP address. Feel free to modify it to suit your needs expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=NEDFLA~1.ICO #AutoIt3Wrapper_outfile=IP Address Changer.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;IP address changer Utility ;Terry J Myers ;Johnson Matthey ;11.24.08 ; ;Function: system tray icon that allows user to quickly change IP address to an address that cooresponds to ;some of our equipment in Devon 1 that is not on the 192.168 network ; ;If new equipment needs to be added, contact Terry Myers, or following this procedure: ;1. Find the IP address and subnet mask you need ;2. Uncomment the pre-prepared lines by getting rid of the comment symbol: ";" in front of the lines that pertain ;3. enter the correct IP address and Subnet Mask in the case select #Include <Constants.au3> #include <Array.au3> #NoTrayIcon If @OSVersion <> "WIN_XP" then ; Check to see if this is Window XP, at some point we will upgrade to vista and this utility may not work msgbox(0,"Windows XP only","This utility will only work on Windows XP") Exit EndIf ;TraySetToolTip ("IP Address Change Utility") Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. $IPAddress = "XXX.XXX.XXX.XXX" ;Set a generic IP address to display for stuff ;Setup Menu items $D1Menu = TrayCreateMenu("Devon I") $D1AID = TrayCreateItem("AID: 192.168.73.22.0", $D1Menu) $D1LD = TrayCreateItem("Lanly Dryer: 192.168.28.244", $D1Menu) $D1LAK = TrayCreateItem("Lanly Air Knive: 100.100.100.145", $D1Menu) ;$NewEquipment1 = TrayCreateItem("New Equipment 1", $D1Menu); get rid of the front comment of this line to activate this menu option ;$NewEquipment2 = TrayCreateItem("New Equipment 2", $D1Menu);get rid of the front comment of this line to activate this menu option $ManualEntry = TrayCreateItem("Enter IP Manually") $AutoDHCP = TrayCreateItem("Go back to automatic DHCP") TrayCreateItem("") $aboutitem = TrayCreateItem("About") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() ;MAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOP While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $D1AID ChangeIpAddress("192.168.73.22.0", "255.255.255.0",1) Case $msg = $D1LD ChangeIpAddress("192.168.28.244", "255.255.255.0",1) Case $msg = $D1LAK ChangeIpAddress("100.100.100.145", "255.255.255.0",1) ;Get rid of the first comment in the next two lines to activate the menu option, also add the IP address and subnet mask in the appropriate place ;Case $msg = $NewEquipment1 ;ChangeIpAddress("ENTER IP ADDRESS HERE", "ENTER SUBNETMASK HERE",1); ;Get rid of the first comment int he next two lines to activate the menu option, also add the IP address and subnet mask in the appropriate place ;Case $msg = $NewEquipment2 ;ChangeIpAddress("ENTER IP ADDRESS HERE", "ENTER SUBNETMASK HERE",1); Case $msg = $ManualEntry While 1 $IPAddress = InputBox ( "Enter IP address", "Enter IP Address", $IPAddress) If @error = 1 then continueloop(2) IF CheckIPAddressForErrors($IPAddress) = 1 then continueloop exitloop Wend IF @error = 0 then ChangeIpAddress($IPAddress, "255.255.255.0",1) Case $msg = $AutoDHCP ChangeIpAddress(0,0,0) Case $msg = $aboutitem Msgbox(64, "IP Address Change Utility:", "This ultity changes IP addresses quickly when accessing equipment that requires such. Created by Terry Myers, JM Automation.") Case $msg = $exititem ExitLoop EndSelect WEnd ;MAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOP Exit ;-------------------------------------------- Func ChangeIpAddress($IPAddress, $SubnetMask,$change) ;Changes IP address using netsh interface in a dos prompt window ;$Change = 0 or 1 where 0 = set IP back to Automatically obtain address from DHCP, 1 = change to stated IP and Subnet $timeouttime = 20000 ;Time to wait for dos window to finish before erroring. MUST be a multiple of 100! While 1 ;This is a loop in case it fails you can give the user the option of starting the loop over effectivley redoing this function. Select ;Select which Dos prompt to run and run it Case $change = 0 $Run = Run(@ComSpec & " /c " & "netsh interface ip set address name=""Local Area Connection"" source=dhcp", "", @SW_Show,8) Case $Change = 1 $Run = Run(@ComSpec & " /c " & "netsh interface ip set address name=""Local Area Connection"" static " & $IPAddress & " " & $SubnetMask, "", @SW_Show,8) EndSelect ProgressOn ( "Changing IP Address to: " & $IPAddress, "Waiting for the dos window to complete...","",@DesktopWidth/2-200,@DesktopHeight/2-50,16);Start fake progress bar $i = 0 $timer = timerinit() ;Start timeout timer While 1 ;Loop until the dos window finished sleep($timeouttime/100) ;Divide time into 100 parts to sleep for $i= $i+1 ProgressSet( $i, $i & " percent") ;Set progress each loop If timerdiff($timer) >$timeouttime then ;If you reach the timeout time give user option to try again or quit the function ProgressOff ( ) IF msgbox(5,"ERROR","It screwed up, you will have to change it manually.") = 4 then Continueloop(2) Else return EndIf EndIf $line = StdoutRead($Run) If @error Then ExitLoop Wend ProgressOff ( ) Select ;Display success Case $change = 0 msgbox(0,"DHCP assigned address Set","Obtain IP Address Automatically") Case $Change = 1 msgbox(0,"IP Address Set",$IPAddress & " / " & $SubnetMask) EndSelect return WEnd endfunc ;-------------------------------------------------- Func CheckIPAddressForErrors($IPAddress) $array = Stringsplit($IPAddress,".") ;Populate an array with the IP address. The array SHOULD look like: 0: Number of strings returned(should be 4), 1-4, integers from 0 to 255 ;check to make sure there are 4 numbers separated by "." If $array[0] <> 4 then msgbox(0,"ERROR","Not an properly formatted IP Address") return 1 EndIf ;check each number of the address for 0-255 and an integer for $i = 1 to 4 IF $array[$i] < 0 OR $array[$i] > 255 or ISINT(Number($array[$i])) = 0 Then msgbox(0,"ERROR","Not an properly formatted IP Address") return 1 EndIf next Return 0 EndFunc Link to comment Share on other sites More sharing options...
hackerbaby Posted March 14, 2009 Share Posted March 14, 2009 Made a small utility for my work to change to a few set IP address in a system tray menu. As we support a few systems around our factory we often have to switch to the local IP address of the isolated network. This will allow us to quickly change the IP address. Feel free to modify it to suit your needs expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=NEDFLA~1.ICO #AutoIt3Wrapper_outfile=IP Address Changer.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;IP address changer Utility ;Terry J Myers ;Johnson Matthey ;11.24.08 ; ;Function: system tray icon that allows user to quickly change IP address to an address that cooresponds to ;some of our equipment in Devon 1 that is not on the 192.168 network ; ;If new equipment needs to be added, contact Terry Myers, or following this procedure: ;1. Find the IP address and subnet mask you need ;2. Uncomment the pre-prepared lines by getting rid of the comment symbol: ";" in front of the lines that pertain ;3. enter the correct IP address and Subnet Mask in the case select #Include <Constants.au3> #include <Array.au3> #NoTrayIcon If @OSVersion <> "WIN_XP" then ; Check to see if this is Window XP, at some point we will upgrade to vista and this utility may not work msgbox(0,"Windows XP only","This utility will only work on Windows XP") Exit EndIf ;TraySetToolTip ("IP Address Change Utility") Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. $IPAddress = "XXX.XXX.XXX.XXX" ;Set a generic IP address to display for stuff ;Setup Menu items $D1Menu = TrayCreateMenu("Devon I") $D1AID = TrayCreateItem("AID: 192.168.73.22.0", $D1Menu) $D1LD = TrayCreateItem("Lanly Dryer: 192.168.28.244", $D1Menu) $D1LAK = TrayCreateItem("Lanly Air Knive: 100.100.100.145", $D1Menu) ;$NewEquipment1 = TrayCreateItem("New Equipment 1", $D1Menu); get rid of the front comment of this line to activate this menu option ;$NewEquipment2 = TrayCreateItem("New Equipment 2", $D1Menu);get rid of the front comment of this line to activate this menu option $ManualEntry = TrayCreateItem("Enter IP Manually") $AutoDHCP = TrayCreateItem("Go back to automatic DHCP") TrayCreateItem("") $aboutitem = TrayCreateItem("About") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() ;MAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOP While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $D1AID ChangeIpAddress("192.168.73.22.0", "255.255.255.0",1) Case $msg = $D1LD ChangeIpAddress("192.168.28.244", "255.255.255.0",1) Case $msg = $D1LAK ChangeIpAddress("100.100.100.145", "255.255.255.0",1) ;Get rid of the first comment in the next two lines to activate the menu option, also add the IP address and subnet mask in the appropriate place ;Case $msg = $NewEquipment1 ;ChangeIpAddress("ENTER IP ADDRESS HERE", "ENTER SUBNETMASK HERE",1); ;Get rid of the first comment int he next two lines to activate the menu option, also add the IP address and subnet mask in the appropriate place ;Case $msg = $NewEquipment2 ;ChangeIpAddress("ENTER IP ADDRESS HERE", "ENTER SUBNETMASK HERE",1); Case $msg = $ManualEntry While 1 $IPAddress = InputBox ( "Enter IP address", "Enter IP Address", $IPAddress) If @error = 1 then continueloop(2) IF CheckIPAddressForErrors($IPAddress) = 1 then continueloop exitloop Wend IF @error = 0 then ChangeIpAddress($IPAddress, "255.255.255.0",1) Case $msg = $AutoDHCP ChangeIpAddress(0,0,0) Case $msg = $aboutitem Msgbox(64, "IP Address Change Utility:", "This ultity changes IP addresses quickly when accessing equipment that requires such. Created by Terry Myers, JM Automation.") Case $msg = $exititem ExitLoop EndSelect WEnd ;MAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOP Exit ;-------------------------------------------- Func ChangeIpAddress($IPAddress, $SubnetMask,$change) ;Changes IP address using netsh interface in a dos prompt window ;$Change = 0 or 1 where 0 = set IP back to Automatically obtain address from DHCP, 1 = change to stated IP and Subnet $timeouttime = 20000 ;Time to wait for dos window to finish before erroring. MUST be a multiple of 100! While 1 ;This is a loop in case it fails you can give the user the option of starting the loop over effectivley redoing this function. Select ;Select which Dos prompt to run and run it Case $change = 0 $Run = Run(@ComSpec & " /c " & "netsh interface ip set address name=""Local Area Connection"" source=dhcp", "", @SW_Show,8) Case $Change = 1 $Run = Run(@ComSpec & " /c " & "netsh interface ip set address name=""Local Area Connection"" static " & $IPAddress & " " & $SubnetMask, "", @SW_Show,8) EndSelect ProgressOn ( "Changing IP Address to: " & $IPAddress, "Waiting for the dos window to complete...","",@DesktopWidth/2-200,@DesktopHeight/2-50,16);Start fake progress bar $i = 0 $timer = timerinit() ;Start timeout timer While 1 ;Loop until the dos window finished sleep($timeouttime/100) ;Divide time into 100 parts to sleep for $i= $i+1 ProgressSet( $i, $i & " percent") ;Set progress each loop If timerdiff($timer) >$timeouttime then ;If you reach the timeout time give user option to try again or quit the function ProgressOff ( ) IF msgbox(5,"ERROR","It screwed up, you will have to change it manually.") = 4 then Continueloop(2) Else return EndIf EndIf $line = StdoutRead($Run) If @error Then ExitLoop Wend ProgressOff ( ) Select ;Display success Case $change = 0 msgbox(0,"DHCP assigned address Set","Obtain IP Address Automatically") Case $Change = 1 msgbox(0,"IP Address Set",$IPAddress & " / " & $SubnetMask) EndSelect return WEnd endfunc ;-------------------------------------------------- Func CheckIPAddressForErrors($IPAddress) $array = Stringsplit($IPAddress,".") ;Populate an array with the IP address. The array SHOULD look like: 0: Number of strings returned(should be 4), 1-4, integers from 0 to 255 ;check to make sure there are 4 numbers separated by "." If $array[0] <> 4 then msgbox(0,"ERROR","Not an properly formatted IP Address") return 1 EndIf ;check each number of the address for 0-255 and an integer for $i = 1 to 4 IF $array[$i] < 0 OR $array[$i] > 255 or ISINT(Number($array[$i])) = 0 Then msgbox(0,"ERROR","Not an properly formatted IP Address") return 1 EndIf next Return 0 EndFunc YOur script very nice, if i want to change "defaultgateway" .... how to code it ?? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 14, 2009 Developers Share Posted March 14, 2009 YOur script very nice, if i want to change "defaultgateway" .... how to code it ??Have you looked at the Netsh command on what needs adding for the gateway? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
hackerbaby Posted March 14, 2009 Share Posted March 14, 2009 Have you looked at the Netsh command on what needs adding for the gateway?yes, i viewed Netsh command, i can use it to change the gateway .... but i don't know how to code script do it ... Link to comment Share on other sites More sharing options...
Developers Jos Posted March 14, 2009 Developers Share Posted March 14, 2009 Show the code you tried? Jos PS:(no need to change the color of your text) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Legacy99 Posted March 14, 2009 Share Posted March 14, 2009 (edited) Here is where you change the computer name for a non domain connected XP pc. RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$PCNAME) RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters","NV Hostname","REG_SZ", $PCNAME) Here what you can use to set your IP's RunWait (@ComSpec & " /c " & "netsh interface ip set address Local static " & $PCs_IP & " " & $PC_Subnetmask & " " & $PC_Gateway & " 1", @SystemDir) RunWait (@ComSpec & " /c " & "netsh interface ip set dns Local static 192.168.0.1") RunWait (@ComSpec & " /c " & "netsh interface ip add dns Local 192.168.0.2") Edited March 14, 2009 by Legacy99 Link to comment Share on other sites More sharing options...
bDooley Posted March 3, 2010 Share Posted March 3, 2010 Just want to thank Jos and BotXpert for your posts. BotXpert..I have taken parts of your ip change function for use in scripts at my company. Thanks, bDooley Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now