例如,3D FlowerBox屏幕保护程序具有Direct3D FlowerBox的文件描述.我无法在任何地方找到“3D FlowerBox”.
这些信息存储在哪里?
我该如何检索它.
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);
基本上,屏幕保护程序的显示名称是.scr文件中的第一个资源字符串.请注意,对于某些屏幕保护程序(例如windows内置屏幕保护程序),本地化资源不在主.scr文件中,而是在特定于区域性的子目录中的.scr.mui文件中.您不必担心它,因为LoadString知道在哪里可以找到足够的资源.
总结以上是内存溢出为你收集整理的C#:检索已安装的屏幕保护程序的名称全部内容,希望文章能够帮你解决C#:检索已安装的屏幕保护程序的名称所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)