Sign in to follow this  
Followers 0
Wena

IP Write

5 posts in this topic

Hi

Attached is a simple script which I will use to write the Computer name and IP address to the respective places.

I have worked out how to regwrite the computer name but I cannot work out how to write the IP to the network card.

Thanks

POS_SETUP.txt

Share this post


Link to post
Share on other sites



Try this. Not tested

$IP[0] = "192.168.0.100"
$Subnet[0] = "255.255.255.0"
$Gateway[0] = "192.168.0.1"
$DNS[0] = "192.168.0.1"

$objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2")
If Not IsObj($objWMIService) Then Exit 
$colAdapters = $objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For $objAdapter in $colAdapters
    $err = $objAdapter.EnableStatic($IP,$Subnet)
    $err2 = $objAdapter.SetGateways($Gateway)
    $err3 = $objAdapter.SetDNSServerSearchOrder($DNS)
    If $err = 1 Then
        MsgBox(1,"","Unable to set static IP until reboot")
    ElseIf $err > 1 Then
        MsgBox(1,"","Unable to set IP")
    EndIf
Next

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks TEC

It's a bit over my head but I will work it out.

Thanks

Alistair

Edited by Wena

Share this post


Link to post
Share on other sites

Hi

Not to sure how to mark this as resolved.

Please assist

Thanks

Alistair

Share this post


Link to post
Share on other sites

Test this and play with it

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiIPAddress.au3>

Example()
Func Example()

    GUICreate("Till Setup", 400, 300)
    GUICtrlCreateLabel("Please note IP = Till number + 10", 100, 50)
    $Till = GUICtrlCreateInput("", 200, 100, 100)
    GUICtrlCreateLabel("Enter Till Number", 100, 102)
    $IP = GUICtrlCreateInput("", 200, 154, 100)
    GUICtrlCreateLabel("Enter IP Address", 100, 156)
    $Subnet = GUICtrlCreateInput("255.255.255.0", 200, 194, 100)
    GUICtrlCreateLabel("Enter Subnet", 100, 196)
    $Gateway = GUICtrlCreateInput("192.168.0.1", 200, 224, 100)
    GUICtrlCreateLabel("Enter Gateway", 100, 226)
    $Button = GUICtrlCreateButton("OK", 200, 250, 100)

    GUISetState()
    $POS = "POS"

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop

                GUIDelete()

            Case $msg = $Button
                $Till1 = $POS & GUICtrlRead($Till)
                $IP1 = GUICtrlRead($IP)
                $Subnet1 = GUICtrlRead($Subnet)
                $Gateway1 = GUICtrlRead($Gateway)
                RegWrite("hkey_local_machine\system\Controlset001\control\computername\computername", "computername", "REG_SZ", $Till1)
                RegWrite("hkey_local_machine\system\Controlset001\Services\tcpip\parameters", "NV Hostname", "REG_SZ", $Till1)
                RegWrite("hkey_local_machine\system\CurrentControlset\control\computername\Computername", "computername", "REG_SZ", $Till1)
                RegWrite("hkey_local_machine\system\Controlset001\Services\tcpip\parameters", "nv hostname", "REG_SZ", $Till1)
                RegWrite("hkey_local_machine\system\Controlset001\Services\lanmanserver\parameters", "srvcomment", "REG_SZ", $Till1)
                RegWrite("hkey_local_machine\system\Controlset\Services\lanmanserver\parameters", "srvcomment ", "REG_SZ", $Till1)

                $IP[0] = $IP1
                $Subnet[0] = $Subnet1
                $Gateway[0] = $Gateway1
                ;$DNS[0] = "192.168.0.1"

                $objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2")
                If Not IsObj($objWMIService) Then Exit
                $colAdapters = $objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

                For $objAdapter in $colAdapters
                    $err = $objAdapter.EnableStatic($IP,$Subnet)
                    $err2 = $objAdapter.SetGateways($Gateway)
                    ;$err3 = $objAdapter.SetDNSServerSearchOrder($DNS)
                    If $err = 1 Then
                        MsgBox(1,"","Unable to set static IP until reboot")
                    ElseIf $err > 1 Then
                        MsgBox(1,"","Unable to set IP")
                    EndIf
                Next                
                
                GUIDelete()
        EndSelect
    WEnd
EndFunc   ;==>Example

Share this post


Link to post
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
Sign in to follow this  
Followers 0