System registry in VB

zhaozj2021-02-17  31

System registry in VB

Ini files are mostly in-inch to put their own interface or initialize information, and the application should use system information or to know some information that has been registered in the system, it is necessary to read the system registry, such as some applications need to use calls. MS Outlook Express needs to read the path from the installroot from HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / Outlook Express / Microsoft / Outlook Express.

Declinations:

Option expedition

Public const _ = & h20000

Public const standard_rights_read = (Read_Control)

Public const standard_rights_write = (Read_Control)

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 synchronize = & h100000

Public const standard_rights_all = & h1f0000

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_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 key_execute = ((Key_Read) and (not synchronize))

Public const error_success = 0 &

Declare function regopenkeyex lib "advapi32.dll" Alias ​​"regopenkeyexa" (Byval HKEYEXA "(Byval Lpsubkey As String, Byval Uloptions As long, Byval Samdesired As Long, PhkResult As long) As long

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 LongDeclare Function RegCloseKey Lib "advapi32.dll "(Byval HKEY As Long) As Long

Function SDageTRegentry (strkey as string, strsubkeys as string, lngtype as ring) AS String

On Error Goto SdageTregentry_ERR

Dim Lngresult As Long, LngKey As Long

Dim LNGHANDLE AS Long, LNGCBDATA AS Long

DIM STRET AS STRING

Select Case StrKey

Case "hkey_classes_root": LngKey = & H80000000

Case "hkey_current_config": LngKey = & H80000005

Case "hkey_current_user": LngKey = & H80000001

Case "hkey_dyn_data": lngKey = & h80000006

Case "hkey_local_machine": lngKey = & h80000002

Case "HKEY_PERFORMANCE_DATA": LngKey = & H80000004

Case "HKEY_USERS": LngKey = & H80000003

Case Else: Exit Function

End SELECT

IF not error_success = regopenkeyex (LNGKEY, STRSUBKKEYS, 0 &, Key_Read, LNGHANDLE) THEN EXIXIT function

LNGRESULT = RegQueryValueex (LNGHANDLE, STRVALNAME, 0 &, LNGTYPE, BYVAL STRRET, LNGCBDATA)

Strret = space (LNGCBDATA)

LNGRESULT = RegQueryValueex (LNGHANDLE, STRVALNAME, 0 &, LNGTYPE, BYVAL STRRET, LNGCBDATA)

IF not error_success = regclosekey (LNGHANDLE) THEN LNGTYPE = -1 &

SDAGETREGENTRY = STRRET

SDAGETREGENTRY_EXIT:

ON Error Goto 0

EXIT FUNCTION

SDAGETREGENTRY_ERR:

LNGTYPE = -1 &

MsgBox Err & "> & Error $, 16," Genutils / SDageTRegentry "

Resume SDageTRegentry_exit

END FUNCTION

It seems that it is very complicated, but it is simple, which has reached a complex purpose. For example: Using Outlook Express

Dim Outlook_path as string

Dim shString as string

Outlook_path = SDAGETREGENTRY ("HKEY_LOCAL_MACHINE", "Software / Microsoft / Outlook Express /", "InstallRoot", 2)

ShString = MID (Trim (Outlook_Path), 1, Len (Outlook_Path) - 1) & "/msimn.exe"

Shell shString

转载请注明原文地址:https://www.9cbs.com/read-30620.html

New Post(0)