The UDF will look something like this:
Code:
Function ConfigureIP($sPC,$sEthID,$sNewIp,$sNewGW)
Dim $sRegKey,$iDiscard

$ConfigureIP=0

$sRegKey="\\"+$sPC+"\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"+$sEthID+"\Parameters\Tcpip"
$ConfigureIP = $ConfigureIP + (WriteValue($sRegKey, "IPAddress", $sNewIP, "REG_MULTI_SZ")<>0)
$ConfigureIP = $ConfigureIP + (WriteValue($sRegKey, "DefaultGateway", $sNewGW, "REG_MULTI_SZ")<>0)
$iDiscard = WriteLine(1, " neue IP-Adresse:..."+$sNewIP+@CRLF+@CRLF)
$iDiscard = WriteLine(1, " neuer Gateway:..."+$sNewGW+@CRLF+@CRLF)

$sRegKey="\\"+$sPC+"\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"+$sEthID
$ConfigureIP = $ConfigureIP + (WriteValue($sRegKey, "IPAddress", $sNewIP, "REG_MULTI_SZ")<>0)
$ConfigureIP = $ConfigureIP + (WriteValue($sRegKey, "DefaultGateway", $sNewGW, "REG_MULTI_SZ")<>0)
$iDiscard = WriteLine (1, " IP-Change von "+$sPC+" abgeschlossen"+@CRLF)

Exit $ConfigureIP
Return



Now, instead of the gosub, call it like this:
Code:
$regerr=ConfigureIP($ps,$EthID,$newIP,$newGW)