@@ -148,17 +148,56 @@ $script:PSScriptParams = $script:PSBoundParameters # volatile
148148
149149. " $ScriptRootPath \INCLUDE.ps1"
150150
151- $VersionMinForAddin = [Version ]' 11.0.7 ' # This version and later use SDK v1.0.7 +
152- $VersionForProcessors = [Version ]' 11.8.0' # Version 11.8.262 and later requires: -Processors (Earlier versions allow it.)
151+ $VersionMinForAddin = [Version ]' 11.7.383 ' # This public WPA version and later use SDK v1.2.2 +
152+ $VersionForProcessors = [Version ]' 11.8.0' # WPA Version 11.8.262 and later requires: -Processors (Earlier versions allow it.)
153153
154- $AddInPath = " $script :ScriptHomePath \ADDIN" # Uses SDK v1.0.7+
154+ $AddInPaths = @ (
155+ " $script :ScriptHomePath \ADDIN" # Released ZIP with NetBlame Plug-in
156+ " $script :ScriptRootPath \NetBlame\bin\*" # Cloned project with built NetBlame Plug-in
157+ )
155158
156159$WPA_Version_RegPath = " $script :RegPathStatus \WPA-Plugin" # $RegPathStatus also used for SetProfileStartTime, etc.
157160
158161# Most modern versions of WPA list/accept these plug-in names via: WPA -listplugins -addsearchdir MSO-Scripts\BETA\ADDIN
159162$ETW_Plugins_Default = ' Event Tracing for Windows' , ' Office_NetBlame'
160163
161164
165+ <#
166+ Find the path that contains the most recent (or 'Release') NetBlame plug-in: NetBlameAddIn.dll
167+ If this installation was downloaded and unzipped from the Release site, then it will be in: BETA\ADDIN
168+ If this installation was cloned and built then it will be in NetBlame\bin\Release|Debug\net8.0
169+ #>
170+ function GetAddinPath
171+ {
172+ # List the various path(s) which contain NetBlameAddIn.dll
173+
174+ $moduleName = ' NetBlameAddIn.dll'
175+ $paths = Resolve-Path - Path $AddInPaths - ErrorAction:SilentlyContinue
176+ $pathIOs = $paths | ForEach-Object { Get-ChildItem - Path $_ - Filter $moduleName - File - Recurse - ErrorAction:SilentlyContinue }
177+
178+ if (! $pathIOs )
179+ {
180+ Write-Err " The `" NetBlame`" WPA Plug-in ($moduleName ) was not be found at any of these locations:"
181+ foreach ($path in $AddInPaths ) { Write-Err " `t $path " }
182+ foreach ($path in $paths ) { Write-Err " `t $ ( $path.Path ) " }
183+
184+ Write-Info " Please see: https://github.com/Microsoft/MSO-Scripts/wiki/Network-Activity"
185+
186+ # No reason to go on!
187+ exit 1
188+ }
189+
190+ # Choose the path which contains the most recent NetBlameAddIn.dll, or a recent 'Release' version.
191+ $pathIORel = $pathIOs | Where-Object { $_.FullName -like ' *Release*' }
192+ if ($pathIORel ) { $pathIOs = $pathIORel } # filter to 'Release' version(s)
193+ $pathIO = $pathIOs | Sort-Object { $_.LastWriteTime } - Descending | Select-Object - First 1
194+ $path = (Split-Path - Path $pathIO.FullName - Parent)
195+
196+ Write-Status " NetBlame Plug-in found at: $path "
197+ return $path
198+ }
199+
200+
162201<#
163202 Return a quoted, comma-separated string of WPA Plug-ins needed for this script.
164203 Usually: "Event Tracing for Windows","Office_NetBlame"
@@ -168,7 +207,8 @@ function GetPluginsList
168207Param (
169208 [Version ]$WpaVersion
170209)
171- [string []]$ETW_Plugins = GetRegistryValue $WPA_Version_RegPath $WpaVersion.ToString ()
210+ [string []]$ETW_Plugins = $Null
211+ if ($WpaVersion ) { $ETW_Plugins = GetRegistryValue $WPA_Version_RegPath $WpaVersion.ToString () }
172212 if (! $ETW_Plugins ) { $ETW_Plugins = $ETW_Plugins_Default }
173213
174214 return ($ETW_Plugins | ForEach-Object { " `" $_ `" " }) -join ' ,'
@@ -307,30 +347,38 @@ Param ( # $ViewerParams 'parameter splat'
307347 Write-Action " `n This network analyzer plug-in will not likely work before Windows 10.`n "
308348 }
309349
310- # The viewer: Windows Performance Analyzer (WPA)
350+ # Find the most recent version of the viewer: Windows Performance Analyzer (WPA)
351+
311352 $WpaPath = GetWptExePath " WPA.exe"
312353 $Version = GetFileVersion $WpaPath
313354
314- if (! $Version -or ( $Version -lt $VersionMinForAddin ) )
355+ if ((IsRealVersion $Version ) -and ! $ env: WPT_PATH )
315356 {
316- if ($Version )
317- {
318- Write-Err " Found an older version of the Windows Performance Analyzer (WPA): $Version "
319- }
320- elseif ($WpaPath -ne ' WPA' )
321- {
322- Write-Err " Found an unknown version of the Windows Performance Analyzer (WPA)."
323- }
324- Write-Err " The minimum required version is: $VersionMinForAddin "
357+ # Find an even newer version, maybe.
325358
326- if ($WpaPath -ne ' WPA' ) { WriteWPTInstallMessage " wpa.exe" } # Else GetWptExePath wrote the message
359+ $WpaPath2 = GetWptExePath " WPA.exe" - Silent - AltPath
360+ $Version2 = GetFileVersion $WpaPath2
327361
328- if ($Version ) { exit 1 } # else maybe we found WPA.bat, etc.
362+ if ($Version2 -and ($Version2 -gt $Version ))
363+ {
364+ $WpaPath = $WpaPath2
365+ $Version = $Version2
366+ }
329367 }
330368
331- if (! (Test-Path - PathType container - Path $AddInPath - ErrorAction:SilentlyContinue))
369+ <#
370+ 1. Found a recent WPA
371+ 2. Found an old WPA
372+ 3. Found WPA.bat or stub WPA.exe without 'real' version info
373+ 4. Found no WPA (but try to launch "WPA" anyway)
374+ #>
375+ if ((IsRealVersion $Version ) -and ($Version -lt $VersionMinForAddin ))
332376 {
333- Write-Err " Could not find the NetBlame add-in path: $AddInPath "
377+ # Case 2: Do not proceed.
378+
379+ Write-Err " Found an older version of the Windows Performance Analyzer (WPA): $Version "
380+ Write-Err " The minimum version for this analysis is: $VersionMinForAddin "
381+ WriteWPTInstallMessage " WPA.exe"
334382 exit 1
335383 }
336384
@@ -349,7 +397,7 @@ Param ( # $ViewerParams 'parameter splat'
349397 $ExtraParams += GetArgs - processors $Processors
350398 }
351399
352- $ExtraParams += GetArgs - addsearchdir " `" $AddInPath `" " - NoSymbols
400+ $ExtraParams += GetArgs - addsearchdir " `" $ ( GetAddinPath ) `" " - NoSymbols
353401
354402 # Now load LaunchViewerCommand and related.
355403
0 commit comments