ViciousXUSMC Posted June 2, 2017 Posted June 2, 2017 Ok so I am sure this is a easy one that I just can't figure out. So ProcessExists() can be used to see if a process exist, and it also returns the value of the PID of that process. Trying to keep a script short I wanted to do something like this. If ProcessExists("Notepad.exe") Then $sBinary = "Notepad.exe" ElseIf ProcessExists("WinWord.exe") Then $sBinary = "WinWord.exe" EndIf But I also need the PID in another variable. I could right after my Then put $iPID = @Error or @Extended to capture those return values and save them to a variable, is there a way to do something similar for non error values? Else I need to add more lines to the code that feels kinda sloppy and does the work twice. If ProcessExists("Notepad.exe") Then $sBinary = "Notepad.exe" $iPID = ProcessExists("Notepad.exe") ElseIf ProcessExists("WinWord.exe") Then $sBinary = "WinWord.exe" $iPID = ProcessExists("WinWord.exe") EndIf
anthonyjr2 Posted June 2, 2017 Posted June 2, 2017 (edited) I think you might be able to do this: If $iPID = ProcessExists("Notepad.exe") Then $sBinary = "Notepad.exe" ElseIf $iPID = ProcessExists("WinWord.exe") Then $sBinary = "WinWord.exe" EndIf Edited June 2, 2017 by anthonyjr2 UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=
mikell Posted June 2, 2017 Posted June 2, 2017 (edited) anthonyjr2, $iPID = undeclared variable and confusion comparison/assignment ? Why not Local $iPID, $sBinary, $var $var = ProcessExists("Notepad.exe") If $var Then $iPID = $var $sBinary = "Notepad.exe" EndIf $var = ProcessExists("WinWord.exe") If $var Then $iPID = $var $sBinary = "WinWord.exe" EndIf Edited June 2, 2017 by mikell
Danyfirex Posted June 4, 2017 Posted June 4, 2017 (edited) Just for fun. #include <Array.au3> Local $aArray[] = [ProcessExists("notepad.exe") ? ProcessExists("notepad.exe") : ProcessExists("WinWord.exe"),( ProcessExists("notepad.exe") ? "notepad.exe" : (ProcessExists("WinWord.exe") ? "WinWord.exe" : ""))] _ArrayDisplay($aArray) Saludos Edited June 4, 2017 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
ViciousXUSMC Posted June 5, 2017 Author Posted June 5, 2017 Mikels way is the clean way I was trying to see if I could get around since I had to declare each as a variable, and originally in my code I had an Else as well so it was If, ElseIf, and Else. The target question was, more or less is there a hidden @Return type thing I did not know about or some simple syntax I was missing. For this particular scenario the best solution was simply to run the check twice like I showed in the 2nd example, I did not want complicated hard to follow code and I did not want a lot of lines.
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