Jump to content

Need Help... Array to ListView


Mowalk
 Share

Recommended Posts

Hello,

i know this is probably a simple question, but in my defence i never programmed anything untill last week when i got the task to use Autoit to make a programm that can change IP-configs. So far i could do everything with the wiki and the tutorial is found.

So i got this Button that is supposed to update a listView with the current configuration of the network adapters. This works fine as long as all the information is there but if for example here is no DNS or gateway configured the whole thing crashes.

Follow error message: Subscript used with non-Array variable

Func UpdateAdapters()
_GUICtrlListView_DeleteAllItems($ListView)


$count = 0
$objWMI = ObjGet("winmgmts:\\.\root\cimv2")
$collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")


$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colNIC = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapter WHERE Netconnectionstatus = 2")
Dim $pcinfo
For $object In $colNIC
$pcinfo = $pcinfo & $object.name & @CRLF
Next


For $obj In $collection
If $obj.DHCPEnabled = -1 Then
$currentDHCPStatus = "TRUE"
Else
$currentDHCPStatus = "FALSE"
EndIf

$currentIP = $obj.IPAddress
$currentSubnet = $obj.IPSubnet
$currentGateway = $obj.DefaultIPGateway
$currentDNS = $obj.DNSServerSearchOrder


Next
For $obj In $collection
$count = $count + 1
If $obj.DHCPEnabled = -1 Then
$currentDHCPStatus1 = "TRUE"
Else
$currentDHCPStatus1 = "FALSE"
EndIf

$currentIP = $obj.IPAddress
$currentSubnet = $obj.IPSubnet
$currentGateway = $obj.DefaultIPGateway
$currentDNS = $obj.DNSServerSearchOrder


$item2 = GUICtrlCreateListViewItem("Name | Subnet | Gateway | DNS | DHCP", $ListView)


GUICtrlSetData($item2, $pcinfo & " | " & $currentIP[0] & " | " & $currentSubnet[0] & " | " & $currentGateway[0] & " | " & $currentDNS[0] & " | " & $currentDHCPStatus)

Next


EndFunc

Thanks for any help or tips

Cheers

Link to comment
Share on other sites

  • Moderators

Mowalk,

Then for the benefit of others who might read this thread in the future, could you please explain how? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Of course!

the problem was that if the Gateway or the DNS were not configured in the system the variable $currentDNS and $currentGW were empty variable instead of an array. Thats why i got the Subscript used with non-Array variable error.

So i add lines which check if the variables are arrays and if not turn them into arrays. I also added the "not set" so that the listview woulnd't just be empty at that part of the table but say that the GW/DNS is not set.

i hope that makes sense so far.

here is the new code

Func UpdateAdapters()
_GUICtrlListView_DeleteAllItems($ListView)

$count = 0
$objWMI = ObjGet("winmgmts:\\.\root\cimv2")
$collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colNIC = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapter WHERE Netconnectionstatus = 2")
Dim $pcinfo
For $object In $colNIC
$pcinfo = $pcinfo & $object.name & @CRLF
Next


For $obj In $collection
If $obj.DHCPEnabled = -1 Then
$currentDHCPStatus = "TRUE"
Else
$currentDHCPStatus = "FALSE"
EndIf

$currentIP = $obj.IPAddress
$currentSubnet = $obj.IPSubnet
$currentGateway = $obj.DefaultIPGateway
$currentDNS = $obj.DNSServerSearchOrder


Next
For $obj In $collection
$count = $count + 1

If $obj.DHCPEnabled = -1 Then
$currentDHCPStatus1 = "TRUE"
Else
$currentDHCPStatus1 = "FALSE"
EndIf
$currentIP = $obj.IPAddress
$currentSubnet = $obj.IPSubnet
$currentGateway = $obj.DefaultIPGateway
$currentDNS = $obj.DNSServerSearchOrder

; New Lines start here----------------------
if Not IsArray($currentGateway) Then
Dim $currentGateway[$count+1]
$currentGateway[0] = "not set"
EndIf

if Not IsArray($currentDNS) Then
Dim $currentDNS[$count+1]
$currentDNS[0] = "not set"
EndIf
;New Lines end here---------------------

$item2 = GUICtrlCreateListViewItem("Name | Subnet | Gateway | DNS | DHCP", $ListView)
GUICtrlSetData($item2, $pcinfo & " | " & $currentIP[0] & " | " & $currentSubnet[0] & " | " & $currentGateway[0] & " | " & $currentDNS[0] & " | " & $currentDHCPStatus)
Next


EndFunc
Link to comment
Share on other sites

  • Moderators

Mowalk,

Thanks. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 month later...

Hi so i got it to run the way i wanted it but it is still a very rough ... there is no errorhandling in it and so on.... Nevertheless here you go:

(After every start the pre-saved conifguration are the same... i did that so i wouldn't have to type them everytime i tested it)

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#Include 

$connections = GuiCtrlCreateCombo("Connection", 20, 10, 220, 21)
$counter = 0 ;Variablendeklaration
$counter2 = 0 ;Variablendeklaration

$currentIP = "" ;Variablendeklaration
$currentSubnet = "" ;Variablendeklaration
$currentGateway = "Gateway" ;Variablendeklaration
$currentDNS = "" ;Variablendeklaration
$currentDNS1 = "" ;Variablendeklaration
$currentName= ""
global $Form1,$Combo1, $ComboConNames


$base = "HKLM\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}"
$configname ="" ;Variablendeklaration
$configIP = "" ;Variablendeklaration
$configSNM ="" ;Variablendeklaration
$configGW = "" ;Variablendeklaration
$configDNS ="" ;Variablendeklaration
$configDHCP="" ;Variablendeklaration
$index="" ;Variablendeklaration
$adaptername ="" ;Variablendeklaration

DIm $var, $SelectedName[16]
$ini = @WorkingDir & "\IP-Config.ini" ;Variablendeklaration
$data="" ;Variablendeklaration
$IP="" ;Variablendeklaration
$SM="" ;Variablendeklaration
$comboname="" ;Variablendeklaration
$comboNetConName =""

$ListView="" ;Variablendeklaration
$txtName ="" ;Variablendeklaration
$txtIP ="" ;Variablendeklaration
$txtSNM ="" ;Variablendeklaration
$txtdefaultGW ="" ;Variablendeklaration
$txtDNS ="" ;Variablendeklaration
$btnConfSave ="" ;Variablendeklaration
$btnChange ="" ;Variablendeklaration
$chboxDHCP="" ;Variablendeklaration
$btnSetIP="" ;Variablendeklaration

Func _iniwrite($number,$name,$ipaddr,$SNmask,$gateway,$DNS,$DHCP) ;Write .ini Func
$sectionnumber="Section" & $number
iniWriteSection($ini,$sectionnumber,"") ;Write .ini Section
IniWrite($ini,$sectionnumber,"NAME",$name) ;Write .ini Name Bereich
IniWrite($ini,$sectionnumber,"IP",$ipaddr) ;Write .ini IP Bereich
IniWrite($ini,$sectionnumber,"Subnetmask",$SNmask) ;Write .ini Sub Bereich
IniWrite($ini,$sectionnumber,"Gateway",$gateway) ;Write .ini GW Bereich
IniWrite($ini,$sectionnumber,"DNS",$DNS) ;Write .ini DNS Bereich
IniWrite($ini,$sectionnumber,"DHCP",$DHCP) ;Write .ini DHCP Bereich
EndFunc

Func MainMenu() ;Create GUI Func

$IP = @IPAddress1 ;Variablendeklaration
Opt("GUIOnEventMode", 1)

#RequireAdmin ;User=Admin?

#region ### START Koda GUI section ### Form= ;Koda GUI section
$Form1 = GUICreate("IP Finder", 600, 450, 192, 124) ;Greate GUI [Form]

$Combo1 = GUICtrlCreateCombo("",450, 50, 130, 80, $CBS_DROPDOWNLIST + $WS_VSCROLL) ;Create GUI [Combo]

Local $var = IniReadSectionnames($ini) ;ReadSectionNames

For $i = 1 To $var[0]
$confname = IniRead($ini,"Section" & $i,"NAME","No Name entered") ;get Confname from .ini
$comboname = $comboname & $confname & "|" ;Confname to Combo
Next
$comboname = StringTrimRight($comboname,1) ;Truncate Confnames in Combo

$ComboConNames = GUICtrlCreateCombo("",450, 75, 130, 80, $CBS_DROPDOWNLIST + $WS_VSCROLL)




GUICtrlSetData($Combo1, $comboname, "")
GetConnectionname()

$ListView = GUICtrlCreateListView("Name | IP | Subnet | Gateway | DNS | DHCP", 0, 300, 600, 150) ;Create GUI[ListView]
_GUICtrlListView_SetColumnWidth($ListView,0,$LVSCW_AUTOSIZE_USEHEADER)
$LblName = GUICtrlCreateLabel("Name:", 56, 16, 35, 17) ;Create GUI[Lbl]
$LblIP = GUICtrlCreateLabel("IP Address:", 33, 48, 58, 17) ;Create GUI[Lbl]
$LblSNM = GUICtrlCreateLabel("Subnet Mask:", 22, 80, 70, 17) ;Create GUI[Lbl]
$LbldefaultGW = GUICtrlCreateLabel("Default GW:", 27, 112, 63, 17) ;Create GUI[Lbl]
$LblDNS = GUICtrlCreateLabel("DNS Server:", 27, 144, 64, 17) ;Create GUI[Lbl]
$txtName = GUICtrlCreateInput($configname, 112, 13, 181, 21) ;Create GUI[Input]
$txtIP = GUICtrlCreateInput($configIP, 112, 45, 181, 21) ;Create GUI[Input]
$txtSNM = GUICtrlCreateInput($configSNM, 112, 77, 181, 21) ;Create GUI[Input]
$txtdefaultGW = GUICtrlCreateInput($configGW, 112, 109, 181, 21) ;Create GUI[Input]
$txtDNS = GUICtrlCreateInput($configDNS, 112, 141, 181, 21) ;Create GUI[Input]
$btnConfSave = GUICtrlCreateButton("Save", 200, 192, 49, 25) ;Create GUI[Button]
$chboxDHCP = GUICtrlCreateCheckbox("DHCP", 112, 176, 97, 17) ;Create GUI[Checkbox]
$btnChange = GUICtrlCreateButton("Change", 250, 192, 49, 25) ;Create GUI[Button]
$btnSetIP = GUICtrlCreateButton ("Set IP", 400, 192, 49, 25) ;Create GUI[Button]
$btnUpdtAdapter = GUICtrlCreateButton ("Update Adapters", 450, 192,100, 25) ;Create GUI[Button]


#endregion ### END Koda GUI section ###
UpdateAdapters() ;Execute Func


GUICtrlSetOnEvent ($btnUpdtAdapter,"UpdateAdapters")
GUICtrlSetOnEvent ($btnSetIP,"SetIP")
GUICtrlSetOnEvent ($chboxDHCP, "chboxDHCP")
GUICtrlSetOnEvent ($btnConfSave, "ConfSave")
GUICtrlSetOnEvent ($combo1,"Getinfocombo")
GUICtrlSetOnEvent ($btnChange, "Changefunc")
GUICtrlSetOnEvent ($ComboConNames,"SetStates")
GUISetOnEvent ($GUI_EVENT_CLOSE, "ExitGui")


GUISetState(@SW_SHOW)



GUICtrlSetState( $txtName , $Gui_DISABLE)
GUICtrlSetState( $txtIP , $Gui_DISABLE)
GUICtrlSetState( $txtSNM , $Gui_DISABLE)
GUICtrlSetState( $txtdefaultGW , $Gui_DISABLE)
GUICtrlSetState( $txtDNS , $Gui_DISABLE)
GUICtrlSetState( $btnConfSave , $Gui_DISABLE)
GUICtrlSetState( $btnChange , $Gui_DISABLE)
GUICtrlSetState( $chboxDHCP , $Gui_DISABLE)
GUICtrlSetState( $btnSetIP , $Gui_DISABLE)

While 1
Sleep(10)
WEnd

EndFunc

func SetStates()
GUICtrlSetState( $txtName , $Gui_DISABLE)
GUICtrlSetState( $txtIP , $Gui_DISABLE)
GUICtrlSetState( $txtSNM , $Gui_DISABLE)
GUICtrlSetState( $txtdefaultGW , $Gui_DISABLE)
GUICtrlSetState( $txtDNS , $Gui_DISABLE)
GUICtrlSetState( $btnConfSave , $Gui_DISABLE)
GUICtrlSetState( $btnChange , $Gui_DISABLE)
GUICtrlSetState( $chboxDHCP , $Gui_DISABLE)
GUICtrlSetState($btnSetIP,$Gui_ENABLE)

EndFunc

Func UpdateAdapters() ;Execute Func


$currentDHCPStatus="" ;Variablendeklaration
_GUICtrlListView_DeleteAllItems($ListView) ;Clear ListView

$count = 0
$objWMI = ObjGet("winmgmts:\\.\root\cimv2") ;Get WMIobj
$collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") ;Query WMI

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$Output=""
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter where NetConnectionID != NULL", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colNIC = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapter WHERE Netconnectionstatus = 2")
Dim $pcinfo
For $object In $colNIC
$pcinfo = $pcinfo & $object.name & @CRLF
Next

For $obj In $collection
If $obj.DHCPEnabled = -1 Then
$currentDHCPStatus = "TRUE"
Else
$currentDHCPStatus = "FALSE"
EndIf
$currentIP = $obj.IPAddress
$currentSubnet = $obj.IPSubnet
$currentGateway = $obj.DefaultIPGateway
$currentDNS = $obj.DNSServerSearchOrder

If Not IsArray($currentGateway) Then
Dim $currentGateway[$count+1]
$currentGateway[0] = "not set"
EndIf
if Not IsArray($currentDNS) Then
Dim $currentDNS[$count+1]
$currentDNS[0] = "not set"
EndIf
$item2 = GUICtrlCreateListViewItem("Name | Subnet | Gateway | DNS | DHCP ", $ListView)
GUICtrlSetData($item2, $pcinfo & " | " & $currentIP[0] & " | " & $currentSubnet[0] & " | " & $currentGateway[0] & " | " & $currentDNS[0] & " | " & $currentDHCPStatus & " | " & "MammutHacken")

Next


EndFunc

Func Changefunc ()

GUICtrlSetState( $txtName , $Gui_ENABLE)
GUICtrlSetState( $txtIP , $Gui_ENABLE)
GUICtrlSetState( $txtSNM , $Gui_ENABLE)
GUICtrlSetState( $txtdefaultGW , $Gui_ENABLE)
GUICtrlSetState( $txtDNS , $Gui_ENABLE)
GUICtrlSetState( $btnConfSave , $Gui_ENABLE)
GUICtrlSetState( $chboxDHCP , $Gui_ENABLE)

If GUICtrlRead($chboxDHCP) = $GUI_CHECKED Then
GUICtrlSetState( $txtIP , $Gui_DISABLE)
GUICtrlSetState( $txtSNM , $Gui_DISABLE)
GUICtrlSetState( $txtdefaultGW , $Gui_DISABLE)
GUICtrlSetState( $txtDNS , $Gui_DISABLE)
EndIf

EndFunc


Func ExitGui()
Exit
EndFunc ;==>ExitGui


Func Getinfocombo()
GUICtrlSetState( $txtName , $Gui_DISABLE)
GUICtrlSetState( $txtIP , $Gui_DISABLE)
GUICtrlSetState( $txtSNM , $Gui_DISABLE)
GUICtrlSetState( $txtdefaultGW , $Gui_DISABLE)
GUICtrlSetState( $txtDNS , $Gui_DISABLE)
GUICtrlSetState( $btnConfSave , $Gui_DISABLE)
GUICtrlSetState( $btnChange , $Gui_DISABLE)
GUICtrlSetState( $chboxDHCP , $Gui_DISABLE)
GUICtrlSetState($btnSetIP,$Gui_ENABLE)

$index = _GUICtrlComboBox_GetCurSel($Combo1) + 1

$configname = IniRead($ini,"Section" & $index,"NAME","No Name entered")
$configIP = IniRead($ini,"Section" & $index,"IP","No IP entered")
$configSNM = IniRead($ini,"Section" & $index,"Subnetmask","No Subnetmask entered")
$configGW = IniRead($ini,"Section" & $index,"Gateway","No Gateway entered")
$configDNS = IniRead($ini,"Section" & $index,"DNS","No DNS entered")
$configDHCP = IniRead($ini,"Section" & $index,"DHCP","No DHCP entered")


GUICtrlSetData($txtName, $configname)
GUICtrlSetData($txtIP, $configIP)
GUICtrlSetData( $txtSNM ,$configSNM)
GUICtrlSetData( $txtdefaultGW ,$configGW)
GUICtrlSetData( $txtDNS ,$configDNS)

If $configDHCP = "True" Then

GUICtrlSetState($chboxDHCP, $GUI_CHECKED)
Else
GUICtrlSetState($chboxDHCP, $Gui_UNCHECKED)
EndIf

GUICtrlSetState( $btnChange , $Gui_ENABLE)


EndFunc

Func chboxDHCP()

If GUICtrlRead($chboxDHCP) = $GUI_CHECKED Then

GUICtrlSetState( $txtIP , $Gui_DISABLE)
GUICtrlSetState( $txtSNM , $Gui_DISABLE)
GUICtrlSetState( $txtdefaultGW , $Gui_DISABLE)
GUICtrlSetState( $txtDNS , $Gui_DISABLE)

Else
GUICtrlSetState( $txtIP , $Gui_ENABLE)
GUICtrlSetState( $txtSNM , $Gui_ENABLE)
GUICtrlSetState( $txtdefaultGW , $Gui_ENABLE)
GUICtrlSetState( $txtDNS , $Gui_ENABLE)
EndIf

EndFunc

Func ConNames ()
Dim $i, $Base, $key, $name1
$base = "HKLM\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}"

Do
$i = $i +1
$key = RegEnumKey($base, $i)
Global $name1 = RegRead($base & "\" & $key & "\Connection", "Name")
If StringLeft($key, 1) = "{" Then GUiCtrlSetData($connections, $name1 & "|")
Until $key = ""

EndFunc

Func ConfSave ()

$YorN = MsgBox(52,"Caution", "You are about to override the current settings for this configuration. Once saved the current settings can't be restored! Do you really want to save the changes?")

If $YorN= 6 Then

GUICtrlSetState( $txtName , $Gui_DISABLE)
GUICtrlSetState( $txtIP , $Gui_DISABLE)
GUICtrlSetState( $txtSNM , $Gui_DISABLE)
GUICtrlSetState( $txtdefaultGW , $Gui_DISABLE)
GUICtrlSetState( $txtDNS , $Gui_DISABLE)
GUICtrlSetState( $btnConfSave , $Gui_DISABLE)
GUICtrlSetState( $btnChange , $Gui_DISABLE)
GUICtrlSetState( $chboxDHCP , $Gui_DISABLE)

$configname = GUICtrlRead ( $txtName)
$configIP = GUICtrlRead ( $txtIP)
$configSNM = GUICtrlRead ( $txtSNM)
$configGW = GUICtrlRead ( $txtdefaultGW)
$configDNS = GUICtrlRead ( $txtDNS)

If GUICtrlRead($chboxDHCP) = $GUI_CHECKED Then
$configDHCP = "True"
Else
$configDHCP= "False"
EndIf


$sectionnumber="Section" & $index
iniWriteSection($ini,$sectionnumber,"")
IniWrite($ini,$sectionnumber,"NAME",$configname)
IniWrite($ini,$sectionnumber,"IP",$configIP)
IniWrite($ini,$sectionnumber,"Subnetmask",$configSNM)
IniWrite($ini,$sectionnumber,"Gateway",$configGW)
IniWrite($ini,$sectionnumber,"DNS",$configDNS)
IniWrite($ini,$sectionnumber,"DHCP",$configDHCP)

$comboname=""
Local $var = IniReadSectionnames($ini)

For $i = 1 To $var[0]
$confname = IniRead($ini,"Section" & $i,"NAME","No Name entered")
$comboname = $comboname & $confname & "|"
Next
$comboname = StringTrimRight($comboname,1)


GUICtrlSetData($Combo1, "", "")

GUICtrlSetData($Combo1,$comboname)

EndIf

EndFunc



Func GetConnectionname()

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$Output=""
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter where NetConnectionID != NULL", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
For $objItem In $colItems
$Output = $objItem.NetConnectionID
$comboNetConName = $comboNetConName & $Output & "|"
Next
Endif
GUICtrlSetData($ComboConNames, $comboNetConName, "")

EndFunc

Func SetIp()
$sText=""
$s=_GUICtrlComboBox_GetCurSel($ComboConNames)
_GUICtrlComboBox_GetLBText($ComboConNames,$s,$sText)
$adaptername = $sText

$sectionnumber="Section" & $index
$configname = IniRead($ini,"Section" & $index,"NAME","No Name entered")
$configIP = IniRead($ini,"Section" & $index,"IP","No IP entered")
$configSNM = IniRead($ini,"Section" & $index,"Subnetmask","No Subnetmask entered")
$configGW = IniRead($ini,"Section" & $index,"Gateway","No Gateway entered")
$configDNS = IniRead($ini,"Section" & $index,"DNS","No DNS entered")
$configDHCP = IniRead($ini,"Section" & $index,"DHCP","False")

MsgBox(64, "IP Change", " Attempting to Change IP")

GUICtrlSetState( $txtName , $Gui_DISABLE)
GUICtrlSetState( $txtIP , $Gui_DISABLE)
GUICtrlSetState( $txtSNM , $Gui_DISABLE)
GUICtrlSetState( $txtdefaultGW , $Gui_DISABLE)
GUICtrlSetState( $txtDNS , $Gui_DISABLE)
GUICtrlSetState( $btnConfSave , $Gui_DISABLE)
GUICtrlSetState( $btnChange , $Gui_DISABLE)
GUICtrlSetState( $chboxDHCP , $Gui_DISABLE)
GUICtrlSetState($btnSetIP,$Gui_DISABLE)
GUICtrlSetState($combo1,$Gui_DISABLE)


If $configDHCP ="False" then
$test = RunWait('netsh interface ip set address name=' & '"' & $adaptername & '" static ' & $configIP & ' '& $configSNM & ' ' & $configGW & ' 1',"",@SW_HIDE)
Else
$test = runwait ('netsh interface ip set address name=' & '"' & $adaptername & '" dhcp', "", @SW_HIDE)
EndIf


If $test = 0 Then
MsgBox(64, "Success", "The IP-Address was changed successfully")
Else
MsgBox(64,"Error"," Something went terribly wrong ")
EndIf

GUICtrlSetState($combo1,$Gui_ENABLE)
UpdateAdapters()
EndFunc
_iniwrite(3,"CONF3","126.0.0.10","255.0.0.0","0.0.0.0","0.0.0.0","False") ;Write CONF3conf
_iniwrite(1,"CONF1","10.0.0.10","255.255.255.0","0.0.0.0","0.0.0.0","False") ;Write CONF1 conf
_iniwrite(2,"CONF2","196.168.0.10","255.255.255.0","0.0.0.0","0.0.0.0","False") ;Write CONF2 conf
_iniwrite(5,"Empty","Empty","Empty","Empty","Empty","False") ;Write empty conf
_iniwrite(4,"DHCP","Empty","Empty","Empty","Empty","True") ;Write DHCPconf
_iniwrite(7,"Empty","Empty","Empty","Empty","Empty","False") ;Write empty conf
_iniwrite(6,"Empty","Empty","Empty","Empty","Empty","False") ;Write empty conf


MainMenu()
Link to comment
Share on other sites

  • 2 weeks later...

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...