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

Set Start In: Path for WshShell.Run command? 1

Status
Not open for further replies.

mfagala

IS-IT--Management
Jan 19, 2007
2
US
Below is a simple program I use from a CRM application. It works great, except I have one program that is looking for a file in the directory it starts from. Is there a way to specify a "Start in:" directory in this script?

On Error Resume Next
Dim App_Path
App_Path = "C:\MY PROGRAM.EXE"

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run Chr(34) & App_Path & Chr(34)

If Err.Number <> 0 Then
msgbox App_Path & " - This application could not be started or is installed in a different location. Please contact BLAH for help.",16,"Application unable to start."
Err.Clear
End If
 
Perhaps this ?
WshShell.Run "CMD /C CD ""\path\to\start in"" & """ & App_Path & """

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
OOps, sorry for the typo:
WshShell.Run "CMD /C CD ""\path\to\start in"" & """ & App_Path & """"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
> looking for a file in the directory it starts from...
"it starts from", whatever what "it" means, is exposed in the currentdirectory property of wshshell object. It is a read-write property. You can read it. If you want to change it, write to it a new path.
[tt]
wscript.echo wshshell.currentdirectory
'if you need to change it, assign it a new path
wshshell.currentdirectory="d:\abc"
wscript.echo wshshell.currentdirectory
[/tt]
 
I wouldn't try putting words into tsuji's mouth, but perhaps what he's getting at is that the child process inherits the parent's CD:

Parent.vbs
Code:
Option Explicit
Dim objWShell
Dim strCDCache

Set objWShell = WScript.CreateObject("WScript.Shell")
strCDCache = objWShell.CurrentDirectory

'Set CurDir to child process' CurDir.
'Here this is "SubDir" below our CurDir.
objWShell.CurrentDirectory = strCDCache & "\SubDir"
objWShell.Run "WScript Child.vbs", 1, False

'Restore CurDir if need be.
objWShell.CurrentDirectory = strCDCache
MsgBox objWShell.CurrentDirectory, vbOkOnly, "Parent CurDir"
\SubDir\Child.vbs
Code:
Option Explicit
Dim objWShell
Dim strCD

Set objWShell = CreateObject("WScript.Shell")
MsgBox objWShell.CurrentDirectory, vbOkOnly, "Child CurDir"

This is lighter weight than starting an extra CMD shell process and console to host your program's process if it doesn't require their services.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top