(1)添加項
專注于為中小企業(yè)提供網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)山丹免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
Dim reg As RegistryKey
reg = Registry.CurrentUser
reg = reg.OpenSubKey("Software\Microsoft\Internet Explorer\Main", True)
reg.SetValue("Window Title", Me.TextBox1.Text)
(2)讀取項
Dim reg As RegistryKey
Dim regStr As String
reg = Registry.CurrentUser
reg = reg.OpenSubKey("Software\Microsoft\Internet Explorer\Main", True)
regStr = reg.GetValue("Window Title")
Me.TextBox1.Text = regStr
(3)刪除項
Dim reg As RegistryKey
reg = Registry.CurrentUser
reg = reg.OpenSubKey("Software\Microsoft\Internet Explorer\Main", True)
reg.DeleteValue("Window Title")
Sub?Button1Click(sender?As?Object,?e?As?寬羨EventArgs)
'HKEY_CLASSES_ROOT\.doc
Dim?Root1?As?RegistryKey?=?Registry.ClassesRoot
慎明拍??????? '打開"SYSTEM"子健
Dim?key1?As?RegistryKey?=?Root1.OpenSubKey?(?".doc"槐棗?,true?)
'打開".doc"子健
textBox1.Text??=key1.GetValue(String.Empty)
End?Sub
微軟在net里內(nèi)置了一一些提供注旁扮冊表操作的類,因此我們可以很輕松的操作注冊表
導(dǎo)入名詞稱空間 imports Microsoft.Win32
Dim reg As RegistryKey
Dim regStr As String
reg = Registry.LocalMachine
reg = reg.OpenSubKey("SYSTEM\CurrentControlSet\Enum\USB"首凱, True)
regStr = reg.GetValue("運芹灶VID_08E2PID_0006")
if regstr.tostring ""then …復(fù)制文件
的拿首睜完整路徑寫在HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
就可以自啟動了。
以下是我前消歲一段時間寫的防u盤自動運行的程序,里面可以找到如何操作注冊表。
Option Explicit
Global Const REG_SZ As Long = 1
Global Const REG_DWORD As Long = 4
Global Const HKEY_CLASSES_ROOT = H80000000
Global Const HKEY_CURRENT_USER = H80000001
Global Const HKEY_LOCAL_MACHINE = H80000002
Global Const HKEY_USERS = H80000003
Global Const ERROR_NONE = 0
Global Const ERROR_BADDB = 1
Global Const ERROR_BADKEY = 2
Global Const ERROR_CANTOPEN = 3
Global Const ERROR_CANTREAD = 4
Global Const ERROR_CANTWRITE = 5
Global Const ERROR_OUTOFMEMORY = 6
Global Const ERROR_INVALID_PARAMETER = 7
Global Const ERROR_ACCESS_DENIED = 8
Global Const ERROR_INVALID_PARAMETERS = 87
Global Const ERROR_NO_MORE_ITEMS = 259
Global Const KEY_ALL_ACCESS = H3F
Global Const REG_OPTION_NON_VOLATILE = 0
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
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
Declare Function RegQueryValueEx 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
Declare Function RegSetValueEx 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 Sub cmdAbout_Click()
MsgBox "作者wolfccb不對芹纖本軟件可能造成的任何錯誤或損失負(fù)責(zé),請自行承擔(dān)使用風(fēng)險。", vbInformation, "About"
End Sub
Private Sub cmdDefault_Click()
Check0.Value = 1
Check1.Value = 0
Check2.Value = 1
Check3.Value = 0
Check4.Value = 1
Check5.Value = 0
Check6.Value = 0
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdRecommend_Click()
Check0.Value = 1
Check1.Value = 1
Check2.Value = 1
Check3.Value = 1
Check4.Value = 1
Check5.Value = 0
Check6.Value = 1
End Sub
Private Sub cmdSet_Click()
Dim hkey As Long
Dim lvalue As Long
Dim cddata As Long
Dim retval As Long
lvalue = GetValue
retval = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", 0, KEY_ALL_ACCESS, hkey)
retval = RegSetValueEx(hkey, "NoDriveTypeAutoRun", 0, REG_DWORD, lvalue, 4)
RegCloseKey hkey
If retval = 0 Then
MsgBox "設(shè)置已保存。", vbInformation, "提示"
Else
MsgBox "保存失敗,錯誤代碼:" + CStr(retval), vbExclamation, "錯誤"
End If
End Sub
Private Sub Form_Load()
Dim hkey As Long
Dim lvalue As Long
Dim cddata As Long
Dim retval As Long
retval = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", 0, KEY_ALL_ACCESS, hkey)
If retval 0 Then
MsgBox "打開注冊表失敗,錯誤代碼:" + CStr(retval), vbExclamation, "錯誤"
End If
retval = RegQueryValueEx(hkey, "NoDriveTypeAutoRun", 0, REG_DWORD, lvalue, 4)
RegCloseKey hkey
If retval 0 Then
MsgBox "讀取注冊表失敗,錯誤代碼:" + CStr(retval), vbExclamation, "錯誤"
End If
ShowCheck (lvalue)
End Sub
Private Sub ShowCheck(lvalue As Long)
Check0.Value = lvalue Mod 2
lvalue = (lvalue - Check0.Value) / 2
Check1.Value = lvalue Mod 2
lvalue = (lvalue - Check1.Value) / 2
Check2.Value = lvalue Mod 2
lvalue = (lvalue - Check2.Value) / 2
Check3.Value = lvalue Mod 2
lvalue = (lvalue - Check3.Value) / 2
Check4.Value = lvalue Mod 2
lvalue = (lvalue - Check4.Value) / 2
Check5.Value = lvalue Mod 2
lvalue = (lvalue - Check5.Value) / 2
Check6.Value = lvalue Mod 2
End Sub
Private Function GetValue() As Long
GetValue = Check0.Value + Check1.Value * 2 + Check2.Value * 4 + Check3.Value * 8 + Check4.Value * 16 + Check5.Value * 32 + Check6.Value * 64 + 128
End Function
以上。
餓的老狼