wga22 Posted April 16, 2003 Posted April 16, 2003 This program demonstrates how to get a file listing, then set a value to the registry. When run, maybe through a daily scheduled task, this program looks at all of the *.scr files in your SYSTEM directory and sets to the registry one of the file names as your current screensaver.randomscreensaver.cs Quote
Moderators Robby Posted April 16, 2003 Moderators Posted April 16, 2003 Do you have a question or you just sharing some code? Quote Visit...Bassic Software
wga22 Posted April 18, 2003 Author Posted April 18, 2003 No question, just sharing code! :) I am contemplating adding the ability to set random wallpapers. It would require a simple gui to let the user choose images to use randomly. It could store the paths in an xml file, or maybe create a registry key. Quote
wga22 Posted April 18, 2003 Author Posted April 18, 2003 Here is the code, so you can see how simple it is; without downloading: namespace Bobbyber { using System; using System.IO; using Microsoft.Win32; public class ConsoleApp { public static int Main(string[] args) { //writeURLs //HKCU\\SOFTWARE\\MICROSOFT\\INTERNET EXPLORER\\TYPEDURLS RegistryKey keyCurrentMachine = Registry.CurrentUser ; RegistryKey keySoftware = keyCurrentMachine.OpenSubKey ("Control Panel\\Desktop", true); try { keySoftware.SetValue("Scrnsave.exe", getScreenSaverName(Environment.SystemDirectory)); Console.WriteLine ("Screensaver is now :" + keySoftware.GetValue("Scrnsave.exe")); keySoftware.SetValue("ScreenSaveTimeOut", "300"); Console.WriteLine("Screensaver timeone now 5 minutes"); //keySoftware.SetValue("Scrnsave.exe", getScreenSaverName("c:\\winnt\\system32\\")); } catch (Exception e) { Console.WriteLine(e.Message); } return 0; } public static string getScreenSaverName(string targetDirectory) { // Process the list of files found in the directory string [] fileEntries; try { fileEntries = Directory.GetFiles(targetDirectory, "*.scr"); } catch(Exception e) { Console.WriteLine(e.Message); Console.WriteLine("not happening for dir:" + targetDirectory); return ""; } Random asdf = new Random(); return (string)fileEntries[asdf.Next(0,fileEntries.Length)]; } public static void writeURLs() { RegistryKey theCurrentMachine = Registry .CurrentUser ; RegistryKey theSoftware = theCurrentMachine.OpenSubKey ("SOFTWARE"); RegistryKey theMicrosoft = theSoftware.OpenSubKey ("Microsoft"); RegistryKey theIE = theMicrosoft.OpenSubKey ("Internet Explorer"); RegistryKey theTypedURLS = theIE.OpenSubKey ("TypedURLs"); //Now get all the values in the key... long lCount = theTypedURLS.ValueCount; if(lCount <= 0) return; string [] arTypedURL = theTypedURLS.GetValueNames(); Console.WriteLine ("You have typed in following web sites in IE :"); int i = 1; foreach ( string theURL in arTypedURL) { //get the name of the url ... Console.WriteLine ("[{0}] {1}",i,theTypedURLS.GetValue (theURL)); i++; } } } } Quote
aewarnick Posted April 27, 2003 Posted April 27, 2003 Thank you so much for sharing that. Does the screen saver actually change in windows so that when you open up display the new screen saver is set? Quote C#
wga22 Posted May 24, 2003 Author Posted May 24, 2003 Yes. The screensaver changes inside of the display properties menu. The program runs in the console (I have mine in my startup). BTW, it would be easy to randomly set the wallpaper as well as it is also a key in the registry. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.