简体   繁体   中英

Getting which file is open in notepad using Python

I want to figure out whether a file is open in Notepad and a File open on Adobe Reader. If you open task manager, Go to process tab, You can see the "Command Line" column (If not, then Go to View->Select Column) which contains EXE path and opened file's path. If I get this information, I can easily parse this string to get opened file name (Along with it's path -- Bonus!)

I found an article , which shows the way by PowerShell using WMI. Is there any way to do the same using Python 2.7 I know there's a WMI library for python but not able to figure out how to implement:

Get-CimInstance Win32_Process -Filter "name = 'notepad.exe'" | fl *

I found a way using psutil

import psutil

for pid in psutil.pids():
    p = psutil.Process(pid)
    if p.name() == "notepad.exe":
        print p.cmdline()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM