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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...