Peter Gordon
2/5/2009 8:46:00 AM
"Al Dunbar" <alandrub@hotmail.com> wrote in
news:e2S2u60hJHA.4596@TK2MSFTNGP06.phx.gbl:
>
> "Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
> news:OLHFYSmgJHA.3708@TK2MSFTNGP04.phx.gbl...
>>
>> "Peter Gordon" <petergo@netspacedelete.net.au> wrote in message
>> news:Xns9BA3574629C80petergonetspacenetau@216.196.97.142...
>>> The two lines of code below, will open a console window,
>>> run the dir command and then close the window before
>>> the contents can be read. Is there any way to keep the
>>> window open and displaying it's [its] contents?
>>>
>>> The code:
>>> Set aShell = Wscript.CreateObject("Wscript.Shell")
>>> iret = aShell.Run( "dir", 1, TRUE)
>>>
>>>
>>> --
>>> Peter Gordon
>>
>> Unfortunately your code won't run anything because there is no
>> executable called "dir.exe" or "dir.com". "Dir" is an internal
>> Command Processor command, which means that you must launch cmd.exe
>> to run it, as for some other commands such as cd, md, del, copy.
>
> Unless, of course, there is a dir.bat or dir.cmd file...
>
>> Try this code:
>>
>> Set oShell = WScript.CreateObject("Wscript.Shell")
>> iret = oShell.run("cmd.exe /c dir c:\ & pause", 1, True)
>>
>> To prevent the Console process from closing, add the "pause" command.
>
> Another method would be this:
>
> Set oShell = WScript.CreateObject("Wscript.Shell")
> iret = oShell.run("cmd.exe /k dir c:\", 1, True)
>
> this will keep the command window open and usable, allowing the user
> to examine environment variables or what have you before closing the
> window with exit.
>
> /Al
Thanks for the replies, I eventually used the code below
which works well.
Set xxcopyShell = Wscript.CreateObject("Wscript.Shell")
strXXCOPY = "%comspec% /c xxcopy.exe "
strOptions = " /BI /Y /KS /E /R /X*\Tmp\ /Q "
strCmd = strXXCOPY & strOptions & strFiles & " & pause"
' MsgBox strCmd, vbOkOnly, "The Command"
ret = xxcopyShell.Run( strCmd, 1, TRUE)
--
Peter Gordon