Guest User

Untitled

a guest
Jan 20th, 2014
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Usage: regtest [-reg|-write|-read]
  2.  
  3. $key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
  4. $file = 'data.txt'
  5.  
  6. if ($args.count -eq 0) {
  7.     Write-Host "Usage: regtest [-reg|-write|-read]"
  8.     exit 1
  9. }
  10.  
  11. if ($args[0] -eq "-reg") {
  12.     Get-ChildItem -Path $key | ForEach-Object {
  13.         Write-Host "App name :" $_.GetValue('DisplayName')
  14.         Write-Host "Uninstall:" $_.GetValue('UninstallString')
  15.     }
  16. }
  17.  
  18. if ($args[0] -eq "-write") {
  19.     Get-ChildItem -Path $key | ForEach-Object {
  20.         "[" + $_.GetValue('DisplayName') + "]"
  21.         "# " + $_.GetValue('DisplayName')
  22.         "Uninstall=" + $_.GetValue('UninstallString')
  23.         ""
  24.     } > $file
  25. }
  26.  
  27. $group = ""
  28. if ($args[0] -eq "-read") {
  29.     Get-Content $file | ForEach-Object {
  30.         if ($_.trim().length -gt 0) {
  31.             $c = $_[0]
  32.             if ($c -ne "#") {
  33.                 if ($c -eq "[") {
  34.                     $group = $_.trim("[]")
  35.                 } else {
  36.                     $keyname, $value = $_.split("=")
  37.                     if ($keyname -eq "Uninstall") {
  38.                         Write-Host "App name :" $group
  39.                         Write-Host "Uninstall:" $value
  40.                     }
  41.                }
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment