This question already has answers here:
How do I get process name of an open port in C#?
(4 answers)
Closed 9 months ago.
I need a way of, given a tcp port number, discover if there's some process using that port (and get the process id).
Something like netstat does but programmatically.
This is probably too late for the original poster but someone else may find it useful. You can use the PowerShell class in the System.Management.Automation namespace.
private static IEnumerable<uint> ProcessesUsingPorts(uint id)
{
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-NetTCPConnection").AddParameter("LocalPort", id);
return ps.Invoke().Select(p => (uint)p.Properties["OwningProcess"].Value);
}
Related
This question already has answers here:
Check if a specific exe file is running
(8 answers)
Closed 5 years ago.
Is there a way to check (using C#) whether there is an instance of an EXE that is refered to by path running? If so, please provide the method of doing so. Thank you in advance.
Example: Is there a way to find out if "C:\foo\bar.exe" has a running instance, by refering to the EXE as "C:\foo\bar.exe"?
Do you want something like that;
public List<Process> GetProcessesByFileName(string fileName)
{
return Process.GetProcesses().Where(x => x.MainModule.FileName == fileName).ToList();
}
This question already has answers here:
How to perform "nslookup host server"
(4 answers)
Closed 9 years ago.
In my application, I should get the domain names of the few IP Addresses I give as Input. I guess this process is called NSLOOKUP. However, I would like to confirm if I'm right. Simple program to implement this and display a MessageBox output is what I look for.
Contributions please...
Thank you in anticipation
IPAddress address = IPAddress.Parse("127.0.0.1");
IPHostEntry entry = Dns.GetHostEntry(address );
Console.WriteLine(entry.HostName);
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
C# Telnet Library
I wish to do telnet programatically using C# so that once I establish the connection to the server, I can execute the commands like ls, ls -l, mv, rm.. etc on the server.
Is it possible? Are there classes in C# for this purpose similar to the classes for FTP (FtpWebRequest)? If yes, please direct me to the right approach.
When I execute ls, I need the list generated on server to be sent to the client i.e. windows machine in my case.
Yes, here you have a telnet library
http://www.codeproject.com/KB/IP/MinimalisticTelnet.aspx
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Faking an RS232 Serial Port
I have an application that reads data from serial port. To test the application i would like to create a virtual serial port that generates data and puts the the port at the same PC, so that the other app can access that data.
Any idea how?
Thanks
I have used com0com tool for this. It has no direct API, but you can write an application (or a method) which starts a new com0com process to set up / modify your virtual ports "on the fly" with commandline parameters.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Prevent multiple instances of a given app in .NET?
How can I enforce a single instance of my application?
I have a source then complie to App.exe file. I want if App.exe is running, then a person open it again, it know that it is running and close automaticly. Is there any way to do this?
**Edit: I want a code that insert to source of App.exe
Window Form**
You want to use a Mutex, like so:
bool bIsSingleInstance;
using (new Mutex(true, Assembly.GetExecutingAssembly().GetName().Name, out bIsSingleInstance)) {
if (bIsSingleInstance) {
// START APP HERE.
}
}
Note that you must NOT use 'using' if your winforms isn't blocking in the comment block.