Vbscript does not include a variable populated with the current directory in which the script is called. They do however include two other variables that give us the ability to dynamically grab this string:
Wscript.ScriptFullName = Full Path and Name of script ( ie. c:\Folder\SubFolder\Script.vbs )
Wscript.ScriptName = Name of Script ( ie. Script.vbs )
Using the Len built-in function, we can cut the name from the end of the “ScriptFullName” script to acheive our goal:
scriptPath = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) – Len(WScript.ScriptName))
Note: Output includes “\” after folder name ( ie. c:\Folder\SubFolder\ )
In MDT ( Microsoft Deployment Toolkit ), the ZTIUTility.vbs script includes this functionality. As long as you include this script in your custom .WSF, then you can use the “sScriptDir” variable. That is populated via the “FileSystemObject”.
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
sScriptDir = oFSO.GetParentFolderName(WScript.ScriptFullName)