简体   繁体   English

EvtExportLog API 将远程机器的事件日志保存在远程 PC 本身中。 如何将其保存到主机 PC?

[英]EvtExportLog API is saving eventlog of remote machine in remote PC itself. How can I save it to host PC?

I have used EvtOpenSession API to create a session to a remote machine's eventlog, then used the session handle to call EvtExportLog API.我使用EvtOpenSession API 创建到远程机器EvtExportLog的会话,然后使用会话句柄调用EvtExportLog API。 I need the eventlog file in the host PC(where I am running this application), but this API is dumping the evenlog into the remote machine itself.我需要主机 PC 中的事件日志文件(我在其中运行此应用程序),但此 API 正在将事件日志转储到远程机器本身。 What should I do to get the eventlog in host PC?我应该怎么做才能在主机 PC 中获取事件日志?

I have tried with a shared path in host PC as well(instead of _T("C:\\Test\\EventLogApplication.evt") I used _T("\\\\ComputerName\\Events\\EventLogApplication.evt"). In this case I am getting an access violation error.我也尝试过在主机 PC 中使用共享路径(而不是 _T("C:\\Test\\EventLogApplication.evt") 我使用了 _T("\\\\ComputerName\\Events\\EventLogApplication.evt")。在这种情况下,我是收到访问冲突错误。

here is the code snippet i used这是我使用的代码片段

......

hRemote = EvtOpenSession(EvtRpcLogin, &Credentials, 0, 0);

if (hRemote)    
{

   if (!EvtExportLog(hRemote, _T("Application"), NULL,_T("C:\\Test\\EventLogApplication.evt"), EvtExportLogChannelPath))    
   {
       std::cout << "Error-Code : " << GetLastError() << std::endl;
   }

}

......

As far as I know, EvtExportLog cannot be used to save eventlog of remote machine to host PC.据我所知, EvtExportLog不能用于将远程机器的EvtExportLog保存到主机 PC。 But for the issue, you can use the workaround.但是对于这个问题,您可以使用解决方法。

Beacuse this behavior is by designed since all the operation is based on the RPC server.因为此行为是设计的,因为所有操作都基于 RPC 服务器。 To save the event logs on local PC, we can create a shared folder on remote PC which save the remote event logs.要将事件日志保存在本地 PC 上,我们可以在远程 PC 上创建一个共享文件夹,用于保存远程事件日志。

Refer: How do you create a file share on a remote system?参考: 如何在远程系统上创建文件共享?

After the logs save on remote PC, we can use CopyFile to copy the logs to local PC from the shared folder on the remote PC.日志保存在远程PC上后,我们可以使用CopyFile将日志从远程PC上的共享文件夹复制到本地PC。

Note: Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: Security resource properties for the existing file are not copied to the new file until Windows 8 and Windows Server 2012.注意:Windows 7、Windows Server 2008 R2、Windows Server 2008、Windows Vista、Windows Server 2003 和 Windows XP:在 Windows 8 和 Windows Server 2012 之前,不会将现有文件的安全资源属性复制到新文件中。

File attributes for the existing file are copied to the new file.现有文件的文件属性被复制到新文件中。 For example, if an existing file has the FILE_ATTRIBUTE_READONLY file attribute, a copy created through a call to CopyFile will also have the FILE_ATTRIBUTE_READONLY file attribute.例如,如果现有文件具有 FILE_ATTRIBUTE_READONLY 文件属性,则通过调用 CopyFile 创建的副本也将具有 FILE_ATTRIBUTE_READONLY 文件属性。 For more information, see Retrieving and Changing File Attributes.有关更多信息,请参阅检索和更改文件属性。

This function fails with ERROR_ACCESS_DENIED if the destination file already exists and has the FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_READONLY attribute set.如果目标文件已经存在并且设置了 FILE_ATTRIBUTE_HIDDEN 或 FILE_ATTRIBUTE_READONLY 属性,则此函数将失败并显示 ERROR_ACCESS_DENIED。

When CopyFile is used to copy an encrypted file, it attempts to encrypt the destination file with the keys used in the encryption of the source file.当 CopyFile 用于复制加密文件时,它会尝试使用加密源文件时使用的密钥来加密目标文件。 If this cannot be done, this function attempts to encrypt the destination file with default keys.如果无法做到这一点,该函数将尝试使用默认密钥加密目标文件。 If neither of these methods can be done, CopyFile fails with an ERROR_ENCRYPTION_FAILED error code.如果这两种方法都无法完成,则 CopyFile 将失败并显示 ERROR_ENCRYPTION_FAILED 错误代码。

Refer: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-copyfile#remarks参考: https : //docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-copyfile#remarks

Hope to help you.希望能帮到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM