Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'************************************
'*
'* Registry Key Exists (Function)
'* Version 1.1
'*
'************************************
'This function checks to see if a passed registry key exists, and
'returns true if it does
'
'Requirements: The registry key you are looking for (RegistryKey)
Function RegistryKeyExists (fncStrRegistryKey)
'Ensure the last character is a backslash (\) - if it isn't, add one
If (Right(fncStrRegistryKey, 1) <> "\") Then
'Add a backslash
fncStrRegistryKey = fncStrRegistryKey & "\"
End If
'If there isnt the key when we read it, it will return an error, so we need to resume
On Error Resume Next
'Try reading the key
WshShell.RegRead fncStrRegistryKey
'Catch the error
Select Case Err
'Error Code 0 = 'success'
Case 0
fncStrRegistryKeyExists = true
'This checks for the (Default) value existing (but being blank); as well as key's not existing at all (same error code)
Case &h80070002
'Read the error description, removing the registry key from that description
strErrDescription = Replace(Err.description, fncStrRegistryKey, "")
'Clear the error
Err.clear
'Read in a registry entry we know doesn't exist (to create an error description for something that doesnt exist)
WshShell.RegRead "HKEY_ERROR\"
'The registry key exists if the error description from the HKEY_ERROR RegRead attempt doesn't match the error
'description from our fncStrRegistryKey RegRead attempt
If (strErrDescription <> Replace(Err.description, "HKEY_ERROR\", "")) Then
RegistryKeyExists = true
Else
RegistryKeyExists = false
End If
'Any other error code is a failure code
Case Else
RegistryKeyExists = false
End Select
'Turn error reporting back on
On Error Goto 0
End Function
'************************************
'*
'* Registry Value Exists (Function)
'* Returns a value (true / false)
'*
'************************************
'This function checks to see if a passed registry value exists, and
'returns true if it does
'
'Requirements: The registry value you are looking for (RegistryValue)
Function RegistryValueExists (fncStrRegistryValue)
'Ensure the last character is NOT a backslash (\) - if it is, we aren't looking for a value
If (Right(fncStrRegistryValue, 1) = "\") Then
'It's not a registry value we are looking for
RegistryValueExists = false
Else
'If there isnt the value when we read it, it will return an error, so we need to resume
On Error Resume Next
'Try reading the value
WshShell.RegRead fncStrRegistryValue
'Catch the error
Select Case Err
Case 0:
'Error Code 0 = 'success'
RegistryValueExists = true
Case Else
'Any other error code is a failure code
RegistryValueExists = false
End Select
'Turn error reporting back on
On Error Goto 0
End If
End Function
'************************************
'*
'* Registry Item Exists (Function)
'* Version 1.1
'*
'************************************
'This function checks to see if a passed registry key/value exists, and
'returns true if it does
'
'Requirements: The registry key/value you are looking for (fncStrRegistryItem)
'Note: RegistryItem MUST end in a backslash (\) if you are looking for a key
' RegistryItem's without a backslash (\) will assume you are looking for a value
Function RegistryItemExists (fncStrRegistryItem)
'If there isnt the item when we read it, it will return an error, so we need to resume
On Error Resume Next
'Find out if we are looking for a key or a value
If (Right(fncStrRegistryItem, 1) = "\") Then
'It's a registry key we are looking for
'Try reading the key
WshShell.RegRead fncStrRegistryItem
'Catch the error
Select Case Err
'Error Code 0 = 'success'
Case 0:
RegistryItemExists = true
'This checks for the (Default) value existing (but being blank); as well as key's not existing at all (same error code)
Case &h80070002:
'Read the error description, removing the registry key from that description
ErrDescription = Replace(Err.description, fncStrRegistryItem, "")
'Clear the error
Err.clear
'Read in a registry entry we know doesn't exist (to create an error description for something that doesnt exist)
WshShell.RegRead "HKEY_ERROR\"
'The registry key exists if the error description from the HKEY_ERROR RegRead attempt doesn't match the error
'description from our RegistryKey RegRead attempt
If (ErrDescription <> Replace(Err.description, "HKEY_ERROR\", "")) Then
RegistryItemExists = true
Else
RegistryItemExists = false
End If
'Any other error code is a failure code
Case Else:
RegistryItemExists = false
End Select
Else
'It's a registry value we are looking for
'Try reading the value
WshShell.RegRead fncStrRegistryItem
'Catch the error
Select Case Err
Case 0:
'Error Code 0 = 'success'
RegistryItemExists = true
Case Else
'Any other error code is a failure code
RegistryItemExists = false
End Select
End If
'Turn error reporting back on
On Error Goto 0
End Function