View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Restrict AddIn to limited users


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)





On Wed, 21 Oct 2009 06:30:52 -0700 (PDT), JP
wrote:

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

--JP

On Oct 21, 5:37*am, Madiya wrote:
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