Hi, I have the script below as part of a login script. This script will switch the auto detect settings within IE on. The problem I have is that the login script has to be run twice for auto detect to be switched on, can anyone see why this is ?

$rc=setIEAutoDetect(1)
function SetIEAutoDetect($enable)
dim $subkey, $value, $byte, $rc
$subkey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
$value = readvalue($subkey, "DefaultConnectionSettings")
$rc = @error

If $rc = 0
$byte = val(substr($value, 18, 1))
If $enable
$byte = $byte | 8 ; set bit
Else
$byte = $byte & 7 ; clear bit
Endif

$byte = dectohex($byte)
$value = substr($value, 1, 17) + $byte + substr($value, 19, len($value) - 18)
$rc = writevalue($subkey, "DefaultConnectionSettings", $value, "REG_BINARY")

Endif
$SetIEAutoDetect = $rc
endfunction