sure,
create a batch file (foo.bat)
and use the SHELL command
varResult = Shell("foo.bat"
The Shell command will pick the "right" process on the basis of extension (from same table as Explorer uses) and thus you can use this to launch Word, Excel, ....
The Shell command DOES NOT guarentee that the application so launched is done when it returns....to handle this you need dig a little deeper.
Right on DsB! God, and I've been using the Shell command for launching applications for ages too... talk about right under your nose! Thanks!
LeGo PiEcE
"The Computer Spock! Destroy it!" - Captain James T. Kirk
Using the shell command is the way to go. It took me a couple of days of banging my head off of my desk to think of this. To make VB wait until the shell command is finished try this:
Dim iTask As Long, ret As Long, pHandle As Long
iTask = Shell(batch_file_name_here, vbNormalFocus)
pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
ret = WaitForSingleObject(pHandle, INFINITE)
ret = CloseHandle(pHandle)
It worked for me. Just remember to set the property of the DOS window to close on exit from the batch file otherwise the window will stay open and in the middle of your screen until you close it manually.
In my typical dunder-headed way, I left out something you will need to make VB wait for the shell command to finish.
Add this in (and forgive my stupidity):
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
ok, for your wait-on-the-shell-started-process-to-finish solution....which provided a lot of useful api's and use thereof. guess calling this a waiting-game was too glib.
There's another way of doing this, if you have the Windows Script Host installed on your machine (which you will if you are running 98 or W2K). Set a reference to the Windows script Host Object Model and create a new instance of the WSHShell class the code:
Dim objShell As New WshShell
objShell.Run "notepad.exe", , True [\b]
will shell an instance of notepad and [\b] wait until it has finished running. The missing second parameter allow you to specify a window style: maximised, minimized, hidden etc. Very easy, and not an API call in sight!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.