The boot.ini file has a /safeboot switch which might be helpful writing a script. I guess you would need another "safe mode" script to reset the boot.ini to boot normally.
Without an OS actually running when you make the determination to safe or normal boot, your options are somewhat limited.
8-)