Check if the application is running on a networked computer

I have a C # application application working to some extent. I need to continue execution if the computer (taking into account the IP address) starts the application (TEKBSS.exe). How can i do this? Can anybody help me?

+4
source share
4 answers

Take a look:

System.Diagnostics.Process Process p = new Process(); p.StartInfo.FileName = "TEKBSS.exe"; p.StartInfo.CreateNoWindow = true; p.Start(); p.WaitForExit(); 

EDIT:

 using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime; using System.Runtime.CompilerServices; using System.Security; public class MainClass { public static void Main() { Process[] allProcs = Process.GetProcesses("RemoteMachineOnYourNetwork"); foreach (Process p in allProcs) Console.WriteLine(" -> {0} - {1}", p.ProcessName, p.PeakWorkingSet64); } } 
-1
source

You can do this through WMI . To access the remote computer, you will need the appropriate credentials.

The System.Management namespace has functions for using WMI with 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 area tells WMI which machine the request will be executed on, so be sure to change the IP address accordingly.

Then ManagementObjectSearcher will query the machine for a list of all processes named TEKBSS.exe.

+6
source

You can use WMI to request information on remote computers, for example, which programs are running.

You will need to reference System.Management.dll and have the appropriate rights on the remote computer to access WMI.

 using System; using System.Linq; using System.Management; namespace Bling { public static void Main() { const string Host = "vmhost01"; const string Path = (@"\\" + Host + @"\root\CIMV2"); const string Exe = "TEKBSS.exe"; var queryString = string.Format("SELECT Name FROM Win32_Process WHERE Name = '{0}'", Exe); var query = new SelectQuery(queryString); var options = new ConnectionOptions(); options.Username = "Administrator"; options.Password = "*"; var scope = new ManagementScope(Path, options); var searcher = new ManagementObjectSearcher(scope, query); bool isRunnning = searcher.Get().Count > 0; Console.WriteLine("Is {0} running = {1}.", Exe, isRunnning); } } 
+3
source

I know this is .net code. But I used it a while ago to do the same. Hope this will give you an idea and I will try to convert. As long as you have the rights to the right, you can execute the pushd command in your code. First you can try to run from the command line to make sure you can log in.

Pushd

 //pushes into the Given Machine on the C:\ and filters for your program Dim sCommand as String = "pushd \\<MachineName>\C$ && tasklist.exe /FI ""IMAGENAME eq <NameOfExecutable>.exe"" //execute command from program Shell("cmd.exe /c" & sCommand. AppWinStyle.Hide, True); 

Most likely, you will want to popd after returning to the directory on your computer.

Let me see if I can convert to C for you. I will edit a little.

EDIT

Link to command execution in C #

0
source

All Articles