Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Help: is it possible to launch acommand prompt shell and have commands piped into it?

Hi folks,

Is anybody able to tell me if and how it is possible to have vb open a
command prompt and have commands or text i specify piped into it to carry
out some tasks?

Help is appreciated.

Thank you in advance.

Clint


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default is it possible to launch acommand prompt shell and have commands piped into it?

Try this code:


Option Explicit
Private Const NORMAL_PRIORITY_CLASS = 32
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadId As Long
End Type

Private Declare Function WaitForSingleObject _
Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As
Long

Private Declare Function CreateProcessA _
Lib "kernel32" (ByVal lpApplicationName As String,
_
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long,
_
ByVal lpThreadAttributes As Long,
_
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As
String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As
PROCESS_INFORMATION) As Long

Private Declare Function GetExitCodeProcess _
Lib "kernel32" (ByVal hProcess As Long, _
lpExitCode As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Function ExecCmd(sCmdLine As String, lmSecsWait As Long) As Long

'will start an external process and
'wait till this process is finished
'returns -1 if successfull and -1 if not
'-----------------------------------------
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim lReturn As Long

'Initialize the STARTUPINFO structu
With Start
.cb = Len(Start)
.dwFlags = 1 'hexadecimal would be &H1
'.wShowWindow = 0
End With

'Start the shelled application:
lReturn = CreateProcessA(sCmdLine, _
vbNullString, _
0, _
0, _
1, _
NORMAL_PRIORITY_CLASS, _
0, _
vbNullString, _
Start, _
proc)

'Wait for the shelled application to finish:
'6 seconds is enough here
lReturn = WaitForSingleObject(proc.hProcess, lmSecsWait)
GetExitCodeProcess proc.hProcess, lReturn
CloseHandle proc.hThread
CloseHandle proc.hProcess
ExecCmd = lReturn

End Function



sCmdLine can be the path of a .bat file.


RBS



"Clinton M James" wrote in message
...
Hi folks,

Is anybody able to tell me if and how it is possible to have vb open a
command prompt and have commands or text i specify piped into it to carry
out some tasks?

Help is appreciated.

Thank you in advance.

Clint


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Help: is it possible to launch acommand prompt shell and have commands piped into it?

I needed to do this recently and ended up creating a .cmd or .bat
file, which contained
the actions I needed then getting excel to open and run that.

Think I had about 4 scenarios (based on excel user input variations)
so just wrote a .cmd for
each scenario and it worked fine.

It was simpler than trying to get excel to "drive" the .cmd session,
though I am certain that
ppl here would be able to get that to work it was beyond me!

Rgds,

Stuart


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sequential Shell commands? steve66 Excel Programming 3 May 23rd 05 11:14 PM
running commands from hte shell Ruthless Dog Excel Programming 4 May 17th 05 02:38 PM
shell commands K Dales[_2_] Excel Programming 0 January 19th 05 09:21 PM
Simple Shell Commands cogent Excel Programming 4 June 8th 04 10:09 PM
Commands at the line prompt using Shell cogent Excel Programming 2 April 27th 04 04:56 AM


All times are GMT +1. The time now is 03:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"