/build/static/layout/Breadcrumb_cap_w.png

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....

0 Comments   [ + ] Show comments

Answers (7)

Posted by: anonymous_9363 15 years ago
Red Belt
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
Posted by: turbokitty 15 years ago
6th Degree Black Belt
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
Posted by: sanhivi 15 years ago
Third Degree Green Belt
0
Thank u for ur reply
Posted by: deepakkumar 15 years ago
Orange Belt
0
Hi all,

please give me some info about SMS 2003 certification

Thanks
Deepakkumar
Posted by: anonymous_9363 15 years ago
Red Belt
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
Posted by: turbokitty 15 years ago
6th Degree Black Belt
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.
Posted by: anonymous_9363 15 years ago
Red Belt
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! :)
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