2011-08-15 55 views
1

我打電話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

+0

請顯示一些代碼 – Yahia

+0

更多信息:我在不同的過程中調用此函數。會影響結果嗎?另一件奇怪的事情是:我在「計算機」中看不到驅動程序名稱。 –

+0

重點在於:你稱之爲什麼參數?多久 ?你經常打電話的原因是什麼?例如在不同的會話/終端服務器連接中是否有進程?任何你不叫'WNetCancelConnection2'的原因? – Yahia

回答

1

錯誤消息是不是會話相關的...它說ERROR_ALREADY_ASSIGNED(見http://msdn.microsoft.com/en-us/library/ms681382%28v=vs.85%29.aspx)。

這意味着你用它來安裝方法被調用該會話中超過一次(你的應用程序的不同部分,在同一會話的應用程序的多個實例,在重新啓動同一個會話的應用程序...)。

你的方法,這樣做是有缺陷的 - 你需要:

還有其他的點,以確保...但它們所依賴的回答以下問題:

  • 是否在同一個會話中多次內的應用程序運行?
  • 申請是否嘗試安裝在應用程序的不同部分?
  • 這是一個的TerminalServer環境?