Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

[Source] Is my process running? Check to see if your program is running or not :D

Hi guys,
This is a short little snippet I made that checks to see whether your current application is running or not.
Code
string filename = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
Process[] process = Process.GetProcessesByName(filename);
if (process.Length == 0)
  MessageBox.Show("Your program is not running :(");
else
  MessageBox.Show("Your program is running!");

This is probably the fastest program I have ever coded, it took me only around 40 seconds. 😎
I think this is a troll if I should be honest.
Actually this has practical uses. For instance, if you are creating a program such as ShiftWindows like I did to create a listBox of all processes that are open, so you don't have to shift through all the random things like JME_LOAD that I would never want to run it on. Instead, right now it would only show that I had Diablo III, Steam and Google Chrome on the list instead of my 25 processes running.

or take my http://pastebin.com/LvC901th for instance. I only wanted to bring programs that are actually running on display to be brought to front, nothing else. This isn't a troll thread, however I don't like how he does it but it does work.

What he does is completely useless, however it can be applied to actual examples.
why not use mutex API instead of doing process checking. mutex is the clean way, a mutex is when you give your application are unique identifier and you can prevent multiple instances of the file. even if you rename the file it will not run twice as the code will not change.
it would be better to check if other process is running instead of checking own process. I don't see any usage of this
(Oct 18, 2012 04:03 AM)Debroski Wrote:  Actually this has practical uses.

Actually it doesn't. It makes no sense to check if the process you're running is running ;)
(Oct 18, 2012 06:27 AM)BaussHacker Wrote:  Actually it doesn't. It makes no sense to check if the process you're running is running ;)

Agreed, there's no point to this thread.
(Oct 18, 2012 06:27 AM)BaussHacker Wrote:  Actually it doesn't. It makes no sense to check if the process you're running is running ;)

check the rest of what i said and not just that line :P yes, the GetCurrentProcess is useless, I was more referring to the name length part. That can be used to get current applications. Look at my example if you don't understand.
Thanks to all who commented.
If anyone's wondering, this was a parody of this thread: https://hackforums.net/showthread.php?tid=2910267 🙂
This is not good, you should use the PID.
(Oct 18, 2012 11:52 AM)Shinoowns Wrote:  check the rest of what i said and not just that line :P yes, the GetCurrentProcess is useless, I was more referring to the name length part. That can be used to get current applications. Look at my example if you don't understand.

Yeah I know, but I was just speaking about this alone. It has no real purpose xD If it can even execute that then it's running rofl :p
If this program is running it shoud close it just for the lolz :D
(Oct 18, 2012 07:13 PM)Birds Wrote:  This is not good, you should use the PID.

LOL. I hope this is a troll.
If not, facepalm.
(Oct 20, 2012 06:03 AM)The-One Wrote:  If its not running then System.Diagnostics.Process.GetCurrentProcess().ProcessName will result in an exception, OPs code will only work if the process is running.

It wouldn't even result in an exception. For an exception to be thrown your process also has to run ;)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by gigajewMar 4, 2019 08:44 AM 15 1,611 Mar 4, 2019 08:44 AM
Last Post: Aristocles
[.NET] by Formula 1Mar 3, 2019 02:36 PM 6 229 Mar 3, 2019 02:36 PM
Last Post: Formula 1
[.NET] by BapeZOct 1, 2018 01:09 PM 5 279 Oct 1, 2018 01:09 PM
Last Post: oxidebuffalo