How to Read Windows Registered User & Organization

Last reviewed: June 21, 1995
Article ID: Q113945
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0

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 reference words: 3.00 MSJ CodeSampleMSDN
KBCategory: kbprg kbcode
KBSubcategory: APrgOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.