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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I change the current directory in VBScript?

Status
Not open for further replies.

rabbs06

Programmer
Jun 24, 2002
1
AU
Hi,

I am running an application through my script, the application relies on other libraries/databases that are in it's local path. I need to change the current path so that the application i am calling can find these Libraries/Databases. How can i change the current path? Using the application's full path doesn't work.


Thanks.
 
This may help:
You can use the Windows Scripting Host object model to modify the environment variables. For more info you may want to search microsofts web site for Windows Scripting Host

(you can start here:

)

Also, here is a sample of a script that I used (If you update a System Variable, like this script does, than you will need to be logged in as an Admin. However, you should be able to create temporary environment variables that are for a specific process, in which case you would not need to be logged in as admin.) Check out Microsofts site for more info....

Option Explicit

Dim WshShell
Dim WshEnvVar
Dim sOrigPath

'Create the windows shell object
Set WshShell = wscript.createObject("wscript.shell")

'Create the windows environment object and have it
'return the System Environment Variable collection.
Set WshEnvVar = WshShell.Environment("SYSTEM")

'** Update the PATH Variable **
'Save the original path
sOrigPath = WshEnvVar("PATH")

'Assign the new path
WshEnvVar("PATH") = "\\Server\Share\Dir1\Dir2\DLL;" & sOrigPath

'** Create new environment variables **
WshEnvVar("Test1") = "\\Server\Share\Dir1\Dir2\.COK"
WshEnvVar("Test2") = "\\Server\Share\Dir1\Dir2\.IZP"

WshShell.Popup "All Variables Successfully Registered.", 5, "Environment Variable Registration", 0

Set WshEnvVar = Nothing
Set WshShell = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top