VB5: Help with the Shell() command

Is there any good code for shell that can run the other app in the background, hidden (as vbhide method does), waits for it to finish executing, and then closes it?  Right now I'm using vbhide and every time it runs that line I get "winoldap" showing in my task bar...and that reproduces each time the line is run.  Help!
LVL 2
ChrisKAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ajsriramCommented:
Just Call this function to kill any program after it is finished.

If this is not working tell me and i will give one more solution.

Hope the Following code will help you

;->

KillApp ("winoa386.mod")



Public Function KillApp(myName As String) As Boolean
       Const PROCESS_ALL_ACCESS = 0
       Dim uProcess As PROCESSENTRY32
       Dim rProcessFound As Long
       Dim hSnapshot As Long
       Dim szExename As String
       Dim exitCode As Long
       Dim myProcess As Long
       Dim AppKill As Boolean
       Dim appCount As Integer
       Dim i As Integer
       On Local Error GoTo Finish
       appCount = 0
       
       Const TH32CS_SNAPPROCESS As Long = 2&
       
       uProcess.dwSize = Len(uProcess)
       hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
       rProcessFound = ProcessFirst(hSnapshot, uProcess)


       Do While rProcessFound
           i = InStr(1, uProcess.szexeFile, Chr(0))
           szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
           If Right$(szExename, Len(myName)) = LCase$(myName) Then
               KillApp = True
               appCount = appCount + 1
               myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
               AppKill = TerminateProcess(myProcess, exitCode)
               Call CloseHandle(myProcess)
           End If
           rProcessFound = ProcessNext(hSnapshot, uProcess)
       Loop
       Call CloseHandle(hSnapshot)
Finish:
   End Function

0
ChrisKAuthor Commented:
processentry32 isn't defined
0
ajsriramCommented:
Sorry Chrisk,

All the variables are decalred here


Public Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
Public Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long


Public Type PROCESSENTRY32
        dwSize As Long
        cntUsage As Long
        th32ProcessID As Long
        th32DefaultHeapID As Long
        th32ModuleID As Long
        cntThreads As Long
        th32ParentProcessID As Long
        pcPriClassBase As Long
        dwFlags As Long
        szexeFile As String * MAX_PATH
 End Type

Public Function KillApp(myName As String) As Boolean
       Const PROCESS_ALL_ACCESS = 0
       Dim uProcess As PROCESSENTRY32
       Dim rProcessFound As Long
       Dim hSnapshot As Long
       Dim szExename As String
       Dim exitCode As Long
       Dim myProcess As Long
       Dim AppKill As Boolean
       Dim appCount As Integer
       Dim i As Integer
       On Local Error GoTo Finish
       appCount = 0
       
       Const TH32CS_SNAPPROCESS As Long = 2&
       
       uProcess.dwSize = Len(uProcess)
       hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
       rProcessFound = ProcessFirst(hSnapshot, uProcess)


       Do While rProcessFound
           i = InStr(1, uProcess.szexeFile, Chr(0))
           szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
           If Right$(szExename, Len(myName)) = LCase$(myName) Then
               KillApp = True
               appCount = appCount + 1
               myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
               AppKill = TerminateProcess(myProcess, exitCode)
               Call CloseHandle(myProcess)
           End If
           rProcessFound = ProcessNext(hSnapshot, uProcess)
       Loop
       Call CloseHandle(hSnapshot)
Finish:
   End Function

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ChrisKAuthor Commented:
now MAX_PATH has no definition
0
ChrisKAuthor Commented:
"constant expression required"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.