📜 ⬆️ ⬇️

Version Control in the Explorer context menu on VBS

When collectively working with a common group of files, it is often possible for someone from the employees to spoil the document. When I work as a layout designer in a district newspaper, I encounter such cases, and I have to rearrange some elements.

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

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

To begin with, in the backup utility I created a rule that copies all files that were changed in the layout to the X: \ Backup \ directory, indicating the date and time, every 7 minutes (the time was chosen experimentally). Each version of the file has a difference in a short period of time, if, of course, has been changed. Having worked since this Monday, I once again faced data corruption, and tried to recover them. For this, we had to manually go into the backup directory and type the name of the strip in the search. But it is impossible to work this way, and from the principle it is necessary to develop the idea. I turn to the second part - I add the “File Versions” item to the context menu.
')
To start in the registry created directory

HKEY_CLASSES_ROOT\*\shell\Search\command 


In the last added string parameter

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


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

What happened:

image

image

My backups are saved to the directory automatically as they change to 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 searches for the necessary files in the backup and lists them.
We use 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 /sc:\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 put backup files on auto deletion older than 10 days. Since the accumulated occupied disk volume from Monday to Friday was 6 GB, you should not worry about the free space. Now it is possible, without keeping cumbersome software in memory, to have quick access to backup copies, including over the network, since there is no need for additional software on other machines.

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

Source: https://habr.com/ru/post/239515/


All Articles