runas

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package runas launches a process as a different user, given a credential.

This is the modern, in-process replacement for the legacy run-as trick:

cmd /c echo <password> | su.exe svc-install "cmd" -l

Every variant of that — su.exe, a keyed userexec.exe, runas piped a password — is doing one Win32 thing: CreateProcessWithLogonW. This package calls it directly, so there is no helper EXE, no echo pipe, and the password never lands on a command line or in the process list.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedPlatform = errors.New("winadmin/runas: only supported on Windows")

ErrUnsupportedPlatform is returned when run-as is invoked off Windows.

Functions

func Run

func Run(p secret.Provider, opts Options) error

Run resolves a credential from p and launches Options.CommandLine as that user. On non-Windows builds it returns ErrUnsupportedPlatform.

Types

type Options

type Options struct {
	// CommandLine is the full command line to execute, e.g.
	//   `C:\Windows\System32\cmd.exe /c icacls C:\foo /grant grp:M`.
	CommandLine string

	// WorkingDir is the starting directory ("" -> inherit).
	WorkingDir string

	// Wait blocks until the launched process exits.
	// When false, returns as soon as the process is created (@NOWAIT).
	Wait bool

	// LoadProfile loads the target user's profile (runas /profile). Needed when
	// the command reads HKCU or the user's environment.
	LoadProfile bool
}

Options controls how the command is launched.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL