Allow only one single process of a Exe

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> my hard coded title was changed in the 'window title bar' by the OS.

Impossible. Sounds more like a third-party app was changing the title bar.

I had a user report that one of my apps wasn't working on his machine, and it
was eventually discovered that he was running an app that put the time/date in
the title bar of every open window on his system. This was after I told him
to try my app after booting in Safe Mode, which he never did -- it would have
made finding the problem much easier.

Actually, upon typing this, I've just realised that perhaps my method of checking
for my app's title with FindWindow is not such a good idea after all... hmm.
But I guess, if the user is going to screw with the normal operation of the
OS by using such an app, then it's not my fault that my app doesn't work...

Anyway, Franco: I apologize for saying that your template was not the best way,
so please feel free to hit me.


PB - Registered PureBasic Coder

Edited by - PB on 11 May 2002 19:22:09
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

Isnt it possible to set a process Name or something like that and search for it fromin other applications? should be possible or? listens logical, better then comparing the Windowtitle.

´Mike

Tranquilizer/ Secretly!
Registred PureBasic User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Isnt it possible to set a process Name or something like that and search for
> it fromin other applications?

Probably, but that's how the Mutex method works anyway: your app creates a Mutex,
which is unique and searchable by other apps. The Mutex only exists in RAM,
and is lost when rebooted or the app ends, so it's probably the best way to
do it. Unfortunately it's not so easy to set up as a quick FindWindow, and
it uses more RAM, which is why I prefer to look for my unique app title.


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Hi, first of all:

PB, I would NEVER hit anybody (OK, OK, if you are a cruel spider or a fly that would be different...)


I said:
> The window title is not always the same on Win9x and WinNT+.
and:
> I remember 4 years ago I coded a program that waited as long another
> program was running, and after that my program went to work.
> Searched for this application with 'FindWindow' and it worked very
> fine - on my machine, running WinNT4.

> A coworker of mine wanted to use this program for the same
> reason/application and it didn't work.
> The problem: he worked with Win95 - and the displayed name
> was NOT the same.
> The Problem was that my hard coded title was changed in the
> 'window title bar' by the OS.
> I had to add code to find out which OS was running and adapt
> the 'FindWindow' routine...

I didn't say that the OS changes the window title from:

Apples -> Bananas

The program that I had to observe was a DOS program running in a Windowed DOS-BOX.
Under WinNT+ you will see that in the 'windows title' is the full path displayed plus the file name.
Under Win9x was only the file name visible. (don't know about WinME)

That's why my 'FindWindow' routine didn't work properly on every Windows OS.

I also said:

> And if I recall it right, under WinXP you can choose to have the full
> 'PATH NAME' or only the 'NAME' in the window title .

Proof:

Under WinXP
Settings -> Folder Options -> View -> Advanced Settings -> Files and Folders

you will find:

Display the full path in the title bar (you can switch it on or off)

The help for this (RMB -> What's This) says:

'Specifies that the complete path of the open file or folder is displayed in the title bar of the window.'

If you open the Internet explorer you can see it (open a http site...)

WinXP changes the title of IE (on my system for a short time and then it switches back... , seems that this function is not working properly - Microsoft's normal way of doing things...)

If you have 'OpenOffice V1' you can see that nothing happens - not even for a short amount of time.

It seems that this function also depends 'how' the application is coded.
(or there is more confusion in this function that I can handle...)

Anyway, you see that Microsoft Windows XP is willing to alter the window title.

The next what I said was:

> Also if somebody renames your application the 'NAME' method
> doesn't work anymore!

This is 100% for sure if you have hard coded:

If FindWindow_(0,"MyApplication")0 : End : EndIf

'Power users' change a lot on her machines, so be avare of it...

You have to use:

If FindWindow_(0,RealAppNameFromCmdLine$)0 : End : EndIf

than it would work.
But what can you do if a user uses your application twice with different names like:

Apples.exe and Bananas.exe

Your Application runs twice and you can't do anything about that.
If your application can't handle this situation, your program don't work properly anymore.

But like I said: you can do whatever you want
(just my 2c)


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.

Edited by - franco on 12 May 2002 05:14:27
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by horst.

Franco,

the problem was another instance of my (Windows) program.
The command processor (DOS Box), Explorer or IE are not my
Windows programs.

>> Also if somebody renames your application the 'NAME' method
>> doesn't work anymore!

> 'Power users' change a lot on her machines, so be avare of it...

Yes, but they do so on their own risk.
I am not willing to protect these users against themselves.

BTW: another advantage of the FindWindow_() method:
I can easily bring the first instance of the program to the
foreground (which is probably a better help than an error message).

horst.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> The program that I had to observe was a DOS program running in a Windowed DOS-BOX.

Well, I was referring to Win32 applications, not DOS apps.

> Under WinXP
> Settings -> Folder Options -> View -> Advanced Settings -> Files and Folders
> you will find:
> Display the full path in the title bar (you can switch it on or off)

This applies only to folders, and not Win32 applications.

> Also if somebody renames your application the 'NAME' method
> doesn't work anymore! This is 100% for sure if you have hard coded:
> If FindWindow_(0,"MyApplication")0 : End : EndIf

Sorry, this is wrong. Hardcoding works perfectly. I've tested it on Win 95,
Win 98, Win 2000, and Win XP. Want proof? Download this test app, and try
to run it twice -- you won't be able to:

http://www.bowlay.com/RunOnce.exe

> But what can you do if a user uses your application twice with different
> names like: Apples.exe and Bananas.exe
> Your Application runs twice and you can't do anything about that.

Again, you're wrong: try it with my test app above.

Trust me: I've been doing this for years with no side effects, other than when
the user runs another third-party app that changes the window title, which, in
fact, is a big no-no really. But the OS will *never* change the window title
of a running Win32 application that isn't part of the OS itself (such as IE).

Please try my test app above and get back with your results...


PB - Registered PureBasic Coder

Edited by - PB on 12 May 2002 12:12:22
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.
Sorry, this is wrong. Hardcoding works perfectly. I've tested it on Win 95,
Win 98, Win 2000, and Win XP. Want proof? Download this test app, and try
to run it twice -- you won't be able to:
You forget one thing here, program names can be much like names for people... not every one is unique. I can write an app and unknowingly use the same name someone else has.

Using your FindWindow method, only one app can be started, and in this case, they are completely different apps!! This is going to really upset someone who may have paid money for an app and finds out he must close others apps just to use it.

When using hacks or workarounds you must be aware of the consequences no matter how small. (and this is only one example that has nothing to do with modifying a hardcoded title)



Edited by - paul on 12 May 2002 18:49:58
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> You forget one thing here,

No I didn't, actually. Read on...

> program names can be much like names for people... not every one is unique.
> I can write an app and unknowingly use the same name someone else has.

Very true. But that's why I use unique names -- how many apps out there are
called PBToolBox? Only mine -- and if someone else writes one with the same
name, then they are in the wrong and at fault, not me. It's up to them to
ensure they search the Internet (or whatever) and choose a program name that
doesn't currently exist.

Nobody would consider releasing a program called PureBasic, or even Visual
Basic, because these already exist -- and I would assume the same applies to
my own apps, such as PBToolBox and vis2pure. In fact, vis2pure was originally
called vb2pb at first (but not released that way), until I discovered that a
PowerBasic program called vb2pb.exe already existed, so I chose vis2pure instead
after a careful search of the Internet.

I also post announcements to public forums when I release an app (such as to
Usenet) so there is undeniable proof that I used the name first.

I do understand what you're saying, though. Perhaps I really should use Mutex's
instead as these are much safer, but they're just not as convenient (from what
I've seen). I'll have to investigate them further and see if I can be convinced
to use them...

PB - Registered PureBasic Coder

Edited by - PB on 12 May 2002 19:23:46
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.
how many apps out there are
called PBToolBox? Only mine -- and if someone else writes one with the same
name, then they are in the wrong and at fault, not me. It's up to them to
ensure they search the Internet (or whatever) and choose a program name that
doesn't currently exist.
Not to get into a shouting match or anything but you might want practice what you preach. I just did a quick search for PBToolBox and the first thing that popped up was PBToolBox written in 1998.

Enough said :)



Edited by - paul on 12 May 2002 20:39:03
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> you might want practice what you preach.

I did, and always do. Read on...

> I just did a quick search for PBToolBox and the first thing that popped up
> was PBToolBox written in 1998. Enough said :)

Hmm, I don't know where you searched, but checking the search engines below
all returned zero matches for "PBToolBox". The proof is below. What search engine
did you use, and what did you search for? I'd like to see this other app...

Google:
http://www.google.com/search?hl=en&q=pbtoolbox
Result:
Your search - pbtoolbox - did not match any documents.
No pages were found containing "pbtoolbox".


Yahoo:
http://google.yahoo.com/bin/query?p=pbtoolbox&hc=0&hs=0
Result:
Sorry no results were found matching: pbtoolbox.

AltaVista:
http://au.altavista.com/q?pg=q&q=pbtool ... X&what=web
Result:
The query returned no results; please try another query

CNet Downloads:
http://download.com.com/3120-20-0.html? ... tg=dl-2001
Result:
No software found for pbtoolbox

Lycos:
http://search.lycos.com/main/default.as ... =pbtoolbox
Result:
Returned 3 matches from these forums.

Ask Jeeves:
http://www.askjeeves.com/main/askjeeves ... oolbox&o=0
Result:
No matches, and prompts to search elsewhere.


PB - Registered PureBasic Coder

Edited by - PB on 12 May 2002 21:44:39
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Ahh, we had a wonderful day at the beach.
Hope everybody is doing well here.

I said:
> Also if somebody renames your application the 'NAME' method
> doesn't work anymore! This is 100% for sure if you have hard coded:
> If FindWindow_(0,"MyApplication")0 : End : EndIf

Yes PB, what I said was totally wrong.

Actually I wanted to refer to this command line:
If FindWindow_(0,RealAppNameFromCmdLine$)0 : End : EndIf
than if would not stop users to rename your application and use it twice at the same time.
(This was the method I used to use with FindWindow... my fault, sorry for that)

Your application works fine with the hardcoded NAME method as long you use unique names.

Now I have to apologize - and you can hit me.




Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.

Edited by - franco on 13 May 2002 05:17:43
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Stan.

Hi all,

I have used a solution which works under any OS :

Create a dummy file in your application directory and check if it exists when
running your application ( well in fact check first ... ).

There is still a remote possibility that an other application creates such a
file but up to now I never ran into it ...

Hope this helps.

Stan



Since I attended an MS course, my programs no longer have bugs ... just hidden "features" !! [ PB. registered user ]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Now I have to apologize - and you can hit me.

It's okay dude... peace!


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
I have used a solution which works under any OS :

Create a dummy file in your application directory and check if it exists when
running your application ( well in fact check first ... ).
No good: if the OS or app crashes then the file will still exist, and your app
can never be run again. (This is also why using a Registry entry won't work).
Also, if you create the file in the same folder as your app, then your app can
never be run from CD or a write-disabled floppy...

The FindWindow and Mutex methods are the only true ways to do it, since they
check for the running application in RAM, which is always clean after a reboot or
app crash.

Also, the FindWindow method has another advantage over the Mutex method: if your
app crashes, then the Mutex CloseHandle_() call never gets made, which is not a
good thing...


PB - Registered PureBasic Coder

Edited by - PB on 14 May 2002 03:53:51
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.
Also, the FindWindow method has another advantage over the Mutex method: if your
app crashes, then the Mutex CloseHandle_() call never gets made, which is not a
good thing...
Guess it all depends what you are doing. If your app is using Mutex and does crash, you are able to see if the program has crashed when you start the program again because the Mutex tells your app that it has been abandone.

By knowing this, you can have your app do data backups, file checks, repair databases, etc. before continuing and maybe damaging something. You seem to be under the assumption that all these mutex processes are running in the background if something crashes.

The companies for which I write software can't chance having data damaged, so personally I would rather know the state of which my program ended the next time it starts up.


ps. Just curious where you are located that you only have access to 6 search engines? There are actually many hundreds out there :)
Post Reply