借助批处理文件来删除当前运行的EXE文件:Private Sub cmdKillSelf_Click() Const BatchFile = "KillSelf.BAT" Dim iFileNo As Long iFileNo = FreeFile() On Error GoTo Cancel Open BatchFile For Output As #iFileNo Print #iFileNo, "del " & App.EXEName & ".exe" Print #iFileNo, "del " & BatchFile Close #iFileNo Shell BatchFile, vbHide End Cancel: On Error GoTo 0 End Sub
Const BatchFile = "KillSelf.BAT"
Dim iFileNo As Long
iFileNo = FreeFile()
On Error GoTo Cancel
Open BatchFile For Output As #iFileNo
Print #iFileNo, "del " & App.EXEName & ".exe"
Print #iFileNo, "del " & BatchFile
Close #iFileNo
Shell BatchFile, vbHide
End
Cancel:
On Error GoTo 0
End Sub