ハードディスク(HDD)のデータ完全消去です。
不要なハードディスク(HDD)はフォーマットしてもデータは消去できません。
※復元ソフトを使用すると復元可能な為
なので、データファイルを作成してデータを上書きしてデータを消去させます。
今回は自作でプログラムを作成しました。
仕様は下記になります。
1.実行ファイルのドライブが対象
2.フォルダ階層は「日付」→「時間(時)」→「時間(分)」
3.作成ファイル名は「時間(時、分、秒、ミリ秒)」
4.作成ファイル内容は「1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ」を「10000」回ループ
5.状況ログとしてドライブ情報表示
【サンプルプログラム(VB.Net)】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
Imports System.IO Module ModuleMain Private Const WRITE_NUMBER As Integer = 10000 Private Const WRITE_BUFFER As String = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ" Private Const FILE_SIZE As Double = 1.2 'HDDの空き容量にデータを作成 Sub Main() '実行ファイル名取得 Dim myAssemblyName As String = My.Application.Info.AssemblyName Console.WriteLine("{0} 処理開始", myAssemblyName) Try Dim myMessage As String = String.Empty '対象ドライブ名取得 Dim myDrivePath As String = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()) Dim myDriveName As String = myDrivePath.Substring(0, 1) '実行確認取得 myMessage = String.Format("{0}ドライブの空き容量にデータ作成しますか?", myDriveName) Dim myDigResult As MsgBoxResult = MsgBox(myMessage, MsgBoxStyle.YesNo, myAssemblyName) If myDigResult = MsgBoxResult.No Then Exit Try End If '対象ドライブ情報表示 Dim myFreeSpace As Long = 0 If ConsoleDriveInfo(myDriveName, myFreeSpace) = False Then Exit Try End If 'ファイル内容作成 Dim myBuffer As String = String.Empty For ii As Integer = 1 To WRITE_NUMBER myBuffer = String.Format("{0}{1}{2}", myBuffer, WRITE_BUFFER, Environment.NewLine) Next 'サイズ計算 Dim mySize As Long = 0 mySize = WRITE_BUFFER.Count * WRITE_NUMBER * FILE_SIZE Dim myDatePath As String = String.Empty Dim myTimeHPath As String = String.Empty Dim myTimeMPath As String = String.Empty Dim myTimeFilePath As String = String.Empty Do While mySize < myFreeSpace '日付ディレクトリ名生成 myDatePath = Path.Combine(myDrivePath, Now.ToString("yyyyMMdd")) If Directory.Exists(myDatePath) = False Then Directory.CreateDirectory(myDatePath) End If '時間(時)ディレクトリ名生成 myTimeHPath = Path.Combine(myDatePath, Now.ToString("HH")) If Directory.Exists(myTimeHPath) = False Then Directory.CreateDirectory(myTimeHPath) End If '時間(分)ディレクトリ名生成 myTimeMPath = Path.Combine(myTimeHPath, Now.ToString("mm")) If Directory.Exists(myTimeMPath) = False Then Directory.CreateDirectory(myTimeMPath) End If '時間ファイル作成 myTimeFilePath = Path.Combine(myTimeMPath, Now.ToString("HHmmssfff") & ".txt") Try Using myFile As New IO.StreamWriter(myTimeFilePath, False, Text.Encoding.GetEncoding("shift_jis")) '書き込み myFile.WriteLine(myBuffer) End Using Catch ex As Exception Console.WriteLine(ex.Message, myAssemblyName) Exit Do End Try '対象ドライブ情報表示 If ConsoleDriveInfo(myDriveName, myFreeSpace) = False Then Exit Do End If Loop Console.WriteLine("{0} 処理終了", myAssemblyName) myMessage = String.Format("{0}ドライブの空き容量にデータ作成完了", myDriveName) MsgBox(myMessage, MsgBoxStyle.Information, myAssemblyName) Catch ex As Exception Console.WriteLine(ex.Message, myAssemblyName) Console.WriteLine("{0} 処理終了", myAssemblyName) MsgBox(ex.Message, MsgBoxStyle.Critical, myAssemblyName) End Try End Sub Private Function ConsoleDriveInfo(ByVal myDriveName As String, ByRef myFreeSpace As Long) As Boolean '初期化 ConsoleDriveInfo = False myFreeSpace = 0 '対象ドライブ情報取得 Dim myDriveInfo As New DriveInfo(myDriveName) If myDriveInfo.IsReady = False Then Exit Function End If 'サイズ取得 Dim myTotalSize As Long = myDriveInfo.TotalSize myFreeSpace = myDriveInfo.TotalFreeSpace '画面出力 Console.WriteLine(" ") Console.WriteLine("{0}ドライブのバイト数: {1,20} Byte", myDriveName, myTotalSize.ToString("#,0")) Console.WriteLine("{0}ドライブの空きバイト数:{1,20} Byte", myDriveName, myFreeSpace.ToString("#,0")) ConsoleDriveInfo = True End Function End Module |
それでは、実行して確認します。
無事動作して目的(データ完全消去)は達成しましたが、状況ログ表示に問題がりました。
問題は表示回数が多くて早くて読めません。
※画像では停止しているように見えますが、1秒間に50回位表示されてる
- 投稿タグ
- ソフト