Integrating with Windows Security
If you want to integrate your application with Windows security, you can add code to your application that does the following:
- Retrieve the current user's name from Windows
- Get the primary key of the current user from the MM .NET User Manager
- Register the user with the Security Manager
For example, you could put the following code in your application's Main() method found in the Main.cs or Main.vb file:
public static void Main()
{
try
{
// Instantiate the Application Object
App = new AppDesktop();
// Get the current user
string Name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
// Get a reference to the User object
OakLeaf.MM.Main.Security.mmUser oUser = mmAppBase.SecurityMgr.oUser;
// Try to get the user record
oUser.GetUserByIdAndPassword(Name, null);
if (oUser.DataRow != null)
{
// Register the user with the application security manager
mmAppBase.SecurityMgr.RegisterUser(oUser.DataRow[oUser.PrimaryKey]);
}
else
{
// Invalid user!!!
}And in VB .NET:
Public Shared Sub Main()
Try
' Instantiate the Application Object
App = New AppDesktop()
' Get the current user
Dim Name As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name
' Get a reference to the User object
Dim oUser As OakLeaf.MM.Main.Security.mmUser = mmAppBase.SecurityMgr.oUser
' Try to get the user record
oUser.GetUserByIdAndPassword(Name, Nothing)
If Not (oUser.DataRow Is Nothing) Then
' Register the user with the application security manager
mmAppBase.SecurityMgr.RegisterUser(oUser.DataRow(oUser.PrimaryKey))
Else
' Invalid user!!!
End IfIf you take this approach, you will typically want to turn off the user login form. You can do this by setting the DisplayLoginForm property of your application object to False.
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 03/02/10
Comment or report problem with topic
