请给出详细的代码和注释,并列出所用的控键,如果可以的话把整个做好的工程发到我邮箱里(mrzhousanlong@126.com)本人感激不尽!!!
请给出详细的代码和注释,并列出所用的控键,如果可以的话把整个做好的工程发到我邮箱里(mrzhousanlong@126.com)本人感激不尽!!!
我做了一个扫描电脑IP和子网掩码!!你看看哦!! Option Explicit
Const REG_SZ As Long = 1
Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) 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 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.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 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 RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Dim aaa As String
Private Sub Command1_Click()
Dim hKey As Long, hKey1 As Long, hKey2 As Long, ret As Long, ret1 As Long, lenData As Long, typeData As Long
Dim Name As String, name1 As String, name2 As String, s As String, S1 As String
Dim idx As Integer
idx = 0
Name = String(256, Chr(0))
RegCreateKey HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\Class\NetTrans", hKey
Text1.Text = hKey
Do
ret = RegEnumKey(hKey, idx, Name, Len(Name))
If ret = 0 Then
aaa = Left(Name, InStr(Name, Chr(0)) - 1)
aaa = "System\CurrentControlSet\Services\Class\NetTrans\" & aaa
ret = RegOpenKey(HKEY_LOCAL_MACHINE, aaa, hKey)
'获得IP地址
If ret = 0 Then
name1 = "IPAddress"
name2 = "IPMask"
ret = RegQueryValueEx(hKey, name1, 0, typeData, ByVal vbNullString, lenData)
s = String(lenData, Chr(0))
RegQueryValueEx hKey, name1, 0, typeData, ByVal s, lenData
If s <> "" Then s = Left(s, InStr(s, Chr(0)) - 1)
'获得子网掩码
ret1 = RegQueryValueEx(hKey, name2, 0, typeData, ByVal vbNullString, lenData)
S1 = String(lenData, Chr(0))
RegQueryValueEx hKey, name2, 0, typeData, ByVal S1, lenData
If S1 <> "" Then S1 = Left(S1, InStr(S1, Chr(0)) - 1)
If Val(s) > 0 Then
Text1.Text = s
Text2.Text = S1
Command2.Enabled = True
Exit Sub
End If
End If
idx = idx + 1
End If
Loop Until ret <> 0
End Sub
Private Sub Command2_Click()
Dim hKey As Long
If Text1.Text <> "" Then
RegCreateKey HKEY_LOCAL_MACHINE, aaa, hKey
' 修改IP地址
RegSetValueEx hKey, "IPAddress", 0, REG_SZ, ByVal Text1.Text, 13
' 修改子网掩码
RegSetValueEx hKey, "IPMask", 0, REG_SZ, ByVal Text2.Text, 13
RegCloseKey hKey
End If
End Sub
Private Sub Command3_Click()
End
End Sub