]> vilimpoc.org git repositories - dotfiles/blame_incremental - setup-windows-7-test-env.bat
dotfiles: drop the non-elevated ETW tracing, it never worked
[dotfiles] / setup-windows-7-test-env.bat
... / ...
CommitLineData
1@echo off
2setlocal
3
4rem ---------------------------------------------------------------------------
5rem setup-windows-7-test-env.bat - prepare a Windows 7 VM as a test target for
6rem native Windows software driven from the host by VBoxManage guestcontrol.
7rem
8rem Copy this file into the guest and run it there. It is idempotent: run it
9rem again after a rollback, or after any snapshot restore, to get the same box.
10rem
11rem Split in two halves, like the other provisioning scripts here:
12rem - the per-user half runs as you and needs no UAC prompt
13rem - the machine-wide half needs elevation and is SKIPPED (with a notice)
14rem when this runs unelevated, so an unattended run never blocks on a prompt
15rem
16rem That split matters more than usual here: a guestcontrol-launched process gets
17rem a UAC-filtered token even for an account in Administrators, so the elevated
18rem half can only be done by running this from an interactive Administrator
19rem prompt inside the guest. Everything the host harness actually needs is in
20rem the per-user half.
21rem ---------------------------------------------------------------------------
22
23echo(
24echo ============================================================
25echo Windows 7 test-target setup
26echo ============================================================
27
28rem --- Are we elevated? "net session" is the cheapest reliable probe. ---
29set "ELEVATED=0"
30net session >nul 2>&1
31if "%ERRORLEVEL%"=="0" set "ELEVATED=1"
32
33rem === PER-USER HALF (no UAC needed) =========================================
34
35echo(
36echo [user] Suppressing crash/hard-error dialogs
37rem A modal Windows Error Reporting dialog in the guest blocks a guestcontrol
38rem call until its timeout: the run looks like a hang, and a harness that scores
39rem a timeout as a failure will invent bugs that are not there. DontShowUI makes
40rem a crashing test process die immediately and return its exit code instead.
41reg add "HKCU\Software\Microsoft\Windows\Windows Error Reporting" /v DontShowUI /t REG_DWORD /d 1 /f >nul
42if errorlevel 1 echo WARN: could not set DontShowUI
43
44echo [user] Disabling the screen saver and monitor blanking
45rem The host watches this VM's screen with "VBoxManage controlvm screenshotpng".
46rem A blanked screen makes every screenshot useless.
47reg add "HKCU\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 0 /f >nul
48reg add "HKCU\Control Panel\Desktop" /v ScreenSaverIsSecure /t REG_SZ /d 0 /f >nul
49reg add "HKCU\Control Panel\Desktop" /v SCRNSAVE.EXE /t REG_SZ /d "" /f >nul 2>&1
50
51echo [user] Creating the staging directory C:\bb
52if not exist "C:\bb" mkdir "C:\bb"
53if not exist "C:\bb" echo WARN: could not create C:\bb
54
55echo [user] Mapping Z: to the VirtualBox shared folder "Downloads"
56rem Bulk file transfer over a shared folder is far faster than a copyto per file.
57rem The mapping is per-user and must be re-made in each new interactive session,
58rem which is exactly why it lives in this script rather than in a host-side note.
59if exist Z:\ goto :zdone
60net use Z: \vboxsvr\Downloads /persistent:yes >nul 2>&1
61if errorlevel 1 echo WARN: could not map Z: - is the shared folder attached to this VM?
62:zdone
63
64rem === MACHINE-WIDE HALF (needs elevation) ===================================
65
66if "%ELEVATED%"=="0" goto :skipadmin
67
68echo(
69echo [admin] Suppressing the system hard-error dialog (ErrorMode=2)
70reg add "HKLM\SYSTEM\CurrentControlSet\Control\Windows" /v ErrorMode /t REG_DWORD /d 2 /f >nul
71if errorlevel 1 echo WARN: could not set ErrorMode
72
73echo [admin] Disabling sleep and monitor timeout on AC
74powercfg -change -monitor-timeout-ac 0 >nul 2>&1
75powercfg -change -standby-timeout-ac 0 >nul 2>&1
76powercfg -change -disk-timeout-ac 0 >nul 2>&1
77powercfg -change -hibernate-timeout-ac 0 >nul 2>&1
78
79echo [admin] Turning off Windows Update automatic install
80rem An update reboot in the middle of a test run destroys the run and, worse,
81rem silently changes the system under test between two comparable results.
82reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /v AUOptions /t REG_DWORD /d 1 /f >nul 2>&1
83goto :adminend
84
85:skipadmin
86echo(
87echo [admin] SKIPPED - this process is not elevated.
88echo Run this script from an Administrator prompt INSIDE the guest to
89echo apply: ErrorMode=2, sleep/monitor timeouts, Windows Update policy.
90echo A guestcontrol-launched process cannot elevate itself, so these
91echo cannot be done from the host harness.
92:adminend
93
94rem === READINESS REPORT ======================================================
95rem Everything below only reports. A test that silently runs against a box
96rem missing a device reads as "the software under test refused" when the truth is
97rem "this VM never had one" - so the harness must know, up front, what is here.
98
99echo(
100echo ============================================================
101echo Readiness
102echo ============================================================
103echo(
104echo -- OS --
105ver
106echo arch=%PROCESSOR_ARCHITECTURE% user=%USERNAME% elevated=%ELEVATED%
107
108echo(
109echo -- Desktop Window Manager composition --
110rem SetWindowDisplayAffinity requires DWM composition. With composition OFF it
111rem fails with error 8 for every value, so any screen-capture protection under
112rem test is a silent no-op and its checks fail for a reason that has nothing to
113rem do with the code. Windows 7 runs the Basic theme (composition off) whenever
114rem the install is not activated.
115rem
116rem Ask the API, not a proxy for it. Two plausible-looking shortcuts are both
117rem WRONG on this box, measured: dwm.exe keeps running with composition off, and
118rem HKCU\...\DWM\Composition is the stored preference, not the live state. Both
119rem say ENABLED while DwmIsCompositionEnabled returns false.
120rem
121rem Two shapes to keep, both learned the hard way against guestcontrol:
122rem - PowerShell PRINTS the verdict; the batch does not capture it. Redirecting
123rem its stdout to a file, or capturing through for /f, hangs the whole run
124rem until the host's timeout fires.
125rem - the if/else is ONE line. Split across two, PowerShell treats the file as
126rem an incomplete command, waits on stdin and never exits. The <nul below is
127rem belt and braces for that whole class of hang.
128set "DWMPS=%TEMP%\w7env-dwm.ps1"
129> "%DWMPS%" echo Add-Type -TypeDefinition @^"
130>>"%DWMPS%" echo using System;
131>>"%DWMPS%" echo using System.Runtime.InteropServices;
132>>"%DWMPS%" echo public class D { [DllImport("dwmapi.dll")] public static extern int DwmIsCompositionEnabled(out bool e); }
133>>"%DWMPS%" echo ^"@
134>>"%DWMPS%" echo $e = $false
135>>"%DWMPS%" echo [void][D]::DwmIsCompositionEnabled([ref]$e)
136>>"%DWMPS%" echo if ($e) { " composition = ENABLED - screen-capture affinity is testable." } else { " composition = DISABLED - SetWindowDisplayAffinity fails with error 8 for every value, so a screen-capture-protection test here is testing nothing. Windows 7 forces the Basic theme while the install is not activated; activate it to test that path." }
137powershell -NoProfile -ExecutionPolicy Bypass -File "%DWMPS%" <nul
138del "%DWMPS%" >nul 2>&1
139
140echo(
141echo -- Printers (a print test needs at least one) --
142rem wmic, not PowerShell: no quoting to get wrong, and it is in the base install.
143wmic printer get Name,Default /format:table 2>nul | findstr /R /V "^$"
144if errorlevel 1 echo NONE - print tests will report "could not create a printer DC"
145
146echo(
147echo -- Audio capture devices (a microphone test needs at least one) --
148wmic sounddev get Name,Status /format:table 2>nul | findstr /R /V "^$"
149if errorlevel 1 echo NONE - enable audio for this VM in its VirtualBox settings
150
151echo(
152echo -- Shared folder --
153if exist Z:\ (echo Z: mapped) else (echo Z: NOT mapped)
154
155echo(
156echo -- Staging directory --
157if exist C:\bb (echo C:\bb present) else (echo C:\bb MISSING)
158
159echo(
160echo ============================================================
161echo Done. Re-run this after any snapshot restore.
162echo ============================================================
163endlocal