PDA

View Full Version : Free DLL + Source Code: Get User Group Membership



NewsArchive
01-24-2005, 12:59 AM
[Monday, January 24, 2005 8:25 AM]

I've been anxious to move from WISE to SetupBuilder for quite some time. I
removed one of the remaining barriers to doing so by porting some WISE script
code to Clarion.

I am making this code available to anyone here that would like it. The
download contains the Clarion source project, DLL, and an SB5 script to test
it with. The compiled script is in the UserGroupsTest directory, so you can
test it without recompiling the script, or the Clarion project. If you modify
the SB5 script, you will have to change the Support File path to
InstallFunc.dll to reflect its location on your system.

Download: ftp.lanbytes.net/pub/sb5/install.func.zip

MemberOfGroup( *cstring ), long, pascal

InstallFunc.dll exports the function above. Its cstring parameter is the name
of a Windows user group for which you wish to determine membership of the
current user. MemberOfGroup() performs case insensitive match of incoming
user group name with local groups to which the user belongs. It returns True
(1) for a match, False (0) for no match, and (-1) if an error occurs. This
makes determining if the user is in an arbitrary group trivial from SB5.

GetOSVersion(), long, pascal

This may be in SB5 now, but I need to determine the specific Windows platform
under which an install is being performed. GetOSVersion() returns a numeric
constant representing one of the following as defined in InstallFunc.inc.
Some of you may find a use for this in your own work outside of SB5. If you
haven't seen this done before, you may be surprised at how easy it is.

WIN_WINDOWS_95
WIN_WINDOWS_98
WIN_WINDOWS_ME
WIN_WINDOWS_NT4
WIN_WINDOWS_2K
WIN_WINDOWS_XP
WIN_WINDOWS_NET_03

Caveats: MemberOfGroup() is NT4/2K/XP centric. I no longer maintain a 9x/ME
box for testing, and am generally not impressed by the large numbers of those
OS installations that survive. It may work, though.

This implementation only handles local groups. That is, those on the local
machine. I don't currently have a need for global group membership
information, but it would be easy to add.

While the 9x/ME thing makes everyday use of this impractical for many,
there's less than 500 lines of code to the whole thing, and it contains work
that some folks may find interesting. Something that was particularly fun for
me was dealing with the Unicode strings required of the Netapi. It turns out
to be quite straightforward for this bit of work.

My humble thanks to the Hillbilly that helped me with the crucial bit of
pointer manipulation that slipped by me. May it rain pizza on his porch every
day. :}

Enjoy!

--
Best regards,

Mark

NewsArchive
01-25-2005, 01:23 AM
[Monday, January 24, 2005 11:35 PM]

The InstallFunc package was modified earlier today to make the following
changes.

Function added:

EnumGroupMembership( long, *cstring ), long

This function allows building a list of all groups to which a user is a
member. The example script was modified to demonstrate its use, although
simply displays each group name in a message.

EnumGroupMembership() is called within a loop in your SB5 by passing it two
SB5 variables; a 1 based counter that is incremented by the script, and a
variable to hold the group name returned by each call. EnumGroupMembership()
returns True (1) when another group name is available and it should be called
again, and returns False (0) when no more group names are present. You should
break the loop and it returns False.

GetOSVersion() as renamed to rsc_GetOSVersion(), as the original name was too
generic.

--
Best regards,

Mark

NewsArchive
01-25-2005, 09:22 AM
[Tuesday, January 25, 2005 5:26 PM]

Mark,

Very interesting code. Thanks so much for sharing your knowledge!

Friedrich

--
Friedrich Linder
www.lindersoft.com
Fax: 1.954.252.3910

NewsArchive
01-25-2005, 10:34 AM
[Tuesday, January 25, 2005 5:48 PM]

>Mark,
>
>Very interesting code. Thanks so much for sharing your knowledge!

You're welcome, Friedrich. You may not recall that you helped me in a huge
way several years ago with cryptx. It sits at the base of my licensing system
and is crucial in a number of other places I use it. I haven't forgotten your
generosity. :} Now when I pester you to make SB better, just remember that's
the price you pay for being so nice. ;}

--
Best regards,

Mark

NewsArchive
01-25-2005, 10:34 AM
[Tuesday, January 25, 2005 6:37 PM]

<bg> :)

Unbelievable. This was five years ago. Time flies when you are having fun
:)

Friedrich

NewsArchive
01-27-2005, 12:42 AM
[Wednesday, January 26, 2005 6:14 AM]

There was one last addition to this package today.

Function added:

EnumGroupMembershipEx( *cstring ), long

This function places all groups to which the user belongs into the passed
cstring. The string is formatted for use as a variable parameter to an SB5
combo dialog.

The sample script was modified to demonstrate this. It is used in the dialog
set after the other function call tests.

--
Best regards,

Mark