Get list of running windows applications using python
You could use powershell instead of WMIC to get the desired list of applications:
import subprocess
cmd = 'powershell "gps | where {$_.MainWindowTitle } | select Description'
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
for line in proc.stdout:
if line.rstrip():
# only print lines that are not empty
# decode() is necessary to get rid of the binary string (b')
# rstrip() to remove `\r\n`
print(line.decode().rstrip())
Getting an empty table?
Please note that on some systems this results in an empty table as the description seems to be empty. In that case you might want to try a different column, such as ProcessName
, resulting in the following command:
cmd = 'powershell "gps | where {$_.MainWindowTitle } | select ProcessName'
Need more columns/information in the output?
If you want to have more information, for example process id or path tidying up the output needs a bit more effort.
import subprocess
cmd = 'powershell "gps | where {$_.MainWindowTitle } | select Description,Id,Path'
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
for line in proc.stdout:
if not line.decode()[0].isspace():
print(line.decode().rstrip())
The output of cmd
is text formatted as a table. Unfortunately it returns more than just the applications we need, so we need to tidy up a bit. All applications that are wanted have an entry in the Description column, thus we just check if the first character is whitespace or not.
This is, what the original table would look like (before the isspace()
if clause):
Description Id Path
----------- -- ----
912
9124
11084
Microsoft Office Excel 1944 C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE
How to get list of current running application like Task Manager except applications running in background using JAVA?
You need here the powershell cmdlet called Get-Process.
Process process = new ProcessBuilder("powershell","\"gps| ? {$_.mainwindowtitle.length -ne 0} | Format-Table -HideTableHeaders name, ID").start();
new Thread(() -> {
Scanner sc = new Scanner(process.getInputStream());
if (sc.hasNextLine()) sc.nextLine();
while (sc.hasNextLine()) {
String line = sc.nextLine();
System.out.println(line);
}
}).start();
process.waitFor();
System.out.println("Done");
The output would be like this:
ApplicationFrameHost 15592
chrome 12920
cmd 21104
debian 13264
Far 3968
firefox 17240
HxOutlook 4784
idea64 13644
MicrosoftEdge 8024
MicrosoftEdgeCP 13908
MicrosoftEdgeCP 14604
mstsc 24636
notepad++ 9956
OUTLOOK 9588
pycharm64 6396
rider64 10468
Teams 11540
Telegram 16760
Done
How to get running applications in windows?
This may help:
Process[] processes = Process.GetProcesses();
foreach(Process p in processes)
{
if(!String.IsNullOrEmpty(p.MainWindowTitle))
{
listBox1.Items.Add(p.MainWindowTitle);
}
}
How to get list of running applications using PowerShell or VBScript
This should do the trick:
Set Word = CreateObject("Word.Application")
Set Tasks = Word.Tasks
For Each Task in Tasks
If Task.Visible Then Wscript.Echo Task.Name
Next
Word.Quit
http://msdn.microsoft.com/en-us/library/bb212832.aspx
How to get a list of all running GUI apps?
By GUI process I assume you mean processes that have a window attached. What you need is EnumWindows API which with a callback, and within the callback, you could use GetWindowThreadProcessId to get the process id of each window.
Here's an answer that's close enough to get you going: https://stackoverflow.com/a/21767578
Related Topics
Getview Returning Null When Fragment Has Been Created from an Activity
How to Set the Edittext Keyboard to Only Consist of Numbers on Android
Alphabetindexer with Custom Adapter Managed by Loadermanager
Android.Content.Activitynotfoundexception: Unable to Find Explicit Activity Class
What Should I Use Android Accountmanager For
Java.Lang.Illegalstateexception: Can Not Perform This Action After Onsaveinstancestate
Remove Icon/Logo from Action Bar on Android
How to Interface with the Badgeprovider on Samsung Phones to Add a Count to the App Icon
How to Handle Imeoptions' Done Button Click
Best Way to Add Activity to an Android Project in Eclipse
Android: Force Edittext to Remove Focus
How to Compile the Android Aosp Kernel and Test It with the Android Emulator
Resolved Versions for App (22.0.0) and Test App (21.0.3) Differ
Connectivitymanager Getnetworkinfo(Int) Deprecated
Android Custom Dropdown/Popup Menu
Blue Dot and Circle Is Not Shown on Mylocation Using Android Fused Location API