Check if software is installed
-
Hello! I want to check if a program is installed. For instance I want to see if the Visual C++ Toolkit 2003 is installed on my computer. How can I do this in C#? Thank you for helping me! :)
-
Hello! I want to check if a program is installed. For instance I want to see if the Visual C++ Toolkit 2003 is installed on my computer. How can I do this in C#? Thank you for helping me! :)
There's no complete way of doing this, other than enumerating the registry keys under HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall. You can use the
System.Management
classes to enumerate theWin32_Product
CIMv2 class, but that only covers Windows Installer packages. Most of Microsoft's products, samples, etc. use Windows Installer (in fact, I haven't seen one in years besides the Managed DirectX runtime that doesn't - even the .NET Framework uses Windows Installer). For more information and a great add-in for VS.NET 2002 and VS.NET 2003, read WMI and .NET: System.Management Lets You Take Advantage of WMI APIs within Managed Code -- MSDN Magazine, May 2002[^]. For links to the add-ins, see http://www.microsoft.com/downloads/results.aspx?productID=BF0EBDD7-5D74-479A-B01E-D7B141200243&freetext=WMI&DisplayLang=en[^].Microsoft MVP, Visual C# My Articles
-
There's no complete way of doing this, other than enumerating the registry keys under HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall. You can use the
System.Management
classes to enumerate theWin32_Product
CIMv2 class, but that only covers Windows Installer packages. Most of Microsoft's products, samples, etc. use Windows Installer (in fact, I haven't seen one in years besides the Managed DirectX runtime that doesn't - even the .NET Framework uses Windows Installer). For more information and a great add-in for VS.NET 2002 and VS.NET 2003, read WMI and .NET: System.Management Lets You Take Advantage of WMI APIs within Managed Code -- MSDN Magazine, May 2002[^]. For links to the add-ins, see http://www.microsoft.com/downloads/results.aspx?productID=BF0EBDD7-5D74-479A-B01E-D7B141200243&freetext=WMI&DisplayLang=en[^].Microsoft MVP, Visual C# My Articles
Even after enumerating and possibly finsing the correct registry key, you should check for the exsistence of the dll or exe. Windows applications are infamous for not removing all registry entries after an un-install or even people will delete directories without using the un-install. Top and bottom is even if it has a registry key, don't assume that it's there. Just expanding on what Heath mentioned. Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
-
Even after enumerating and possibly finsing the correct registry key, you should check for the exsistence of the dll or exe. Windows applications are infamous for not removing all registry entries after an un-install or even people will delete directories without using the un-install. Top and bottom is even if it has a registry key, don't assume that it's there. Just expanding on what Heath mentioned. Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
True to a point (although he didn't ask about files - merely products), but Windows Installer - unless you explicitly change the execution sequence from the default or change the Component table attributes or transitive condition to keep the component installed during uninstall - will remove all files it placed there originally. Windows Installer really is a powerful package distribution system, something I've been working with since it's 1.0 beta days and am currently beta testing for 3.0. If you're interested, you should take a look at the Windows Installer SDK on MSDN.
Microsoft MVP, Visual C# My Articles
-
True to a point (although he didn't ask about files - merely products), but Windows Installer - unless you explicitly change the execution sequence from the default or change the Component table attributes or transitive condition to keep the component installed during uninstall - will remove all files it placed there originally. Windows Installer really is a powerful package distribution system, something I've been working with since it's 1.0 beta days and am currently beta testing for 3.0. If you're interested, you should take a look at the Windows Installer SDK on MSDN.
Microsoft MVP, Visual C# My Articles
[original posting]I want to check if a program is installed. For instance I want to see if the Visual C++ Toolkit 2003 is installed on my computer. How can I do this in C#? The point I'm refering to is that just because something has a registry entry, doesn't mean it exists, only that it was installed at some point in time. I know from experience not to take anything for granted if it has a registry entry. Heath Stewart wrote: (although he didn't ask about files - merely products), He wants to see if a specific product is installed. I merely wanted to point out that an un-install may have failed or been un-installed incorrectly (like deleting directory - infamous in users :) ) and still have left registry entries that may be included in the enum. Regards, Eric C. Tomlinson P.S. Haven't used Windows Installer yet, all the clients I work for have subjected me to Installshield X| Maybe someday I'll be able to use it on something that I write (and actually finish) ;P Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
-
[original posting]I want to check if a program is installed. For instance I want to see if the Visual C++ Toolkit 2003 is installed on my computer. How can I do this in C#? The point I'm refering to is that just because something has a registry entry, doesn't mean it exists, only that it was installed at some point in time. I know from experience not to take anything for granted if it has a registry entry. Heath Stewart wrote: (although he didn't ask about files - merely products), He wants to see if a specific product is installed. I merely wanted to point out that an un-install may have failed or been un-installed incorrectly (like deleting directory - infamous in users :) ) and still have left registry entries that may be included in the enum. Regards, Eric C. Tomlinson P.S. Haven't used Windows Installer yet, all the clients I work for have subjected me to Installshield X| Maybe someday I'll be able to use it on something that I write (and actually finish) ;P Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
I know that non-Windows Installer products are notorious for this, but Window Installer packages are actually transacted - you won't see this behavior (except, perhaps, from poorly-written custom actions where the developer doesn't take rollbacks into account or simply can't). It's Windows Installer I'm defending, not installs. Regarding installs in general, I wholy agree with you...except for one problem: proprietary installs are just that - proprietary. There may be no way to determine where to even look for a product if the install information (or, rather, the uninstall information) doesn't tell you. This is another reason why Windows Installer kicks butt: it's a relational database and tracks everything from files, registry entries, and feature and component installation states. :)
Microsoft MVP, Visual C# My Articles
-
I know that non-Windows Installer products are notorious for this, but Window Installer packages are actually transacted - you won't see this behavior (except, perhaps, from poorly-written custom actions where the developer doesn't take rollbacks into account or simply can't). It's Windows Installer I'm defending, not installs. Regarding installs in general, I wholy agree with you...except for one problem: proprietary installs are just that - proprietary. There may be no way to determine where to even look for a product if the install information (or, rather, the uninstall information) doesn't tell you. This is another reason why Windows Installer kicks butt: it's a relational database and tracks everything from files, registry entries, and feature and component installation states. :)
Microsoft MVP, Visual C# My Articles
First I want to thank you all for your great help. All I wanted to do is to check if the Visual C++ Toolkit 2003 is installed on a system. I give my programs only to users who uses the Uninstall packages. So there won't be problems with deleting program directories or something. But there is only interesting thing: When I open my Control Panel and double click "Software" (in German) or "Add Or Remove Programs" (something like that in English). However, I got a list with all currently installed programs. How is this?
-
First I want to thank you all for your great help. All I wanted to do is to check if the Visual C++ Toolkit 2003 is installed on a system. I give my programs only to users who uses the Uninstall packages. So there won't be problems with deleting program directories or something. But there is only interesting thing: When I open my Control Panel and double click "Software" (in German) or "Add Or Remove Programs" (something like that in English). However, I got a list with all currently installed programs. How is this?
Add/Remove Programs uses the
IAppPublisher
shell interface, a COM interface not available in .NET, though you can declare it in managed code. COM servers containing implementations ofIAppPublisher
are in the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\AppManagement\Publishers registry key. Unfortunately, COM interop with .NET requires that you import the typelibs - if available - from each of these before you can create an instance of them. So, I recommend reading about theIAppPublisher
interface in the MSDN Online Library[^] and creating a mixed-mode Managed C++ assembly. This way, you can work with native COM and expose the functionality you need to managed code. Writing an MC++ assembly this way allows you to reference it in your other managed projects, like a C# project.Microsoft MVP, Visual C# My Articles