Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey there,
i want to make a windows service to monitor process specific by user for this i make a win form which contains textbox ,Radio button for time interval like 1 hour, 30 min, 15 min and a button name as save setting. when user click press the button that save is save in registry file.

now what i wants to monitor that process which is save in registry key

can any body tell me how to check that process save in registry is running or not in fixed interval.

this is the code which i am using

C#
protected override void OnStart(string[] args)
{
    timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
    timer1.Interval = 5000;
    timer1.Enabled = true;
    timer1.Start();
    try
    {
        FileStream fs = new FileStream(@"c:\SystemActiveTimeInformation.txt",
        FileMode.OpenOrCreate, FileAccess.Write);
        StreamWriter sWriter = new StreamWriter(fs);
        sWriter.BaseStream.Seek(0, SeekOrigin.End);
        sWriter.WriteLine("=====================================================================================");
        sWriter.WriteLine("System Turn On Time: \t " + DateTime.Now);
        sWriter.Flush();
        sWriter.Close();
        RegistryKey exampleRegistryKey = Registry.CurrentUser.OpenSubKey("ExampleTest");
        using (StreamWriter sw = File.AppendText("d:\\close.txt"))
        if(exampleRegistryKey != null)
        {
            sw.WriteLine("ProcessName = " + DateTime.Now + " Running");
        }
        else
        {
            sw.WriteLine("ProcessName = " + DateTime.Now + " n Running");
        }
    }
    catch
    {
        Exception ex;
    }
   
}
private void timer1_Elapsed(object sender, ElapsedEventArgs e)
{
    RegistryKey exampleRegistryKey = Registry.CurrentUser.OpenSubKey("ExampleTest");
    using (StreamWriter sw = File.AppendText("d:\\close.txt"))
     if(exampleRegistryKey.== ListProcesses())
        {
            sw.WriteLine("ProcessName = " + DateTime.Now + " Running");
        }
        else
        {
            sw.WriteLine("ProcessName = " + DateTime.Now + " NR");
        }
    
}
Posted
Updated 13-Oct-15 0:14am
v2
Comments
Nathan Minier 13-Oct-15 11:12am    
Well, you can check to see if the process has saved any data to the registry that way, but frankly I'm not sure why you're not using the Process object instead.

https://msdn.microsoft.com/en-us/library/z3w4xdc9(v=vs.110).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900