Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

count - How many times program has run? C#

How can I get the number of times a program has previously run in C# without keeping a file and tallying. If it is not possible that way, can it be gotten from the Scheduled Task Manager?

To C. Ross: how would this be done in a registry setting? forgive me. . . what is a registry setting?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I do this in a registry setting.

static string AppRegyPath = "Software\Cheeso\ApplicationName";
static string rvn_Runs = "Runs";

private Microsoft.Win32.RegistryKey _appCuKey;
public Microsoft.Win32.RegistryKey AppCuKey
{
    get
    {
        if (_appCuKey == null)
        {
            _appCuKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(AppRegyPath, true);
            if (_appCuKey == null)
                _appCuKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(AppRegyPath);
        }
        return _appCuKey;
    }
    set { _appCuKey = null; }
}

public int UpdateRunCount()
{
    int x = (Int32)AppCuKey.GetValue(rvn_Runs, 0);
    x++;
    AppCuKey.SetValue(rvn_Runs, x);
    return x;
}

If it's a WinForms app, you can hook the Form's OnClosing event to run UpdateCount.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...