Account Groups

  • Thread starter Thread starter Steven Licciardi
  • Start date Start date
S

Steven Licciardi

I am accessing an Access database with User groups/accounts set up, is there
any way for me to determine which groups indvidual accounts are a member of
from my .net application.

i.e. if my connection string is :

Dim STR_CONNECTION As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=db.mdb; User ID=Alice; Password=AliceABC"

Is there any way to determine what group Alice is in?

Thanks,

Steven
 
¤ I am accessing an Access database with User groups/accounts set up, is there
¤ any way for me to determine which groups indvidual accounts are a member of
¤ from my .net application.
¤
¤ i.e. if my connection string is :
¤
¤ Dim STR_CONNECTION As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
¤ Source=db.mdb; User ID=Alice; Password=AliceABC"
¤
¤ Is there any way to determine what group Alice is in?
¤

I don't believe you can use Access SQL DDL so you will probably need to use ADOX (Microsoft ADO Ext
2.x for DDL and Security):

http://msdn.microsoft.com/library/d...susersappendchangepasswordmethodsexamplex.asp


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Uzytkownik "Paul Clement said:
¤ I am accessing an Access database with User groups/accounts set up, is
there
¤ any way for me to determine which groups indvidual accounts are a member
of
¤ from my .net application.
¤ (...)

I don't believe you can use Access SQL DDL so you will probably need to
use ADOX (Microsoft ADO Ext
2.x for DDL and Security):

Another option is use system tables or queries. In Access membership of
users is preserved in mdw file, that is specific access database file. There
is query: MSysUserMemberships (among others) that contains information you
want. Example of use;

using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;

namespace TestMemberOfGroupMdwCsharp
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string user = "Grzegorz";
Test t = new Test(@"E:\Development\Test.mdw");

try
{
ArrayList groups = t.Groups(user);
System.Console.WriteLine(user + "'s groups:");
foreach(string gr in groups)
System.Console.WriteLine(gr);
}
catch(OleDbException ex)
{
System.Console.WriteLine(ex.Message);
}

System.Console.ReadLine();
}
}

class Test
{
OleDbConnection con;
OleDbCommand grC;
public Test(string mdwFile)
{
//path, user and password to any mdw file,
//it can be also mdwFile, but in the situation
//true password and user id is needed
string systemDb = @"C:\Windows\System32\System.mdw";
string user = "Admin";
string pass = "";

con = new OleDbConnection(
";Provider=Microsoft.Jet.OLEDB.4.0" +
";Data Source=" + mdwFile +
";Jet OLEDB:System database=" + systemDb +
";Password=" + pass + ";User ID=" + user);

//reference to access system database query
grC = new OleDbCommand("MSysUserMemberships", con);
grC.CommandType = CommandType.StoredProcedure;
grC.Parameters.Add("@UserName", OleDbType.VarChar);
}

public ArrayList Groups(string userName)
{
ArrayList usGroups = new ArrayList();
con.Open();
try
{
grC.Parameters["@UserName"].Value = userName;
OleDbDataReader dr = grC.ExecuteReader();
while(dr.Read())
usGroups.Add(dr.GetString(0));
}
finally
{
con.Close();
}
return usGroups;
}
}
}

Of course using system tables/queries is less recommended - it is some
undocumented feature and in future version of Access it can be changed.

I hope it helps.
Grzegorz
 
I'll explore both of these options.

Thanks,

Steven

Grzegorz Danowski said:
Uzytkownik "Paul Clement said:
¤ I am accessing an Access database with User groups/accounts set up, is
there
¤ any way for me to determine which groups indvidual accounts are a
member of
¤ from my .net application.
¤ (...)

I don't believe you can use Access SQL DDL so you will probably need to
use ADOX (Microsoft ADO Ext
2.x for DDL and Security):

Another option is use system tables or queries. In Access membership of
users is preserved in mdw file, that is specific access database file.
There is query: MSysUserMemberships (among others) that contains
information you want. Example of use;

using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;

namespace TestMemberOfGroupMdwCsharp
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string user = "Grzegorz";
Test t = new Test(@"E:\Development\Test.mdw");

try
{
ArrayList groups = t.Groups(user);
System.Console.WriteLine(user + "'s groups:");
foreach(string gr in groups)
System.Console.WriteLine(gr);
}
catch(OleDbException ex)
{
System.Console.WriteLine(ex.Message);
}

System.Console.ReadLine();
}
}

class Test
{
OleDbConnection con;
OleDbCommand grC;
public Test(string mdwFile)
{
//path, user and password to any mdw file,
//it can be also mdwFile, but in the situation
//true password and user id is needed
string systemDb = @"C:\Windows\System32\System.mdw";
string user = "Admin";
string pass = "";

con = new OleDbConnection(
";Provider=Microsoft.Jet.OLEDB.4.0" +
";Data Source=" + mdwFile +
";Jet OLEDB:System database=" + systemDb +
";Password=" + pass + ";User ID=" + user);

//reference to access system database query
grC = new OleDbCommand("MSysUserMemberships", con);
grC.CommandType = CommandType.StoredProcedure;
grC.Parameters.Add("@UserName", OleDbType.VarChar);
}

public ArrayList Groups(string userName)
{
ArrayList usGroups = new ArrayList();
con.Open();
try
{
grC.Parameters["@UserName"].Value = userName;
OleDbDataReader dr = grC.ExecuteReader();
while(dr.Read())
usGroups.Add(dr.GetString(0));
}
finally
{
con.Close();
}
return usGroups;
}
}
}

Of course using system tables/queries is less recommended - it is some
undocumented feature and in future version of Access it can be changed.

I hope it helps.
Grzegorz
 
¤ Uzytkownik "Paul Clement" <[email protected]> napisal
¤ w wiadomosci ¤ >
¤ > ¤ I am accessing an Access database with User groups/accounts set up, is
¤ > there
¤ > ¤ any way for me to determine which groups indvidual accounts are a member
¤ > of
¤ > ¤ from my .net application.
¤ > ¤
¤ (...)
¤ >
¤ > I don't believe you can use Access SQL DDL so you will probably need to
¤ > use ADOX (Microsoft ADO Ext
¤ > 2.x for DDL and Security):
¤
¤ Another option is use system tables or queries. In Access membership of
¤ users is preserved in mdw file, that is specific access database file. There
¤ is query: MSysUserMemberships (among others) that contains information you
¤ want. Example of use;
¤

Although it's one way to avoid interop I don't typically recommend using hidden tables for two
reasons. First, Microsoft can change the internal implementation in a future version of Access and
second, these tables should typically be secured so that they cannot be directly accessed.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Uzytkownik "Paul Clement said:
On Thu, 11 Nov 2004 22:29:26 +0100, "Grzegorz Danowski"
Although it's one way to avoid interop I don't typically recommend using
hidden tables for two
reasons. First, Microsoft can change the internal implementation in a
future version of Access

I have mentioned the risk, but personally I don't suppose that MS will
introduce another version of Jet some day in the future. Rather MS will be
continually promote MSDE. Have you listen about Jet 5.0? From Access 2000,
Access XP and Access 2003 all the databases still use Jet 4.0 (but eight
service packs), additionally Jet 3.5 (Access 97) has the same system query I
used in my code (I don't know about it in Access 2.0).

and
second, these tables should typically be secured so that they cannot be
directly accessed.

"Should typically be sececured" - what do you mean? I have run my snippet
without any problem on various mdw files and I have noticed no problem with
it, also when I have run it on mdw that have set up password on Admin
account - It was no trouble to open the file using standard "System.mdw"
without password on Admin (as in my snippet).
I suppose mdw file that contains intormation about users/group, theirs
passwords (encrypted) and sids should not be secured because it would make
impossible to retrieve the informations.
But maybe I misunderstand it.

Regards,
Grzegorz

Ps. Probably the discusion is off topic on adonet group :-)
 
¤ and
¤ > second, these tables should typically be secured so that they cannot be
¤ > directly accessed.
¤
¤ "Should typically be sececured" - what do you mean? I have run my snippet
¤ without any problem on various mdw files and I have noticed no problem with
¤ it, also when I have run it on mdw that have set up password on Admin
¤ account - It was no trouble to open the file using standard "System.mdw"
¤ without password on Admin (as in my snippet).
¤ I suppose mdw file that contains intormation about users/group, theirs
¤ passwords (encrypted) and sids should not be secured because it would make
¤ impossible to retrieve the informations.
¤ But maybe I misunderstand it.

It's possible that they may have changed the default permissions since Access 97. Looking at an
Access 97 System.mdw file, no permissions are enabled for the system database QueryDefs.

But the question I would ask is if you're implementing user-level security for your database then
why would you want to open up the System.mdw file for access to this information? Access security is
weak enough as it is. ;-)


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top