How to know if an app is launched in windows service application.

I'm trying to write a program which waits for a specific app (matlab in my case) to launch and does stuff when the app launches.

I see that I had to write a windows service application and managed get this working. I can see the service in Service Manager and can start-stop it. But I don't know how can "listen" or understand if Matlab (or any other app.) is launched. I'm kinda newbie when it comes to Windows Programming. Can you help me in this?

I'm using c++ with visual studio 2013.

https://www.oursainsburys.biz/
Last edited on
You didn't need to write a service to do this.

Your code will basically look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
bool is_program_running(const wchar_t *name){
    //iterate over running processes looking for one with the specified name
}

int main(){
    while (true){
        if (!is_program_running(L"matlab.exe")){
            Sleep(1000);
            continue;
        }
        //do something with the process
    }
}


These are the functions you'll need:
https://docs.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot
https://docs.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-process32first
https://docs.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-process32next
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-queryfullprocessimagenamew
Registered users can post here. Sign in or register to post.