Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if App is running on network PC

Tags:

c#

I have a C# app application working to some extent. What i need to do is to continue execution if a computer (given an IP Address) is running an application (TEKBSS.exe). How can i do that? Can someone help me?

like image 843
Privesh Avatar asked Jan 20 '23 02:01

Privesh


1 Answers

You can do this through WMI. You'll need appropriate credentials to access the remote machine.

The System.Management namespace includes features for using WMI from C#.

Here you go:

        // Don't forget...
        // using System.Management; <-- Need to add a reference to System.Management, too.

        ManagementScope scope = new ManagementScope(@"\\192.168.1.73\root\cimv2");
        string query = "SELECT * FROM Win32_Process WHERE Name='TEKBSS.exe'";
        var searcher = new ManagementObjectSearcher(query);
        searcher.Scope = scope;
        bool isRunning = searcher.Get().Count > 0;

The scope tells WMI what machine to execute the query on, so don't forget to change the IP address accordingly.

The ManagementObjectSearcher will then query the machine for a list of all processes with the name TEKBSS.exe.

like image 99
Steve Morgan Avatar answered Jan 29 '23 07:01

Steve Morgan