简体   繁体   中英

Application Logic - Only allow one admin user to use app

I have a very tricky situation right now..

I have an application which downloads the email attachments of a particular email account, and then saves those attachment to a specified folder. The application also has some features, like sort the attachments by date, sort by keywords, etc.

So the app has two key features:

Email Attachment Download

Sorting


The requirement:

Only ONE administrator can run both features, and the normal users can only run the sorting feature

The Problem:

If there are two administrator accounts, how can I limit it to one only? I only have one useful code as of now..

If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
   MsgBox("I have admin privileges")
Else
   MsgBox("I do not have admin privileges")
End If

I just need to know if other admins are using the app. If one admin already ran the app, other admins can't run it anymore..only 1 instance of the app should run for all admins.. thanks.

Why not Create one application level variable to keep count

AdminLoggedinCount

default to 0 and +1 when app starts

If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
    If AdminLoggedinCount >=1
      MsgBox("try again later another admin is using now")
   Else
      MsgBox("I have admin privileges")
   End if
Else
   MsgBox("I do not have admin privileges")
End If

You could do it by doing with a simple Semaphore file. The basic premise, when the application starts, and user is an admin user, try to open a file to a common location visible by all users. if the file exsits, try to erase it, in case the other user may have aborted out and did not properly close and erase the file.

If the file can not be deleted, then an admin is STILL active with the file open. When the user is finished, close and erase the file...

You could have a variable in the app for the status that the semaphore file is theirs (or not), and to allow (or not) the special extra feature.

Again, the file could be as simple as...

X:\\YourSharePath\\ActiveAdminUser.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM