我打電話WNetAddConnection2很多次都沒有WNetCancelConnection2創造太多的插座,我只是檢查它的返回值。這在Windows Server 2003中工作,只創建一個連接,但在Windows Server 2008中,它創建了太多的連接。有什麼問題?WNetAddConnection2在Windows Server 2008 HPC版
編輯 - 代碼,根據註釋:
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創建,用戶名是一樣的。從日誌消息來看,它有時會起作用,它是否與登錄會話相關?
感謝
DMA
請顯示一些代碼 – Yahia
更多信息:我在不同的過程中調用此函數。會影響結果嗎?另一件奇怪的事情是:我在「計算機」中看不到驅動程序名稱。 –
重點在於:你稱之爲什麼參數?多久 ?你經常打電話的原因是什麼?例如在不同的會話/終端服務器連接中是否有進程?任何你不叫'WNetCancelConnection2'的原因? – Yahia