View Full Version : [vb6] leggere chiavi del reg
disumano
09-01-2004, 01:32
mi serve che una mia applicazione "sappia" che os è installato.
credo che il controllo possa essere fatto leggendo la chiave del registro di configurazione dove c'è scritto che os uso.
ora volevo sapere però come si fa ad assegnare ad una stringa il valore di una chiave del reg e se eventualmente c'è anche un altro modo per avere la stessa informazione.
grazie
maxithron
09-01-2004, 09:20
con la premessa che non sono molto ferrato in vb6, la prima cosa che dovresti fare è di leggere il registro di sistema mettendo questo codice in una classe:
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 RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal HKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal HKey As Long, ByVal dwIndex As Long, ByVal lpName As String, cbName As Long, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData 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 RegCloseKey Lib "advapi32.dll" (ByVal HKey As Long) As Long
Public Enum HKeys
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_CURRENT_CONFIG = &H80000005
HKEY_DYN_DATA = &H80000006
End Enum
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const SYNCHRONIZE = &H100000
Private 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 _
) _
)
Dim RootHKey As HKeys
Dim SubDir As String
Dim HKey As Long
Dim OpenRegOk As Boolean
Originariamente inviato da disumano
mi serve che una mia applicazione "sappia" che os è installato.
Per questo nn serve leggere il registro perchè le info su un OS le puoi reperire in altri modi...la mianiera più corretta è questa...
é una mia funzione che utilizza le API, se nn ti piace cambiala pure ma cmq il modo di riperirle è cmq una parte della funzione.
Option Explicit
Public Enum OS_INFORMATION
OSI_PLATFORM
OSI_MAJOR_VERSION
OSI_MINOR_VERSION
OSI_BUILD_NUMBER
OSI_UPDATE
End Enum
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Public Function GetOSInformation(ByVal OSInformation As OS_INFORMATION) As String
Dim OSInfo As OSVERSIONINFO
'imposto la dimensione della struttura
OSInfo.dwOSVersionInfoSize = Len(OSInfo)
'prelevo le informazioni di windows
Call GetVersionEx(OSInfo)
Select Case OSInformation
Case 0
'testo di che genere di OS c'è
Select Case OSInfo.dwPlatformId
Case 0: GetOSInformation = "Windows 32s"
Case 1: GetOSInformation = IIf(OSInfo.dwMinorVersion = 0, "Windows 95", "Windows 98")
Case 2: GetOSInformation = IIf(OSInfo.dwMajorVersion = 4, "Windows NT", IIf(OSInfo.dwMinorVersion = 0, "Windows 2000", "Windows XP"))
End Select
Case 1: GetOSInformation = OSInfo.dwMajorVersion
Case 2: GetOSInformation = OSInfo.dwMinorVersion
Case 3: GetOSInformation = OSInfo.dwBuildNumber
Case 4: GetOSInformation = Left$(OSInfo.szCSDVersion, InStr(1, OSInfo.szCSDVersion, Chr$(0)))
End Select
End Function
Spero di nn avere sbagliato a tracopiare nulla altrimenti mi dici che cosa ti manca, metti tutto in un modulo (se ti va) e basta che dal main richiami la funzione e ti fa scegliere lui che cosa richiedere.
Ti posto anche la funzione per sapere se un OS è base NT o no, magari ti serve...
Public Function IsWinNT() As Boolean
Dim myOS As OSVERSIONINFO
myOS.dwOSVersionInfoSize = Len(myOS)
Call GetVersionEx(myOS)
IsWinNT = (myOS.dwPlatformId = 2) '2 parametro piattaforma NT
End Function
maxithron
09-01-2004, 13:04
Aspettavo con ansia le tue correzioni :D :D
Originariamente inviato da maxithron
Aspettavo con ansia le tue correzioni :D :D
:oink:
disumano
10-01-2004, 23:28
grazie:D
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.