在自动文件历史记录设置中排除特定文件夹

在自动文件历史记录设置中排除特定文件夹

我正在尝试在我的组织中启用文件历史记录功能。我使用了 Ben N 编写的应用程序,他的剧本。但是,我想在其中添加特定文件夹的排除项。此应用程序有选项可以做到这一点吗?

答案1

添加排除项需要调用IFhConfigMgr::AddRemoveExcludeRule函数。要排除特定文件夹,请在脚本中提及的段落后添加此代码ProvisionAndSetNewTarget

newslot native addRemoveExcludeRule
copyslot addRemoveExcludeRule = vtbl field 6

// fh->AddRemoveExcludeRule(TRUE, FH_FOLDER, "C:\Users\User\Documents\Excluded")
call funcat addRemoveExcludeRule /return uint (slotdata fhPtr, int 1, int 0, bstr "C:\\Users\\User\\Documents\\Excluded")

将最后一行中的路径(不只是那一//行,它只是一个解释性注释)更改为要排除的路径。由于转义,反斜杠必须加倍。要排除多个文件夹,请添加call funcat addRemoveExcludeRule具有不同路径的其他语句。不要重复newslotcopyslot语句。

要排除标准文件夹/库而不是指定特定的用户配置文件路径,代码会有所不同。您需要标准文件夹的 GUID,您可以从这一页。将其(不带花括号)放在星号后的引号内。例如,这将排除下载文件夹:

// fh->AddRemoveExcludeRule(TRUE, FH_LIBRARY, "*374DE290-123F-4565-9164-39C4925E467B")
call funcat addRemoveExcludeRule /return uint (slotdata fhPtr, int 1, int 1, bstr "*374DE290-123F-4565-9164-39C4925E467B")

要排除非标准文件夹或库的用户特定路径,请使用环境变量扩展(在设置插槽的语句之后addRemoveExcludeRule):

allocslot lpwstr userPath: 260 chars
newslot bstr userPathBstr

// userPath = ExpandEnvironmentStringsW("%USERPROFILE%\Documents\Excluded", userPath, MAX_PATH - 1)
call kernel32.dll!ExpandEnvironmentStringsW /return uint (lpwstr "%USERPROFILE%\\Documents\\Excluded", slotdata userPath, int 259)
// userPathBstr = SysAllocString(userPath)
call oleaut32.dll!SysAllocString /into userPathBstr (slotdata userPath)
// fh->AddRemoveExcludeRule(TRUE, FH_FOLDER, userPathBstr)
call funcat addRemoveExcludeRule /return uint (slotdata fhPtr, int 1, int 0, slotdata userPathBstr)

要设置路径,请更改ExpandEnvironmentStringsW调用语句中引号内的文本。与此处调用的其他函数不同,该函数在成功时返回非零值。要排除多个文件夹,请复制三个调用语句,但不要复制allocslotnewslot语句。

相关内容