PsExec Command Builder

Build PsExec commands to run programs on remote Windows machines.

Advertisement

Build a PsExec command to run something on a remote Windows machine

PsExec runs a program on another Windows computer as if you had walked over and typed it there. This builder assembles the command from the target, the program you want to run, and the handful of switches that actually change behaviour. It produces text only — the page has no access to your network and cannot connect to anything.

The shape of every PsExec command is the same:

psexec \\PC01 -accepteula cmd

Target first, switches next, then the program and its arguments last. Anything after the program name belongs to the remote program, not to PsExec, which is the single most common syntax mistake.

Before anything else: PsExec is not built into Windows, and your EDR will notice

Two facts that matter more than any flag.

First, PsExec is a Microsoft Sysinternals utility, not a Windows component. It is not present on a stock installation. You download it as part of the Sysinternals Suite (or PSTools) and run it from wherever you unzipped it. The first run shows a licence dialog, which is why the builder always includes -accepteula — without it, a script that calls PsExec on a machine where it has not run before will hang on a dialog nobody is watching.

Second, PsExec is one of the most heavily flagged legitimate tools in existence. Ransomware crews and intrusion operators use it for lateral movement constantly, so endpoint detection products, SIEM rules and managed SOC playbooks treat its use as a signal. Expect any of the following:

  • The binary itself quarantined or blocked on download, sometimes under a generic “hacktool” classification.
  • An alert raised on the target machine when the PSEXESVC service is installed — a service installation writes System event ID 7045, which is a standard hunting rule.
  • A phone call from your security team, or a ticket auto-raised against you, if you use it during business hours without warning.

None of that means you should not use it. It means you should tell whoever runs detection before you do, on machines you administer, and it means that if PowerShell Remoting is available it is usually the lower-friction option. Use PsExec when you need what it uniquely gives you: SYSTEM context, an interactive process on someone’s visible desktop, or access to a machine where WinRM is not configured.

How it works, and what that requires

Understanding the mechanism explains every error message you will hit. PsExec connects to the target’s hidden administrative share, copies a small service executable there, installs and starts it as a Windows service, and then relays input and output over named pipes across that same SMB connection. When the remote program exits, the service is stopped and removed and the exit code is returned to you.

Which means all of the following must be true:

  • You hold local administrator rights on the target — installing a service is an administrative operation.
  • SMB reaches the target on TCP 445, and File and Printer Sharing is permitted through its firewall. On a machine whose network profile is Public, the Windows firewall blocks this by default.
  • The administrative shares exist. ADMIN$ and IPC$ are present by default on domain-joined machines but are often disabled by hardening baselines.
  • Remote UAC filtering is not in the way. Connecting with a local administrator account to a workgroup machine hands you a filtered, non-elevated token, and PsExec fails with access denied even though the credentials are correct. Domain accounts in the local Administrators group are not affected. The workaround is the LocalAccountTokenFilterPolicy registry value on the target — which weakens a deliberate protection, so weigh it rather than applying it reflexively.

The switches this builder emits

SwitchWhat it doesWhen you actually need it
\\hostThe target computer, by name or IP. The builder adds the leading backslashes for you if you leave them offAlways. Omit it and PsExec runs locally instead
-accepteulaSuppresses the first-run licence dialogAlways, in anything automated. The builder includes it unconditionally
-u DOMAIN\userConnect as a different accountWhen your current logon is not an administrator on the target, or you are crossing a trust boundary
-sRun the remote process as the LocalSystem accountAnything that needs full machine privilege: service repair, registry work under HKLM, tools that refuse to run as an ordinary admin
-iRun in the interactive desktop session so the logged-on user can see itAny program with a window. Without -i a GUI application starts invisibly and hangs there forever
-cCopy the specified program to the remote machine before running itRunning a tool that is not installed on the target — the point being you do not have to stage it first
-dDo not wait for the remote process to finishLong-running jobs, and anything you are firing at many machines in sequence

Notably absent: -p. The builder deliberately never writes a password onto the command line. If you supply a username, PsExec prompts for the password instead, which keeps it out of your shell history, out of process-creation event logs, and out of the command line that any other process on your machine can read. That is worth the extra keypress every time.

Other real PsExec switches the builder does not produce — add them by hand if you need them — include -h for the account’s elevated token, -e to skip loading the profile, -w to set the working directory, -f and -v to control overwriting with -c, -low and -high for priority, and @file to run against a list of computers.

Combinations that come up constantly

  • A shell on a remote machine: psexec \\PC01 -accepteula cmd. You get a prompt that behaves like a local one. Type exit to close it cleanly — killing the window can leave the service behind.
  • A SYSTEM shell: add -s. This is how you reach places even an administrator prompt cannot, and it is also exactly the pattern that lights up detection, so use it deliberately.
  • Show a message or app to the signed-in user: -i is mandatory. Without it, the process runs in session 0 where nobody can see or dismiss it.
  • SYSTEM, but visible: -s -i together. Common for running a repair tool on a user’s desktop while they watch.
  • Run a tool the target does not have: -c with the full local path to the executable. PsExec copies it, runs it, and removes it afterwards.
  • Fire and forget: -d so your console returns immediately. You lose the remote exit code and the output, so use it for things whose result you will check another way.

Error messages, translated

What you seeWhat it usually means
Couldn’t access <host>: Access is deniedNot an administrator on the target, or remote UAC filtering blocking a local account
The network path was not foundHost unreachable, name not resolving, or TCP 445 blocked by a firewall
The system cannot find the file specifiedThe program does not exist on the target. Either give a path that exists there, or use -c
Access is denied when copying PSEXESVCThe ADMIN$ share is disabled or unreachable
The command completes but nothing visibly happensA GUI program launched without -i, running invisibly in session 0
PsExec hangs with no outputThe remote program is waiting for input, or the licence dialog appeared — hence -accepteula
The binary vanished from your Downloads folderAntivirus quarantined it. Expected, not a corrupted download

If PsExec is interrupted badly, the PSEXESVC service can be left installed on the target. sc \\PC01 query psexesvc tells you, and sc \\PC01 delete psexesvc removes it.

When to use something else instead

PowerShell Remoting — Invoke-Command and Enter-PSSession over WinRM — is the modern answer for most remote execution. It is built in, authenticates and encrypts by default, returns objects rather than screen-scraped text, and does not install a service on the target, so it draws far less attention from detection tooling. Where PsExec still wins is running as SYSTEM, putting a process on the interactive desktop, staging a binary with -c, and reaching machines where WinRM was never enabled — which, in the field, is a great many of them.

Use it on machines you are authorised to administer, tell your security team when you do, and never leave a password on the command line.

Running against more than one machine

PsExec accepts a file of computer names in place of the target: psexec @hosts.txt -accepteula ipconfig /all, with one name or IP per line. The builder does not produce that form — it writes a single target — but the command it gives you is the template, and swapping \PC01 for @hosts.txt is the only change needed.

A few realities of running at scale. PsExec works through the list sequentially, so an unreachable machine costs you its full timeout before the run moves on; a stale list is the usual reason a fleet-wide command appears to hang. Adding -d stops PsExec waiting for each remote process to finish, which is much faster but discards both the output and the exit code, so only use it for actions you can verify another way. And every machine in the list gets a service installed and removed, which means every machine in the list generates the detection signal described above — running against fifty hosts at once is a reliable way to trigger an incident response.

If you find yourself doing this regularly, Invoke-Command -ComputerName (Get-Content hosts.txt) -ScriptBlock { ... } runs in parallel, returns structured results tagged with the machine each came from, and installs nothing. That is the better tool for fleet work; keep PsExec for the individual machine that needs SYSTEM, a visible desktop, or a binary staged onto it.

Frequently Asked Questions

What is PsExec used for?+

PsExec is a Sysinternals tool that runs programs and commands on remote Windows machines without installing anything on them. Admins use it to open a remote command shell, run diagnostics, or apply a quick fix across computers, with the output shown on their own console.

How do I run PsExec without exposing the password?+

Leave the -p switch off the command line. When you specify a user with -u but no -p, PsExec securely prompts you for the password at runtime instead of storing it in your shell history or logs, which is the recommended practice.

Why does antivirus flag PsExec?+

PsExec is a legitimate admin tool, but attackers and malware frequently abuse it for lateral movement across a network. Because of that reputation, EDR and antivirus products often flag or block it. Use it only on machines you manage, and expect to allow-list it in your security tooling.

What does the -s flag do in PsExec?+

The -s flag runs the remote command under the local SYSTEM account, the highest-privilege built-in account on the machine. It bypasses user-level restrictions, so use it only when a task genuinely requires SYSTEM rights, such as certain service or registry operations.

This tool is provided for informational and educational purposes only. All processing happens in your browser — no data is sent to or stored on our servers. While we strive for accuracy, we make no warranties about the completeness or reliability of results.