Can I get command line arguments of other processes from .NET/C?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Yes, but not through a simple built-in cross-platform .NET API. System.Diagnostics.Process can tell you a lot about another process, but command-line arguments are operating-system-specific and often protected by permissions. In practice, you read them through platform facilities such as WMI on Windows or /proc on Linux.
Windows approach with WMI
On Windows, a common solution is querying the Win32_Process class and reading its CommandLine property.
This is straightforward for administrative tools and diagnostics. You need a reference to System.Management, and the code works only on Windows.
Permissions matter. Some processes, especially system or elevated ones, may deny access unless your program has sufficient privileges.
Linux approach with /proc
On Linux, the usual source is /proc/<pid>/cmdline. That file contains the command line as NUL-separated strings.
The first element is usually the executable path or command name, and the remaining elements are the arguments. As on Windows, access depends on process ownership, container isolation, and system configuration.
There is no single portable answer
If your application targets multiple platforms, you usually branch by operating system and use the native mechanism for each one.
This is one of those cases where the operating system defines the capability much more than .NET does.
On macOS, this is generally more restricted and often requires native platform calls or elevated privileges. That is another reason there is no clean, universal managed API for the job.
When you control the target process
If you own both processes, reading the startup command line is often the wrong integration strategy. A more reliable design is to have the target process expose the data you need through:
- Named pipes
- HTTP or gRPC
- Shared files
- Environment-specific IPC
That avoids permission problems and keeps you from depending on platform-specific internals.
Common Pitfalls
The first pitfall is assuming .NET should expose a universal GetCommandLine() method for arbitrary processes. The runtime avoids that because the OS rules differ widely.
Another issue is access denial. Even if the API is correct, the operating system may hide command-line data for processes owned by other users or with elevated privileges.
Developers also forget that quoted arguments are already flattened into a platform-specific command line. Reconstructing exactly how the original command was typed can be harder than simply reading the current parsed form.
Finally, do not use this technique as a substitute for proper inter-process communication when you control both programs. It is a diagnostic tool first, not a robust contract.
Summary
- You can read another process's command line, but the method is OS-specific.
- On Windows, WMI and
Win32_Process.CommandLineare common options. - On Linux,
/proc/<pid>/cmdlineis the standard source. - Permissions and process ownership can block access.
- If both processes are yours, use explicit IPC instead of scraping startup arguments.

