Link to home
Start Free TrialLog in
Avatar of donniedarko801
donniedarko801

asked on

Self Destruct VBS file. How?

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

SelfDestruct
ASKER CERTIFIED SOLUTION
Avatar of hes
hes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>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.

Leon