Jump to content

Get the Name and Path of a .vbs script from within the script


Recommended Posts



I have a similar post in this forum, I may have asked my question incorrectly.


I have a file "C:RRRSystemsScriptIncludeClass.Script.vbs."


how can I get this file name from a Subroutine within the script itself.


The file is an Include in a file "C:RRRSystemsScriptX-Testing.wsf"


<job id = "X-Testing.wsf"> <script language = "VBScript" Src = ".Include/Class.Script.vbs"/></job>


If I use WScript.ScriptName or WScript.ScriptFullName

in the file "C:RRRSystemsScriptIncludeClass.Script.vbs." it returns the name of the .wsf



Perhaps because it is an included file.


Any Ideas?






Link to comment
Share on other sites

This seems to be the way to go, But I need to enter the file name to get the file name


Sub ShowFileInfo() Dim FSO, F Set fso = CreateObject("Scripting.FileSystemObject") 'Set F = FSO.GetFile() 'Wrong Number of Arguments 'Set F = FSO.GetFile("") 'Invalid Procedure Call or Argument 'Set F = FSO.GetFile(".") 'File Not Found 'Argument in examples is always filespec, but nobody explains filespec Set F = FSO.GetFile("C:RRRSystemsSoftwareScript.IncludeClass.Script.vbs") 'This works but I want it for the current file whatever that may be 'even if I rename, move it or use the class in another Script MsgBox F.Name 'MsgBox = F.Path 'MsgBox = F.ShortName 'MsgBox = F.ShortPath 'MsgBox = F.DateCreated 'MsgBox = F.DateLastAccessed 'MsgBox = F.DateLastModifiedEnd Sub



Link to comment
Share on other sites

I know what you're looking for, and I am suggesting that Microsoft did not make that possible to do programmatically. PHP, for example, has a "magic constant" called __FILE__ which holds the absolute path to the file that contains the constant, regardless of how it was included or executed (there are other ways to get things like the name of the file that was requested, which file included the current file, etc). I don't think that anyone bothered to create something similar in VBScript. The best you have is WScript.ScriptFullName.


Here is the reference for the WScript object:




If you scroll down to properties and methods, you can see that it is fairly limited.


Maybe you can set a variable in the file that includes the other one to say which file is about to be included, and then check that variable in the included file. I haven't done a lot of work with VB in general so I'm sure what all of your options are.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...