Click here to Skip to main content
Click here to Skip to main content

How to execute program time to time (reading and writing values in system registry)

, 26 Jul 2007
Rate this:
Please Sign up or sign in to vote.
this code will help you to read an exisiting value or to create a value in system registry and execute program time to time

Download Sample.zip - 521.5 KB

Introduction

When we are creating a program some of us in order to save settings of application, we inteded to do is to have file processing techiniques, like .ini /.dat Files or an xml files in order to check the recent setting that have done. So we can do it by just simply manipulating the system registry files...

Background

The basic idea here is how to store settings on your system regitry for your application:

  • Read and write setting in system regstry of your computer.
  • Cheking the recent state of your application
  • Set your application at windows strartup.

Using the code

Here is the sample code that i made using C# language (Dotnet Framework ver.2.0 or higher).

This sample code is use to execute application at windows start up and will show in every 30 minutes of an hour.

<i made this stuff actually for a naughty things.. hmm.. let me say to scary some body by just viewing a scarry picture on their computer unexepectedly> =} ENJOY!! HERE It IS.

//
// 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {    
            this.Hide();
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (DateTime.Now.Minute.ToString() == "30")
            {
                this.Show();
            }
            else
            {
                this.Hide();
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                timer1_Tick(sender, e);
                bool isKeyExist = false;
                string strSubkey = @"Software\Microsoft\Windows\CurrentVersion\Run";
                RegistryKey Mykey = Registry.CurrentUser.OpenSubKey(strSubkey);
                string[] strSearcKey = Mykey.GetValueNames();
                Mykey.Close();
                foreach (string strSearch in strSearcKey)
                {
                    if (strSearch.ToUpper().Equals("ERIC"))
                    {
                    isKeyExist = true;
                    break;
                    }
                }
                if (isKeyExist == false)
                {
                    Mykey = Registry.CurrentUser.CreateSubKey(strSubkey);
                    Mykey.SetValue("ERIC", Application.ExecutablePath, RegistryValueKind.String);
                    Mykey.Close();
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
    }
}
//

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

jinfrics
Other
Philippines Philippines
No Biography provided

Comments and Discussions

 
GeneralAlternative PinmemberJaseNet26-Jun-07 6:54 
GeneralRe: Alternative PinmemberFrederic Sivignon17-Jul-07 5:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 26 Jul 2007
Article Copyright 2007 by jinfrics
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid