views:

1010

answers:

4

I'm a limited user, and I need to write an Outlook macro that exposes a C# library in Outlook 2003 and 2007.

I do not have any admin privilges at all, not even at install time, so I can't run RegAsm and I can't (I assume) write a managed add-in.

Is there any way to call .Net code from VBA in this scenario, or are there any other solutions?

This is for personal use only, so an ugly hack is perfectly acceptable (so long as it works)

A: 

Unfortunately due to the way that COM works it would be impossible to install a COM object (interop or otherwise) without admin privileges.

When you register a com objects it writes several entries to HKEY_CLASSES_ROOT which is a machine level key and therefore requires admin privileges.

Now because you did say that a hackish solution is acceptable here are some possible steps you could take to get it to work; however if you do not have admin rights I am assuming that this is not your machine and most likely a work machine. Taking these steps could very well get you fired. Standard disclaimer and whatnot: It isn't my fault if you are a moron and get yourself sued/fired/shot/mugged/etc.

First you need to find out what registry keys need to be added. Make sure you are doing this on a 'clean' machine that host not seen your component before (or one you know that doesn't have the reg keys). Install a machine monitoring program to capture the keys. Here is a link to a [unrelated] MS article where they recommend some apps that do just that.

Now with the monitor running install you addin. You should now be able to get a log of what keys need to be created. Using your log create registry export files.

Now here is where it gets tricky. Basically what you will do is boot the machine from a BartPE image and mount the registry and run your scripts; however the key paths will be incorrect so the scripts will not work 'out of the box'.

MS has a TechNet article (but the link has parens in it so it doesn't play nice here) so Google it, it should be the first result.

After you have read that article you will see that the machines registry will be mounted as a subkey of HKEY_LOCAL_MACHINE. What you need to do is change your registry exports to match the new path. As soon as this step is complete you should be able to boot from your BartPE image, mount the registry, and then import your scripts, unmount the hive and then reboot. Assuming you copied the files to the correct path then it 'should' work.

Good luck.

Andrew Burns
What about Registration-Free COM, or HKCU\Classes?
SLaks
There is no way that I'm doing this solution.
SLaks
I thought you would want to use it, but put the info out there for others who are hacking. What do you mean by Registration-Free COM? You can just use HKCU\Classes because COM still requires the entries in HKLM.
Andrew Burns
Can a .Net assembly be used as a registration free COM server? Also, did you mean can't? As I stated in my answer, it should work.
SLaks
+1  A: 

I found a possible solution, but I haven't have time to try it yet.

SLaks
+1  A: 

I solved this by running regasm with the /regfile option, and replacing HKLM with HKCU in the resulting .reg file.

SLaks
A: 

Registering a COM object (ex. ActiveX control) and making it visible to all users in the system requires administrative rights.

BUT, if visibility to all users is not needed (or not possible due to limited user restriction) then the COM object can be registered only for the particular user.

This generally done by registering the object in HKCU instead of HKLM. This will apply for "regular" COM objects and the ones exposed through .NET COM Interop.

Other more fine grained approaches also exits, the already mentioned RegFree COM which addresses a particular executable.

So, given all of the above the solution to capture all info into reg file and replace HKLM with HKCU shall work (not nice, but so are the tools).

I already did this.
SLaks