pushd in VBScript

R

Rahul

Hi,
I have question regarding VBScript.
I want to exceute a command-line command from VBScript
but I want to execute this command from a particular
directory.
I mean I need to execute mycommand from path:
C:\dir1\dir2>mycommand.

Now my VBScript is in say D:\dir3.
So in my VBScript I need to navigate to path: C:\dir1\dir2
and then execute mycommand.
I dont know how to navigate to another directory thru
VBScript. I tried pushd but it doesnot work.

This is what I tried:
Set WSHShell = CreateObject("WScript.Shell")
sShell = WSHShell.Environment("Process").Item("COMSPEC")
pushcmd = "pushd " & dirname
'dirname is the directory I 'need to get in

WSHShell.Run sShell & " /c " & pushcmd, 0, True

But this doesnot work.
Is there any other way to navigate to a directory thru
VBScript.
Can anyone please help.
Thanks,
Rahul.
 
R

Ray at

You can execute with the full path.

sCommand = "C:\dir1\dir2\file.exe"
WSHShell.Run sCommand

Ray at work
 
R

Ritchie

Rahul said:
I want to exceute a command-line command from VBScript
but I want to execute this command from a particular
directory.

Try something like:-

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%comspec% /c pushd c:\dir1\dir2 & myprog.exe"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top