The core functionality of the Answer File Generator is implemented in the Ookii.AnswerFile library, which you can integrate into your own applications. The library requires .Net 8.0 or later, and is available on NuGet.
To generate an answer file, you invoke the AnswerFileGenerator.Generate
method, passing in an
instance of the AnswerFileOptions
class, which describes the various settings you want to use
in the answer file.
To specify the install method, you set the AnswerFileOptions.InstallOptions
property to an
instance of the CleanEfiOptions
, CleanBiosOptions
, ExistingPartitionOptions
, or
ManualInstallOptions
class. Additional options that are specific to an install method, such as
partition layout or optional features, are set in those classes.
Leave the AnswerFileOptions.InstallOptions
property set to null to generate an answer file for
a pre-installed image, such as one created by sysprep or DISM tools.
The below example sets various options to perform a clean installation on a UEFI-based system, enabling some optional features and remote desktop. It creates a user account, and sets it to be logged on automatically at first boot.
var options = new AnswerFileOptions()
{
InstallOptions = new CleanEfiOptions()
{
OptionalFeatures = new OptionalFeatures(new Version(10, 0, 22621, 1))
{
Features = { "Microsoft-Windows-Subsystem-Linux", "VirtualMachinePlatform" }
}
},
EnableRemoteDesktop = true,
LocalAccounts = { new LocalCredential("MyUser", "Password") },
AutoLogon = new AutoLogonOptions(new DomainUser(null, "MyUser"), "Password"),
ProductKey = "ABCDE-12345-ABCDE-12345-ABCDE",
DisplayResolution = new Resolution(1920, 1080)
};
AnswerFileGenerator.Generate("unattend.xml", options);
For more information, check out the class library documentation.
Version 2.0 of the library has a few breaking changes from version 1.x:
- The
Generator
class was renamed toAnswerFileGenerator
. - The
GeneratorOptions
class was renamed toAnswerFileOptions
. - The
AnswerFileOptions.DisplayResolution
property has a different type. - The
AnswerFileOptions.JoinDomain
property has a different type. - The
AnswerFileOptions.CmdKeyAccount
property has been removed. - The
DomainOptions
class now derives from theDomainOptionsBase
class. - The
DomainOptionsBase.DomainAccounts
property has a different type. - The
AnswerFileOptions.SetupScripts
property was renamed toFirstLogonScripts
.