我想写一个程序主要是写入注册表的启动项和删除这一项目.
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1
'写入到注册表
Private Sub inre()
Call RegCreateKey(HKEY_LOCAL_MACHINE, "software\microsoft\windows\currentVersion\run", stmser)
Call RegSetValue(stmser, vbNullString, REG_SZ, App.Path & "\stmser", 4)
Call RegCloseKey(stmser)
End Sub请问删除应该怎么弄呀。
而且我发现这个好象不怎么全,因为在下面的项中是默认的值,连名字都不能改而且那个写入不怎么全.
哪位高手弄一个全点的范例呀??
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1
'写入到注册表
Private Sub inre()
Call RegCreateKey(HKEY_LOCAL_MACHINE, "software\microsoft\windows\currentVersion\run", stmser)
Call RegSetValue(stmser, vbNullString, REG_SZ, App.Path & "\stmser", 4)
Call RegCloseKey(stmser)
End Sub请问删除应该怎么弄呀。
而且我发现这个好象不怎么全,因为在下面的项中是默认的值,连名字都不能改而且那个写入不怎么全.
哪位高手弄一个全点的范例呀??
删除值键用RegDeleteValueRegSetValue是写默认项
写任意值键用RegSetValueEx
具体用法可以查MSDN
Dim RetVal As Long
Dim Exist As LongIf mOpened Then
OpenKey = False
Exit Function
End If
RetVal = RegCreateKeyEx(RootKey, SubKey, 0, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, mHKey, Exist)
If RetVal <> ERROR_SUCCESS Then
OpenKey = False
Exit Function
End If
mOpened = True
OpenKey = True
End FunctionPublic Function SetValue(ByVal NameString As String, ByVal Value As Variant) As Boolean
Dim mType As Long
Dim RetVal As Long
Dim ValueStr As String
Dim ValueLong As Long
If Not mOpened Then SetValue = False
Exit Function
End If
If TypeName(Value) = "String" Then
mType = REG_SZ
ElseIf TypeName(Value) = "Long" Or TypeName(Value) = "Integer" Then
mType = REG_DWORD
Else
SetValue = False
Exit Function
End If
If mType = REG_SZ Then
ValueStr = Value
RetVal = RegSetValueEx(mHKey, NameString, 0, mType, ByVal ValueStr, Len(ValueStr))
Else
ValueLong = Value
RetVal = RegSetValueEx(mHKey, NameString, 0, mType, ValueLong, 4)
End If
If RetVal <> ERROR_SUCCESS Then
SetValue = False
Else
SetValue = True
End If
End FunctionPublic Function GetValue(ByVal NameString, Value As Variant) As Boolean
Dim mType As Long
Dim L As Long
Dim RetVal As Long
Dim GetValueStr As String
Dim GetValueLong As Long
If Not mOpened Then
GetValue = False
Exit Function
End If
RetVal = RegQueryValueEx(mHKey, NameString, 0, mType, ByVal GetValueStr, L)
If RetVal <> ERROR_SUCCESS Then
GetValue = False
Exit Function
End If
Select Case mType
Case REG_SZ
GetValueStr = String(L, 0)
RetVal = RegQueryValueEx(mHKey, NameString, 0, mType, ByVal GetValueStr, L)
If RetVal <> ERROR_SUCCESS Then
GetValue = False
Exit Function
Else
GetValue = True
Value = Left(GetValueStr, L)
Exit Function
End If
Case REG_DWORD
RetVal = RegQueryValueEx(mHKey, NameString, 0, mType, GetValueLong, L)
If RetVal <> ERROR_SUCCESS Then
GetValue = False
Exit Function
Else
GetValue = True
Value = GetValueLong
Exit Function
End If
Case Else
GetValue = False
End Select
End Function