-
August 3rd, 2009, 05:24 AM
#1
Windows 7 and Reg Functions..
i have two very simple functions... to load and save regkeys..
Code:
Public Function Load(ByVal Regloc As Reg_type, ByVal Keyloc As String, ByVal Keyname As String, Optional ByVal DefValue As String = "NA") As Regkeys
Dim TmpReg As New Regkeys
Dim TmpVal As String
TmpVal = DefValue
Try
Select Case Regloc
Case Reg_type.Current_Config
rk = Registry.CurrentConfig.OpenSubKey(Keyloc, False)
Case Reg_type.Current_User
rk = Registry.CurrentUser.OpenSubKey(Keyloc, False)
Case Reg_type.Local_Machine
rk = Registry.LocalMachine.OpenSubKey(Keyloc, False)
Case Reg_type.Users
rk = Registry.Users.OpenSubKey(Keyloc, False)
End Select
TmpVal = DirectCast(rk.GetValue(Keyname, DefValue), String)
Catch ex As Exception
RaiseEvent Int_Error(Error_type.Load_Err)
Finally
TmpReg.LoadReg(Regloc, Keyloc, Keyname, TmpVal)
TmpReg.Changed = True
Try
rk.Close()
Catch ex As Exception
End Try
End Try
Save(TmpReg)
Return TmpReg
End Function
Public Sub Save(ByRef RegKey As Regkeys)
If RegKey.Change Then
Try
Select Case RegKey.RegType
Case Reg_type.Current_Config
rk = Registry.CurrentConfig.CreateSubKey(RegKey.KeyLoc)
Case Reg_type.Current_User
rk = Registry.CurrentUser.CreateSubKey(RegKey.KeyLoc)
Case Reg_type.Local_Machine
rk = Registry.LocalMachine.CreateSubKey(RegKey.KeyLoc)
Case Reg_type.Users
rk = Registry.Users.CreateSubKey(RegKey.KeyLoc)
End Select
rk.SetValue(RegKey.Keyname, RegKey.KeyVal)
RegKey.Changed = False
Catch ex As Exception
RaiseEvent Int_Error(Error_type.Save_Err)
Finally
rk.Close()
End Try
End If
End Sub
these functions work fine in XP and vista, but when tested in Windows 7 .. the save reg function crashes... we assume it may be to do with Windows 7 having changed access to the reg... any ideas ???
Gremmy...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|