Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the User and Company Name
Message
De
10/05/2001 11:29:30
 
 
À
10/05/2001 02:16:14
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00505632
Message ID:
00505798
Vues:
21
This message has been marked as the solution to the initial question of the thread.
>I would like to know if it is possible to get the
>user and company that windows is registered to
>as shown in the My Computer properties screen.
>
>
>Does anybody know if there is a function to do this?

In the Init() of the form, try:
DO CASE
   CASE UPPER(OS())='WINDOWS NT' OR UPPER(OS())='WINDOWS 4'
      lcSection=IIF('NT'$UPPER(OS()),'Software\Microsoft\Windows NT\CurrentVersion',;
       'Software\Microsoft\Windows\CurrentVersion')
      ThisForm.lblUserName.Caption=GETREGISTER(-2147483646,lcSection,'RegisteredOwner')
      ThisForm.lblUserCorp.Caption=GETREGISTER(-2147483646,lcSection,'RegisteredOrganization')
  OTHERWISE

    * Gets default user name, organization, and location of MSINFO.EXE from 
    * WIN.INI (for Windows 3.x machines)
    * Gets default user name 
    ThisForm.lblUserName.Caption=GETPROFIL('MS USER INFO','DEFNAME')

    * Get default corporation name 
    ThisForm.lblUserCorp.Caption=GETPROFIL('MS USER INFO','DEFCOMPANY')

ENDCASE
Then, create those two functions or methods, whatever you like:
FUNCTION GetRegister
* Return a value from a register
* expN1 Key
* expC1 Section
* expC2 Entry
PARAMETER tnKey,tcSection,tcString
PRIVATE lnResult,lcBuffer,lnBufferSize,lnType,lcReturn
lnResult=0
lcBuffer=SPACE(128)
lnBufferSize=LEN(lcBuffer)
lnType=0
lcReturn=''

* First need to open the appropriate key
IF RegOpenKeyEx(tnKey,tcSection,0,1,@lnResult)=0

   * Read the value for the DLL entry
   IF RegQueryValueEx(lnResult,tcString,0,@lnType,@lcBuffer,@lnBufferSize)=0

      * Strip off the junk at the end
      lcReturn=LEFT(lcBuffer,lnBufferSize-1)

   ENDIF
ENDIF

* Close the key
=RegCloseKey(lnResult)

RETURN lcReturn

FUNCTION GetProfil
* Return a value in an API mode
* expC1 Section
* expC2 Entry
PARAMETER tcSection,tcString
PRIVATE lcReturn,lcBuffer,lnBufferSize
lcBuffer=SPACE(128)
lnBufferSize=LEN(lcBuffer)
lcReturn=GetProfileString(tcSection,tcString,'',@lcBuffer,lnBufferSize)
lcReturn=LEFT(lcBuffer,lcReturn)
RETURN lcReturn
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform