Non Admin Example

This page sets out a complete example of creating a simple EA Addin and installing it, manually, as a Non-Admin user.

The steps are:

  • Create your AddIn DLL
  • Configure your Sparx AddIn key
  • Register your DLL

Create a simple EA Addin

Create a very simple EA Addin e.g.

Imports EA
'
'E001 - ASimpleEAMenu
' This is a basic example of an EA Extension - it simply creates a single menu item in both the Toolbar extensions menu and Project Browser (right click) context menu
' upon selecting a message is displayed

Public Class ASimpleEAMenu
    ' set up the menu item - just the one - and it is available for both locations - no filtering (see in later examples)
    Public Function EA_GetMenuItems(ByVal Repository As EA.Repository, _
                              ByVal MenuLocation As String, _
                              ByVal MenuName As String) As Object

        EA_GetMenuItems = "&ASimpleEAMenuItem"

    End Function

    ' Define the menu state - we want to enable out menu item in all instances
    Public Sub EA_GetMenuState(ByVal Repository As EA.Repository, _
                 ByVal MenuLocation As String, _
                 ByVal MenuName As String, _
                 ByVal ItemName As String, _
                 ByRef IsEnabled As Boolean, _
                 ByRef IsChecked As Boolean)
        ' set state for menu item
        Try
            Select Case MenuName
                Case "&ASimpleEAMenuItem"
                    IsEnabled = True
            End Select
        Catch ex As Exception
            IsEnabled = False
        End Try
    End Sub

    ' respond to menu click event 
    ' i.e. entry from EA when user clicks menu item
    Public Sub EA_MenuClick(ByVal Repository As EA.Repository, _
             ByVal MenuName As String, _
             ByVal ItemName As String)

        If Repository Is Nothing Then
            MsgBox("Error between EA and E001 Extension")
            Exit Sub
        End If
        Try
            Select Case ItemName
                Case "&ASimpleEAMenuItem"
                    MsgBox("ASimpleEAMenu has been selected.")
            End Select
        Catch ex As Exception
            MsgBox("ASimpleEAMenu exception : " & vbCrLf & ex.ToString)
        End Try

    End Sub

End Class



Review when build

Assembly name: ASimpleAddIn.ASimpleAddIn

Compiled this AddIn within VS project.

  • .NET 4
  • Make Assembly COM visible
  • Unchecked Compile option "Register for COM interop"

This meant that it could build

Configure your Sparx AddIn key

Add key for the addin to list of Sparx Addin keys under HKCU using the following command:

REG ADD "HKCU\Software\Sparx Systems\EAAddins\SimpleAddIn"  /ve /d "ASimpleAddIn.ASimpleMenu"

Inspected

Screen shot below illustrates that the AddIn is known to EA but no class registered


Register the DLL

The normal way of registering a DLL will be with RegAsm but that requires Admin rights - but lets check...

Use RegAsm

Attempted to register DLL with RegAsm but failed as non-admin user

RegAsm Command

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe  "ASimpleAddIn.dll" /codebase /verbose > regclass.log 2>&1

RegAsm log


Microsoft .NET Framework Assembly Registration Utility version 4.7.2556.0
for Microsoft .NET Framework version 4.7.2556.0
Copyright (C) Microsoft Corporation.  All rights reserved.

RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can cause your assembly to interfere with other applications that may be installed on the same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it.
RegAsm : error RA0000 : An error occurred while writing the registration information to the registry. Administrator permissions are needed to use the selected options. Use an administrator command prompt to complete these tasks.


Use RegAsm to create a .reg file

An alternative way of registering a DLL for just the current user is to create the registration entries - using RegAsm a .reg file can be produced using a command similar to that shown below.

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe  "ASimpleAddIn.dll" /codebase /verbose /regfile: regclass.reg  > regclass.log 2>&1

Log file

Microsoft .NET Framework Assembly Registration Utility version 4.7.2556.0
for Microsoft .NET Framework version 4.7.2556.0
Copyright (C) Microsoft Corporation.  All rights reserved.

RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can cause your assembly to interfere with other applications that may be installed on the same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it.
Registry script 'C:\Users\adrian\Documents\Visual Studio 2012\Projects\eaAddInProjects\E001_ASimpleEAMenu\E001_ASimpleEAMenu\bin\x86\Debug\regclass.reg' generated successfully

This created the following .reg file

REGEDIT4

[HKEY_CLASSES_ROOT\ASimpleAddIn.ASimpleEAMenu]
@="ASimpleAddIn.ASimpleEAMenu"

[HKEY_CLASSES_ROOT\ASimpleAddIn.ASimpleEAMenu\CLSID]
@="{2600790F-D0E2-3A3C-981A-1008CE94D968}"

[HKEY_CLASSES_ROOT\CLSID\{2600790F-D0E2-3A3C-981A-1008CE94D968}]
@="ASimpleAddIn.ASimpleEAMenu"

[HKEY_CLASSES_ROOT\CLSID\{2600790F-D0E2-3A3C-981A-1008CE94D968}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="ASimpleAddIn.ASimpleEAMenu"
"Assembly"="ASimpleAddIn, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"
"CodeBase"="file:///C:/Users/adrian/Documents/Visual Studio 2012/Projects/eaAddInProjects/E001_ASimpleEAMenu/E001_ASimpleEAMenu/bin/x86/Debug/ASimpleAddIn.dll"

[HKEY_CLASSES_ROOT\CLSID\{2600790F-D0E2-3A3C-981A-1008CE94D968}\InprocServer32\1.0.0.0]
"Class"="ASimpleAddIn.ASimpleEAMenu"
"Assembly"="ASimpleAddIn, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"
"CodeBase"="file:///C:/Users/adrian/Documents/Visual Studio 2012/Projects/eaAddInProjects/E001_ASimpleEAMenu/E001_ASimpleEAMenu/bin/x86/Debug/ASimpleAddIn.dll"

[HKEY_CLASSES_ROOT\CLSID\{2600790F-D0E2-3A3C-981A-1008CE94D968}\ProgId]
@="ASimpleAddIn.ASimpleEAMenu"

[HKEY_CLASSES_ROOT\CLSID\{2600790F-D0E2-3A3C-981A-1008CE94D968}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]


However, note that it references to HKEY_CLASSES_ROOT and hence this will not load as it is, but if we change the target location the all will work fine.

Edited .REG file to store key in HKCU

Modified REG file

  • set classname keys in HKCU\Software\Classes
  • set CLSID keys in HKCU\Software\Classes\WOW6432Node\CLSID - 32-bit app on 64-bit OS
REGEDIT4

[HKEY_CURRENT_USER\Software\Classes\ASimpleAddIn.ASimpleEAMenu]
@="ASimpleAddIn.ASimpleEAMenu"

[HKEY_CURRENT_USER\Software\Classes\ASimpleAddIn.ASimpleEAMenu\CLSID]
@="{2600790F-D0E2-3A3C-981A-1008CE94D968}"

[HKEY_CURRENT_USER\Software\Classes\WOW6432Node\CLSID\{2600790F-D0E2-3A3C-981A-1008CE94D968}]
@="ASimpleAddIn.ASimpleEAMenu"

[HKEY_CURRENT_USER\Software\Classes\WOW6432Node\CLSID\{2600790F-D0E2-3A3C-981A-1008CE94D968}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="ASimpleAddIn.ASimpleEAMenu"
"Assembly"="ASimpleAddIn, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"
"CodeBase"="file:///C:/Users/adrian/Documents/Visual Studio 2012/Projects/eaAddInProjects/E001_ASimpleEAMenu/E001_ASimpleEAMenu/bin/x86/Debug/ASimpleAddIn.dll"

[HKEY_CURRENT_USER\Software\Classes\WOW6432Node\CLSID\{2600790F-D0E2-3A3C-981A-1008CE94D968}\InprocServer32\1.0.0.0]
"Class"="ASimpleAddIn.ASimpleEAMenu"
"Assembly"="ASimpleAddIn, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"
"CodeBase"="file:///C:/Users/adrian/Documents/Visual Studio 2012/Projects/eaAddInProjects/E001_ASimpleEAMenu/E001_ASimpleEAMenu/bin/x86/Debug/ASimpleAddIn.dll"

[HKEY_CURRENT_USER\Software\Classes\WOW6432Node\CLSID\{2600790F-D0E2-3A3C-981A-1008CE94D968}\ProgId]
@="ASimpleAddIn.ASimpleEAMenu"

[HKEY_CURRENT_USER\Software\Classes\WOW6432Node\CLSID\{2600790F-D0E2-3A3C-981A-1008CE94D968}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]

Regdit import

With this modified .reg file we can open regedit, as a standard user, and then import the modified .reg file.

BE careful to check:

  • class names are consistent
  • location of DLL (i.e.Codebase)

Then upon inspecting entries in the registry it should all be OK.

Reference added for Class in HKCU

Class details added in HKCU

Visible in EA Inspector

In place in EA Extensions