1

Being newbie with "Inno Setup" and "Inno Script Studio", I now want to Reg-Delete a Key that was created during one of the installations included in my installer. Meaning it should be the very last step, because the key will not exist at an earlier time of my install-routine.

Actually, I am only lacking the right Pascalscript-syntax.

I know how I can do this through the [Registry] part, however then I wouldn't know how to do it as the last step.

[Registry]
Root: "HKLM"; Subkey: "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "Example"; Flags: deletekey

Through [Code] section I tried this to make it the last step, but the compiler keeps telling me my command is unknown:

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    Log('Installation finished. Deleting connection string.');
    RegDeleteKey(HKEY_LOCAL_MACHINE, 'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run', 'Example');
  end;
end;

"RegDeleteKey" is not an existing command. By looking commands up, I only found "RegQueryStringValue", "RegWriteStringValue", "RegDeleteStringValue" (won't do the job) - it's all not what I'm looking for. I want to delete the key, no matter what's the value. In hopes that the solution is simple... thanks in advance.

Yauhun
  • 103
  • 2
  • 9
  • Possible duplicate of [Inno Setup: Removing a problematic registry key left by another program](http://stackoverflow.com/questions/19600188/inno-setup-removing-a-problematic-registry-key-left-by-another-program) – Scott Feb 03 '17 at 15:10
  • @Scott - no, it is not, because I in fact did check the topic you linked. However, I want to delete a key at the end of my install-routine, if you worked with Inno Setup you will know that the [Registry] section will always run first which is a problem, and there is no [Code] example given in your linked topic as well, which I actually need. You know that this isn't a duplicate by checking my first code-section above, I am one step further with my question - which means you did not really take the time to understand my problem when already looking for duplicates. – Yauhun Feb 03 '17 at 15:35
  • I use innosetup, and have a few live projects using it. I'm not seeing how this isn't a duplicate? You wont need to do any post install command because if the registry key is redundant and no longer used - then it makes no difference when innosetup calls the command - it can be done right at the very start of the install process for all you care. So as long as the registry declaration is at the top - it will remove the offending registry key at install startup (without the need of any [Code] section) - which makes no difference to the timing of the deletion of a redundant key. – Scott Feb 03 '17 at 16:26
  • @Scott the key is created during the installation. If I attempt to delete the key at the beginning of my routine, the key will not even exist yet, which is why I need it as the last step. I wrote that in my first sentence above already. I already tested deleting with the [Registry]-part-command, however when I do it this way, the key will still be there after the installation of the rest, which makes sense if the installation creates the key. If you check my code-example, you will see that I only went into the code-section here because I want to declare this as the last step. – Yauhun Feb 06 '17 at 07:44
  • OK fair point - I read your original question as you created it during a previous installation package - i.e. an older innosetup script and you wanted the new script to remove it. – Scott Feb 09 '17 at 08:55

2 Answers2

3

Try RegDeleteValue(HKEY_LOCAL_MACHINE,'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run','Example');

RN92
  • 1,380
  • 1
  • 13
  • 32
2

It's RegDeleteKeyIncludingSubkeys:
https://jrsoftware.org/ishelp/index.php?topic=isxfunc_regdeletekeyincludingsubkeys

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I see. Still getting an error in the same line, I guess I also need to add that this is a String? – Yauhun Feb 03 '17 at 15:14
  • In case this helps: Compiler Error says "Invalid number of Parameters". Am I still missing something? – Yauhun Feb 03 '17 at 15:28
  • 1
    Well actually, the `Microsoft\Windows\CurrentVersion\Run` key does not contain any subkeys. It contains only values. So why do you attempt to delete a key? Isn't the `Example` actually a value? Use [`RegDeleteValue`](http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_regdeletevalue`). – Martin Prikryl Feb 03 '17 at 16:31
  • Alright, neither of the commands worked for me, at the end of the install, `Example` is still there. However, compiler doesn't complain now. Still not having a solution though. Reg-path is correct... EXE executed as admin. I'm out of ideas again. – Yauhun Feb 07 '17 at 09:12
  • Show us a registry export of the `Run`, so that we finally learn what it is that you are trying to remove (key or value) + Show us your code using `RegDeleteValue` (I'm still assuming that the `Example` is a value, unless you show otherwise). – Martin Prikryl Feb 07 '17 at 09:29
  • Yeah sorry my bad, forgot to add that, it is a value. The example above stays the same (in `[Code]`), I just replaced as you recommended `RegDeleteValue`. With a work-around, I can solve it by running a small script at the end of the install-routine which deletes the value, removing `[Code]`-Section completely, however not the solution I wanted... – Yauhun Feb 07 '17 at 14:04
  • I've tested your exact code now. And it works. Show us an export of the `Run` registry key. – Martin Prikryl Feb 07 '17 at 14:10
  • You tested this part of the code and yeah it works as a stand-alone, it just seems to run at the wrong time so it's without effect if the value does not exist at that time. The Setup.exe starts several installations and runs one after another. 1st: Creating folder, insert all files, 2nd: starting Installer1 (creates the Registry-String!), 3rd: starting Installer2, 4th: supposed to delete the key at this point of the whole install routine, 5th: end, no more actions. Is it possible that this just runs at the wrong spot still, even `CurStep = ssPostInstall`? (Hope I deliver what I mean to say...) – Yauhun Feb 07 '17 at 14:41
  • If you know that the code works, and is just called at a wrong time, you should have told us at the very beginning! But anyway, unless your code is terribly designed, the `CurStep = ssPostInstall` should be one of the very last events. But we can hardly know without you showing us a relevant code. – Martin Prikryl Feb 07 '17 at 14:44
  • I just came to that conclusion, not holding back info. When you tested, I did. There is no more code to show under the `[Code]` section. The previous two installations are to be found under `[Run]`, and then there's nothing more. I used the same code before to create a Key at the end of a setup, so I expected this to work for deletion vice versa and didn't expect the problem in the order. Willing to show you more, if you still want to help, sorry for the lack of experience and understanding, just doing this for hobby. System tells me to move discussion to chat - if you are not tired yet. – Yauhun Feb 07 '17 at 14:55
  • On one hand, you write that it *"works as a stand-alone"*, on the other hand, you write that *"There is no more code to show"*. That's sounds contradictory to me. So post [mcve]. – Martin Prikryl Feb 07 '17 at 20:10
  • By that I mean, if I run this part as a stand-alone, manually, after the whole installations as a second EXE with solely that job, it will delete the value I want to delete. Still, in the `[Code]`-section this is all I have, so yeah, both I said is right, speaking of the Coding-section only, I showed you all I have. Even my English is not perfect, I believe this is understandable. If we can't find a solution here, it is no problem, it was just an attempt. I am still thinking about this further, and till that my work-around is acceptable. – Yauhun Feb 08 '17 at 09:16
  • So start with your full installer code and keep reducing it until you find the minimal code that still reproduces the problem. Just a wild guess: The `Example` entry is created by some subinstaller, right? Are you sure you are waiting for the subinstaller to finish completely? Isn't it still running in the background, while the main (Inno Setup) installer is finishing (and calling the `RegDeleteValue`? - What happens if you delay the delete by using `Sleep(10000)` before the `RegDeleteValue`? – Martin Prikryl Feb 08 '17 at 09:25