” 关闭打开的键

vb添加运营项和删除运维项

” 关闭张开的键
Private Declare Function RegCloseKey Lib “advapi32.dll” _
                         (ByVal hKey As Long) 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 RegSetValueEx Lib “advapi32” Alias
“RegSetValueExA” ( _
                         ByVal hKey As Long, ByVal lpValueName As
String, _
                         ByVal Reserved As Long, ByVal dwType As Long,
_
                         ByVal lpData As String, ByVal cbData As Long)
As Long
‘删除插手的键值
Private Declare Function RegDeleteValue Lib “advapi32.dll” Alias
“RegDeleteValueA” ( _
                         ByVal hKey As Long, ByVal lpValueName As
String) As Long
‘打开注册表subkey的hkey
Private Declare Function RegOpenKey Lib “advapi32.dll” Alias
“RegOpenKeyA” ( _
                         ByVal hKey As Long, ByVal lpSubKey As String,
phkResult As Long) As Long
Private Const HKEY_CURRENT_MACHINE = &H80000002
Private Const REG_SZ = 1
Private Sub Command1_Click()
‘把应用程序参预自运营
Dim ret As Long
RegCreateKey HKEY_CURRENT_MACHINE,
“SOFTWAREMICROSOFTWINDOWSCURRENTVERSIONRUN”, ret
RegSetValueEx ret, App.EXEName, 0, REG_SZ, ByVal App.Path & “” &
App.EXEName & “.exe”, ByVal LenB(StrConv(App.Path & “” & App.EXEName &
“.exe”, vbFromUnicode)) + 1
RegCloseKey ret
MsgBox “成功走入运转项”, , “提醒”
End Sub
Private Sub Command2_Click()
‘把应用程序退出自运转
Dim ret As Long
ret = RegOpenKey(HKEY_CURRENT_MACHINE,
“SOFTWAREMICROSOFTWINDOWSCURRENTVERSIONRUN”, hKey)
If ret = 0 Then
       RegDeleteValue hKey, App.EXEName
       RegCloseKey hKey
End If
MsgBox “成功删除运转项”, , “提示”
End Sub