KaFu Posted Friday at 09:24 AM Posted Friday at 09:24 AM (edited) Hello Team, I've encountered a strange behavior and currently can not track down the reasons. Maybe it's related to my specific Installation only? Or hopefully someone else can reproduce the issue. I've got two different approaches for a singleton script, one with CreateSemaphoreW and one with CreateFileMappingW. ; https://www.autoitscript.com/forum/topic/185203-new-_singleton-need-opinion/ ; by Terenz Local $hSemaphore = _SingletonSemaphore If _SingletonSemaphore("TestSemaphore", 1) = 0 Then MsgBox(16, "Warning", "An occurrence of test is already running") Exit EndIf MsgBox(64, "OK", "The first occurrence of test is running") DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hSemaphore) Func _SingletonSemaphore($sOccurrenceName, $iFlag = 0) Local Const $ERROR_ALREADY_EXISTS = 183 $hStartEvent = DllCall('kernel32.dll', 'handle', 'CreateSemaphoreW', 'struct*', 0, 'long', 0, 'long', 1, 'wstr', $sOccurrenceName) If @error Then Return SetError(@error, @extended, 0) Local $hError = DllCall("kernel32.dll", "dword", "GetLastError") If $hError[0] = $ERROR_ALREADY_EXISTS Then DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hStartEvent[0]) If @error Then Return SetError(@error, @extended, 0) If BitAND($iFlag, 1) Then Return SetError($hError[0], $hError[0], 0) Else Exit -1 EndIf EndIf Return $hStartEvent[0] EndFunc ;==>_SingletonSemaphore ; https://www.autoitscript.com/forum/topic/185203-new-_singleton-need-opinion/ ; by Terenz Local $hFilemapping = _SingletonMap("Testmapping", 1) If $hFilemapping = 0 Then MsgBox(16, "Warning", "An occurrence of test is already running") Exit EndIf MsgBox(64, "OK", "The first occurrence of test is running") DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hFilemapping) Func _SingletonMap($sOccurrenceName, $iFlag = 0) Local Const $ERROR_ALREADY_EXISTS = 183 Local $tInt64 = DllStructCreate('int64') Local $tQWord = DllStructCreate('dword;dword', DllStructGetPtr($tInt64)) DllStructSetData($tInt64, 1, 1) Local $iSize_HiDWord = DllStructGetData($tQWord, 2), $iSize_LoDWord = DllStructGetData($tQWord, 1) Local $hStartEvent = DllCall('kernel32.dll', 'handle', 'CreateFileMappingW', 'handle', -1, 'struct*', 0, 'dword', 0x0004, 'dword', $iSize_HiDWord, 'dword', $iSize_LoDWord, 'wstr', $sOccurrenceName) If @error Then Return SetError(@error, @extended, 0) Local $hError = DllCall("kernel32.dll", "dword", "GetLastError") If $hError[0] = $ERROR_ALREADY_EXISTS Then DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hStartEvent[0]) If @error Then Return SetError(@error, @extended, 0) If BitAND($iFlag, 1) Then Return SetError($hError[0], $hError[0], 0) Else Exit -1 EndIf EndIf Return $hStartEvent[0] EndFunc ;==>_SingletonMap Now if I compile the code and run it from the created executable, the first instance shows the "first occurrence" message and all subsequent instances (while the fist message box is still open) will result in the "already running" message box. If I leave the "first occurrence" message box open then run the code in parallel form SciTE, that code will produce another "first occurrence" message box, but I expected an "already running" message box here too. What might be the reason for the different results, running the code directly or through SciTE? Edited Friday at 09:25 AM by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Developers Jos Posted Friday at 09:58 AM Developers Posted Friday at 09:58 AM Did you check if there is another error returned by?: Local $hError = DllCall("kernel32.dll", "dword", "GetLastError") If $hError[0] = $ERROR_ALREADY_EXISTS Then SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
KaFu Posted Friday at 10:01 AM Author Posted Friday at 10:01 AM Returns 0 on first run as exe and also on subsequent runs in SciTE. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Nine Posted Friday at 11:39 AM Posted Friday at 11:39 AM Unable to reproduce your issue, works as expected with both semaphore and file mapping. (exe, au3, and scite) KaFu 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
KaFu Posted Friday at 01:38 PM Author Posted Friday at 01:38 PM It's getting even more strange. When I use x64 (#AutoIt3Wrapper_UseX64=y), it seems to work for me too in both directions. When I switch to x86 (#AutoIt3Wrapper_UseX64=n) and - start SciTE first, the executable can detect the existing filemapping - start the executable first, SciTE can not detect the existing filemapping OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Nine Posted Friday at 02:00 PM Posted Friday at 02:00 PM I tested that mixing x86 and x64, even #requireadmin with non elevated. All works for me. It is a bit like my child GUI issue...strange things can happen. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
Developers Jos Posted Friday at 02:19 PM Developers Posted Friday at 02:19 PM Are you using the x64 or x86 SciTE version? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
water Posted Friday at 02:22 PM Posted Friday at 02:22 PM My first questions would be: Which version of AutoIt do you run? Which version of Windows do you run? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
argumentum Posted Friday at 02:30 PM Posted Friday at 02:30 PM Win11pro 24H2 = All good, no mishaps. SciTE shouldn't be a factor as far as code not running. Then to replicate my question is what version of windows and type ( IoT, Multi-user, etc. ), is it hardware, a VM ( then VM platform ) ? Because it makes no sense, so the closer to your environment the better. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
KaFu Posted Friday at 02:41 PM Author Posted Friday at 02:41 PM (edited) I'm using Win10 Home 22H2 64bit, AutoIt 3.3.16.1 and SciTE 32-bit, Version 4.4.6, Mar 12 2022 10:14:43 Edited Friday at 02:44 PM by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
argumentum Posted Friday at 03:45 PM Posted Friday at 03:45 PM 1 hour ago, KaFu said: I'm using Win10 Home 22H2 64bit, AutoIt 3.3.16.1 and SciTE 32-bit, Version 4.4.6, Mar 12 2022 10:14:43 ok, am making a VM, same as yours, to test there. I've never had a home version running at home Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted Friday at 03:57 PM Posted Friday at 03:57 PM (edited) OS Build: 19035.3570 as it came back then for 22H2. What is yours @KaFu ? Edit: am updating to the latest, will see. Edited Friday at 04:25 PM by argumentum more Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted Friday at 05:18 PM Posted Friday at 05:18 PM (edited) Updated to the latest update ( 19045.5679 ) and can not replicate an issue. Edited Saturday at 02:17 PM by argumentum Removed the picture. Save space. KaFu 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
KaFu Posted Saturday at 09:54 AM Author Posted Saturday at 09:54 AM (edited) Thanks for testing and following up! So it really seems like there's something freaky in my own setup going on, good to know that at least it's not a common problem. I'll post a result, if I ever find out what it was 🙃. Best Regards Edited Saturday at 09:54 AM by KaFu argumentum 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
KaFu Posted Saturday at 02:54 PM Author Posted Saturday at 02:54 PM (edited) Hi @UEZ, did you ever solve this wow64 related topic here? I have the feeling that my topic could be related to the Wow64 redirection too. Is there anything Wow64 related that the autoit3.exe compiler does? Or in the manifest? My 32bit compiled scripts work as expected, un-compiled scripts running as 32 bit from SciTE fail. Edited Saturday at 02:55 PM by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Nine Posted Saturday at 03:40 PM Posted Saturday at 03:40 PM 45 minutes ago, KaFu said: Wow64 redirection Have you tried to disable redirection ? _WinAPI_Wow64EnableWow64FsRedirection(False) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
KaFu Posted Saturday at 03:58 PM Author Posted Saturday at 03:58 PM Yes, tried that, didn't change the outcome. Also strange is that _WinAPI_IsWow64Process() still reports 1 after the successful call of _WinAPI_Wow64EnableWow64FsRedirection(False), I would have expected a 0 then. But maybe _WinAPI_IsWow64Process() still is true even if the redirection has been disable. Also tried "Wow64DisableWow64FsRedirection", also didn't help. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
UEZ Posted Saturday at 05:14 PM Posted Saturday at 05:14 PM (edited) 2 hours ago, KaFu said: Hi @UEZ, did you ever solve this wow64 related topic here? I have the feeling that my topic could be related to the Wow64 redirection too. Is there anything Wow64 related that the autoit3.exe compiler does? Or in the manifest? My 32bit compiled scripts work as expected, un-compiled scripts running as 32 bit from SciTE fail. Hi KaFu, I now have a new notebook and have not looked into the problem since then because it works with ioa747's suggestion. Maybe I will make some tests. Btw, I have no problems with the CreateSemaphore code from post#1. Edit: still same problem with x86. #AutoIt3Wrapper_UseX64=n ShellExecute("C:\Users\Public\Desktop\Adobe Acrobat.lnk") Edited Saturday at 05:38 PM by UEZ KaFu 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
argumentum Posted Saturday at 05:34 PM Posted Saturday at 05:34 PM ..it is a pickle but, maybe a WinExists() or ProcessExists() serve as a _Singleton() of sorts ?, is just to not run it twice right ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
UEZ Posted Saturday at 05:57 PM Posted Saturday at 05:57 PM (edited) Just wondering why API call is different when using Freebasic: 'Coded by UEZ build 2025-03-29 #include "windows.bi" 'https://learn.microsoft.com/de-de/windows/win32/api/winbase/nf-winbase-createsemaphorea Function _WinAPI_CreateSemaphore(sOccurrenceName As String, InitCount As Long = 0, MaxCount As Long = 1) As HANDLE Dim As HANDLE hSemaphore = CreateSemaphore(NULL, InitCount, MaxCount, sOccurrenceName) If GetLastError() = ERROR_ALREADY_EXISTS Then Return 0 If hSemaphore = 0 Then Return -1 Return hSemaphore End Function Dim As HANDLE hSemaphore = _WinAPI_CreateSemaphore("1a2b3c4d5e6f") If hSemaphore = 0 Then End MessageBox(0, "An occurrence of this app (x64 or x86) is already running! Exiting...", "ERROR", MB_OK Or MB_ICONSTOP Or MB_TOPMOST) MessageBox(0, "Started", "Information", MB_OK Or MB_TOPMOST Or MB_ICONINFORMATION) If hSemaphore > 0 Then ReleaseSemaphore(hSemaphore, 1, NULL) CloseHandle(hSemaphore) End If In FB I call the CreateSemaphore with the key whereas in Autoit the first call is empty. Any other call with the compiled exe regardless if it is x86 or x64 it will show the MsgBox. Edited Saturday at 06:07 PM by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now