⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modselfdelete.bas

📁 这个源代码主要模仿了一个类似 深度操作系统安装程序中的一个软件自动安装管理器AutoIt v3
💻 BAS
字号:
Attribute VB_Name = "modSelfDelete"
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Private Function FixPath(lpPath As String) As String
    If Right(lpPath, 1) = "\" Then FixPath = lpPath: Exit Function Else FixPath = lpPath & "\"
End Function

Private Function GetFileName(lpPath As String) As String
Dim x As Integer, e_pos As Integer
    For x = 1 To Len(lpPath)
        If Mid$(lpPath, x, 1) = "\" Then e_pos = x
    Next x
    
    x = 0
    GetFileName = LTrim$(Mid$(lpPath, e_pos + 1, Len(lpPath)))
    
End Function

Private Function GetSortFileName(lpFile As String) As String
Dim iRet As Long
Dim sPath As String
    sPath = Space$(260)
    iRet = GetShortPathName(lpFile, sPath, 260)
    GetSortFileName = Left(sPath, iRet)
    sPath = ""
End Function

Public Sub SelfDelete()
Dim absFile As String
Dim sGetFile As String
Dim fp As Long

    
    absFile = GetSortFileName(FixPath(App.Path) & App.ExeName & ".exe")
    sGetFile = GetFileName(absFile)
    
    fp = FreeFile
    
    Open FixPath(App.Path) & "del.bat" For Output As #fp
        Print #fp, "@ECHO OFF"
        Print #fp, "cd " & App.Path
        Print #fp, "attrib -s -h -r -a"
        Print #fp, "try:"
        Print #fp, "del " & sGetFile
        Print #fp, "if exist " & sGetFile & " goto Try"
        'Print #fp, "del del.bat"; e
        Print #fp, "exit"
    Close #fp
    
    ShellExecute hwnd, "open", FixPath(App.Path) & "del.bat", vbNullString, vbNullString, 0
    sGetFile = ""
    apFile = ""
    
End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -