Getting the Script’s Path with WSH
WSH has no function or method for retrieving a script’s path, so in VBScript you can use the ScriptFullName property of the WScript object to extract the path, as shown here:
Function GetPath
' Retrieve path to the script file.
Dim path
path = WScript.ScriptFullName ' Script filename
GetPath = Left(path, InStrRev(path, "\"))
End Function
This function assumes that the path ends with a backslash character. But as long as Microsoft implements GetParentFolderName correctly, you get the path more portably with:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Path = fso.GetParentFolderName(WScript.ScriptFullName)
From Windows Script Host 2.0 Developer’s Guide by Gunter Born.
0 Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URI