Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does VBScript / WSH Have a "self" property? 2

Status
Not open for further replies.

djhawthorn

Technical User
Mar 4, 2002
641
AU
Does VBScript / WSH have a "self" property - ala, an object that tells you the path to the script?

Or is there any easy way to obtain this information (without hard-coding a path).

[auto] MCSE NT4/W2K
 
Hello dhawthorn,

Pick the appropriate & parse with instr or instrrev etc.
Code:
wscript.echo wscript.scriptfullname
wscript.echo wscript.scriptname
wscript.echo createobject("wscript.shell").currentdirectory
regards - tsuji
 
Thanks heaps, exactly what I was looking for.

[auto] MCSE NT4/W2K
 
I'm trying to find a way to call an executable from
vbscript without having to do any hard-coding of pathnames.
In order to do this, I need to be able call an executable
located in the same folder as the script.

Is there a way to return the path of the script that is
calling the executable, so that I can eliminate all
hard-coding ?
 
You should start a new thread for this rather than posting in an existing one.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Yes, I created a function a long time ago that does this more me. Here it is...

'This function returns the path from which the script was called
Function ScriptPath
ScriptPath=Left(Wscript.scriptfullname,Instr(1,WScript.ScriptFullName,wscript.scriptname,1)-1)
End Function
 
AbsPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
And what about the fso.GetParentFolderName method ?
What happens with your methods when a subdirectory is the same as the script name ?
 
Use InStrRev() instead.

But you make an excellent point PHV, why reinvent the wheel?
 
Thanks tom, i was working on something and i needed that saved me haveing to look it up.
The boss will be well pleased with me, a star and a get out of jail free card for tom


if it is to be it's up to me
 
PHV is correct, if you expect to ever have a situation where there is a folder name anywhere in the path that is the same as the script name, then my solution won't work. I can use it because of a no '.' in folder names policy at my work.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top