Question on closing processes
Hey. So in my program I have code that will automatically check the task manager to see if any programs with a certain name are open. Is there any way I can also make it so that if it finds a program open, it can call a specific method within that program?
Thanks
John
Re: Question on closing processes
Only if there is some built in method of doing it, which I doubt there is. In order to interact with outside applications, you more than likely will need to use API. What are you trying to do?
Re: Question on closing processes
hmm well I want to close programs, but for some reason when I use the .closeMainWindow() method it doesn't seem to close it -- I'm forced to use .kill(). So I want to call a special method that runs the shutdown commands, then i can kill it...
Re: Question on closing processes
Well CloseMainWindow() will only work if there is a window associated with the application. Would these be services, by chance?
Re: Question on closing processes
CloseMainWindow, should be equivelant to clicking the close button on a form.
However you can use API like this:
VB Code:
'Top of the form below imports etc
Const WM_CLOSE = &H10
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Object) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
'In some event like a button click, post the message like this:
PostMessage(FindWindow(vbNullString, exe.MainWindowTitle.ToString()), WM_CLOSE, 0, 0)
Otherwise you'll need to automate these with virtual keys.
I can help with that too, if you need. :wave: