tag:blogger.com,1999:blog-8259613.post8103101028497827063..comments2023-08-05T11:16:50.347+02:00Comments on Kristof Verbiest - Bite-size C#: Creating a single-instance applicationKristofhttp://www.blogger.com/profile/01727380410232817527noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-8259613.post-4941085611960990582011-06-15T01:36:26.724+02:002011-06-15T01:36:26.724+02:00This works until the day your application is run o...This works until the day your application is run on something like Windows Server 2003 or 2008, or anything that uses terminal services. Then you find that each logged in user can run their own instance of the application. Great... if the application is OK for having a single-instance-per-logged-in-user.<br /><br />Some applications, though, need to use a single-instance-per-machine. In this case you need to go to a whole lot more trouble, probably put the mutex in the Global space (prefix Local -> Global). This requires Administrator rights, or similar privilege elevation and can get very messy.ashleighhttps://www.blogger.com/profile/03109431499306884717noreply@blogger.comtag:blogger.com,1999:blog-8259613.post-4938219422946766572009-02-12T10:05:00.000+01:002009-02-12T10:05:00.000+01:00@Dom: this is indeed a placeholder. The first part...@Dom: this is indeed a placeholder. The first part "Local\\" is mandatory. The rest "MyAppName{...}" is just meant to be a unique identifier. You need to be sure that nobody else uses the same identifier. Usually I include the name of the application (so replace "MyAppName" with the name of your application - it is OK to do this hardcoded). The reason is that this makes it easier to debug your application if you suspect there may be problems with this mutex.<BR/>The rest (between curly braces) is a GUID which makes sure that your identifier is unique. This is for the unlikely case when some other application with the same name is using exactly this same code pattern.Kristofhttps://www.blogger.com/profile/01727380410232817527noreply@blogger.comtag:blogger.com,1999:blog-8259613.post-91745708218152197102009-02-11T17:01:00.000+01:002009-02-11T17:01:00.000+01:00Is "Local\\MyAppName{A6F214AB-669D-41B2-9F30-8DD5E...Is "Local\\MyAppName{A6F214AB-669D-41B2-9F30-8DD5E5AC9AE1}" just a place holder of somesort, to be changed in each specific application? You can't use that in every program, can you?<BR/><BR/>I tried Application.ExecutablePath, thinking this is unique to every application, but I get the message "Part of the path can not be found." Why is that?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8259613.post-43234097639680767802009-01-09T08:50:00.000+01:002009-01-09T08:50:00.000+01:00@tertium alter ego: if I understand you correctly,...@tertium alter ego: if I understand you correctly, you want to bypass this protection. First of all I should warn you that this is probably not a safe thing to do, most of the time this protection will be very usefull to protect you from doing something harmfull.<BR/>But if you really want to circumvent this protection, here is how you do it: start the first instance of the application. Then use <A HREF="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" REL="nofollow">Process Explorer</A> to find the mutex (handle) that was used for the protection and kill this mutex. Then you should be able to start the second instance of the application. Note that I haven't tested this though.Kristofhttps://www.blogger.com/profile/01727380410232817527noreply@blogger.comtag:blogger.com,1999:blog-8259613.post-32396894292951237982009-01-08T17:48:00.000+01:002009-01-08T17:48:00.000+01:00very clear explanation! thank you!maybe you know a...very clear explanation! thank you!<BR/><BR/>maybe you know as well how we can avoid this behavior in run time?<BR/><BR/>i mean if we have already installed an application that was developed with such a functionality. speaking simpler i'd like to launch more than one instance. any tricks?<BR/>thank you!wojzehhttps://www.blogger.com/profile/17752044692176547068noreply@blogger.com