|
| 1 | +# Check administrator privileges |
| 2 | +if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { |
| 3 | + Start-Process powershell "-File `"$PSCommandPath`"" -Verb RunAs |
| 4 | + exit |
| 5 | +} |
| 6 | + |
| 7 | +Add-Type -AssemblyName System.Windows.Forms |
| 8 | +Add-Type -AssemblyName System.Drawing |
| 9 | + |
| 10 | +function Console |
| 11 | +{ |
| 12 | + param ([Switch]$Show,[Switch]$Hide) |
| 13 | + if (-not ("Console.Window" -as [type])) { |
| 14 | + |
| 15 | + Add-Type -Name Window -Namespace Console -MemberDefinition ' |
| 16 | + [DllImport("Kernel32.dll")] |
| 17 | + public static extern IntPtr GetConsoleWindow(); |
| 18 | +
|
| 19 | + [DllImport("user32.dll")] |
| 20 | + public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow); |
| 21 | + ' |
| 22 | + } |
| 23 | + |
| 24 | + if ($Show) |
| 25 | + { |
| 26 | + $consolePtr = [Console.Window]::GetConsoleWindow() |
| 27 | + |
| 28 | + $null = [Console.Window]::ShowWindow($consolePtr, 5) |
| 29 | + } |
| 30 | + |
| 31 | + if ($Hide) |
| 32 | + { |
| 33 | + $consolePtr = [Console.Window]::GetConsoleWindow() |
| 34 | + #0 hide |
| 35 | + $null = [Console.Window]::ShowWindow($consolePtr, 0) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +function Get-CoreIndex { |
| 40 | + param ( |
| 41 | + [uint32]$CoreMask |
| 42 | + ) |
| 43 | + |
| 44 | + $coreList = "N/A" |
| 45 | + $isFirst = $false |
| 46 | + $currentCore = 0 |
| 47 | + $mask = $CoreMask |
| 48 | + |
| 49 | + while ($mask -gt 0) { |
| 50 | + if ($mask % 2 -eq 1) { |
| 51 | + if (-not $isFirst) { |
| 52 | + $coreList = "$currentCore" |
| 53 | + $isFirst = $true |
| 54 | + } else { |
| 55 | + $coreList += ", $currentCore" |
| 56 | + } |
| 57 | + } |
| 58 | + $mask = [math]::Floor($mask / 2) |
| 59 | + $currentCore++ |
| 60 | + } |
| 61 | + |
| 62 | + return $coreList |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +function Load-ListViewData { |
| 67 | + $listView.Items.Clear() |
| 68 | + $enumKey = "HKLM:\SYSTEM\CurrentControlSet\Enum" |
| 69 | + $categoryKeys = Get-ChildItem -Path $enumKey |
| 70 | + $showAllDevices = $chkShowAll.Checked |
| 71 | + |
| 72 | + foreach ($categoryKey in $categoryKeys) { |
| 73 | + $deviceKeys = Get-ChildItem -Path $categoryKey.PSPath |
| 74 | + foreach ($deviceKey in $deviceKeys) { |
| 75 | + $instanceKeys = Get-ChildItem -Path $deviceKey.PSPath |
| 76 | + foreach ($instanceKey in $instanceKeys) { |
| 77 | + $deviceDesc = $instanceKey.GetValue("DeviceDesc") |
| 78 | + if ($deviceDesc -like "*;*") { |
| 79 | + $deviceDesc = $deviceDesc.Split(";")[1] |
| 80 | + } |
| 81 | + |
| 82 | + $temporalPath = "$($instanceKey.PSPath)\Device Parameters\Interrupt Management\Affinity Policy - Temporal" |
| 83 | + $msiPath = "$($instanceKey.PSPath)\Device Parameters\Interrupt Management\MessageSignaledInterruptProperties" |
| 84 | + $Path = "$($instanceKey.PSPath)\Device Parameters\Interrupt Management\Affinity Policy" |
| 85 | + |
| 86 | + # Obtener Affinity y Priority |
| 87 | + $cores = $null |
| 88 | + $priority = $null |
| 89 | + $msiSupported = $null |
| 90 | + $messageLimit = $null |
| 91 | + |
| 92 | + $showDevice = $false |
| 93 | + if (Test-Path -Path $temporalPath) { |
| 94 | + $temporalKey = Get-Item -Path $temporalPath |
| 95 | + $bitmask = $temporalKey.GetValue("TargetSet", $null) |
| 96 | + if ($bitmask -ne $null) { |
| 97 | + $tempcores = Get-CoreIndex -CoreMask $BitMask |
| 98 | + $showDevice = $true |
| 99 | + } |
| 100 | + } else { |
| 101 | + $tempcores = "N/A" |
| 102 | + } |
| 103 | + |
| 104 | + if (Test-Path -Path $Path) { |
| 105 | + $defaultKey = Get-Item -Path $Path |
| 106 | + $priority = $defaultKey.GetValue("DevicePriority", $null) |
| 107 | + $policy = $defaultKey.GetValue("DevicePolicy", $null) |
| 108 | + $assignmentBytes = $defaultKey.GetValue("AssignmentSetOverride", $null) |
| 109 | + if ($assignmentBytes -ne $null) { |
| 110 | + if ($assignmentBytes.Length -eq 4) { |
| 111 | + # Convertir el array de bytes a UInt32 |
| 112 | + $assignment = [BitConverter]::ToUInt32($assignmentBytes, 0) |
| 113 | + $cores = Get-CoreIndex -CoreMask $assignment |
| 114 | + } |
| 115 | + } |
| 116 | + } else { |
| 117 | + $priority = "N/A" |
| 118 | + $policy = "N/A" |
| 119 | + $assignmentBytes = "N/A" |
| 120 | + |
| 121 | + } |
| 122 | + |
| 123 | + if (Test-Path -Path $msiPath) { |
| 124 | + $msiKey = Get-Item -Path $msiPath |
| 125 | + $msiSupported = $msiKey.GetValue("MSISupported", $null) |
| 126 | + $messageLimit = $msiKey.GetValue("MessageNumberLimit", $null) |
| 127 | + } |
| 128 | + |
| 129 | + if ($showAllDevices -or $showDevice) { |
| 130 | + $item = New-Object System.Windows.Forms.ListViewItem($deviceDesc) |
| 131 | + |
| 132 | + $item.SubItems.Add($tempcores) |
| 133 | + |
| 134 | + switch ($policy) { |
| 135 | + 0 {$strpolicy = "MachineDefault (0)"} |
| 136 | + 1 {$strpolicy = "AllCloseProc (1)"} |
| 137 | + 2 {$strpolicy = "OneCloseProc (2)"} |
| 138 | + 3 {$strpolicy = "AllProcInMachine (3)"} |
| 139 | + 4 {$strpolicy = "SpecifiedProc (4)"} |
| 140 | + 5 {$strpolicy = "SpreadMessagesAcrossAllProc (5)"} |
| 141 | + 6 {$strpolicy = "AllProcInMachineWhenSteered (6)"} |
| 142 | + |
| 143 | + default { |
| 144 | + $strpolicy = "N/A" |
| 145 | + } |
| 146 | + } |
| 147 | + $item.SubItems.Add($strpolicy) |
| 148 | + |
| 149 | + switch ($priority) { |
| 150 | + 1 {$strpriority = "Low (1)"} |
| 151 | + 2 {$strpriority = "Normal (2)"} |
| 152 | + 3 {$strpriority = "High (3)"} |
| 153 | + |
| 154 | + default { |
| 155 | + $strpriority = "N/A" |
| 156 | + } |
| 157 | + |
| 158 | + } |
| 159 | + $item.SubItems.Add($strpriority) |
| 160 | + |
| 161 | + switch ($msiSupported) { |
| 162 | + 0 {$strmsi = "Off"} |
| 163 | + 1 {$strmsi = "On"} |
| 164 | + |
| 165 | + default { |
| 166 | + $strmsi = "N/A" |
| 167 | + } |
| 168 | + } |
| 169 | + $item.SubItems.Add($strmsi) |
| 170 | + |
| 171 | + if ($messageLimit) { |
| 172 | + $item.SubItems.Add("$messageLimit Messages") |
| 173 | + } else { |
| 174 | + $item.SubItems.Add("N/A") |
| 175 | + } |
| 176 | + |
| 177 | + $item.SubItems.Add("$instanceKey") |
| 178 | + |
| 179 | + $listView.Items.Add($item) |
| 180 | + } |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + $listView.AutoResizeColumns([System.Windows.Forms.ColumnHeaderAutoResizeStyle]::ColumnContent) |
| 186 | +} |
| 187 | + |
| 188 | +# ocultar consola, crear form |
| 189 | +Console -Hide |
| 190 | +[System.Windows.Forms.Application]::EnableVisualStyles(); |
| 191 | +$form = New-Object System.Windows.Forms.Form |
| 192 | +$form.Text = "Device-Interrupt-Viewer" |
| 193 | +$form.ClientSize = New-Object System.Drawing.Size(780,440) |
| 194 | +$form.StartPosition = "CenterScreen" |
| 195 | +$form.MaximizeBox = $false |
| 196 | +$form.MinimizeBox = $false |
| 197 | +$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle |
| 198 | +$form.KeyPreview = $true |
| 199 | +$form.Add_KeyDown({ |
| 200 | + param($sender, $e) |
| 201 | + if ($e.KeyCode -eq [System.Windows.Forms.Keys]::F5) { |
| 202 | + Load-ListViewData |
| 203 | + } |
| 204 | +}) |
| 205 | + |
| 206 | +$listView = New-Object System.Windows.Forms.ListView |
| 207 | +$listView.Size = New-Object System.Drawing.Size(760, 400) |
| 208 | +$listView.Location = New-Object System.Drawing.Point(10, 10) |
| 209 | +$listView.View = [System.Windows.Forms.View]::Details |
| 210 | +$listView.FullRowSelect = $true |
| 211 | +$listView.GridLines = $true |
| 212 | + |
| 213 | +$columnHeader1 = New-Object System.Windows.Forms.ColumnHeader |
| 214 | +$columnHeader1.Text = "Device Description" |
| 215 | +$columnHeader2 = New-Object System.Windows.Forms.ColumnHeader |
| 216 | +$columnHeader2.Text = "Affinity" |
| 217 | +$columnHeader3 = New-Object System.Windows.Forms.ColumnHeader |
| 218 | +$columnHeader3.Text = "Policy" |
| 219 | +$columnHeader4 = New-Object System.Windows.Forms.ColumnHeader |
| 220 | +$columnHeader4.Text = "Priority" |
| 221 | +$columnHeader5 = New-Object System.Windows.Forms.ColumnHeader |
| 222 | +$columnHeader5.Text = "Msi" |
| 223 | +$columnHeader6 = New-Object System.Windows.Forms.ColumnHeader |
| 224 | +$columnHeader6.Text = "MsiLimit" |
| 225 | +$columnHeader7 = New-Object System.Windows.Forms.ColumnHeader |
| 226 | +$columnHeader7.Text = "KeyPath" |
| 227 | + |
| 228 | +$listView.Columns.AddRange(@($columnHeader1, $columnHeader2, $columnHeader3, $columnHeader4, $columnHeader5, $columnHeader6, $columnHeader7)) |
| 229 | +$form.Controls.Add($listView) |
| 230 | + |
| 231 | +$listView.Add_DoubleClick({ |
| 232 | + $selectedItem = $listView.SelectedItems[0] |
| 233 | + if ($selectedItem) { |
| 234 | + $keyPathValue = $selectedItem.SubItems[6].Text |
| 235 | + Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" -Name "LastKey" -Value $keyPathValue |
| 236 | + Start-Process -FilePath regedit |
| 237 | + } |
| 238 | +}) |
| 239 | + |
| 240 | +$chkShowAll = New-Object System.Windows.Forms.CheckBox |
| 241 | +$chkShowAll.Text = "Show All Devices" |
| 242 | +$chkShowAll.Size = New-Object System.Drawing.Size(120, 20) |
| 243 | +$chkShowAll.Location = New-Object System.Drawing.Point(10, 415) |
| 244 | +$chkShowAll.Add_CheckedChanged({ |
| 245 | + Load-ListViewData | Out-Null |
| 246 | +}) |
| 247 | +$form.Controls.Add($chkShowAll) |
| 248 | + |
| 249 | +Load-ListViewData | Out-Null |
| 250 | + |
| 251 | +[void]$form.ShowDialog() |
0 commit comments