Pergunta

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

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

enter image description here

Thanks advanced! =]

Foi útil?

Solução 2

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.

enter image description here

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! =]

Outras dicas

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:

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top