 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
gavrielsinvani Cheater
Reputation: 0
Joined: 29 May 2019 Posts: 36
|
Posted: Sat Mar 28, 2020 8:58 am Post subject: I want to stop opening the software many times |
|
|
i have lua trianer And I want it to be open only once no multiple.
please help , thanks..
|
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sat Mar 28, 2020 10:43 am Post subject: |
|
|
Easy, just open it once, right?
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
 |
mindoff Advanced Cheater
Reputation: 0
Joined: 12 Jun 2016 Posts: 96
|
Posted: Wed Apr 01, 2020 8:57 pm Post subject: |
|
|
I know there is a Win32 API called CreateMutex can do this with C++ in my own win32 app.
That can prevent openning multiple instance,keep only one instance.
But I don't know how to do this in lua.
Want to see how lua version written.
Here is my C++ code
Code: |
#include <windows.h>
HANDLE win32Mutex = NULL;
...
win32Mutex = CreateMutex(NULL, FALSE, "MyWin32Mutex");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
CloseHandle(win32Mutex);
win32Mutex = NULL;
MessageBoxA(NULL, "Only 1 instance works", "Only 1 instance works", MB_OK);
return;//exit app
}
|
And I think there may be other way to check same instance,something like window title string if you give it an unique name.
|
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Thu Apr 02, 2020 6:41 am Post subject: |
|
|
First, if ported C++ code by @mindoff, maybe something like this in CE Lua:
Code: | function CreateMutex(lpMutexAttributes, bInitialOwner, lpName)
return executeCodeLocalEx("kernel32.CreateMutex",lpMutexAttributes, bInitialOwner, lpName)
end
function ReleaseMutex(hMutex)
return executeCodeLocalEx("kernel32.ReleaseMutex",hMutex)
end
function GetLastError(SetLastError, flag)
SetLastError = true
return executeCodeLocalEx("kernel32.GetLastError", SetLastError)
end
function CloseHandle(hObject)
return executeCodeLocalEx("kernel32.CloseHandle", hObject)
end
ERROR_ALREADY_EXISTS = 183
win32Mutex = nil
win32Mutex = CreateMutex(nil, false, "MyWin32Mutex")
if (GetLastError() == ERROR_ALREADY_EXISTS)
CloseHandle(win32Mutex)
win32Mutex = nil
showMessage("Only 1 instance works")
return
end |
But the code above seems not to work or need to modify. So, for me, if I want to prevent open multi instances for the same apps, I will use this:
Code: | list = createStringlist()
myprocess = "notepad.exe"
WM_SYSCOMMAND = 0x112
SC_MAXIMIZE = 0xF030
SC_MINIMIZE = 0xF020
SC_CLOSE = 0xF060
function closewindow(hWnd, msg, wParam, lParam)
return executeCodeLocalEx("user32.SendMessageA", hWnd, msg, wParam, lParam)
end
function avoidMultiInstances()
getProcesslist(list)
local count = 0
for i=0,list.count-1 do
if list[i]:find(myprocess) then
count = count + 1
end
end
if count > 1 then
--t.Enabled = false
local w = GetForegroundWindow()
if w ~= 0 then closewindow(w, WM_SYSCOMMAND, SC_CLOSE, 0) end
showMessage('Only one instance allowed')
return
end
list.clear()
end
t = createTimer(nil)
t.OnTimer = avoidMultiInstances
t.Interval = 200
t.Enabled = true |
Tested and works.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25785 Location: The netherlands
|
Posted: Thu Apr 02, 2020 6:55 am Post subject: |
|
|
sharedMemory is easier:
Code: |
l=allocateSharedMemoryLocal('MyTrainer',15) --allocates 4096 anyhow
if readStringLocal(l,11)=='DO NOT LOAD' then
showMessage('already loaded')
return -- or closeCE()
end
writeStringLocal(l,"DO NOT LOAD")
showMessage('First one')
|
as long as one process is open with the shared memory object called "MyTrainer" it will exist. Once the last process with it closes, it gets destroyed as well
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Thu Apr 02, 2020 7:24 am Post subject: |
|
|
Personally been using createPipe to prevent duplicates for some time, great alternatives tho
Code: | local pipeExists = createPipe('unique_pipe_name');
if (not pipeExists) then
return showMessage('duplicated');
end |
_________________
I'm rusty and getting older, help me re-learn lua. |
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|