How to Read Windows Registered User & OrganizationID: Q113945
|
The example in this article demonstrates how to extract user registration information for use in an About box for programs running under Microsoft Windows. It shows you how to retrieve this information from the string table resource inside USER.EXE.
The registered owner and organization of Microsoft Windows versions 3.x are
stored as string resources in USER.EXE. By knowing the resource identifier,
you can use the LoadString Windows API function to read these values into
your Visual Basic program. For the registered owner, the resource
identifier is 514, and for the registered organization, the resource
identifier is 515.
' Enter each of the following Declare statements as one, single line:
Declare Function GetModuleHandle Lib "Kernel" (ByVal Module As String)
As Integer
Declare Function LoadString Lib "User" (ByVal hInst As Integer,
ByVal wID As Integer, ByVal buf As Any, ByVal size As Integer)
As Integer
Sub Command1_Click ()
Dim hInst As Integer
Dim user As String, organization As String, title As String
Dim length As Integer
hInst = GetModuleHandle("user.exe")
' Get user name:
user = Space$(256)
length = LoadString(hInst, 514, user, Len(user))
user = Left$(user, length)
' Get organization:
organization = Space$(256)
length = LoadString(hInst, 515, organization, Len(organization))
organization = Left$(organization, length)
title = "This copy of Windows Registered to:"
MsgBox user & Chr(13) & Chr(10) & organization, , title
End Sub
The information in this article came from a companion application for "Windows Questions and Answers" by Matt Pietrek ("Microsoft Systems Journal," Vol. 8, No. 10). It is also located on the Microsoft Developers Network (MSDN) CD number 6.
Additional query words: 3.00 MSJ CodeSampleMSDN
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 8, 1999