First, when you check the return value for WTSQuerySessionInformation, you're not doing anything when the return value is False. Call
GetLastError[
^] to find out what it's complaining about.
Second, don't rely on Enum to correctly assign type and values to its members. Specifically assign a type to the Enum and every value. This makes the code very explicit so no assumptions are made and also makes it easier to maintain the code.