Querying the registry
You may never need to query the registry on the computer when creating a NAV modification, but you should consider it as an option.
How to do it...
Create a new Class Library project in Visual Studio.
Create a new file with the following code:
using System; using System.Runtime.InteropServices; using Microsoft.Win32; namespace RegistryQuery { [ClassInterface(ClassInterfaceType.AutoDual)] [ProgId("RegistryQuery")] [ComVisible(true)] public class RegistryQuery { public string GetKeyValue(string key, string name) { RegistryKey regKey = Registry.Users.OpenSubKey(key); if (regKey == null) { return "Key not found!"; } else { object value = regKey.GetValue(name); if (value != null) { return value.ToString(); } else { return "Name not found!"; } } } } }
Set the properties of the program according to the Creating your own Automation using C# recipe from the integration chapter.
Save, compile, and close the project.
Create a new codeunit from Object Designer.
Add the following global...