How to Read Windows Registered User & Organization

ID: Q113945


The information in this article applies to:


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.
  1. Start a new project in Visual Basic. Form1 is created by default.


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


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


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



REFERENCES

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