"If you want to use Interop, then the component should be installed in the system. Otherwise, it won't work."
I have a WinForm application, that is used by many users in several SO (WinXP, Win7, Win8.1, WinServer 2008, WinServer 2012)
In development, I use a COM component (Outlook, SpeechLib,...).
Two keys:
- Some users cannot installed the component. Or they haven't installed it.
- Another users can be installed the component.
Any programatically way to:
- avoid the application fails for the users that hasn't installed the component
- the application works for the users that has installed the component
?
Notes:
Programmatically way to determine whether a particular COM library DLL has been installed or is installed. Anyways, if a particular COM library not installed, the target is that my source code not fails in runtime in that machine without that COM installed.
For example, for Excel, Word, Outlook COM (ActiveX), SpeechLib (Microsoft Speech Object Library), etc
I could have source code like this:
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpeechLib.ISpeechVoice speech = new SpeechLib.SpVoiceClass();
// ....
Or anyways using Outlool application class, or Excel.Application, etc.
Type officeType = Type.GetTypeFromProgID("Excel.Application");
if (officeType == null)
{
// Excel is not installed.
// Show message or alert that Excel is not installed.
}
else
{
// Excel is installed.
// Continue your work.
}
My old issue, but not solution:
Detect Outlook installed and load dynamically INterop.Outlook Detect Outlook installed and load dynamically INterop.Outlook
I have a Windows Forms application in VS2010. It has a reference to Interop.Outlook (2003). Then, I have reinstalled Windows XP and VS2010, but not install Outlook.
Now, the project not compiles.
I think this, my application will not work if Outlook not installed in machine that my program executes on.
I need to know if I detect Outlook installed, and load dynamically Interop.Outlook.dll (for using the Outlook PIA or Embedded Interop types in .NET 4).
If the machine has Outlook (2003, 2007, 2010, perhaps need code to detect version and do compatibility of Outlook versions) installed, the application works fine with functionally Outlook.
If the machine hasn’t Outlook installed, (in runtime) the application works fine without functionally Outlook. I think, If the machine hasn’t Outlook installed, (in runtime) the application fails because references (in source code) to Outlook.Application class?.
In development machine, the application works because Outlook (and COM) is installed in the machine.
Any sample source code or goog patterns and practices about it??
References
Does this code fails if Office not installed in machine ? How to detect installed version of MS-Office?
http://www.codeproject.com/Tips/679027/How-to-Check-Whether-Excel-is-Installed-in-the-Sys?msg=5027820#xx5027820xx How to check, programatically, if MS Excel exists on a pc?
http://codeblog.jonskeet.uk/2009/07/07/faking-com-to-fool-the-c-compiler