List installed screensavers
-
In a project I'm developing, I need to duplicate the functionality of the Display Properties -> Screen Saver tab. Most importantly, I'd like to list the screensavers the person has installed on their computer, complete with descriptions. I know that screensavers are usually located in the "%windir%\system32\" folder (Usually C:\Windows\System32), but is there a possibility that a screensaver that's available in this list could be located elsewhere on the system? If so, then what method can I use to reliably list the screensavers available? I've searched through the registry, and there don't seem to be any keys that I can enumerate to give me a list. The other problem I'm encountering is that I can't seem to locate the "title" of the screensaver. I assumed it would be visible through FileVersionInfo.GetVersionInfo, but that doesn't seem to be the case (unless I'm blind). Can anybody point me in the right direction here?
-
In a project I'm developing, I need to duplicate the functionality of the Display Properties -> Screen Saver tab. Most importantly, I'd like to list the screensavers the person has installed on their computer, complete with descriptions. I know that screensavers are usually located in the "%windir%\system32\" folder (Usually C:\Windows\System32), but is there a possibility that a screensaver that's available in this list could be located elsewhere on the system? If so, then what method can I use to reliably list the screensavers available? I've searched through the registry, and there don't seem to be any keys that I can enumerate to give me a list. The other problem I'm encountering is that I can't seem to locate the "title" of the screensaver. I assumed it would be visible through FileVersionInfo.GetVersionInfo, but that doesn't seem to be the case (unless I'm blind). Can anybody point me in the right direction here?
Yep it just lists the *.SCR files that impelement the screen saver entry points. PeterRitchie.com
-
Yep it just lists the *.SCR files that impelement the screen saver entry points. PeterRitchie.com
But how can I extract the "title" of the screensaver to list them on my form? I'd like to use the same display title as the Display Settings window uses, if that's possible - I assume you have to be able to find that somewhere, since Windows does it.
-
But how can I extract the "title" of the screensaver to list them on my form? I'd like to use the same display title as the Display Settings window uses, if that's possible - I assume you have to be able to find that somewhere, since Windows does it.
The string resource with ID 1 is used as the title to display in Display control panel applet. PeterRitchie.com
-
The string resource with ID 1 is used as the title to display in Display control panel applet. PeterRitchie.com
I guess I'm missing it here, but how do I extract a resource from another EXE file? Is there some code available to do this rather simply? Either VB or C# will do. Thanks for your help!
-
I guess I'm missing it here, but how do I extract a resource from another EXE file? Is there some code available to do this rather simply? Either VB or C# will do. Thanks for your help!
.NET doesn't have support for Win32 resources. You have to pinvoke LoadStringW from kernel32. A little helper class:
using System;
using System.Runtime.InteropServices;
using System.Text;namespace PeterRitchie
{
/// <summary>
/// Helper class for various things
/// </summary>
[ComVisible(false)]
sealed class Helper
{
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("user32", EntryPoint="LoadString")]
private static extern int LoadStringW(int hInstance, int wID, [Out] StringBuilder lpBuffer, int nBufferMax) ;/// <summary> /// Load a Win32 Resource string. /// </summary> /// <param name="ModuleFilePathString">Module to load from</param> /// <param name="ID">ID or index of the string</param> /// <param name="LoadedString">Destination reference</param> public static void LoadString(String ModuleFilePathString, int ID, ref String LoadedString) { IntPtr InstanceHandle = LoadLibrary(ModuleFilePathString); StringBuilder BufferString = new StringBuilder(1024); LoadStringW(InstanceHandle.ToInt32(), ID, BufferString, BufferString.Capacity); LoadedString = BufferString.ToString(); } }
};
Sample usage:
using PeterRitchie; string LoadedString = ""; Helper.LoadString(@"C:\\windows\\system32\\ssbezier.scr", 1, ref LoadedString); Debug.WriteLine(LoadedString);
Enjoy! PeterRitchie.com