mbirth
Joined: 03 Oct 2005 Posts: 40 Location: DE, Berlin
|
Posted: Sun Feb 03, 2008 11:50 am Post subject: Show unreferenced Microsoft Installer files to free up space |
|
|
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 |
|