Microsoft KB Archive/153309

= How To Retrieve the Registered User Under Windows =

Article ID: 153309

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Enterprise Edition

-



This article was previously published under Q153309



SUMMARY
The strings related to the registered user of a particular copy of Windows are stored in a string inside USER.EXE. They are displayed in the Help About box of File Manager, or Explorer in Windows 95 and Windows 98. This article provides a code sample showing how to extract this information.



Step-by-Step Example
 Start a new project in Visual Basic. Form1 is created by default. Place a command button on the form.  Add the following code to the form1 code window: Option Explicit

Private Declare Function GetModuleHandle Lib "Kernel" _ (ByVal Module As String) As Integer Private 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 ihInst As Integer Dim sUserName As String * 128 Dim sOrganization As String * 128 Dim sTitle As String Dim iLength As Integer ihInst = GetModuleHandle("user.exe") iLength = LoadString(ihInst, 514, sUserName, Len(sUserName)) sUserName = Left$(sUserName, iLength) iLength = LoadString(ihInst, 515, sOrganization, Len(sOrganization)) sOrganization = Left$(sOrganization, iLength) Print sUserName Print sOrganization End Sub  Press F5 to run the project. Click the command button. The information should be printed on the form.

