This could be either software or malware/virus problem.
The first thing you should try is to turn off the autorestart option (Windows XP)
Right click the MyComputer icon, select Properties, open the Advcanced tab, clcik the Startup and Recovery Settings button
Un-check Automatically restart

See if you can log on to Windows now and do a complete virus and malware scan or see what software causes the problem.
If that doesn't work try
rebooting in safe mode and run a complete virus and malware scan.