As I see this HKLM, does the user have the proper permissions to write here?

also you can put @serror on the next line after the writevalue to get more info as to what is going on.