Skip to content
⌘ NSIS Forum Archive

Loop with EnumRegValue only partially works

6 posts

The Raddish#

Loop with EnumRegValue only partially works

I have a bunch of laptops with pre-configured software that are being retasked. They are non-networked machines so using a GPO type deployment will not work for my application. I am creating an installer with specific software that will be used for deployment, but these laptops each have between 12-17 entries set to run on startup. Bad bad bad!

I wrote the following into my installer, but when it runs it only gets a half dozen or so then jumps out. I intend to log the installation and would like to detail each of the removed entries from the Run key, otherwise I would just brute-force it and use DelRegKey and then make a new, empty one.

; Remove everything from the startup menu and the Run registry key
StrCpy $0 0       ; initialize a loop counter
loop:
  ClearErrors
  EnumRegValue $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Run" $0
  IfErrors RunDone   ; if nothing is set to run, then jump out
  DetailPrint "Removed from startup: $1"  ; print what software is set to autostart
  DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" $1   ; delete the registry entry so it doesn't run automatically
  IntOp $0 $0 + 1   ; increment the loop counter
  Goto loop
RunDone: 
Am I missing something here? Why will it not cycle through all of the values in the Run key?
The Raddish#
Can you explain why?

Later in the script I was passing the number of removed entries, although that was pretty much for testing purposes.
Afrow UK#
Because when you delete the registry value there is 1 fewer values to enumerate so the index will point to the next value. Have you tried?

Stu
The Raddish#
I will on my next go-round. I have a VM set up to test most of the installer package, but there are a few items that appear to work on the VM but not on the notebooks. This is one of those items.

I'll report back if it works.