2011-12-11 4 views
0

VB.NetでExcelファイル回復プログラムを作成して、Microsoft's recommended methodsにアクセスしてアクセスすると便利です。おそらく私のkludgyに興味があり、充実したエラーがあり、十分なクリーンアップコードがない場合は、http://pastebin.com/v4GgDteYです。私はまだグラフのマクロテーブルのリカバリをテストしていませんが、基本的な機能は動作するようです。VB.Net:以前のシャドウコピーバージョンのファイルを表示して1つを選択できるようにする方法

シャドウコピーサービスが有効になっていて以前のコピーがある場合、VistaおよびWindows 7のユーザーはアプリケーション内のファイルの以前のバージョンのリストを提供されることから利益を得ることができました。これはどうすればいいですか?

私は多くのウェブページを見ていましたが、ベビーベッドのコードは簡単ではありませんでした。私は、シェル経由でvssadminを使うことが1つの可能性はあると思いますが、それはかなり面倒です。私は、以前のバージョンのプロパティシートのようなダイアログボックスを表示し、ユーザーが以前のバージョンの1つを選択できるようにしたいだけです。私は、コンテキストメニューと "以前のバージョンの選択を復元"をプログラムで呼び出すことで、以前のバージョンのプロパティシートをシェルから表示することができたと思いますが、Vista Home BasicとPremiumユーザーのリストを提供できるようにしたいと思っています。明らかに以前のバージョンが存在していても、そのタブにアクセスできます。さらに、私はXPのユーザファイルをシャドウコピーに置いているだけですが、XPユーザには同じ機能を提供したいと考えています。

私はシャドウコピーサービスのMSDNを見て、すべてのページを調べました。また、AlphaVSSとAlphaFSとすべてのコメントも調べました。私はAlphaVssとAlphFSを使い、次のことをする必要があると思っていますか?

  1. コンピュータに存在するスナップショット/復元ポイントの一覧を確認します。
  2. これらのスナップショットをマウントします。
  3. マウントされたボリュームを、ユーザーが回復したいExcelファイルに移動し、それらのパスのリストを作成します。
  4. パスのリストを使って、ある種のdiffプログラムと比較して、元のファイルのシャドウコピーを比較します。
  5. 復旧対象と異なるシャドウコピーの中で最も古いバージョンまたは最も古いバージョン(問題はないと思われます)を引き出します。
  6. 異なるバージョンのファイルがリストされています。

これは面倒で時間がかかるようですが、おそらく最速の方法です。私はちょうど今行く方法である確認が必要です。

答えて

0

最後に、コーディングを開始することにしました。コードの高速化や、リカバリファイルのターゲットとは異なるファイルとの関係については、ご提案ください。 AlphaVSSとAlphaFSでこれを行う簡単な方法はありますか?

Private Sub Button1_Click_2(sender As System.Object, e As System.EventArgs) Handles Button1.Click 

    'Find out the number of vss shadow snapshots (restore 
    'points). All shadows apparently have a linkable path 
    '\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy#, 
    'where # is a simple one, two or three digit integer. 
    Dim objProcess As New Process() 
    objProcess.StartInfo.UseShellExecute = False 
    objProcess.StartInfo.RedirectStandardOutput = True 
    objProcess.StartInfo.CreateNoWindow = True 
    objProcess.StartInfo.RedirectStandardError = True 
    objProcess.StartInfo.FileName() = "vssadmin" 
    objProcess.StartInfo.Arguments() = "List Shadows" 
    objProcess.Start() 

    Dim burp As String = objProcess.StandardOutput.ReadToEnd 
    Dim strError As String = objProcess.StandardError.ReadToEnd() 
    objProcess.WaitForExit() 
    Dim xnum As Integer = 0 
    Dim counterVariable As Integer = 1 
    ' Call Regex.Matches method. 
    Dim matches As MatchCollection = Regex.Matches(burp, _ 
          "HarddiskVolumeShadowCopy") 
    ' Loop over matches. 
    For Each m As Match In matches 
     xnum = xnum + 1 
     'At the max xnum + 1 is the number of shadows that exist 
    Next 
    objProcess.Close() 

    Do 
     'Here we make symbolic links to all the shadows, one at a time 
     'and loop through until all shadows are exposed as folders in C:\. 
     Dim myProcess As New Process() 
     myProcess.StartInfo.FileName = "cmd.exe" 
     myProcess.StartInfo.UseShellExecute = False 
     myProcess.StartInfo.RedirectStandardInput = True 
     myProcess.StartInfo.RedirectStandardOutput = True 
     myProcess.StartInfo.CreateNoWindow = True 
     myProcess.Start() 
     Dim myStreamWriter As StreamWriter = myProcess.StandardInput 
     myStreamWriter.WriteLine("mklink /d C:\shadow" & counterVariable _ 
      & " \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy" _ 
      & counterVariable & "\") 
     myStreamWriter.Close() 
     myProcess.WaitForExit() 
     myProcess.Close() 

     ' Here I compare our recovery target file against the shadow copies 
     Dim sFile As String = PathTb.Text 
     Dim sFileShadowPath As String = "C:\shadow" & _ 
      counterVariable & DelFromLeft("C:", sFile) 
     Dim jingle As New Process() 
     jingle.StartInfo.FileName = "cmd.exe" 
     jingle.StartInfo.UseShellExecute = False 
     jingle.StartInfo.RedirectStandardInput = True 
     jingle.StartInfo.RedirectStandardOutput = True 
     jingle.StartInfo.CreateNoWindow = True 
     jingle.Start() 
     Dim jingleWriter As StreamWriter = jingle.StandardInput 
     jingleWriter.WriteLine("fc """ & sFile & """ """ _ 
           & sFileShadowPath & """") 
     jingleWriter.Close() 
     jingle.WaitForExit() 
     Dim jingleReader As StreamReader = jingle.StandardOutput 
     Dim JingleCompOut As String = jingleReader.ReadToEnd 
     jingleReader.Close() 
     jingle.WaitForExit() 
     jingle.Close() 
     Dim jingleBoolean As Boolean = JingleCompOut.Contains(_ 
      "no differences encountered").ToString 
     If jingleBoolean = "True" Then 
      MsgBox(jingleBoolean) 
     Else 
      'I haven't decided what to do with the paths of 
      'files that are different from the recovery target. 
      MsgBox("No") 
     End If 

     counterVariable = counterVariable + 1 
    Loop Until counterVariable = xnum + 1 

End Sub 
+1

VBには、あなたのためにそれらのいくつかをきれいにするかもしれないWithステートメントがあります。 – StingyJack

関連する問題