@@ -164,49 +164,47 @@ char* CreateUnattendXml(int arch, int flags)
164164 free (tzstr );
165165 }
166166 }
167- if (flags & UNATTEND_SET_USER || flags & UNATTEND_USE_MS2023_BOOTLOADERS ) {
168- if (flags & UNATTEND_SET_USER ) {
169- for (i = 0 ; (i < ARRAYSIZE (unallowed_account_names )) && (stricmp (unattend_username , unallowed_account_names [i ]) != 0 ); i ++ );
170- if (i < ARRAYSIZE (unallowed_account_names )) {
171- uprintf ("WARNING: '%s' is not allowed as local account name - Option ignored" , unattend_username );
172- } else if (unattend_username [0 ] != 0 ) {
173- uprintf ("• Use '%s' for local account name" , unattend_username );
174- // If we create a local account in unattend.xml, then we can get Windows 11
175- // 22H2 to skip MSA even if the network is connected during installation.
176- fprintf (fd , " <UserAccounts>\n" );
177- fprintf (fd , " <LocalAccounts>\n" );
178- fprintf (fd , " <LocalAccount wcm:action=\"add\">\n" );
179- fprintf (fd , " <Name>%s</Name>\n" , unattend_username );
180- fprintf (fd , " <DisplayName>%s</DisplayName>\n" , unattend_username );
181- fprintf (fd , " <Group>Administrators;Power Users</Group>\n" );
182- // Sets an empty password for the account (which, in Microsoft's convoluted ways,
183- // needs to be initialized to the Base64 encoded UTF-16 string "Password").
184- // The use of an empty password has both the advantage of not having to ask users
185- // to type in a password in Rufus (which they might be weary of) as well as allowing
186- // automated logon during setup.
187- fprintf (fd , " <Password>\n" );
188- fprintf (fd , " <Value>UABhAHMAcwB3AG8AcgBkAA==</Value>\n" );
189- fprintf (fd , " <PlainText>false</PlainText>\n" );
190- fprintf (fd , " </Password>\n" );
191- fprintf (fd , " </LocalAccount>\n" );
192- fprintf (fd , " </LocalAccounts>\n" );
193- fprintf (fd , " </UserAccounts>\n" );
194- // Since we set a blank password, we'll ask the user to change it at next logon.
195- // NB: In case you wanna try, please be aware that Microsoft doesn't let you have multiple
196- // <FirstLogonCommands> sections in unattend.xml. Don't ask me how I know... :(
197- fprintf (fd , " <FirstLogonCommands>\n" );
198- fprintf (fd , " <SynchronousCommand wcm:action=\"add\">\n" );
199- fprintf (fd , " <Order>%d</Order>\n" , order ++ );
200- fprintf (fd , " <CommandLine>net user "%s" /logonpasswordchg:yes</CommandLine>\n" , unattend_username );
201- fprintf (fd , " </SynchronousCommand>\n" );
202- // Some people report that using the `net user` command above might reset the password expiration to 90 days...
203- // To alleviate that, blanket set passwords on the target machine to never expire.
204- fprintf (fd , " <SynchronousCommand wcm:action=\"add\">\n" );
205- fprintf (fd , " <Order>%d</Order>\n" , order ++ );
206- fprintf (fd , " <CommandLine>net accounts /maxpwage:unlimited</CommandLine>\n" );
207- fprintf (fd , " </SynchronousCommand>\n" );
208- fprintf (fd , " </FirstLogonCommands>\n" );
209- }
167+ if (flags & UNATTEND_SET_USER ) {
168+ for (i = 0 ; (i < ARRAYSIZE (unallowed_account_names )) && (stricmp (unattend_username , unallowed_account_names [i ]) != 0 ); i ++ );
169+ if (i < ARRAYSIZE (unallowed_account_names )) {
170+ uprintf ("WARNING: '%s' is not allowed as local account name - Option ignored" , unattend_username );
171+ } else if (unattend_username [0 ] != 0 ) {
172+ uprintf ("• Use '%s' for local account name" , unattend_username );
173+ // If we create a local account in unattend.xml, then we can get Windows 11
174+ // 22H2 to skip MSA even if the network is connected during installation.
175+ fprintf (fd , " <UserAccounts>\n" );
176+ fprintf (fd , " <LocalAccounts>\n" );
177+ fprintf (fd , " <LocalAccount wcm:action=\"add\">\n" );
178+ fprintf (fd , " <Name>%s</Name>\n" , unattend_username );
179+ fprintf (fd , " <DisplayName>%s</DisplayName>\n" , unattend_username );
180+ fprintf (fd , " <Group>Administrators;Power Users</Group>\n" );
181+ // Sets an empty password for the account (which, in Microsoft's convoluted ways,
182+ // needs to be initialized to the Base64 encoded UTF-16 string "Password").
183+ // The use of an empty password has both the advantage of not having to ask users
184+ // to type in a password in Rufus (which they might be weary of) as well as allowing
185+ // automated logon during setup.
186+ fprintf (fd , " <Password>\n" );
187+ fprintf (fd , " <Value>UABhAHMAcwB3AG8AcgBkAA==</Value>\n" );
188+ fprintf (fd , " <PlainText>false</PlainText>\n" );
189+ fprintf (fd , " </Password>\n" );
190+ fprintf (fd , " </LocalAccount>\n" );
191+ fprintf (fd , " </LocalAccounts>\n" );
192+ fprintf (fd , " </UserAccounts>\n" );
193+ // Since we set a blank password, we'll ask the user to change it at next logon.
194+ // NB: In case you wanna try, please be aware that Microsoft doesn't let you have multiple
195+ // <FirstLogonCommands> sections in unattend.xml. Don't ask me how I know... :(
196+ fprintf (fd , " <FirstLogonCommands>\n" );
197+ fprintf (fd , " <SynchronousCommand wcm:action=\"add\">\n" );
198+ fprintf (fd , " <Order>%d</Order>\n" , order ++ );
199+ fprintf (fd , " <CommandLine>net user "%s" /logonpasswordchg:yes</CommandLine>\n" , unattend_username );
200+ fprintf (fd , " </SynchronousCommand>\n" );
201+ // Some people report that using the `net user` command above might reset the password expiration to 90 days...
202+ // To alleviate that, blanket set passwords on the target machine to never expire.
203+ fprintf (fd , " <SynchronousCommand wcm:action=\"add\">\n" );
204+ fprintf (fd , " <Order>%d</Order>\n" , order ++ );
205+ fprintf (fd , " <CommandLine>net accounts /maxpwage:unlimited</CommandLine>\n" );
206+ fprintf (fd , " </SynchronousCommand>\n" );
207+ fprintf (fd , " </FirstLogonCommands>\n" );
210208 }
211209 }
212210 fprintf (fd , " </component>\n" );
0 commit comments