我嘗試使用DirectoryEntry對象連接到遠程Windows 7機器。這裏是我的代碼System.IO.FileNotFoundException:未找到網絡路徑。在Windows 7上使用DirectoryEntry對象時出現異常
DirectoryEntry obDirEntry = new DirectoryEntry("WinNT://hostName", "hostName\\testUser", "password123", AuthenticationTypes.Secure);
try
{
if (obDirEntry.Properties.Count > 0)
{
//ok
}
}
catch (Exception excp)
{}
如果我能夠連接到遠程Windows Server 2003的計算機或本地Windows 7計算機,然後我沒有得到任何錯誤。但是,當我試圖連接到遠程Windows 7的機器,那麼我在行if (obDirEntry.Properties.Count > 0)
Exception :System.IO.FileNotFoundException: The network path was not found.
at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.GetInfo()
at System.DirectoryServices.DirectoryEntry.RefreshCache()
at System.DirectoryServices.DirectoryEntry.FillCache(String propertyName)
at System.DirectoryServices.PropertyCollection.get_Count()
得到例外我能ping遠程Windows 7的M/C。防火牆和UAC也關閉。問題是我在每臺遠程Windows 7機器上都遇到了這個問題。我試圖把IP地址,而不是主機名,但在這種情況下,即使在本地機器上我得到以上例外。 nslookup命令能夠解析遠程m/c hostName。 這可能是什麼原因?什麼可以解決這個問題? 在此先感謝!
Windows 7不是服務器操作系統,所以它實際上並不提供遠程服務。 – Petesh
這些計算機是域的一部分嗎? – cheesemacfly
您可以從命令行訪問遠程Windows 7計算機嗎?也就是說,你可以做'dir \\ hostname \ directory'嗎? –