Why does the computer log a user log off immediately after logging in?

On XP / Vista, this is likely an issue with the winlogon key in the registry being either missing or corrupt.

This is the result of a virus, or more commonly, virus software automatically removing a virus.

If you can boot to a recovery console or off your original install disk, edit the registry to add/repair these keys:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"Shell"="Explorer.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"Userinit"="C:\\Windows\\system32\\userinit.exe,"

This will solve your immediate issue and allow you to log on, but you still want to do a full virus scan.