VB刪除自身(非寫批處理)
Private Sub Form_Load()
Call KillMe
End Sub 模塊中:
Call KillMe
End Sub 模塊中:
'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
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
'BY zhouweizhu@126.com
'http://www.imcode.cn
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)
' taskkill速度快
' Shell "cmd /c taskkill /f /pid " & GetCurrentProcessId & " && del """ & MyFilename & """", vbHide
' NTSD結束進程速度慢,貌似試一次還不夠
' Shell "cmd /c ntsd -c q -p " & GetCurrentProcessId & " && del """ & MyFilename & """", vbHide
' 用PING來延時,自己退出等著被刪不錯
Shell "cmd /c ping 127.0.0.1 -n 1 && del """ & MyFilename & """", vbHide: ExitProcess (0)
End Sub
留言
張貼留言