donjkurian
Member
- Joined
- Oct 6, 2009
- Messages
- 9
- Programming Experience
- 1-3
Hi,
I've recently learnt that Regex class maybe used to develop case insensitive searches. I have a registry search program that will return only the exact matches from the registry. I need to make it case insensitive. Can you guide me how to do that using regular expressions in vb.net 2005. Im posting my code below:
I've recently learnt that Regex class maybe used to develop case insensitive searches. I have a registry search program that will return only the exact matches from the registry. I need to make it case insensitive. Can you guide me how to do that using regular expressions in vb.net 2005. Im posting my code below:
VB.NET:
Sub SearchSubKeys(ByVal root As RegistryKey, ByVal searchKey As String)
Dim matchtype As String = Nothing
Dim str(5) As String
Dim itm As ListViewItem
totalcount = totalcount + 1
Label1.Refresh()
Label2.Refresh()
TextBox2.Refresh()
Label1.Text = "No. of keys searched : " + totalcount.ToString
Label2.Text = "Matching items : " + count.ToString
TextBox2.Text = "Last key scanned : " + root.ToString
'search key name
If root.Name.Contains(searchKey) Then
matchtype = "Key"
str(0) = matchtype
str(1) = root.Name
str(2) = "N/A"
str(3) = "N/A"
itm = New ListViewItem(str)
ListView1.BeginUpdate()
ListView1.Items.Add(itm)
ListView1.EndUpdate()
count = count + 1
End If
'search value names
For Each valueName As String In root.GetValueNames
If valueName.Contains(searchKey) Then
matchtype = "Value Name"
str(0) = matchtype
str(1) = root.Name
str(2) = valueName
str(3) = root.GetValue(valueName)
itm = New ListViewItem(str)
ListView1.BeginUpdate()
ListView1.Items.Add(itm)
ListView1.EndUpdate()
count = count + 1
End If
'search values
Select Case root.GetValueKind(valueName)
Case RegistryValueKind.String, RegistryValueKind.ExpandString
Dim value As String = CStr(root.GetValue(valueName))
If value.Contains(searchKey) Then
matchtype = "Value"
str(0) = matchtype
str(1) = root.Name
str(2) = valueName
str(3) = value
itm = New ListViewItem(str)
ListView1.BeginUpdate()
ListView1.Items.Add(itm)
ListView1.EndUpdate()
count = count + 1
End If
Case RegistryValueKind.MultiString
Dim value As String = String.Join(vbNewLine, CType(root.GetValue(valueName), String()))
If value.Contains(searchKey) Then
matchtype = "Value"
str(0) = matchtype
str(1) = root.Name
str(2) = valueName
str(3) = value
itm = New ListViewItem(str)
ListView1.BeginUpdate()
ListView1.Items.Add(itm)
ListView1.EndUpdate()
count = count + 1
End If
End Select
Next
For Each subkeyName As String In root.GetSubKeyNames
Try
Dim subkey As RegistryKey = root.OpenSubKey(subkeyName, RegistryKeyPermissionCheck.ReadSubTree, Security.AccessControl.RegistryRights.ReadKey)
SearchSubKeys(subkey, searchKey)
subkey.Close()
Catch ex As Exception
End Try
Next
End Sub