Zohar Posted September 4, 2014 Share Posted September 4, 2014 Hi If you run ProcessExplorer, and add a column called "Command Line", (can be found via RightClicking the Column Headers, and going to the Process Image tab) you can see the command that the process was started with. How can I get it programmatically inside AutoIt, for a process which I have its PID? Thank you Link to comment Share on other sites More sharing options...
computergroove Posted September 4, 2014 Share Posted September 4, 2014 (edited) I would think you could just use ProcessList https://www.autoitscript.com/autoit3/docs/functions/ProcessList.htm If you already know the pid then you can compare it to the array created by processList (remember to use a loop so if a new process starts then it will include it in the array). Share what you have for getting the PID (code) Edited September 4, 2014 by computergroove Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
spudw2k Posted September 4, 2014 Share Posted September 4, 2014 You could use WMI to retrieve the CommandLine. Change the value of $PID in the example below for a demo. ; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $PID = "0" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessID=" & $PID, "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "CommandLine: " & $objItem.CommandLine & @CRLF $Output = $Output & "ProcessId: " & $objItem.ProcessId & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Process" ) Endif Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Exit Posted September 4, 2014 Share Posted September 4, 2014 (edited) $PID = @AutoItPID ; just to pick a PID $oWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") If @error Then RunWait(@ComSpec & ' /c net start winmgmt ', '', @SW_HIDE) RunWait(@ComSpec & ' /c net continue winmgmt ', '', @SW_HIDE) $oWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") EndIf $oProcesses = $oWMI.ExecQuery("SELECT * FROM Win32_Process", "WQL", 0x30) For $oProcess In $oProcesses If $oProcess.ProcessId = $PID Then ExitLoop Next MsgBox(262144, Default, $oProcess.CommandLine, 0)Edit: spudw2k was quicker Edited September 4, 2014 by Exit App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Gianni Posted September 4, 2014 Share Posted September 4, 2014 this >link could also be of interest Zohar 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
spudw2k Posted September 4, 2014 Share Posted September 4, 2014 this >link could also be of interest Even better. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
UEZ Posted September 4, 2014 Share Posted September 4, 2014 (edited) Or just check out _WinAPI_GetProcessCommandLine function in the help file. Br, UEZ Edited September 4, 2014 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Gianni Posted September 4, 2014 Share Posted September 4, 2014 Or just check out _WinAPI_GetProcessCommandLine function in the help file. Br, UEZ Even better. Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Zohar Posted September 4, 2014 Author Share Posted September 4, 2014 Thank you all Or just check out _WinAPI_GetProcessCommandLine function in the help file. Br, UEZ I cannot find this function in the help file. I assume it's because I am not using the latest version.. I use v3.3.6.1.. Link to comment Share on other sites More sharing options...
Gianni Posted September 4, 2014 Share Posted September 4, 2014 Thank you all I cannot find this function in the help file. I assume it's because I am not using the latest version.. I use v3.3.6.1.. you can use >this then Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
BrewManNH Posted September 4, 2014 Share Posted September 4, 2014 Thank you all I cannot find this function in the help file. I assume it's because I am not using the latest version.. I use v3.3.6.1.. Yes, it's because you're using a very old version, so that function isn't in there. _WinAPIEx was added to the UDFs back in December 2013 to version 3.3.10.0. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Zohar Posted September 4, 2014 Author Share Posted September 4, 2014 (edited) OK I understand. BTW, maybe I should tell you what is the bigger picture. I am writing a small function that will prevent more than 1 instance of a script running. the code to do it is quite simple: Func CheckIfAnotherInstanceLikeMeExists() Local $Array_ProcessList =ProcessList(@ScriptName) Return ($Array_ProcessList[0][0]>1) EndFunc This code resides in a Common UDF that I created, and use among my scripts. The problem: It works for compiled scripts, but not for not-yet-compiled(au3) scripts. Why? Because compiled scripts have their process name like the name of the script, for example "SomeScript.exe". When scripts that are still in source are ran, their process name is "AutoIt3.exe". So I want my function to work also if the script is not compiled yet. I found via ProcessExplorer that the CommandLine data holds the name of the script. But is there another way to do it? Edited September 4, 2014 by Zohar Link to comment Share on other sites More sharing options...
Developers Jos Posted September 4, 2014 Developers Share Posted September 4, 2014 What's wrong with the _Singleton() UDF? Jos BrewManNH 1 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. Link to comment Share on other sites More sharing options...
jguinch Posted September 4, 2014 Share Posted September 4, 2014 Something like this ? #include <WinAPIProc.au3> $iPID = @AutoItPID $sFullExe = @AutoItExe $sExe = StringRegExpReplace($sFullExe, ".*\\", "") $aProcessList = ProcessList($sExe) For $i = 1 To $aProcessList[0][0] If $aProcessList[$i][1] = $iPID Then ContinueLoop $sFileName = _WinAPI_GetProcessFileName($aProcessList[$i][1]) If $sFileName = $sFullExe Then ConsoleWrite("Launched two times !") Exit EndIf Next Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Zohar Posted September 5, 2014 Author Share Posted September 5, 2014 jguinch: Thank you looks good, however I don't have this function too, due to my AutoIt version.. jos: I completely forgot about it.. I will use it now, thank you Link to comment Share on other sites More sharing options...
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