Need a vb script to delete a registry if the value is there
HI,
I need a vbscript to delete the registry by the checking the value.
My application is having following key.
HKLM\Software\Java Soft\Java Runtime Environment
Value is Vesion 1.4.2_08
Here I need to delete the Java Runtime Environment key by checking whether it is having a value of 1.4.2._08. If this key has different version they it shouldn't delete.
Please help me....
I need a vbscript to delete the registry by the checking the value.
My application is having following key.
HKLM\Software\Java Soft\Java Runtime Environment
Value is Vesion 1.4.2_08
Here I need to delete the Java Runtime Environment key by checking whether it is having a value of 1.4.2._08. If this key has different version they it shouldn't delete.
Please help me....
0 Comments
[ + ] Show comments
Answers (7)
Please log in to answer
Posted by:
anonymous_9363
15 years ago
Here's a neat function I found somewhere, for testing a registry key's existence. The clever thing is that it doesn't rely on reading a value: not all keys have values assigned to them.
Function DoesRegistryKeyExist(ByVal strRegistryKey)
Dim strErrDescription
Const strDummyKey = "HKEY_ERROR\"
'// Ensure the last character is a backslash (\). If it isn't, we aren't looking for a key
If (Right(strRegistryKey, 1) <> "\") Then
'// It's not a registry key we are looking for
DoesRegistryKeyExist = False
Else
'// If the key isn't present when we read it, it will return an error, so we need to resume
On Error Resume Next
'// Try reading the key
objWSHShell.RegRead strRegistryKey
'// Catch the error
Select Case Err
Case 0
'// Error Code 0 = 'success'
DoesRegistryKeyExist = True
Case &h80070002
'// This checks for the (Default) value existing (but being blank); as well as key's not existing at all (same error code)
'// Read the error description, removing the registry key from that description
strErrDescription = Replace(Err.Description, strRegistryKey, "")
'// Clear the error
Err.Clear
'// Read in a registry entry we know doesn't exist (to create an error description for something that doesn't exist)
objWSHShell.RegRead strDummyKey
'// The registry key exists if the error description from the HKEY_ERROR RegRead attempt doesn't match the error
'// description from our strRegistryKey RegRead attempt
If (strErrDescription<> Replace(Err.Description, strDummyKey, "")) Then
DoesRegistryKeyExist = True
Else
DoesRegistryKeyExist = False
End If
Case Else
'// Any other error code is a failure code
DoesRegistryKeyExist = False
End Select
'// Turn error reporting back on
On Error Goto 0
End If
End Function
Posted by:
turbokitty
15 years ago
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\JavaSoft\Java Runtime Environment\1.4.2_08"
strValueName = "JavaHome"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If IsNull(strValue) Then
Wscript.Echo "The registry key does not exist."
Else
Wscript.Echo "The registry key exists."
objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
End If
Posted by:
deepakkumar
15 years ago
Posted by:
anonymous_9363
15 years ago
Posted by:
turbokitty
15 years ago
Posted by:
anonymous_9363
15 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.