. '$PSScriptRoot\tc-common.ps1' $LogFile = Join-Path $script:DefaultLogDir 'rot-list.log' New-Item -ItemType Directory -Force -Path (Split-Path $LogFile) | Out-Null function Write-Log($m) { $line = "[{0}] {1}" -f (Get-Date -Format 'HH:mm:ss'), $m; Write-Host $line; Add-Content -Path $LogFile -Value $line -Encoding UTF8 } Write-Log "=== Enumerating ROT ===" Add-Type -TypeDefinition @' using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Text; public class RotEnum { [DllImport("ole32.dll")] static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable pprot); [DllImport("ole32.dll")] static extern int CreateBindCtx(int reserved, out IBindCtx ppbc); public static string[] List() { IRunningObjectTable rot; IBindCtx bc; GetRunningObjectTable(0, out rot); CreateBindCtx(0, out bc); IEnumMoniker em; rot.EnumRunning(out em); IMoniker[] mons = new IMoniker[1]; IntPtr fetched = IntPtr.Zero; var sb = new StringBuilder(); int n = 0; while (em.Next(1, mons, fetched) == 0) { string name; mons[0].GetDisplayName(bc, null, out name); sb.AppendLine(name); n++; } sb.Insert(0, n + " entries:\r\n"); return sb.ToString().Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); } } '@ -ReferencedAssemblies System.Runtime.InteropServices foreach ($e in [RotEnum]::List()) { Write-Log $e } Write-Log "=== ROT done ==="