从 WINAPI 获取文件的先前版本 [英] Get file's Previous Versions, from WINAPI

查看:31
本文介绍了从 WINAPI 获取文件的先前版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 7 中,有可能获取文件的先前版本,如下图所示:

In Windows 7 theres a possibility for getting file's previous versions like in the below image:

有没有办法通过代码检索文件的先前版本?因为我找不到任何 API.

Is there any way to retrieve file's previous version by code? because I couldn't find any API.

先谢谢了!=]

推荐答案

所以经过一番搜索,感谢@ryyker 和@Ben 的指导,我找到了答案:

So after some searching, and thanks to @ryyker and @Ben directions I was able to find out the answer:

例如文件:C:\SomeFolder\SomeFile.exe

For example for file: C:\SomeFolder\SomeFile.exe

从 cmd(以管理员身份运行):

From cmd (run as administrator):

vssadmin list shadows for=C:\

对于程序化解决方案,您可以使用:

For programmatic solution you can run it with:

CreateProcessW(NULL,L"cmd.exe /c \"vssadmin list shadows for=C:\\ > C:\\someTmpFile.txt\"",...);

读取并解析创建的文件.

Read and parse the created file.

在上面你会得到一个卷影副本列表(一种以前的版本"容器).

Here above you get a list of shadow copies (kind of "Previous versions" containers).

参考相应的Shadow Copy Volume"行(您想要的版本)并在卷名后附加剩余的文件路径:

Refer to the appropriate "Shadow Copy Volume" row (the version you want) and append the remaining file path after the volume name:

\\ Previous version path =  \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy3\SomeFolder\SomeFile.exe"
wchar_t* prevPath = L"\\\\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy3\\SomeFolder\\SomeFile.exe";

现在您可以使用众所周知的 WIN32API 函数 CreateFile 和 ReadFile 读取文件.(从 MSDN 创建和读取文件示例:示例)

Now you can read the file with the well known WIN32API functions CreateFile and ReadFile. (Create and Read file example from MSDN: EXAMPLE)

确保使用该函数的 UNICODE 版本,因为 ASCII 版本可能不支持\?\"路径.

Make sure to use the UNICODE versions of that functions as the ASCII version may lack support of "\?\" paths.

祝你好运!=]

这篇关于从 WINAPI 获取文件的先前版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆