VBScript - Self Deleting Script

Date Submitted Mon. Oct. 9th, 2006 2:22 AM
Revision 1 of 1
Helper TimboTheGreat
Tags "self deleting" | VBSCRIPT
Comments 1 comments
This script demonstrates the use of a function that allows a script to delete itself from disk. The function can be called from anywhere within the script and the script will continue to function normally (assuming the script does not further attempt to access itself on disk). Handy for homebrew uninstallation programs that require the removal of all installation files, including the setup file.

Option Explicit

MsgBox "Before the self delete", vbInformation, "Self Deleting Script"
'Delete the script
MsgBox "After the self delete", vbInformation, "Self Deleting Script"

Sub DeleteSelf()       
        Dim objFSO
Create a File System Object
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        'Delete the currently executing script
        objFSO.DeleteFile WScript.ScriptFullName
        Set objFSO = Nothing
End Sub

Tim M


Comments This don't work
Thu. Feb. 22nd, 2007 4:11 PM    Newbie sv