I'm trying to enumerate Terminal servers in our local domain, but WTSEnumerateServers() fails with ErrorCode 1212 ( The format of the specified domain name is invalid. ). I tried it with the subdomain name "sub", with the full domain name "sub.company.local" and with NULL which is a synonym for the computer's domain. Always the same.
The MSDN Article states: This function will not work if NetBT is disabled.
NetBT is NetBIOS over TCP/IP. Which, I checked, is on by default. I'm using Windows 8.1
Does anyone know why WTSEnumerateServers() is failing?
#include <stdio.h>
#include <Wtsapi32.h>
#include <Windows.h>
#pragma comment(lib, "Wtsapi32.lib")
void LastErrorMsgBox(int err);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
PWTS_SERVER_INFO DiscoveredServers = NULL;
DWORD count = 0;
if(WTSEnumerateServers(NULL, 0, 1, &DiscoveredServers, &count) == 0)
{
LastErrorMsgBox(GetLastError());
return 1;
}
WTSFreeMemory(DiscoveredServers);
return 0;
}
void LastErrorMsgBox(int err)
{
TCHAR dbg[1024];
LPTSTR sys = NULL;
_stprintf(dbg, TEXT("Errorcode: %d\n"), err);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&sys, 0, NULL);
_tcsncat(dbg, sys, 1024);
if(sys != NULL)
LocalFree(sys);
MessageBox(0, dbg, TEXT("Error"), MB_ICONERROR);
}