Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do I get a Registry Key Value?
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00529701
Message ID:
00529715
Views:
9
This message has been marked as the solution to the initial question of the thread.
>My goal is to get a string telling me who is currently logged on to WindowsNT. I have found a Registry Key (HKEY_LOCAL_MACHINE/Software/Microsoft/Windows NT/CurrentVersion/Winlogon/DefaultUserName) that I believe holds this information.
>
>There might be an easier way but what I have done so far is add the Registry.vcx to my project and copied a registry object to my form. I am attemping to figure out how to use it but there isn't much help available that I've found. It seems I should be using the GetKeyValue method or the GetRegKey method.
>
>I have tried this code:
>pUser=thisform.registry1.getkeyvalue('HKEY_LOCAL_MACHINE/ ... /DefaultUserName')
>
>pUser is set to equal -105 so I'm obviously doing something wrong. Could someone please tell me how to set up the registry object to return the UserID or give me an easier way of getting it?
>
>Thanks in advance,
Justin,

To use the registry class, you first have to have to open the key:
#DEFINE HKEY_LOCAL_MACHINE          -2147483646
SET CLASSLIB TO REGISTRY.VCX ADDITIVE
oReg = CREATEOBJECT('Registry')
RELEASE CLASSLIB REGISTRY
IF oReg.OpenKey('Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName) = 0 && ERROR_SUCCESS
  lcuser = SPACE(100)
  IF oReg.GetKeyValue("", @lcuser) = 0 && Get the default value
    ? lcuser
  ENDIF
ENDIF
To get the currently logged in user, you can use either the GetUserName() API call, or if available the Windows Script Host's Network object UserName property.
George

Ubi caritas et amor, deus ibi est
Previous
Reply
Map
View

Click here to load this message in the networking platform