Link to home
Start Free TrialLog in
Avatar of ChrisK
ChrisKFlag for United States of America

asked on

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!
Avatar of ajsriram
ajsriram

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

Avatar of ChrisK

ASKER

processentry32 isn't defined
ASKER CERTIFIED SOLUTION
Avatar of ajsriram
ajsriram

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ChrisK

ASKER

now MAX_PATH has no definition
Avatar of ChrisK

ASKER

"constant expression required"