Click here to Skip to main content
Licence 
First Posted 10 Jun 2007
Views 15,555
Bookmarked 14 times

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

By | 26 Jul 2007 | Article
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

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAlternative PinmemberJaseNet6:54 26 Jun '07  
GeneralRe: Alternative PinmemberFrederic Sivignon5:17 17 Jul '07  

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.

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