Reputation: 1890
I have a very simple script, which only prints current directory. That's the code:
set WshShell = WScript.CreateObject("WScript.Shell")
Wscript.Echo (WshShell.CurrentDirectory)
This script is called from .exe
file. It works fine until the calling executable was run directly. If I create a link to exe-file and launch it, then it runs my .vbs
and it prints the directory of link, not the .exe
itself! How can I fix this?
Upvotes: 1
Views: 205
Reputation: 18827
Get help from FileSystemObject, (vbscript example) :
scriptdir=CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
Wscript.Echo scriptdir
Upvotes: 1
Reputation: 1890
OK, maybe it's somehow clumsy, but I've discovered a workable solution. The idea is simple: get full script name and a short one. Then subtract the second from the first.
set WshShell = WScript.CreateObject("WScript.Shell")
Wscript.Echo (Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - Len(WScript.ScriptName)))
Upvotes: 0