我这里在csdn一收,csdn网站就出问题了,唉.麻烦还是给俺举个简单例子吧
解决方案 »
- 大家看看这个要怎么弄?
- DataGrid 赋值给 textbox 报错:类型不匹配
- 有没有办法把savepicture保存出来的图片改变大小??
- 如何通過vb實現sql server 中檔案導入導出功能,在線等.
- 谁能提供个二级VB考试模拟软件的原代码啊?有分相给。
- 求一段代码,使用 ActiveBar2.0 自动读取数据库的相关数据生成菜单
- 文本文件修改
- 查询一段ip内的网卡mac地址与主机名
- 有谁做过空调销货管理系统?
- 急急急!!!!!!那位大哥请帮下忙,我使用Data控件时出错,不知是什么原因。
- 怎样改变一个label的backcolor, 当mouse在label上移动时
- 请问form如何得到它上面的控件的mousemove消息?
具体用法MSDN有。
'以下是为了操作注册表Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const ERROR_SUCCESS = 0&' Registry API prototypesDeclare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal HKEY As Long, ByVal lpValueName As String) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, 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 Any, 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, lpData As Any, ByVal cbData As Long) As Long
Public Const REG_SZ = 1 ' Unicode nul terminated string
Public Const REG_DWORD = 4 ' 32-bit number
Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongPublic Sub savekey(HKEY As Long, strPath As String)
Dim keyhand&
r = RegCreateKey(HKEY, strPath, keyhand&)
r = RegCloseKey(keyhand&)
End SubPublic Function getstring(HKEY As Long, ByVal strPath As String, ByVal strValue As String)Dim keyhand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
r = RegOpenKey(HKEY, strPath, keyhand)
lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
getstring = Left$(strBuf, intZeroPos - 1)
Else
getstring = strBuf
End If
End If
End If
End Function
Public Sub savestring(HKEY As Long, ByVal strPath As String, ByVal strValue As String, ByVal strdata As String)
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(HKEY, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand)
End Sub
Function getdword(ByVal HKEY As Long, ByVal strPath As String, ByVal strValueName As String) As Long
Dim lResult As Long
Dim lValueType As Long
Dim lBuf As Long
Dim lDataBufSize As Long
Dim r As Long
Dim keyhand As Longr = RegOpenKey(HKEY, strPath, keyhand) ' Get length/data type
lDataBufSize = 4
lResult = RegQueryValueEx(keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)If lResult = ERROR_SUCCESS Then
If lValueType = REG_DWORD Then
getdword = lBuf
End If
'Else
' Call errlog("GetDWORD-" & strPath, False)
End Ifr = RegCloseKey(keyhand)
End FunctionFunction SaveDword(ByVal HKEY As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
Dim lResult As Long
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(HKEY, strPath, keyhand)
lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)
'If lResult <> error_success Then Call errlog("SetDWORD", False)
r = RegCloseKey(keyhand)
End FunctionPublic Function DeleteKey(ByVal HKEY As Long, ByVal strKey As String)
Dim r As Long
r = RegDeleteKey(HKEY, strKey)
End FunctionPublic Function DeleteValue(ByVal HKEY As Long, ByVal strPath As String, ByVal strValue As String)
Dim keyhand As Long
r = RegOpenKey(HKEY, strPath, keyhand)
r = RegDeleteValue(keyhand, strValue)
r = RegCloseKey(keyhand)
End Function例子:
'添加DNS主机名
HKEY = HKEY_LOCAL_MACHINE
strPath = "System\CurrentControlSet\Services\VxD\MSTCP"
strValue = "HostName"
strdata = "Mycomputer"
If strdata <> getstring(HKEY, strPath, strValue) Then
Call savestring(HKEY, strPath, strValue, strdata)
End If'删除DNS主机名
Dim HKEY As Long
HKEY = HKEY_LOCAL_MACHINE
strPath = "System\CurrentControlSet\Services\VxD\MSTCP"
strValue = "HostName"
t = DeleteValue(HKEY, strPath, strValue)