Advertisement
Ubidibity

dwm process owner

Jul 13th, 2023 (edited)
1,180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.72 KB | Source Code | 0 0
  1. Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE Name = 'dwm.exe'" | ForEach-Object {
  2.     $owner = $_.GetOwner()
  3.     $username = $owner.User
  4.     $domain = $owner.Domain
  5.     Write-Output "Process ID: $($_.ProcessId), User: $domain\$username"
  6. }
  7.  
  8. try two:
  9. # Get all dwm.exe processes
  10. $dwms = Get-Process -Name dwm -ErrorAction SilentlyContinue
  11.  
  12. # Loop through the dwm.exe processes
  13. foreach ($dwm in $dwms) {
  14.     $processId = $dwm.Id
  15.     $owner = $null
  16.  
  17.     # Try to get the owner of the process using Get-WmiObject
  18.     $process = Get-WmiObject -Class Win32_Process | Where-Object { $_.ProcessId -eq $processId } -ErrorAction SilentlyContinue
  19.  
  20.     if ($process) {
  21.         $owner = $process.GetOwner()
  22.     }
  23.  
  24.     # If Get-WmiObject failed or didn't provide the owner, try using Get-Process
  25.     if (-not $owner) {
  26.         $owner = $dwm | Select-Object -ExpandProperty UserName
  27.     }
  28.  
  29.     Write-Output "Process ID: $processId, User: $owner"
  30. }
  31.  
  32. try three:
  33. # Get all dwm.exe processes
  34. $dwms = Get-Process -Name dwm -ErrorAction SilentlyContinue
  35.  
  36. # Loop through the dwm.exe processes
  37. foreach ($dwm in $dwms) {
  38.     $processId = $dwm.Id
  39.     $owner = $null
  40.  
  41.     # Try to get the owner of the process using Get-WmiObject
  42.     $process = Get-WmiObject -Class Win32_Process | Where-Object { $_.ProcessId -eq $processId } -ErrorAction SilentlyContinue
  43.  
  44.     if ($process) {
  45.         $owner = $process.GetOwner() | Select-Object -ExpandProperty User
  46.     }
  47.  
  48.     # If Get-WmiObject failed or didn't provide the owner, try using Get-Process
  49.     if (-not $owner) {
  50.         $owner = ($dwm | Get-Process | Select-Object -ExpandProperty UserName) -replace ".*\\"
  51.     }
  52.  
  53.     Write-Output "Process ID: $processId, User: $owner"
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement