C# UserProfile=ProfileValue+=sk.GetValue(“ProfileImagePath”); UserProfileKey=ProfileKeyName+=skName; RegKeyInfo UserInformation=新的R
UserProfile=ProfileValue+=sk.GetValue(“ProfileImagePath”); UserProfileKey=ProfileKeyName+=skName; RegKeyInfo UserInformation=新的RegKeyInfo(); UserInformation.Name=UserProfile; UserInformation.SubKeyPath=UserProfileKey; UserProfile=UserProfile.Substring(9)//这减少了C:\Users\Home-to-Home。(0,8)将提供C:\用户 keys.Add(新的RegKeyInfo { Name=UserProfile, SubKeyPath=UserProfileKey }); } } 捕获(例外情况除外) { MessageBox.Show(例如Message); } } } comboBox1.DataSource=键; } } 私有无效按钮1\u单击(对象发送者,事件参数e) { 尝试 { 字符串结果=comboBox1.SelectedValue作为字符串; 使用(注册表项Key=Registry.Users.OpenSubKey(结果+@“\Software\Microsoft\Office\14.0\Outlook\OST”)) if(Key!=null) { int Value=System.Convert.ToInt32(Key.GetValue(“NoOST”); 如果(值==3) { MessageBox.Show(“是”); } 其他的 { MessageBox.Show(“否”); } } 其他的 { MessageBox.Show(“不存在”); } } 捕获(例外) { 投掷; } } } }C# UserProfile=ProfileValue+=sk.GetValue(“ProfileImagePath”); UserProfileKey=ProfileKeyName+=skName; RegKeyInfo UserInformation=新的R,c#,.net,winforms,C#,.net,Winforms,UserProfile=ProfileValue+=sk.GetValue(“ProfileImagePath”); UserProfileKey=ProfileKeyName+=skName; RegKeyInfo UserInformation=新的RegKeyInfo(); UserInformation.Name=UserProfile; UserInformation.SubKeyPath=UserProfileKey; UserProfile=UserProfile.Substrin
//更新的代码。
使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用Microsoft.Win32;
命名空间注册表用户
{
公共部分类Form1:Form
{
公共类RegKeyInfo
{
公共字符串子密钥路径{get;set;}
公共字符串名称{get;set;}
}
公共表格1()
{
初始化组件();
comboBox1.ValueMember=“SubKeyPath”;
comboBox1.DisplayMember=“Name”;
}
私有void Form1\u加载(对象发送方、事件参数e)
{
var keys=新列表();
使用(RegistryKey ProfileKey=Registry.LocalMachine.OpenSubKey(@“SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList”))
{
foreach(ProfileKey.GetSubKeyNames()中的字符串skName)
{
使用(RegistryKey sk=ProfileKey.OpenSubKey(skName))
{
尝试
{
如果(!(sk.GetValue(“Guid”)==null))
{
字符串用户配置文件;
字符串UserProfileKey;
字符串ProfileValue=null;
字符串ProfileKeyName=null;
UserProfile=ProfileValue+=sk.GetValue(“ProfileImagePath”);
UserProfileKey=ProfileKeyName+=skName;
RegKeyInfo UserInformation=新的RegKeyInfo();
UserInformation.Name=UserProfile;
UserInformation.SubKeyPath=UserProfileKey;
UserProfile=UserProfile.Substring(9);//这减少了C:\Users\Home到Home的连接。(0,8)将提供C:\Users
keys.Add(新的RegKeyInfo
{
Name=UserProfile,
SubKeyPath=UserProfileKey
});
}
}
捕获(例外情况除外)
{
MessageBox.Show(例如Message);
}
}
}
comboBox1.DataSource=键;
}
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
尝试
{
字符串结果=comboBox1.SelectedValue作为字符串;
使用(注册表项Key=Registry.Users.OpenSubKey(结果+@“\Software\Microsoft\Office\14.0\Outlook\OST”))
if(Key!=null)
{
int Value=System.Convert.ToInt32(Key.GetValue(“NoOST”);
如果(值==3)
{
MessageBox.Show(“是”);
}
其他的
{
MessageBox.Show(“否”);
}
}
其他的
{
MessageBox.Show(“不存在”);
}
}
捕获(例外)
{
投掷;
}
}
}
}
那么现有代码有什么问题?当前代码完美地获得了用户配置文件名,但我想将profileimagepath所在的子项存储为变量,以便稍后在更改注册表键时使用它。那么现有代码有什么问题?当前代码完美地获得了用户配置文件名,但我想将子项存储在profileimagepath是一个变量,我可以稍后使用它
using System;
using System.Windows.Forms;
using Microsoft.Win32;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//http://www.dreamincode.net/code/snippet1995.htm
//The registry key:
string SoftwareKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
if (!(sk.GetValue("Guid") == null))
{
string UserProfile;
string UserProfileComboBox;
string Software = null;
UserProfile = Software += sk.GetValue("ProfileImagePath");
UserProfileComboBox = UserProfile.Substring(9); //this reduces C:\Users\Home to Home. (0, 8) would have provide C:\Users
comboBox1.Items.Add(UserProfileComboBox);
//This messagebox displays the sub key I need when the userprofile is selected from the checkbox
MessageBox.Show(UserProfile + " " + skName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
}
}
using (RegistryKey test = registry.Users.OpenSubKey(@"Software\Policies\Microsoft\..."))
string hkeyuserprofile;
using (RegistryKey test = registry.Users.OpenSubKey(hkeyuserprofile + @"\Software\Policies\Microsoft\...")
public class RegKeyInfo
{
public String SubKeyPath { get; set; }
public String Name { get; set; }
}
public Form1()
{
InitializeComponent();
comboBox1.ValueMember = "SubKeyPath";
comboBox1.DisplayMember = "Name";
}
private void Form1_Load(object sender, EventArgs e)
{
//http://www.dreamincode.net/code/snippet1995.htm
//Declare the string to hold the list:
var keys = new List<RegKey>();
//Snip...
UserProfileComboBox = UserProfile.Substring(9);
keys.Add(new RegKey {
Name = UserProfileComboBox,
KeyPath = skName
});
//Snip...
comboBox1.DataSource = keys;
}
void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.SelectedValue as String);
}
//Updated code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace RegistryUSER
{
public partial class Form1 : Form
{
public class RegKeyInfo
{
public String SubKeyPath { get; set; }
public String Name { get; set; }
}
public Form1()
{
InitializeComponent();
comboBox1.ValueMember = "SubKeyPath";
comboBox1.DisplayMember = "Name";
}
private void Form1_Load(object sender, EventArgs e)
{
var keys = new List<RegKeyInfo>();
using (RegistryKey ProfileKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"))
{
foreach (string skName in ProfileKey.GetSubKeyNames())
{
using (RegistryKey sk = ProfileKey.OpenSubKey(skName))
{
try
{
if (!(sk.GetValue("Guid") == null))
{
string UserProfile;
string UserProfileKey;
string ProfileValue = null;
string ProfileKeyName = null;
UserProfile = ProfileValue += sk.GetValue("ProfileImagePath");
UserProfileKey = ProfileKeyName += skName;
RegKeyInfo UserInformation = new RegKeyInfo();
UserInformation.Name = UserProfile;
UserInformation.SubKeyPath = UserProfileKey;
UserProfile = UserProfile.Substring(9); //this reduces C:\Users\Home to Home. (0, 8) would have provide C:\Users
keys.Add(new RegKeyInfo
{
Name = UserProfile,
SubKeyPath = UserProfileKey
});
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
comboBox1.DataSource = keys;
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string result = comboBox1.SelectedValue as string;
using (RegistryKey Key = Registry.Users.OpenSubKey(result + @"\Software\Microsoft\Office\14.0\Outlook\OST"))
if (Key != null)
{
int Value = System.Convert.ToInt32(Key.GetValue("NoOST"));
if (Value == 3)
{
MessageBox.Show("yes");
}
else
{
MessageBox.Show("no");
}
}
else
{
MessageBox.Show("not present");
}
}
catch (Exception)
{
throw;
}
}
}
}