]> vilimpoc.org git repositories - dotfiles/blobdiff - README.md
dotfiles: stop the UAC launch line mangling its own arguments
[dotfiles] / README.md
index 6544500334e67d3930539cb2877d460d5437536b..aea40620d1cc29d4cb713a6039b6cdbd573edf25 100644 (file)
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ throwaway VM reachable from a Linux host.
 | --- | --- |
 | `setup-windows.bat` | Entry point. Runs the winget installs, then launches the elevated half and prints its log, then runs the non-elevated script. |
 | `setup-windows-no-uac.ps1` | The non-elevated, per-user half: WinMerge and BinSkim on the user `PATH`, and the global git config (identity, plus `core.sshCommand`). Can also be run directly from an ordinary prompt. |
-| `setup-windows-with-uac.ps1` | The elevated half, started via UAC by the batch file. Enables `ssh-agent`, installs the OpenSSH Client and Server capabilities and starts `sshd`, unpacks the `rsync-windows` release zip for this architecture (`rsync.exe` plus the `ssh.exe` it runs) into `C:\Tools\rsync` on the machine `PATH`, then installs Visual Studio 2022 Community with the required components, the WDK, and the Windows Performance Toolkit. Can also be run directly from an Administrator prompt. |
+| `setup-windows-with-uac.ps1` | The elevated half, started via UAC by the batch file. Enables `ssh-agent`, installs the OpenSSH Client and Server capabilities and starts `sshd`, unpacks the `rsync-windows` release zip for this architecture (`rsync.exe` plus the `ssh.exe` it runs) into `C:\Tools\rsync` on the machine `PATH`, then installs Visual Studio 2022 Community with the required components, the WDK, and the Windows Performance Toolkit, and finally grants one ordinary account the rights to collect ETW traces without elevation. Can also be run directly from an Administrator prompt — pass `-TraceUser DOMAIN\user` to say who gets those rights. |
 | `setup-windows-7-test-env.bat` | Prepares a **Windows 7 VM** as a test target driven from the host by `VBoxManage guestcontrol`. Copy it into the guest and run it there; it is idempotent, so re-run it after any snapshot restore. The per-user half needs no UAC (crash-dialog suppression, no screen blanking, a staging directory, the shared folder on `Z:`); the machine-wide half is skipped with a notice unless run elevated inside the guest. It then reports what the box can actually test: DWM composition, printers, audio capture devices. |
 
 ## Usage
@@ -118,6 +118,62 @@ throwaway VM reachable from a Linux host.
   (`.../releases/download/<tag>/<asset>`) instead.
 - Visual Studio is installed in three labelled passes (base workload, Clang/LLVM,
   XP toolset) so a failure identifies which component group is responsible.
+- **Windows Performance Analyzer is not part of Visual Studio.** VS has its own
+  Performance Profiler, which is a different, `.diagsession`-based tool and
+  cannot open an `.etl`. WPA ships with `xperf` and `wpr` in the Windows
+  Performance Toolkit, which exists in exactly two places: as an optional
+  *feature* of the Windows SDK (`OptionId.WindowsPerformanceToolkit`) and inside
+  the Windows ADK, which bundles the same toolkit. Whether the SDK install that
+  Visual Studio performs selects that feature varies by version, so the elevated
+  half **detects first** — `%ProgramFiles(x86)%\Windows Kits\10\Windows
+  Performance Toolkit`, its 64-bit twin, and the ADK location — and only falls
+  back to `winget install Microsoft.WindowsADK` when nothing is there. It then
+  re-asserts that directory on the machine `PATH` (the toolkit's own installer
+  usually does this, and the Start Menu gets *Windows Kits > Windows Performance
+  Toolkit* shortcuts for WPA and WPR). To install just the toolkit instead of the
+  whole ADK, run the standalone SDK setup with
+  `winsdksetup.exe /features OptionId.WindowsPerformanceToolkit /q`. A newer WPA
+  also exists in the Microsoft Store (`winget install --id 9N0W1B2BXGNZ --source
+  msstore`); it is not installed here because the Store source needs an
+  interactive, signed-in session, which the unattended elevated half does not
+  have.
+- **Tracing without a UAC prompt.** `xperf` and `wpr` fail for a standard user in
+  two different ways, because two different things are missing:
+
+  ```text
+  xperf -on base             -> NT Kernel Logger: Access is denied. (0x5)
+  wpr -start GeneralProfile  -> Failed to enable the policy to profile system performance.
+  ```
+
+  Creating or controlling *any* ETW session — even a user-mode one naming a
+  single provider — is checked against the security descriptor ETW keeps per
+  provider GUID under `HKLM\SYSTEM\CurrentControlSet\Control\WMI\Security`, whose
+  default grants the session-control rights to SYSTEM, Administrators, the
+  service accounts and `BUILTIN\Performance Log Users`, and to nobody else.
+  Switching on the *kernel* provider on top of that additionally needs the
+  `SeSystemProfilePrivilege` user right ("Profile system performance"), held by
+  default only by Administrators and `NT SERVICE\WdiServiceHost` — that is the
+  one `wpr` names. So the elevated half grants the privilege to the **group** and
+  puts the account in the group; enabling another account afterwards is just
+  `net localgroup "Performance Log Users" <user> /add`. `SeDebugPrivilege` is
+  deliberately *not* granted: CPU sampling and stack walks of your own processes
+  do not need it, and it is equivalent to handing out administrator.
+
+  Two consequences worth knowing. Both a privilege and a group membership are
+  read into the access token **at logon**, so the account must sign out and back
+  in — any new logon does it, and an `ssh` login into the box is the quick way to
+  check without dropping the desktop. And this only helps a **non-admin**
+  account: UAC hands an administrator a filtered token carrying just five
+  harmless privileges, so an admin's ordinary shell still cannot trace however
+  the policy reads. Verify from the target account, unelevated:
+
+  ```powershell
+  whoami /priv | findstr SeSystemProfilePrivilege
+  xperf -on base ; xperf -stop C:\Temp\trace.etl
+  ```
+
+  Analysis never needed any of this — `wpa.exe` opens an existing `.etl` as a
+  plain user. This is only about collection.
 - The scripts were extracted from a native Windows project, so the component
   selection is tuned for that: Spectre-mitigated runtimes, the v141/XP toolset,
   and driver-kit headers. Trim the component lists in the `.ps1` if you don't