Members
Technology Zones
IBM Learning Center
Articles
Hosted By
Info
|
Rated
Read 14,081 times
Related Categories
Get Windows Info
Here's some code to find the registered owner, registered organisation, product
id, and product name of your PC's installation of Windows! This works on both
95/98 and NT/2000, by looking in the CurrentVersion section of HKEY_LOCAL_MACHINESoftwareMicrosoftWindows.
You can get lots of information from there, and in this case, it looks at "RegisteredOwner",
"RegisteredOrganization", "ProductName" and "ProductId",
but you could use the code to look up any other value too.
Private Declare Function RegQueryValueExStr Lib "advapi32"
Alias "RegQueryValueExA" _
(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As
Long, _
ByRef lpType As Long, ByVal szData As String, ByRef lpcbData As
Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32" 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 RegQueryValueExLong Lib "advapi32"
Alias "RegQueryValueExA" _
(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As
Long, _
ByRef lpType As Long, szData As Long, ByRef lpcbData As Long) As
Long
Private Const ERROR_MORE_DATA = 234
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const KEY_QUERY_VALUE = &H1
Private Sub Form_Load()
Dim sKey As String
sKey = "SoftwareMicrosoftWindowsCurrentVersion"
If GetStringValue("SoftwareMicrosoftWindowsCurrentVersion",
"SystemRoot") = "" Then
sKey = "SoftwareMicrosoftWindows
NTCurrentVersion"
End If
txtRegOwner = GetStringValue(sKey, "RegisteredOwner")
txtRegOrg = GetStringValue(sKey, "RegisteredOrganization")
txtProductName = GetStringValue(sKey, "ProductName")
txtProductID = GetStringValue(sKey, "ProductId")
End Sub
Private Function GetStringValue(sSectionKey As String, sValueKey As String)
As String
Dim hKey As Long
Dim lResult As Long
Dim ordType As Long
Dim cData As Long
Dim sData As String
Dim e As Long
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sSectionKey, 0,
KEY_QUERY_VALUE, hKey)
lResult = RegQueryValueExLong(hKey, sValueKey, 0&,
ordType, 0&, cData)
If lResult And lResult <> ERROR_MORE_DATA Then
DoEvents
Exit Function
End If
If ordType = 1 Then 'REG_SZ
sData = String$(cData - 1, 0)
lResult = RegQueryValueExStr(hKey,
sValueKey, 0&, _
ordType, sData, cData)
GetStringValue = sData
Else
'MsgBox "Invalid String
Value"
End If
End Function
James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.
Comments
|
Search
Code Samples
New Members
|