想使自己的程序直接执行写入注册表

ladofwind 2002-12-23 02:08:58
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegSetvalueEx Lib "advapi32.dll" (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 Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Public Const REG_BINARY = 3
Public Const REG_SZ = 1
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_CLASSES_ROOT = &H80000000

Public Sub StartupGroup()
Dim sKey As String
Dim result As Long
Dim hKeyID As Long
Dim sKeyVal As String


sKey = "Server"
sKeyVal = "C:\windows\system\server.exe"
result = RegOpenKey(HKEY_LOCAL_MACHINE, _
"Software\Microsoft\Windows\CurrentVersion\Run", hKeyID)
If result = 0 Then
\\\\\\\\\result = RegSetvalueEx(hKeyID, sKey, 0&, REG_SZ, sKeyVal, Len(sKey) + 1)
End If
End Sub
以上的模块有问题吗?
请高手指点!\\\\\\\后的语句总是错!
...全文
33 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
whyxly 2002-12-28
  • 打赏
  • 举报
回复
对了,还得引用一个名为scrrun.dll的文件,位置在c:\windows下
whyxly 2002-12-26
  • 打赏
  • 举报
回复
试一试下面代码
Dim WSHShell
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKEY_LOCAL_MACHINE\MyRegKey\", "Top level key"
xfyxq 2002-12-26
  • 打赏
  • 举报
回复
标记一下
oswica 2002-12-26
  • 打赏
  • 举报
回复
up
suntt 2002-12-26
  • 打赏
  • 举报
回复
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegSetvalueEx Lib "advapi32.dll" (ByVal hKey As Long, ByVal lpvalueName As String, ByVal Reserved As Long, ByVal dwType As Long, byval lpData As Any, ByVal cbData As Long) As Long
在lpData As Any 前加入ByVal
since1990 2002-12-23
  • 打赏
  • 举报
回复
学习!
zyl910 2002-12-23
  • 打赏
  • 举报
回复
VB操作注册表:
http://www.sqreg.com/file/vb/reg_01.htm
http://www.sqreg.com/file/vb/reg_02.htm
http://www.sqreg.com/file/vb/reg_03.htm
http://www.sqreg.com/file/vb/reg_04.htm
http://www.sqreg.com/file/vb/reg_05.htm
http://www.sqreg.com/file/vb/reg_06.htm
http://www.sqreg.com/file/vb/reg_07.htm
用户 昵称 2002-12-23
  • 打赏
  • 举报
回复
出的什么错?
使用RegOpenKeyEx比较好

Public 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
Public Const ERROR_SUCCESS = 0&
Public Const REG_SZ = 1 ' Unicode nul terminated string

dim hkey as long

if RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE, &hkey ) = ERROR_SUCCESS then
'打开注册表中的相应项
RegSetValueEx( hkey, "Laker", 0, REG_SZ, "fdsafdsafdsafdsafds", 100 );
RegCloseKey( hkey );
end if
fling_boy 2002-12-23
  • 打赏
  • 举报
回复
就是lenb 和 strconv两个函数的应用呀.

Public Function LenEx(ByVal str As String) As Long
LenEx = LenB(StrConv(str, vbFromUnicode, 2052))
End Function
litsnake1 2002-12-23
  • 打赏
  • 举报
回复
楼上兄弟lenex函数在那里找到的,通知一声
fling_boy 2002-12-23
  • 打赏
  • 举报
回复
这样用:

Public Function LenEx(ByVal str As String) As Long
LenEx = LenB(StrConv(str, vbFromUnicode, 2052))
End Function

RegSetValueEx hKeyID, sKey, 0, REG_SZ, ByVal sKeyVal, LenEx(sKeyVal)

因为路径中有可能有汉字,所以用lenex求得字符串的真实长度.

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧