The 6th parameter of RegCreateKeyEx is the desired access mode. You are passing 0. Try using KEY_SET_VALUE.