Self Destruct VBS file. How?

Posted on 2006-03-28
Last Modified: 2013-12-25
Hello Experts,

I fould the following script on the net and it works just fine. What I don't understand is why I can not get to be called as a function from within a Sub. Also I'm curious as to why the word Selfdestruct appears after the End Sub and without it the code does not work. Thanks for any clarification.

Sub SelfDestruct()

Set fs_obj = CreateObject("Scripting.FileSystemObject")
fs_obj.DeleteFile WScript.ScriptFullName
Set fs_obj = Nothing

End Sub

Question by:donniedarko801
    LVL 24

    Accepted Solution

    The last SelfDestruct in the script is calling the Sub SelfDestruct()
    LVL 29

    Expert Comment

    >What I don't understand is why I can not get to be called as a function from within a Sub.

    Because then the function tries to remove the file, it can not since it is locked. The reason it is locked is that the calling procedure is waiting to the result of the Function you are calling.

    hes answered your other question.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now