WNetAddConnection2在Windows Server 2008 HPC Edition中创build了太多的套接字

我多次调用WNetAddConnection2没有WNetCancelConnection2,我只是检查它的返回值。 这在Windows Server 2003中工作,只创build一个连接,但在Windows Server 2008中,它创build了太多的连接。 有什么问题?

编辑 – 按照评论代码:

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创build的,用户名是一样的。 从日志消息,它有时工作,是否login会话相关?

谢谢

DMA

错误消息不是与会话相关的…它表示ERROR_ALREADY_ASSIGNED (请参阅http://msdn.microsoft.com/en-us/library/ms681382%28v=vs.85%29.aspx )。

这意味着您用于装入的方法在该会话中被多次调用(应用程序的不同部分,同一会话中的应用程序的多个实例,在同一会话中重新启动的应用程序…)。

你这样做的方法是有缺陷的 – 你需要:

还有其他一些要点,以确保…但他们取决于以下问题的答案:

  • 应用程序是否在同一个会话中多次运行?
  • 应用程序是否在应用程序的不同部分尝试安装?
  • 这是一个Terminalserver环境吗?