.net - How do you register/unregister an EXE as a COM object from C#? -


edit 5/11/2013: question asked how programmatically register com object using code .net without having use regasm. yahia's answer covers both how register dll programmatically , exe.

original question: @ moment, have batch script call our ui register/unregister our software in com when setting default version (using regasm , adding registry entries). no longer wish use batch script running problem if script fails, program not aware of failure. there several ways can address issue, don't notion of calling batch scripts code if don't have to, i'd switch registering our software com using managed code.

assuming it's possible, how register/unregister com objects c#? googling turns ways installer packages, or tells me use regasm, can't find information on how programmatically or if it's possible.

thanks in advance assistance this.

edit 5/10/2013: looks registering exe com object not same registering dll. there programmatic way in .net (pinvoke fine) register exe com object (in 32 bit registry)? how we're doing in script, app , regcmd vars shorthand:

    set app=%pathtotheexecutable%     set regcmd=%pathto32bitregexe%     "c:\windows\microsoft.net\framework\v4.0.30319\regasm" /tlb /codebase %app%     %regcmd% add hkcr\clsid\{app-guid}\localserver32 /ve /t reg_sz /d %app% /f     %regcmd% delete hkcr\clsid\{app-guid}\inprocserver32 /f 

basically run regasm on executable, add our exe localserver32 , remove entry associates inprocserver. possible programmatically without having call regasm code?

you can in c# - using pinvoke, loadlibrary / getprocaddress / freelibrary.

basically need load dll, call register/unregister functions inside dll , unload it.

for complete walkthrough including working c# source code see here. reference see msdn per comment.

update after op updated question:

the above method works dlls.

with assemblies (esp. exe com-server implemented in .net) easiest , robust option use regasm.

if need programmatically should take @ these msdn-links:

basically need load exe via assembly.load , call registertypeforcomclients on relevant types.

another option dynamically (at runtime) - perhaps this of use you...


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -