Wena Posted April 14, 2009 Posted April 14, 2009 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. ThanksPOS_SETUP.txt
Tec Posted April 14, 2009 Posted April 14, 2009 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
Wena Posted April 15, 2009 Author Posted April 15, 2009 (edited) Thanks TEC It's a bit over my head but I will work it out. Thanks Alistair Edited April 15, 2009 by Wena
Wena Posted April 15, 2009 Author Posted April 15, 2009 Hi Not to sure how to mark this as resolved. Please assist Thanks Alistair
Tec Posted April 15, 2009 Posted April 15, 2009 Test this and play with it expandcollapse popup#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
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