C# 错误:System.IO.IOException:未找到网络路径

C# 错误:System.IO.IOException:未找到网络路径,c#,wmi,remote-access,registrykey,C#,Wmi,Remote Access,Registrykey,当我执行以下代码时,它会导致一个错误,请帮助我解决这个问题 class MySample { public static void Main() { string eventLogName = "Security"; string sourceName = "BTHUSB"; string machineName = "v.i.com"; EventLog eventLog; eventLog = new EventLog(); eventLog.Log = e

当我执行以下代码时,它会导致一个错误,请帮助我解决这个问题

 class MySample
{

    public static void Main()
    {


string eventLogName = "Security";

string sourceName = "BTHUSB";

string machineName = "v.i.com";

EventLog eventLog;

eventLog = new EventLog();

eventLog.Log = eventLogName;

eventLog.Source = sourceName;

eventLog.MachineName = machineName;
foreach (EventLogEntry log in eventLog.Entries.Cast<EventLogEntry>().Reverse())// Entries.Cast<EventLogEntry>().Reverse
{
 Console.WriteLine(") Entry type: {0} , Category: {1},  Data: {2}, ID: {3}, Source: {4} \n", log.EntryType, log.TimeWritten, log.EventID, log.InstanceId, log.Source);
}
}
}
类MySample
{
公共静态void Main()
{
字符串eventLogName=“安全”;
字符串sourceName=“BTHUSB”;
字符串machineName=“v.i.com”;
事件日志事件日志;
eventLog=新的eventLog();
eventLog.Log=eventLogName;
eventLog.Source=sourceName;
eventLog.MachineName=MachineName;
foreach(eventLog.Entries.Cast().Reverse()中的EventLogEntry日志)//Entries.Cast().Reverse
{
Console.WriteLine(“)条目类型:{0},类别:{1},数据:{2},ID:{3},源:{4}\n”,log.EntryType,log.timewrited,log.EventID,log.InstanceId,log.Source);
}
}
}
错误是

未处理的异常:System.IO.IOException:未找到网络路径。
位于Microsoft.Win32.RegistryKey.Win32 ErrorStatic(Int32 errorCode,字符串str)
位于Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive hKey,字符串名称)
位于System.Diagnostics.EventLog.GetEventLogRegKey(字符串机器,布尔可写)
位于System.Diagnostics.EventLog.Exists(字符串logName,字符串machineName)
位于System.Diagnostics.EventLog.OpenForRead(字符串currentMachineName)
位于System.Diagnostics.EventLog.GetEntryAtNoThrow(Int32索引)
在System.Diagnostics.EventLogEntryCollection.EntriesEnumerator.MoveNext()中
在System.Linq.Enumerable.d_uaa`1.MoveNext()中
在System.Linq.Enumerable.d_u99`1.MoveNext()处的System.Linq.Buffer`1..ctor(IEnumerable`1 source)处
在E:\.net prep\.net examples\event\event\Program.cs中的event.MySample.Main()处:第42行

请帮助我解决这个问题,在机器名字段中,当远程机器有v.i.com,但该系统名仅为v时,如何输入远程机器。

该代码运行的帐户是什么?它可能没有访问网络的权限。这将取决于web服务配置


另外,最近的操作系统版本不允许严格的本地帐户访问其他系统上的管理共享,这将再次成为该帐户。

我假设您指定的machineName“Venus.instal.com”无法通过此路径联系。到机器的UNC路径是什么?您是否已验证机器是否可通过其他方式联系(ping、UNC文件浏览等)?

如果查看堆栈跟踪,您可以看到尝试打开远程注册表项时发生的故障

这意味着远程注册表服务未在目标计算机上运行。在v.i.com上,打开服务控制面板(services.msc)并启动名为远程注册表的服务


此服务通常设置为手动启动类型,因此不会自动启动。如果您需要经常远程配置或访问事件日志,请将其设置为“自动启动”,使其始终可用。

很可能您确实连接到了其他计算机。我认为错误更像是连接被拒绝或连接失败时凭据无效。此异常发生在move next操作上(请参阅堆栈跟踪),这意味着代码在试图读取不存在的条目时正在读取列表。我的猜测是,当
foreach
命令创建其列表时,条目就在那里,但在遍历列表时就不在那里了。我怀疑问题在于有什么东西正在改变您的数据。

您是否尝试过使用类似于
\\MachineName\$E`的方法来进行此操作?该计算机上的文件夹名称是否真的是
.net示例`您可以通过
\\MachineName\$Drive
路径从您的计算机访问该计算机吗?远程主机已连接,如何使用c#Code检查服务器,转到上载文件夹。分享吧。为您的应用程序授予该文件夹的权限(如果是网站,请使用应用程序池标识。如果共享位于与需要访问共享的进程不同的计算机上,则您可能希望使用应用程序池的域帐户)。我得到了相同的错误跟踪,但此修复程序对我无效。
  Unhandled Exception: System.IO.IOException: The network path was not found.

  at Microsoft.Win32.RegistryKey.Win32ErrorStatic(Int32 errorCode, String str)
  at Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive hKey, String ma chineName)
  at System.Diagnostics.EventLog.GetEventLogRegKey(String machine, Boolean writ able)
  at System.Diagnostics.EventLog.Exists(String logName, String machineName)
 at System.Diagnostics.EventLog.OpenForRead(String currentMachineName)
  at System.Diagnostics.EventLog.GetEntryAtNoThrow(Int32 index)
  at System.Diagnostics.EventLogEntryCollection.EntriesEnumerator.MoveNext()
  at System.Linq.Enumerable.<CastIterator>d__aa`1.MoveNext()
    at System.Linq.Buffer`1..ctor(IEnumerable`1 source)    at System.Linq.Enumerable.<ReverseIterator>d__99`1.MoveNext()
 at event.MySample.Main() in E:\.net prep\.net examples\event\event\Program.cs :line 42