VBScript -- Refer To Self In Program

vbscript

Solution

`WScript.ScriptFullName` gives you the full path to your running script. You can use the `FileSystemObject` to parse this path further, if you'd like. For example:

' Assuming the script is at c:\scripts\test.vbs
strFile = WScript.ScriptFullName

With CreateObject("Scripting.FileSystemObject")
    MsgBox .GetDriveName(strFile)           ' => c:
    MsgBox .GetParentFolderName(strFile)    ' => c:\scripts
    MsgBox .GetFileName(strFile)            ' => test.vbs
    MsgBox .GetBaseName(strFile)            ' => test
    MsgBox .GetExtensionName(strFile)       ' => vbs    
End With

Problem

Is there a way to refer to the current file running in VBScript? I could just use the name of the file, but it needs to be operable despite directory changes and renames. The purpose of this is to use the file in a file I/O operation. If not possible, are there any potential alternatives, such as making a file non-re-namable, or non-movable?

Original source