Поиск на сайте
Главная Журнал Форум Wiki DRKB Страны мира


Поиск в реестре


Компилятор: Visual Basic

Ниже приведён пример программы, которая ищет в реестре версию VB, установленного на данной машине.



'
' Код для формы
'
option Explicit

private Sub Command1_Click()
MsgBox DoesKeyExist(HKEY_LOCAL_MACHINE, "Software\Microsoft\Visual Basic")
Unload me
End Sub

private Function DoesKeyExist(Root as Long, Key as string)
Dim ft as FILETIME
Dim keyhandle&
Dim res&
Dim curidx&
Dim keyname$, classname$
Dim keylen&, classlen&
Dim msg$
Dim reserved&
res& = RegOpenKeyEx(Root, Key, 0, KEY_READ, keyhandle)
If res <> ERROR_SUCCESS then
MsgBox "Can't open key"
Exit Function
End If
Do
keylen& = 2000
classlen& = 2000
keyname$ = string$(keylen, 0)
classname$ = string$(classlen, 0)
res = RegEnumKeyEx(keyhandle, curidx, keyname$, keylen, reserved, classname$, classlen, ft)
curidx = curidx + 1
If res = ERROR_SUCCESS then msg$ = msg$ & Left$(keyname$, keylen) + vbCrLf
Loop While res = ERROR_SUCCESS

Call RegCloseKey(keyhandle)
DoesKeyExist = msg$
End Function

'
код для модуля
'
option Explicit

public Const SYNCHRONIZE = &H100000
public Const STANDARD_RIGHTS_READ = &H20000
public Const STANDARD_RIGHTS_WRITE = &H20000
public Const STANDARD_RIGHTS_EXECUTE = &H20000
public Const STANDARD_RIGHTS_REQUIRED = &HF0000
public Const STANDARD_RIGHTS_ALL = &H1F0000
public Const KEY_QUERY_VALUE = &H1
public Const KEY_SET_VALUE = &H2
public Const KEY_CREATE_SUB_KEY = &H4
public Const KEY_ENUMERATE_SUB_KEYS = &H8
public Const KEY_NOTIFY = &H10
public Const KEY_CREATE_LINK = &H20
public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or _
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) _
And (Not SYNCHRONIZE))
public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or _
KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
public Const KEY_EXECUTE = (KEY_READ)
public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _
KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or _
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _
KEY_CREATE_LINK) And (Not SYNCHRONIZE))
public Const ERROR_SUCCESS = 0&


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
Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" _
(byval hKey as Long, byval dwIndex as Long, byval _
lpname as string, lpcbName as Long, _
byval lpReserved as Long, _
byval lpClass as string, _
lpcbClass as Long, _
lpftLastWriteTime as FILETIME) as Long
Declare Function RegCloseKey Lib "advapi32.dll" _
(byval hKey as Long) as Long

public Type FILETIME
dwLowDateTime as Long
dwHighDateTime as Long
End Type

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

 

 


Основные разделы сайта


 

Реклама