AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Show unreferenced Microsoft Installer files to free up space

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
mbirth



Joined: 03 Oct 2005
Posts: 40
Location: DE, Berlin

PostPosted: Sun Feb 03, 2008 11:50 am    Post subject: Show unreferenced Microsoft Installer files to free up space Reply with quote

This script searches the registry for references to MSI packages located under C:\WINDOWS\Installer and lists missing or unused .msi packages.

You can then safely delete the unused ones.

Code:
#SingleInstance

Ctr := 0
Loop HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData, 2, 0
{
  Ctr++
  UserKey%Ctr% := A_LoopRegName
}
UserKey0 := Ctr

Ctr := 0
Loop %UserKey0%
{
  CurUK := UserKey%A_Index%
   
  Loop HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\%CurUK%\Patches, 2, 0
  {
    RegRead CurItem, %A_LoopRegKey%, %A_LoopRegSubkey%\%A_LoopRegName%, LocalPackage
    If (StrLen(CurItem) < 2)
      Continue
    Ctr++
    Patches%Ctr% := CurItem
  }
  Patches0 := Ctr
 
  Loop HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\%CurUK%\Products, 2, 0
  {
    RegRead CurItem, %A_LoopRegKey%, %A_LoopRegSubkey%\%A_LoopRegName%\InstallProperties, LocalPackage
    If (StrLen(CurItem) < 2)
      Continue
    Ctr++
    Patches%Ctr% := CurItem
  }
  Patches0 := Ctr
}

msg := ""
anomalies := ""
Loop %Patches0%
{
  CurFile := Patches%A_Index%
  msg .= CurFile
  IfNotExist %CurFile%
  {
    msg .= " (does not exist)"
    anomalies .= CurFile . " (does not exist)`n"
  }
  msg .= ", "
}

MsgBox %Patches0% items found:`n`n%msg%

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Ctr := 0
Loop %WINDIR%\Installer\*.msp, 0, 0
{
  CurFile := A_LoopFileLongPath
  Ctr++
  Files%Ctr% := CurFile
}
Files0 := Ctr
 
Loop %WINDIR%\Installer\*.msi, 0, 0
{
  CurFile := A_LoopFileLongPath
  Ctr++
  Files%Ctr% := CurFile
}
Files0 := Ctr

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

msg := ""
Loop %Files0%
{
  CurFile := Files%A_Index%
  StringLower CurFileL, CurFile
  NotThere := 1
  Loop %Patches0%
  {
    StringLower CurPatchL, Patches%A_Index%
    If (CurFileL = CurPatchL)
    {
      NotThere := 0
      Break
    }
  }
  msg .= CurFile
  If (NotThere = 1)
  {
    msg .= " (not referenced)"
    anomalies .= CurFile . " (not referenced)`n"
  }
  msg .= ", "
}

MsgBox %Files0% files found:`n`n%msg%
MsgBox Anomalies found:`n`n%anomalies%


Cheers,
-mARKUS
Back to top
View user's profile Send private message Visit poster's website
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Sat Feb 16, 2008 2:36 pm    Post subject: Reply with quote

Nifty!
_________________
GitHubScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group