Skip to content

Commit adc6ad4

Browse files
committed
OX-02 P14 probe: screenshots and window inventory during VS startup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011ZFvhLx1fM9Gerg4dKsZcL
1 parent 6b8311a commit adc6ad4

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

‎scripts/vs/probe.ps1‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,39 @@ $major = $ver.Split('.')[0]
3434
$t0 = Get-Date
3535
$p = Start-Process $devenv -ArgumentList "/rootsuffix", "Exp", "`"$sln`"" -PassThru
3636
Log "devenv pid $($p.Id)"
37+
Add-Type -AssemblyName System.Windows.Forms, System.Drawing, UIAutomationClient, UIAutomationTypes
38+
$shot = 0
39+
function Shot($name) {
40+
try {
41+
$b = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
42+
$bmp = New-Object System.Drawing.Bitmap $b.Width, $b.Height
43+
$g = [System.Drawing.Graphics]::FromImage($bmp); $g.CopyFromScreen($b.Location, [System.Drawing.Point]::Empty, $b.Size)
44+
$bmp.Save((Join-Path $out "$name.png")); $g.Dispose(); $bmp.Dispose()
45+
} catch { Log "screenshot failed: $_" }
46+
}
47+
function Windows($procId) {
48+
$root = [System.Windows.Automation.AutomationElement]::RootElement
49+
$cond = New-Object System.Windows.Automation.PropertyCondition([System.Windows.Automation.AutomationElement]::ProcessIdProperty, $procId)
50+
foreach ($w in $root.FindAll([System.Windows.Automation.TreeScope]::Children, $cond)) {
51+
Log " window: '$($w.Current.Name)' class=$($w.Current.ClassName)"
52+
foreach ($c in $w.FindAll([System.Windows.Automation.TreeScope]::Descendants, [System.Windows.Automation.Condition]::TrueCondition)) {
53+
$n = $c.Current.Name
54+
if ($n -and $c.Current.ControlType.ProgrammaticName -match 'Button|Hyperlink|Text|Window') { Log " $($c.Current.ControlType.ProgrammaticName) '$n'" }
55+
}
56+
}
57+
}
3758
$dte = $null
3859
for ($k = 0; $k -lt 120 -and -not $dte; $k++) {
3960
Start-Sleep -Seconds 2
61+
if ($k % 15 -eq 0) { Shot ("start-{0:D3}" -f $k); Log "t=$($k*2)s"; Windows $p.Id }
4062
try { $dte = [System.Runtime.InteropServices.Marshal]::GetActiveObject("VisualStudio.DTE.$major.0") } catch { }
4163
}
64+
Shot "dte"; Windows $p.Id
4265
if (-not $dte) { Log "NO DTE after 240 s"; }
4366
else {
4467
Log "DTE after $([int]((Get-Date) - $t0).TotalSeconds) s: $($dte.Version) $($dte.Edition)"
4568
function Retry([scriptblock]$b) { for ($r = 0; $r -lt 60; $r++) { try { return & $b } catch { Start-Sleep -Milliseconds 1000 } } ; throw "gave up" }
46-
for ($k = 0; $k -lt 60; $k++) { try { if ($dte.Solution.IsOpen -and $dte.Solution.Projects.Count -gt 0) { break } } catch { } ; Start-Sleep 2 }
69+
for ($k = 0; $k -lt 60; $k++) { try { if ($dte.Solution.IsOpen -and $dte.Solution.Projects.Count -gt 0) { break } } catch { Log "dte call: $($_.Exception.Message)" } ; Start-Sleep 2; if ($k % 10 -eq 0) { Shot ("wait-{0:D3}" -f $k); Windows $p.Id } }
4770
Log "solution: $(Retry { $dte.Solution.FullName }) projects=$(Retry { $dte.Solution.Projects.Count })"
4871
$win = Retry { $dte.ItemOperations.OpenFile($cs) }
4972
$doc = Retry { $dte.ActiveDocument }

0 commit comments

Comments
 (0)