AndSoW Posted April 2, 2023 Posted April 2, 2023 (edited) This is a script that can open multiple same applications, as long as you find the mutex name, close the application thread opened before, and start a new thread program, you can achieve the purpose of opening multiple applications. (Script source ACN, and not tested, please test yourself) Do you have any other better method code? I want to be able to open each thread and return a process ID. Good luck! expandcollapse popup#Include <WinAPI.au3> Global Const $PROCESS_ALL_ACCESS = 0x000F0000 + 0x00100000 ;Global Const $DUPLICATE_CLOSE_SOURCE = 0x00000001 Global Const $MUTEX_ALL_ACCESS = 0x1F0001 $lPID = Run(_WeChatPath()) ConsoleWrite("PID: " & @TAB & @TAB & @TAB & $lPID & @CR) $MutexName = "_Mutex_Name" ConsoleWrite("MUTEX exists: "& @TAB & @TAB & _MutexExists($MutexName) & @CR) If _MutexExists($MUTEXname) == 1 Then $lhandle = _MutexOpen($MutexName) ConsoleWrite("MUTEX handle: " & @TAB & @TAB & $lhandle & @CR) $hprocess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $lPID , False) ConsoleWrite("Process handle: " & @TAB & $hprocess & @CR) $ret = DllCall("ntdll.dll", "long", "NtDuplicateObject", "long", $hprocess, "long", $lhandle, _ "long", 0, "long", 0, "long", 0, "long", 0, "long", $DUPLICATE_CLOSE_SOURCE) ConsoleWrite("@error on DllCall #1: "& @TAB & @error & @CR) ;ConsoleWrite("Return on DllCall #1: "& @TAB & $ret & @CR) $ret = DllCall("ntdll.dll", "long", "NtClose", "long", $lhandle) ConsoleWrite("@error on DllCall #2: "& @TAB & @error & @CR) ;ConsoleWrite("Return on DllCall #2: "& @TAB & $ret & @CR) ConsoleWrite("MUTEX exists: "& @TAB & @TAB & _MutexExists($MUTEXname) & @CR) If _MutexExists($MUTEXname) == 1 Then ConsoleWrite("You have failed!" & @CR) Else ConsoleWrite("You have won!" & @CR) EndIf Else ConsoleWrite("Mutex name not found, script terminated" & @CR) EndIf Func _MutexOpen($MutexName) Local $hMutex = DllCall("kernel32.dll", "hwnd", "OpenMutex", "int", $MUTEX_ALL_ACCESS, "int", 0, "str", $MutexName) If IsArray($hMutex) And $hMutex[0] Then Return $hMutex[0] Return 0 EndFunc Func _MutexExists($MutexName) Local $hMutex = DllCall("Kernel32.dll", "hwnd", "OpenMutex", "int", 0x1F0001, "int", 1, "str", $MutexName) Local $aGLE = DllCall("Kernel32.dll", "int", "GetLastError") If IsArray($hMutex) And $hMutex[0] Then DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hMutex[0]) If IsArray($aGLE) And $aGLE[0] = 127 Then Return 1 Return 0 EndFunc Edited April 8, 2023 by AndSoW Added code tags
AndSoW Posted April 4, 2023 Author Posted April 4, 2023 This is a problem script, has not found the reason, would like to ask you to help cattle!
Developers Jos Posted April 4, 2023 Developers Posted April 4, 2023 Moved to the appropriate AutoIt General Help and Support forum, as the AutoIt Example Scripts forum very clearly states: Quote Share your cool AutoIt scripts, UDFs and applications with others. Do not post general support questions here, instead use the AutoIt Help and Support forums. Moderation Team 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.
Developers Solution Jos Posted April 4, 2023 Developers Solution Posted April 4, 2023 3 hours ago, AndSoW said: like to ask you to help cattle! Gotta love g-translate 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.
Nine Posted April 4, 2023 Posted April 4, 2023 Cattle...I went to Alberta once (Province in Canada), and they leave beefs free in the mountains. So in order to prevent accidents, they have signs saying, "Help Cattle to stay Free". Funny... “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 Interface Object based on Tag
AndSoW Posted April 5, 2023 Author Posted April 5, 2023 21 hours ago, Jos said: Gotta love g-translate 😁😁😁I am a student from China, my English is not good, but I love learning, especially love AU3! Thank you for your platform and support, let me continue to learn and grow, thank you! In our China (Daniel) is a wonderful person, in your place should be called God!
argumentum Posted April 5, 2023 Posted April 5, 2023 On 4/2/2023 at 10:46 AM, AndSoW said: Script source ACN, and not tested On 4/4/2023 at 10:26 AM, AndSoW said: This is a problem script, has not found the reason So, not tested but has a problem. What are you trying to accomplish ( regardless of the script you posted ). Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting
AndSoW Posted April 8, 2023 Author Posted April 8, 2023 On 4/6/2023 at 12:41 AM, argumentum said: So, not tested but has a problem. What are you trying to accomplish ( regardless of the script you posted ). i 'm sorry! I have tested the script and achieved form thread exclusion using [_WeChattApp_Instance_Identity-MutexName], which allows for unlimited startup of the same program, but this feature is not effective. Can you help me? I think the script can achieve unlimited startup of the same program, but it can also not close existing programs that have already been opened?thank!
636C65616E Posted April 8, 2023 Posted April 8, 2023 (edited) Hey, Dunno how you're confident with msdn, windows native stuff, etc and maybe about programming itself ... But to make it simple (and i don't get why you asked that for so i just gonna explain how it works without example (don't have time to check the pasted code you provided, and mainly this kind of stuff is usually used for some sus application)). So in one line : You can't close the mutex itself. You have to duplicate it and free the copy : windows "kills" the original handle when you free the dup handle. /Regards NB: maybe this is not what you're trying to accomplish, but it's hard to understand your goal: openning infinite instances of a program limited by a mutex (that's what i explained) ? opening, killing then reopening a same program an infinite number of time ? Edited April 8, 2023 by 636C65616E
AndSoW Posted April 8, 2023 Author Posted April 8, 2023 1 hour ago, 636C65616E said: Hey, Dunno how you're confident with msdn, windows native stuff, etc and maybe about programmation itself ... But to make it simple (and i don't get why you asked that for so i just gonna explain how it works without example (don't have time to check the pasted code you provided, and mainly this kind of stuff is usually used for some sus application)). So in one line : You can't close the mutex itself. You have to duplicate it and free the copy : windows "kills" the original handle when you free the dup handle. /Regards NB: maybe this is not what you're trying to accomplish, but it's hard to understand your goal: openning infinite instances of a programme limited by a mutex (that's what i explained) ? opening, killing then reopening a same program an infinite number of time ? thank you!I have already processed it. Thank you for your attention
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