현재 위치 - 회사기업대전 - 중국 기업 정보 - VB 전문가가 코드 수정에 도움을 줄 수 있나요?

VB 전문가가 코드 수정에 도움을 줄 수 있나요?

창과 모듈을 만들고 컨트롤(레이블 5개, 텍스트 5개, 명령 1개)을 배치하기만 하면 됩니다.

창 코드는 다음과 같습니다.

Private Sub Command1_Click()

SetStringValue(HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", Text1.Text) 호출

SetStringValue(HKEY_LOCAL_MACHINE 호출) , "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", Text2.Text)

SetStringValue2(HKEY_LOCAL_MACHINE, "SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{C09A8CD0-2C7A)를 호출합니다. - 4866-AAD0-D36CBD733EFC}", "IPAddress", Text3.Text)

SetStringValue2(HKEY_LOCAL_MACHINE, "SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{C09A8CD0-2C7A-4866-AAD0" 호출 - D36CBD733EFC}", "DefaultGateway", Text4.Text)

SetStringValue(HKEY_LOCAL_MACHINE, "SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{C09A8CD0-2C7A-4866-AAD0-D36CBD733EFC}" 호출 , "NameServer", Text5.Text)

End Sub

Private Sub Form_Load()

Command1.Caption = "쓰기"

Label1.Caption = "컴퓨터 이름:"

Text1.Text = GetStringValue(HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Control\ComputerName\ComputerName", "컴퓨터 이름")

Label2.Caption = "호스트 이름:"

Text2.Text = GetStringValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "호스트 이름")

Label3.Caption = "IP: "

Text3.Text = GetStringValue(HKEY_LOCAL_MACHINE, "SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{C09A8CD0-2C7A-4866-AAD0-D36CBD733EFC}",

"IPAddress")

Label4.Caption = "기본 게이트웨이:"

Text4.Text = GetStringValue(HKEY_LOCAL_MACHINE, "SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{C09A8CD0 -2C7A-4866-AAD0-D36CBD733EFC}", "DefaultGateway")

Label5.Caption = "DNS 서버:"

Text5.Text = GetStringValue(HKEY_LOCAL_MACHINE, "SYSTEM\ControlSet001 \Services\Tcpip\Parameters\Interfaces\{C09A8CD0-2C7A-4866-AAD0-D36CBD733EFC}", "NameServer")

End Sub

모듈 코드는 다음과 같습니다.

'레지스트리 항목 상수

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&

RegCloseKey Lib "advapi32.dll"(ByVal) 함수 선언 hKey As Long)

함수 RegCreateKey Lib "advapi32.dll" 별칭 ​​"RegCreateKeyA" 선언(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long)

RegDeleteKey Lib "advapi32.dll" 별칭 ​​"RegDeleteKeyA"(ByVal hKey As Long, ByVal lpSubKey As String) 함수 선언

RegDeleteValue Lib "advapi32.dll" 별칭 ​​" 함수 선언 RegDeleteValueA"(ByVal hKey As Long, ByVal lpValueName As String) As Long

함수 RegOpenKey Lib "advapi32.dll" 별칭 ​​"RegOpenKeyA"(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

RegOpenKeyEx Lib "advapi32.dll" Ali 함수 선언

as "RegOpenKeyExA"(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long)

함수 RegQueryValueEx Lib "advapi32.dll" 별칭 선언 ​​"RegQueryValueExA"(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long)

함수 RegQueryValueExString Lib "advapi32.dll" 별칭 선언 ​​"RegQueryValueExA " (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long)

함수 RegQueryValueExLong Lib "advapi32. dll" 별칭 ​​" RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long)

함수 RegQueryValueExNULL Lib 선언 " advapi32.dll" 별칭 ​​" RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long)

함수 선언 RegSetValueEx Lib "advapi32.dll" 별칭 "RegSetValueExA"(ByVal hKey As Long, ByVal lpValueName As String, ByVal 예약된 As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long)

Public Const REG_SZ = 1

Public Const REG_DWORD = 4

Public Sub savekey(hKey As Long, strPath As String)

Dim keyhand&

r = RegCreateKey(hKey, strPath, keyhand&)

r = RegCloseKey(keyhand&)

)

End Sub

공개 함수 GetStringValue(hKey As Long, strPath As String, strValue As String)

Dim 키핸드 As Long

긴 데이터 유형 희미

긴만큼 lResult 희미

문자열로 희미한 strBuf

긴만큼 lDataBufSize 희미

정수로 희미한 intZeroPos

r = RegOpenKey(hKey, strPath, keyhand)

lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)

lValueType = REG_SZ 그러면

strBuf = String(lDataBufSize, " ")

lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)

If lResult = ERROR_SUCCESS 그러면

intZeroPos = InStr(strBuf, Chr$(0))

If intZeroPos > 0 그러면

GetStringValue = Left$(strBuf, intZeroPos - 1)

Else

GetStringValue = strBuf

End If

End If

End If

p>

End If

p>

함수 종료

Public Sub SetStringValue(hKey As Long, strPath As String, strValue As String, strdata As String)

p>

긴 키손

긴 r 길이

r = RegCreateKey(hKey, strPath, keyhand)

r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))

r = RegCloseKey(keyhand)

End Sub

함수 GetDwordValue(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

lDataBufSize를 길게

r을 길게

키핸드를 길게

r = RegOpen

Key(hKey, strPath, keyhand)

lDataBufSize = 4

lResult = RegQueryValueEx(keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)

lResult인 경우 = ERROR_SUCCESS 그러면

IValueType = REG_DWORD이면

GetDwordValue = lBuf

End If

End If

r = RegCloseKey(keyhand)

함수 종료

함수 SetDwordValue(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)

lResult를 길게

키손을 길게

r을 길게

r = RegCreateKey(hKey, strPath, keyhand)

lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)

r = RegCloseKey(keyhand)

함수 종료

공용 함수 DeleteKey (lPredefineKey As Long, sKeyName As String)

'기본 키 삭제

Dim lRetVal As Long

Dim hKey As Long

lRetVal = RegOpenKeyEx(lPre DefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)

lRetVal = RegDeleteKey(lPredefineKey, sKeyName)

RegCloseKey(hKey)

함수 종료

p >

공개 함수 DeleteValue(lPredefineKey As Long, sKeyName As String, sValueName As String)

'키 값 삭제

Dim lRetVal As Long

긴 hKey

lRetVal = RegOpenKeyEx(lPredefineKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)

lRetVal = RegDeleteValue(hKey, sValueName)

RegCloseKey (hKey) )

함수 종료

공용 함수 QueryValue(lPredefineKey As Long, sKeyName As String, sValueName As String)

'키 값 가져오기

긴 lRetVal 어림

긴 hKey 어림

변형인 vValue 어림

lRetVal = RegOpenKeyEx(lPredefineKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)

lRetVal = RegQueryValueEx(hKey, sValueName, vValue, 0, 0, 0)

QueryValue = vValue

RegCloseKey(hKey)

기능 종료

copyright 2024회사기업대전