Thread: Check number of times a process is running

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    2

    Check number of times a process is running

    I'm having a bit of an issue figuring out how to check how many times a process is running in windows. I have an existing Visual C++ Program that uses the open source application dtelnet to connect to a system.

    We have modified it here at our company to create lock files for each session of dtelnet, thus allowing only 8 sessions to be open at a time.

    We've got a similar utility in Linux for graphical workstations. The problem I'm seeing is that sometimes, the screen locks are not being removed, this is the case in Windows and Linux.

    In linux, I wrote a simple bash script script to check how many times the process was running, and if it's the first instance, go ahead and clear out the lock files.

    I'm looking for something similar in Windows and am having some trouble locating a fix for what I need.

    I need to:
    1) Check how many times the process dtelnet.exe is running.
    2) If the process is running 1 time, then this is the initial process and let's go ahead and clear any screen lock files (names scr1 - scr8).
    3) If the process is running more than 1 time, then it's not the first running, so don't clear any locks.


    Admittedly, I am new to programming in Windows and with C++. I have done shell scripting, some perl, and some java. Any code snippets or examples would be greatly appreciated.

    The existing program was compiled with Visual C++ 6.0 and I have this or Visual C++ 8.0 available to me.

    I don't mind researching, and have been for a couple of days but have not had much luck finding a specific solution.

    Thanks in advance.

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Download the WinSpy++ source code. In it, the creator uses a library that has the tools to easily do this.

    Or, if you're not worried about different processes with the same name you could use MS' Tool Help API.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I don't really see that you need those files, or to be able to enumerate processes at all. Those methods are flawed.
    You could simply use 8 mutexes and have your program try to acquire one of those before it will allow itself to continue. There's probably an even better way though.
    I mean this is all one one machine right?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    what you do is use Process32First , Process32Next and enumrate the snapshot
    google those functions

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    2
    Quote Originally Posted by iMalc View Post
    I don't really see that you need those files, or to be able to enumerate processes at all. Those methods are flawed.
    You could simply use 8 mutexes and have your program try to acquire one of those before it will allow itself to continue. There's probably an even better way though.
    I mean this is all one one machine right?
    Correct, these are all on one PC. Each PC has it's own dtelnet program.

    I'm not familiar with what a mutexe is. I'll look up some info. Any other info would be greatly appreciated.

    I may be trying to go to an ssh connection as this does telnet.

    Just as a disclaimer, my position is Research and Development, but I primarily deal in linux systems. I have some understanding of programming concepts, but have only used bash scripting, perl, and some java. Thanks for all the help from everybody, I'll look into the solutions provided thus far. Any further assistance is greatly appreciated.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    It's a mutex, not a mutexe.

  7. #7
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Right, I don't know why I didn't think of that. "enumerate proccesses" was stuck in my head.

    Mutexes are really easy to use, I'm even using them in my current project. Mutex docs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check Running Process Dev-C++
    By gamesplant in forum Windows Programming
    Replies: 23
    Last Post: 10-19-2009, 03:20 AM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  4. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM
  5. How is to check prime number?
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 10-04-2001, 11:36 PM