(without "PID" , "Session Name" etc etc)
what im doing wrong ?
thanks in advance
Code: Select all
Run, %ComSpec% /c tasklist > c:\tasklist.txt
loop, read, c:\tasklist.txt
{
StringSplit, Name, A_LoopReadLine, .exe
MsgBox % Name
}
return
Code: Select all
Run, %ComSpec% /c tasklist > c:\tasklist.txt
loop, read, c:\tasklist.txt
{
StringSplit, Name, A_LoopReadLine, .exe
MsgBox % Name
}
return
(https://autohotkey.com/docs/commands/St ... tm#command)Otherwise, Delimiters contains one or more characters (case sensitive), each of which is used to determine where the boundaries between substrings occur in InputVar.
Code: Select all
Run, %ComSpec% /c tasklist > C:\Users\g\Desktop\tasklist.txt ; change path
sleep 1000 ; If FileExist() would be a nifty alternative
loop, read, C:\Users\g\Desktop\tasklist.txt ; change path
{
Arr := StrSplit(A_LoopReadLine, A_space A_space) ; two spaces in a row because some names contain single spaces
If (Arr[1] != "")
MsgBox % Arr[1]
}
return
Try this other method also, I don't claim it to be better, just a different approach:if you have a better methood please share it
Code: Select all
#NoEnv
#SingleInstance Force
OutputFile := "R:\tasklist.txt"
RunWait, %ComSpec% /c tasklist > %OutputFile%
FileRead, TaskList, %OutputFile%
/* 💬
TaskList appears to be somewhat tabular.
Desired result is contained in first column.
Length of the columns seems to be related to length of "======".
*/
; naive approach: Look at only the first column
Length := 25 ; hardcoded 🤢, sufficient for this demo, ToDo: improve for real script
Result := ""
Loop, Parse, TaskList, `n, `r
Result .= SubStr(A_LoopField, 1, Length) "`n"
MsgBox % Result
ExitApp
Code: Select all
#NoEnv
#SingleInstance Force
OutputFile := "R:\tasklist.txt"
RunWait, %ComSpec% /c tasklist > %OutputFile%
FileRead, TaskList, %OutputFile%
; first column
MsgBox, % Column(TaskList, 1)
ExitApp
;-------------------------------------------------------------------------------
Column(Haystack, n) { ; return the n-th column from tasklist.exe output
;-------------------------------------------------------------------------------
Sum := 1, Start := [1], Lengths := [], Result := ""
Loop, Parse, Haystack, `n, `r
IfLess, A_Index, 3, continue
else if A_Index = 3
for each, Column in StrSplit(A_LoopField, A_Space)
Lengths.Push(L:=StrLen(Column)), Start.Push(Sum+=1+L)
else Result .= SubStr(A_LoopField, Start[n], Lengths[n]) "`n"
return Result
}
Users browsing this forum: jameswrightesq and 300 guests