├── .gitignore
├── LICENSE
├── README.md
├── UnattendTool.cmd
├── UnattendTool.ps1
├── build.cmd
├── build.ps1
└── product.json
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UnattendTool 简介
2 |
3 | * 生成 Windows 系统自动安装应答文件 Unattend.xml
4 | * 只支持 Windows 10 或 Windows 11
5 | * Windows 11 支持跳过硬件检测
6 | * Windows 11 支持创建本地账户
7 | * 支持 Ventoy 制作的启动盘
8 | * 支持 Rufus 制作的启动盘
9 | * 支持微软官方启动盘制作工具 `MediaCreationTool.exe` 制作的启动盘
10 |
11 | # 下载
12 |
13 | 从如下链接下载最新的版本:`UnattendTool_v2024.9.21.zip`
14 |
15 | > https://github.com/dsx42/UnattendTool/releases
16 |
17 | # 如何使用本工具?
18 |
19 | 有如下两种使用场景:
20 |
21 | ## 当前电脑要安装系统
22 |
23 | * 在当前电脑安装系统前,把下载的文件解压到当前电脑
24 | * 鼠标左键双击运行解压后的 `UnattendTool.cmd` 文件,根据提示操作
25 | * 提示包含当前电脑的信息,可以直接参考
26 |
27 | ## 其他电脑要安装系统
28 |
29 | * 把下载的文件解压到当前电脑
30 | * 鼠标左键双击运行解压后的 `UnattendTool.cmd` 文件,根据提示操作
31 | * 提示包含当前电脑的信息,不是将要安装系统的电脑信息,不可以作为参考
32 | * 必须了解要安装系统的电脑信息,并合理设置
33 |
34 | # 生成的应答文件在哪里?
35 |
36 | * 默认情况下,在 `%userprofile%\Desktop\script\` 目录下
37 | * 若指定了应答文件目录,则在指定目录下的 `script\` 目录下
38 | * 若指定目录是镜像文件解压目录,存在 `setup.exe` 文件,则在指定目录下
39 |
40 | # 生成的应答文件如何使用?
41 |
42 | ## 和 Venoty 一起使用
43 |
44 | 在 “输入启动盘盘符或者镜像文件所在目录” 时,选择 Ventoy 启动盘的盘符即可
45 |
46 | ## 镜像文件解压后和 setup.exe 一起使用
47 |
48 | > PE 下也支持
49 |
50 | 在 “输入启动盘盘符或者镜像文件所在目录” 时,选择镜像解压文件所在目录,运行生成的 `Install_Autounattend.cmd` 即可
51 |
52 | > 原理:镜像解压后的 `setup.exe` 支持指定应答文件 `setup.exe /unattend:应答文件路径`
53 | > 注意:非 PE 环境下,应答文件里的磁盘设置不生效,即变成在指定分区下不格式化安装系统
54 |
55 | ## 镜像文件挂载后和 setup.exe 一起使用
56 |
57 | > PE 下也支持
58 |
59 | 在 “选择使用应答文件的 ISO 镜像文件” 时,选择镜像文件所在目录,挂载镜像文件后,运行生成的 `script\Install_xxx.cmd` 即可
60 |
61 | > 原理:镜像解压后的 `setup.exe` 支持指定应答文件 `setup.exe /unattend:应答文件路径`
62 | > 注意:非 PE 环境下,应答文件里的磁盘设置不生效,即变成在指定分区下不格式化安装系统
63 |
64 | ## 和 Rufus 一起使用
65 |
66 | 在 “输入启动盘盘符或者镜像文件所在目录” 时,选择 Rufus 启动盘符即可
67 |
68 | > 原理:启动盘根目录下存在 `Autounattend.xml` 时,会自动使用 `Autounattend.xml` 应答文件
69 |
70 | ## 和微软官方启动盘制作工具
71 |
72 | 在 “输入启动盘盘符或者镜像文件所在目录” 时,选择微软官方启动盘制作工具制作的启动盘符即可
73 |
74 | > 原理:启动盘根目录下存在 `Autounattend.xml` 时,会自动使用 `Autounattend.xml` 应答文件
75 |
76 | # 支持的选项
77 |
78 | `UnattendTool.ps1` 支持非交互式运行
79 |
80 | ```powershell
81 | .\UnattendTool.ps1 -Version
82 | ```
83 |
84 | ```powershell
85 | .\UnattendTool.ps1 -Interactive
86 | ```
87 |
88 | ```powershell
89 | .\UnattendTool.ps1
90 | [-Language String]
91 | [-OsVersion int]
92 | [-WindowsProductName String]
93 | [-Architecture String]
94 | [-DiskId int]
95 | [-PartitionID int]
96 | [-PartitionStyle String]
97 | [-FullName String]
98 | [-Password String]
99 | [-DriverLetter String]
100 | [-ISOPath String]
101 | [-ByPassCheck]
102 | [-NotFormat]
103 | ```
104 |
105 | * `-Version`:返回当前工具的版本号
106 | * `-Interactive`:交互模式运行,作用和鼠标左键双击运行 `UnattendTool.cmd` 文件一样的效果
107 | * `-Language String`:要安装系统的语言,只支持如下两个值:
108 | * `'zh-CN'`:简体中文;默认值
109 | * `'en-US'`:英文
110 | * `-OsVersion int`:要安装系统的版本,只支持如下两个值:
111 | * `11`:Windows 11;默认值
112 | * `10`:Windows 10
113 | * `-WindowsProductName String`:要安装系统的产品,支持如下值:
114 | * `'Enterprise'`:企业版;默认值
115 | * `'Education'`:教育版
116 | * `'Pro'`:专业版
117 | * `'Pro Education'`:专业教育版
118 | * `'Pro For Workstations'`:专业工作站版
119 | * `''`:空字符串,表示非上述的其他版本
120 | * `-Architecture String`:要安装系统的架构,只支持如下两个值:
121 | * `'x64'`:64 位系统;默认值
122 | * `'x86'`:32 位系统;注意,Windows 11 只有 64 位系统
123 | * `-DiskId int`:要安装系统的硬盘编号,硬盘编号从 0 开始;默认为 -1,表示自动选择当前操作系统所在的硬盘
124 | * `-PartitionID int`:要安装系统的分区编号,分区编号从 1 开始;默认为 -1,表示自动选择当前操作系统所在的分区
125 | * `-PartitionStyle String`:未指定 `-NotFormat` 时,需要指定该参数,表示要安装系统的硬盘的分区类型,只支持如下两个值:
126 | * `GPT`:GPT 分区;默认值
127 | * `MBR`:MBR 分区;注意,Windows 11 官方镜像不支持 `MBR` 分区
128 | * `-FullName String`:系统安装后的登录账号名;推荐英文字母或数字的组合,尽量不使用中文或其他特殊字符;默认为 `'MyPC'`
129 | * `-Password String`:系统安装后的登录账号密码;推荐不设置密码,系统安装后再自行设置密码;默认无密码
130 | * `-DriverLetter String`:U 盘启动盘盘符或者镜像文件所在目录;默认为当前用户的桌面
131 | * `-ISOPath String`:使用应答文件的 ISO 镜像文件的路径;默认未指定
132 | * `-ByPassCheck`:系统安装时是否跳过硬件检测;只对 Windows 11 系统生效;默认为不跳过
133 | * `-NotFormat`:安装系统时不格式化所选硬盘分区;默认安装时会格式化所选硬盘分区
134 |
135 | # 参考资料
136 |
137 | * Windonws 11 应答文件必须的内容:https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/automate-windows-setup?view=windows-11
138 | * 应答文件组件介绍:https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/components-b-unattend
139 | * 在线应答文件生成器:https://www.windowsafg.com/index.html
140 | * Ventoy 使用:https://www.ventoy.net/cn/doc_start.html
141 | * Ventoy 自动安装:https://www.ventoy.net/cn/plugin_autoinstall.html
142 |
--------------------------------------------------------------------------------
/UnattendTool.cmd:
--------------------------------------------------------------------------------
1 | PowerShell -NoProfile -ExecutionPolicy Bypass -File "%~dp0UnattendTool.ps1" -Interactive
2 |
--------------------------------------------------------------------------------
/UnattendTool.ps1:
--------------------------------------------------------------------------------
1 | param(
2 | $Language = 'zh-CN',
3 | $OsVersion = 11,
4 | $WindowsProductName = 'Enterprise',
5 | $Architecture = 'x64',
6 | $DiskId = -1,
7 | $PartitionId = -1,
8 | $PartitionStyle = 'GPT',
9 | $FullName = 'MyPC',
10 | $Password = '',
11 | $DriverLetter = '',
12 | $ISOPath = '',
13 | [switch]$ByPassCheck,
14 | [switch]$Interactive,
15 | [switch]$NotFormat,
16 | [switch]$Version
17 | )
18 |
19 | function GetDefaultFolderPath {
20 | return [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop)
21 | }
22 |
23 | function GetPartitionTypeName {
24 | param($GptType, $MbrType, $FileSystem)
25 |
26 | if ($GptType) {
27 | if ($GptType -ieq '{de94bba4-06d1-4d40-a16a-bfd50179d6ac}') {
28 | return '微软恢复分区'
29 | }
30 | elseif ($GptType -ieq '{c12a7328-f81f-11d2-ba4b-00a0c93ec93b}') {
31 | return 'EFI 系统分区'
32 | }
33 | elseif ($GptType -ieq '{e3c9e316-0b5c-4db8-817d-f92df00215ae}') {
34 | return '微软保留分区'
35 | }
36 | elseif ($GptType -ieq '{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}') {
37 | return '基本数据分区'
38 | }
39 | elseif ($GptType -ieq '{af9b60a0-1431-4f62-bc68-3311714a69ad}') {
40 | return '逻辑磁盘管理器元数据分区'
41 | }
42 | elseif ($GptType -ieq '{af9b60a0-1431-4f62-bc68-3311714a69ad}') {
43 | return '逻辑磁盘管理器数据分区'
44 | }
45 | }
46 |
47 | if ($MbrType) {
48 | if ($MbrType -ieq '1') {
49 | return 'FAT12 分区'
50 | }
51 | elseif ($MbrType -ieq '4') {
52 | return 'FAT16 分区'
53 | }
54 | elseif ($MbrType -ieq '5') {
55 | return '扩展分区'
56 | }
57 | elseif ($MbrType -ieq '6') {
58 | return '逻辑分区'
59 | }
60 | elseif ($MbrType -ieq '7') {
61 | return "$FileSystem 分区"
62 | }
63 | elseif ($MbrType -ieq '12') {
64 | return 'FAT32 分区'
65 | }
66 | }
67 |
68 | return '未知分区'
69 | }
70 |
71 | function GetCurrentDisk {
72 |
73 | $CurrentDisks = [ordered]@{}
74 |
75 | Get-Disk | ForEach-Object {
76 |
77 | $Partitions = [ordered]@{}
78 | $PhydicalDisk = Get-PhysicalDisk -FriendlyName $_.FriendlyName
79 |
80 | Get-Partition -DiskNumber $_.DiskNumber | ForEach-Object {
81 |
82 | $Volume = Get-Volume -Partition $_
83 | $PartitionTypeName = GetPartitionTypeName -GptType $_.GptType -MbrType $_.MbrType `
84 | -FileSystem $Volume.FileSystem
85 |
86 | $Partition = @{
87 | 'Guid' = $_.Guid; # 分区 ID
88 | 'PartitionNumber' = $_.PartitionNumber; # 分区编号,值从 1 开始
89 | 'DiskNumber' = $_.DiskNumber; # 所属硬盘编号,值从 0 开始
90 | 'GptType' = $_.GptType; # 分区类型的 ID
91 | 'DriveLetter' = $_.DriveLetter; # 驱动器号,如 C
92 | 'FileSystem' = $Volume.FileSystem; # 分区文件系统类型
93 | 'FileSystemType' = $Volume.FileSystemType; # 分区文件系统类型
94 | 'SizeRemaining' = $Volume.SizeRemaining; # 分区可用空间大小,单位为 Byte
95 | 'Size' = $_.Size; # 分区容量,单位为 Byte
96 | 'Type' = $_.Type; # GPT 分区类型,System 表示 EFI 分区,Basic 表示基本数据分区,Reserved 表示 MSR 保留分区
97 | 'TypeName' = $PartitionTypeName;
98 | 'MbrType' = $_.MbrType; # MBR 分区类型的 ID
99 | 'IsHidden' = $_.IsHidden; # 是否隐藏分区
100 | 'IsBoot' = $_.IsBoot; # 是否启动分区
101 | 'IsSystem' = $_.IsSystem; # 是否 EFI 系统分区
102 | 'IsActive' = $_.IsActive # 是否活动分区,MBR 才有意义,GPT 无意义
103 | }
104 | $Partitions.Add($_.PartitionNumber, $Partition)
105 | }
106 |
107 | $Disk = @{
108 | 'DiskNumber' = $_.DiskNumber; # 硬盘编号,值从 0 开始
109 | 'PartitionStyle' = $_.PartitionStyle; # 分区类型,如 GPT 或 MBR
110 | 'MediaType' = $PhydicalDisk.MediaType; # 硬盘类型,如 SSD 或 HDD
111 | 'OperationalStatus' = $_.OperationalStatus; # 硬盘状态,如 Online
112 | 'HealthStatus' = $_.HealthStatus; # 硬盘健康状态,如 Healthy
113 | 'BusType' = $_.BusType; # 硬盘接口类型,如 RAID 或 USB
114 | 'BootFromDisk' = $_.BootFromDisk; # 是否从该硬盘启动
115 | 'FirmwareVersion' = $_.FirmwareVersion; # 硬盘固件版本
116 | 'FriendlyName' = $_.FriendlyName; # 硬盘名称
117 | 'IsBoot' = $_.IsBoot; # 是否从该硬盘启动
118 | 'IsSystem' = $_.IsSystem; # 是否系统盘
119 | 'Manufacturer' = $_.Manufacturer; # 硬盘制造商
120 | 'Model' = $_.Model; # 硬盘型号
121 | 'NumberOfPartitions' = $_.NumberOfPartitions; # 硬盘分区数量
122 | 'Size' = $_.Size; # 硬盘容量,单位为 Byte
123 | 'AllocatedSize' = $PhydicalDisk.AllocatedSize; # 已分配容量,单位为 Byte
124 | 'Partitions' = $Partitions
125 | }
126 | $CurrentDisks.Add($_.DiskNumber, $Disk)
127 | }
128 |
129 | return $CurrentDisks
130 | }
131 |
132 | function GetSystemDiskId {
133 |
134 | $CurrentDisks = GetCurrentDisk
135 |
136 | foreach ($_ in $CurrentDisks.GetEnumerator()) {
137 | if ($_.Value['IsBoot']) {
138 | return $_.Value['DiskNumber']
139 | }
140 | }
141 |
142 | return 0
143 | }
144 |
145 | function GetSystemPartitionId {
146 |
147 | $CurrentDisks = GetCurrentDisk
148 |
149 | foreach ($_ in $CurrentDisks.GetEnumerator()) {
150 | foreach ($__ in $_.Value['Partitions'].GetEnumerator()) {
151 | if ($__.Value['IsBoot']) {
152 | return $__.Value['PartitionNumber']
153 | }
154 | }
155 | }
156 |
157 | return 1
158 | }
159 |
160 | function FormatSize {
161 | param($Size)
162 |
163 | $Tb = [Math]::Round($Size * 1.0 / 1024 / 1024 / 1024 / 1024, 2)
164 | if ($Tb -gt 1) {
165 | return "$Tb" + ' TB'
166 | }
167 |
168 | $Gb = [Math]::Round($Size * 1.0 / 1024 / 1024 / 1024, 2)
169 | if ($Gb -gt 1) {
170 | return "$Gb" + ' GB'
171 | }
172 |
173 | $Mb = [Math]::Round($Size * 1.0 / 1024 / 1024, 2)
174 | if ($Mb -gt 1) {
175 | return "$Mb" + ' MB'
176 | }
177 |
178 | $Kb = [Math]::Round($Size * 1.0 / 1024, 2)
179 | if ($Kb -gt 1) {
180 | return "$Kb" + ' KB'
181 | }
182 |
183 | if ($Size -le 0) {
184 | return '0 Byte'
185 | }
186 |
187 | return "$Size" + ' Byte'
188 | }
189 |
190 | function ShowLanguageSelect {
191 |
192 | Clear-Host
193 | Write-Host -Object ''
194 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
195 | Write-Host -Object ''
196 | Write-Host -Object '============================'
197 | Write-Host -Object '选择要安装系统的语言,推荐 1' -ForegroundColor Green
198 | Write-Host -Object '============================'
199 | Write-Host -Object ''
200 | Write-Host -Object '1: 简体中文 zh-CN' -ForegroundColor Green
201 | Write-Host -Object ''
202 | Write-Host -Object '2: 英文 en-US'
203 |
204 | while ($true) {
205 | Write-Host -Object ''
206 | $InputOption = Read-Host -Prompt '请输入选择的序号(默认为 1),按回车键确认'
207 | if ($InputOption -ieq '' -or $InputOption -ieq '1') {
208 | Write-Host -Object ''
209 | return 'zh-CN'
210 | }
211 | elseif ($InputOption -ieq '2') {
212 | Write-Host -Object ''
213 | return 'en-US'
214 | }
215 | else {
216 | Write-Host -Object ''
217 | Write-Warning -Message '选择无效,请重新输入'
218 | }
219 | }
220 | }
221 |
222 | function ShowOsVersionSelect {
223 |
224 | Clear-Host
225 | Write-Host -Object ''
226 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
227 | Write-Host -Object ''
228 | Write-Host -Object '============================'
229 | Write-Host -Object '选择要安装系统的版本,推荐 1' -ForegroundColor Green
230 | Write-Host -Object '============================'
231 | Write-Host -Object ''
232 | Write-Host -Object '1: Windows 11' -ForegroundColor Green
233 | Write-Host -Object ''
234 | Write-Host -Object '2: Windows 10'
235 |
236 | while ($true) {
237 | Write-Host -Object ''
238 | $InputOption = Read-Host -Prompt '请输入选择的序号(默认为 1),按回车键确认'
239 | if ($InputOption -ieq '' -or $InputOption -ieq '1') {
240 | Write-Host -Object ''
241 | return 11
242 | }
243 | elseif ($InputOption -ieq '2') {
244 | Write-Host -Object ''
245 | return 10
246 | }
247 | else {
248 | Write-Host -Object ''
249 | Write-Warning -Message '选择无效,请重新输入'
250 | }
251 | }
252 | }
253 |
254 | function ShowWindowsProductNameSelect {
255 |
256 | Clear-Host
257 | Write-Host -Object ''
258 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
259 | Write-Host -Object ''
260 | Write-Host -Object '============================'
261 | Write-Host -Object '选择要安装系统的产品,推荐 1' -ForegroundColor Green
262 | Write-Host -Object '============================'
263 | Write-Host -Object ''
264 | Write-Host -Object '1: 企业版 Enterprise' -ForegroundColor Green
265 | Write-Host -Object ''
266 | Write-Host -Object '2: 教育版 Education'
267 | Write-Host -Object ''
268 | Write-Host -Object '3: 专业版 Pro'
269 | Write-Host -Object ''
270 | Write-Host -Object '4: 专业教育版 Pro Education'
271 | Write-Host -Object ''
272 | Write-Host -Object '5: 专业工作站版 Pro For Workstations'
273 | Write-Host -Object ''
274 | Write-Host -Object '6: 其他'
275 |
276 | while ($true) {
277 | Write-Host -Object ''
278 | $InputOption = Read-Host -Prompt '请输入选择的序号(默认为 1),按回车键确认'
279 | if ($InputOption -ieq '' -or $InputOption -ieq '1') {
280 | Write-Host -Object ''
281 | return 'Enterprise'
282 | }
283 | elseif ($InputOption -ieq '2') {
284 | Write-Host -Object ''
285 | return 'Education'
286 | }
287 | elseif ($InputOption -ieq '3') {
288 | Write-Host -Object ''
289 | return 'Pro'
290 | }
291 | elseif ($InputOption -ieq '4') {
292 | Write-Host -Object ''
293 | return 'Pro Education'
294 | }
295 | elseif ($InputOption -ieq '5') {
296 | Write-Host -Object ''
297 | return 'Pro For Workstations'
298 | }
299 | elseif ($InputOption -ieq '6') {
300 | Write-Host -Object ''
301 | return ''
302 | }
303 | else {
304 | Write-Host -Object ''
305 | Write-Warning -Message '选择无效,请重新输入'
306 | }
307 | }
308 | }
309 |
310 | function ShowByPassSelect {
311 | param($OsVersion)
312 |
313 | if ($OsVersion -eq 10) {
314 | return $false
315 | }
316 |
317 | Clear-Host
318 | Write-Host -Object ''
319 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
320 | Write-Host -Object ''
321 | Write-Host -Object '======================================'
322 | Write-Host -Object '选择系统安装时是否跳过硬件检测,推荐 0' -ForegroundColor Green
323 | Write-Host -Object '======================================'
324 | Write-Host -Object ''
325 | Write-Host -Object '0: 否' -ForegroundColor Green
326 | Write-Host -Object ''
327 | Write-Host -Object '1: 是'
328 |
329 | while ($true) {
330 | Write-Host -Object ''
331 | $InputOption = Read-Host -Prompt '请输入选择的序号(默认为 0),按回车键确认'
332 | if ($InputOption -ieq '' -or $InputOption -ieq '0') {
333 | Write-Host -Object ''
334 | return $false
335 | }
336 | elseif ($InputOption -ieq '1') {
337 | Write-Host -Object ''
338 | return $true
339 | }
340 | else {
341 | Write-Host -Object ''
342 | Write-Warning -Message '选择无效,请重新输入'
343 | }
344 | }
345 | }
346 |
347 | function ShowArchitectureSelect {
348 | param($OsVersion)
349 |
350 | if ($OsVersion -eq 11) {
351 | return 'x64'
352 | }
353 |
354 | Clear-Host
355 | Write-Host -Object ''
356 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
357 | Write-Host -Object ''
358 | Write-Host -Object '============================'
359 | Write-Host -Object '选择要安装系统的架构,推荐 1' -ForegroundColor Green
360 | Write-Host -Object '============================'
361 | Write-Host -Object ''
362 | Write-Host -Object '1: 64 位系统 x64' -ForegroundColor Green
363 | Write-Host -Object ''
364 | Write-Host -Object '2: 32 位系统 x86'
365 |
366 | while ($true) {
367 | Write-Host -Object ''
368 | $InputOption = Read-Host -Prompt '请输入选择的序号(默认为 1),按回车键确认'
369 | if ($InputOption -ieq '' -or $InputOption -ieq '1') {
370 | Write-Host -Object ''
371 | return 'x64'
372 | }
373 | elseif ($InputOption -ieq '2') {
374 | Write-Host -Object ''
375 | return 'x86'
376 | }
377 | else {
378 | Write-Host -Object ''
379 | Write-Warning -Message '选择无效,请重新输入'
380 | }
381 | }
382 | }
383 |
384 | function ShowDiskIdSelect {
385 |
386 | $SystemDiskId = GetSystemDiskId
387 | $CurrentDisks = GetCurrentDisk
388 |
389 | Clear-Host
390 | Write-Host -Object ''
391 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
392 | Write-Host -Object ''
393 | Write-Host -Object '================================================'
394 | Write-Host -Object "选择要安装系统的硬盘编号,推荐当前系统所在硬盘 $SystemDiskId" -ForegroundColor Green
395 | Write-Host -Object '================================================'
396 | Write-Host -Object ''
397 | Write-Host -Object '当前系统识别到的硬盘如下:绿色字体的硬盘为当前系统所在硬盘,绿色字体的分区为当前系统所在分区'
398 |
399 | $CurrentDisks.GetEnumerator() | ForEach-Object {
400 |
401 | $msg = '硬盘编号: ' + $_.Value['DiskNumber'] + ', 硬盘类型: ' + $_.Value['MediaType'] + ', 接口类型: ' `
402 | + $_.Value['BusType'] + ', 分区类型: ' + $_.Value['PartitionStyle'] + ', 硬盘容量: ' `
403 | + (FormatSize -Size $_.Value['Size']) + ', 硬盘名称: ' + $_.Value['FriendlyName']
404 |
405 | Write-Host -Object ''
406 | if ($_.Value['IsBoot']) {
407 | Write-Host -Object $msg -ForegroundColor Green
408 | }
409 | else {
410 | Write-Host -Object $msg
411 | }
412 |
413 | $_.Value['Partitions'].GetEnumerator() | ForEach-Object {
414 |
415 | $msg = ' |- 分区编号: ' + $_.Value['PartitionNumber'] + ', 驱动器: ' + $_.Value['DriveLetter'] `
416 | + ', 是否隐藏: ' + $_.Value['IsHidden'] + ', 文件系统: ' + $_.Value['FileSystem'] + ', 类型: ' `
417 | + $_.Value['TypeName'] + ', 可用空间: ' + (FormatSize -Size $_.Value['SizeRemaining']) + ', 容量: ' `
418 | + ( FormatSize -Size $_.Value['Size'])
419 |
420 | Write-Host -Object ' |'
421 | if ($_.Value['IsBoot']) {
422 | Write-Host -Object $msg -ForegroundColor Green
423 | }
424 | else {
425 | Write-Host -Object $msg
426 | }
427 | }
428 | }
429 |
430 | while ($true) {
431 | Write-Host -Object ''
432 | try {
433 | [System.Int32]$InputOption = Read-Host `
434 | -Prompt "请输入选择的硬盘编号(硬盘编号从 0 开始,默认为 $SystemDiskId),按回车键确认"
435 | if ($InputOption -ge 0) {
436 | Write-Host -Object ''
437 | return $InputOption
438 | }
439 | else {
440 | Write-Host -Object ''
441 | Write-Warning -Message '输入无效,请重新输入'
442 | }
443 | }
444 | catch {
445 | Write-Host -Object ''
446 | Write-Warning -Message '输入无效,请重新输入'
447 | }
448 | }
449 | }
450 |
451 | function ShowWipeDiskSelect {
452 | param($DiskId)
453 |
454 | $CurrentDisks = GetCurrentDisk
455 | $SelectDisk = $CurrentDisks[$DiskId]
456 | $DefalultSelect = 0
457 |
458 | Clear-Host
459 | Write-Host -Object ''
460 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
461 | Write-Host -Object ''
462 | if ($SelectDisk -and $SelectDisk['PartitionStyle'] -ine 'GPT') {
463 | Write-Host -Object '=================================='
464 | Write-Host -Object '选择是否对所选硬盘进行分区,推荐 1' -ForegroundColor Green
465 | Write-Host -Object '=================================='
466 | $DefalultSelect = 1
467 | }
468 | else {
469 | Write-Host -Object '=================================='
470 | Write-Host -Object '选择是否对所选硬盘进行分区,推荐 0' -ForegroundColor Green
471 | Write-Host -Object '=================================='
472 | $DefalultSelect = 0
473 | }
474 |
475 | Write-Host -Object ''
476 | Write-Host -Object '0: 否' -ForegroundColor Green
477 | Write-Host -Object ''
478 | Write-Host -Object '1: GPT 分区,注意:安装系统时会清除所选硬盘的数据,请及时备份所选硬盘的数据' -ForegroundColor Red
479 | Write-Host -Object ''
480 | Write-Host -Object '2: MBR 分区,注意:安装系统时会清除所选硬盘的数据,请及时备份所选硬盘的数据' -ForegroundColor Red
481 |
482 | while ($true) {
483 | Write-Host -Object ''
484 | $InputOption = Read-Host -Prompt "请输入选择的序号(默认为 $DefalultSelect),按回车键确认"
485 | if ($InputOption -ieq '') {
486 | Write-Host -Object ''
487 | return $DefalultSelect
488 | }
489 | elseif ('0' -ieq $InputOption) {
490 | Write-Host -Object ''
491 | return 0
492 | }
493 | elseif ($InputOption -ieq '1') {
494 | Write-Host -Object ''
495 | return 1
496 | }
497 | elseif ($InputOption -ieq '2') {
498 | Write-Host -Object ''
499 | return 2
500 | }
501 | else {
502 | Write-Host -Object ''
503 | Write-Warning -Message '选择无效,请重新输入'
504 | }
505 | }
506 | }
507 |
508 | function ShowNewPartition {
509 | param($CreatePartitionInfo)
510 |
511 | Write-Host -Object '所选硬盘重新分区如下:绿色字体的分区为系统安装分区'
512 | Write-Host -Object ''
513 |
514 | $CreatePartitionInfo.GetEnumerator() | ForEach-Object {
515 |
516 | $VolumeSize = '硬盘剩余所有空间'
517 | if (!$_.Value['Extend']) {
518 | $VolumeSize = FormatSize -Size $($_.Value['Size'] * 1024 * 1024)
519 | }
520 |
521 | $msg = '分区编号: ' + $_.Value['Order'] + ', 是否隐藏: ' + $_.Value['IsHidden'] + ', 文件系统: ' `
522 | + $_.Value['FileSystem'] + ', 类型: ' + $_.Value['TypeName'] + ', 容量: ' + $VolumeSize
523 |
524 | if ($_.Value['IsBoot']) {
525 | Write-Host -Object $msg -ForegroundColor Green
526 | }
527 | else {
528 | Write-Host -Object $msg
529 | }
530 | Write-Host -Object ''
531 | }
532 | }
533 |
534 | function ShowAddNewPartition {
535 |
536 | while ($true) {
537 | $InputOption = Read-Host -Prompt '是否增加新分区(0: 否, 1: 是),按回车键确认'
538 | Write-Host -Object ''
539 | if ($InputOption -ieq '0') {
540 | return $false
541 | }
542 | elseif ($InputOption -ieq '1') {
543 | return $true
544 | }
545 | else {
546 | Write-Warning -Message '输入无效,请重新输入'
547 | Write-Host -Object ''
548 | }
549 | }
550 | }
551 |
552 | function ShowIsBoot {
553 | param($CreatePartitionInfo)
554 |
555 | Clear-Host
556 | Write-Host -Object ''
557 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
558 | Write-Host -Object ''
559 | Write-Host -Object '================================================'
560 | Write-Host -Object '选择要安装系统的分区编号,类型必须为基本数据分区' -ForegroundColor Green
561 | Write-Host -Object '================================================'
562 | Write-Host -Object ''
563 |
564 | ShowNewPartition -CreatePartitionInfo $CreatePartitionInfo
565 |
566 | while ($true) {
567 | $InputOption = Read-Host -Prompt '请输入选择的分区编号(分区编号从 1 开始,类型必须为基本数据分区),按回车键确认'
568 | $SelectPartition = $CreatePartitionInfo[$InputOption]
569 | if ($SelectPartition) {
570 | if ($SelectPartition['Type'] -ieq 'Primary') {
571 | Write-Host -Object ''
572 | $SelectPartition['IsBoot'] = $true
573 | $Script:PartitionId = $SelectPartition['Order']
574 | return
575 | }
576 | else {
577 | Write-Host -Object ''
578 | Write-Warning -Message '所选分区非基本数据分区,只能选择基本数据分区,请重新输入'
579 | Write-Host -Object ''
580 | }
581 | }
582 | else {
583 | Write-Host -Object ''
584 | Write-Warning -Message '所选分区不存在,请重新输入'
585 | Write-Host -Object ''
586 | }
587 | }
588 | }
589 |
590 | function ShowCreatePartition {
591 |
592 | Clear-Host
593 | Write-Host -Object ''
594 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
595 | Write-Host -Object ''
596 |
597 | if (1 -eq $script:WipeDisk) {
598 | $CreatePartitionInfo = [ordered]@{
599 | '1' = @{
600 | 'Order' = 1;
601 | 'Size' = 100;
602 | 'Type' = 'EFI';
603 | 'TypeName' = 'EFI 分区';
604 | 'FileSystem' = 'FAT32';
605 | 'Extend' = $false;
606 | 'IsHidden' = $true;
607 | 'IsBoot' = $false
608 | }
609 | #'2' = @{
610 | # 'Order' = 2;
611 | # 'Size' = 128;
612 | # 'Type' = 'MSR';
613 | # 'TypeName' = '微软保留分区';
614 | # 'FileSystem' = '';
615 | # 'Extend' = $false;
616 | # 'IsHidden' = $true;
617 | # 'IsBoot' = $false
618 | #}
619 | }
620 | $PartitionNumber = 1
621 | Write-Host -Object '==============='
622 | Write-Host -Object '创建新 GPT 分区' -ForegroundColor Green
623 | Write-Host -Object '==============='
624 | Write-Host -Object ''
625 | }
626 | else {
627 | $CreatePartitionInfo = [ordered]@{}
628 | $PartitionNumber = 0
629 | Write-Host -Object '======================================'
630 | Write-Host -Object '创建新 MBR 分区,最多支持创建 4 个分区' -ForegroundColor Green
631 | Write-Host -Object '======================================'
632 | Write-Host -Object ''
633 | }
634 |
635 | ShowNewPartition -CreatePartitionInfo $CreatePartitionInfo
636 |
637 | while ($true) {
638 | try {
639 | $PartitionNumber = $PartitionNumber + 1
640 | [System.Int32]$InputOption = Read-Host `
641 | -Prompt "输入第 $PartitionNumber 个分区的大小,0 表示占用硬盘所有剩余空间(默认为 0),单位为 MB,按回车键确认"
642 | if ($InputOption -eq 0) {
643 | Write-Host -Object ''
644 | $CreatePartitionInfo.Add([System.String]$PartitionNumber, @{
645 | 'Order' = $PartitionNumber;
646 | 'Size' = 0;
647 | 'Type' = 'Primary';
648 | 'TypeName' = '基本数据分区';
649 | 'FileSystem' = 'NTFS';
650 | 'Extend' = $true;
651 | 'IsHidden' = $false;
652 | 'IsBoot' = $false
653 | })
654 | ShowNewPartition -CreatePartitionInfo $CreatePartitionInfo
655 | break
656 | }
657 | elseif ($InputOption -gt 0) {
658 | Write-Host -Object ''
659 | $CreatePartitionInfo.Add([System.String]$PartitionNumber, @{
660 | 'Order' = $PartitionNumber;
661 | 'Size' = $InputOption;
662 | 'Type' = 'Primary';
663 | 'TypeName' = '基本数据分区';
664 | 'FileSystem' = 'NTFS';
665 | 'Extend' = $false;
666 | 'IsHidden' = $false;
667 | 'IsBoot' = $false
668 | })
669 | ShowNewPartition -CreatePartitionInfo $CreatePartitionInfo
670 | }
671 | else {
672 | $PartitionNumber = $PartitionNumber - 1
673 | Write-Host -Object ''
674 | Write-Warning -Message '输入无效,请重新输入'
675 | Write-Host -Object ''
676 | continue
677 | }
678 | if (2 -eq $script:WipeDisk -and $PartitionNumber -ge 4) {
679 | $ShowAddNewPartition = $false
680 | }
681 | else {
682 | $ShowAddNewPartition = ShowAddNewPartition
683 | }
684 | if (!$ShowAddNewPartition) {
685 | $CreatePartitionInfo["$PartitionNumber"]['Extend'] = $true
686 | break
687 | }
688 | }
689 | catch {
690 | $PartitionNumber = $PartitionNumber - 1
691 | Write-Host -Object ''
692 | Write-Warning -Message '输入无效,请重新输入'
693 | Write-Host -Object ''
694 | }
695 | }
696 |
697 | ShowIsBoot -CreatePartitionInfo $CreatePartitionInfo
698 | ShowNewPartition -CreatePartitionInfo $CreatePartitionInfo
699 | return $CreatePartitionInfo
700 | }
701 |
702 | function ShowPartitionIdSelect {
703 | param($DiskId)
704 |
705 | $DefalultSelect = GetSystemPartitionId
706 | $CurrentDisks = GetCurrentDisk
707 | $SelectDisk = $CurrentDisks[$DiskId]
708 |
709 | Clear-Host
710 | Write-Host -Object ''
711 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
712 | Write-Host -Object ''
713 |
714 | if ($SelectDisk) {
715 | Write-Host -Object '================================================'
716 | Write-Host -Object "选择要安装系统的分区编号,推荐当前系统所在分区 $DefalultSelect" -ForegroundColor Green
717 | Write-Host -Object '================================================'
718 | Write-Host -Object ''
719 | Write-Host -Object '所选硬盘的分区如下:绿色字体的分区为当前系统所在分区'
720 |
721 | $SelectDisk['Partitions'].GetEnumerator() | ForEach-Object {
722 |
723 | $msg = '分区编号: ' + $_.Value['PartitionNumber'] + ', 驱动器: ' + $_.Value['DriveLetter'] + ', 是否隐藏: ' `
724 | + $_.Value['IsHidden'] + ', 文件系统: ' + $_.Value['FileSystem'] + ', 类型: ' + $_.Value['TypeName'] `
725 | + ', 可用空间: ' + (FormatSize -Size $_.Value['SizeRemaining']) + ', 容量: ' `
726 | + (FormatSize -Size $_.Value['Size'])
727 |
728 | Write-Host -Object ''
729 | if ($_.Value['IsBoot']) {
730 | Write-Host -Object $msg -ForegroundColor Green
731 | }
732 | else {
733 | Write-Host -Object $msg
734 | }
735 | }
736 | }
737 | else {
738 | Write-Host -Object '================================'
739 | Write-Host -Object "选择要安装系统的分区编号,推荐 $DefalultSelect" -ForegroundColor Green
740 | Write-Host -Object '================================'
741 | }
742 |
743 | while ($true) {
744 | Write-Host -Object ''
745 | $InputOption = Read-Host -Prompt "请输入选择的分区编号(分区编号从 1 开始,默认为 $DefalultSelect),按回车键确认"
746 | if ($InputOption -ieq '') {
747 | Write-Host -Object ''
748 | return $DefalultSelect
749 | }
750 | try {
751 | [System.Int32]$InputOption1 = [System.Int32]$InputOption
752 | if ($InputOption1 -eq 0) {
753 | Write-Host -Object ''
754 | Write-Warning -Message '输入无效,请重新输入'
755 | continue
756 | }
757 | if ($InputOption1 -ge 1) {
758 | Write-Host -Object ''
759 | return $InputOption1
760 | }
761 | else {
762 | Write-Host -Object ''
763 | Write-Warning -Message '输入无效,请重新输入'
764 | }
765 | }
766 | catch {
767 | Write-Host -Object ''
768 | Write-Warning -Message '输入无效,请重新输入'
769 | }
770 | }
771 | }
772 |
773 | function ShowFomatSelect {
774 |
775 | Clear-Host
776 | Write-Host -Object ''
777 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
778 | Write-Host -Object ''
779 | Write-Host -Object '================================'
780 | Write-Host -Object '选择是否对所选分区格式化,推荐 1' -ForegroundColor Green
781 | Write-Host -Object '================================'
782 | Write-Host -Object ''
783 | Write-Host -Object '0: 否'
784 | Write-Host -Object ''
785 | Write-Host -Object '1: 是,注意:安装系统时会清除所选分区的数据,请及时备份所选分区的数据' -ForegroundColor Red
786 |
787 | while ($true) {
788 | Write-Host -Object ''
789 | $InputOption = Read-Host -Prompt '请输入选择的序号(默认为 1),按回车键确认'
790 | if ($InputOption -ieq '' -or $InputOption -ieq '1') {
791 | Write-Host -Object ''
792 | return $true
793 | }
794 | elseif ($InputOption -ieq '0') {
795 | Write-Host -Object ''
796 | return $false
797 | }
798 | else {
799 | Write-Host -Object ''
800 | Write-Warning -Message '选择无效,请重新输入'
801 | }
802 | }
803 | }
804 |
805 | function ShowPartitionStyleSelect {
806 | param($DiskId)
807 |
808 | $CurrentDisks = GetCurrentDisk
809 | $SelectDisk = $CurrentDisks[$DiskId]
810 | $DefalultSelect = 1
811 | $DefaultPartitionStyle = 'GPT'
812 | if ($SelectDisk -and $SelectDisk['PartitionStyle'] -ine 'GPT') {
813 | $DefalultSelect = 2
814 | $DefaultPartitionStyle = 'MBR'
815 | }
816 |
817 | Clear-Host
818 | Write-Host -Object ''
819 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
820 | Write-Host -Object ''
821 | Write-Host -Object '===================================='
822 | Write-Host -Object "请确认所选硬盘分区的分区类型,推荐 $DefalultSelect" -ForegroundColor Green
823 | Write-Host -Object '===================================='
824 | Write-Host -Object ''
825 | Write-Host -Object '1: GPT 分区'
826 | Write-Host -Object ''
827 | Write-Host -Object '2: MBR 分区'
828 |
829 | while ($true) {
830 | Write-Host -Object ''
831 | $InputOption = Read-Host -Prompt "请输入选择的序号(默认为 $DefalultSelect),按回车键确认"
832 | if ($InputOption -ieq '') {
833 | Write-Host -Object ''
834 | return $DefaultPartitionStyle
835 | }
836 | if ($InputOption -ieq '1') {
837 | Write-Host -Object ''
838 | return 'GPT'
839 | }
840 | elseif ($InputOption -ieq '2') {
841 | Write-Host -Object ''
842 | return 'MBR'
843 | }
844 | else {
845 | Write-Host -Object ''
846 | Write-Warning -Message '选择无效,请重新输入'
847 | }
848 | }
849 | }
850 |
851 | function ShowNameInput {
852 |
853 | Clear-Host
854 | Write-Host -Object ''
855 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
856 | Write-Host -Object ''
857 | Write-Host -Object '=================================================='
858 | Write-Host -Object '输入系统安装后的登录账号名,账号名建议符合如下要求' -ForegroundColor Green
859 | Write-Host -Object '=================================================='
860 | Write-Host -Object ''
861 | Write-Host -Object '1: 推荐英文字母或数字的组合,尽量不使用空格或其他特殊字符' -ForegroundColor Yellow
862 | Write-Host -Object ''
863 | Write-Host -Object '2: 尽量不使用中文,防止某些应用软件不支持中文而无法使用' -ForegroundColor Yellow
864 | Write-Host -Object ''
865 |
866 | $InputOption = Read-Host -Prompt '请输入登录账号名(默认为 MyPC),按回车键确认'
867 | if ($InputOption -ieq '') {
868 | Write-Host -Object ''
869 | return 'MyPC'
870 | }
871 | else {
872 | Write-Host -Object ''
873 | return $InputOption
874 | }
875 | }
876 |
877 | function ShowPasswordInput {
878 |
879 | Clear-Host
880 | Write-Host -Object ''
881 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
882 | Write-Host -Object ''
883 | Write-Host -Object '======================================================================'
884 | Write-Host -Object '输入系统安装后的登录账号密码,推荐不设置密码,系统安装后再自行设置密码' -ForegroundColor Green
885 | Write-Host -Object '======================================================================'
886 | Write-Host -Object ''
887 |
888 | $InputOption = Read-Host -Prompt '请输入登录账号密码(默认无密码),按回车键确认'
889 | if ($InputOption -ieq '') {
890 | Write-Host -Object ''
891 | return ''
892 | }
893 | else {
894 | Write-Host -Object ''
895 | return $InputOption
896 | }
897 | }
898 |
899 | function ShowDriverLetterSelect {
900 |
901 | $CurrentDisks = GetCurrentDisk
902 |
903 | Clear-Host
904 | Write-Host -Object ''
905 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
906 | Write-Host -Object ''
907 | Write-Host -Object '=================================='
908 | Write-Host -Object '输入启动盘盘符或者镜像文件所在目录' -ForegroundColor Green
909 | Write-Host -Object '=================================='
910 | Write-Host -Object ''
911 | Write-Host -Object '当前系统识别到的驱动器如下:'
912 |
913 | $CurrentDisks.GetEnumerator() | ForEach-Object {
914 |
915 | $msg = '硬盘类型: ' + $_.Value['MediaType'] + ', 接口类型: ' + $_.Value['BusType'] + ', 分区类型: ' `
916 | + $_.Value['PartitionStyle'] + ', 硬盘容量: ' + (FormatSize -Size $_.Value['Size']) + ', 硬盘名称: ' `
917 | + $_.Value['FriendlyName']
918 |
919 | Write-Host -Object ''
920 | Write-Host -Object $msg
921 | $_.Value['Partitions'].GetEnumerator() | ForEach-Object {
922 | if ($_.Value['DriveLetter']) {
923 | $msg = ' |- 驱动器: ' + $_.Value['DriveLetter'] + ', 文件系统: ' + $_.Value['FileSystem'] `
924 | + ', 可用空间: ' + (FormatSize -Size $_.Value['SizeRemaining']) + ', 容量: ' `
925 | + (FormatSize -Size $_.Value['Size'])
926 | Write-Host -Object ' |'
927 | Write-Host -Object $msg
928 | }
929 | }
930 | }
931 |
932 | while ($true) {
933 | Write-Host -Object ''
934 | $InputOption = Read-Host `
935 | -Prompt '请输入启动盘盘符或者镜像文件所在目录(0 表示将应答文件保存到当前用户的桌面上),按回车键确认'
936 | if ($InputOption -ieq '') {
937 | Write-Host -Object ''
938 | Write-Warning -Message '选择无效,请重新输入'
939 | }
940 | elseif ($InputOption -ieq '0') {
941 | Write-Host -Object ''
942 | return ''
943 | }
944 | elseif (Test-Path -Path "$InputOption" -PathType Container) {
945 | Write-Host -Object ''
946 | return $InputOption
947 | }
948 | elseif (Test-Path -Path $($InputOption + ':\') -PathType Container) {
949 | Write-Host -Object ''
950 | return $($InputOption + ':\')
951 | }
952 | else {
953 | Write-Host -Object ''
954 | Write-Warning -Message '输入路径不存在,请重新输入'
955 | }
956 | }
957 | }
958 |
959 | function ShowGetISOPath {
960 | param($Path)
961 |
962 | Clear-Host
963 | Write-Host -Object ''
964 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
965 | Write-Host -Object ''
966 | Write-Host -Object '==============================='
967 | Write-Host -Object '选择使用应答文件的 ISO 镜像文件' -ForegroundColor Green
968 | Write-Host -Object '==============================='
969 | Write-Host -Object ''
970 | Write-Host -Object '搜索 ISO 镜像文件中......'
971 |
972 | $ISOFiles = [ordered]@{}
973 | $Index = 0;
974 | try {
975 | Get-ChildItem -Path "$Path" -Filter '*.iso' -Recurse -Depth 1 -File -ErrorAction SilentlyContinue | `
976 | ForEach-Object {
977 | $Index = $Index + 1
978 | $ISOFiles.Add([System.String]$Index, $_.FullName)
979 | }
980 | }
981 | catch {
982 | $msg = $Path + ' 无权限'
983 | Write-Host -Object ''
984 | Write-Warning -Message $msg
985 | }
986 |
987 | if ($ISOFiles.Count -gt 0) {
988 | Write-Host -Object ''
989 | Write-Host -Object '搜索到的镜像文件如下:'
990 | $ISOFiles.GetEnumerator() | ForEach-Object {
991 | Write-Host -Object ''
992 | $msg = '镜像文件序号: ' + $_.Key + ', 镜像文件路径: ' + $_.Value
993 | Write-Host -Object $msg -ForegroundColor Green
994 | }
995 | while ($true) {
996 | Write-Host -Object ''
997 | $InputOption = Read-Host -Prompt '请输入使用应答文件的 ISO 镜像文件序号,按回车键确认'
998 | $ISOFile = $ISOFiles[$InputOption]
999 | if ($ISOFile) {
1000 | Write-Host -Object ''
1001 | return $ISOFile
1002 | }
1003 | else {
1004 | Write-Host -Object ''
1005 | Write-Warning -Message '镜像文件序号不存在,请重新输入'
1006 | }
1007 | }
1008 | }
1009 | else {
1010 | Write-Host -Object ''
1011 | Write-Host -Object '未搜索到 ISO 镜像文件'
1012 | Write-Host -Object ''
1013 | return ''
1014 | }
1015 | }
1016 |
1017 | function UpdateVentoyConfig {
1018 | param(
1019 | $ISOPath,
1020 | $UnattendPath,
1021 | $VentoyConfigParentPath,
1022 | $ByPassCheck
1023 | )
1024 |
1025 | if (!$ISOPath) {
1026 | return
1027 | }
1028 | if (!$UnattendPath) {
1029 | return
1030 | }
1031 | if (!$VentoyConfigParentPath) {
1032 | return
1033 | }
1034 |
1035 | $ByPassCheckStr = '0'
1036 | if ($ByPassCheck) {
1037 | $ByPassCheckStr = '1'
1038 | }
1039 |
1040 | $ISOPath = Split-Path -Path "$ISOPath" -NoQualifier
1041 | $ISOPath = $ISOPath.Replace('\', '/')
1042 |
1043 | $UnattendPath = Split-Path -Path "$UnattendPath" -NoQualifier
1044 | $UnattendPath = $UnattendPath.Replace('\', '/')
1045 |
1046 | $VentoyConfigJsonPath = Join-Path -Path "$VentoyConfigParentPath" -ChildPath 'ventoy.json'
1047 |
1048 | $JSONContent = $null
1049 | if (Test-Path -Path "$VentoyConfigJsonPath" -PathType Leaf) {
1050 | try {
1051 | $JSONContent = Get-Content -Path "$VentoyConfigJsonPath" | ConvertFrom-Json
1052 | }
1053 | catch {
1054 | $msg = $VentoyConfigJsonPath + ' 解析失败'
1055 | Write-Warning -Message $msg
1056 | }
1057 | }
1058 |
1059 | if (!$JSONContent -or !($JSONContent -is [PSCustomObject])) {
1060 | $JSONContent = [PSCustomObject]@{
1061 | 'control' = @(@{
1062 | 'VTOY_WIN11_BYPASS_CHECK' = "$ByPassCheckStr"
1063 | });
1064 | 'auto_install' = @(@{
1065 | 'image' = $ISOPath;
1066 | 'template' = $UnattendPath
1067 | })
1068 | }
1069 |
1070 | $JSONString = $JSONContent | ConvertTo-Json
1071 | $Utf8NoBomEncoding = New-Object -TypeName System.Text.UTF8Encoding -ArgumentList $false
1072 | [System.IO.File]::WriteAllLines($VentoyConfigJsonPath, $JSONString, $Utf8NoBomEncoding)
1073 | return
1074 | }
1075 |
1076 | $Controls = $JSONContent.'control'
1077 | if ($null -eq $Controls -or !($Controls -is [System.Array])) {
1078 | Add-Member -InputObject $JSONContent -Force `
1079 | -NotePropertyMembers @{ 'control' = @(@{ 'VTOY_WIN11_BYPASS_CHECK' = "$ByPassCheckStr" }) }
1080 | }
1081 | else {
1082 | $AddFlag = $false
1083 | foreach ($Control in $Controls) {
1084 | if ($null -eq $Control) {
1085 | $AddFlag = $true
1086 | Add-Member -InputObject $Control -Force -NotePropertyMembers @{
1087 | 'VTOY_WIN11_BYPASS_CHECK' = "$ByPassCheckStr"
1088 | }
1089 | break
1090 | }
1091 | $Check = $Control.'VTOY_WIN11_BYPASS_CHECK'
1092 | if ($null -eq $Check) {
1093 | continue
1094 | }
1095 | $AddFlag = $true
1096 | Add-Member -InputObject $Control -Force -NotePropertyMembers @{
1097 | 'VTOY_WIN11_BYPASS_CHECK' = "$ByPassCheckStr"
1098 | }
1099 | break
1100 | }
1101 | if (!$AddFlag) {
1102 | $Controls += [PSCustomObject]@{ 'VTOY_WIN11_BYPASS_CHECK' = "$ByPassCheckStr" }
1103 | $JSONContent.'control' = $Controls
1104 | }
1105 | }
1106 |
1107 | $Installs = $JSONContent.'auto_install'
1108 | if ($null -eq $Installs -or !($Installs -is [System.Array])) {
1109 | Add-Member -InputObject $JSONContent -Force `
1110 | -NotePropertyMembers @{ 'auto_install' = @(@{ 'image' = $ISOPath; 'template' = $UnattendPath }) }
1111 | }
1112 | else {
1113 | $AddFlag = $false
1114 | foreach ($Install in $Installs) {
1115 | if ($null -eq $Install) {
1116 | Add-Member -InputObject $Install -Force `
1117 | -NotePropertyMembers @{ 'image' = $ISOPath; 'template' = $UnattendPath }
1118 | $AddFlag = $true
1119 | break
1120 | }
1121 | $Image = $Install.'image'
1122 | if ($null -eq $Image) {
1123 | Add-Member -InputObject $Install -Force `
1124 | -NotePropertyMembers @{ 'image' = $ISOPath; 'template' = $UnattendPath }
1125 | $AddFlag = $true
1126 | break
1127 | }
1128 | if ($Image -ne $ISOPath) {
1129 | continue
1130 | }
1131 | Add-Member -InputObject $Install -Force `
1132 | -NotePropertyMembers @{ 'image' = $ISOPath; 'template' = $UnattendPath }
1133 | $AddFlag = $true
1134 | break
1135 | }
1136 | if (!$AddFlag) {
1137 | $Installs += [PSCustomObject]@{ 'image' = $ISOPath; 'template' = $UnattendPath }
1138 | $JSONContent.'auto_install' = $Installs
1139 | }
1140 | }
1141 |
1142 | $JSONString = $JSONContent | ConvertTo-Json
1143 | $Utf8NoBomEncoding = New-Object -TypeName System.Text.UTF8Encoding -ArgumentList $false
1144 | [System.IO.File]::WriteAllLines($VentoyConfigJsonPath, $JSONString, $Utf8NoBomEncoding)
1145 | }
1146 |
1147 | function GetVertion {
1148 | $ProductJsonPath = "$PSScriptRoot\product.json"
1149 |
1150 | if (!(Test-Path -Path "$ProductJsonPath" -PathType Leaf)) {
1151 | Write-Warning -Message ("$ProductJsonPath 不存在")
1152 | [System.Environment]::Exit(0)
1153 | }
1154 |
1155 | $ProductInfo = $null
1156 | try {
1157 | $ProductInfo = Get-Content -Path "$ProductJsonPath" | ConvertFrom-Json
1158 | }
1159 | catch {
1160 | Write-Warning -Message ("$ProductJsonPath 解析失败")
1161 | [System.Environment]::Exit(0)
1162 | }
1163 | if (!$ProductInfo -or $ProductInfo -isNot [PSCustomObject]) {
1164 | Write-Warning -Message ("$ProductJsonPath 解析失败")
1165 | [System.Environment]::Exit(0)
1166 | }
1167 |
1168 | $Version = $ProductInfo.'version'
1169 | if (!$Version) {
1170 | Write-Warning -Message ("$ProductJsonPath 不存在 version 信息")
1171 | [System.Environment]::Exit(0)
1172 | }
1173 |
1174 | return $Version
1175 | }
1176 |
1177 | $VersionInfo = GetVertion
1178 |
1179 | if ($Version) {
1180 | return $VersionInfo
1181 | }
1182 |
1183 | Clear-Host
1184 | $PSDefaultParameterValues['*:Encoding'] = 'utf8'
1185 | $ProgressPreference = 'SilentlyContinue'
1186 | $Host.UI.RawUI.WindowTitle = "UnattendTool v$VersionInfo"
1187 | Set-Location -Path "$PSScriptRoot"
1188 | Write-Host -Object ''
1189 | Write-Host -Object "=====> UnattendTool v$VersionInfo https://github.com/dsx42/UnattendTool <====="
1190 | Write-Host -Object ''
1191 |
1192 | $WipeDisk = 0
1193 | $Token = '31bf3856ad364e35'
1194 | $WindowsProduct = [ordered]@{
1195 | 'Enterprise' = @{
1196 | 'CN' = '企业版';
1197 | 'US' = 'Enterprise';
1198 | 'NoSpaceName' = 'Enterprise';
1199 | 'gvlk' = 'NPPR9-FWDCX-D2C8J-H872K-2YT43'
1200 | };
1201 | 'Education' = @{
1202 | 'CN' = '教育版';
1203 | 'US' = 'Education';
1204 | 'NoSpaceName' = 'Education';
1205 | 'gvlk' = 'NW6C2-QMPVW-D7KKK-3GKT6-VCFB2'
1206 | };
1207 | 'Pro' = @{
1208 | 'CN' = '专业版';
1209 | 'US' = 'Pro';
1210 | 'NoSpaceName' = 'Pro';
1211 | 'gvlk' = 'W269N-WFGWX-YVC9B-4J6C9-T83GX'
1212 | };
1213 | 'Pro Education' = @{
1214 | 'CN' = '专业教育版';
1215 | 'US' = 'Pro Education';
1216 | 'NoSpaceName' = 'Pro_Education';
1217 | 'gvlk' = '6TP4R-GNPTD-KYYHQ-7B7DP-J447Y'
1218 | };
1219 | 'Pro For Workstations' = @{
1220 | 'CN' = '专业工作站版';
1221 | 'US' = 'Pro For Workstations';
1222 | 'NoSpaceName' = 'Pro_For_Workstations';
1223 | 'gvlk' = 'NRG8B-VKK3Q-CXVCJ-9G2XF-6Q84J'
1224 | }
1225 | }
1226 |
1227 | $CurrentDisks = GetCurrentDisk
1228 |
1229 | if ($Interactive) {
1230 | $Language = ShowLanguageSelect
1231 | $OsVersion = ShowOsVersionSelect
1232 | $WindowsProductName = ShowWindowsProductNameSelect
1233 | $Architecture = ShowArchitectureSelect -OsVersion $OsVersion
1234 | $ByPassCheck = ShowByPassSelect -OsVersion $OsVersion
1235 | $DiskId = ShowDiskIdSelect
1236 | $WipeDisk = ShowWipeDiskSelect -DiskId $DiskId
1237 | if (1 -eq $WipeDisk -or 2 -eq $WipeDisk) {
1238 | $CreatePartitionInfo = ShowCreatePartition
1239 | }
1240 | else {
1241 | $PartitionId = ShowPartitionIdSelect -DiskId $DiskId
1242 | $NotFormat = !$(ShowFomatSelect)
1243 | if (!$NotFormat) {
1244 | $PartitionStyle = ShowPartitionStyleSelect -DiskId $DiskId
1245 | }
1246 | }
1247 | $FullName = ShowNameInput
1248 | $Password = ShowPasswordInput
1249 | $DriverLetter = ShowDriverLetterSelect
1250 | if ($DriverLetter) {
1251 | $ISOPath = ShowGetISOPath -Path "$DriverLetter"
1252 | }
1253 | }
1254 |
1255 | if ($Language -ine 'zh-CN' -and $Language -ine 'en-US') {
1256 | Write-Warning -Message '参数 Language 只支持 zh-CN (简体中文), en-US (英文)'
1257 | [System.Environment]::Exit(0)
1258 | }
1259 | if ($Language -ieq 'zh-CN') {
1260 | $Language = 'zh-CN'
1261 | }
1262 | elseif ($Language -ieq 'en-US') {
1263 | $Language = 'en-US'
1264 | }
1265 |
1266 | if ($OsVersion -ne 10 -and $OsVersion -ne 11) {
1267 | Write-Warning -Message '参数 OsVersion 只支持 10 (Windows 10), 11 (Windows 11)'
1268 | [System.Environment]::Exit(0)
1269 | }
1270 |
1271 | if ($WindowsProductName -and !$WindowsProduct.Contains($WindowsProductName)) {
1272 | $WindowsProductNameArray = @($WindowsProduct.GetEnumerator() | ForEach-Object {
1273 | $_.Value['US'] + ' (' + $_.Value['CN'] + ')'
1274 | })
1275 | $AllSupportProductName = [string]::join(', ', $WindowsProductNameArray)
1276 | Write-Warning -Message "参数 WindowsProductName 只支持 $AllSupportProductName"
1277 | [System.Environment]::Exit(0)
1278 | }
1279 |
1280 | if ($OsVersion -eq 10) {
1281 | if ($Architecture -ne 'x64' -and $Architecture -ne 'x86') {
1282 | Write-Warning -Message '参数 OsVersion 为 Windows 10 时,参数 Architecture 只支持 x64 (64 位系统), x86 (32 位系统)'
1283 | [System.Environment]::Exit(0)
1284 | }
1285 | }
1286 | if ($OsVersion -eq 11) {
1287 | if ($Architecture -ine 'x64') {
1288 | Write-Warning -Message '参数 OsVersion 为 Windows 11 时,参数 Architecture 只支持 x64 (64 位系统)'
1289 | [System.Environment]::Exit(0)
1290 | }
1291 | }
1292 |
1293 | $ArchitectureName = 'amd64'
1294 | if ($Architecture -eq 'x86') {
1295 | $ArchitectureName = 'x86'
1296 | }
1297 |
1298 | if ($DiskId -eq -1) {
1299 | $DiskId = GetSystemDiskId
1300 | }
1301 |
1302 | if ($PartitionId -eq -1) {
1303 | $PartitionId = GetSystemPartitionId
1304 | }
1305 |
1306 | if ($PartitionStyle -ine 'GPT' -and $PartitionStyle -ine 'MBR') {
1307 | Write-Warning -Message '参数 PartitionStyle 只支持 GPT, MBR'
1308 | [System.Environment]::Exit(0)
1309 | }
1310 | if ($PartitionStyle -ieq 'GPT') {
1311 | $PartitionStyle = 'GPT'
1312 | }
1313 | elseif ($PartitionStyle -ieq 'MBR') {
1314 | $PartitionStyle = 'MBR'
1315 | }
1316 |
1317 | if ('' -ieq $DriverLetter) {
1318 | $ParentPath = GetDefaultFolderPath
1319 | }
1320 | else {
1321 | $ParentPath = $DriverLetter
1322 | if ($ISOPath) {
1323 | $Letter1 = Split-Path -Path "$ISOPath" -Qualifier
1324 | $Letter2 = Split-Path -Path "$ISOPath" -Qualifier
1325 | if ($Letter1 -ine $Letter2) {
1326 | Write-Warning -Message '参数 ISOPath 指定的路径必须和参数 DriverLetter 指定的驱动器属于同一个驱动器'
1327 | [System.Environment]::Exit(0)
1328 | }
1329 | }
1330 | }
1331 |
1332 | $ProductInfo = @{}
1333 | if ($WindowsProductName) {
1334 | $ProductInfo = $WindowsProduct[$WindowsProductName]
1335 | }
1336 |
1337 | $UnattendName = 'Autounattend'
1338 | if ($ISOPath) {
1339 | $VentoyConfigParentPath = Join-Path -Path "$ParentPath" -ChildPath 'ventoy'
1340 | if (!$(Test-Path -Path "$VentoyConfigParentPath" -PathType Container)) {
1341 | New-Item -Path "$VentoyConfigParentPath" -ItemType Directory -Force | Out-Null
1342 | }
1343 | }
1344 | if (!(Test-Path -Path "$ParentPath\setup.exe" -PathType Leaf)) {
1345 | $VentoyConfigScriptPath = Join-Path -Path "$ParentPath" -ChildPath 'script'
1346 | if (!$(Test-Path -Path "$VentoyConfigScriptPath" -PathType Container)) {
1347 | New-Item -Path "$VentoyConfigScriptPath" -ItemType Directory -Force | Out-Null
1348 | }
1349 |
1350 | $DiskTypeStr = ''
1351 | if ($WipeDisk -eq 1) {
1352 | $DiskTypeStr = '_CreateGPT'
1353 | }
1354 | elseif ($WipeDisk -eq 2) {
1355 | $DiskTypeStr = '_CreateMBR'
1356 | }
1357 | elseif (!$NotFormat) {
1358 | $DiskTypeStr = "_Format$PartitionStyle"
1359 | }
1360 |
1361 | if ('' -ieq $WindowsProductName) {
1362 | $UnattendName = 'Unattend_Windows_' + $OsVersion + '_' + $Architecture + '_' `
1363 | + $Language + $DiskTypeStr + '_' + $FullName
1364 | }
1365 | else {
1366 | $NoSpaceName = $ProductInfo['NoSpaceName']
1367 | $UnattendName = 'Unattend_Windows_' + $OsVersion + '_' + $NoSpaceName + '_' `
1368 | + $Architecture + '_' + $Language + $DiskTypeStr + '_' + $FullName
1369 | }
1370 | $UnattendPath = "$VentoyConfigScriptPath\$UnattendName.xml"
1371 |
1372 | Remove-Item -Path "$VentoyConfigScriptPath\Install_$UnattendName.cmd" -Force -ErrorAction SilentlyContinue
1373 | $GB2312Encoding = [System.Text.Encoding]::GetEncoding('gb2312')
1374 | $CmdContents = @(
1375 | '@echo off',
1376 | '',
1377 | 'if "%1" == "RunAs" (',
1378 | ' goto RunAs',
1379 | ')',
1380 | '',
1381 | 'set file_folder=%~dp0',
1382 | '',
1383 | ("mshta `"javascript:new ActiveXObject('Shell.Application').ShellExecute('%~nx0', 'RunAs', " `
1384 | + "'%file_folder:\=\\%', 'runas', 1); window.close()`" && exit /b 0"),
1385 | '',
1386 | ':RunAs',
1387 | 'echo.',
1388 | '',
1389 | ':GetSetupPath',
1390 | 'set /P setupPath=请输入镜像挂载或解压后的目录:',
1391 | '',
1392 | 'if not exist %setupPath%\setup.exe (',
1393 | ' if not exist %setupPath%:\setup.exe (',
1394 | ' echo.',
1395 | ' echo 目录 %setupPath% 下不存在 setup.exe,并非镜像挂载或解压后的目录,请重新确认输入',
1396 | ' echo.',
1397 | ' goto GetSetupPath',
1398 | ' ) else (',
1399 | ' set finalPath=%setupPath%:',
1400 | ' )',
1401 | ') else (',
1402 | ' set finalPath=%setupPath%',
1403 | ')',
1404 | ''
1405 | )
1406 | if (11 -eq $OsVersion -and $ByPassCheck) {
1407 | $CmdContents += 'reg add "HKLM\System\Setup\LabConfig" /v "BypassTPMCheck" /t REG_DWORD /d "1" /f'
1408 | $CmdContents += 'reg add "HKLM\System\Setup\LabConfig" /v "BypassSecureBootCheck" /t REG_DWORD /d "1" /f'
1409 | $CmdContents += 'reg add "HKLM\System\Setup\LabConfig" /v "BypassRAMCheck" /t REG_DWORD /d "1" /f'
1410 | $CmdContents += 'reg add "HKLM\System\Setup\LabConfig" /v "BypassStorageCheck" /t REG_DWORD /d "1" /f'
1411 | $CmdContents += 'reg add "HKLM\System\Setup\LabConfig" /v "BypassCPUCheck" /t REG_DWORD /d "1" /f'
1412 | }
1413 | $CmdContents += ''
1414 | $CmdContents += "%finalPath%\setup.exe /unattend:%~dp0$UnattendName.xml"
1415 | [System.IO.File]::WriteAllLines("$VentoyConfigScriptPath\Install_$UnattendName.cmd", $CmdContents, $GB2312Encoding)
1416 | }
1417 | else {
1418 | $UnattendPath = "$ParentPath\$UnattendName.xml"
1419 | Remove-Item -Path "$ParentPath\Install_Autounattend.cmd" -Force -ErrorAction SilentlyContinue
1420 | $GB2312Encoding = [System.Text.Encoding]::GetEncoding('gb2312')
1421 | $CmdContents = @(
1422 | '@echo off',
1423 | '',
1424 | 'if "%1" == "RunAs" (',
1425 | ' goto RunAs',
1426 | ')',
1427 | '',
1428 | 'set file_folder=%~dp0',
1429 | '',
1430 | ("mshta `"javascript:new ActiveXObject('Shell.Application').ShellExecute('%~nx0', 'RunAs', " `
1431 | + "'%file_folder:\=\\%', 'runas', 1); window.close()`" && exit /b 0"),
1432 | '',
1433 | ':RunAs',
1434 | ''
1435 | )
1436 | if (11 -eq $OsVersion -and $ByPassCheck) {
1437 | $CmdContents += 'reg add "HKLM\System\Setup\LabConfig" /v "BypassTPMCheck" /t REG_DWORD /d "1" /f'
1438 | $CmdContents += 'reg add "HKLM\System\Setup\LabConfig" /v "BypassSecureBootCheck" /t REG_DWORD /d "1" /f'
1439 | $CmdContents += 'reg add "HKLM\System\Setup\LabConfig" /v "BypassRAMCheck" /t REG_DWORD /d "1" /f'
1440 | $CmdContents += 'reg add "HKLM\System\Setup\LabConfig" /v "BypassStorageCheck" /t REG_DWORD /d "1" /f'
1441 | $CmdContents += 'reg add "HKLM\System\Setup\LabConfig" /v "BypassCPUCheck" /t REG_DWORD /d "1" /f'
1442 | }
1443 | $CmdContents += ''
1444 | $CmdContents += '%~dp0setup.exe /unattend:%~dp0Autounattend.xml'
1445 | [System.IO.File]::WriteAllLines("$ParentPath\Install_Autounattend.cmd", $CmdContents, $GB2312Encoding)
1446 | }
1447 |
1448 | UpdateVentoyConfig -ISOPath $ISOPath -UnattendPath $UnattendPath -VentoyConfigParentPath $VentoyConfigParentPath `
1449 | -ByPassCheck $ByPassCheck
1450 |
1451 | if (Test-Path -Path "$UnattendPath" -PathType Leaf) {
1452 | Remove-Item -Path "$UnattendPath" -Force
1453 | }
1454 | Add-Content -Path "$UnattendPath" -Value ''
1455 | Add-Content -Path "$UnattendPath" -Value ''
1456 | Add-Content -Path "$UnattendPath" -Value ""
1457 | Add-Content -Path "$UnattendPath" -Value ''
1458 | Add-Content -Path "$UnattendPath" -Value ''
1459 | Add-Content -Path "$UnattendPath" -Value ''
1460 | Add-Content -Path "$UnattendPath" -Value ''
1461 | Add-Content -Path "$UnattendPath" -Value ' '
1462 | Add-Content -Path "$UnattendPath" -Value (" ")
1466 | Add-Content -Path "$UnattendPath" -Value ' '
1467 | Add-Content -Path "$UnattendPath" -Value " $Language"
1468 | Add-Content -Path "$UnattendPath" -Value ' '
1469 | Add-Content -Path "$UnattendPath" -Value " $Language"
1470 | Add-Content -Path "$UnattendPath" -Value " $Language"
1471 | Add-Content -Path "$UnattendPath" -Value " $Language"
1472 | Add-Content -Path "$UnattendPath" -Value " $Language"
1473 | Add-Content -Path "$UnattendPath" -Value ' '
1474 | Add-Content -Path "$UnattendPath" -Value ''
1475 | Add-Content -Path "$UnattendPath" -Value (" ")
1479 | if (11 -eq $OsVersion -and $ByPassCheck) {
1480 | Add-Content -Path "$UnattendPath" -Value ' '
1481 | Add-Content -Path "$UnattendPath" -Value ' '
1482 | Add-Content -Path "$UnattendPath" -Value ' 1'
1483 | Add-Content -Path "$UnattendPath" -Value (' reg add "HKLM\System\Setup\LabConfig"' `
1484 | + ' /v "BypassTPMCheck" /t REG_DWORD /d "1" /f')
1485 | Add-Content -Path "$UnattendPath" -Value ' '
1486 | Add-Content -Path "$UnattendPath" -Value ''
1487 | Add-Content -Path "$UnattendPath" -Value ' '
1488 | Add-Content -Path "$UnattendPath" -Value ' 2'
1489 | Add-Content -Path "$UnattendPath" -Value (' reg add "HKLM\System\Setup\LabConfig"' `
1490 | + ' /v "BypassSecureBootCheck" /t REG_DWORD /d "1" /f')
1491 | Add-Content -Path "$UnattendPath" -Value ' '
1492 | Add-Content -Path "$UnattendPath" -Value ''
1493 | Add-Content -Path "$UnattendPath" -Value ' '
1494 | Add-Content -Path "$UnattendPath" -Value ' 3'
1495 | Add-Content -Path "$UnattendPath" -Value (' reg add "HKLM\System\Setup\LabConfig"' `
1496 | + ' /v "BypassRAMCheck" /t REG_DWORD /d "1" /f')
1497 | Add-Content -Path "$UnattendPath" -Value ' '
1498 | Add-Content -Path "$UnattendPath" -Value ''
1499 | Add-Content -Path "$UnattendPath" -Value ' '
1500 | Add-Content -Path "$UnattendPath" -Value ' 4'
1501 | Add-Content -Path "$UnattendPath" -Value (' reg add "HKLM\System\Setup\LabConfig"' `
1502 | + ' /v "BypassStorageCheck" /t REG_DWORD /d "1" /f')
1503 | Add-Content -Path "$UnattendPath" -Value ' '
1504 | Add-Content -Path "$UnattendPath" -Value ''
1505 | Add-Content -Path "$UnattendPath" -Value ' '
1506 | Add-Content -Path "$UnattendPath" -Value ' 5'
1507 | Add-Content -Path "$UnattendPath" -Value (' reg add "HKLM\System\Setup\LabConfig"' `
1508 | + ' /v "BypassCPUCheck" /t REG_DWORD /d "1" /f')
1509 | Add-Content -Path "$UnattendPath" -Value ' '
1510 | Add-Content -Path "$UnattendPath" -Value ' '
1511 | Add-Content -Path "$UnattendPath" -Value ''
1512 | }
1513 | Add-Content -Path "$UnattendPath" -Value ' false'
1514 | Add-Content -Path "$UnattendPath" -Value ''
1515 | Add-Content -Path "$UnattendPath" -Value ' '
1516 | Add-Content -Path "$UnattendPath" -Value ' true'
1517 | if ($FullName) {
1518 | Add-Content -Path "$UnattendPath" -Value " $FullName"
1519 | }
1520 | if ($WindowsProductName) {
1521 | $key = $ProductInfo['gvlk']
1522 | Add-Content -Path "$UnattendPath" -Value ' '
1523 | Add-Content -Path "$UnattendPath" -Value " $key"
1524 | Add-Content -Path "$UnattendPath" -Value ' '
1525 | }
1526 | Add-Content -Path "$UnattendPath" -Value ' '
1527 | Add-Content -Path "$UnattendPath" -Value ''
1528 | if ($WipeDisk -ne 0) {
1529 | Add-Content -Path "$UnattendPath" -Value ' '
1530 | Add-Content -Path "$UnattendPath" -Value ' '
1531 | Add-Content -Path "$UnattendPath" -Value " $DiskId"
1532 | Add-Content -Path "$UnattendPath" -Value ''
1533 | Add-Content -Path "$UnattendPath" -Value ' true'
1534 | Add-Content -Path "$UnattendPath" -Value ''
1535 | Add-Content -Path "$UnattendPath" -Value ' '
1536 | $CreatePartitionInfo.GetEnumerator() | ForEach-Object {
1537 | Add-Content -Path "$UnattendPath" -Value ' '
1538 | if ($_.Value['Extend']) {
1539 | Add-Content -Path "$UnattendPath" -Value ' true'
1540 | }
1541 | else {
1542 | $Size = $_.Value['Size']
1543 | Add-Content -Path "$UnattendPath" -Value " $Size"
1544 | }
1545 | $Order = $_.Value['Order']
1546 | Add-Content -Path "$UnattendPath" -Value " $Order"
1547 | $Type = $_.Value['Type']
1548 | Add-Content -Path "$UnattendPath" -Value " $Type"
1549 | Add-Content -Path "$UnattendPath" -Value ' '
1550 | }
1551 | Add-Content -Path "$UnattendPath" -Value ' '
1552 | Add-Content -Path "$UnattendPath" -Value ''
1553 | Add-Content -Path "$UnattendPath" -Value ' '
1554 | $CreatePartitionInfo.GetEnumerator() | ForEach-Object {
1555 | Add-Content -Path "$UnattendPath" -Value ' '
1556 | if ($WipeDisk -eq 2 -and $_.Value['IsBoot']) {
1557 | Add-Content -Path "$UnattendPath" -Value ' true'
1558 | }
1559 | $Format = $_.Value['FileSystem']
1560 | if ($Format) {
1561 | Add-Content -Path "$UnattendPath" -Value " $Format"
1562 | }
1563 | $Order = $_.Value['Order']
1564 | Add-Content -Path "$UnattendPath" -Value " $Order"
1565 | Add-Content -Path "$UnattendPath" -Value " $Order"
1566 | Add-Content -Path "$UnattendPath" -Value ' '
1567 | }
1568 | Add-Content -Path "$UnattendPath" -Value ' '
1569 | Add-Content -Path "$UnattendPath" -Value ' '
1570 | Add-Content -Path "$UnattendPath" -Value ' '
1571 | Add-Content -Path "$UnattendPath" -Value ''
1572 | }
1573 | elseif (!$NotFormat) {
1574 | Add-Content -Path "$UnattendPath" -Value ' '
1575 | Add-Content -Path "$UnattendPath" -Value ' '
1576 | Add-Content -Path "$UnattendPath" -Value " $DiskId"
1577 | Add-Content -Path "$UnattendPath" -Value ''
1578 | Add-Content -Path "$UnattendPath" -Value ' '
1579 | Add-Content -Path "$UnattendPath" -Value ' '
1580 | if ($PartitionStyle -ieq 'MBR') {
1581 | Add-Content -Path "$UnattendPath" -Value ' true'
1582 | }
1583 | Add-Content -Path "$UnattendPath" -Value ' NTFS'
1584 | Add-Content -Path "$UnattendPath" -Value ' 1'
1585 | Add-Content -Path "$UnattendPath" -Value " $PartitionId"
1586 | Add-Content -Path "$UnattendPath" -Value ' '
1587 | Add-Content -Path "$UnattendPath" -Value ' '
1588 | Add-Content -Path "$UnattendPath" -Value ' '
1589 | Add-Content -Path "$UnattendPath" -Value ' '
1590 | Add-Content -Path "$UnattendPath" -Value ''
1591 | }
1592 | Add-Content -Path "$UnattendPath" -Value ' '
1593 | Add-Content -Path "$UnattendPath" -Value ' '
1594 | if ($WindowsProductName) {
1595 | $ImageName = 'Windows ' + $OsVersion + ' ' + $ProductInfo['US']
1596 | Add-Content -Path "$UnattendPath" -Value ' '
1597 | Add-Content -Path "$UnattendPath" -Value ' '
1598 | Add-Content -Path "$UnattendPath" -Value ' /IMAGE/NAME'
1599 | Add-Content -Path "$UnattendPath" -Value " $ImageName"
1600 | Add-Content -Path "$UnattendPath" -Value ' '
1601 | Add-Content -Path "$UnattendPath" -Value ' '
1602 | Add-Content -Path "$UnattendPath" -Value ''
1603 | }
1604 |
1605 | Add-Content -Path "$UnattendPath" -Value ' '
1606 | Add-Content -Path "$UnattendPath" -Value " $DiskId"
1607 | Add-Content -Path "$UnattendPath" -Value " $PartitionId"
1608 | Add-Content -Path "$UnattendPath" -Value ' '
1609 | Add-Content -Path "$UnattendPath" -Value ' '
1610 | Add-Content -Path "$UnattendPath" -Value ' '
1611 | Add-Content -Path "$UnattendPath" -Value ' '
1612 | Add-Content -Path "$UnattendPath" -Value ' '
1613 | Add-Content -Path "$UnattendPath" -Value ''
1614 | Add-Content -Path "$UnattendPath" -Value ' '
1615 | Add-Content -Path "$UnattendPath" -Value (" ")
1619 | Add-Content -Path "$UnattendPath" -Value ' true'
1620 | Add-Content -Path "$UnattendPath" -Value ' '
1621 | Add-Content -Path "$UnattendPath" -Value ''
1622 | Add-Content -Path "$UnattendPath" -Value (" ")
1626 | Add-Content -Path "$UnattendPath" -Value ' 0'
1627 | Add-Content -Path "$UnattendPath" -Value ' '
1628 | if ($WindowsProductName) {
1629 | $key = $ProductInfo['gvlk']
1630 | Add-Content -Path "$UnattendPath" -Value ''
1631 | Add-Content -Path "$UnattendPath" -Value (" ")
1635 | Add-Content -Path "$UnattendPath" -Value " $key"
1636 | Add-Content -Path "$UnattendPath" -Value ' '
1637 | }
1638 | Add-Content -Path "$UnattendPath" -Value ' '
1639 | Add-Content -Path "$UnattendPath" -Value ''
1640 | Add-Content -Path "$UnattendPath" -Value ' '
1641 | Add-Content -Path "$UnattendPath" -Value (" ")
1645 | Add-Content -Path "$UnattendPath" -Value " $Language"
1646 | Add-Content -Path "$UnattendPath" -Value " $Language"
1647 | Add-Content -Path "$UnattendPath" -Value " $Language"
1648 | Add-Content -Path "$UnattendPath" -Value " $Language"
1649 | Add-Content -Path "$UnattendPath" -Value ' '
1650 | Add-Content -Path "$UnattendPath" -Value ''
1651 | Add-Content -Path "$UnattendPath" -Value (" ")
1655 | if ($FullName) {
1656 | Add-Content -Path "$UnattendPath" -Value ' '
1657 | Add-Content -Path "$UnattendPath" -Value ' '
1658 | if ($Password) {
1659 | Add-Content -Path "$UnattendPath" -Value " $Password"
1660 | }
1661 | else {
1662 | Add-Content -Path "$UnattendPath" -Value ' '
1663 | }
1664 | Add-Content -Path "$UnattendPath" -Value ' true'
1665 | Add-Content -Path "$UnattendPath" -Value ' '
1666 | Add-Content -Path "$UnattendPath" -Value ' true'
1667 | Add-Content -Path "$UnattendPath" -Value " $FullName"
1668 | Add-Content -Path "$UnattendPath" -Value ' '
1669 | Add-Content -Path "$UnattendPath" -Value ''
1670 | Add-Content -Path "$UnattendPath" -Value ' '
1671 | Add-Content -Path "$UnattendPath" -Value ' '
1672 | Add-Content -Path "$UnattendPath" -Value ' '
1673 | Add-Content -Path "$UnattendPath" -Value ' '
1674 | if ($Password) {
1675 | Add-Content -Path "$UnattendPath" -Value " $Password"
1676 | }
1677 | else {
1678 | Add-Content -Path "$UnattendPath" -Value ' '
1679 | }
1680 | Add-Content -Path "$UnattendPath" -Value ' true'
1681 | Add-Content -Path "$UnattendPath" -Value ' '
1682 | Add-Content -Path "$UnattendPath" -Value " $FullName"
1683 | Add-Content -Path "$UnattendPath" -Value ' Administrators'
1684 | Add-Content -Path "$UnattendPath" -Value " $FullName"
1685 | Add-Content -Path "$UnattendPath" -Value ' '
1686 | Add-Content -Path "$UnattendPath" -Value ' '
1687 | Add-Content -Path "$UnattendPath" -Value ' '
1688 | Add-Content -Path "$UnattendPath" -Value ''
1689 | Add-Content -Path "$UnattendPath" -Value " $FullName"
1690 | Add-Content -Path "$UnattendPath" -Value ''
1691 | }
1692 | Add-Content -Path "$UnattendPath" -Value ' '
1693 | Add-Content -Path "$UnattendPath" -Value ' true'
1694 | Add-Content -Path "$UnattendPath" -Value ' true'
1695 | Add-Content -Path "$UnattendPath" -Value ' true'
1696 | Add-Content -Path "$UnattendPath" -Value ' true'
1697 | Add-Content -Path "$UnattendPath" -Value ' true'
1698 | Add-Content -Path "$UnattendPath" -Value ' 3'
1699 | Add-Content -Path "$UnattendPath" -Value ' '
1700 | Add-Content -Path "$UnattendPath" -Value ''
1701 | Add-Content -Path "$UnattendPath" -Value ' '
1702 | Add-Content -Path "$UnattendPath" -Value ' '
1703 | Add-Content -Path "$UnattendPath" -Value ' 1'
1704 | Add-Content -Path "$UnattendPath" -Value (' cmd /C del /f /q %WINDIR%\Panther' `
1705 | + '\unattend.xml')
1706 | Add-Content -Path "$UnattendPath" -Value ' '
1707 | if ($Password) {
1708 | Add-Content -Path "$UnattendPath" -Value ''
1709 | Add-Content -Path "$UnattendPath" -Value ' '
1710 | Add-Content -Path "$UnattendPath" -Value ' 2'
1711 | Add-Content -Path "$UnattendPath" -Value (' cmd /C wmic useraccount' `
1712 | + " where 'Name=`"$FullName`"' set PasswordExpires=false")
1713 | Add-Content -Path "$UnattendPath" -Value ' '
1714 | }
1715 | Add-Content -Path "$UnattendPath" -Value ' '
1716 | Add-Content -Path "$UnattendPath" -Value ' '
1717 | Add-Content -Path "$UnattendPath" -Value ' '
1718 | Add-Content -Path "$UnattendPath" -Value ''
1719 |
1720 | Write-Host -Object ('生成的应答文件位置: ' + $UnattendPath) -ForegroundColor Green
1721 | Write-Host -Object ''
1722 | if ($Interactive) {
1723 | Read-Host -Prompt '按回车键关闭此窗口'
1724 | }
1725 |
--------------------------------------------------------------------------------
/build.cmd:
--------------------------------------------------------------------------------
1 | PowerShell -NoProfile -ExecutionPolicy Bypass -File "%~dp0build.ps1"
2 |
--------------------------------------------------------------------------------
/build.ps1:
--------------------------------------------------------------------------------
1 | Clear-Host
2 |
3 | Set-Location -Path $PSScriptRoot
4 |
5 | $ProductJsonPath = "$PSScriptRoot\product.json"
6 |
7 | if (!(Test-Path -Path $ProductJsonPath -PathType Leaf)) {
8 | Write-Warning -Message ("$ProductJsonPath 不存在")
9 | [System.Environment]::Exit(0)
10 | }
11 |
12 | $ProductInfo = $null
13 | try {
14 | $ProductInfo = Get-Content -Path $ProductJsonPath | ConvertFrom-Json
15 | }
16 | catch {
17 | Write-Warning -Message ("$ProductJsonPath 解析失败")
18 | [System.Environment]::Exit(0)
19 | }
20 | if (!$ProductInfo -or $ProductInfo -isNot [PSCustomObject]) {
21 | Write-Warning -Message ("$ProductJsonPath 解析失败")
22 | [System.Environment]::Exit(0)
23 | }
24 |
25 | $Version = $ProductInfo.'version'
26 | if (!$Version) {
27 | Write-Warning -Message ("$ProductJsonPath 不存在 version 信息")
28 | [System.Environment]::Exit(0)
29 | }
30 |
31 | $ProjectName = $ProductInfo.'name'
32 | if (!$ProjectName) {
33 | Write-Warning -Message ("$ProductJsonPath 不存在 name 信息")
34 | [System.Environment]::Exit(0)
35 | }
36 |
37 | $Files = $ProductInfo.'files'
38 | if (!$Files -or $Files -isNot [System.Array] -or $Files.Count -le 0) {
39 | Write-Warning -Message ("$ProductJsonPath 不存在 files 信息")
40 | [System.Environment]::Exit(0)
41 | }
42 |
43 | $CopyFiles = @()
44 | foreach ($File in $Files) {
45 | $CopyFiles += "$PSScriptRoot\$File"
46 | }
47 |
48 | $Output = 'target'
49 | $OutputPath = "$PSScriptRoot\$Output"
50 | $OutputProjectPath = "$OutputPath\${ProjectName}"
51 | $OutputFileName = "${ProjectName}_v$Version"
52 | $ZipFilePath = "$OutputPath\$OutputFileName.zip"
53 | $Sha256FilePath = "$OutputPath\$OutputFileName.sha256"
54 |
55 | if (Test-Path -Path $OutputPath -PathType Container) {
56 | Remove-Item -Path $OutputPath -Recurse -Force
57 | }
58 |
59 | New-Item -Path $OutputProjectPath -ItemType Directory -Force | Out-Null
60 |
61 | Copy-Item -Path $CopyFiles -Destination $OutputProjectPath -Force -Recurse
62 |
63 | Compress-Archive -Path $OutputProjectPath -DestinationPath $ZipFilePath -Force
64 |
65 | $Hash = Get-FileHash -Path $ZipFilePath -Algorithm SHA256
66 |
67 | $Checksum = $Hash.Hash + " $OutputFileName.zip"
68 |
69 | Add-Content -Path $Sha256FilePath -Value $Checksum
70 |
71 | Write-Host -Object ''
72 | Write-Host -Object ('Path: ' + $Hash.Path)
73 | Write-Host -Object ''
74 | Write-Host -Object ('SHA256: ' + $Hash.Hash)
75 | Write-Host -Object ''
76 | Read-Host -Prompt '按回车键关闭此窗口'
77 |
--------------------------------------------------------------------------------
/product.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "UnattendTool",
3 | "author": "dsx42",
4 | "license": "GPL-3.0",
5 | "home": "https://github.com/dsx42/UnattendTool",
6 | "version": "2024.9.21",
7 | "files": [
8 | "UnattendTool.cmd",
9 | "UnattendTool.ps1",
10 | "product.json",
11 | "LICENSE",
12 | "README.md"
13 | ]
14 | }
--------------------------------------------------------------------------------