How to obtain Product Code within a C# application?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?=

    How to obtain Product Code within a C# application?


    Hi misters,

    How I can do this in C# ??

    Dim installer As Object

    installer = CreateObject("W indowsInstaller .Installer")

    Dim products As Object = installer.Produ cts



    For Each strProductCode As String In products

    'Console.WriteL ine(strProductC ode)

    Dim strProductName As String =
    installer.Produ ctInfo(strProdu ctCode, "InstalledProdu ctName")

    If strProductName = "Something" Then

    'That's it.

    End If

    Next


    Thanks !!!

    --





  • Paul Musso

    #2
    Re: How to obtain Product Code within a C# application?

    Alhambra Eidos Desarrollo a couché sur son écran :
    Hi misters,
    >
    How I can do this in C# ??
    >
    Dim installer As Object
    >
    installer = CreateObject("W indowsInstaller .Installer")
    >
    Dim products As Object = installer.Produ cts
    >
    >
    >
    For Each strProductCode As String In products
    >
    'Console.WriteL ine(strProductC ode)
    >
    Dim strProductName As String =
    installer.Produ ctInfo(strProdu ctCode, "InstalledProdu ctName")
    >
    If strProductName = "Something" Then
    >
    'That's it.
    >
    End If
    >
    Next
    >
    >
    Thanks !!!
    Hi, i think this following code works, try it :

    Type type = Type.GetType("W indows.Installe r");

    WindowsInstalle r.Installer installer = Activator.Creat eInstance(type) ;

    foreach (string strProductCode in installer.Produ cts)
    {
    Console.WriteLi ne(strProductCo de);
    string strProductName = installer.Produ ctInfo(strProdu ctCode,
    "InstalledProdu ctName");
    if (strProductCode == "Something" )
    {
    }
    }

    --
    Paul Musso


    Comment

    • =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?=

      #3
      Re: How to obtain Product Code within a C# application?

      Type type = Type.GetType("W indows.Installe r");
      >
      WindowsInstalle r.Installer installer = Activator.Creat eInstance(type) ;
      thanks mister !!!

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

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

      Thanks again, mister.

      Comment

      • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

        #4
        Re: How to obtain Product Code within a C# application?

        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.

        "Alhambra Eidos Desarrollo" wrote:
        >
        Type type = Type.GetType("W indows.Installe r");

        WindowsInstalle r.Installer installer = Activator.Creat eInstance(type) ;
        >
        thanks mister !!!
        >
        I need add some reference about Windows.Install er in my csproj ??? which
        Reference, where the type WindowsInstalle r.Installer contains within the
        reference ?
        >
        How can I detect that Windows Installer is installed in my machine ??
        >
        Thanks again, mister.
        >

        Comment

        • Paul Musso

          #5
          Re: How to obtain Product Code within a C# application?

          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.
          >
          "Alhambra Eidos Desarrollo" wrote:
          >
          >>
          >>Type type = Type.GetType("W indows.Installe r");
          >>>
          >>WindowsInstal ler.Installer installer = Activator.Creat eInstance(type) ;
          >>
          >thanks mister !!!
          >>
          >I need add some reference about Windows.Install er in my csproj ??? which
          >Reference, where the type WindowsInstalle r.Installer contains within the
          >reference ?
          >>
          >How can I detect that Windows Installer is installed in my machine ??
          >>
          >Thanks again, mister.
          >>
          You must add a reference to "C:\Windows\Sys tem32\msi.dll"

          Here is the C# code reviewed :

          Type type = Type.GetType("W indows.Installe r");

          WindowsInstalle r.Installer installer = (WindowsInstall er.Installer)
          Activator.Creat eInstance(type) ;

          foreach (string strProductCode in installer.Produ cts)
          {
          Console.WriteLi ne(strProductCo de);
          string strProductName = installer.get_P roductInfo(strP roductCode,
          "InstalledProdu ctName");
          if (strProductName == "Something" )
          {
          }
          }

          --
          Paul Musso


          Comment

          • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

            #6
            Re: How to obtain Product Code within a C# application?

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

            WindowsInstalle r.Installer installer = new WindowsInstalle r.Installer();

            "Paul Musso" wrote:
            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.

            "Alhambra Eidos Desarrollo" wrote:
            >
            >Type type = Type.GetType("W indows.Installe r");
            >>
            >WindowsInstall er.Installer installer = Activator.Creat eInstance(type) ;
            >
            thanks mister !!!
            >
            I need add some reference about Windows.Install er in my csproj ??? which
            Reference, where the type WindowsInstalle r.Installer contains within the
            reference ?
            >
            How can I detect that Windows Installer is installed in my machine ??
            >
            Thanks again, mister.
            >
            >
            You must add a reference to "C:\Windows\Sys tem32\msi.dll"
            >
            Here is the C# code reviewed :
            >
            Type type = Type.GetType("W indows.Installe r");
            >
            WindowsInstalle r.Installer installer = (WindowsInstall er.Installer)
            Activator.Creat eInstance(type) ;
            >
            foreach (string strProductCode in installer.Produ cts)
            {
            Console.WriteLi ne(strProductCo de);
            string strProductName = installer.get_P roductInfo(strP roductCode,
            "InstalledProdu ctName");
            if (strProductName == "Something" )
            {
            }
            }
            >
            --
            Paul Musso
            >
            >
            >

            Comment

            • Paul Musso

              #7
              Re: How to obtain Product Code within a C# application?

              Exact, i just respected that he wrote in VB.

              --
              Paul Musso


              Comment

              Working...