0

レジストリからユーザープロファイルエントリを削除する簡単なアプリケーションに取り組んでいますが、問題が発生しました。

したがって、最初に、次のコードを介してProfileListにあるすべてのサブキーを取得します。

List<string> KeyList = new List<string>();

        RegistryKey ProfileList = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\Windows NT\\CurrentVersion\\ProfileList\\");
        foreach (string ProfileKey in ProfileList.GetSubKeyNames())
        {
            KeyList.Add(ProfileKey);
        }

そこから、これらの各キーのProfileImagePath値を取得し、チェックされたリストボックスに追加します。

KeyList.ForEach(delegate(string ProfileKey)
        {
            ProfileList = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\Windows NT\\CurrentVersion\\ProfileList\\" + ProfileKey + "\\");
            checkedListBox1.Items.Add(ProfileList.GetValue("ProfileImagePath").ToString());
        });

次に、ユーザーが削除ボタンをクリックしたときに、チェックされているユーザープロファイルをアプリケーションに削除してもらいたい。ただし、チェックした各項目の値(C:/ Users / Nameのようなもの)を取得し、削除するレジストリキーを決定する必要があります。これはforeachループで実行できると思いますが、その方法はよくわかりません。これを回避するための最良の方法は何ですか?ありがとう。

4

1 に答える 1

2

どうぞ。このコードは、ユーザーが「選択したユーザーの削除」などのボタンをクリックしたときに実行できます。コードのシェルは次のとおりです。

string[] CheckItemsArray = new string[checkedListBox1.CheckedItems.Count+1];
        checkedListBox1.CheckedItems.CopyTo(CheckItemsArray, 0);

        foreach (string CheckedItem in CheckItemsArray)
        {
            if (CheckedItem != null)
            {
                //your deleting logic here

            }
        }
于 2012-12-21T02:26:24.713 に答える