Click here to Skip to main content
12,953,263 members (81,314 online)
Click here to Skip to main content
Add your own
alternative version

Stats

18.6K views
14 bookmarked
Posted 10 Jun 2007

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

, 26 Jul 2007 CPOL
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jinfrics
Other
Philippines Philippines
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralAlternative Pin
JaseNet26-Jun-07 6:54
memberJaseNet26-Jun-07 6:54 
GeneralRe: Alternative Pin
Frederic Sivignon17-Jul-07 5:17
memberFrederic Sivignon17-Jul-07 5:17 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170525.1 | Last Updated 26 Jul 2007
Article Copyright 2007 by jinfrics
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid