VB程序,编译成exe文件,这个exe文件在运行过程中如何能删除自身。即当软件30天试用期过后,让它自行消灭,从客户的硬盘中删除。

解决方案 »

  1.   

    借助批处理文件来删除当前运行的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