Windows Prevent accidental Double Loading of exes...

K12gamer

Member
I make educational games for my 1st grade students. I taught them how to double click to start games...but sometimes they get impatient and click several more times...This causes a game to load multiple times....to a point where it can freeze my PC.

Is there a way to prevent this in GM setting...or are any simple codes available?
 

GMWolf

aka fel666
As far as im aware, there is nothing you can do in GM:S itself. (though maybe GM8 had a feature like that)
THe only way im aware of is to write a .dll that would check if another instance of the program is running.
 

Yal

GMC Memer
GMC Elder
You could use a temporary file. At game start, you check if there's a file with the correct name (e.g. the current time rounded to 5 minutes or something like that), and if the file exists, you instantly quit the game. If not, you create the file and continue to actually running the program. When you close down the game after playing, you remove the file.
 

Opticrow

Member
You could use a temporary file. At game start, you check if there's a file with the correct name (e.g. the current time rounded to 5 minutes or something like that), and if the file exists, you instantly quit the game. If not, you create the file and continue to actually running the program. When you close down the game after playing, you remove the file.
What if the game crashes?
 

Yal

GMC Memer
GMC Elder
If you just make empty files, that should be a negligible effect - you'll at most make 20 files per HOUR this way, and they only take up a couple of bytes, so it would take ages before they would impact the system.
 
S

Snail Man

Guest
I think he means "what would happen if it crashed less than five minutes into the game", meaning that it wouldn't be able to remove the file, and you would be unable to reopen the game until that time had passed (or you deleted it manually, but the end user wouldn't know this)
 

Yal

GMC Memer
GMC Elder
You could probably lower the timespan to one minute - navigating the menus enough to start an actual game mode plus recovering from the crash should add up to at least a minute, especially for kids. 5 minutes just felt like a good limit that is a middle ground between short and "long enough that the game doesn't manage to load in the time between a previous instance making a file and it expiring".
 

Opticrow

Member
This would be absolutely terrible for HDD lifespan, but what about this for a solution. The game generates a random number, and writes it out to the save file. It then checks what's in the file 5 seconds later, and if it's not the same number it just wrote, there's another window open.
 
R

rui.rosario

Guest
You could also make Debug Mode be God Mode. Whenever you ran in Debug it would just delete all file that had a given prefix that signaled running instances. Just running in Debug Mode would take a long time tough, and it could be a one-press solution to the many files.
 

Yal

GMC Memer
GMC Elder
This would be absolutely terrible for HDD lifespan
Nah, you'd still only create files once (if the program loads quickly enough) and ideally the user stops trying to re-launch the program once at least one instance of it has started properly. A program that constantly makes auto-saves is probably more harmful for HDDs, and a lot of modern games do exactly that.
 

Opticrow

Member
I meant that my solution was harmful to the HDD :3
Nah, a program that constantly makes auto-saves is probably more harmful for HDDs
The game generates a random number, and writes it out to the save file. It then checks what's in the file 5 seconds later, and if it's not the same number it just wrote, there's another window open.
But on the other hand, it would work! ;)
 

Yal

GMC Memer
GMC Elder
Having to have the application run for 5 seconds could be harmful to the computer/user, though, since you could have a lot of different instances running at once during those 5 seconds, and the issue the OP is having is too many instances existing at once.
 
I think Yal has the best solution, using outside "flags". So the algorythm is:

1) Crazy kids click 50 times on the icon
2) The first exe checks if a save file in %localappdata% exists (it doesn't... yet)
3) The first exe then creates the save file
4) The second, third (and so on) instances check if the save file exists (it does, now)
5) All the instances for which the check was positive end the game
6) The first instance waits for any player interaction (mouse click or something) to know that the window is active - then it destroys the file

I also think this would be best. The problem would be in the case of the game crashing before any player interaction. In that case, you should go to %localappdata% and destroy the file manually...

The same thing could also be done by setting environment variables but for that you need dll support bla bla bla.
 

Dreadshadow

Member
I think Yal has the best solution, using outside "flags". So the algorythm is:

1) Crazy kids click 50 times on the icon
2) The first exe checks if a save file in %localappdata% exists (it doesn't... yet)
3) The first exe then creates the save file
4) The second, third (and so on) instances check if the save file exists (it does, now)
5) All the instances for which the check was positive end the game
6) The first instance waits for any player interaction (mouse click or something) to know that the window is active - then it destroys the file

I also think this would be best. The problem would be in the case of the game crashing before any player interaction. In that case, you should go to %localappdata% and destroy the file manually...

The same thing could also be done by setting environment variables but for that you need dll support bla bla bla.


I am not sure if that can easily be done, but I will just dump an idea here, to tweak things a bit, so we might overcome this problem stated above.

0) We create a permanent file named stamp.

1) Crazy kids click 50 times on the icon
2) The first exe checks if the stamp file contains anything. If not It creates a timestamp in it and goes on. If yes, it checks if the existing timestamp is aged 30 seconds from now. If not, it will terminate itself, else it will go on and delete the timestamp (all contents) and add a new timestamp in stamp file containing current time.

4) The second, third (and so on) instances, check if the contents of stamp file too.

On crash, worry not, timestamps expire.

You can have ONE permanent checkfile.
If it has contents, the contents is a timestamp.
Thus you can do a lot of things easier this way, updating the timestamp value.

Problem with manual file destruction disappears.


There will be a problem though in intentional many instance loadings.
Scenario:
Crazy kid loads a game once.
Then double click the game after 10 minutes.
But that's a different story. We talked about accidental double clicks.

Also there will be a problem if a game crashes, then you try to relaunch it within 30 seconds.
All right. That's logical, but it is solved in about half a minute so...


P.S. It doesn't have to be 30 seconds. You can make a timestamp expire after 2 or 5 minutes or whatever.
 
Last edited:

johnwo

Member
Make a preloader/launcher application that checks if the game process is running.

Preloader/launcher:
  • If it is running, show a prompt that tells the user that the game is already running.
  • If it is not running, pass a command-line parameter, of your choice, to the game.
Game:
  • Check if the game recieved a command-line parameter; Quit if it didn't, or it is incorrect.

This can be done without headache in most programming languages.

Although this isn't totally reliable (someone could figure out the command-line parameter), you can make it harder to crack by using string encryption, ect.; Or simply making it into a DLL and using it in the game EXE itself.

Cheers!

PS:
If you're not currently equipped to do this, I'd be happy to make you a simple preloader/launcher that does what I described above in C/C++. Just send me a PM if you're interested.
 
Last edited:

Dreadshadow

Member
Make a preloader/launcher application that checks if the game process is running.

Preloader/launcher:
  • If it is running, show a prompt that tells the user that the game is already running.
  • If it is not running, pass a command-line parameter, of your choice, to the game.
Game:
  • Check if the game recieved a command-line parameter; Quit if it didn't, or it is incorrect.

This can be done without headache in most programming languages.

Although this isn't totally reliable (someone could figure out the command-line parameter), you can make it harder to crack by using string encryption, ect.; Or simply making it into a DLL and using it in the game EXE itself.

Cheers!
Your approach is really interesting, I am not sure though if it works for this case.
If what you suggest is possible using GML why not doing it inside the same program, checking self and other potential instances?
If not, making a preloader might involve knowledge of another programming language and stuff (not really a real issue) so yes this is a possible solution.
The problem is that the OP is using the applications to teach children. Thus the OP might need to keep things as simple as possible, thus a pre-load launcher makes things a little more complicated.
Not to mention that the kids can do this double clicking on the preloader.

Edit: Corrected some things on my reply.
 
Last edited:

johnwo

Member
Your approach is really interesting, I am not sure though if it works for this case.
If what you suggest is possible using GML why not doing it inside the same program, checking self and other potential instances?
If not, making a preloader might involve knowledge of another programming language and stuff (not really a real issue) but yes this is a possible solution.
The problem is that the OP is using the applications to teach children. Thus the OP might need to keep things as simple as possible, thus a pre-load launcher makes things a little more complicated.
Not to mention that the kids can do this double clicking on the preloader.
What I am describing is not possible in GML AFAIK.
If they double-click the preloader, no harm done; It will simply quit silently/show a message that the game is already running, and to be patient while it loads.

This would not be a part of the course, I imagine.
If it is not a part of the course, but simply preventing multiple instances of the game from being run, doing something like this, whether it be in python (*yuck*), ruby(*double yuck*) or C++, isn't going to impact the course.

Just my two cents!

Cheers!
 

icuurd12b42

TMC Founder
GMC Elder
I have not read the topic... any GML solution would not fix this. if the kids are impatient and GML code wont run until the game starts... which is after the boot sequence

Here's a .vbs you can modify to do just this before the game starts
http://naumanyousuf.blogspot.ca/2013/01/vbscript-to-restrict-only-one-instance.html
Code:
' Process.vbs
' VBScript to enforce single instance execution of an application
' Date : 5 Jan 2012
' Author : Nauman (Solveso)
' -------------------------------------------------------'

Option Explicit

Dim objWMIService, objProcess, colProcess, objShell
Dim strComputer, strList, strprocess, strprocess1

strComputer = "."

strprocess = "'notepad.exe'"
strprocess1 = "notepad.exe"

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name = " & strprocess)


For Each objProcess in colProcess
strList = objProcess.Name
Next


if strlist = strprocess1 Then
wscript.echo "Aplication "& strprocess &" is already running, only one instance is allowed, please contact your administrator."
wscript.quit
end if


Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run strprocess1
wscript.quit
Just name it to the name of the game.vbs. change the notepad.exe reference in there... and change the icon of the vbs file...
 

Dreadshadow

Member
"I have not read the topic... any GML solution would not fix this. if the kids are impatient and GML code wont run until the game starts... which is after the boot sequence"

Oh, didn't thought of that, wow.

And the script seems an interesting and easy solution.
Nothing changes for the children experience, teacher just modifies an easy piece of code, changes an icon and everything is ready to go.

Shall we use this code freely? Does it come under certain Terms or conditions?
The blog says nothing, so I sent an email to the author.
I will report back when I will get his reply.
Thanks for sharing that.
 

Tsa05

Member
Yal's method is the best method, presuming that the program gets up and running.

If your concern is that many copies are initiated before the game's logic actually begins running (eg, they launch many copis while the first is loading), then this may not solve the issue entirely--Windows will legitimately try to launch every copy. If they all get up and running without crashing, then Yal's solution will cause a race condition and the fastest instance to load will stay running while the others will fall away. Unless you do the random number route--then they might all fail.

Another avenue to explore is this:
Suppose that you don't have them launch the program at all. Instead, you create a batch script which launches the program. So, you create "myFunGame.bat" and put the actual game out of the way somewhere. The Bat looks like this:

tasklist /nh /fi "imagename eq notepad.exe" | find /i "notepad.exe" > nul ||(start notepad.exe)

Note that my fun game is named notepad, because notepad is fun. But you'd use your game name. The script above checks whether a process has begun in the task manager named notepad, and if it has not, it launches notepad. This prevents the application from being launched multiple times via the bat.

edit: annnd, icuurd identified the same issue, and likes notepad.
 

icuurd12b42

TMC Founder
GMC Elder
Yal's method is the best method, presuming that the program gets up and running.

If your concern is that many copies are initiated before the game's logic actually begins running (eg, they launch many copis while the first is loading), then this may not solve the issue entirely--Windows will legitimately try to launch every copy. If they all get up and running without crashing, then Yal's solution will cause a race condition and the fastest instance to load will stay running while the others will fall away. Unless you do the random number route--then they might all fail.

Another avenue to explore is this:
Suppose that you don't have them launch the program at all. Instead, you create a batch script which launches the program. So, you create "myFunGame.bat" and put the actual game out of the way somewhere. The Bat looks like this:

tasklist /nh /fi "imagename eq notepad.exe" | find /i "notepad.exe" > nul ||(start notepad.exe)

Note that my fun game is named notepad, because notepad is fun. But you'd use your game name. The script above checks whether a process has begun in the task manager named notepad, and if it has not, it launches notepad. This prevents the application from being launched multiple times via the bat.

edit: annnd, icuurd identified the same issue, and likes notepad.
The vbs solution is much cleaner than a batch file, unfortunately everyone sort of defaults to thinking "batch file" for these sort of solutions. vbs is a batch file on steroids. You can write scripts with the entire system at your fingertips without the anothing command prompt... And as a bonus you have a proper readable logic flow
 

K12gamer

Member
I appreciate all the responses so far...I'll give some a try...although I'm not very advanced in programming.
I mainly use drag and drop techniques.

Maybe a feature (that prevents double loading) could be included into a future version of GM Studio?
I'll try to submit the idea...
Note: I no longer see the suggestion forum...
 

Dreadshadow

Member
Shall we use this code freely? Does it come under certain Terms or conditions?
The blog says nothing, so I sent an email to the author.
I will report back when I will get his reply.

People I got a reply.


"Hello, <my name was here>
Firstly please accept my apologies for the delayed response.
Appreciate the gesture :)
Yes you may freely use it for any purpose and alter as per your needs. It's not under any license control.
Best regards,
Nauman"​


So the VB script seems a great solution.





Maybe a feature (that prevents double loading) could be included into a future version of GM Studio?
I'll try to submit the idea...
On the other hand, maybe an update to the current version og GM Studio could do that too.
I mean why not having that feature soon?
 
Last edited:
Top