Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Monday, 7 May 2007

Timezone Information on Windows

I was trying to find out how to grab the current timezone settings from the Windows registry, so I searched on the Internet, and eventually found where it was stored

(HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation)

, but most sites that showed the data structure were wrong. Only with one thing, that was which 16 bit integer represented the day of the week. Most sites said it was the 3rd Integer, but actually, it is the 8th (or last) Integer in the keys "StandardStart" and "DaylightStart". Eventually I found a site that said the right thing, so I'm going to list it here anyway.

 

Path: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation
Keys: StandardStart and DaylightStart
All integers are two byte big endian
Integer IndexRepresents
0Year: 0 = 1900
1Month: 1 = January ... 12 = December
2Week: 1 = First week ... 5 = Last Week
3Hour: 0 = Midnight, 23 = 11pm
4Minute: 0 - 59
5Second: 0 - 59
6Millisecond: 0 - 999
7Day of week: 0 = Sunday ... 6 = Saturday

 

So, there you have it.

Tuesday, 20 September 2005

Batch File to Fix my Internet

The setup of the computers at my flat to access the Internet is like this:

Internet--USB ADSL Modem--Server--Fast Switch--Access Point--Computers
                                             |
                                             |-Computers
Some computers are connected to the server via the router, others by the wireless router. Everything is happy in the networking world, except for one problem.

Sometimes the modem on the server drops the Internet connection, and cannot reconnect. The only way that I could find to fix the problem was to logon to the Server with VNC and restart the computer. Eventually I got sick of doing this (after the second time) and decided to write a batch file to do the job for me (after the millionth time).

The batch file checks every 15s to see if the Internet is still working by pinging Google.com. I did start with Microsoft.com, but they must have some automatic protection, because after about 10min of pinging, all further requests were bounced. If the ping fails consistently after three attempts at the ping command, the computer reboots.

The batch file on the server is like so:

@echo off
set timeouts=
:start
echo Testing Internet Connection...
set timeout=
for /f "tokens=1*" %%r in ( 'ping -n 1 google.com' ) do (
  if "%%r"=="Unknown" (
    set timeout=o
  )
  if "%%r"=="Request" (
    set timeout=o
  )
)

if "!timeout!"=="o" (
  echo Failure
  set timeouts=!timeouts!c
) else (
  echo Success
  set timeouts=
)

if "!timeouts!"=="ccc" (
  echo About to restart computer
  net send vincentp4 The Internet computer is about to restart in 20+10s.
)

choice /Ty,20 Continue? 

if errorlevel 2 goto end

if "!timeouts!"=="ccc" (
  net send vincentp4 The Internet computer is going down now!
  shutdown /r /t:10 "Shutting down to fix Internet!" /c
  echo Command issued
  goto end
)

goto start
:end
This file is stored at "c:\bat\test.bat" the machine has Windows 2000 installed. The bat directory also includes choice.com and shutdown.exe. In my start menu startup folder I have the following batch file:
net send vincentp4 This computer has restarted and the Internet needs to be reconnected.
"C:\Program Files\Alcatel\SpeedTouch USB\STDialUp.exe" /WindowsDial /Entry "Alcatel Speedtouch Connection"
net send vincentp4 The Internet is now connected.
cd c:\battest
Which sends me a message before it dials, and after it dials, then starts test.bat.

If you need any explanation, just leave me a comment and I will elaborate.