PDA

نسخه کامل مشاهده نسخه کامل : يه مثال واضح ميخوام از تابع RegOpenKey و RegSetValue



Arash_XL7710i_207
17-12-2006, 07:56
که يه key بسازيم و در اون يه value مثلا با مقدار DWORD قرار بديم.

Romina2006
29-12-2006, 12:38
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type

Private Declare Function RegCreateKeyEx Lib "advapi32.dll" _
Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal _
lpSubKey As String, ByVal Reserved As Long, ByVal _
lpClass As String, ByVal dwOptions As Long, ByVal _
samDesired As Long, lpSecurityAttributes _
As SECURITY_ATTRIBUTES, phkResult As Long, _
lpdwDisposition 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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Private 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

Private Declare Function RegDeleteValue Lib _
"advapi32.dll" Alias "RegDeleteValueA" (ByVal _
hKey As Long, ByVal lpValueName As String) As Long

Const REG_OPTION_VOLATILE = 1 ' Key is not preserved when system is rebooted
Const REG_OPTION_NON_VOLATILE = 0 ' Key is preserved when system is rebooted

Const HKEY_CURRENT_USER = &H80000001
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_DYN_DATA = &H80000006
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003

Const KEY_WRITE = &H20006
Const REG_SZ = 1
Const KEY_ALL_ACCESS = &HF003F
Const REG_BINARY = 3
Const REG_DWORD = 4
Const KEY_READ = &H20019

Private Sub Command1_Click()
Dim hKey As Long
Dim secattr As SECURITY_ATTRIBUTES
Dim subkey As String
Dim neworused As Long
Dim stringbuffer1 As String
Dim stringbuffer2 As String
Dim retval As Long

subkey = "Software\Microsoft\Windows\CurrentVersion\Winlogon"
secattr.nLength = Len(secattr)
secattr.lpSecurityDescriptor = 0
secattr.bInheritHandle = 1

retval = RegCreateKeyEx(HKEY_LOCAL_MACHINE, subkey, 0, "", 0, KEY_WRITE, secattr, hKey, neworused)

If retval <> 0 Then

Exit Sub
End If

stringbuffer1 = "HELLO MR.user" & vbNullChar
stringbuffer2 = "Please check the Disk for VIRUS!Tank you" & vbNullChar

retval = RegSetValueEx(hKey, "LegalNoticeCaption", 0, REG_SZ, ByVal stringbuffer1, Len(stringbuffer1))
retval = RegSetValueEx(hKey, "LegalNoticeText", 0, REG_SZ, ByVal stringbuffer2, Len(stringbuffer2))

retval = RegCloseKey(hKey)
Text1.Text = "---->=Create"

End Sub

Private Sub Command2_Click()

Dim hKey As Long
Dim retval As Long

retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Winlogon", _
0, KEY_ALL_ACCESS, hKey)
If retval = 0 Then

retval = RegDeleteValue(hKey, "LegalNoticeCaption")
retval = RegDeleteValue(hKey, "LegalNoticeText")

retval = RegCloseKey(hKey)
Text1.Text = "---->=Deleted"
End If

End Sub

Payman_62
30-12-2006, 01:34
که يه key بسازيم و در اون يه value مثلا با مقدار DWORD قرار بديم.
سلام.
این توابع که کلید نمیسازن.
برای ساخت کلید میتونی از RegCreateKeyExA استفاده کنی.

Arash_XL7710i_207
30-12-2006, 07:07
مرسي از راهنماييت