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.
TAI-Asked:
Who is Participating?
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

or

get-process > c:\file.txt
0
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.
0
Benjamin VoglarIT ProCommented:
type

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)
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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.
0
oBdACommented:
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

0

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!
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.