3

Is it possible to find the version of the installed Silverlight (e.x. 4.0.51204.0) and its installation folder (e.x. C:\Program Files (x86)\Microsoft Silverlight\4.0.51204.0) in a C# program?

Some notes:

  1. Not within a Silverlight application, but from somewhere else (for example in a console application)
  2. This is NOT such a thing as HKEY_LOCAL_MACHINE\Software\Microsoft\Silverlight in my machine.
el_shayan
  • 2,735
  • 4
  • 28
  • 42
  • The purpose is actually using CSharpCodeProvider to compile a dll with Silverlight target, from a dynamically generated source code – el_shayan Jan 27 '11 at 09:41

4 Answers4

3

There should be a key in the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Silverlight\Version

The installation folder should always be:

%ProgramFiles%\Microsoft Silverlight

You could also read the version number from the files in this directory (sllauncher.exe for example).

Flavio
  • 458
  • 1
  • 3
  • 10
  • Well, I have a clean installation of Windows 7 on my PC. I installed SL4 and I can assure you there is not such a registry key in my machine! %ProgramFiles% can be indeed helpful but I would need the exact-and latest- version of SL. – el_shayan Jan 27 '11 at 09:48
  • 2
    You could use "FileVersionInfo.GetVersionInfo()" on "%ProgramFiles%\Microsoft Silverlight\sllauncher.exe" and then you can combine ""%ProgramFiles%\Microsoft Silverlight\" with that version number to get the full directory. But the registry key should be there, so I would use this only as a backup. – Flavio Jan 27 '11 at 09:53
  • A good solution but it is more like a "hack" than a standard method for getting something so routine. or??? am I the only person in the world who tries to get version of silverlight? :) – el_shayan Jan 27 '11 at 10:20
  • The standard method should be to check the registry key, but you could use this hack as a backup in case it is missing like on your machine. – Flavio Jan 27 '11 at 10:40
  • This is incorrect for a 64-bit Windows installation since %ProgramFiles% does not point to C:\Program Files (x86). – SergioL Feb 16 '11 at 17:07
1

Silverlight runtime is a CLR, as such any .NET code running within it can use any standard method available to it. In this case, System.Environment.Version is used to get the version of the CLR that the executing code is presently running within, if you use this from within a silverlight application you will get the silverlight version running on that sys

1

On a 64-bit computer the registry key might be found here: HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Silverlight\Version

bucktronic
  • 3,027
  • 2
  • 22
  • 27
0

You can visit the official page of Silverlight to check the version.

EDIT: You can do it from a console application. Just fetch the web page in a buffer and find the version number using regular expressions or simple string processing. See here for an example of how to fetch a web page in a buffer.

EDIT: See this question. This might work for you.

Community
  • 1
  • 1
Yogesh
  • 14,498
  • 6
  • 44
  • 69
  • Of course it is not doable "in a console application" (please see note 1 in my question) – el_shayan Jan 27 '11 at 09:46
  • That "fetch" method works only for static pages. Silverlight official page has a http redirect plus a lot of dynamic content+silverlight content. I would have to write a complete browser application to just fetch that piece of text :) – el_shayan Jan 27 '11 at 09:54
  • Thank you for your 3rd edit but that solution won't work for this problem. That relies on javascript and it is only applicable to a web page. – el_shayan Jan 27 '11 at 10:13