'建立子项subkey , shubkey2
'裤模CreateNewKey HKEY_CURRENT_USER, "Software\SubKey1\SubKey2"
'建立REG_SZ类型键"text" ,并赋予项值"this is just a test"
'SetKeyValue HKEY_CURRENT_USER, "Software\SubKey1\SubKey2", "Test","0", "This is just a test", REG_SZ
'删除子项毁闷subkey \ shubkey2下的纤纯弯"test"键
'DeleteValue HKEY_CURRENT_USER, "Software\SubKey1\SubKey2", "Test"
'删除子项shubkey2
'DeleteKey HKEY_CURRENT_USER, "Software\SubKey1\SubKey2"
Option Explicit
Private Const REG_SZ As Long = 1
Private Const REG_DWORD As Long = 4
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const ERROR_NONE = 0
Private Const ERROR_BADDB = 1
Private Const ERROR_BADKEY = 2
Private Const ERROR_CANTOPEN = 3
Private Const ERROR_CANTREAD = 4
Private Const ERROR_CANTWRITE = 5
Private Const ERROR_OUTOFMEMORY = 6
Private Const ERROR_INVALID_PARAMETER = 7
Private Const ERROR_ACCESS_DENIED = 8
Private Const ERROR_INVALID_PARAMETERS = 87
Private Const ERROR_NO_MORE_ITEMS = 259
Private Const KEY_ALL_ACCESS = &H3F
Private Const REG_OPTION_NON_VOLATILE = 0
Private Const SPI_SETDESKWALLPAPER = 20
Private Const SPIF_SENDWININICHANGE = &H2
Private Const SPIF_UPDATEINIFILE = &H1
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
Private Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
Private Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
Private Declare Function RegDeleteKey&Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String)
Private Declare Function RegDeleteValue&Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String)
Private Foucs As Boolean
Private TimerOver As Long
'删除子项
Private Function DeleteKey(lPredefinedKey As Long, sKeyName As String)
Dim lRetVal As Long
Dim hKey As Long
lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
lRetVal = RegDeleteKey(lPredefinedKey, sKeyName)
RegCloseKey (hKey)
End Function
'删除键
Private Function DeleteValue(lPredefinedKey As Long, sKeyName As String, sValueName As String)
Dim lRetVal As Long
Dim hKey As Long
lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
lRetVal = RegDeleteValue(hKey, sValueName)
RegCloseKey (hKey)
End Function
'建立键
Private Function SetValueEx(ByVal hKey As Long, sValueName As String, lType As Long, vValue As Variant) As Long
Dim lValue As Long
Dim sValue As String
Select Case lType
Case REG_SZ
sValue = vValue
SetValueEx = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, LenB(sValue))
Case REG_DWORD
lValue = vValue
SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, lType, lValue, 4)
End Select
End Function
'建立子项
Private Function CreateNewKey(lPredefinedKey As Long, sNewKeyName As String)
Dim hNewKey As Long
Dim lRetVal As Long
lRetVal = RegCreateKeyEx(lPredefinedKey, sNewKeyName, 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, hNewKey, lRetVal)
RegCloseKey (hNewKey)
End Function
'建立键并赋值
Private Function SetKeyValue(lPredefinedKey As Long, sKeyName As String, sValueName As String, vValueSetting As Variant, lValueType As Long)
Dim lRetVal As Long
Dim hKey As Long
lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting)
RegCloseKey (hKey)
End Function
Private Sub cmdDel_Click()
DeleteKey HKEY_CLASSES_ROOT, ".jdc"
DeleteKey HKEY_CLASSES_ROOT, "AAAAAA\Shell\Open\Command"
DeleteKey HKEY_CLASSES_ROOT, "AAAAAA\Shell\Open"
DeleteKey HKEY_CLASSES_ROOT, "AAAAAA\Shell"
DeleteKey HKEY_CLASSES_ROOT, "AAAAAA\DefaultIcon"
DeleteKey HKEY_CLASSES_ROOT, "AAAAAA"
End Sub
Private Sub cmdReg_Click()
Dim ss As String
ss = Chr(34)
CreateNewKey HKEY_CLASSES_ROOT, ".jdc"
SetKeyValue HKEY_CLASSES_ROOT, ".jdc", "", "AAAAAA", REG_SZ
CreateNewKey HKEY_CLASSES_ROOT, "AAAAAA\DefaultIcon"
CreateNewKey HKEY_CLASSES_ROOT, "AAAAAA\Shell"
CreateNewKey HKEY_CLASSES_ROOT, "AAAAAA\Shell\Open"
CreateNewKey HKEY_CLASSES_ROOT, "AAAAAA\Shell\Open\Command"
SetKeyValue HKEY_CLASSES_ROOT, "AAAAAA\DefaultIcon", "", "%SystemRoot%\\System32\\shell32.dll,-153", REG_SZ
SetKeyValue HKEY_CLASSES_ROOT, "AAAAAA\Shell\Open", "", "打开(&O)", REG_SZ
SetKeyValue HKEY_CLASSES_ROOT, "AAAAAA\Shell\Open\Command", "", ss &"C:\MyId\Notepad.exe\" &ss &" " &ss &" %1" &ss, REG_SZ
End Sub
右键需要建立关联的文件,在d出的菜单中选“打开方式”,如果要修改的话,右键的时候需同时按shift键。(注意,一定要同时按住shift键,否则不会出现“打开方式”)。在随后的小窗口中选择打开该文件的程序即可!如果要建立永久性的关联,则还需要在下面的“始终使用该程序打开这种类型的文件”前打勾唤枯。该方法比较简单,但需要网友们对电脑有一定的了解,能大致知道何种文件调用何种程序。所谓“文件关联”,通俗地讲就是调用一个(一些)程序来打开与这些皮笑程序相对应的文件!比如*.txt文件可和握洞以用notepad(记事本)或wordpad(写字板)程序来打开,*.zip文件可以用程序winzip来打开,*.chm文件用程序“hh”来打开等等。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)