jparker
8th March 2007 01:15 UTC
Deleting Dynamic Registry key
I am trying to delete a registry key. The problem is the name of the key is dependent on how many apps you have installed on your palm pilot. Here is the key :
[HKEY_CURRENT_USER\Software\U.S. Robotics\Pilot Desktop\Application6]
"Creator"=dword:53704e6f
"Conduit"="TFCnd.dll"
"Name"="MyApp"
"Priority"=dword:00000002
"Directory"="MyApp"
"Integrate"=dword:00000001
"Module"="C:\\Program Files\\MyApp.exe"
the Application6 could be any number. Here is the NSIS code I use to try and delete it :
loop:
EnumRegKey $1 HKCU "\Software\U.S. Robotics\Pilot Desktop" $0
StrCmp $1 "" done
IntOp $0 $0 + 1
ReadRegStr $1 HKCU "\Software\U.S. Robotics\Pilot Desktop\Application$1" "Name"
StrCmp $1 "MyApp" removeKey loop
removeKey:
DeleteRegKey HKCU "\Software\U.S. Robotics\Pilot Desktop\Application$1"
done:
SetAutoClose true
The code doesn't work, any ideas how to remove this key ?
Red Wine
8th March 2007 05:21 UTC
OutFile "test.exe"
Section "boo"
StrCpy $0 0
loop:
EnumRegKey $1 HKCU "Software\U.S. Robotics\Pilot Desktop" $0
StrCmp $1 "" done
IntOp $0 $0 + 1
MessageBox MB_OK "$$1 == [$1]"
ReadRegStr $2 HKCU "Software\U.S. Robotics\Pilot Desktop\$1" "Name"
MessageBox MB_OK "$$2 == [$2]"
StrCmp $2 "MyApp" removeKey loop
removeKey:
DeleteRegKey HKCU "Software\U.S. Robotics\Pilot Desktop\$1"
done:
SectionEnd
Comperio
8th March 2007 05:23 UTC
well, a couple issues:[list=1][*]First, ReadRegStr does not need the leading backslash.
Example: ReadRegStr $1 HKCU "Software\U.S. Robotics\Pilot Desktop\Application$0" "Name"
[*]Second, in this line:
ReadRegStr $1 HKCU "\Software\U.S. Robotics\Pilot Desktop\Application$1" "Name"
You are reading a completely bogus key becuase of what $1 is set to at that part of the code.[/list=1]
I assume that the "application#" part of the example would be where "#" is a number counted up, starting at one, and continuing for however many application are installed. If so, then something like this might work better. (I'm using LogicLib here just to make it easier to code. And this is un-tested, so you may have to tweak it a bit, but shoudl at least get you started:
!include LogicLib.nsh
...
StrCpy $0 0
ClearErrors
${Do}
IntOp $0 $0 + 1
ReadRegStr $1 HKCU "Software\U.S. Robotics\Pilot Desktop\Application$0" "Name"
${If} ${Errors}
${ExitDo}
${EndIf}
${If} "$1" == "MyApp"
DeleteRegKey HKCU "Software\U.S. Robotics\Pilot Desktop\Application$0" "Name"
${ExitDo}
${EndIf}
${Loop}
SetAutoClose true
edit:
I just hit submit as RedWine posted his... I guess now you have 2 options! :D