'Removes Unchecked StartUp Items from Msconfig

Dim WshShell
On Error Resume Next

If WScript.Arguments.length = 0 Then
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "wscript.exe", """" & _
WScript.ScriptFullName & """" &_
 " RunAsAdministrator", , "runas", 1
Else

sMsg = "This script will remove unchecked items from the MSConfig menu." & vbCr & vbCr _
 & "Adding information can unintentionally change or delete values and cause components to stop working correctly." _
 & "  If you do not trust the source of this information, do not add it to the registry."  & vbCr  & vbCr _
 & "Would you like to continue?"

sInput = MsgBox(sMsg, vbYesNo + vbInformation, "Paul's XP and Vista Tweaks")
If sInput = vbYes Then 

Set pReg = GetObject("winmgmts:!root/default:StdRegProv")
Const HKLM = &H80000002
RegKeyPHM = "Software\Microsoft\Shared Tools\MSConfig\startupfolder"
RegKeyJAM = "Software\Microsoft\Shared Tools\MSConfig\startupreg"

ResultsPHM = EnumKey(HKLM, RegKeyPHM, False)
If ResultsPHM = "" Then
ResultsPHM = space(5) & "(NONE)"
pBtns = 0

Else

pBtns = 4
pDelPrompt = "Would you like to DELETE any of these items?"

End If

pResults = "Disabled items in Your Startup Folder:" & vbcrlf & _
           ResultsPHM & vbcrlf & vbcrlf

ResultsJAM = EnumKey(HKLM, RegKeyJAM, False)
If ResultsJAM = "" Then
ResultsJAM = space(5) & "(NONE)"
If pBtns <> 4 Then pBtns = 0

Else

pBtns = 4
pDelPrompt = "Would you like to DELETE any of these items?"

End If

pResults = pResults & "Disabled items in Startup Reg Keys:" & vbcrlf & _
           ResultsJAM & vbcrlf & vbcrlf

If MsgBox(pResults & pDelPrompt, pBtns + 256, "Don't forget to uncheck your StartUp items in Msconfig.     ") <> 6 Then WScript.quit

EnumKey HKLM, RegKeyJAM, True
EnumKey HKLM, RegKeyPHM, True

Function EnumKey(Key, SubKey, pDelete)
Dim Ret()
pReg.EnumKey Key, SubKey, pKeys

On Error Resume Next
  
ReDim Ret(UBound(pKeys))
If Err = 13 Then Exit Function

On Error GoTo 0

For Count = 0 to UBound(pKeys)
If Not pDelete Then

Ret(Count) = space(5) & pKeys(Count)

Else

If MsgBox("Would You Like to DELETE this Item? "& vbcrlf & _
                            pKeys(Count) & "?" & vbcrlf, 4 + 256 , "This Item Can Be Deleted") = 6 Then
DeleteKey HKLM, SubKey & "\" & pKeys(Count)

End If

End If

Next

EnumKey = Join(Ret, vbcrlf)

End Function

Function DeleteKey(Key, SubKey)
	DeleteKey = pReg.DeleteKey(Key, SubKey)

End Function
End If
End If
