gpt4 book ai didi

c - WNetAddConnection2 在 windows server 2008 HPC 版中创建了太多套接字

转载 作者:太空宇宙 更新时间:2023-11-04 04:05:06 25 4
gpt4 key购买 nike

我在没有 WNetCancelConnection2 的情况下多次调用 WNetAddConnection2,我只是检查它的返回值。这在 windows server 2003 中有效,只创建一个连接,但在 windows server 2008 中,它创建了太多连接。有什么问题?

编辑 - 根据评论编写代码:

TCHAR szLocalName[32] = _T("t:"), szRemoteName[MAX_PATH] = _T("\\\\ws2008_1\\sample_share");

// Assign our values to the NETRESOURCE structure.
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = szLocalName;
nr.lpRemoteName = szRemoteName;
nr.lpProvider = NULL;

// Call the WNetAddConnection2 function to assign
// a drive letter to the share.
dwRetVal = WNetAddConnection2(&nr, 0, 0, FALSE);

输出是:

mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:8956
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:7284
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:8592
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:4196
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:7708
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:7028
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:3988
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:3680
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:6364
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:7764
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:8764
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:4692
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:4996
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:5300
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:6028

注意:进程是CreateProcessAsUser创建的,用户名相同。从日志消息来看,它有时会起作用,是否与登录 session 相关?

谢谢

妈妈

最佳答案

错误消息与 session 无关...它说 ERROR_ALREADY_ASSIGNED(参见 http://msdn.microsoft.com/en-us/library/ms681382%28v=vs.85%29.aspx)。

这意味着您用于挂载的方法在该 session 中被调用了不止一次(应用程序的不同部分、同一 session 中应用程序的多个实例、同一 session 中重新启动的应用程序...)。

您这样做的方法有缺陷 - 您需要:

还有其他要点需要确定...但它们取决于以下问题的答案:

  • 应用程序是否在同一 session 中多次运行?
  • 应用程序是否尝试在应用程序的不同部分进行挂载?
  • 这是 TerminalServer 环境吗?

关于c - WNetAddConnection2 在 windows server 2008 HPC 版中创建了太多套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7061853/

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