非常非常急的问题,谢谢,谢谢了!在线等啊,哭!

hackate 2004-04-30 06:27:42
REG_DWORD

这个大家一看都清楚啊,就是注册表里面的啊!

   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 RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
   Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

  然后声明以下两个常数,要进行注册表写入的位置是在HKEY_LOCAL_MACHINE下,我们可以在VB自带的API文本查看器中找到这些常数的定义方法。

   Private Const HKEY_LOCAL_MACHINE = &H80000002
   Private Const REG_SZ = 1

  然后使用如下语句就行了,你可以把这段代码放在程序的某个位置:

  '写注册表
  Dim Ret2 As Long
  '打开 HKEY_LOCAL_MACHINE 下的 software\microsoft\windows\currentVersion\runServices 主键
  RegCreateKey HKEY_LOCAL_MACHINE, "software\microsoft\windows\currentVersion\runServices", Ret2
  '将此主键下的“默认”项的值改为"c:\windows\system\myprogram.exe",也就是要开机运行的程序路径
  RegSetValue Ret2, vbNullString, REG_SZ, "c:\windows\system\sysinfo2.exe", 4
  '关闭对主键的操作
  RegCloseKey Ret2

这个是REG_SZ的啊,和我的REG_DOWORD不同的操作方法啊

我要实现的操作是在
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp]

这里下面,如果您的系统是WIN2K/NT/XP应该都有,因为这个终端服务的,来到这个下面的目的就是改终端的端口了啊,端口的数值保存里面是用的REG——DOWORD保存的,所以我做的时候操作就不会了,跟他们的套用也不行啊,你试试,帮我一下,看如何改呢,你们来到我说的这个注册表路径下面就看到一个

"PortNumber"这个键值,我就要改这个里面的值,他的值是
00000d3d(3389)

00000d3d就是二进制,那么(3389)是十进制啊,我先改他们的值啊,就是改端口号啊比如把3389改成1234
那么二进制也就随着改变,那个(3389)也变成了(1234),用注册表,如何做到呢,谢谢了

...全文
19 13 点赞 打赏 收藏 举报
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
mingtian2008 2004-05-03
up
  • 打赏
  • 举报
回复
lsftest 2004-05-02
前几天被人无缘无故地删了帖子又扣了信誉分,现在回答问题也要被人砍。。。csdn真是越来越恐怖了。。。。。呵呵。。。老兄,你认错人啦。。。。。。
  • 打赏
  • 举报
回复
hackate 2004-05-01
啊,你就是猪水牛呢,怎么又用这个号啊,杀了你呢!
  • 打赏
  • 举报
回复
lsftest 2004-04-30
你有没有试过???有REG_DOWORD这种类型吗???是REG_DWORD吧。。。。
看:RegSetValueEx hKey, "PortNumber", 0, REG_DWORD, L, 4



这里下面,如果您的系统是WIN2K/NT/XP应该都有,因为这个终端服务的,来到这个下面的目的就是改终端的端口了啊,端口的数值保存里面是用的REG——DOWORD保存的,所以我做的时候操作就不会了,跟他们的套用也不行啊,你试试,帮我一下,看如何改呢,你们来到我说的这个注册表路径下面就看到一个

"PortNumber"这个键值,我就要改这个里面的值,他的值是
00000d3d(3389)

00000d3d就是二进制,那么(3389)是十进制啊,我先改他们的值啊,就是改端口号啊比如把3389改成1234
那么二进制也就随着改变,那个(3389)也变成了(1234),用注册表,如何做到呢,谢谢了

=========================
我的代码是能够成功修改你说的键的。。。。是在xp下。。。如果是nt或2000就没试过了。。。
  • 打赏
  • 举报
回复
hackate 2004-04-30
晕哦,可是我说的是
REG_DOWORD的啊,可是你的就不是,不是吗?
  • 打赏
  • 举报
回复
lsftest 2004-04-30
一向就讨厌注册表,觉得又长又丑又无聊,居然还有人专门研究这破东西。。。。于是连带把注册表相关的编程也一起讨厌了。。。。。。。。


模块中:
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 HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006

Public Const REG_NONE = 0
Public Const REG_SZ = 1
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3
Public Const REG_DWORD = 4
Public Const REG_DWORD_BIG_ENDIAN = 5
Public Const REG_MULTI_SZ = 7

Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
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
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

程序中:
Private Sub Command1_Click()

Dim ret As Long, hKey As Long, hKey2 As Long
Dim L As Long

ret = RegOpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp", hKey)
Print hKey

L = 1234
RegSetValueEx hKey, "PortNumber", 0, REG_DWORD, L, 4



RegCloseKey hKey
RegCloseKey hKey2


End Sub

vb6+xp下通过。。。。。
  • 打赏
  • 举报
回复
daisy8675 2004-04-30
拜托好好看,偶8想給你解釋...

Const REG_BINARY = 3 ' Free form binary
請注意這個好8好

偶最近心情8太好,你還是8要給偶講了
  • 打赏
  • 举报
回复
hackate 2004-04-30
可这里根本就说到我这个需要的东西,你帖这个也没用啊,不是吗?
  • 打赏
  • 举报
回复
daisy8675 2004-04-30


'This program needs 3 buttons
Const REG_SZ = 1 ' Unicode nul terminated string
Const REG_BINARY = 3 ' Free form binary
Const HKEY_CURRENT_USER = &H80000001
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 RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private 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
Private 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
Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
'retrieve nformation about the key
lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
If lResult = 0 Then
If lValueType = REG_SZ Then
'Create a buffer
strBuf = String(lDataBufSize, Chr$(0))
'retrieve the key's content
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
If lResult = 0 Then
'Remove the unnecessary chr$(0)'s
RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
End If
ElseIf lValueType = REG_BINARY Then
Dim strData As Integer
'retrieve the key's value
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = strData
End If
End If
End If
End Function
Function GetString(hKey As Long, strPath As String, strValue As String)
Dim Ret
'Open the key
RegOpenKey hKey, strPath, Ret
'Get the key's content
GetString = RegQueryStringValue(Ret, strValue)
'Close the key
RegCloseKey Ret
End Function
Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
Dim Ret
'Create a new key
RegCreateKey hKey, strPath, Ret
'Save a string to the key
RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
'close the key
RegCloseKey Ret
End Sub
Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
Dim Ret
'Create a new key
RegCreateKey hKey, strPath, Ret
'Set the key's value
RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4
'close the key
RegCloseKey Ret
End Sub
Sub DelSetting(hKey As Long, strPath As String, strValue As String)
Dim Ret
'Create a new key
RegCreateKey hKey, strPath, Ret
'Delete the key's value
RegDeleteValue Ret, strValue
'close the key
RegCloseKey Ret
End Sub
Private Sub Command1_Click()
Dim strString As String
'Ask for a value
strString = InputBox("Please enter a value between 0 and 255 to be saved as a binary value in the registry.", App.Title)
If strString = "" Or Val(strString) > 255 Or Val(strString) < 0 Then
MsgBox "Invalid value entered ...", vbExclamation + vbOKOnly, App.Title
Exit Sub
End If
'Save the value to the registry
SaveStringLong HKEY_CURRENT_USER, "KPD-Team", "BinaryValue", CByte(strString)
End Sub
Private Sub Command2_Click()
'Get a string from the registry
Ret = GetString(HKEY_CURRENT_USER, "KPD-Team", "BinaryValue")
If Ret = "" Then MsgBox "No value found !", vbExclamation + vbOKOnly, App.Title: Exit Sub
MsgBox "The value is " + Ret, vbOKOnly + vbInformation, App.Title
End Sub
Private Sub Command3_Click()
'Delete the setting from the registry
DelSetting HKEY_CURRENT_USER, "KPD-Team", "BinaryValue"
MsgBox "The value was deleted ...", vbInformation + vbOKOnly, App.Title
End Sub
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Command1.Caption = "Set Value"
Command2.Caption = "Get Value"
Command3.Caption = "Delete Value"
End Sub

你自己先看這例子吧,這個的問題偶實在不想去做了
  • 打赏
  • 举报
回复
hackate 2004-04-30
那你帮我一下好么?谢谢你,帮帮我吧!
  • 打赏
  • 举报
回复
daisy8675 2004-04-30
二進制的時候還要進行轉換呀,你這麼強行寫當然有問題了
  • 打赏
  • 举报
回复
hackate 2004-04-30
这到底是为什么啊?
  • 打赏
  • 举报
回复
hackate 2004-04-30
我这人问问题就不知道,我的表达能力差,别怪我啊,

总得来说也就是说如何对注册表的REG_DOWORD进行修改呢,谢谢了!
  • 打赏
  • 举报
回复
相关推荐
发帖
VB基础类
加入

7545

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2004-04-30 06:27
社区公告
暂无公告