Restrict AddIn to limited users

M

Madiya

I have developed a addin for our internal usage.
I need to restrict the usage of this addin to only limited users.
This is to be in such a way that even if someone copies and installs
the addin file on other PC, he want be able to use it unless we
authorise the same.

Can I have some pointers or sample code to start with?
I dont mind lanthy process if it works.

Regards,
Madiya
 
J

JP

You could hardcode the usernames in your application, then check
Application.Username against that list.

--JP
 
C

Chip Pearson

Application.Username against that list.

This isn't a good approach because the user can change the UserName
property in the Options dialog. If you are going to go down the
username road, you would be better using the Windows user name. You
can read this from an environment variable with:

Dim CurrentUser As String
CurrentUser = Environ("UserName")

I have, however, on rare occasion found circumstances in which the
user name isn't available as an environment variable. To be extra
safe, use the GetUserName Windows API function:

Public Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" ( _
ByVal lpBuffer As String, _
nSize As Long) As Long

Sub Test()
Dim L As Long
Dim S As String
L = 255
S = Space$(L)
L = GetUserName(S, L)
L = InStr(1, S, vbNullChar)
S = Left(S, L - 1)
Debug.Print S
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
M

Madiya

This isn't a good approach because the user can change the UserName
property in the Options dialog. If you are going to go down the
username road, you would be better using the Windows user name. You
can read this from an environment variable with:

Dim CurrentUser As String
CurrentUser = Environ("UserName")

I have, however, on rare occasion found circumstances in which the
user name isn't available as an environment variable. To be extra
safe, use the GetUserName Windows API function:

Public Declare Function GetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" ( _
    ByVal lpBuffer As String, _
    nSize As Long) As Long

Sub Test()
    Dim L As Long
    Dim S As String
    L = 255
    S = Space$(L)
    L = GetUserName(S, L)
    L = InStr(1, S, vbNullChar)
    S = Left(S, L - 1)
    Debug.Print S
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
    Excel Product Group, 1998 - 2010
Pearson Software Consulting, LLCwww.cpearson.com
(email on web site)



- Show quoted text -

Thanks to both.

Chip : Your code is exactly what I was looking for.
However, line S = Space$(L) is having "$" after space.
Can you pl explain this. I have tried without $ which also works all
the same.

Regards,
Madiya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top