C #: getting the names of installed screen savers

I want to show basically the same list as in the Windows Screen Saver dialog box, with the name of each screen saver. However, the problem I ran into is that the names displayed in the drop-down list in the dialog box do not seem to match the file name, the built-in file information, anything in the registry, etc.

For example, the 3D FlowerBox screen saver has a Direct3D FlowerBox file description. And I can not find only the "3D FlowerBox" anywhere.

Where is this information stored? And how to get it.

+7
c # fileinfo screensaver
source share
4 answers

This question is a bit outdated, but I just had to solve the same problem and came up with the following solution:

public class ScreenSaverInfo { public string FileName { get; set; } public string Name { get; set; } } public IEnumerable<ScreenSaverInfo> GetScreenSavers() { string currentSSPath = null; using (RegistryKey desktopKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop")) { if (desktopKey != null) { string screenSaverExe = desktopKey.GetValue("SCRNSAVE.EXE") as string; if (!string.IsNullOrEmpty(screenSaverExe)) { currentSSPath = Path.GetDirectoryName(screenSaverExe); } } } HashSet<string> directories = new HashSet<string>(); directories.Add(Environment.GetFolderPath(Environment.SpecialFolder.System)); directories.Add(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86)); if (currentSSPath != null) directories.Add(currentSSPath); foreach (string dir in directories) { foreach (string file in Directory.EnumerateFiles(dir, "*.scr", SearchOption.TopDirectoryOnly)) { yield return GetScreenSaverInfo(file); } } } public ScreenSaverInfo GetScreenSaverInfo(string filename) { IntPtr hLibrary = IntPtr.Zero; try { hLibrary = LoadLibrary(filename); StringBuilder sb = new StringBuilder(1024); LoadString(hLibrary, 1, sb, sb.Capacity); return new ScreenSaverInfo { FileName = filename, Name = sb.ToString() }; } finally { if (hLibrary != IntPtr.Zero) FreeLibrary(hLibrary); } } [DllImport("kernel32.dll")] static extern IntPtr LoadLibrary(string lpFileName); [DllImport("kernel32.dll")] static extern bool FreeLibrary(IntPtr hLibrary); [DllImport("user32")] static extern int LoadString(IntPtr hInstance, int wID, [Out] StringBuilder lpBuffer, int nBufferMax); 

Basically, the splash screen display name is the first line of the resource in the .scr file. Please note that for some screensavers (for example, Windows built-in screensavers), localized resources are not located in the main .scr file, but in the .scr.mui file in a culture-specific subdirectory. You have nothing to worry about, because LoadString knows where to find an adequate resource.

+5
source share

Take a look at the question I once asked here about the screen saver . This is the direction of the decision. In addition, it seems that such a thing does not exist in the structure itself.

NTN

+2
source share

My assumption is that if you cannot find it anywhere in the system, it is stored in the assembly as metadata. Open the file with a binary editor and find the name you are looking for.

0
source share

I searched all over the system ... checked the registry, searched the contents of each file for names, opened the .scr files in hexadecimal viewing, but could never find the names anywhere ... I also tried installing other screen savers and noticed that always displayed in the settings as a file name. Whatever I changed the file name appeared there. Therefore, for non-standard screen savers, he does not look for any special names ... this led me to believe that the names of the built-in screen savers were somehow hardcoded in the settings dialog box as special cases.

So, I did the same in my application ... just made an array of all special cases and processed accordingly. This seems to be the only option.

0
source share

All Articles