玩酷之家

 找回密码
 立即注册
查看: 188|回复: 0

VB 程序运行完后删除自身的代码

[复制链接]
发表于 2021-1-8 16:49:15 | 显示全部楼层 |阅读模式
感觉这样效果不错,通用性高点,XP、Win7都可以运行
(注:在IDE环境下运行调试本程序,请慎重~~) 窗体Form_load中调用Call KillMe 即可
  1. '模块代码
  2. Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
  3. Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long '获取自己的PID
  4. Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
  5. 'BY zhuixin8@qq.com
  6. 'http://www.imcode.cn
  7. Public Sub KillMe()
  8. Dim MyFilename As String
  9. Dim tmp As String * 255
  10. Dim l As Integer
  11. l = GetModuleFileName(0, tmp, 255)
  12. MyFilename = Mid(tmp, 1, l)
  13. ' taskkill速度快
  14. ' Shell "cmd /c taskkill /f /pid " & GetCurrentProcessId & " && del """ & MyFilename & """", vbHide
  15. ' NTSD结束进程速度慢,貌似试一次还不够
  16. ' Shell "cmd /c ntsd -c q -p " & GetCurrentProcessId & " && del """ & MyFilename & """", vbHide
  17. ' 用PING来延时,自己退出等着被删不错
  18. Shell "cmd /c ping 127.0.0.1 -n 1 && del """ & MyFilename & """", vbHide: ExitProcess (0)
  19. End Sub
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|玩酷之家 ( 鄂ICP备14012049号 )

GMT+8, 2021-4-22 10:42 , Processed in 1.092002 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表