Microsoft KB Archive/113945

= How to Read Windows Registered User & Organization =

Article ID: 113945

Article Last Modified on 10/29/2003

-

APPLIES TO


 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q113945



SUMMARY
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.



MORE INFORMATION
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.

Step-by-Step Example
The following example shows you how to implement this into your Visual Basic program.

 Start a new project in Visual Basic. Form1 is created by default.  Add the following lines to the general declarations section of Form1: ' 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

  Add a command button (Command1) to the form, and place the following code in the click event: 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

 Press the F5 key to run the program. When you click the command button, the registered user and organization should be displayed in the message box.

