Used some code from Microsoft for W8/10 compatibility.

Signed-off-by: Difegue <sugoi@cock.li>