jack niekerk
asked on
IN VB6 TO FORCE CLOSING A "HANGING" PROGRAM
It happens that a "VB6 program is not properly closed by user, then it will be when I popup taskmanager still in "running tasks" I have to manualy force by clicking few times in taskmanager to get rid off it.
So I wonder would there be a way to do this from VB6 from my startup VB6 program from where I shell to all the other VB6 programs
So I wonder would there be a way to do this from VB6 from my startup VB6 program from where I shell to all the other VB6 programs
Oh, and I should point out that that EndProcess function will not work on programs running from the IDE, only on the executables.
ASKER
ok, what would be the syntax to use this function at the end off my program ( private sub form_unload part)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
ASKER
1 qst, is it possible to find at running time the programname, myProgram1.exe instead off fixed text?
Hmm, the function would need to know how to distinguish between your programs and any others in the process list.
Are the programs you want to unload located in the same folder, where no other programs (which you wouldn't want to close) reside? If so you could use the ExecutablePath property of the winProcess object to check whether found processes should be closed. Try the sub below. (You will need to add a program reference to the "Microsoft Scripting Runtime")
Are the programs you want to unload located in the same folder, where no other programs (which you wouldn't want to close) reside? If so you could use the ExecutablePath property of the winProcess object to check whether found processes should be closed. Try the sub below. (You will need to add a program reference to the "Microsoft Scripting Runtime")
Public Sub EndMyApps()
Const sAppFolder As String = "C:\MyAppFolder"
Dim winProcess, FSO As New FileSystemObject, sExeFolder As String
For Each winProcess In GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_Process")
sExeFolder = FSO.GetParentFolderName("" & winProcess.ExecutablePath)
'Terminate any programs (except this one) running from the app folder'
If sExeFolder = sAppFolder Then
If winProcess.Name <> App.EXEName & ".exe" Then winProcess.Terminate
End If
Next
Set FSO = Nothing
End Sub
ASKER
True , allways in same drive/folder (network), so thanks again
Regards
Regards
Failing that, this code should accomplish what you want:
Open in new window