Version control in Explorer context menu on VBS

When working together with a common group of files, often one of the employees can ruin the document. Working as a typesetter in a regional newspaper, I encounter such cases, and I have to re-arrange some elements.

So I thought about a file recovery system. Backups on the machine are carried out automatically once a week, which allows you to not lose data, but with frequent changes to documents this does not save. The publication is weekly, there are few bands - the directory with the layout files of the current release takes 1-2 GB. We do not have a separate file server, all the data is stored on my machine, and is used over the network by two more PCs. Actually, all the cards are in my hands.

For backup I use the MAX SyncUp utility(not advertising). There are 3 hard drives in the machine: OS / software, layout / photo and backups. Creating a backup copy of any file does not affect performance noticeably. There is plenty of free space on the third HDD, so I did not use additional software, guided by the principle "Less frills - more stable operation of the system."
So, I started organizing my ideas.

To begin with, I created a rule in the backup utility that copies all files changed in the layout to the X: \ Backup \ directory, with the date and time, every 7 minutes (the time was selected experimentally). Each version of the file has a difference in a short period of time, unless, of course, has been changed. Having worked since this Monday, I once again ran into data corruption, and tried to recover it. To do this, I had to manually go into the directory with backups and type the name of the strip in the search. But it’s impossible to work like that, and from the principle it is necessary to develop an idea. I pass to the second part - I add the item “File Versions” to the context menu.

To start, I created a directory in the registry

HKEY_CLASSES_ROOT\*\shell\Search\command


In the latter added a string parameter

WScript C:\windows\version.vbs \"%1\"


In the Search directory in the registry above, I created a string parameter called MUIVerb, which specifies the name of the item. In our case, these are “File Versions”, and the Icon parameter containing the path to the icon.

What happened:

image

image

My backups are automatically saved to the directory as they change in this form:

X:\Backup\2014-09-01T16-45\Сб 3 полоса
X:\Backup\2014-09-02T15-32\Сб 1 полоса
X:\Backup\2014-09-02T15-39\Сб 1 полоса


Now it's time to write a VBS script that looks for the necessary files in the backup and lists them.
Using WSO.dll

Script code
Dim folder
Dim fso
Dim filename
Dim mass()
folder = "X:\Backup" 'Здесь указывается путь к папке с бэкапами
Set WshShell = CreateObject("WScript.Shell")
rc = WshShell.Run("regsvr32.exe /s c:\windows\wso.dll", 0, True) 
Set objArg = WScript.Arguments
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set oFolders = fso.GetFolder(folder)
Set oSubfolders = oFolders.SubFolders
filename = FSO.GetFileName(objArg(0))
Redim mass(oSubFolders.Count)
i = 1
For Each oFolder In oSubFolders
	mass(i) = oFolder.Name
	i=i+1
Next 
Set o = WScript.CreateObject("Scripting.WindowSystemObject")
o.EnableVisualStyles = true
Set f = o.CreateForm(0,0,520,0)
f.Text = "Версии Файлов"
f.CenterControl()
Sub ButtonClick(this)
	rc=WshShell.Run(this.note)
	f.Close()
End Sub
Function CanClose(Sender,Result)
Result.Put(true)
End Function
files =0
for i = oSubFolders.Count to 1 Step -1
	if FSO.FileExists(Folder & "\"& mass(i) & "\" & filename) Then
		if files < 15 then
			f.ClientHeight = 40 * (files +1)
			f.CenterControl()
			strListFolders = fso.GetBaseName(Folder & "\"& mass(i) & "\" & filename) & " - " & GetDate(mass(i)) & vbcrlf
			SET Button = f.CreateButton(7,40 * files,490,40,strListFolders)
			Button.CommandLinkButton = true
			Button.OnClick = GetRef("ButtonClick")
			Button.Note = chr(34) & Folder & "\"& mass(i) & "\" & filename & chr(34)
			files = files +1
		End if
	End if
Next
if files =0 then
MsgBox "Файлы не найдены"
f.close
End if
f.OnCloseQuery = GetRef("CanClose")
f.Show()
o.Run()
Function StartupDir()
	Dim s
	s = WScript.ScriptFullName
	s = Left(s,InStrRev(s,"\"))
	StartupDir = s
End Function
Sub AboutWSO_OnHitTest(Sender,x,y,ResultPtr)	
	ResultPtr.put(o.Translate("HTCAPTION"))
End Sub
Sub CloseFormHandler(Sender)
	Sender.Form.Close()
End Sub
function GetDate(ByVal DateIn)
	If DateDiff("d",DateSerial(Left(DateIn,4),Mid(DateIn,6,2),Mid(DateIn,9,2)),Date()) = 1 Then
		GetDate = "Вчера в " & Mid(DateIn,12,2) & "." & Right(DateIn,2)
	ElseIf DateDiff("d",DateSerial(Left(DateIn,4),Mid(DateIn,6,2),Mid(DateIn,9,2)),Date()) > 1 Then
		GetDate = Mid(DateIn,9,2) & "." & Mid(DateIn,6,2) & "." & Left(DateIn,4) & " в " & Mid(DateIn,12,2) & "." & Right(DateIn,2)
	'ElseIf DateDiff("d",DateSerial(Left(DateIn,4),Mid(DateIn,6,2),Mid(DateIn,9,2)),Date()) < 1 Then
	'	GetDate = Mid(DateIn,9,2) & "." & Mid(DateIn,6,2) & "." & Left(DateIn,4) & " в " & Mid(DateIn,12,2) & "." & Right(DateIn,2)
	ElseIf DateSerial(Left(DateIn,4),Mid(DateIn,6,2),Mid(DateIn,9,2)) = Date() Then
		GetDate = "Сегодня в " & Mid(DateIn,12,2) & "." & Right(DateIn,2)
	End If	
end function



What happened:

image

image

I also set auto-deletion of backup files older than 10 days. Since the accumulated occupied disk space from Monday to Friday amounted to 6 GB, you can not worry about free space. Now you can, without holding cumbersome software in your memory, have quick access to backups, including over the network, since there is no need for additional software on other machines.

The implementation, of course, has flaws, such as the lack of search in subdirectories and binding to a name. But, although now there is no need for a more flexible structure of the VBS script, it will certainly be needed in the future. I will be glad to criticism and suggestions.

Also popular now: