Skip to content
Back to skills

Windows Env Variable Mgmt

ASecurity

Use when managing Windows PATH and environment variables.

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 10, 2026
ai-agentsgoshelldockerapi

Works with

  • api

Security analysis

A100/100

Scanned September 10, 2026

npx -y skills add LoopyLuci/Skills --skill windows-env-variable-mgmt --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Windows Env Variable Mgmt?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Windows Env Variable Mgmt
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/loopyluci-windows-env-variable-mgmt/badge)](https://www.skillsdirectory.com/skills/loopyluci-windows-env-variable-mgmt)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: windows-env-variable-mgmt
description: "Use when managing Windows PATH and environment variables."
category: software-development
tags: [windows, environment, path, env-vars, powershell]
---
# Windows Environment Variable Management

Managing PATH and environment variables on Windows.

## Scopes

| Scope | Visibility | Admin Needed | Storage |
|-------|-----------|-------------|---------|
| Process | Current process only | No | Memory |
| User | Current user | No | HKCU\Environment |
| Machine | All users | Yes | HKLM\SYSTEM\CurrentControlSet |

## Reading

```powershell
# Process scope (current session)
$env:PATH
$env:DOCKER_HOST

# User scope
[Environment]::GetEnvironmentVariable('PATH', 'User')
[Environment]::GetEnvironmentVariable('DOCKER_HOST', 'User')

# Machine scope
[Environment]::GetEnvironmentVariable('PATH', 'Machine')

# All scopes with fallback
[Environment]::GetEnvironmentVariable('PATH', 'User')
[Environment]::GetEnvironmentVariable('PATH', 'Machine')
$env:PATH  # combines User + Machine
```

## Writing

```powershell
# Process scope (temporary, current session only)
$env:MY_VAR = "value"

# User scope (persistent)
[Environment]::SetEnvironmentVariable('MY_VAR', 'value', 'User')

# Machine scope (persistent, needs admin)
[Environment]::SetEnvironmentVariable('MY_VAR', 'value', 'Machine')

# Delete
[Environment]::SetEnvironmentVariable('MY_VAR', $null, 'User')
```

## PATH Manipulation

```powershell
# Add to User PATH (idempotent)
$scope = 'User'
$path = [Environment]::GetEnvironmentVariable('PATH', $scope)
$newEntry = "C:\MyApp\bin"
if ($path -split ';' -notcontains $newEntry) {
    $path = $newEntry + ';' + $path
    [Environment]::SetEnvironmentVariable('PATH', $path, $scope)
}

# Remove Docker from PATH
$path = [Environment]::GetEnvironmentVariable('PATH', 'User')
$newPath = ($path -split ';' | Where-Object { $_ -notmatch '(?i)docker' }) -join ';'
[Environment]::SetEnvironmentVariable('PATH', $newPath, 'User')
```

## Docker Env Vars to Remove

```powershell
$dockerVars = @('DOCKER_HOST','DOCKER_CERT_PATH','DOCKER_TLS_VERIFY',
                'DOCKER_CONFIG','DOCKER_CONTEXT','DOCKER_API_VERSION')
foreach ($ev in $dockerVars) {
    [Environment]::SetEnvironmentVariable($ev, $null, 'User')
    [Environment]::SetEnvironmentVariable($ev, $null, 'Machine')
}
```

## Broadcast Change (Notify Windows)

```powershell
# After changing environment, notify running apps
$HWND_BROADCAST = 0xFFFF
$WM_SETTINGCHANGE = 0x001A
[User32.SendMessage]::SendMessage($HWND_BROADCAST, $WM_SETTINGCHANGE, 0, 'Environment')
```

## Pitfalls

- **Machine scope** requires admin -- use try/catch
- **PATH is cached** per process -- new processes pick up changes
- **`$env:PATH`** only shows Process scope (User+Machine combined at logon)
- **String length limit** -- PATH has ~2048 char limit in older Windows
- **%VARIABLE%** in PATH entries are expanded; set with `REG_EXPAND_SZ` type
- **`[Environment]::SetEnvironmentVariable`** with Machine scope auto-broadcasts

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…