Get file's Previous Versions, from WINAPI

混江龙づ霸主 提交于 2019-12-05 18:26:55
ryyker

There are several tags listed with this question. So it is unclear if a strictly c/c++ approach is desired, or if scripting etc will work. In any case...

Here are some links that will hopefully point in the right direction:

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

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

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).

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";

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

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

Good luck! =]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!