主题:删除自身文件
wangyanghetaohua
[专家分:110] 发布于 2008-11-29 00:01:00
各位大蛇们:请问怎么实现当程序运行后再退出程序后自动删除本身文件?或隐藏自身文件呀?谢谢了!
回复列表 (共5个回复)
沙发
artless [专家分:1490] 发布于 2008-11-29 00:12:00
这难。
板凳
snyga [专家分:1480] 发布于 2008-11-29 01:25:00
方法1:
Private Sub Form_Unload(Cancel As Integer)
Shell "cmd /c del " & App.EXEName & ".exe"
End Sub
方法2:
Public Sub KillMe(Optional Delay As Long) '自杀
Dim PathExeName As String
Dim PathBat As String
Dim str1 As String
PathExeName = App.EXEName & ".exe"
PathBat = "kill.bat"
If Delay > 0 Then str1 = "ping -n 2 -w 500 0.0.0.1>nul"
str1 = "@echo off" & vbCrLf & _
str1 & vbCrLf & _
"del " & PathExeName & vbCrLf & _
"del " & PathBat & vbCrLf & _
"cls" & vbCrLf & _
"exit"
Open PathBat For Output As #1
Print #1, str1
Close
Shell PathBat, vbHide
End
End Sub
方法3: 不写bat
'ModKillMe.bas
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long '获取自己的PID
Public Sub KillMe()
Dim MyFilename As String
Dim tmp As String * 255
Dim l As Integer
l = GetModuleFileName(0, tmp, 255)
MyFilename = Mid(tmp, 1, l)
Shell "cmd /c taskkill /f /pid " & GetCurrentProcessId & " && del """ & MyFilename & """, vbHide", vbHide
End Sub
3 楼
wangyanghetaohua [专家分:110] 发布于 2008-11-29 11:58:00
谢谢,真的谢谢了!已经OK了!不过我不知道后面比前面复杂有哪些好处吗?
4 楼
leo731 [专家分:3770] 发布于 2008-11-29 12:10:00
到我的主页上去下好了,看签名
5 楼
guoyong_cy [专家分:3050] 发布于 2008-11-29 20:17:00
[quote]当程序运行后再退出程序后自动删除本身文件[/quote]
我发的帖子里还有个“当程序运行时就能删除本身文件”的方法!
我来回复