Results 1 to 24 of 24

Thread: Multiple Instances?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Multiple Instances?

    Is there anyway to prevent multiple instances of a program from being spawned? Unlike say Internet Explorer which you can have multiple browsers running. There must be a way but im not too sure how i would go about doing this.

  2. #2
    Member
    Join Date
    Apr 2001
    Location
    Hamilton, ON, Canada
    Posts
    43
    i'm not sure if this will work, but you can try it anyway. When your program starts up, lookup the names of all processes running, if you see one that is already up, close the program.

  3. #3
    Addicted Member Mrs Kensington's Avatar
    Join Date
    Sep 2001
    Location
    Dorset, UK
    Posts
    144
    one cunning way i've heard of is to check to see if a port is open. If it is close the program if its not open that port.

    You obviously want to make sure you pick a port that is rarely used.
    Ford? Theres an infinite number of monkeys outside that want to talk to you about a script of hamlet they've produced!

  4. #4
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    i have thought of doing this in java. In vb and c++ on windows this is cake. I can think of no reason why the port trick should not work so I would try that approach.

  5. #5

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    When you guys say port are you refering to ports like in sockets and ports? I thought the purpose of a port was for incoming and outgoing data transfer?

  6. #6
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Yes, sockets. If you put a listener on a particular port #, when another instance of the program is run, it is prevented from creating a listener on that same port #.

    Heh, you could even choose the commonly used port for Back Orifice, which, if you were in Windows, would prevent a script kiddie from being able to install B.O. on your computer! Might freak out your virus detection software though.

    Also, I suppose the listener shouldn't actually do anything. It should just wait but ignore any attempts at a connection. Part of your testing should include a test to ensure that if someone does a:
    telnet <your_server> <port_number_of_your_choosing>
    That it doesn't stop or disrupt your program!

    cudabean

  7. #7

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Cudabean it sounds like you are talking about a remote user running an application off of a server. I was thinking of just a stand alone application.

  8. #8
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Doesn't matter, you can use some of the features of sockets even if you're writing a stand-alone ap, unless you're in like DOS or Windows 3.1 that doesn't have Winsock.

    cudabean

  9. #9
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Dilenger4 - You don't have to use this port/sockets approach. It's just one idea suggested by Mrs. Kensington. I think it's a good way to go because other approaches like writing to a file are prone to failure. If the computer goes down because somebody pulled the plug, you still have this message in a file that says that "the program is running" when the program is NOT running.

    Also checking for processes would be a real pain, I think, compared to the port/socket approach.

    cudabean

  10. #10

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    So let me see if i can understand this better. When the user
    fires up the application. I would have to find what port it is running on?

  11. #11
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Sort of, when the program starts up, it tries to listen on port 7823. If it can't listen on 7823, that means that some other program is already listening on that port and it shuts down.

    cudabean

  12. #12
    Member lordsty's Avatar
    Join Date
    Oct 2001
    Location
    mD, Us
    Posts
    58
    use the prevInstance property of App, it returns true if another instance is running, false if it is not....

    Private Sub Form_Load()
    If App.PrevInstance Then
    Unload Me
    Exit Sub
    End If
    'continue

    or use in your code and exit function another instance is running...

    lord

  13. #13

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    I think where im a little bit fuzzy is were and how Windows runs programs. Ill have to look into this further. Thanks.

  14. #14

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    lordsty yes that is what i am looking for. But i have to find a way to do it in Java not VB. Im sure there is a way i just have to search through my books.

  15. #15
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Lordsty -

    This is Java, not VB

    Dillenger -

    Don't think Windows because this approach will work in Unix and Windows, so long as sockets exists, which is 99% of computers. Plus, it doesn't matter if you are connected to the internet at the time or not.

    cudabean

  16. #16
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    Lordsty you are in the wrong forum.

    Cuda is right, when the app starts up grab a port and hold on to it, if the port is in use, display a message saying the app is already up. When the app is shut down, release the port. Simple as that. The jvm and windows will handle clearing the port on wierd shutdowns.

    I would not go the processes route, or if you want to you will lose the platform independcy.

    Files do not work.

  17. #17
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    you specify the port that you want your socket to listen on, if it cant it will error.

  18. #18

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Oh ok i get it. Every time my prog fires up i assign it to the same port. So if another instanace of the application wants to run, it cant because the port is taken from the first time the program was ran.

  19. #19
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    yup, you got it, if the app is up already and has the port the new one should throw an i/o exception....


  20. #20
    Member
    Join Date
    Apr 2001
    Location
    Hamilton, ON, Canada
    Posts
    43
    isn't opening ports a secruity risk?

  21. #21
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    no, just dont let the socket accept any connections...

  22. #22
    Member
    Join Date
    Apr 2001
    Location
    Hamilton, ON, Canada
    Posts
    43
    if the program does accept connections, but doesn't do anything else, how hard is it for someone to remotely get control of the computer through that port?

    I'm writing a networking app. now, and security is important to me, so i'm trying to learn as much as i can on the issue.

  23. #23
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    I don't think you'd have a security risk. Most port listeners do implement some sort of protocol like ftp or telnet or somesuch, but since this port listener is dumb as a post even the M3G4-733T script kiddie gets bored after a very short time.

    For example:

    telnet i_will_own_you.com 7823

    Connection Refused

    telnet i_will_own_you.com 7823

    Connection Refused

    "Dang, I'm bored"

    cudabean

  24. #24
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    Yep! As long as the socket refuses connections you are fine with security.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width