none
Not able to retrive Operating System Service Pack Name for 64 bit OS using C#

    Question

  • Hi

    I am not trying to retrive OS service pack name using the below c# code. code is working fine for 32 bit but it doesnot work for 64 bits OS. For 64 bits OS, the code returns "NULL" value even though it has some service pack entry

           var reg = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, word.Trim());
            var key = reg.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\");
           string servicePack = (string)key.GetValue("CSDVersion");

    i dont think is there any name space for 64 bit like "Microsoft.Win64", Any idea how do i get the service pack name for 64 bit OS?..

    your help would be appreciated!.

    Thanks,

    Umapathy


    Thanks -Umapathy

    Tuesday, March 27, 2012 1:31 AM

Answers

  • You can use cmd.exe to get your SP version by: wmic os get servicepackmajorversion

    ...

    ServicePackMajorVersion
    1

    ...

    Also, please read this:

    What OS / Service Pack Am I Running?

    It turned out that the problem wasn’t with the installation of Service Pack 1.  The problem lay in the method being used by the application to check the OS and Service Pack version.  The application was checking for the OS version in a registry value, specifically: HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\CSDVersion.  On the x64 version of Windows Vista Service Pack 1, however this value does not exist.  The

    correct value does show up under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CSDVersion however.  This highlights an inherent problem with relying on the registry method to capture this information.  As operating systems evolve, there is no guarantee that registry information will persist between operating systems, or in some cases there may be changes between service packs for the same operating system.

    When determining OS versions for application installs, a better method than reading the registry would be to either use a WMI query or to use an API.  The GetVersionEx function is designed to retrieve this information and is not affected by change.  One caveat though – if you are testing for whether a particular feature is installed, the GetVersionEx function would not be the best approach.  With that in mind, below are some items returned by using this function that are specific to Service Packs:

    • szCSDVersion: A null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack installed on the system. If no Service Pack has been installed, the string is empty.
    • wServicePackMajor:  The major version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the major version number is 3. If no Service Pack has been installed, the value is zero.
    • wServicePackMinor: The minor version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the minor version number is 0.

    Regards, Nighting Liu


    Tuesday, March 27, 2012 5:30 AM

All replies

  • On 64bit machine please use the following path

    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion


    Regards, Nighting Liu

    Tuesday, March 27, 2012 2:28 AM
  • Hi Liu

    The "CSDVersion" name does not avaialble under the path that you mentioned above. this "CSDVersion" is available only under "Software\Microsoft\Windows NT\CurrentVersion\".  but i am unable to read this value using my code.

    i am not sure about how do i retrive this "CSDVersion" name.

    Thanks,

    Umaapthy


    Thanks -Umapathy

    Tuesday, March 27, 2012 5:10 AM
  • You can use cmd.exe to get your SP version by: wmic os get servicepackmajorversion

    ...

    ServicePackMajorVersion
    1

    ...

    Also, please read this:

    What OS / Service Pack Am I Running?

    It turned out that the problem wasn’t with the installation of Service Pack 1.  The problem lay in the method being used by the application to check the OS and Service Pack version.  The application was checking for the OS version in a registry value, specifically: HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\CSDVersion.  On the x64 version of Windows Vista Service Pack 1, however this value does not exist.  The

    correct value does show up under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CSDVersion however.  This highlights an inherent problem with relying on the registry method to capture this information.  As operating systems evolve, there is no guarantee that registry information will persist between operating systems, or in some cases there may be changes between service packs for the same operating system.

    When determining OS versions for application installs, a better method than reading the registry would be to either use a WMI query or to use an API.  The GetVersionEx function is designed to retrieve this information and is not affected by change.  One caveat though – if you are testing for whether a particular feature is installed, the GetVersionEx function would not be the best approach.  With that in mind, below are some items returned by using this function that are specific to Service Packs:

    • szCSDVersion: A null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack installed on the system. If no Service Pack has been installed, the string is empty.
    • wServicePackMajor:  The major version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the major version number is 3. If no Service Pack has been installed, the value is zero.
    • wServicePackMinor: The minor version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the minor version number is 0.

    Regards, Nighting Liu


    Tuesday, March 27, 2012 5:30 AM