Skip to content

Commit 37ed173

Browse files
authored
Merge pull request #32 from SvenGroot/v2.0-dev
Merge v2.0 into main
2 parents 22ba7d1 + 87dcab0 commit 37ed173

File tree

70 files changed

+3097
-779
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3097
-779
lines changed

README.md

Lines changed: 98 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ available through this tool. Customizations supported by the Answer File Generat
1414
- The installation method, partition layout, and target disk and partition.
1515
- Enabling optional features during installation.
1616
- Creation of local user accounts.
17-
- Joining a domain and adding domain accounts to the local Administrators group.
17+
- Joining a domain, and adding domain accounts to a local security group.
1818
- Configuring automatic log-on.
1919
- The product key, computer name, language/culture, and time zone.
2020
- Display resolution.
2121
- Disabling Windows Defender.
2222
- Enabling remote desktop access.
2323
- Running PowerShell scripts and other commands on first log-on.
2424

25-
All of these items can be customized using command line arguments. In addition, the answer files
26-
generated here will always skip the entire OOBE experience unless no local account was created and
27-
no domain was joined.
25+
Answer files generated by this application will always skip the entire OOBE experience, unless no
26+
local account was created and no domain was joined.
2827

2928
Below, the core functionality is explained with several examples. You can also check the
30-
[full list of command line arguments](doc/CommandLine.md), or run `./GenerateAnswerFile -Help`.
29+
[full list of command line arguments](doc/CommandLine.md), or run `./GenerateAnswerFile -Help`. It's
30+
also possible to specify customization options using a [JSON file](doc/Json.md).
3131

3232
See [what's new in Answer File Generator](doc/ChangeLog.md).
3333

@@ -71,18 +71,19 @@ command to list the images in an install.wim or install.esd file.
7171

7272
Passwords are needed for several actions taken by the answer file. When creating local accounts,
7373
their initial password must be set. To join a domain, the password of a domain account with
74-
the appropriate permissions must be specified. For automatic log-on, you must specify the password
75-
of the account that will be logged on.
76-
77-
:warning: **Passwords in answer files are not securely stored** :warning:
78-
79-
They are at best base64-encoded (which is easily reversible), and at worst just stored in plain
80-
text. Do not store answer files with sensitive passwords in unsecure locations, and delete such
81-
files when you are done with them.
82-
83-
The answer file generator also does not treat these passwords securely (it can't, to be able to
84-
write them out to the answer file in this fashion), so copies of the passwords may remain in system
85-
memory after the application is terminated.
74+
the appropriate permissions must be specified (unless a provisioned computer account is used). For
75+
automatic log-on, you must specify the password of the account that will be logged on.
76+
77+
> [!WARNING]
78+
> Passwords in answer files are not securely stored!
79+
>
80+
> They are at best base64-encoded (which is easily reversible), and at worst just stored in plain
81+
> text. Do not store answer files with sensitive passwords in unsecure locations, and delete such
82+
> files when you are done with them.
83+
>
84+
> The answer file generator also does not treat these passwords securely (it can't, to be able to
85+
> write them out to the answer file in this fashion), so copies of the passwords may remain in system
86+
> memory after the application is terminated.
8687
8788
## Time zone
8889

@@ -123,7 +124,7 @@ such as "x86" for 32 bit processors, or "arm64" for ARM based systems.
123124
```text
124125
./GenerateAnswerFile autounattend.xml `
125126
-Install CleanEfi `
126-
-LocalAccount "John,Password" "Steve,OtherPassword" `
127+
-LocalAccount "John,Password" "Users:Steve,OtherPassword" `
127128
-ProductKey ABCDE-12345-ABCDE-12345-ABCDE
128129
```
129130

@@ -132,42 +133,22 @@ password, obviously), and a user named "Steve" with the password "OtherPassword"
132133
[`-LocalAccount`][] argument takes one or more values, allowing the creation of any number of
133134
accounts.
134135

135-
All accounts created during this method will be members of the local Administrators group.
136-
137-
### Joining a domain and automatic log-on
138-
139-
```text
140-
./GenerateAnswerFile unattend.xml `
141-
-ComputerName mypc `
142-
-JoinDomain mydomain `
143-
-JoinDomainUser domainuser `
144-
-JoinDomainPassword Password `
145-
-DomainAccount domainuser `
146-
-AutoLogonUser mydomain\domainuser `
147-
-AutoLogonPassword Password
148-
```
149-
150-
The answer file created by this command sets the computer name to "mypc" and joins it to the domain
151-
"mydomain", using the supplied credentials. It also adds the account "domainuser" from the
152-
"mydomain" domain to the local Administrators group, and logs in using that account automatically on
153-
first boot.
136+
By default, accounts created using this method will be added to the local Administrators group.
137+
You can customize which group(s) to add them to by prefixing the account name with the group,
138+
separated by a colon. You can use multiple groups by separating them with a semicolon.
154139

155-
This sample does not use the [`-Install`][] argument, so it creates an answer file suitable for
156-
pre-installed Windows images, such as those created using sysprep or DISM tools. The
157-
[`-JoinDomain`][] argument can be used with any install method, however.
158-
159-
The [`-AutoLogonUser`][] argument can be used for both domain or local accounts; to use a local
160-
account, specify the user name only, without a domain. To log in automatically more than once, use
161-
the [`-AutoLogonCount`][] argument[^1].
140+
In the above example, John is an administrator, but Steve is added to the Users group, so they will
141+
be a restricted user.
162142

163143
### Custom partition layout
164144

165-
If you use the `CleanEfi` or `CleanBios`, you can choose to customize the partition layout for the
166-
disk specified by [`-InstallToDisk`][], by using the [`-Partition`][] argument. This argument accepts
167-
multiple values, each creating a partition on that disk in the order specified.
145+
If you use the `CleanEfi` or `CleanBios` installation method, you can choose to customize the
146+
partition layout for the disk specified by [`-InstallToDisk`][], by using the [`-Partition`][]
147+
argument. This argument accepts multiple values, each creating a partition on that disk in the order
148+
specified.
168149

169150
If the [`-Partition`][] argument is not specified, the default partition layout for the install
170-
method is used, as specified in the table above.
151+
method is used, as listed in the table above.
171152

172153
The [`-Partition`][] argument uses the format `label:size`, where label is the volume label, and
173154
size is the size of the partition. The size can use multiple-byte units, such as GB or MB[^2], and
@@ -198,9 +179,9 @@ data partitions with that label. These will be assigned drive letters in the ord
198179
specified, starting with `C:`.
199180

200181
You can use the format `label:size[fs]`, where fs is a file system like FAT32 or NTFS, to specify
201-
a file system to format the volume with. If no file system is specified, it defaults to NTFS except
182+
a file system to format the volume with. If no file system is specified, it defaults to NTFS, except
202183
for EFI partitions, which must be FAT32. MSR partitions are not formatted, so this attribute is
203-
ignored.
184+
ignored for that partition type.
204185

205186
You can use the [`-InstallToPartition`][] argument to specify which partition should hold the OS. If you
206187
don't supply this argument, Windows will be installed on the first regular data partition.
@@ -244,24 +225,81 @@ using sysprep, or by using DISM tools.
244225
./GenerateAnswerFile autounattend.xml `
245226
-Install CleanEfi `
246227
-FirstLogonCommand "reg add HKCU\Software\MyCompany /v ImportantRegistryKey /t REG_DWORD /d 1 /f" `
247-
-SetupScript "\\server\share\script.ps1 -Argument" `
228+
-FirstLogonScript "\\server\share\script.ps1 -Argument" `
248229
-LocalAccount "John,Password" `
249230
-AutoLogonUser John `
250231
-AutoLogonPassword Password `
251232
-ProductKey ABCDE-12345-ABCDE-12345-ABCDE
252233
```
253234

254-
The [`-FirstLogonCommand`][] argument can be used to execute a command when a user first logs on to the
255-
system after installation (either manually, or automatically as in the above example). For
256-
convenience, there is also a [`-SetupScript`][] argument which executes the specified Windows PowerShell
257-
script, including any arguments.
235+
The [`-FirstLogonCommand`][] argument can be used to execute a command when a user first logs on to
236+
the system after installation (either manually, or automatically as in the above example). For
237+
convenience, there is also a [`-FirstLogonScript`][] argument which executes the specified Windows
238+
PowerShell script, including any arguments. PowerShell scripts will be executed using the command
239+
`PowerShell.exe -ExecutionPolicy Bypass`.
258240

259241
Either argument accepts multiple values to run multiple commands or scripts. Both are executed in
260242
the order they are supplied, but all commands will be executed before any scripts.
261243

262244
If you execute any scripts, they must be stored in a location that is accessible to the system after
263245
installation, such as a network share like the example above.
264246

247+
### Joining a domain and automatic log-on
248+
249+
```text
250+
./GenerateAnswerFile unattend.xml `
251+
-ComputerName mypc `
252+
-JoinDomain mydomain `
253+
-JoinDomainUser domainuser `
254+
-JoinDomainPassword Password `
255+
-DomainAccount domainuser `
256+
-AutoLogonUser mydomain\domainuser `
257+
-AutoLogonPassword Password
258+
```
259+
260+
The answer file created by this command sets the computer name to "mypc" and joins it to the domain
261+
"mydomain", using the supplied credentials. It also adds the account "domainuser" from the
262+
"mydomain" domain to the local Administrators group, and logs in using that account automatically on
263+
first boot.
264+
265+
This sample does not use the [`-Install`][] argument, so it creates an answer file suitable for
266+
pre-installed Windows images, such as those created using sysprep or DISM tools. The
267+
[`-JoinDomain`][] argument can be used with any install method, however.
268+
269+
The [`-AutoLogonUser`][] argument can be used for both domain or local accounts; to use a local
270+
account, specify the user name only, without a domain. To log in automatically more than once, use
271+
the [`-AutoLogonCount`][] argument[^1].
272+
273+
### Joining a domain using provisioning
274+
275+
```text
276+
./GenerateAnswerFile unattend.xml `
277+
-Install CleanEfi
278+
-JoinDomainProvisioningFile AccountData.txt `
279+
-JoinDomainOffline
280+
```
281+
282+
Instead of embedding a domain account password into the answer file, you can provision a domain
283+
account using the `djoin.exe` utility, and use that to join the domain by passing the name of the
284+
file created by `djoin.exe` to the [`-JoinDomainProvisioningFile`][] argument.
285+
286+
When using provisioning, you can also join the domain during the offlineServicing pass by using the
287+
[`-JoinDomainOffline`][] argument. This is not supported if you join a domain by using credentials.
288+
289+
To provision a domain account for the computer, you can use the following command:
290+
291+
```text
292+
djoin.exe /provision /domain domainname /machine machinename /savefile filename
293+
```
294+
295+
## Using JSON to provide options
296+
297+
Because the large number of command line arguments may get unwieldy, the Answer File Generator
298+
provides a custom JSON file format that can be used as an alternative way to provide the options
299+
for generating an answer file.
300+
301+
For more information, see [the JSON file documentation](doc/Json.md).
302+
265303
## Using an answer file
266304

267305
Please refer to the [official Microsoft documentation](https://learn.microsoft.com/windows-hardware/manufacture/desktop/windows-setup-automation-overview)
@@ -271,13 +309,13 @@ to see how to use an answer file during Windows setup.
271309

272310
The core functionality for generating answer files is implemented in the
273311
[Ookii.AnswerFile library](doc/Library.md), which you can use in your own applications targeting
274-
.Net 7.0 or later.
312+
.Net 8.0 or later.
275313

276314
## Building and testing
277315

278316
To build Answer File Generator, make sure you have the following installed:
279317

280-
- [Microsoft .Net 7.0 SDK](https://dotnet.microsoft.com/download) or later
318+
- [Microsoft .Net 8.0 SDK](https://dotnet.microsoft.com/download) or later
281319

282320
To build the application, library, and tests, simply use the `dotnet build` command in the `src`
283321
directory. You can run the unit tests using `dotnet test`.
@@ -306,10 +344,12 @@ any other adverse effects caused by the use of answer files generated by this to
306344
[`-InstallToPartition`]: doc/CommandLine.md#-installtopartition
307345
[`-ImageIndex`]: doc/CommandLine.md#-imageindex
308346
[`-JoinDomain`]: doc/CommandLine.md#-joindomain
347+
[`-JoinDomainOffline`]: doc/CommandLine.md#-joindomainoffline
348+
[`-JoinDomainProvisioningFile`]: doc/CommandLine.md#-joindomainprovisioningfile
309349
[`-LocalAccount`]: doc/CommandLine.md#-localaccount
310350
[`-Partition`]: doc/CommandLine.md#-partition
311351
[`-ProcessorArchitecture`]: doc/CommandLine.md#-processorarchitecture
312352
[`-ProductKey`]: doc/CommandLine.md#-productkey
313-
[`-SetupScript`]: doc/CommandLine.md#-setupscript
353+
[`-FirstLogonScript`]: doc/CommandLine.md#-firstlogonscript
314354
[`-TimeZone`]: doc/CommandLine.md#-timezone
315355
[`-WindowsVersion`]: doc/CommandLine.md#-windowsversion

doc/ChangeLog.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# What's new in Answer File Generator
22

3+
## Answer File Generator 2.0 (2024-10-07)
4+
5+
- The [`-DomainAccount`][] argument now allows you to specify users from different domains than the
6+
one you're joining.
7+
- The [`-LocalAccount`][] and [`-DomainAccount`][] arguments now allow you to customize which groups
8+
the account is added to.
9+
- You can join a domain using provisioning with the new [`-JoinDomainProvisioningFile`][] argument,
10+
and do it during the offlineServicing pass with the new [`-JoinDomainOffline`][] argument.
11+
- The `-CmdKeyUser` and `-CmdKeyPassword` arguments have been removed; this was a bad security
12+
practice that I don't wish to promote. You can still get identical behavior using the
13+
[`-FirstLogonCommand`][] argument if desired.
14+
- You can specify options using a [custom JSON file format](Json.md), as an alternative to using
15+
command line arguments.
16+
- If no output file name is provided, the answer file is now written to the console.
17+
- The `-SetupScript` argument has been renamed to [`-FirstLogonScript`][], for consistency with the
18+
[`-FirstLogonCommand`][] argument. A `-SetupScript` alias is provided for compatibility.
19+
- The Answer File Generator is now available in standalone single-file versions, that do not require
20+
you to install the .Net Runtime.
21+
- There are some breaking changes to the [Ookii.AnswerFile library](Library.md#breaking-changes).
22+
323
## Answer File Generator 1.1 (2023-10-10)
424

525
- Apply a workaround for a [known issue with the `LogonCount` element](https://learn.microsoft.com/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup-autologon-logoncount),
@@ -24,9 +44,13 @@
2444

2545
[`-AutoLogonCount`]: CommandLine.md#-autologoncount
2646
[`-DisableServerManager`]: CommandLine.md#-disableservermanager
47+
[`-DomainAccount`]: CommandLine.md#-domainaccount
2748
[`-FirstLogonCommand`]: CommandLine.md#-firstlogoncommand
2849
[`-JoinDomain`]: CommandLine.md#-joindomain
50+
[`-JoinDomainOffline`]: doc/CommandLine.md#-joindomainoffline
51+
[`-JoinDomainProvisioningFile`]: doc/CommandLine.md#-joindomainprovisioningfile
2952
[`-JoinDomainUser`]: CommandLine.md#-joindomainuser
3053
[`-LocalAccount`]: CommandLine.md#-localaccount
3154
[`-Partition`]: CommandLine.md#-partition
32-
[`-SetupScript`]: CommandLine.md#-setupscript
55+
[`-FirstLogonScript`]: CommandLine.md#-firstlogonscript
56+
[`-SetupScript`]: CommandLine.md#-firstlogonscript

0 commit comments

Comments
 (0)