0

I need to create a registry entry based on finding of 32/64-bit system from cake script. I can see the File operations reference, Directory operations reference in C# cake site. But i could not find the registry related reference in C# cake. Could anyone please let me know is there any option to make a registry entry using C# cake? If so, please specify the reference link. This will help me a lot to continue in cake script.

2 Answers2

4

An alternative to using C# you could also be using the Reg.exe shipped with all major versions of Windows.

You could use this tool with Cake using StartProcess alias.

An example of doing this below:

DirectoryPath   system32Path    = Context.Environment
                                    .GetSpecialPath(SpecialPath.Windows)
                                    .Combine("System32");
FilePath        regPath         = system32Path.CombineWithFilePath("reg.exe");
string          keyName         = "HKEY_CURRENT_USER\\Software\\Cake";
string          valueName       = "Rocks";
string          valueData       = "1";
ProcessSettings regSettings     = new ProcessSettings()
                                    .WithArguments(
                                        arguments => arguments
                                            .Append("add")
                                            .AppendQuoted(keyName)
                                            .Append("/f")
                                            .AppendSwitchQuoted("/v", valueName)
                                            .AppendSwitchQuoted("/t", "REG_DWORD")
                                            .AppendSwitchQuoted("/d", valueData)
                                        );

int result = StartProcess(regPath, regSettings);

if (result == 0)
{
    Information("Registry value successfully set");
}
else
{
    Information("Failed to set registry value");
}
devlead
  • 4,935
  • 15
  • 36
2

Currently, there are no Cake aliases for working with the registry. Having said that, there is nothing to stop you manipulating the Registry directly using that standard C# types.

An example of one such approach is here:

Writing to registry in a C# application

Cake provides a number of aliases for things that are more complicated to do, however, remember that almost everything that is provided in an alias could be done directly with C# in your main script. The aliases are simply there as a convenience.

Community
  • 1
  • 1
Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60