Author Topic: Distributing my add-in for users with no admin privilege  (Read 1762 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7752
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Distributing my add-in for users with no admin privilege
« Reply #15 on: November 22, 2017, 04:56:57 am »
Guillaume,

If managed to get the dll registering done in code.
It is basically the same as registering the dll for a machine install.

Here's the interesting part of the code.
This snippet will register a single public com visible class.

Code: [Select]
private bool register(Type type)
{
bool isAlreadyRegistered = isAlreadyRegisteredInHKCR(type);

if (!isAlreadyRegistered && isComVisible(type))
{

// software classes
RegistryKey controlKey = Registry.CurrentUser.CreateSubKey(@"Software\Classes\" + type.FullName);
controlKey.SetValue(string.Empty,type.FullName);
RegistryKey clsidKey = controlKey.CreateSubKey("CLSID");
clsidKey.SetValue(string.Empty,type.GUID.ToString("B"));

//CLSID
RegistryKey classKey = Registry.CurrentUser.CreateSubKey(@"Software\Classes\CLSID\" + type.GUID.ToString("B"));
classKey.SetValue(string.Empty,type.FullName);

//implemented category
Registry.CurrentUser.CreateSubKey(@"Software\Classes\CLSID\" + type.GUID.ToString("B") + @"\Implemented Categories");
Registry.CurrentUser.CreateSubKey(@"Software\Classes\CLSID\" + type.GUID.ToString("B") + @"\Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}");

//inprocerver
RegistryKey inprocKey = Registry.CurrentUser.CreateSubKey(@"Software\Classes\CLSID\" + type.GUID.ToString("B") + @"\InprocServer32");
inprocKey.SetValue(string.Empty,"mscoree.dll"); //hardcoded
inprocKey.SetValue("ThreadingModel","Both"); //hardcoded?
inprocKey.SetValue("Class",type.FullName);
inprocKey.SetValue("Assembly",type.Assembly.FullName);
inprocKey.SetValue("RuntimeVersion",type.Assembly.ImageRuntimeVersion);
inprocKey.SetValue("CodeBase",type.Assembly.EscapedCodeBase);

//version
RegistryKey versionKey = Registry.CurrentUser.CreateSubKey(@"Software\Classes\CLSID\" + type.GUID.ToString("B") + @"\InprocServer32\" + type.Assembly.GetName().Version);
versionKey.SetValue("Class",type.FullName);
versionKey.SetValue("Assembly",type.Assembly.FullName);
versionKey.SetValue("RuntimeVersion",type.Assembly.ImageRuntimeVersion);
versionKey.SetValue("CodeBase",type.Assembly.EscapedCodeBase);

//ProgID
RegistryKey progIdkey = Registry.CurrentUser.CreateSubKey(@"Software\Classes\CLSID\" + type.GUID.ToString("B") + @"\ProgId");
progIdkey.SetValue(string.Empty,type.FullName);
}
return isAlreadyRegistered;
}

Geert

Guillaume

  • EA User
  • **
  • Posts: 549
  • Karma: +18/-0
    • View Profile
    • www.umlchannel.com
Re: Distributing my add-in for users with no admin privilege
« Reply #16 on: November 22, 2017, 07:34:19 pm »
Hi Geert,

I seem to have found a working solution yesterday by copying the content from the file generated via the following command line:
Heat.exe file "c:\<addin path>\addin.tlb" -out addinWix.dll.wxs

So far it works but the solution you mentioned looks much more appropriate. I will try it out.

When I get some time, I will try to write something about it.

Thanks!
« Last Edit: November 22, 2017, 08:09:39 pm by Guillaume »
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com | Automated tests for scripts & addins: www.eatests.com

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7752
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Distributing my add-in for users with no admin privilege
« Reply #17 on: November 22, 2017, 08:23:37 pm »
Are you sure that creates the registry entries in the user space? (so without admin rights)

I use a similar method for the installer of my add-ins, but they do require admin-rights.
The command I use is this:
"C:\Program Files (x86)\WiX Toolset v3.8\bin\heat.exe" file MyAddin.dll -ag -template fragment -out MyAddin.wxs
Not sure what those different parameters mean, but this works for me.

The advantage of setting the registry keys in the installer (rather then in code) is that these settings are also removed when un-installing. (I think, not 100% sure :-\)

I haven't found this to be a major problem though. Most organisations who don't give admin-rights to their users want to control which software gets installed and used on the computers. I can imagine that those organisations wouldn't be too with happy users installing software themselves just because they can.

Geert

Guillaume

  • EA User
  • **
  • Posts: 549
  • Karma: +18/-0
    • View Profile
    • www.umlchannel.com
Re: Distributing my add-in for users with no admin privilege
« Reply #18 on: November 23, 2017, 09:02:47 pm »
Found some info on creating Wix Custom Actions that would let me run the suggested Registry update you sent.
Am looking into it as a better & cleaner option.

These installation setup projects aren't straightforward...

Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com | Automated tests for scripts & addins: www.eatests.com

Helmut Ortmann

  • EA User
  • **
  • Posts: 884
  • Karma: +37/-1
    • View Profile
Re: Distributing my add-in for users with no admin privilege
« Reply #19 on: November 26, 2017, 10:15:04 pm »
Hi,

I've tried a bit to find an easy solution to install without local administration right. I use WIX 3.11.

The easiest one is quite simple. Microsoft installer handles all the stuff with the folders, putting the registry keys to the right location. The major things are:
- Add to <Package>
--  InstallScope='perUser'
--  InstallPrivileges='limited'
- Add SetProperty:
  <SetProperty Id="ProgramFilesFolder" Value="[LocalAppDataFolder]" Before="CostFinalize"><![CDATA[NOT Privileged]]></SetProperty>
- Don't use advanced WIX UI (User Interface)
- Register to EA: RegistryKey Root="HKCU" Key="Software\Sparx Systems\EAAddins\hoReverse">
- Register dll: <RegistryValue Root="HKCR" Key="CLSID\...
  (Standard for WIX tool Heat)

I think about making this easy approach to always install for a user to my standard method. Easy to develop and to use! You can see an example in hoTools, branch Development, AaddinSimpleNoAdminSetup.

It's possible to make an *.msi file with WIX for per user or per-machine install. It took me a while to figure it out and to get it running. During install you have to go to advanced (not click install) to make a proper per-user install without asking for admin. See the references.

It's complicated, and you have to install in Advanced Mode to get it properly working without asking for admin rights. The main things are:
- Register to EA: RegistryKey Root="HKMU" Key="Software\Sparx Systems\EAAddins\hoReverse">
- Register dll: <RegistryValue Root="HKCR" Key="CLSID\...
  (Standard for WIX tool Heat)
The Installer keeps care of the correct location in the registry (user/machine).

You can see it at GITHUB in my hoReverse, Branch Development.

I would also like to hear about your experiences.

Summary:
- Install per user without admin rights is quite simple with WIX
- Install with GUI for per user and per machine may cause you long nights. But it works with one drawback I know about.

Best regards,

Helmut

-  Basics: Single Package Authoring
   https://msdn.microsoft.com/en-gb/library/dd408068.aspx?f=255&MSPPError=-2147217396
-  Proper UAC Control (for per machine / per user) in WiX
   http://uvinw.com/per-machine-and-per-user-without-UAC-in-WiX/
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Guillaume

  • EA User
  • **
  • Posts: 549
  • Karma: +18/-0
    • View Profile
    • www.umlchannel.com
Re: Distributing my add-in for users with no admin privilege
« Reply #20 on: November 29, 2017, 02:13:32 am »
Hi Helmut,

Thanks for the info. I seem to have found a solution by combining your approach with custom actions as suggested by Geert.
I wanted to use Custom Actions to avoid having to run Wix Heat tool and copy/paste each time the content.
The way I defined it lets me register and unregister the DLL respectively during the install and uninstall processes.

I will write something up once tests and installation from various users don't bring any other issue.
I published both the standard and portable editions of eaUtils on http://www.eautils.com/en/download. Please feel free to install and send me your feedback (successful or else...)

Thanks
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com | Automated tests for scripts & addins: www.eatests.com

Helmut Ortmann

  • EA User
  • **
  • Posts: 884
  • Karma: +37/-1
    • View Profile
Re: Distributing my add-in for users with no admin privilege
« Reply #21 on: November 30, 2017, 06:14:58 am »
Hi Guillaume,

looks good! I tested the portable release with a test user who has no admin rights.

Making the registration via code has its charm. There is no fiddling with the right version or using Heat and copy and past.

Could you publish the code? Yes, it's not complicated but using code is easy and reliable.

I'm not sure which approach I use in future. Putting the dll registration in WIX or integrating your peace of code.

With the single Package Authoring approach, there is only one *.msi file and the user choose whether to install per-user or per-machine.

Thanks and best regards,

Helmut

Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

MrWappy

  • EA User
  • **
  • Posts: 144
  • Karma: +3/-0
    • View Profile
Re: Distributing my add-in for users with no admin privilege
« Reply #22 on: November 30, 2017, 06:58:31 am »
Hi Guillaume,

Sorry not had much time to look at forum recently - head down mode...

Re registering the DLL have you include code in wxs file to do this, e.g. below is the complete registration for my eaForms installer, which works for both machine and current users hence use of root HKMU but this could be HKCU if definitely only for current user.  This is the component that does class registration and sparx addin key


     <Component Id="ProgramKeys"  Guid="9******">
          <RegistryKey Root="HKMU" Key="Software\EXploringEA\eaForms">
            <RegistryValue Type="string" Value="Default Value" />
            <RegistryValue Type='string' Name='ProgramDir' Value='[INSTALLDIR]' KeyPath ="yes"/>
            <RegistryValue Type="string" Name="Examples" Value='[EXAMPLESFOLDER]' />
          </RegistryKey>

        <RegistryKey Root="HKMU" Key="Software\Sparx Systems\EAAddins\eaForms" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
          <RegistryValue Type="string" Value="eaFormsCE.eaForms"/>
        </RegistryKey>

        <RegistryKey Root="HKMU" Key="Software\Microsoft\Active Setup\Installed Components\eaForms"  ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
          <RegistryValue Type="string" Value="eaForms Addin" />
          <RegistryValue Type="string" Name="Version" Value="1" />
          <RegistryValue Type="string" Name="StubPath" Value='reg add "HKMU\Software\Sparx Systems\EAAddins\eaForms" /ve /d eaFormsCE.eaForms /t REG_SZ /f' />
        </RegistryKey>
       
     </Component>



Then includes in the feature section as:

 <ComponentRef Id="ProgramKeys"/>


Perhaps this may give you a clue, and one day I'll update my post with other findings such as custom UI etc along my path of creating quite a few installers now!!
Ping me if you are still having issues and I'll see what I can do.

BR

Adrian