Docfxit Posted April 30, 2020 Share Posted April 30, 2020 This code isn't changing the static IP address. I think it's because $Networkname doesn't have Quotes around it. I can't figure out how to add Quotes. ;Sometimes when I am working on a PC the IP settings get removed. This will put the IP settings back in. ;I would like this script to run everytime the machine reboots or when I run it manually. ;I would like it to check to make sure there is an internet connection. ;I would like to run this on a PC that is remote to me. I can't connect if it's not connected to the internet. ;AutoIt_Debugger_Command:Disable_Debug Opt("WinWaitDelay", 100) Opt("WinTitleMatchMode", 4) Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 0) Opt("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number #RequireAdmin ;AutoIt_Debugger_Command:Enable_Debug $Networkname = "Local Area Connection" $CMD = 'netsh interface ipv4 set address ' & $Networkname & ' static 192.168.2.5 255.255.255.0 192.168.2.254' _DosRun($CMD) _DosRun('netsh interface ipv4 add dns ' & $Networkname & ' 66.51.205.100') _DosRun('netsh interface ipv4 add dns ' & $Networkname & ' 66.51.206.100 index=2') Exit Func _DosRun($sCommand) Local $nResult = Run('"' & @ComSpec & '" /c ' & $sCommand, @SystemDir, @SW_HIDE, 6) Sleep(1000) ProcessWaitClose($nResult) Return StdoutRead($nResult) EndFunc ;==>_DosRun Link to comment Share on other sites More sharing options...
Gianni Posted April 30, 2020 Share Posted April 30, 2020 1 hour ago, Docfxit said: ... I can't figure out how to add Quotes. something like this: $CMD = 'netsh interface ipv4 set address "' & $Networkname & '" static 192.168.2.5 255.255.255.0 192.168.2.254' Docfxit 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Docfxit Posted April 30, 2020 Author Share Posted April 30, 2020 (edited) 10 hours ago, Chimp said: something like this: $CMD = 'netsh interface ipv4 set address "' & $Networkname & '" static 192.168.2.5 255.255.255.0 192.168.2.254' That worked perfectly in Windows 7 32bit. Thank you very much, I can't get it to replace the IP addresses in Windows 10 64bit. ;Sometimes when I am working on a PC the IP settings gets removed. This will put the IP settings back in. ;I would like this script to run everytime the machine reboots or when I run it manually. ;I would like it to check to make sure there is an internet connection. ;I would like to run this on a PC that is remote to me. I can't connect if it's not connected to the internet. Opt("WinWaitDelay", 100) Opt("WinTitleMatchMode", 4) Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 0) Opt("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number #RequireAdmin Global $CMD $Networkname = "Ethernet" $IPAddress = "192.168.168.7" $Gateway = "192.168.168.168" _DosRun($CMD) _DosRun('netsh interface ipv4 set address "' & $Networkname & '" static ' & $IPAddress & ' 255.255.255.0 ' & $Gateway) _DosRun('netsh interface ipv4 add dns "' & $Networkname & '" 66.51.205.100') _DosRun('netsh interface ipv4 add dns "' & $Networkname & '" 66.51.206.100 index=2') MsgBox(32, "Set IP Address", 'netsh interface ipv4 set address "' & $Networkname & '" static ' & $IPAddress & ' 255.255.255.0 ' & $Gateway) Exit Func _DosRun($sCommand) Local $nResult = Run('"' & @ComSpec & '" /c ' & $sCommand, @SystemDir, @SW_HIDE, 6) Sleep(1000) ProcessWaitClose($nResult) Return StdoutRead($nResult) EndFunc ;==>_DosRun Edited April 30, 2020 by Docfxit Link to comment Share on other sites More sharing options...
Gianni Posted April 30, 2020 Share Posted April 30, 2020 ...not sure, but worth try this line at the beginning of your script... #include <WinAPIFiles.au3> ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Docfxit Posted April 30, 2020 Author Share Posted April 30, 2020 (edited) That's a great idea. I tried it. The script still isn't working. I put in some if statements and it is running "X64 and it is "NOT @AutoItx64" So the if statement should be working. Thanks, Edited April 30, 2020 by Docfxit Link to comment Share on other sites More sharing options...
Nine Posted April 30, 2020 Share Posted April 30, 2020 (edited) Do you get any error messages after netsh commands ? You do not seem to report it. Edited April 30, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Docfxit Posted May 1, 2020 Author Share Posted May 1, 2020 8 hours ago, Nine said: Do you get any error messages after netsh commands ? You do not seem to report it. I'm not seeing any error messages. I'm not sure my script is written to show any errors. I don't know how to write something into the script to capture any errors. Thanks, Docfxit Link to comment Share on other sites More sharing options...
Nine Posted May 1, 2020 Share Posted May 1, 2020 Replace those lines by this : ConsoleWrite ("1 = " & _DosRun($CMD) & @CRLF) ConsoleWrite ("2 = " & _DosRun('netsh interface ipv4 set address "' & $Networkname & '" static ' & $IPAddress & ' 255.255.255.0 ' & $Gateway) & @CRLF) ConsoleWrite ("3 = " & _DosRun('netsh interface ipv4 add dns "' & $Networkname & '" 66.51.205.100') & @CRLF) ConsoleWrite ("4 = " & _DosRun('netsh interface ipv4 add dns "' & $Networkname & '" 66.51.206.100 index=2') & @CRLF) Run your script from Scite, report here the console, so we can have a look. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Docfxit Posted May 1, 2020 Author Share Posted May 1, 2020 6 hours ago, Nine said: Replace those lines by this : ConsoleWrite ("1 = " & _DosRun($CMD) & @CRLF) ConsoleWrite ("2 = " & _DosRun('netsh interface ipv4 set address "' & $Networkname & '" static ' & $IPAddress & ' 255.255.255.0 ' & $Gateway) & @CRLF) ConsoleWrite ("3 = " & _DosRun('netsh interface ipv4 add dns "' & $Networkname & '" 66.51.205.100') & @CRLF) ConsoleWrite ("4 = " & _DosRun('netsh interface ipv4 add dns "' & $Networkname & '" 66.51.206.100 index=2') & @CRLF) Run your script from Scite, report here the console, so we can have a look. Writing out the output was a really great idea. Thank you very much for the code. When I run it in Windows 10 I get: 1 = 2 = The object already exists. 3 = The object is already in the list. 4 = The object is already in the list. This is what the network screen looks like after it's run: When I run it in Windows 7 line #2 is empty and it inserts the IP addresses like it should. Thanks for the help, Docfxit Link to comment Share on other sites More sharing options...
faustf Posted May 2, 2020 Share Posted May 2, 2020 for me in windows 10 work Link to comment Share on other sites More sharing options...
jvds Posted May 4, 2020 Share Posted May 4, 2020 i had a problem with this also with a .bat script (that was run as admin), i think it was Win7, and i didn't look deep into it, i just did it like this, reset to dhcp then set ip and i worked. netsh interface ipv4 set address "Local Area Connection" dhcp netsh interface ipv4 add address "Local Area Connection" 192.168.1.44 255.255.255.0 192.168.1.1 pause also look in the advanced options in the internet protocol version4 tcpip properties, there you can add several IP addresses to the same network card, look if the IP addresses you are trying to add aren't already in the list, in my case they where not strangely, also it seems according to the console writes you posted that they are already added to the interface, so let know what you see there. Link to comment Share on other sites More sharing options...
Docfxit Posted May 4, 2020 Author Share Posted May 4, 2020 I ended up fix it with this code: expandcollapse popup;Sometimes when I am working on a PC the IP settings gets removed. This will put the IP settings back in. ;I would like this script to run everytime the machine reboots or when I run it manually. ;I would like it to check to make sure there is an internet connection. ;I would like to run this on a PC that is remote to me. I can't connect if it's not connected to the internet. #RequireAdmin #include <WinAPIFiles.au3> ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) Opt("WinWaitDelay", 100) Opt("WinTitleMatchMode", 4) Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 0) Opt("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number Global $CMD FileDelete(@ScriptDir & "\StaticIPAddressDebug.txt") $Networkname = "Ethernet 2" $IPAddress = "192.168.2.5" $Gateway = "192.168.2.254" FileWrite(@ScriptDir & "\StaticIPAddressDebug.txt" ,("1 = " & _DosRun($CMD) & @CRLF)) FileWrite(@ScriptDir & "\StaticIPAddressDebug.txt" ,("2 = " & _DosRun('netsh int ip reset') & @CRLF)) FileWrite(@ScriptDir & "\StaticIPAddressDebug.txt" ,("3 = " & _DosRun('netsh interface ipv4 set address "' & $Networkname & '" static ' & $IPAddress & ' 255.255.255.0 ' & $Gateway) & @CRLF)) FileWrite(@ScriptDir & "\StaticIPAddressDebug.txt" ,("4 = " & _DosRun('netsh interface ipv4 add dns "' & $Networkname & '" 66.51.205.100') & @CRLF)) FileWrite(@ScriptDir & "\StaticIPAddressDebug.txt" ,("5 = " & _DosRun('netsh interface ipv4 add dns "' & $Networkname & '" 66.51.206.100 index=2') & @CRLF)) Exit Func _DosRun($sCommand) Local $nResult = Run('"' & @ComSpec & '" /c ' & $sCommand, @SystemDir, @SW_HIDE, 6) Sleep(1000) ProcessWaitClose($nResult) Return StdoutRead($nResult) EndFunc ;==>_DosRun When I have a network problem on a remote PC I: 1. Compile the script above and put a link to it in Programs, Starup 2. Add the program to my antivirus exclusions. 3. Run a bat file that resets the network and does a reboot. Thanks to everyone for the help, Docfxit 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