Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Ookii.AnswerFile.Tests/AnswerFileGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,17 @@ public void TestGenerateDomainOnly()
AnswerFileGenerator.Generate(actualPath, options);
CheckFilesEqual(expectedPath, actualPath);
}

[TestMethod]
public void TestGenerateAdministratorPassword()
{
var (actualPath, expectedPath) = GetPaths();
var options = new AnswerFileOptions
{
AdministratorPassword = "Password123"
};

AnswerFileGenerator.Generate(actualPath, options);
CheckFilesEqual(expectedPath, actualPath);
}
}
3 changes: 3 additions & 0 deletions src/Ookii.AnswerFile.Tests/Ookii.AnswerFile.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<Content Include="expected\TestGeneratePreInstalled.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="expected\TestGenerateAdministratorPassword.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="expected\TestJsonSerializationBios.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="specialize">
<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<InputLocale>en-US</InputLocale>
<SystemLocale>en-US</SystemLocale>
<UILanguage>en-US</UILanguage>
<UserLocale>en-US</UserLocale>
</component>
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<InputLocale>en-US</InputLocale>
<SystemLocale>en-US</SystemLocale>
<UILanguage>en-US</UILanguage>
<UserLocale>en-US</UserLocale>
</component>
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<UserAccounts>
<AdministratorPassword>
<Value>UABhAHMAcwB3AG8AcgBkADEAMgAzAFAAYQBzAHMAdwBvAHIAZAA=</Value>
<PlainText>false</PlainText>
</AdministratorPassword>
</UserAccounts>
<OOBE>
<ProtectYourPC>1</ProtectYourPC>
<HideEULAPage>true</HideEULAPage>
<HideLocalAccountScreen>false</HideLocalAccountScreen>
<HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
<HideOnlineAccountScreens>false</HideOnlineAccountScreens>
<HideWirelessSetupInOOBE>false</HideWirelessSetupInOOBE>
</OOBE>
<TimeZone>Pacific Standard Time</TimeZone>
<FirstLogonCommands />
</component>
</settings>
</unattend>
10 changes: 9 additions & 1 deletion src/Ookii.AnswerFile/AnswerFileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void GenerateOobePass()
using var pass = WritePassStart("oobeSystem");
WriteInternationalCore();
using var shellSetup = WriteComponentStart("Microsoft-Windows-Shell-Setup");
if (Options.LocalAccounts.Count > 0 || (Options.JoinDomain?.DomainAccounts.Count > 0))
if (Options.LocalAccounts.Count > 0 || (Options.JoinDomain?.DomainAccounts.Count > 0) || (Options.AdministratorPassword != null))
{
using var userAccounts = Writer.WriteAutoCloseElement("UserAccounts");
if (Options.LocalAccounts.Count > 0)
Expand Down Expand Up @@ -280,6 +280,14 @@ private void GenerateOobePass()
Writer.WriteEndElement(); // DomainAccountList
}
}

if (Options.AdministratorPassword != null)
{
Writer.WriteStartElement("AdministratorPassword");
Writer.WriteElementString("Value", Convert.ToBase64String(Encoding.Unicode.GetBytes(Options.AdministratorPassword + "Password")));
Writer.WriteElementString("PlainText", "false");
Writer.WriteEndElement();
}
}

bool hideAccountScreens = Options.JoinDomain != null || Options.LocalAccounts.Count != 0;
Expand Down
19 changes: 19 additions & 0 deletions src/Ookii.AnswerFile/AnswerFileOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,25 @@ public Collection<LocalCredential> LocalAccounts
get => _localAccounts ??= new();
set => _localAccounts = value;
}

/// <summary>
/// Gets or sets the administrator password for the system.
/// </summary>
/// <value>
/// The password for the administrator account, or <see langword="null"/> if no password is to be set.
/// The default value is <see langword="null"/>.
/// </value>
/// <remarks>
/// <para>
/// This password will be applied to the default administrator account during the Windows setup.
/// </para>
/// <note type="security">
/// The password is stored using base64 encoding in the answer file; it is not encrypted.
/// Ensure that answer files containing sensitive information are stored securely and are
/// not exposed to unauthorized parties.
/// </note>
/// </remarks>
public string? AdministratorPassword { get; set; }

/// <summary>
/// Gets or sets options for logging on automatically.
Expand Down