Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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

Posted
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.
Posted

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++;
		}		
	}
}
}

  • 2 weeks later...
  • 4 weeks later...
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...