How to get process arguments from command line (windows)

In a Windows 7 environment, I want to get the arguments of running processes from the command line. For example if file C:\textfile.txt is opened in notepad, the resulting process is "C:\Windows\system32\notepad.exe C:\textfile.txt". I want the C:\textfile.txt part.

There are user interface programs that can do this, such as Process Explorer or Windows' own Task Manager (through View -> Select Columns -> Command Line).

There are also utilities like pslist, tasklist or "wmic process get" that provide process details from the command line, but I was not able to find any options that give the arguments of the process.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Benjamin VoglarIT ProCommented:
Open powershell.

get-process | export-csv c:\file.csv


get-process > c:\file.txt
TAI-Author Commented:
get-process lists the process name (notepad.exe) but not the argument (C:\textfile.txt).

Is there any parameter to return the arguments as well? I skimmed through the man page for get-process but could not see one at a glance.
Benjamin VoglarIT ProCommented:

get-process | gm

and tell me witch propertie you like to get.

If you like to list just Notepad process type

get-process -name Notepad | fl *   (* - all properties of Notepad)
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

TAI-Author Commented:
None of the properties listed with "gm", nor the "fl *" option  returns the argument to the process.

MainWindowTitle property came close, as the file opened in Notepad is also in the title. Bu this is specific to Notepad (which I am using only as an example) and not a  general solution. When I test for a process that has an argument but no Window title, no property returns the argument.
Get-Process doesn't return the command line; you'll need to revert to WMI and the Win32_Process class. This has a property "CommandLine", which is the exact call of the process, including the program name (so something like notepad test.txt, or notepad.exe "C:\test.txt".
So something like this should get you started:
Get-WmiObject -Class Win32_Process | Select ProcessName, CommandLine

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TAI-Author Commented:
That is what I was looking for. Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 7

From novice to tech pro — start learning today.