How are you calling / running your script?
Common enough things tend to include:
- Forgetting about 64-bit versus 32-bit mode (if calling from a batch file).
- Permissions. Run a REGMON or PROCMON trace to see what registry keys you're hitting up & if you're falling foul of some borked permissions (as we run as LOCAL SYSTEM by default, this SHOULDN'T be likely, but I've seen some pretty messed up rights in my time).