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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14772386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 12:57:07  来源:igfitidea点击:

Error : System.IO.IOException: the network path was not found

c#wmiremote-accessregistrykey

提问by Gomathipriya

when i am executing following code it results an error please help me to resolve this.

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

 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);
}
}
}

Error is ,

错误是,

  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
  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

please help me to resolve this, in a machine name field how to enter the remote machine, when it have v.i.com , but that system name is v only.

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

回答by Gomathipriya

What account is that code running with? It may not have permission to access the network. That will depend on the web service configuration.

该代码使用哪个帐户运行?它可能没有访问网络的权限。这将取决于 Web 服务配置。

Something else is that recent OS versions do not allow strictly local accounts to access administrative shares on other systems, and that will be the account again.

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

回答by RainbowFish

I'd assume the machineName "Venus.InsTIL.com" which you've specified is not contactable via this path. What's the UNC path to the machine? Have you verified the machine is otherwise contactable (ping, UNC file browse etc)?

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

回答by BrutalDev

If you look at your stack trace you can see the failure happens trying to open the remote registry key.

如果您查看堆栈跟踪,您可以看到尝试打开远程注册表项时失败。

This means that the Remote Registryservice is not running on the target machine. On v.i.com, open the services control panel (services.msc) and start the service called Remote Registry.

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

This service is normally set to have the startup type of Manual so is not started automatically. If you need to configure or access the event log remotely often, set this to start Automatic so that it's always available.

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

回答by Patrick O'Hara

It is likely that you did connect to the other machine. I would expect that the error would be more like connection refused or invalid credentials if the connection failed. The fact that this exception is happening on a move next operation (see stack trace) implies that the code was reading through the list when it attempted to read an entry that was not there. My guess is that the entry had been there when the foreachcommand created its list, but not there when iterating through the list. I suspect the issue is that something is changing the data on you.

您可能确实连接到另一台机器。如果连接失败,我希望错误更像是连接被拒绝或凭据无效。此异常发生在下一个移动操作(请参阅堆栈跟踪)时这一事实意味着代码在尝试读取不存在的条目时正在读取列表。我的猜测是该条目在foreach命令创建其列表时已经存在,但在遍历列表时不存在。我怀疑问题是有什么东西正在改变你的数据。