Skip to content

Command Line and Environment

Inside a Process

A command line is what a process was told when it started, the program followed by its arguments, such as a script to run or a service group to host. Two copies matter, one in the creation records written as the process starts and one in the process's own memory, where it can be rewritten later. The environment variables sit beside it and shape what the process loads and where it looks. Normal is the known command line for each Windows process, and an environment inherited from its parent. Read both copies, and treat any difference between them as a lead.

What It Is

A command line is the text a program is started with. It is the path of the program, then its arguments, the extra words that tell it what to do.

Why Windows Needs It
One program can do many jobs, so it needs to be told which. Notepad opens the file named after it, and each svchost.exe copy hosts the group of services named after -k.
An Everyday Example
When Notepad is started to open notes.txt, its command line reads notepad.exe C:\Users\alice\notes.txt. Windows records that text as the process starts, and keeps a copy in the process's own memory.
Two command lines, part by part
  1. notepad.exeThe Program
  2. C:\Users\alice\notes.txtThe File to Open
  1. svchost.exeThe Program
  2. -k DcomLaunchThe Group of Services to Host
  3. -pAn Option
Kept by the Kernel
The kernel keeps the image name and the path the process started from, so a memory image tool can set them beside the PEB's copy.
In the Process's Own Memory
The command line and environment sit in the PEB, in the process's own memory, which code in it can rewrite.

Two Copies of the Command Line

The creation records (event 4688 in the Security log with command line auditing on, Sysmon event 1, DeviceProcessEvents) keep the command line the process started with. The PEB holds the copy it has now, which Get-CimInstance, Windows.Memory.ProcessInfo and windows.cmdline read.

A process's PEB copy can be rewritten after it starts, so either copy alone can mislead. The arguments a sensor logged at creation may not be the ones the process acted on. A difference between the two is the lead, and what the process then did (its files, connections and children) shows which one it followed.

windows.malware.pebmasquerade adds two flags for a PEB path or command line whose recorded length disagrees with its text. The stable source fills them in swapped order, so read them as a pair.

Normal

ws-017,

Recorded at creation by Sysmon event 1 on ws-017, dana's workstation, on 23 Oct 2026, as an illustration.
NameCommand Line
wscript.exewscript.exe C:\IT\inventory.vbs

Suspicious

ws-017,

The same process's PEB copy at capture, as windows.cmdline reads it, also an illustration.
NameCommand Line
wscript.exewscript.exe C:\Users\Public\a.vbs
Command LineDiffers from the creation record: the two copies of a command line normally match. Odd Command Lines

The Environment

Environment variables are named settings a process inherits from its parent, such as PATH, the list of folders Windows searches for programs. No record of process creation keeps them, so only live collection (Windows.Memory.ProcessInfo, Windows.Detection.EnvironmentVariables) and windows.envars in a memory image show them.

windows.envars with its silent option hides the variables that come from the system and user environment in the Registry. That leaves the variables set while the process runs, where an odd one stands out.

Variables worth reading, and what normal is

VariableNormalWorth a Look
COMSPECC:\Windows\system32\cmd.exeAny other program
COR_ENABLE_PROFILING and COR_PROFILERUnset, or set by a profiling or monitoring tool you knowSet to 1 with a profiler you cannot explain, as its DLL loads into every .NET program that inherits it
COMPlus_ETWEnabledUnsetSet in a .NET program, whose own Event Tracing for Windows reports may then be missing
PATHSystem and user folders from the RegistryA folder a user can write to, ahead of the Windows folders

What Normal Looks Like

On a healthy machine this part looks like this.

  • Windows' own processes start with known command lines. Each process page gives one, and every svchost.exe names its -k group.
  • A child inherits its parent's environment by default, and most variables come from the system and user environment in the Registry.
  • COMSPEC points to cmd.exe under C:\Windows, which Velociraptor treats as normal and anything else as worth a look.
  • A process's creation record and its PEB's copy normally read the same.

Why It Matters

The command line turns a name into an action, naming the script, the DLL or the address. A copy in memory that disagrees with the creation record is a finding in itself.

Normal and Suspicious

A clean machine sits beside a suspicious one, and the pointer marks where to look.

Normal

A clean Windows 11 install

A service host on a clean install, whose command line names the group of services it hosts.
NameParentCommand Line
services.exewininit.exeNot stated
svchost.exeservices.exesvchost.exe -k DcomLaunch -p
See It in the Window

Suspicious

ws-042,

scvhost.exe on ws-042 at 10:08 on 12 Oct 2026, started by updsvc64.exe.
NameParentCommand Line
updsvc64.exeservices.exeC:\Windows\Temp\updsvc64.exe
scvhost.exeupdsvc64.exeC:\Windows\Temp\scvhost.exe
Command LineNo arguments after its path: a genuine svchost.exe names the service group it loads with -k. Odd Command Lines
See It in the Window

What a Malicious Example Shows

Each card is what malicious use of this part looks like, and where it shows.

  • A command line in memory that differs from the one recorded when the process started.Where it shows: windows.cmdline or Windows.Memory.ProcessInfo against event 4688 in the Security log, Sysmon event 1 or DeviceProcessEvents, and windows.malware.pebmasquerade's flags.
  • An encoded or obfuscated PowerShell command line.Where it shows: The text of Sysmon event 1 or Security event 4688. Event 4104 in the PowerShell Operational log, with script block logging on, shows the script blocks decoded.
  • COR_ENABLE_PROFILING set to 1 with a COR_PROFILER value in a process's environment.Where it shows: Windows.Detection.EnvironmentVariables or windows.envars, and the profiler DLL then shows in the module list.
  • COMPlus_ETWEnabled set in the environment of a .NET program.Where it shows: Windows.Detection.EnvironmentVariables or windows.envars.
  • A PATH whose first folder is one a user can write to.Where it shows: windows.envars or Windows.Memory.ProcessInfo, showing an unusual first folder in the process's PATH.

Live and in Memory

Each question has the tools that answer it on a running machine, and in a memory image, a copy of its memory saved to a file.

A creation record keeps the command line a process started with, while live tools and windows.cmdline read the copy in the PEB, the process's own memory. A process can rewrite that copy after it starts, so read both and treat a difference as a lead. Console buffers and PowerShell's script block log add what was typed and what a script really ran.

  • What was it started with, and what does it hold now?

    On a Running Machine

    In a Memory Image

  • Was the PEB rewritten after the process started?

    On a Running Machine

    In a Memory Image

  • What was typed at a prompt?

    On a Running Machine

    In a Memory Image

  • Which environment variables does it run with?

    On a Running Machine

    In a Memory Image

A command line is kept in several places, each written at a different moment and switched on in a different way. Read them side by side when the copies disagree.

Where each copy of a command line lives

Record or PlaceField That Holds ItWhen It Is WrittenWhat to Watch For
Event 4688 in the Security logProcess Command LineAt creation, only when the policy Include command line in process creation events is onAnyone who can read the Security log reads every argument, passwords typed into a command included
Sysmon event 1CommandLine and ParentCommandLineAt creation, with the parent's own command lineNothing after the start, so a later change to the PEB is not recorded
DeviceProcessEventsProcessCommandLine and InitiatingProcessCommandLineAt creationThe same, what the process started with
Event 4104 in the PowerShell Operational logThe text of each script blockAs PowerShell processes each script block, with script block logging onWhat an encoded command really ran. PowerShell 7 writes to its own log
The PEB, live or in memoryWin32_Process's CommandLine, or windows.cmdlineRead at the moment you lookCan be rewritten after the start, and is gone once the process exits

To take it offline, read Dumping a Process and Memory

What It Misses

Every way of looking has gaps, so cover these from another source.

  • A command line shows what a process was told to do, not what it did. What a script ran needs event 4104 in the PowerShell Operational log, or the script file itself.
  • Event 4688 in the Security log records no command line unless the policy Include command line in process creation events is on. The PEB copy is gone once a process exits.

False Positives

These look odd but are normal, so rule them out before you act.

  • Administrators, legitimate scripts and applications run encoded PowerShell too, so judge the parent, the account and the decoded script, not the encoding alone.

Red Flags It Explains

Each red flag below is confirmed by reading this part.

Checks That Use It

These checks read this part as one of their steps.

Sources

MITRE ATT&CK is a free public catalogue of the techniques attackers use. Each technique has an ID, such as T1055 for Process Injection, so defenders can name the same behaviour the same way. Reading this part helps find these techniques.