locked
How to get any application version number using C#.Net code? RRS feed

  • Question

  • Hi

    I have a client application installed in my machine and I have the following requirement :

    1.Check whether the windows application HeadCount.exe is installed in machine.

    2.Get the version number.

    Is there any class which provides information about the applications installed in machine and their version number given an application name ?


    Regards Krrishna


    • Edited by Krrisshna Wednesday, 20 June 2012 6:02 AM
    Wednesday, 20 June 2012 5:18 AM

Answers

  • Hi,

    you can use FileInfo class for this as it will give you all the information about particular given file... as here

    System.IO.FileInfo fi = new System.IO.FileInfo("<your exe path here>");
    it will have more information about version and etc.., in its Attributes property.

    Sai Kumar K (MCP)
    Blog: Sai's Stuff.
    WebSite: SantoshTechnologies.

    • Marked as answer by Krrisshna Friday, 29 June 2012 6:54 AM
    Wednesday, 20 June 2012 5:45 AM
  • Try it like this.....

            public static Version GetVersion(Assembly assembly)
            {
                return assembly.GetName().Version;
            }

    http://msdn.microsoft.com/en-us/library/system.version.aspx

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Wednesday, 20 June 2012 2:22 PM
  • Hi, 

    Check with, 

            var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Product where Name='your application name'");
    	foreach (ManagementObject obj in searcher.Get())
    	{
    		var version = obj["Version"];
    	}
    Hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".


    • Edited by Kris444 Wednesday, 20 June 2012 12:14 PM
    • Proposed as answer by Jason Dot Wang Thursday, 21 June 2012 5:53 AM
    • Marked as answer by Jason Dot Wang Wednesday, 27 June 2012 7:44 AM
    Wednesday, 20 June 2012 12:14 PM

All replies

  • Hi,

    you can use FileInfo class for this as it will give you all the information about particular given file... as here

    System.IO.FileInfo fi = new System.IO.FileInfo("<your exe path here>");
    it will have more information about version and etc.., in its Attributes property.

    Sai Kumar K (MCP)
    Blog: Sai's Stuff.
    WebSite: SantoshTechnologies.

    • Marked as answer by Krrisshna Friday, 29 June 2012 6:54 AM
    Wednesday, 20 June 2012 5:45 AM
  • The application I have is a "ClickOnce Application" type.So I don't have the exe path for it.

    Is there a way to access the version number from ControlPanel -> Programs ?


    Regards Krrishna

    Wednesday, 20 June 2012 6:03 AM
  • Hi, 

    Check with, 

            var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Product where Name='your application name'");
    	foreach (ManagementObject obj in searcher.Get())
    	{
    		var version = obj["Version"];
    	}
    Hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".


    • Edited by Kris444 Wednesday, 20 June 2012 12:14 PM
    • Proposed as answer by Jason Dot Wang Thursday, 21 June 2012 5:53 AM
    • Marked as answer by Jason Dot Wang Wednesday, 27 June 2012 7:44 AM
    Wednesday, 20 June 2012 12:14 PM
  • Try it like this.....

            public static Version GetVersion(Assembly assembly)
            {
                return assembly.GetName().Version;
            }

    http://msdn.microsoft.com/en-us/library/system.version.aspx

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Wednesday, 20 June 2012 2:22 PM
  • Hi Kris

    The query Win32_Product doesnt have an entry for my app HeadCount.exe.Is there any other table like Wind64_Product or sthg else ?


    Regards Krrishna

    Thursday, 21 June 2012 6:36 AM
  • Hi Rudy

    Whats the parameter i have to pass to the method you mentioned above ?


    Regards Krrishna

    Thursday, 21 June 2012 6:36 AM
  • Hi

    I have a client application installed in my machine and I have the following requirement :

    1.Check whether the windows application HeadCount.exe is installed in machine.

    2.Get the version number.

    Is there any class which provides information about the applications installed in machine and their version number given an application name ?


    Regards Krrishna


    Assembly Class (System.Reflection) 

    1.  Don't you have to sooner or later check for the existence of the executable assembly in order to do this?

    2.  Once the file is located on the disk you can create an instance of the Assembly class.  Pass that instance to the method.

    What application is doing the checking, and where is it executing?

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/


    • Edited by Rudedog2 Thursday, 21 June 2012 3:12 PM added linl
    Thursday, 21 June 2012 9:24 AM
  • Hi,

    you can use FileInfo class for this as it will give you all the information about particular given file... as here

    System.IO.FileInfo fi = new System.IO.FileInfo("<your exe path here>");
    it will have more information about version and etc.., in its Attributes property.

    Sai Kumar K (MCP)
    Blog: Sai's Stuff.
    WebSite: SantoshTechnologies.

    I've tried doing this, but it didn't help. All it gave me for the Attributes property was "Archive". How do I get the assembly version number from that? (I'm using VS 2019, writing a WPF app.)

    Rod

    Thursday, 17 October 2019 4:13 PM