Custom action fails for deleting a registry key using VBScript - Advanced Installer Community
shaileshsathe
Posts: 10
Joined: Tue Feb 13, 2018 5:40 am

Custom action fails for deleting a registry key using VBScript

I am new to advanced installer.My java application sets a registry key in HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Prefs/my_key.I want to get it removed during Uninstall. I tried using Registry key removal as you answered before but it doesn't work.Now I have using "Execute Inline Script Code" and using VBScript

Code: Select all

Option Explicit
If Not WScript.Arguments.Named.Exists("elevate") Then
  CreateObject("Shell.Application").ShellExecute WScript.FullName _
    , """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1
  WScript.Quit
End If


Dim objShell
Set objShell = CreateObject( "WScript.Shell" )  
Dim strDelete
strDelete = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs\my_key")
WScript.echo(strDelete)
objShell.RegDelete "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs\my__key"
WScript.Quit
But it gives error while Uninstall that script required to complete this install could not run and when I check my system log it shows
1) Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action ExecuteScriptCode script error -2146827788, Microsoft VBScript runtime error: Variable is undefined: 'WScript' Line 2, Column 1,
OR below when I remove Administrator Login code.
2) Product: MyProduct -- Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action ExecuteScriptCode script error -2147024894, WshShell.RegRead: Invalid root in registry key "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs\". Line 5, Column 1,
Can you please guide me best solution to handle this.Please help me with the throughout procedure in order to achieve the same.

I simply want to remove registry key created by my Java Application and want to remove it while uninstall and not during Upgrade.Please Help.
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Custom action fails for deleting a registry key using VBScript

Hi,

I'm not sure why the first error means, but the second one means that the script cannot find the mentioned registry key. Please keep in mind that if you run the package on a 64-bit machine and try to remove a 64-bit registry entry, then you must check the "64-bit script" option for the "Execute inline script" custom action.

Also, in order to avoid a script failure in case that registry key is not present on the machine, you need to first check if it is present and only after that try to remove it. Also, you need to make sure that the script works well outside your package first.

You can see below an example of an working script that I tested on my machine:

Code: Select all

RegPath = "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs\test\"

Function Exists(RegPath)
    Dim reg
     On Error Resume Next
        Err.clear
        reg = SH.RegRead(RegPath)
     If hex(Err.number) = "80070002" Then
        Exists = False
     Else
        Dim objShell
				Set objShell = CreateObject( "WScript.Shell" )  
				Dim strDelete
				strDelete = objShell.RegRead(RegPath)
				objShell.RegDelete RegPath
     End If
  End Function

Exists(RegPath)
Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
shaileshsathe
Posts: 10
Joined: Tue Feb 13, 2018 5:40 am

Re: Custom action fails for deleting a registry key using VBScript

Thanks a lot for the reply!!
Its absolutely working fine now and getting removed successfully.I checked the option 64 bit Script and used your script given.
Can you tell me will this work for 32 bit system if I uncheck the option 64 bit script ?
Also I want to get it removed during Uninstall not while upgrading so will the same Custom action work with the condition (REMOVE="ALL" AND (NOT UPGRADINGPRODUCTCODE))
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Custom action fails for deleting a registry key using VBScript

Hi,

You're welcome. I'm glad you got this working.
Can you tell me will this work for 32 bit system if I uncheck the option 64 bit script ?
In order to get this working on the 32-bit machines too, you need to duplicate it and uncheck the "64-bit script" option for one of them. You can also use the "VersionNT64" property as a condition for them.
Also I want to get it removed during Uninstall not while upgrading so will the same Custom action work with the condition (REMOVE="ALL" AND (NOT UPGRADINGPRODUCTCODE))
Yes, this is the correct condition if you want to execute it only on a complete uninstall.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
shaileshsathe
Posts: 10
Joined: Tue Feb 13, 2018 5:40 am

Re: Custom action fails for deleting a registry key using VBScript

Thanks a lot for the quick reply.I got this working by unchecking the 64-bit option for 32-bit setup.Can you tell me what would be the script or the condition If I select Mixed 32/64-bit matching platform from the "Install Parameters" tab.That means the script should be executed according to the platform whether it is 32-bit or 64-bit.
Thanks in advance
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Custom action fails for deleting a registry key using VBScript

Hi,

As I mentioned above, if you want that script to work on both 32-bit and 64-bit machines, you need to duplicate that custom action. Check the "64-bit script" option for one of them and uncheck it for another, then use the "VersionNT64" condition for one and "NOT VersionNT64" condition for another.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
shaileshsathe
Posts: 10
Joined: Tue Feb 13, 2018 5:40 am

Re: Custom action fails for deleting a registry key using VBScript

Thanks a lot for the reply.You made my day. ;)
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Custom action fails for deleting a registry key using VBScript

You're welcome. I'm glad I could help.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”