View Full Version : Set current directory when using run method
Hi!
Is there a way to set the current directory (working directory) when using the run method.
Like when you create a shortcut you can set the working directory.
I donīt want the current dir to be the dir the script is executed from.
/Jii
adamdelves
01-11-2002, 08:28 AM
Yes- use
wscript.scriptfullname
this returns the full path of the scripts location. With a bit of manipulation you can also get its working directory.
path = wscript.scriptFullName
dir = Left(path, InstrRev(path, "\") )
Hi!
Thatīs not really what I mean, I wanna change the current directory.
/Jii
darkness
01-14-2002, 09:08 PM
Yup you set it on the wshell object in before executing the command. Here is the code from the windows 5.6 docs doing roughly the same thing.
WshShell object.
Remarks
The CurrentDirectory returns a string that contains the fully qualified path of the current working directory of the active process.
Example
The following code displays the current active directory.
[VBScript]
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo WshShell.CurrentDirectory
You should be able to change it to another path if you choose: Sample code below.
set wshshell = wscript.createobject("wscript.shell")
wscript.echo wshshell.currentdirectory
wshshell.currentdirectory = "c:\"
wscript.echo wshshell.currentdirectory
Michael McLaughlin/images/forums/icons/smile.gif
Systems Manager
Minnesota State University Mankato
Hi!
Thanx alot, that was exactly what I was looking for.
/Jii
Powered by vBulletin™ Version 4.1.0 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.