module dfl.registry;
{
public static RegistryKey classesRoot;
[property getter]
public static RegistryKey currentUser;
[property getter]
public static RegistryKey dynData;
[property getter]
public static RegistryKey users;
[property getter]
}
{
public final void close();
public final void deleteSubKey(char[] name,bool throwIfMissing);
public final void deleteValue(char[] name,bool throwIfMissing);
public final void flush();
public final RegistryValue getValue(char[] name);
public final RegistryValue getValue(char[] name,RegistryValue defaultValue);
public final HKEY handle;
[property getter]
public static final RegistryKey openRemoteBaseKey(RegistryHive hhive,char[] machineName);
public final RegistryKey openSubKey(char[] name,bool writeAccess);
public final int opEquals(RegistryKey rk);
public final void setValue(char[] name,DWORD value);
public final void setValue(char[] name,RegistryValue value);
public final void setValue(char[] name,char[] value);
public final void setValue(char[] name,char[][] value);
}
{
Inherited members
toString
valueType
}
{
Inherited members
toString
valueType
}
{
Inherited members
toString
valueType
}
{
Inherited members
toString
valueType
}
{
Inherited members
toString
valueType
}
{
Inherited members
toString
valueType
}
{
Inherited members
toString
valueType
}
{
Inherited members
toString
valueType
}
{
Inherited members
toString
valueType
}
Example - or a minimalistic howto
The example shown here is very small, is currently alpha and is far from production quality. But based on my tests it does work quite well. TODO: Add return checks and proper exception handling where required. In this example we are manipulating a DWORD and a SZ value. If you want something more robust cite this example as a reference and refer to the dfl.registry documentation. The reader should have a basic knowledge of dfl and of the registry.
In order to manipulate or view the registry you need to open one of the standard hives:
rkey = reg.currentUser(); //I'm opening HKEY_CURRENT_USER here.
the variables rkey and reg has been declared as (subkey will be used later):
dfl.registry.Registry reg;
If you would like to print all the sub keys of HKEY_CURRENT_USER you would do the following:
char[][] allEntries = rkey.getSubKeyNames();
foreach(entry; allEntries)
{
msgBox(entry);
}
You probably want to open another sub key, so you need to do the following:
subkey = rkey.openSubKey("
CloneCD?", true);
Entries = subkey.getValueNames();
We have now opened HKEY_CURRENT_USER\CloneCD?. Listing the values in that key is simple in dfl, too. Lets assume we have only a set of null terminated strings (REG_SZ). We have to declare a new variable and a string to save our information:
char[] v="";
and we list all values using a foreach (like above):
foreach(entry; Entries)
{
to get the type of the current value (stored in variable entry) we have to do following:
val = subkey.getValue(entry);
v = getValueString(val.valueType());
getValueString is a custom method listed below, if Chris Miller wants to commit it to the current development version he is free to do so (I personally find it useful):
//FIXME: Implement enums [ie. enum
RegKeyValueType? : uint { REG_SZ = 1, REG_EXPAND_SZ, REG_BINARY; } ... etc]
char[] getValueString(uint typeValue)
{
switch(typeValue)
{
case 1:
return "REG_SZ";
break;
case 2:
return "REG_EXPAND_SZ";
break;
case 3:
return "REG_BINARY";
break;
case 4:
return "REG_DWORD";
break;
case 5:
return "REG_DWORD_BIG_ENDIAN";
break;
case 6:
return "REG_LINK";
break;
case 7:
return "REG_MULTI_SZ";
break;
case 8:
return "REG_RESOURCE_LIST";
break;
case 9:
return "REG_FULL_RESOURCE_DESCRIPTOR";
break;
case 10:
return "REG_RESOURCE_REQUIREMENTS_LIST";
break;
case 11:
return "REG_QWORD";
break;
default:
return "Unknown";
}
}
And within the foreach loop it can be printed out in a nice dfl messagebox as following:
if(v == "REG_DWORD")
{
msgBox(std.string.format("d, type: %s", entry, cast(uint)dval.value, v));
//subkey.setValue(entry, 1337);
}
else
{
msgBox(std.string.format("s, type: %s", entry, val.toString(), v));
//subkey.setValue(entry, "holy shit...!");
}
In the above example / snippet you can see how to change values, too.
the entire foreach will be closed as:
}
and that's it. Hope you had fun playing with your registry.
Keep in mind that erroneous writes to the registry can prevent your system from functioning normally, always keep a backup handy.
Since this is not a whyto you can read more here about the registry: http://msdn.microsoft.com/en-us/library/ms724182.aspx
thanks for reading, d-k]
PS: Thanks to a_canadian_girl for proof reading and correcting this document.