Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How can I get the Name of a .vbs Script from within the Script

$
0
0

Hello,

I am trying to get the name of a .vbs Script that is included in a .wsf Script.

I have tried WScript.ScriptName and WScript.ScriptFullName both return info of the .wsh Script

I would like to get the Name of the .Include\FileSystemObject.vbs without knowing it.

If I already know it I can hard-code it.

I have two Script Files:

Testing.wsf

---------------

<job id = "Testing.wsf">
    <script language = "VBScript" Src = ".Testing\FileSystemObject.vbs"/>
</job>

And:

.Testing\FileSystemObject.wsf

--------------------------------------

Option Explicit
'///////////////////////////////////////////////////////////////////////////////
Dim FSO
'///////////////////////////////////////////////////////////////////////////////
Sub Initialize()
'---------------
    Set FSO = CreateObject("Scripting.FileSystemObject")
End Sub
'///////////////////////////////////////////////////////////////////////////////
Sub GetAbsolutePathName()
'------------------------
Dim AbsolutePathName
    AbsolutePathName = FSO.GetAbsolutePathName(".")
    MsgBox AbsolutePathName & Space(100),,"GetAbsolutePathName"
    'This returns the PathName of the .wsf Script
    'probably because this file is an include
End Sub
'///////////////////////////////////////////////////////////////////////////////
Sub GetFile()
'------------
Dim File
    'Set File = FSO.GetFile(filespec)
    'The argument in examples and documentation is always filespec,
    'but nobody explains filespec

    'Trying to get file info on the this file without knowing the name of it
    'Set File = FSO.GetFile()          'Wrong Number of Arguments
    'Set File = FSO.GetFile("")        'Invalid Procedure Call or Argument
    'Set File = FSO.GetFile(".")       'File Not Found
    Set File = FSO.GetFile("C:\RRRSystems\Software\Script\.Testing\FileSystemObject.vbs")
    'This works, but I want it for this file whatever its name or location is
    'even if I rename, move or use it in another Script

    MsgBox File.Name & Space(100),,"GetFile"
    MsgBox File.Path & Space(100),,"GetFile"
End Sub
'///////////////////////////////////////////////////////////////////////////////
Sub TryWScript()
'---------------
    MsgBox WScript.ScriptName,,"TryWScript"
    'This returns the name of the Testing.wfs
    'Perhaps because this file is included in Testing.wsf
End Sub
'///////////////////////////////////////////////////////////////////////////////
Initialize
TryWScript
GetAbsolutePathName
GetFile
'///////////////////////////////////////////////////////////////////////////////

Any Ideas?

Thanks,

Raney


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>