473,655 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Force one copy of Application

Hi,

I saw that someone asked that question here before, and i tried one of the
answer that was gaven (Bob's tricks and tiips), The suggestion there was
using the ImoprtDll and tried to import the user32.dll, when i tried to
import it to the refernces, the Visual Studio crashed.

So how can i force one copy of application (i'll be happy and thankful to
get an example).

Thanks,
Gidi.
Nov 17 '05 #1
2 1435
One simple way to do it is to list the running processes on the system and
see if another instance of the same name, running from the same location
exists, with a different process id exists.

Process current = Process.GetCurr entProcess();
Process[] processes = Process.GetProc essesByName
(current.Proces sName);

//Loop through the running processes in with the same name
foreach (Process process in processes)
{
//Ignore the current process
if (process.Id != current.Id)
{
//Make sure that the process is running from the exe file.
if (Assembly.GetEx ecutingAssembly ().Location.
Replace("/", "\\") == current.MainMod ule.FileName)
{
//Return the other process instance.
return true;
}
}
}

Brendan
"Gidi" wrote:
Hi,

I saw that someone asked that question here before, and i tried one of the
answer that was gaven (Bob's tricks and tiips), The suggestion there was
using the ImoprtDll and tried to import the user32.dll, when i tried to
import it to the refernces, the Visual Studio crashed.

So how can i force one copy of application (i'll be happy and thankful to
get an example).

Thanks,
Gidi.

Nov 17 '05 #2
Brendan,

This is a horrible (and not guaranteed way) of allowing only one copy of
an application to run.

It can definitely impact performance (because of all the information
about the processes that have to be retreived).

The proper way to do this is to set up a mutex with a unique name, and
then try and access it. If you can not access it in your app (presumably
because another instance already holds it), then do not run it, and exit the
entry point of the application.

Check out my response to a similar question (watch for line wrap):

http://groups.google.com/group/micro...128f9ddd957ada

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Brendan Grant" <gr****@NOSPAMd ahat.com> wrote in message
news:4A******** *************** ***********@mic rosoft.com...
One simple way to do it is to list the running processes on the system and
see if another instance of the same name, running from the same location
exists, with a different process id exists.

Process current = Process.GetCurr entProcess();
Process[] processes = Process.GetProc essesByName
(current.Proces sName);

//Loop through the running processes in with the same name
foreach (Process process in processes)
{
//Ignore the current process
if (process.Id != current.Id)
{
//Make sure that the process is running from the exe
file.
if (Assembly.GetEx ecutingAssembly ().Location.
Replace("/", "\\") == current.MainMod ule.FileName)
{
//Return the other process instance.
return true;
}
}
}

Brendan
"Gidi" wrote:
Hi,

I saw that someone asked that question here before, and i tried one of
the
answer that was gaven (Bob's tricks and tiips), The suggestion there was
using the ImoprtDll and tried to import the user32.dll, when i tried to
import it to the refernces, the Visual Studio crashed.

So how can i force one copy of application (i'll be happy and thankful to
get an example).

Thanks,
Gidi.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4926
by: Navin | last post by:
hi, guys i am using the following code to force a file download dialog in asp Response.ContentType = "application/vnd.ms-excel" response.AddHeader "content-disposition","attachment; filename=" &" & StrFileName Now the it works fine in ie5.5 sp2 but no ie5.5 sp1 it prompts the user twice the open dialog box.
2
5859
by: Raquel | last post by:
FORCE APPLICATION command is valid only at the 'instance' level. Why is this so? An instance may contain many databases. So, what command do I give if I want to force applications from a particular database. Interestingly, LIST APPLICATIONS command does have a 'FOR DATABASE' option which means that I can find the list of applications for a particular database, but have no option to Force all the applications for that database. I have to...
2
1192
by: Raed Sawalha | last post by:
how can I view only one exec copy of my application? double click app icon-> open-> again double click app icon-> i need to check it already running not to open it again. regards
2
2685
by: Oenone | last post by:
I have an application which loads plugin DLLs from various directories on the local disk. To avoid problems with the DLLs being locked by IIS, I have modified my code so that it copies the DLLs to the /bin/ directory if it determines that they are newer than the version already there, and loads the copy. This then takes advantage of Shadow Copying, so the DLLs never get locked. This is all fine, but the very first time I put a new DLL...
0
2657
by: comp.lang.php | last post by:
I have a form that when you click the "Generate Report" submit button, it will force download a CSV file, required for this project. On the very same page you also have a "Search" submit button, when you press it it should generate search results in a new page. However, when you click the "Generate Report" submit button, the moment you try to THEN click the "Search" submit button, the "Search" submit button NEVER goes to a new page but...
2
2307
by: comp.lang.php | last post by:
class ReportGenerator { function ReportGenerator() {} /** * Generate the HTTP headers necessary for this file type. Can be called statically *
3
3311
by: MarkusJNZ | last post by:
Hi, I have two different applications running on 2003 both in two different vitrual directories. One application runs on the .NET framework 1.1 whilst the other runs on 2.0. If I change the framework version (via IIS admin ASP.NET tab) for either application (Initally the 2.0 app was recognised by IIS as 1.1) does this force IIS to restart? ?? Any links to further reading would be good.
0
1519
by: savajx1 | last post by:
I am loading signed assemblies from a network share. The assemblies are NOT INSTALLED in the GAC as they are part of an enterprise distributed application implemented as a windows service that loads its code (*.dlls/assemblies) from a network share. The assemblies are signed to allow loading given code access security. I am debugging the windows service but I cannot get it to release/replace a copy of an old version of the *.dll. I...
3
4253
by: Dean Slindee | last post by:
Using VS2005, I am deploying a WinForm application with ClickOnce. The project contains a ReportViewer2005 control, so there is a prerequisite for the ReportViewer2005.dll. The ReportViewer.dll that is included with Visual Studio 2005 works fine on my (developer) pc, both within Visual Studio 2005, and after deployed, from my pc. However, this is not the case with the user's pcs. When they download the ReportViewer2005.dll from...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.