The chances are that you need admin permission to change the SYSTEM area of the registry and your modification is being rejected as a result.
This is a good example of why swallowing exceptions is a bad idea: you have no idea there is a problem, or any details about it, just that the code doesn't work.
Change your catch:
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
And it will tell you what the problem is.
Almost certainly, it's an authorization problem. This may be a better way to do it:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/386e0268-8986-4e49-8023-f9ae2e2689ab/disabling-hibernation?forum=csharpgeneral[
^]