这是代码。
DirectoryEntry Discover = new DirectoryEntry("WinNT://Workgroup");
foreach (DirectoryEntry Node in Discover.Children)
{
try {
if (Node.Properties.Count > 0)
{
//you have access to the computer so yeah
}
}
catch(System.IO.FileNotFoundException err) {
var ErrorMesage = err.Message;
//Yeah you dont have access to this computer, lets write a subroutine to allow the user to put in a username and password to access it
}
所以,当我运行这个时,我会得到一个史诗般的盒子弹出窗口,并说出像
这样的愚蠢行为{“找不到网络路径。\ r \ n”:null}
答案 0 :(得分:1)
现在,您只是尝试检查Node.Properties.Count
访问错误,仅此而已。代码范围DirectoryEntry Discover = new DirectoryEntry("WinNT://Workgroup");
也必须放在try
部分。
答案 1 :(得分:1)
试试这个
try {
DirectoryEntry Discover = new DirectoryEntry("WinNT://Workgroup"); **//Error occured here**
foreach (DirectoryEntry Node in Discover.Children)
{
if (Node.Properties.Count > 0)
{
//you have access to the computer so yeah
}
}
}
catch(System.IO.FileNotFoundException err)
{
var ErrorMesage = err.Message;
//Yeah you dont have access to this computer, lets write a subroutine to allow the user to put in a username and password to access it
}