Megadime Posted October 5, 2009 Posted October 5, 2009 I'd like to know how I can get the name of the script which is run by AutoIt3.exe. I know I could do it if I compiled the scripts and checked the processes for the name of the script + .exe. But how can I get the name of the running script if I've started it by clicking the right mouse button on the script-au3 and choosing "Run Script". Maybe it would be possible by getting the name of the system tray icon which is started, but I'd like to know if there's a better way.
Megadime Posted October 5, 2009 Author Posted October 5, 2009 Hey, thanx for the quick answer! One more thing, is there a way to get all scripts which are running? I have a script which is always running and this script needs to know which other scripts are started.
dantay9 Posted October 5, 2009 Posted October 5, 2009 (edited) You can use something similar to this: If ProcessExists("Process name") Then MsgBox(0, "", "The process exists") Else MsgBox(0, "", "The process doesn't exist") EndIf Edited October 5, 2009 by dantay9
Megadime Posted October 5, 2009 Author Posted October 5, 2009 Thanx, but I don't have a process corresponding to the script because I run the script by right clicking and choosing "Run Script" and not by starting a standalone executable. Is there another way?
dantay9 Posted October 5, 2009 Posted October 5, 2009 Here is a way to get the path of the file that created the process. The process name would be "AutoIt3.exe". expandcollapse popupFunc _WinAPI_ProcessGetFilename($vProcessID, $bFullPath = False) ; Not a Process ID? Must be a Process Name If Not IsNumber($vProcessID) Then $vProcessID = ProcessExists($vProcessID) ; Process Name not found (or invalid parameter?) If $vProcessID == 0 Then Return SetError(1, 0, "") EndIf Local $hProcess, $stFilename, $aRet, $sFilename, $sDLLFunctionName ; Since the parameters and returns are the same for both of these DLL calls, we can keep it all in one function If $bFullPath Then $sDLLFunctionName = "GetModuleFileNameEx" Else $sDLLFunctionName = "GetModuleBaseName" EndIf ; Get process handle (lod3n) Local $hProcess = DllCall('kernel32.dll', 'ptr', 'OpenProcess', 'int', BitOR(0x400, 0x10), 'int', 0, 'int', $vProcessID) If @error Or Not IsArray($hProcess) Then Return SetError(2, 0, "") ; Create 'receiving' string buffers and make the call ;If @AutoItUnicode Then ; Path length size maximum in Unicode is 32767 (-1 for NULL) $stFilename = DllStructCreate("wchar[32767]") ; we append 'W' to function names because these are the 'Wide' (Unicode) variants $aRet = DllCall("Psapi.dll", "dword", $sDLLFunctionName & 'W', _ "ptr", $hProcess[0], "ptr", Chr(0), "ptr", DllStructGetPtr($stFilename), "dword", 32767) ;Else #cs ; Path length size maximum otherwise is 260 (-1 for NULL) $stFilename=DllStructCreate("char[260]") $aRet=DllCall("Psapi.dll","dword",$sDLLFunctionName, _ "ptr",$hProcess[0],"ptr",Chr(0),"ptr",DllStructGetPtr($stFilename),"dword",260) EndIf #ce ; Error from either call? Cleanup and exit with error If @error Or Not IsArray($aRet) Then ; Close the process handle DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $hProcess[0]) ; DLLStructDelete()'s: $stFilename = 0 $hProcess = 0 Return SetError(2, 0, "") EndIf ;$aRet[0] = size of string copied over, minus null-terminator ;$stFilename should now contain either the filename or full path string (based on $bFullPath) $sFilename = DllStructGetData($stFilename, 1) DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $hProcess[0]) ; DLLStructDelete()'s $stFilename = 0 $hProcess = 0 Return SetError(0, 0, $sFilename) EndFunc ;==>_WinAPI_ProcessGetFilename
Megadime Posted October 5, 2009 Author Posted October 5, 2009 Thanks again. I've tried it, but the function returns "AutoIt3.exe" when clicking "Run Script" test.au3. Moreover, sorry for not knowing, but, provided it works, how can I get the names of the scripts running using this script?
dantay9 Posted October 5, 2009 Posted October 5, 2009 Oops! Probably should have tested before posting. I just had it lying around so I posted it. I am out of ideas, at least for now. Will post back if I find anything.
TurionAltec Posted October 5, 2009 Posted October 5, 2009 (edited) I was going to suggest trying something with _Singleton, but I really don't understand how this mutex thing works, so I was going to suggest creating a hidden GUI window with the script name. #include <GUIConstants.au3> $Form1 = GUICreate("Autoit3:"& @ScriptName, 237, 104, 193, 125) GUISetState(@SW_hide) While 1 sleep(2000) WEnd Save that as several au3 files with different names, and execute. Optionally just define the GUI title with something unique for each script, then it will return the same regardless of whether it's an au3, exe, or renamed. Next execute this script #include <GUIConstants.au3> #include <array.au3> $Form1 = GUICreate("Autoit3:"& @ScriptName, 237, 104, 193, 125) GUISetState(@SW_hide) $array=WinList("Autoit3:") _ArrayDisplay($array) ;_ArraySearch($array) ;You can use Arraysearch to search for a specific occurrence, ;Or just use Winlist or Winexist or WinGetHandle to begin with While 1 sleep(2000) WEnd Edited October 5, 2009 by TurionAltec
herewasplato Posted October 6, 2009 Posted October 6, 2009 Hey, thanx for the quick answer! One more thing, is there a way to get all scripts which are running? I have a script which is always running and this script needs to know which other scripts are started.Have each script name its hidden window something unique. See here for the code:http://www.autoitscript.com/forum/index.php?showtopic=103366&view=findpost&p=733081Then have the script that is always running look for those windows with a series of "If WinExists" lines. [size="1"][font="Arial"].[u].[/u][/font][/size]
rajeshontheweb Posted October 6, 2009 Posted October 6, 2009 this code detects if a specific au3 script is running - not the compiled exe.. there is a function which tries to retrieve all running autoit scripts i am not sure that would do for you, but give it a try... Started late is much better than having never started it!!!!Failure is another step towards success. I've been messing around with: Adding Entry to 'Hosts'File Information Lister (Logger)Yet Another AutoIT Error Handler Yet Another AutoIT Error Handler & Debugger Control your App's TaskBar Button YCurrency Ticker (Latest Release : 16 Apr 2009)_WinInetInternetCheckConnection UDF Symantec Definitions Lister UDF _GetLocalIPAddresses UDF UDF to get Special Folder Information WMI_NetworkAdapterConfiguration2Array WMI_CDRomDriveCapabilities _ScriptExists - Check if your au3 script is running!! Uninstaller UDF Get Version for your application (at script level or compiled stage) Uninstaller Pro - faster alternative to windows application removal applet
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