Tác giả: Sưu tầm
Mô tả: Xóa mọi file cho dù chúng có đang được mở đi chăng nữa
Bạn đang viết phần mềm về một chương trình kiểm tra Virus USB, phần mềm hệ thống,... ? Đã có khi nào bạn gặp phải những File cực kỳ khoai và rất khó để Kill file đó đi cho dù đã làm mọi cách ?
Hehe, điều đó sẽ được giải quyết triệt để với thủ thuật sau. Chỉ cần bạn copy vào 1 Module rồi chạy thôi.
Using vb Syntax Highlighting
' Đây chỉ là một ví dụ đơn giản cho chương trình xóa File
' dành cho người nào đang muốn viết chương trình đến xóa một file nào đó hoàn toàn
Global LongCount As Long
Global ShortCount As Integer
Global LongString As String
Global ShortString As String
Global Clean_Level As Integer
Function Check_File(filename As String) As Boolean
'Kiểm tra xem file có tồn tại hay ko
On Error GoTo Ferr
Open filename For Input As #1
Close #1: Check_File = True
Exit Function
Ferr: Check_File = False
End Function
Sub update(txt As String)
Form1.status = Form1.status & txt & vbCrLf
End Sub
Function Remove_File(filename As String)
On Error GoTo Ferr
Kill filename ' Đoạn này ta xóa File một cách đơn giản. Dùng hàm Kill
Exit Function
Ferr: a = MsgBox("Có lỗi sảy ra trong quá trình xóa File.", vbCritical, "Error")
End Function
Function Rand_Char() As String
'Hàm tạo ra một chuỗi ký tự tự động và sẽ được dùng để ghi đè lên file
Randomize: Rand_Char = Chr(Int(200 * Rnd + 1))
End Function
Function Determine_Strings(filename As String)
On Error GoTo Ferr
Dim fCount As String
Dim Remr As String
Dim fSize As Double
Dim LongRand As String: LongRand = ""
Dim ShortRand As String: ShortRand = ""
fSize = FileLen(filename)
fCount = fSize / 100
Remr = Mid$(fCount, InStr(1, fCount, ".") + 1, 3)
fCount = Mid$(fCount, 1, InStr(1, fCount, ".") - 1)
'Ghi đè sau khi đã tạo một chuỗi String
For i = 0 To 100
LongRand = LongRand & Rand_Char
Next i
'Tạo một chuỗi String dùng cho X ký tự
'Ghi đè để làm file dừng ko chạy được nữa
For o = 0 To Remr - 1
ShortRand = ShortRand & Rand_Char
Next o
'now set up your global statements for later use
ShortString = ShortRand: LongString = LongRand
LongCount = fCount: ShortCount = Remr
Exit Function
'Hehe, có lỗi nè
Ferr: a = MsgBox("Có lỗi sảy ra.", vbCritical, "Error")
End Function
Function Clean_File(filename As String)
On Error GoTo Ferr
'Dim filename As String
Dim countr As Double:
Dim c As String * 100
Dim f As String '* ShortCount
fSize = FileLen(filename)
Call update(filename & " - " & fSize & " bits long")
For r = 1 To Clean_Level
countr = 0
Open filename For Binary As #1
Call update("-Bắt đầu ghi 100 bit string " & LongCount & " lần...")
Do Until countr = LongCount
countr = countr + 1
c = LongString
Put 1, , c ' Ghi nhiều lần vào nữa
DoEvents
Loop
Call update("-Ghi một chuỗi nhỏ " & ShortCount & " bit string...")
f = ShortString
Put 1, , f ' Ghi một chuỗi nhỏ vào File
Close #1
Next r
Call update("Đã hoàn thành quá trình xóa File!")
Call update("Phá hủy :" & fSize & " bits")
Call Remove_File(filename)
Exit Function
Ferr: a = MsgBox("Có lỗi xảy ra, quá trình xóa file không thành công.", vbOKOnly, "Error")
Call update("Có lỗi xảy ra!")
Close #1 ' Đóng file lại rồi làm lại thui
End Function
' dành cho người nào đang muốn viết chương trình đến xóa một file nào đó hoàn toàn
Global LongCount As Long
Global ShortCount As Integer
Global LongString As String
Global ShortString As String
Global Clean_Level As Integer
Function Check_File(filename As String) As Boolean
'Kiểm tra xem file có tồn tại hay ko
On Error GoTo Ferr
Open filename For Input As #1
Close #1: Check_File = True
Exit Function
Ferr: Check_File = False
End Function
Sub update(txt As String)
Form1.status = Form1.status & txt & vbCrLf
End Sub
Function Remove_File(filename As String)
On Error GoTo Ferr
Kill filename ' Đoạn này ta xóa File một cách đơn giản. Dùng hàm Kill
Exit Function
Ferr: a = MsgBox("Có lỗi sảy ra trong quá trình xóa File.", vbCritical, "Error")
End Function
Function Rand_Char() As String
'Hàm tạo ra một chuỗi ký tự tự động và sẽ được dùng để ghi đè lên file
Randomize: Rand_Char = Chr(Int(200 * Rnd + 1))
End Function
Function Determine_Strings(filename As String)
On Error GoTo Ferr
Dim fCount As String
Dim Remr As String
Dim fSize As Double
Dim LongRand As String: LongRand = ""
Dim ShortRand As String: ShortRand = ""
fSize = FileLen(filename)
fCount = fSize / 100
Remr = Mid$(fCount, InStr(1, fCount, ".") + 1, 3)
fCount = Mid$(fCount, 1, InStr(1, fCount, ".") - 1)
'Ghi đè sau khi đã tạo một chuỗi String
For i = 0 To 100
LongRand = LongRand & Rand_Char
Next i
'Tạo một chuỗi String dùng cho X ký tự
'Ghi đè để làm file dừng ko chạy được nữa
For o = 0 To Remr - 1
ShortRand = ShortRand & Rand_Char
Next o
'now set up your global statements for later use
ShortString = ShortRand: LongString = LongRand
LongCount = fCount: ShortCount = Remr
Exit Function
'Hehe, có lỗi nè
Ferr: a = MsgBox("Có lỗi sảy ra.", vbCritical, "Error")
End Function
Function Clean_File(filename As String)
On Error GoTo Ferr
'Dim filename As String
Dim countr As Double:
Dim c As String * 100
Dim f As String '* ShortCount
fSize = FileLen(filename)
Call update(filename & " - " & fSize & " bits long")
For r = 1 To Clean_Level
countr = 0
Open filename For Binary As #1
Call update("-Bắt đầu ghi 100 bit string " & LongCount & " lần...")
Do Until countr = LongCount
countr = countr + 1
c = LongString
Put 1, , c ' Ghi nhiều lần vào nữa
DoEvents
Loop
Call update("-Ghi một chuỗi nhỏ " & ShortCount & " bit string...")
f = ShortString
Put 1, , f ' Ghi một chuỗi nhỏ vào File
Close #1
Next r
Call update("Đã hoàn thành quá trình xóa File!")
Call update("Phá hủy :" & fSize & " bits")
Call Remove_File(filename)
Exit Function
Ferr: a = MsgBox("Có lỗi xảy ra, quá trình xóa file không thành công.", vbOKOnly, "Error")
Call update("Có lỗi xảy ra!")
Close #1 ' Đóng file lại rồi làm lại thui
End Function
Parsed in 0.065 seconds, using GeSHi 1.0.8.4
Khi dùng, bạn để ý đến Clean_Level
Nếu Clean_Level càng cao thì file sẽ được xóa mạnh hơn
Ví dụ
Đối với File bình thường ( Ví dụ 1 file video chẳng hạn và đang được mở bằng 1 trình duyệt video nào đó ) thì chỉ cần mức 1 cũng có thể xóa file ( để ý đến cái thanh Seek, nó sẽ trôi cực nhanh luôn vì đã bị ghi đè mà nên dữ liệu file hỏng )
Còn đối với loại Virus cứng đầu thì cứ đặt mức 10
Cách dùng cho nút lệnh
Using vb Syntax Highlighting
Private Sub Command1_Click()
If Check_File(SelectedFile) = True Then
Call Determine_Strings(SelectedFile)
Call Clean_File(SelectedFile)
Else
MsgBox "File ko tồn tại"
End If
End Sub
If Check_File(SelectedFile) = True Then
Call Determine_Strings(SelectedFile)
Call Clean_File(SelectedFile)
Else
MsgBox "File ko tồn tại"
End If
End Sub
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
Dùng kèm với CM Dialog để duyệt file


. Cái command dialog là gì vậy?, làm sao chèn vao form?