/build/static/layout/Breadcrumb_cap_w.png

calling vbscript from custom action

Hi,


I have writen a vbscript to remove some registry keys during uninstallation.It works fine when run noramlly but when i call it from a custom action (call VBScript from embedded code) it gives error 1720 script could not be executed.


Dim WshShell, bKey
Set WshShell = CreateObject("WScript.Shell")

Const HKLM = &H80000002
Dim strKey
Dim arrSubKeys()
Dim objReg
Dim strComputer
Dim abc

strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKey = "Software\xyz"
objReg.EnumKey HKLM, strKey, arrSubKeys

'The next section will just go through the array to find the desired key.

For intI = 0 to UBound(arrSubKeys)
If arrSubKeys(intI) = "abc" Then
abc = arrSubKeys(intI)
End If
Next


If abc = "abc" and UBound(arrSubKeys) = 0 Then
WshShell.RegDelete "HKLM\Software\xyz\abc\"
WshShell.RegDelete "HKLM\Software\xyz\"
End If

If abc = "abc" and UBound(arrSubKeys) > 0 Then
WshShell.RegDelete "HKLM\Software\xyz\abc\"
End If

can anybody tell me how i can get this code to work from a custom action..looks like the Enumkey method is not being recognised..any
help would be greatly appreciated..Thanks in advance

0 Comments   [ + ] Show comments

Answers (10)

Posted by: brenthunter2005 19 years ago
Fifth Degree Brown Belt
0
When this script errors on your computer, you should be able to check the Application Event Log and it will tell you which line of code has the error.
Posted by: artiahc_elay 19 years ago
Senior Yellow Belt
0
i checked the logfile says vbscript runtime error: invalid procedure call or argument: 'EnumKey'
Posted by: brenthunter2005 19 years ago
Fifth Degree Brown Belt
0
I've just done this in a MSI CA and it works fine for me, but I'm doing it all with full admin rights.

Try adding the following line of code after your "Set objReg=GetObject..........."
If objReg Is Nothing then msgbox "objReg is not set to anything!"
Posted by: artiahc_elay 19 years ago
Senior Yellow Belt
0
Thanks Brent its working fine just made a few changes
Posted by: brenthunter2005 19 years ago
Fifth Degree Brown Belt
0
Can you post your solution so that others will know please?
Posted by: artiahc_elay 19 years ago
Senior Yellow Belt
0
Hi brent,

This is my code that works fine..If u have any questions let me know




Set WshShell = CreateObject("WScript.Shell")
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")


strKeyPath = "Software\XYZ"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
msgbox "Subkeys under " _
& "HKEY_LOCAL_MACHINE\Software\XYZ"


'The next section will just go through the array to find the desired key.
If not IsNull(arrSubKeys) Then
For intI = 0 to UBound(arrSubKeys)
If arrSubKeys(intI) = "abc" Then
abc = arrSubKeys(intI)
End If
Next



If abc = "abc" and UBound(arrSubKeys) = 0 Then
WshShell.RegDelete "HKLM\Software\XYZ\abc\"
WshShell.RegDelete "HKLM\Software\XYZ\"
End If

If abc = "abc" and UBound(arrSubKeys) > 0 Then
WshShell.RegDelete "HKLM\Software\XYZ\abc\"
End If
End If

Thanks

Chaitra
Posted by: brenthunter2005 19 years ago
Fifth Degree Brown Belt
0
Nice one.
Posted by: challa_praveena 19 years ago
Yellow Belt
0
Hi,

I am new to this forum- I am in need of urgent help- I have to create an MSI file and call and run a vbscript from that MSI file and I have no clue how to do it in .net.


any help is gr8tly appreciated.


thanks

rgds
pivi
Posted by: noodles187 18 years ago
Orange Belt
0
G

Hi Brett,

I have a similar issue with the following script, can you tell me where it's going wrong?

Dim WSHShell
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegDelete "HKLM\SOFTWARE\Figtree Systems Pty Ltd\Figtree Enhancement 18.5\18.5\"
WSHShell.RegDelete "HKLM\SOFTWARE\Figtree Systems Pty Ltd\Figtree Enhancement 18.5\"
WSHShell.RegDelete "HKLM\SOFTWARE\Figtree Systems Pty Ltd\"
set WSHShell = nothing
Posted by: brenthunter2005 18 years ago
Fifth Degree Brown Belt
0
The script looks fine to me.

Your issue might be to do with the sequence location in the MSI package.

If your custom action is placed after the InstallFinalize action then it needs to be run in the Immediate Execution.
If your custom action is placed between then InstallInitalize and InstallFinalize actions then it needs to be run in the Deferred Execution.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ