错误:System.IO.IOException:找不到网络路径

Gom*_*iya 5 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 = 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);
}
}
}
Run Code Online (Sandbox Code Playgroud)

错误是,

  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
Run Code Online (Sandbox Code Playgroud)

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

Bru*_*Dev 16

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

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

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


小智 0

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

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