how can i run a command line from a vbs file

Re: run files by Steven

Steven
Wed Mar 15 13:40:24 CST 2006

Use Shell()

http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_programming/objectmap.asp
http://www.windowsitpro.com/WindowsScripting/Article/ArticleID/15646/15646.html

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Guillermo" <guilles@hotmail.com> wrote in message
news:OfYTh1FSGHA.5908@TK2MSFTNGP10.phx.gbl...
> how can i run a command line from a vbs file
>
>



Re: run files by Fosco

Fosco
Wed Mar 15 21:07:25 CST 2006

"Guillermo"
> how can i run a command line from a vbs file

'1
set oShell = CreateObject("WScript.Shell")
oShell.run"notepad.exe c:\test.txt"


'2
set oShell = CreateObject("WScript.Shell")
Return = oShell.Run("%comspec% /c dir>c:\report.txt", 1, True)
Msgbox return
oShell.Run"c:\report.txt"

--
Fosco



Re: run files by Fosco

Fosco
Wed Mar 15 21:19:18 CST 2006

"Fosco" <fake@fake.invalid>
> "Guillermo"
> > how can i run a command line from a vbs file

> set oShell = CreateObject("WScript.Shell")
> oShell.run"notepad.exe c:\test.txt"

Is the same as :

start run
notepad.exe c:\test.txt
(ENTER)

but with some optional parameter :

set oShell = CreateObject("WScript.Shell")
oShell.run"notepad.exe c:\test.txt" ,3, true


object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])
Arguments
object
WshShell object.
strCommand
String value indicating the command line you want to run. You must include any parameters you want to pass to the
executable file.
intWindowStyle
Optional. Integer value indicating the appearance of the program's window. Note that not all programs make use of this
information.
bWaitOnReturn
Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing
to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns
any error code returned by the program. If set to false (the default), the Run method returns immediately after starting
the program, automatically returning 0 (not to be interpreted as an error code).


Example 2
The following VBScript code opens a command window, changes to the path to C:\ , and executes the DIR command.

Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd /K CD C:\ & Dir"
Set oShell = Nothing

--
Fosco