How to obtain Product Code within a C# application?

  • Thread starter Alhambra Eidos Desarrollo
  • Start date
A

Alhambra Eidos Desarrollo

Hi misters,

How I can do this in C# ??

Dim installer As Object

installer = CreateObject("WindowsInstaller.Installer")

Dim products As Object = installer.Products



For Each strProductCode As String In products

'Console.WriteLine(strProductCode)

Dim strProductName As String =
installer.ProductInfo(strProductCode, "InstalledProductName")

If strProductName = "Something" Then

'That's it.

End If

Next


Thanks !!!
 
P

Paul Musso

Alhambra Eidos Desarrollo a couché sur son écran :
Hi misters,

How I can do this in C# ??

Dim installer As Object

installer = CreateObject("WindowsInstaller.Installer")

Dim products As Object = installer.Products



For Each strProductCode As String In products

'Console.WriteLine(strProductCode)

Dim strProductName As String =
installer.ProductInfo(strProductCode, "InstalledProductName")

If strProductName = "Something" Then

'That's it.

End If

Next


Thanks !!!

Hi, i think this following code works, try it :

Type type = Type.GetType("Windows.Installer");

WindowsInstaller.Installer installer = Activator.CreateInstance(type);

foreach (string strProductCode in installer.Products)
{
Console.WriteLine(strProductCode);
string strProductName = installer.ProductInfo(strProductCode,
"InstalledProductName");
if (strProductCode == "Something")
{
}
}
 
A

Alhambra Eidos Desarrollo

Type type = Type.GetType("Windows.Installer");

WindowsInstaller.Installer installer = Activator.CreateInstance(type);

thanks mister !!!

I need add some reference about Windows.Installer in my csproj ??? which
Reference, where the type WindowsInstaller.Installer contains within the
reference ?

How can I detect that Windows Installer is installed in my machine ??

Thanks again, mister.
 
F

Family Tree Mike

By using CreateInstance or CreateObject, you don't need to add a reference.
You should check for an exception when calling this to see if the class is
not registered, but I believe there will be a windows installer on every
machine.
 
P

Paul Musso

Family Tree Mike avait prétendu :
By using CreateInstance or CreateObject, you don't need to add a reference.
You should check for an exception when calling this to see if the class is
not registered, but I believe there will be a windows installer on every
machine.

You must add a reference to "C:\Windows\System32\msi.dll"

Here is the C# code reviewed :

Type type = Type.GetType("Windows.Installer");

WindowsInstaller.Installer installer = (WindowsInstaller.Installer)
Activator.CreateInstance(type);

foreach (string strProductCode in installer.Products)
{
Console.WriteLine(strProductCode);
string strProductName = installer.get_ProductInfo(strProductCode,
"InstalledProductName");
if (strProductName == "Something")
{
}
}
 
F

Family Tree Mike

You are right, when casting to the WindowsInstaller.Installer type you need a
reference. If you are adding a reference though, why not just use:

WindowsInstaller.Installer installer = new WindowsInstaller.Installer();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top