Jump to content

RunWait(@ComSpec


Recommended Posts

Hello All,

First see what I have so far:

Code:

#include <GuiConstants.au3>

#include <Array.au3>

#include <Date.au3>

AutoItSetOption ( "TrayIconHide", 1 )

Opt ("GUIOnEventMode", 1)

; GUI

; ===

GUICreate("IP Address Changing Tool 3.0", 600, 520, -1, -1, -1, $LVS_SHOWSELALWAYS)

GUISetIcon("Icons\AppIcon.ico")

; INPUT

; =====

$IPAddress = GUICtrlCreateInput("", 210, 170, 130, 20)

GUICtrlCreateLabel("IP-Address:", 120, 172)

$SubNet = GUICtrlCreateInput("", 210, 190, 130, 20)

GUICtrlCreateLabel("Subnet Mask:", 120, 192)

$Gatway = GUICtrlCreateInput("", 210, 210, 130, 20)

GUICtrlCreateLabel("Default Gatway:", 120, 212)

$DNS1 = GUICtrlCreateInput("", 210, 230, 130, 20)

GUICtrlCreateLabel("Preferred DNS:", 120, 232)

$DNS2 = GUICtrlCreateInput("", 210, 250, 130, 20)

GUICtrlCreateLabel("Alternate DNS:", 120, 252)

; BUTTON

; ======

$buttonchangeIP = GUICtrlCreateButton("Change my IP", 360, 170, 100, 30, "")

$buttonresetIP = GUICtrlCreateButton("Reset to DHCP", 360, 200, 100, 30, "")

$buttonDone = GUICtrlCreateButton("Done/Exit", 360, 230, 100, 30, "")

GUICtrlSetOnEvent($buttonchangeIP, "button")

GUISetState()

GUICtrlSetOnEvent($buttonDone, "buttonDone")

GUICtrlSetOnEvent($buttonresetIP, "SetDHCP")

GUICtrlSetBkColor(-1, 0x00ff00)

WinSetOnTop("Date", "", 1)

; GUI MESSAGE LOOP

; ================

GUISetState()

While 1

; GUI Set Ctrl Read

; =================

$IPAddressMessage = GUICtrlRead($IPAddress)

$SubNetMessage = GUICtrlRead($SubNet)

$GatwayMessage = GUICtrlRead($Gatway)

$DNS1Message = GUICtrlRead($DNS1)

$DNS2Message = GUICtrlRead($DNS2)

WEnd

Func buttonDone()

Exit

EndFunc ;==>buttonDone

Func SetDHCP()

RunWait(@ComSpec & " /c " & 'netsh interface ip set address "Local Area Connection" dhcp', "", @SW_HIDE)

RunWait(@ComSpec & " /c " & 'netsh interface ip set dns "Local Area Connection" dhcp', "", @SW_HIDE)

EndFunc ;==>SetDHCP

Func button()

; Call netsh command

; ==================

RunWait(@ComSpec & ' /c ' & 'netsh interface ip set address name="Local Area Connection" static '$IPAddressMessage' '$SubNetMessage' '$GatwayMessage' '1'', '', @SW_HIDE)

EndFunc ;==>button

When I click the rest to DHCP below code works:

RunWait(@ComSpec & " /c " & 'netsh interface ip set address "Local Area Connection" dhcp', "", @SW_HIDE)

RunWait(@ComSpec & " /c " & 'netsh interface ip set dns "Local Area Connection" dhcp', "", @SW_HIDE)

My problem it when trying to set the address to static, code below:

RunWait(@ComSpec & ' /c ' & 'netsh interface ip set address name="Local Area Connection" static '$IPAddressMessage' '$SubNetMessage' '$GatwayMessage' '1'', '', @SW_HIDE)

I have searched the forum for similar problems and tried using variations of " and ' but no luck.

Please can someone help cause I am pulling my hair out with this :whistle: , its proberbly an easy solution but I am out of ideas.

Error I get when running it from SciTE:

C:\IP-Changer\test.au3(70,99) : ERROR: syntax error

RunWait(@ComSpec & ' /c ' & 'netsh interface ip set address name="Local Area Connection" static '$IPAddressMessage

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\IP-Changer\test.au3 - 1 error(s), 0 warning(s)

Thanks,

Craig

Link to comment
Share on other sites

something like

RunWait(@ComSpec & ' /c ' & 'netsh interface ip set address name="Local Area Connection" static ' & $IPAddressMessage & ' ' & $SubNetMessage & ' ' & $GatwayMessage & ' ' & '1', '', @SW_HIDE)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...