I want to be able to display the currently active user on my web page.

Right now I have this code snippet in my CGI program:

char* UserName;
    DWORD Size;
    WTSQuerySessionInformation( WTS_CURRENT_SERVER_HANDLE,

    cout << "<tr bgcolor=\"#DBF7E2\"><td>";
    cout << "Currently active user:</td><td>"  << (GetLastError()==0?UserName:"&lt;error&gt;");
    cout << "</td></tr>";
But the query function fails with the error code 5 (ERROR_ACCESS_DENIED). Does anyone know how to determine which user is currently active?

Note: GetUserName() won't work, it'll return the name of the user the webserver is running as.