0

The goal of my situation/problem is I want to setValue of my getValue to a destination within the registry. I am not not too familiar with get/sets, so any help would be awesome. Let me know if you need anything else from me.

namespace RegistrySetter
{

public class Ironman : CodeActivity
{
    public InArgument<string> keypath { get; set; }
    public OutArgument<string> TextOut { get; set; }


    protected override void Execute(CodeActivityContext context)
    {
        string KeyPath = this.keypath.Get(context);

        context.SetValue<string>(this.TextOut, KeyPath);
    }

}

}
4

1 回答 1

1

要获取注册表值,您可能会使用Registry.GetValue. 您只需要使用上下文来设置输出参数。

一个例子:

using System;
using System.Activities;
using Microsoft.Win32;
using System.IO;

public class GetRegistryValue : CodeActivity
{
    [RequiredArgument]
    public InArgument<string> KeyPath { get; set; }
    public OutArgument<string> TextOut { get; set; }

    protected override void Execute(CodeActivityContext context)
    {
        string keyPath = this.KeyPath.Get(context);
        string keyName = Path.GetDirectoryName(keyPath);
        string valueName = Path.GetFileName(keyPath);
        object value = Registry.GetValue(keyName, valueName, "");
        context.SetValue(this.TextOut, value.ToString());
    }
}

这里的 KeyPath 是这样的:HKEY_CURRENT_USER\Software\7-Zip\PathwherePath实际上是值名,HKEY_CURRENT_USER\Software\7-Zip是键名。如果要设置注册表值,请查看Registry.SetValue.

于 2013-10-25T21:54:26.853 回答