Hack Forums
[.NET] SingleInstance Application [C#/VB] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] SingleInstance Application [C#/VB] (/showthread.php?tid=4470491)

Pages: Pages 1 2


SingleInstance Application [C#/VB] - Nikey646 - Oct 1, 2014

First off: The VB Version crashes. I have no clue as to WHY it crashes, it's something related to the Mutex not properly stating that it's owned as far as i can tell. I'll let a wizard like TheBarret or Aeonhack figure it out ^_^

What does this do:
It uses Mutex and NamedPipeStreams to prevent multiple instances of an application from occuring. It will also send the CMD information to the existing instance of the application, so that it can be processed.

Purpose:
Allows you to open files to queue work on them, or create a URL Based scheme eg: MyApp://Command1/Parameter1/Command2/Parameter2 with a few lines of code and this class.

Examples:
I've created a WinForms application in VB and C#, which outputs each parameter onto a new line of a textbox.

C# Example:
Spoiler (Click to View)

VB Example
Spoiler (Click to View)

Source (Bitbucket):
Full Solution
C# | VB.Net

Did i miss anything?


* - TheBarret - Oct 1, 2014

Oh thats quit intresting, this is similair to what they had in the past, called DDE ( http://en.wikipedia.org/wiki/Dynamic_Data_Exchange ) connection between apps.

ill have a go with it, ill comment back when i find probs.


* - Nikey646 - Oct 1, 2014

(Oct 1, 2014 04:08 AM)TheBarret Wrote:  Oh thats quit intresting, this is similair to what they had in the past, called DDE ( http://en.wikipedia.org/wiki/Dynamic_Data_Exchange ) connection between apps.

ill have a go with it, ill comment back when i find probs.

Was working with DDE (Not directly, but through the NDde library) for getting Firefox's URL a while ago. It's interesting to see that something from so long ago is used in one of the 3 Major Browsers of today.

Btw, it's probs something insanely stupidly simple, i havn't coded in VB for a bit, mostly C#, and hand converted it. (Making sure it works with Options Strict <_< >_>) By the end of the various error had i to fix while converting it, i was tired of working with VB again, and just gave up xD


* - He B TeMy - Oct 1, 2014

What's wrong with "Enable single instance application" ?


* - Nikey646 - Oct 1, 2014

(Oct 1, 2014 05:45 AM)HeBTeMy Wrote:  What's wrong with "Enable single instance application" ?

Besides not passing the Command Parameters from the old instance of the application to a new one, nothing.

If you know of a better way to do this, then please go ahead and enlighten me.


* - TheBarret - Oct 1, 2014

Well not all the peeps arround here had a clue what this does or should perform, perhaps this could be tagged as a challenge ^^


* - CodeAssassin - Oct 1, 2014

Hmm this is quite interesting, Never had the need to pass the args from one single instance app to another, but i can defiantly see the need in certain situations. Thanks for the heads up will have a little look myself :)


* - He B TeMy - Oct 1, 2014

(Oct 1, 2014 06:15 AM)Nikey646 Wrote:  Besides not passing the Command Parameters from the old instance of the application to a new one, nothing.

If you know of a better way to do this, then please go ahead and enlighten me.

Wtf are you talking about with command parameters?


* - Nikey646 - Oct 1, 2014

(Oct 1, 2014 08:17 AM)HeBTeMy Wrote:  Wtf are you talking about with command parameters?

Well. I may not be explaining it that *well*, but two other's seem to have understood what i meant?

Command = Command line (CMD.exe)
If i need to explain Parameters...sigh

If you are wondering what a Real World Everyday use of a system like this is,Spoiler (Click to View)


* - He B TeMy - Oct 1, 2014

I figured it quite out, i don't figure is why you would need such a thing, let's face it, most programs won't, so this is kinda pointless.
No one's gonna code a "so-called browser" and for other programs there's other ways i could think of.
Although this may have value, don't call me dumb at the first reply and don't be so defensive for a rather OLD topic.


* - Nikey646 - Oct 1, 2014

(Oct 1, 2014 08:34 AM)HeBTeMy Wrote:  I figured it quite out, i don't figure is why you would need such a thing, let's face it, most programs won't, so this is kinda pointless.
No one's gonna code a "so-called browser" and for other programs there's other ways i could think of.
Although this may have value, don't call me dumb at the first reply and don't be so defensive for a rather OLD topic.

How is this topic "OLD", in any way?

If you figured it out however cannot think of any usage's of such a program, then why didn't you try to think of a new usage?

In a short-term application there is no usages, however If you are trying to replicate an entire website's functionality in an application (Like i am for several projects, with and without owner approval), generating and using links that use a *name*:// format (URI Scheme) which will automatically open your application and respond to it is quite a useful user interaction feature.

The same could can be done with files, if you associate .*name* file's to your application (Say a Image Converter that adds a Watermark), instead of creating an entirely new instance of your application, it can load it up in a new tab, saving memory and load time.

This topic is not old, and quite a lot of Professionally made applications still use some form of inter-process operations to date. Steam, TS3, Origin, Firefox, Thunderbird, Outlook, GIMP, Any program that can open multiple files into a SINGLE instance.

Unless i've miss understood what you are implying Old to be, this is quite a relevant snippet of code, it's just not usable in any of the normal rinse-repeat code you find the average skid looking for here, aka Malicious code for RATs, Keyloggers, Spammers, etc.

Edit: Also i put this code out there more so if i ever lose it locally it'll be online. It's not like i'm forcing you to use this code in your next application, and infact, if anyone used this code in a proper application, i would be surprised, since it seems this forum's Creativity is limited to Malicious code.


* - He B TeMy - Oct 1, 2014

(Oct 1, 2014 08:54 AM)Nikey646 Wrote:  How is this topic "OLD", in any way?

If you figured it out however cannot think of any usage's of such a program, then why didn't you try to think of a new usage?

In a short-term application there is no usages, however If you are trying to replicate an entire website's functionality in an application (Like i am for several projects, with and without owner approval), generating and using links that use a *name*:// format (URI Scheme) which will automatically open your application and respond to it is quite a useful user interaction feature.

The same could can be done with files, if you associate .*name* file's to your application (Say a Image Converter that adds a Watermark), instead of creating an entirely new instance of your application, it can load it up in a new tab, saving memory and load time.

This topic is not old, and quite a lot of Professionally made applications still use some form of inter-process operations to date. Steam, TS3, Origin, Firefox, Thunderbird, Outlook, GIMP, Any program that can open multiple files into a SINGLE instance.

Unless i've miss understood what you are implying Old to be, this is quite a relevant snippet of code, it's just not usable in any of the normal rinse-repeat code you find the average skid looking for here, aka Malicious code for RATs, Keyloggers, Spammers, etc.

"In any way?" it is, fairly old, since vb6 at least, no need for the "extra feature" for most of it imo.

I wasn't talking about usages of this program, i was talking about other usages that may accomplish this. (in perhaps a more dirty way depending on my brain-mood)
There you go, "website's functionality" , how many vb programs use that? Less than 5% right? (that is, if you want to take a wild guess.)
I'm not saying other programs don't use it, i'm not saying the use of it is old, i'm saying you're comming up to that solution which only brings an extra possible-feature to an older solution (or even the .net built-in one which i was talking about) just for the use referred above.

I'm not saying this is bad, i didn't even see the code (perhaps that's what started this.) i was just referring to the Title basically.

(Oct 1, 2014 08:54 AM)Nikey646 Wrote:  Edit: Also i put this code out there more so if i ever lose it locally it'll be online. It's not like i'm forcing you to use this code in your next application, and infact, if anyone used this code in a proper application, i would be surprised, since it seems this forum's Creativity is limited to Malicious code.

The Creativity is limited. Period.


* - Nikey646 - Oct 1, 2014

(Oct 1, 2014 09:11 AM)HeBTeMy Wrote:  --snip--
I'm not saying other programs don't use it, i'm not saying the use of it is old, i'm saying you're comming up to that solution which only brings an extra possible-feature to an older solution (or even the .net built-in one which i was talking about) just for the use referred above.
--snip--

Ahh, Okay so that's what you mean.

The only problem with your example of the "built-in" solution for Single Instances, is it doesn't tell the running instance of the application the launch commands of the original (Because there is no way to know if it's designed to handle that), which is what i really wanted out of this code. (However, to primary way of implementing that was to create a Mutex to find out if the application is running or not. So it already implements the solution from Visual Studio..(afaik))

Another thing to take into account, is WPF, which as far as i can tell, it actually doesn't have the Single Instance option and excepts you to take care of it yourself.

(Oct 1, 2014 09:11 AM)HeBTeMy Wrote:  --snip--
There you go, "website's functionality" , how many vb programs use that? Less than 5% right? (that is, if you want to take a wild guess.)
--snip--
Well, for one website i'm actually using the API to create a Download Manager for the content. That's implementing the website functionality (Since the API will expose everything that can be accessed from the website...when it's finished lol). In the case of this forum, implementing a website functionality is severely limited Shells, Booters, Resolvers, and an Occasional Pastebin spammer.

(Oct 1, 2014 09:11 AM)HeBTeMy Wrote:  --snip--
The Creativity is limited. Period.
So sad, but so true...Very few people can think outside of the box on this forum...(Hell, even me sometimes :P)


* - DBots - Oct 2, 2014

@Nikey646, what I am understanding is you have an application which is a single-instance app. When you send command-line arguments to it, it does not detect them.

If that is the case then I had the same problem and the solution I found was using the StartUpNextInstance event.

Here is a sample of the code I used:
http://pastebin.com/NV6RcDB7


* - 420 Blaze It - Oct 2, 2014

Thanks for the source, I used exit.app and it kept crashing, now it didn't.