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....
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0

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
Answered 01/21/2009 by: turbokitty
Sixth Degree Black Belt

Please log in to comment
0
Thank u for ur reply
Answered 01/21/2009 by: sanhivi
Second Degree Green Belt

Please log in to comment
1
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
Answered 01/22/2009 by: VBScab
Red Belt

Please log in to comment
0
Hi all,

please give me some info about SMS 2003 certification

Thanks
Deepakkumar
Answered 01/22/2009 by: deepakkumar
Orange Belt

Please log in to comment
0
!?!?

Perhaps you'd like to try posting in the correct forum? Either 'Distribution' http://www.appdeploy.com/messageboards/tt.asp?forumid=2&p=&tmode=1&smode=1 or...at a wild guess...'SMS' http://www.appdeploy.com/messageboards/tt.asp?forumid=23
Answered 01/22/2009 by: VBScab
Red Belt

Please log in to comment
0
I saw code similar to that on the Scripting Guys blog. It's much harder to search for the existence of a key than a value.

In this case, that value should always be there, so the code I posted before should be fine. That said, searching for the key is technically more correct.
Answered 01/23/2009 by: turbokitty
Sixth Degree Black Belt

Please log in to comment
0
In this case, that value should always be there, so the code I posted before should be fine. The nail has been hit on the head right there, with the two occurences of the word should. In ANY script, assume NOTHING! :)
Answered 01/26/2009 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity