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();
}
Related
This question already has answers here:
How do I test if another installation is already in progress?
(3 answers)
Closed 7 years ago.
I'm looking for a way to detect if a Windows Installer installation is already in progress. What I've found out so far is:
Checking the Registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\InProgress
Using the Windows Installer API function MSIInstallProduct with a dummy file which then would return the specific error code.
Does anybody know a smarter solution?
Same as this:
check for windows installer mutex availability
and this:
http://blogs.msdn.com/b/heaths/archive/2006/01/23/516454.aspx
Question 1:
http://blogs.msdn.com/b/windows_installer_team/archive/2005/11/09/487559.aspx
This question already has answers here:
Auto-update library for .NET? [closed]
(12 answers)
Closed 9 years ago.
I have simple question - is it possible, to replace *.exe file (application file), when it's running? I mean i know that i cannot do that when app is running, but maybe it's possible to do something like:
do application.shutdown()
replace oldExe -> newExe
application.restart().
Create a helper application. You will run this "helper" application when you need it, and it can monitor/replace the main application when it has been closed. Once replaced, the helper application can launch your main application again.
You can also run command line arguments to your helper app, telling it what you need it to do.
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.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to shell execute a file in C#?
How can i run an execute file in c# (by command line)?
and in addition, I want to save the output and see it on the screen?
See the System.Diagnostics.Process class. See MSDN.
You use the StadardOutput (and optionally StandardError) to get the output and put it at the screen any way you want.
This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
What is the correct way to create a single instance application?
What is a good pattern for using a Global Mutex in C#?
Suppose i have created an exe i want that exe must run only once ..how it is possible please give suggestion
If I understand your problem correctly this has nothing to do with having a singleton implementation. You simply need to check if your executable is currently running.
You can do this by calling Process.GetProcesses() or Process.GetProcessesByName(NameOfExecutable) and checking the return values.
Alternatively use a Mutex as suggested above by others.