gpt4 book ai didi

c - WTSEnumerateServers ERROR_INVALID_DOMAINNAME

转载 作者:行者123 更新时间:2023-11-30 15:31:53 32 4
gpt4 key购买 nike

我正在尝试枚举本地域中的终端服务器,但 WTSEnumerateServers() 失败,错误代码为 1212(指定域名的格式无效。)。我尝试使用子域名“sub”、完整域名“sub.company.local”以及 NULL(计算机域的同义词)。始终如一。

MSDN Article说明:如果禁用 NetBT,则此功能将不起作用。
NetBT 是基于 TCP/IP 的 NetBIOS。我查了一下,默认情况下是打开的。我使用的是 Windows 8.1

有谁知道为什么 WTSEnumerateServers() 失败?

#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);
}

最佳答案

我搜索了一下,发现了以下here :

/****************************************************************
* PLEASE NOTE:
* The WTSEnumerateServers function was no longer working in Windows 2008.
* The WTSEnumerateServers function relies on NETBIOS to be functional in
* the domain. Windows 2008 server disables the computer browser service on
* the DC by default now, so Netbios is rendered useless. Enabling the computer
* browser service on the DC only will return full functionality of the WTSAPI
* functions. This is a great fix, but as Microsoft have said that they will
* no longer support Netbios in the future, I’m sure we’ll have to revise our
* development strategy in TS environment. For the record as well, those that
* use the NETSERVEREnum function to do the same as WTSEnumerateServers, this
* also requires the Computer Browser Service to be enabled on a Windows 2008 DC.
* This is also the case for the Citrix WFAPI SDK - WFEnumerateServers *
* The best replacement for this I have found is WNetOpenEnum().
*
***************************************************************/

也许WNetOpenEnum 也会对你有帮助。

关于c - WTSEnumerateServers ERROR_INVALID_DOMAINNAME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24506772/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com