MoveFileEx() 重启时删除文件
MoveFileEx() File removal on reboot
目前我可以在重启时删除目录。我目前通过使用 MoveFileEx
函数并传递 MOVEFILE_DELAY_UNTIL_REBOOT
常量来做到这一点。
我的问题是如果我有以下情况:
目录 1 和里面我有目录 2...目录 2 未安装,这意味着目录需要删除,但因为目录 1 中只有一个目录,这意味着我可以删除目录 1,这将反过来删除目录 2。但是假设在我将目录 1 标记为在重新启动时删除另一个目录已安装到目录 1 中,称为目录 3。在这种情况下,只应删除目录 2,因为我们不会删除目录 3。
我想知道是否有任何条件变量/常量可以帮助解决这种情况?
答案是,如果一个目录或文件没有被标记为删除,那么它所在的目录将不会被删除。 (正如 IInspectable 指出的那样)
"The system deletes a directory that is tagged for deletion with the
MOVEFILE_DELAY_UNTIL_REBOOT flag only if it is empty."
But lets say after I have marked Directory 1 to be removed on reboot Another Directory has been installed into Directory 1 called Directory 3. In this scenario only Directory 2 should be removed as we dont wont to remove Directory 3.
没有 API 到 "unmark" 一个 file/directory 被标记为在重新启动时删除。您必须直接更新注册表才能从列表中删除一个项目。 MoveFileEx()
documentation 告诉您使用了哪个注册表项:
The function stores the locations of the files to be renamed at restart in the following registry value:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations
This registry value is of type REG_MULTI_SZ. Each rename operation stores one of the following NULL-terminated strings, depending on whether the rename is a delete or not:
szDstFile[=12=][=12=]
szSrcFile[=12=]szDstFile[=12=]
The string szDstFile[=12=][=12=] indicates that the file szDstFile is to be deleted on reboot. The string szSrcFile[=12=]szDstFile[=12=] indicates that szSrcFile is to be renamed szDstFile on reboot.
另一方面,文档还说:
The system deletes a directory that is tagged for deletion with the MOVEFILE_DELAY_UNTIL_REBOOT flag only if it is empty. To ensure deletion of directories, move or delete all files from the directory before attempting to delete it. Files may be in the directory at boot time, but they must be deleted or moved before the system can delete the directory.
但这只提到了 文件 ,而不是 子目录 。
目前我可以在重启时删除目录。我目前通过使用 MoveFileEx
函数并传递 MOVEFILE_DELAY_UNTIL_REBOOT
常量来做到这一点。
我的问题是如果我有以下情况:
目录 1 和里面我有目录 2...目录 2 未安装,这意味着目录需要删除,但因为目录 1 中只有一个目录,这意味着我可以删除目录 1,这将反过来删除目录 2。但是假设在我将目录 1 标记为在重新启动时删除另一个目录已安装到目录 1 中,称为目录 3。在这种情况下,只应删除目录 2,因为我们不会删除目录 3。
我想知道是否有任何条件变量/常量可以帮助解决这种情况?
答案是,如果一个目录或文件没有被标记为删除,那么它所在的目录将不会被删除。 (正如 IInspectable 指出的那样)
"The system deletes a directory that is tagged for deletion with the MOVEFILE_DELAY_UNTIL_REBOOT flag only if it is empty."
But lets say after I have marked Directory 1 to be removed on reboot Another Directory has been installed into Directory 1 called Directory 3. In this scenario only Directory 2 should be removed as we dont wont to remove Directory 3.
没有 API 到 "unmark" 一个 file/directory 被标记为在重新启动时删除。您必须直接更新注册表才能从列表中删除一个项目。 MoveFileEx()
documentation 告诉您使用了哪个注册表项:
The function stores the locations of the files to be renamed at restart in the following registry value:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations
This registry value is of type REG_MULTI_SZ. Each rename operation stores one of the following NULL-terminated strings, depending on whether the rename is a delete or not:
szDstFile[=12=][=12=]
szSrcFile[=12=]szDstFile[=12=]
The string szDstFile[=12=][=12=] indicates that the file szDstFile is to be deleted on reboot. The string szSrcFile[=12=]szDstFile[=12=] indicates that szSrcFile is to be renamed szDstFile on reboot.
另一方面,文档还说:
The system deletes a directory that is tagged for deletion with the MOVEFILE_DELAY_UNTIL_REBOOT flag only if it is empty. To ensure deletion of directories, move or delete all files from the directory before attempting to delete it. Files may be in the directory at boot time, but they must be deleted or moved before the system can delete the directory.
但这只提到了 文件 ,而不是 子目录 。