|
-
Feb 3rd, 2002, 04:21 PM
#1
Thread Starter
Dazed Member
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.
-
Feb 3rd, 2002, 07:32 PM
#2
Member
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.
-
Feb 4th, 2002, 07:08 AM
#3
Addicted Member
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!
-
Feb 4th, 2002, 10:51 AM
#4
Hyperactive Member
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.
-
Feb 4th, 2002, 02:20 PM
#5
Thread Starter
Dazed Member
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?
-
Feb 4th, 2002, 02:57 PM
#6
Addicted Member
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
-
Feb 4th, 2002, 03:15 PM
#7
Thread Starter
Dazed Member
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.
-
Feb 4th, 2002, 03:19 PM
#8
Addicted Member
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
-
Feb 4th, 2002, 03:24 PM
#9
Addicted Member
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
-
Feb 4th, 2002, 03:25 PM
#10
Thread Starter
Dazed Member
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?
-
Feb 4th, 2002, 03:28 PM
#11
Addicted Member
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
-
Feb 4th, 2002, 03:29 PM
#12
Member
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
-
Feb 4th, 2002, 03:31 PM
#13
Thread Starter
Dazed Member
I think where im a little bit fuzzy is were and how Windows runs programs. Ill have to look into this further. Thanks.
-
Feb 4th, 2002, 03:34 PM
#14
Thread Starter
Dazed Member
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.
-
Feb 4th, 2002, 03:35 PM
#15
Addicted Member
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
-
Feb 4th, 2002, 03:56 PM
#16
Hyperactive Member
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.
-
Feb 4th, 2002, 04:11 PM
#17
Hyperactive Member
you specify the port that you want your socket to listen on, if it cant it will error.
-
Feb 4th, 2002, 04:11 PM
#18
Thread Starter
Dazed Member
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.
-
Feb 4th, 2002, 04:14 PM
#19
Hyperactive Member
yup, you got it, if the app is up already and has the port the new one should throw an i/o exception....
-
Feb 4th, 2002, 04:53 PM
#20
Member
isn't opening ports a secruity risk?
-
Feb 4th, 2002, 04:56 PM
#21
Hyperactive Member
no, just dont let the socket accept any connections...
-
Feb 4th, 2002, 05:11 PM
#22
Member
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.
-
Feb 4th, 2002, 05:25 PM
#23
Addicted Member
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
-
Feb 5th, 2002, 08:58 AM
#24
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|