|
|
|
Click here to copy the following block | Private Const HKEY_CLASSES_ROOT = &H80000000 Private Const HKEY_CURRENT_CONFIG = &H80000005 Private Const HKEY_CURRENT_USER = &H80000001 Private Const HKEY_LOCAL_MACHINE = &H80000002 Private Const HKEY_USERS = &H80000003
Sub SaveRegToFile(ByVal hKey As Long, ByVal sKeyName As String, _ ByVal sRegFile As String, Optional ByVal bIncludeSubKeys As Boolean = True, _ Optional ByVal bAppendToFile As Boolean = False) Dim handle As Integer Dim sFirstKeyPart As String Dim col As New Collection Dim regItem As Variant Dim sText As String Dim sQuote As String Dim sTemp As String Dim sHex As String Dim i As Long Dim vValue As Variant Dim iPointer As MousePointerConstants Dim sValueName As String sQuote = Chr$(34) On Error Resume Next Select Case hKey Case HKEY_CLASSES_ROOT: sFirstKeyPart = "HKEY_CLASSES_ROOT\" Case HKEY_CURRENT_CONFIG: sFirstKeyPart = "HKEY_CURRENT_CONFIG\" Case HKEY_CURRENT_USER: sFirstKeyPart = "HKEY_CURRENT_USER\" Case HKEY_LOCAL_MACHINE: sFirstKeyPart = "HKEY_LOCAL_MACHINE\" Case HKEY_USERS: sFirstKeyPart = "HKEY_USERS\" End Select iPointer = Screen.MousePointer Screen.MousePointer = vbHourglass If bAppendToFile = False Then sText = "REGEDIT4" & vbCrLf & vbCrLf Else handle = FreeFile Open sRegFile For Binary As #handle sTemp = Space$(LOF(handle)) Get #handle, , sTemp Close #handle If InStr(1, sTemp, "REGEDIT4") = 0 Then sText = "REGEDIT4" & vbCrLf & vbCrLf End If End If sText = sText & "[" & sFirstKeyPart & sKeyName & "]" & vbCrLf Set col = EnumRegistryValuesEx(hKey, sKeyName) For Each regItem In col vValue = regItem(1) Select Case regItem(2) Case vbString If Left$(vValue, 3) Like "[A-Z,a-z]:\" Then vValue = Replace _ (vValue, "\", "\\") sTemp = sQuote & vValue & sQuote Case vbLong sTemp = "dword:" & CLng(vValue) Case vbArray + vbByte sTemp = "hex:" For i = 0 To UBound(vValue) sHex = Hex$(vValue(i)) If Len(sHex) < 2 Then sHex = "0" & sHex sTemp = sTemp & sHex & "," Next sTemp = Left$(sTemp, Len(sTemp) - 1) Case Else sTemp = "" End Select sValueName = IIf(Len(regItem(0)) > 0, sQuote & regItem(0) & sQuote, "@") sText = sText & sValueName & "=" & sTemp & vbCrLf Next sText = sText & vbCrLf handle = FreeFile If bAppendToFile Then Open sRegFile For Append As #handle Else Open sRegFile For Output As #handle End If Print #handle, sText; Close #handle If bIncludeSubKeys Then Set col = EnumRegistryKeys(hKey, sKeyName) For Each regItem In col SaveRegToFile hKey, sKeyName & "\" & regItem, sRegFile, True, True Next End If Screen.MousePointer = iPointer End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|