Download
0: ' Copy open files using Volume Shadow Copy Service (FAR Manager User Menu script)
1: ' Author Szikra Istvan, 2011.05.08.
2: ' e-mail: szikra.istvan@freemail.hu
3: ' web: http://www.szikraistvan.hu/
4: ' http://foton.szikraistvan.hu/blog/
5: if WScript.Arguments.Count<1 then
6: WScript.Echo "Parameters: <drive|mountpoint> [callback]"
7: WScript.Echo "If callback parameteris not specified %callback% environment variable will be used."
8: WScript.Echo "Callback will be called with the created Shadow Copy Name (\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy***\)"
9: WScript.Quit -1
10: end if
11:
12: strVolume = WScript.Arguments(0)
13: if Len(strVolume) < 2 then ' only drive letter
14: strVolume = strVolume & ":\"
15: end if
16: if Right(strVolume,1) <> "\" then 'missing trailing backslash
17: strVolume = strVolume & "\"
18: end if
19:
20: Set wshShell = CreateObject( "WScript.Shell" )
21: strRunCmd = wshShell.ExpandEnvironmentStrings( "%callback%" )
22: strLogFile = wshShell.ExpandEnvironmentStrings( "%log%" )
23:
24: if WScript.Arguments.Count>1 then
25: strRunCmd = WScript.Arguments(1)
26: end if
27:
28: if Len(strRunCmd)<1 then
29: strRunCmd = "VSCS.cmd"
30: end if
31: if Len(strLogFile)<1 then
32: strLogFile = "VSCS.vbs.log"
33: end if
34:
35: WScript.echo "Callback: " & strRunCmd
36: WScript.echo "Log: " & strLogFile
37:
38:
39: strComputer = "."
40: Set svc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
41:
42: Set shadow = svc.Get("Win32_ShadowCopy")
43: errResult = shadow.Create(strVolume, "ClientAccessible", strShadowID)
44: 'The Volume parameter can be specified as a volume drive letter, mount point, or volume globally unique identifier (GUID) name.
45:
46:
47: if errResult <> 0 Then
48: WScript.echo "Error:" & errResult
49: else
50: WScript.echo "Created Shadow successfully"
51: Set colItems = svc.ExecQuery("Select * From Win32_ShadowCopy Where ID = '" & strShadowID & "'")
52:
53: For Each objItem in colItems
54: WScript.Echo "Path to files is " & objItem.DeviceObject
55:
56: WScript.Echo "Executing Callback..."
57: 'Set oExec = wshShell.Exec( strRunCmd & " " & objItem.DeviceObject & " >> " & strLogFile )
58: Set oExec = wshShell.Exec( strRunCmd & " " & objItem.DeviceObject )
59: Set oExecOut = oExec.StdOut
60: Do While oExec.Status = 0
61: WScript.Sleep 100
62: While Not oExecOut.AtEndOfStream
63: strLine = oExecOut.ReadLine
64: WScript.Echo strLine
65: Wend
66: Loop
67: WScript.Echo "Callback Status " & oExec.Status
68:
69: objItem.Delete_
70: Next
71: end if
72: