Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Verifying NT Security
Message
From
02/10/1998 19:18:49
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00143504
Message ID:
00143516
Views:
19
>I am trying to put together a VFP 5.0 app that will use Windows NT 4.0 security. How can I use VFP to first figure out what NT user is logged in to the PC and then what group(s) he/she may belong to? Once I can capture that information, I hope to then use it to determine what forms and menu options are available to that user.
>
>Any help in this area would be greatly appreciated.

There are a number of ways to get the current username; the simplest, assuming that the Windows Scripting Host has been installed:
oWshNet = CREATEOBJ('wscript.network')
? oWshNet.UserName    && login to the local station
? oWshNet.DomainName  && login to the current domain

If the WSH is not available, you'll need to use the WNetGetUser() API call.  It's fairly simple to use, and prototypes in VFP as:

DECLARE INTEGER WNetGetUser IN Win32API ;
   STRING lpResourceName, ;
   STRING lpUserName, ;
   INTEGER @lpUserNameLen

cUserName = REPL(CHR(0),256)
nNameLen = 256
IF  WNetGetUser('\\MyServer\SomeShare',@cUsername, @nNameLen) = 0
   *  The first nNameLen-1 characters of cUserName now contain
   *  the name of the user accessing the resource \\MyServer\SomeShare
   *  which well might not be the WIndows Login name
ELSE
   *  Something broke
ENDIF
Determining the group membership requires the use of the NetUserGetGroups() API call. Manipulating the result really requires the use of a wrapper .DLL, since the memory used as a buffer to return the group structures needs to remain static and be relesed with NetAPIBufferFree() afterwards. You probably only need the data contained in a GROUP_USERS_INFO_0 structure, which is easier to parse. You need to pass the name of the server whose groups are to be considered; passing a null for the servername resolves only local groups.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform