我的问题是,当我使用 Registry.SetValue 时,我只希望它更新现有值。如果输入的值名称不存在,我不想创建它。我有用户输入的可变数据,所以我不能在我的代码中硬编码路径。
我的套装代码
public class SetRegistryValue : CodeActivity
{
[RequiredArgument]
public InArgument<string> kpath { get; set; }
public InArgument<string> txtName { get; set; }
[RequiredArgument]
public InArgument<string> kvaluename { get; set; }
[RequiredArgument]
public InArgument<string> kvalue { get; set; }
//This will set the value of an key that is defined by user
protected override void Execute(CodeActivityContext context)
{
string KeyPath = this.kpath.Get(context);
string KeyValueName = this.kvaluename.Get(context);
string KeyValue = this.kvalue.Get(context);
string KeyName = Path.GetDirectoryName(KeyPath);
string KeyFileName = Path.GetFileName(KeyPath);
string fullKeyPath = KeyName + "\\" + KeyFileName;
Registry.SetValue(fullKeyPath, KeyValueName, KeyValue, RegistryValueKind.String);
}
}