Running a file from a .VBS script 
Author Message
 Running a file from a .VBS script

I couldn't find the best newsgroup to post this question
in, so sorry if this is off-topic....

What I'd like to do is to have a command in a .VBS script
run a file (similiar to if I went to Start-Run, typed the
file name, and hit enter)

For example, I'd like to have the .VBS file run
C:\docs\agenda.doc (which would fire up microsoft word
with this document open).

Any ideas?  Thanks.
-Clark



Mon, 25 Jul 2005 00:16:55 GMT  
 Running a file from a .VBS script
You can use the Run method of Windows Scripting Host's Shell class.  An
example follows.  Notice the Chr(34) functions surrounding the file name to
add double-quotes around the file name in case the file name contains
spaces.

On Error Resume Next
Dim objWSH

Set objWSH = CreateObject("WScript.Shell")
objWSH.Run Chr(34) & "C:\Documents and Settings\eric\My Documents\doc1.doc"
& Chr(34)

If Err.number <> 0 Then
 msgbox "Problem: " & Err.Description
Else
 msgbox "All good"
End IF

Set objWSH = Nothing


MCSD, Brainbench MVP for Visual Basic
http://www.brainbench.com

Quote:
> I couldn't find the best newsgroup to post this question
> in, so sorry if this is off-topic....

> What I'd like to do is to have a command in a .VBS script
> run a file (similiar to if I went to Start-Run, typed the
> file name, and hit enter)

> For example, I'd like to have the .VBS file run
> C:\docs\agenda.doc (which would fire up microsoft word
> with this document open).

> Any ideas?  Thanks.
> -Clark



Tue, 26 Jul 2005 13:01:34 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Running a .vbs script from within a .vbs script

2. Calling *.vbs files to Run From Master VBS File

3. Calling / Running Multiple VBS scripts from one file

4. vbs Timer script to run other script

5. Running ASP Script as .VBS

6. Cant Run VBS Scripts

7. setting a vbs script to run under cscript

8. VBS script not running

9. Problem running VBS from script shell

10. Getting Local IP address running a VBS script locally

11. Error 101 trying to run vbs script

12. VBS Scripts won't run, bad association?

 

 
Powered by phpBB® Forum Software