[
  {
    "path": ".gitattributes",
    "content": "# MAS export-ignore\r\n# LICENSE export-ignore\r\n# README.md export-ignore\r\n# .gitattributes export-ignore\r\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "MAS/All-In-One-Version-KL/MAS_AIO.cmd",
    "content": "@::Please stop false-flagging this script over and over. This is the 3rd time I've had to update the script to deal with the false positives.\r\n@::Nothing in this script is malicious and it is used by thousands of people *daily*.\r\n@::Is a real person even the one deciding to flag this or is it Copilot told to flag anything it decides not to like?\r\n@::If a campaign is using this script as a cover, please flag parts of the campaign instead of the script. This isn't the first time we experienced collateral damage due to campaigns completely unrelated to us.\r\n@::If you disagree that MAS is not malicious, we would appreciate if you contacted us to explain what constitutes MAS as \"Sonbokli\" and we'll look into it. Thank you. \r\n@set masver=3.10\r\n@setlocal DisableDelayedExpansion\r\n@echo off\r\n\r\n\r\n\r\n::  For command line switches, check m{}assgrave{dot}dev/command_line_switches\r\n::  If you want to better understand script, read from separate files version. \r\n\r\n\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\nset re1=\r\nset re2=\r\nset \"_cmdf=%~f0\"\r\nfor %%# in (%*) do (\r\nif /i \"%%#\"==\"re1\" set re1=1\r\nif /i \"%%#\"==\"re2\" set re2=1\r\nif /i \"%%#\"==\"-qedit\" (set re1=1&set re2=1)\r\n)\r\n\r\n:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows\r\n:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\Sysnative\\cmd.exe if not defined re1 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\Sysnative\\cmd.exe /c \"\"!_cmdf!\" %* re1\"\r\nexit /b\r\n)\r\n\r\n:: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\SysArm32\\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\SysArm32\\cmd.exe /c \"\"!_cmdf!\" %* re2\"\r\nexit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset \"blank=\"\r\nset \"mas=ht%blank%tps%blank%://m%blank%ass%blank%grave.dev/\"\r\nset \"github=ht%blank%tps%blank%://github.com/m%blank%assgra%blank%vel/Micro%blank%soft-Acti%blank%vation-Scripts\"\r\nset \"selfgit=ht%blank%tps%blank%://git.acti%blank%vated.win/Micr%blank%osoft-Act%blank%ivation-Scripts\"\r\n\r\n::  Check if Null service is working, it's important for the batch script\r\n\r\nsc query Null | find /i \"RUNNING\"\r\nif %errorlevel% NEQ 0 (\r\necho:\r\necho Null service is not running, script may crash...\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%fix_service\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20\r\n)\r\ncls\r\n\r\n::  Check LF line ending\r\n\r\npushd \"%~dp0\"\r\n>nul findstr /v \"$\" \"%~nx0\" && (\r\necho:\r\necho Error - Script either has LF line ending issue or an empty line at the end of the script is missing.\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20 >nul\r\npopd\r\nexit /b\r\n)\r\npopd\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\ntitle  Microsoft_Activation_Scripts %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args set _args=%_args:re1=%\r\nif defined _args set _args=%_args:re2=%\r\nif defined _args (\r\nfor %%A in (%_args%) do (\r\nif /i \"%%A\"==\"-el\"                    set _elev=1\r\n)\r\n)\r\n\r\nif defined _args echo \"%_args%\" | find /i \"/\" >nul && set _unattended=1\r\n\r\n::========================================================================================================================================\r\n\r\nset \"nul1=1>nul\"\r\nset \"nul2=2>nul\"\r\nset \"nul6=2^>nul\"\r\nset \"nul=>nul 2>&1\"\r\n\r\ncall :dk_setvar\r\n\r\nif %winbuild% EQU 1 (\r\n%eline%\r\necho Failed to detect Windows build number.\r\necho:\r\nsetlocal EnableDelayedExpansion\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\nif exist \"%Systemdrive%\\Users\\WDAGUtilityAccount\" (\r\nsc query gcs | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Windows Sandbox detected; activation is not supported.\r\necho The script cannot run due to missing licensing components. Aborting...\r\necho:\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 6001 (\r\n%nceline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho MAS only supports Windows Vista/7/8/8.1/10/11 and their Server equivalents.\r\nif %winbuild% EQU 6000 (\r\necho:\r\necho Windows Vista RTM is not supported because Powershell cannot be installed.\r\necho Upgrade to Windows Vista SP1 or SP2.\r\n)\r\ngoto dk_done\r\n)\r\n\r\nif %winbuild% LSS 7600 if not exist \"%SysPath%\\WindowsPowerShell\\v1.0\\Modules\" (\r\n%nceline%\r\nif not exist %ps% (\r\necho PowerShell is not installed in your system.\r\n)\r\necho Install PowerShell 2.0 using the following URL.\r\necho:\r\necho https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\nif %_unattended%==0 start https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix special character limitations in path name\r\n\r\nset \"_work=%~dp0\"\r\nif \"%_work:~-1%\"==\"\\\" set \"_work=%_work:~0,-1%\"\r\n\r\nset \"_batf=%~f0\"\r\nset \"_batp=%_batf:'=''%\"\r\n\r\nset _PSarg=\"\"\"%~f0\"\"\" -el %_args%\r\nset _PSarg=%_PSarg:'=''%\r\n\r\nset \"_ttemp=%userprofile%\\AppData\\Local\\Temp\"\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\necho \"!_batf!\" | find /i \"!_ttemp!\" %nul1% && (\r\nif /i not \"!_work!\"==\"!_ttemp!\" (\r\n%eline%\r\necho The script was launched from the temp folder.\r\necho You are most likely running the script directly from the archive file.\r\necho:\r\necho Extract the archive file and launch the script from the extracted folder.\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Elevate script as admin and pass arguments and preventing loop\r\n\r\n%nul1% fltmc || (\r\nif not defined _elev %psc% \"start cmd.exe -arg '/c \\\"!_PSarg!\\\"' -verb runas\" && exit /b\r\n%eline%\r\necho This script needs admin rights.\r\necho Right click on this script and select 'Run as administrator'.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check PowerShell\r\n\r\n::pstst $ExecutionContext.SessionState.LanguageMode :pstst\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"if ($PSVersionTable.PSEdition -ne 'Core') {$f=[System.IO.File]::ReadAllText('!_batp!') -split ':pstst';. ([scriptblock]::Create($f[1]))}\" %nul6%') do (set tstresult=%%a)\r\n\r\nif /i not \"%tstresult%\"==\"FullLanguage\" (\r\n%eline%\r\nfor /f \"delims=\" %%a in ('%psc% \"$ExecutionContext.SessionState.LanguageMode\" %nul6%') do (set tstresult2=%%a)\r\necho Test 1 - %tstresult%\r\necho Test 2 - !tstresult2!\r\necho:\r\n\r\nREM check LanguageMode\r\n\r\necho: !tstresult2! | findstr /i \"ConstrainedLanguage RestrictedLanguage NoLanguage\" %nul1% && (\r\necho FullLanguage mode not found in PowerShell. Aborting...\r\necho If you have applied restrictions on Powershell then undo those changes.\r\nset fixes=%fixes% %mas%fix_powershell\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_powershell\"\r\ngoto dk_done\r\n)\r\n\r\nREM check Powershell core version\r\n\r\ncmd /c \"%psc% \"$PSVersionTable.PSEdition\"\" | find /i \"Core\" %nul1% && (\r\necho Windows Powershell is needed for MAS but it seems to be replaced with Powershell core. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n\r\nREM check for Mal-ware that may cause issues with Powershell\r\n\r\nfor /r \"%ProgramFiles%\\\" %%f in (secureboot.exe) do if exist \"%%f\" (\r\necho \"%%f\"\r\necho Mal%blank%ware found, PowerShell is not working properly.\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\ngoto dk_done\r\n)\r\n\r\nREM check if .NET is working properly\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\ncmd /c \"%psc% \"\"try {[System.AppDomain]::CurrentDomain.GetAssemblies(); [System.Math]::Sqrt(144)} catch {Exit 3}\"\"\" %nul%\r\nif !errorlevel!==3 (\r\necho Windows Powershell failed to load .NET command. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nREM check antivirus and other errors\r\n\r\necho PowerShell is not working properly. Aborting...\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\necho:\r\necho Your antivirus software might be blocking the script.\r\necho:\r\nsc query sense | find /i \"RUNNING\" %nul% && (\r\necho Installed Antivirus - Microsoft Defender for Endpoint\r\n)\r\ncmd /c \"%psc% \"\"$av = Get-WmiObject -Namespace root\\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { $n += $i.displayName }; if ($n) { Write-Host ('Installed Antivirus - ' + ($n -join ', '))}\"\"\"\r\n)\r\n\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Disable QuickEdit and launch from conhost.exe to avoid Terminal app\r\n\r\nif %winbuild% GEQ 17763 (\r\nset terminal=1\r\n) else (\r\nset terminal=\r\n)\r\n\r\n::  Check if script is running in Terminal app\r\n\r\nif defined terminal (\r\nset lines=0\r\nfor /f \"skip=3 tokens=* delims=\" %%A in ('mode con') do if \"!lines!\"==\"0\" (\r\nfor %%B in (%%A) do set lines=%%B\r\n)\r\nif !lines! GEQ 100 set terminal=\r\n)\r\n\r\nif %_unattended%==1 goto :skipQE\r\nfor %%# in (%_args%) do (if /i \"%%#\"==\"-qedit\" goto :skipQE)\r\n\r\n::  Relaunch to disable QuickEdit in the current session and use conhost.exe instead of the Terminal app\r\n::  This code disables QuickEdit for the current cmd.exe session without making permanent registry changes\r\n::  It is included because clicking on the script window can pause execution, causing confusion that the script has stopped due to an error\r\n\r\nset resetQE=1\r\nreg query HKCU\\Console /v QuickEdit %nul2% | find /i \"0x0\" %nul1% && set resetQE=0\r\nreg add HKCU\\Console /v QuickEdit /t REG_DWORD /d 0 /f %nul1%\r\n\r\nif defined terminal (\r\nstart conhost.exe \"!_batf!\" %_args% -qedit\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n) else if %resetQE% EQU 1 (\r\nstart cmd.exe /c \"\"!_batf!\" %_args% -qedit\"\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n)\r\n\r\n:skipQE\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check for updates\r\n\r\nset -=\r\nset old=\r\nset pingp=\r\nset upver=%masver:.=%\r\n\r\nfor %%A in (\r\nactiv%-%ated.win\r\nmass%-%grave.dev\r\n) do if not defined pingp (\r\nfor /f \"delims=[] tokens=2\" %%B in ('ping -n 1 %%A') do (\r\nif not \"%%B\"==\"\" (set old=1& set pingp=1)\r\nfor /f \"delims=[] tokens=2\" %%C in ('ping -n 1 updatecheck%upver%.%%A') do (\r\nif not \"%%C\"==\"\" set old=\r\n)\r\n)\r\n)\r\n\r\nif defined old (\r\necho ________________________________________________\r\n%eline%\r\necho Your version of MAS [%masver%] is outdated.\r\necho ________________________________________________\r\necho:\r\nif not %_unattended%==1 (\r\necho [1] Get Latest MAS\r\necho [0] Continue Anyway\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 rem\r\nif !errorlevel!==1 (start %selfgit% & start %github% & start %mas% & exit /b)\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nif not exist \"%SystemRoot%\\Temp\\\" mkdir \"%SystemRoot%\\Temp\" %nul%\r\n\r\n::  Run script with parameters in unattended mode\r\n\r\nset _elev=\r\nif defined _args echo \"%_args%\" | find /i \"/S\" %nul% && (set \"_silent=%nul%\") || (set _silent=)\r\nif defined _args echo \"%_args%\" | find /i \"/\" %nul% && (\r\necho \"%_args%\" | find /i \"/HWID\"   %nul% && (setlocal & cls & (call :HWIDActivation    %_args% %_silent%) & endlocal)\r\necho \"%_args%\" | find /i \"/Z-\"     %nul% && (setlocal & cls & (call :TSforgeActivation %_args% %_silent%) & endlocal)\r\necho \"%_args%\" | find /i \"/K-\"     %nul% && (setlocal & cls & (call :KMSActivation     %_args% %_silent%) & endlocal)\r\necho \"%_args%\" | find /i \"/Ohook\"  %nul% && (setlocal & cls & (call :OhookActivation   %_args% %_silent%) & endlocal)\r\nexit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nsetlocal DisableDelayedExpansion\r\n\r\n::  Check desktop location\r\n\r\nset desktop=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" /v Desktop') do call set \"desktop=%%b\"\r\nif not defined desktop for /f \"delims=\" %%a in ('%psc% \"& {write-host $([Environment]::GetFolderPath('Desktop'))}\"') do call set \"desktop=%%a\"\r\nset \"_pdesk=%desktop:'=''%\"\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\nif not defined desktop (\r\n%eline%\r\necho Unable to detect Desktop location, aborting...\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:MainMenu\r\n\r\ncls\r\ncolor 07\r\ntitle  Microsoft %blank%Activation %blank%Scripts %masver%\r\nif not defined terminal mode 76, 34\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" set _serexist=1\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" set _evalexist=1\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-EnterpriseS*dition~*.mum\" set _ltscexist=1\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-EnterpriseSN*dition~*.mum\" set _ltscnexist=1\r\n\r\nif %winbuild% GEQ 10240 if not defined _serexist if not defined _evalexist set _hwidgo=1\r\nif %winbuild% GTR 14393 if defined _ltscnexist set _hwidgo=\r\nif not defined _hwidgo set _tsforgego=1\r\n\r\nset _ohookgo=1\r\nif %winbuild% GEQ 9200 (\r\nif %winbuild% LSS 10240 set _ohookgo=\r\nif %winbuild% GEQ 19041 if %winbuild% LEQ 19045 set _ohookgo=\r\nif defined _serexist set _ohookgo=\r\nif defined _evalexist set _ohookgo=\r\nif defined _ltscexist set _ohookgo=\r\nreg query HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration /v ProductReleaseIds %nul2% | find /i \"O365\" %nul% && set _ohookgo=1\r\nreg query HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\\ClickToRun\\Configuration /v ProductReleaseIds %nul2% | find /i \"O365\" %nul% && set _ohookgo=1\r\n)\r\nif not defined _ohookgo set _tsforgego=1\r\n\r\necho:\r\necho:\r\necho:\r\nif %winbuild% GEQ 10240 if %winbuild% LEQ 19045 if not defined _serexist if not defined _evalexist if not defined _ltscexist (\r\ncall :dk_color2 %_Green% \"       Tip:\" %_White% \" To activate ESU updates after W10 EOL, use TSforge option.\"\r\n)\r\necho:\r\necho:\r\necho:       ______________________________________________________________\r\necho:\r\necho:                 Activation Methods:\r\necho:\r\nif defined _hwidgo (\r\ncall :dk_color3 %_White% \"             [1] \" %_Green% \"HWID\" %_White% \"                - Windows\"\r\n) else (\r\necho:             [1] HWID                - Windows\r\n)\r\nif defined _ohookgo (\r\ncall :dk_color3 %_White% \"             [2] \" %_Green% \"Ohook\" %_White% \"               - Office\"\r\n) else (\r\necho:             [2] Ohook               - Office\r\n)\r\nif defined _tsforgego (\r\ncall :dk_color3 %_White% \"             [3] \" %_Green% \"TSforge\" %_White% \"             - Windows / Office / ESU\"\r\n) else (\r\necho:             [3] TSforge             - Windows / Office / ESU\r\n)\r\necho:             [4] Online KMS          - Windows / Office\r\necho:             __________________________________________________ \r\necho:\r\necho:             [5] Check Activation Status\r\necho:             [6] Change Windows Edition\r\necho:             [7] Change Office Edition\r\necho:             __________________________________________________      \r\necho:\r\necho:             [8] Troubleshoot\r\necho:             [E] Extras\r\necho:             [H] Help\r\necho:             [0] Exit\r\necho:       ______________________________________________________________\r\necho:\r\ncall :dk_color2 %_White% \"         \" %_Green% \"Choose a menu option using your keyboard [1,2,3...E,H,0] :\"\r\nchoice /C:12345678EH0 /N\r\nset _erl=%errorlevel%\r\n\r\nif %_erl%==11 exit /b\r\nif %_erl%==10 (start %selfgit% & start %github% & start %mas%troubleshoot & goto :MainMenu)\r\nif %_erl%==9 goto :Extras\r\nif %_erl%==8 setlocal & call :troubleshoot      & cls & endlocal & goto :MainMenu\r\nif %_erl%==7 setlocal & call :change_offedition & cls & endlocal & goto :MainMenu\r\nif %_erl%==6 setlocal & call :change_winedition & cls & endlocal & goto :MainMenu\r\nif %_erl%==5 setlocal & call :check_actstatus   & cls & endlocal & goto :MainMenu\r\nif %_erl%==4 setlocal & call :KMSActivation     & cls & endlocal & goto :MainMenu\r\nif %_erl%==3 setlocal & call :TSforgeActivation & cls & endlocal & goto :MainMenu\r\nif %_erl%==2 setlocal & call :OhookActivation   & cls & endlocal & goto :MainMenu\r\nif %_erl%==1 setlocal & call :HWIDActivation    & cls & endlocal & goto :MainMenu\r\ngoto :MainMenu\r\n\r\n:dk_color3\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[%~3%~4%esc%[%~5%~6%esc%[0m\r\n) else (\r\n%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'-NoNewline; write-host -back '%7' -fore '%8' '%9'\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:Extras\r\n\r\ncls\r\ntitle  Extras\r\nif not defined terminal mode 76, 30\r\necho:\r\necho:\r\necho:\r\necho:\r\necho:\r\necho:           ______________________________________________________\r\necho:           \r\necho:                [1] Extract $OEM$ Folder\r\necho:                  \r\necho:                [2] Download Genuine Windows / Office \r\necho:                ____________________________________________      \r\necho:                                                                          \r\necho:                [0] Go to Main Menu\r\necho:           ______________________________________________________\r\necho:\r\ncall :dk_color2 %_White% \"             \" %_Green% \"Choose a menu option using your keyboard [1,2,0] :\"\r\nchoice /C:120 /N\r\nset _erl=%errorlevel%\r\n\r\nif %_erl%==3 goto :MainMenu\r\nif %_erl%==2 start %mas%genuine-installation-media & goto :Extras\r\nif %_erl%==1 goto :Extract$OEM$\r\ngoto :Extras\r\n\r\n::========================================================================================================================================\r\n\r\n:Extract$OEM$\r\n\r\ncls\r\ntitle  Extract $OEM$ Folder\r\nif not defined terminal mode 76, 30\r\n\r\nif exist \"!desktop!\\$OEM$\\\" (\r\n%eline%\r\necho $OEM$ folder already exists on the Desktop.\r\necho _____________________________________________________\r\necho:\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\ngoto :Extras\r\n)\r\n\r\n:Extract$OEM$2\r\n\r\ncls\r\ntitle  Extract $OEM$ Folder\r\nif not defined terminal mode 78, 30\r\necho:\r\necho:\r\necho:\r\necho:\r\necho:                     Extract $OEM$ folder on the desktop           \r\necho:         ____________________________________________________________\r\necho:\r\necho:            [1] HWID       [Windows]\r\necho:            [2] Ohook      [Office]\r\necho:            [3] TSforge    [Windows / ESU / Office]\r\necho:            [4] Online KMS [Windows / Office]\r\necho:\r\necho:            [5] HWID       [Windows] ^+ Ohook [Office]\r\necho:            [6] HWID       [Windows] ^+ Ohook [Office] ^+ TSforge [ESU]\r\necho:            [7] TSforge    [Windows / ESU] ^+ Ohook [Office]\r\necho:\r\ncall :dk_color2 %_White% \"            [R] \" %_Green% \"ReadMe\"\r\necho:            [0] Go Back\r\necho:         ____________________________________________________________\r\necho:  \r\ncall :dk_color2 %_White% \"             \" %_Green% \"Choose a menu option using your keyboard :\"\r\nchoice /C:1234567R0 /N\r\nset _erl=%errorlevel%\r\n\r\nif %_erl%==9 goto:Extras\r\nif %_erl%==8 start %mas%oem-folder &goto:Extract$OEM$2\r\nif %_erl%==7 (set \"_oem=TSforge [Windows / ESU] + Ohook [Office]\" & set \"para=/Z-Windows /Z-ESU /Ohook\" &goto:Extract$OEM$3)\r\nif %_erl%==6 (set \"_oem=HWID [Windows] + Ohook [Office] + TSforge [ESU]\" & set \"para=/HWID /Ohook /Z-ESU\" &goto:Extract$OEM$3)\r\nif %_erl%==5 (set \"_oem=HWID [Windows] + Ohook [Office]\" & set \"para=/HWID /Ohook\" &goto:Extract$OEM$3)\r\nif %_erl%==4 (set \"_oem=Online KMS\" & set \"para=/K-WindowsOffice\" &goto:Extract$OEM$3)\r\nif %_erl%==3 (set \"_oem=TSforge\" & set \"para=/Z-WindowsESUOffice\" &goto:Extract$OEM$3)\r\nif %_erl%==2 (set \"_oem=Ohook\" & set \"para=/Ohook\" &goto:Extract$OEM$3)\r\nif %_erl%==1 (set \"_oem=HWID\" & set \"para=/HWID\" &goto:Extract$OEM$3)\r\ngoto :Extract$OEM$2\r\n\r\n::========================================================================================================================================\r\n\r\n:Extract$OEM$3\r\n\r\ncls\r\nset \"_dir=!desktop!\\$OEM$\\$$\\Setup\\Scripts\"\r\nmd \"!_dir!\\\"\r\n\r\n:: Add random data on top to create unique file which helps in avoiding AV's detections\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!'); [io.file]::WriteAllText('!_pdesk!\\$OEM$\\$$\\Setup\\Scripts\\MAS_AIO.cmd', '@::RANDOM-' + [Guid]::NewGuid().Guid + [Environment]::NewLine + $f, [System.Text.Encoding]::ASCII)\"\r\n\r\n(\r\necho @echo off\r\necho fltmc ^>nul ^|^| exit /b\r\necho call \"%%~dp0MAS_AIO.cmd\" %para%\r\necho cd \\\r\necho ^(goto^) 2^>nul ^& ^(if \"%%~dp0\"==\"%%SystemRoot%%\\Setup\\Scripts\\\" rd /s /q \"%%~dp0\"^)\r\n)>\"!_dir!\\SetupComplete.cmd\"\r\n\r\nset _error=\r\nif not exist \"!_dir!\\MAS_AIO.cmd\" set _error=1\r\nif not exist \"!_dir!\\SetupComplete.cmd\" set _error=1\r\n\r\nif defined _error (\r\n%eline%\r\necho The script failed to create the $OEM$ folder.\r\nif exist \"!desktop!\\$OEM$\\.*\" rmdir /s /q \"!desktop!\\$OEM$\\\" %nul%\r\n) else (\r\necho:\r\ncall :dk_color %Blue% \"%_oem%\"\r\ncall :dk_color %Green% \"$OEM$ folder was successfully created on your Desktop.\"\r\n)\r\necho ___________________________________________________________________\r\necho:\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\ngoto Extras\r\n\r\n:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n\r\n:HWIDActivation\r\n\r\n::  To activate, run the script with \"/HWID\" parameter or change 0 to 1 in below line\r\nset _act=0\r\n\r\n::  To disable changing edition if current edition doesn't support HWID activation, change the value to 1 from 0 or run the script with \"/HWID-NoEditionChange\" parameter\r\nset _NoEditionChange=0\r\n\r\n::  If value is changed in above lines or parameter is used then script will run in unattended mode\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\ntitle  HWID Activation %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args (\r\nfor %%A in (%_args%) do (\r\nif /i \"%%A\"==\"/HWID\"                  set _act=1\r\nif /i \"%%A\"==\"/HWID-NoEditionChange\"  set _NoEditionChange=1\r\nif /i \"%%A\"==\"-el\"                    set _elev=1\r\n)\r\n)\r\n\r\nfor %%A in (%_act% %_NoEditionChange%) do (if \"%%A\"==\"1\" set _unattended=1)\r\n\r\n::========================================================================================================================================\r\n\r\nif %winbuild% LSS 10240 (\r\n%eline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho HWID Activation is only supported on Windows 10/11.\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu.\"\r\ngoto dk_done\r\n)\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" (\r\n%eline%\r\necho HWID Activation is not supported on Windows Server.\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu.\"\r\ngoto dk_done\r\n)\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\nif not defined terminal (\r\nmode 110, 34\r\nif exist \"%SysPath%\\spp\\store_test\\\" mode 134, 34\r\n)\r\ntitle  HWID Activation %masver%\r\n\r\necho:\r\necho Initializing...\r\ncall :dk_chkmal\r\n\r\nfor %%# in (\r\nsppsvc.exe\r\nClipUp.exe\r\n) do (\r\nif not exist %SysPath%\\%%# (\r\n%eline%\r\necho [%SysPath%\\%%#] file is missing, aborting...\r\necho:\r\nif not defined results (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options.\"\r\ncall :dk_color %Blue% \"After that, restart system and try activation again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If it still shows the same error, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_ckeckwmic\r\ncall :dk_checksku\r\ncall :dk_product\r\ncall :dk_sppissue\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check if system is permanently activated or not\r\n\r\ncall :dk_checkperm\r\nif defined _perm (\r\ncls\r\necho ___________________________________________________________________________________________\r\necho:\r\ncall :dk_color2 %_White% \"     \" %Green% \"%winos% is already permanently activated.\"\r\necho ___________________________________________________________________________________________\r\nif %_unattended%==1 goto dk_done\r\necho:\r\nchoice /C:10 /N /M \">    [1] Activate Anyway [0] %_exitmsg% : \"\r\nif errorlevel 2 exit /b\r\n)\r\ncls\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Evaluation version\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Eval\" %nul1% && (\r\n%eline%\r\necho [%winos% ^| %winbuild%]\r\necho:\r\necho Evaluation editions cannot be activated outside of their evaluation period.\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu to reset evaluation period.\"\r\nset fixes=%fixes% %mas%evaluation_editions\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%evaluation_editions\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset error=\r\n\r\ncls\r\necho:\r\ncall :dk_showosinfo\r\n\r\n::  Check Internet connection\r\n\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)\r\n)\r\n\r\nif defined _int (\r\necho Checking Internet Connection            [Connected%ping_f%]\r\n) else (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Internet Connection            [Not Connected]\"\r\ncall :dk_color %Blue% \"Internet is required for HWID activation.\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\necho Initiating Diagnostic Tests...\r\n\r\nset \"_serv=ClipSVC wlidsvc sppsvc KeyIso LicenseManager Winmgmt\"\r\n\r\n::  Client License Service (ClipSVC)\r\n::  Microsoft Account Sign-in Assistant\r\n::  Software Protection\r\n::  CNG Key Isolation\r\n::  Windows License Manager Service\r\n::  Windows Management Instrumentation\r\n\r\ncall :dk_errorcheck\r\n\r\n::========================================================================================================================================\r\n\r\n::  Detect Key\r\n\r\nset key=\r\nset altkey=\r\nset changekey=\r\nset altapplist=\r\nset altedition=\r\nset notworking=\r\n\r\ncall :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\nif defined allapps call :hwiddata key\r\nif not defined key (\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getactivationid\\:.*';. ([scriptblock]::Create($f[1]))\"') do (set altapplist=%%a)\r\nif defined altapplist call :hwiddata key\r\n)\r\n\r\nif defined notworking call :hwidfallback\r\nif not defined key call :hwidfallback\r\n\r\nif defined altkey (set key=%altkey%&set changekey=1&set notworking=)\r\n\r\nif defined notworking if defined notfoundaltactID (\r\ncall :dk_color %Red% \"Checking Alternate Edition For HWID     [%altedition% Activation ID Not Found]\"\r\n)\r\n\r\nif not defined key (\r\n%eline%\r\necho [%winos% ^| %winbuild% ^| SKU:%osSKU%]\r\nif not defined skunotfound (\r\necho This product does not support HWID activation.\r\necho Make sure you are using the latest version of the script.\r\necho If you are, then try TSforge activation option from the main menu.\r\nset fixes=%fixes% %mas%\r\necho %mas%\r\n) else (\r\necho Required license files not found in %SysPath%\\spp\\tokens\\skus\\\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\necho:\r\ngoto dk_done\r\n)\r\n\r\nif defined notworking set error=1\r\n\r\n::========================================================================================================================================\r\n\r\n::  Install key\r\n\r\necho:\r\nif defined changekey (\r\ncall :dk_color %Blue% \"[%altedition%] edition product key will be used to enable HWID activation.\"\r\necho:\r\n)\r\n\r\nif defined winsub (\r\ncall :dk_color %Blue% \"Windows Subscription [SKU ID-%slcSKU%] detected. Script will activate base edition [SKU ID-%regSKU%].\"\r\necho:\r\n)\r\n\r\nset generickey=1\r\ncall :dk_inskey \"[%key%]\"\r\n\r\n::========================================================================================================================================\r\n\r\n::  Change Windows region to USA to avoid activation issues as Windows store license is not available in many countries \r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKCU\\Control Panel\\International\\Geo\" /v Name %nul6%') do set \"name=%%b\"\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKCU\\Control Panel\\International\\Geo\" /v Nation %nul6%') do set \"nation=%%b\"\r\n\r\n::  Skip changing region in top countries\r\n\r\nset regionchange=1\r\nfor %%# in (US CN IN BR DE JP GB FR MX ID IT PK TR KR CA ES AU NG VN PL PH NL EG AR TH CO SA TW MY CL) do if /i \"%name%\"==\"%%#\" set regionchange=\r\n\r\nif defined regionchange (\r\n%psc% \"Set-WinHomeLocation -GeoId 244\" %nul%\r\nif !errorlevel! EQU 0 (\r\necho Changing Windows Region To USA          [Successful] [Script will change it back]\r\n) else (\r\ncall :dk_color %Red% \"Changing Windows Region To USA          [Failed]\"\r\n)\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\n::  Generate GenuineTicket.xml and apply\r\n::  In some cases clipup -v -o method fails and in some cases service restart method fails as well\r\n::  To maximize success rate and get better error details, script will install tickets two times (service restart + clipup -v -o)\r\n\r\nset \"tdir=%ProgramData%\\Microsoft\\Windows\\ClipSVC\\GenuineTicket\"\r\nif not exist \"%tdir%\\\" md \"%tdir%\\\" %nul%\r\n\r\nif exist \"%tdir%\\Genuine*\" del /f /q \"%tdir%\\Genuine*\" %nul%\r\nif exist \"%tdir%\\*.xml\" del /f /q \"%tdir%\\*.xml\" %nul%\r\nif exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\Install\\Migration\\*\" del /f /q \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\Install\\Migration\\*\" %nul%\r\n\r\ncall :hwiddata ticket\r\n\r\ncopy /y /b \"%tdir%\\GenuineTicket\" \"%tdir%\\GenuineTicket.xml\" %nul%\r\n\r\nif not exist \"%tdir%\\GenuineTicket.xml\" (\r\ncall :dk_color %Red% \"Generating GenuineTicket.xml            [Failed, aborting...]\"\r\necho [%encoded%]\r\nif exist \"%tdir%\\Genuine*\" del /f /q \"%tdir%\\Genuine*\" %nul%\r\ngoto :dl_final\r\n) else (\r\necho Generating GenuineTicket.xml            [Successful]\r\n)\r\n\r\nset \"_xmlexist=if exist \"%tdir%\\GenuineTicket.xml\"\"\r\n\r\n%_xmlexist% (\r\n%psc% \"Start-Job { Restart-Service ClipSVC } | Wait-Job -Timeout 20 | Out-Null\"\r\n%_xmlexist% timeout /t 2 %nul%\r\n%_xmlexist% timeout /t 2 %nul%\r\n\r\n%_xmlexist% (\r\nset error=1\r\nif exist \"%tdir%\\*.xml\" del /f /q \"%tdir%\\*.xml\" %nul%\r\ncall :dk_color %Gray% \"Installing GenuineTicket.xml            [Failed with ClipSVC service restart, wait...]\"\r\n)\r\n)\r\n\r\ncopy /y /b \"%tdir%\\GenuineTicket\" \"%tdir%\\GenuineTicket.xml\" %nul%\r\nclipup -v -o\r\n\r\nset rebuildinfo=\r\n\r\nif not exist %ProgramData%\\Microsoft\\Windows\\ClipSVC\\tokens.dat (\r\nset error=1\r\nset rebuildinfo=1\r\ncall :dk_color %Red% \"Checking ClipSVC tokens.dat             [Not Found]\"\r\n)\r\n\r\n%_xmlexist% (\r\nset error=1\r\nset rebuildinfo=1\r\ncall :dk_color %Red% \"Installing GenuineTicket.xml            [Failed With clipup -v -o]\"\r\n)\r\n\r\nif exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\Install\\Migration\\*.xml\" (\r\nset error=1\r\nset rebuildinfo=1\r\ncall :dk_color %Red% \"Checking Ticket Migration               [Failed]\"\r\n)\r\n\r\nif not defined altapplist if not defined showfix if defined rebuildinfo (\r\nset showfix=1\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\n\r\nif exist \"%tdir%\\Genuine*\" del /f /q \"%tdir%\\Genuine*\" %nul%\r\n\r\n::==========================================================================================================================================\r\n\r\ncall :dk_product\r\n\r\necho:\r\necho Activating...\r\n\r\ncall :dk_act\r\ncall :dk_checkperm\r\nif defined _perm (\r\necho:\r\ncall :dk_color %Green% \"%winos% is permanently activated with a digital license.\"\r\ngoto :dl_final\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\n::  Clear store ID related registry to fix activation if Internet is connected\r\n\r\nset \"_ident=HKU\\S-1-5-19\\SOFTWARE\\Microsoft\\IdentityCRL\"\r\n\r\nif %keyerror% EQU 0 if defined _int (\r\nreg delete \"%_ident%\" /f %nul%\r\nfor %%# in (wlidsvc LicenseManager sppsvc) do (%psc% \"Start-Job { Restart-Service %%# } | Wait-Job -Timeout 20 | Out-Null\")\r\ncall :dk_refresh\r\ncall :dk_act\r\ncall :dk_checkperm\r\n\r\nreg query \"%_ident%\" %nul% || (\r\nset error=1\r\necho:\r\ncall :dk_color %Red% \"Generating New IdentityCRL Registry     [Failed] [%_ident%]\"\r\n)\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\n::  Extended licensing servers tests incase error not found and activation failed\r\n\r\nif %keyerror% EQU 0 if not defined _perm if defined _int (\r\nipconfig /flushdns %nul%\r\nset \"tls=[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;\"\r\n\r\nfor %%# in (\r\nlicensing.mp.microsoft.com/v7.0/licenses/content\r\nlogin.live.com/ppsecure/deviceaddcredential.srf\r\npurchase.mp.microsoft.com/v7.0/users/me/orders\r\n) do if not defined resfail (\r\n%psc% \"try { !tls! irm https://%%# -Method POST } catch { if ($_.Exception.Response -eq $null) { Write-Host \"\"\"\"[%%#] $($_.Exception.Message)\"\"\"\" -ForegroundColor Red -BackgroundColor Black; exit 3 } }\"\r\nif !errorlevel!==3 set resfail=1\r\n)\r\n)\r\n\r\nif defined resfail (\r\nset error=1\r\nfor %%# in (\r\nlive.com\r\nmicrosoft.com\r\nlogin.live.com\r\npurchase.mp.microsoft.com\r\nlicensing.mp.microsoft.com\r\n) do (\r\nfindstr /i \"%%#\" \"%SysPath%\\drivers\\etc\\hosts\" %nul1% && set \"hosfail= [%%# Blocked in Hosts]\"\r\n)\r\ncall :dk_color %Red% \"Checking Licensing Servers              [Failed to Connect]!hosfail!\"\r\nset fixes=%fixes% %mas%licensing-servers-issue\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%licensing-servers-issue\"\r\necho:\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\n::  Windows update and store block check\r\n\r\nif %keyerror% EQU 0 if not defined _perm if defined _int (\r\n\r\nreg query \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\" /v DisableWindowsUpdateAccess %nul2% | find /i \"0x1\" %nul% && set wublock=1\r\nreg query \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\" /v DoNotConnectToWindowsUpdateInternetLocations %nul2% | find /i \"0x1\" %nul% && set wublock=1\r\nif defined wublock (\r\ncall :dk_color %Red% \"Checking Update Blocker In Registry     [Found]\"\r\ncall :dk_color %Blue% \"HWID activation needs working Windows updates, if you have used any tool to block updates, undo it.\"\r\necho:\r\n)\r\n\r\nreg query \"HKLM\\SOFTWARE\\Policies\\Microsoft\\WindowsStore\" /v DisableStoreApps %nul2% | find /i \"0x1\" %nul% && (\r\nset storeblock=1\r\ncall :dk_color %Red% \"Checking Store Blocker In Registry      [Found]\"\r\ncall :dk_color %Blue% \"If you have used any tool to block Store, undo it.\"\r\necho:\r\n)\r\n\r\nset wcount=0\r\nfor %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type ServiceSidType RequiredPrivileges FailureActions) do (\r\nreg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\wuauserv /v %%G %nul% || (set wucorrupt=1&set /a wcount+=1)\r\n)\r\n\r\nfor %%G in (Parameters Security) do (\r\nreg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\wuauserv\\%%G %nul% || (set wucorrupt=1&set /a wcount+=1)\r\n)\r\n\r\nif defined wucorrupt (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Windows Update Registry        [Corruption Found]\"\r\nif !wcount! GTR 2 (\r\ncall :dk_color %Red% \"Windows seems to be infected with Mal%w%ware.\"\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\necho:\r\n) else (\r\ncall :dk_color %Blue% \"HWID activation needs working Windows updates, if you have used any tool to block updates, undo it.\"\r\necho:\r\n)\r\n) else (\r\n%psc% \"Start-Job { Start-Service wuauserv } | Wait-Job -Timeout 20 | Out-Null\"\r\nsc query wuauserv | find /i \"RUNNING\" %nul% || (\r\nset error=1\r\nset wuerror=1\r\nsc start wuauserv %nul%\r\ncall :dk_color %Red% \"Starting Windows Update Service         [Failed] [!errorlevel!]\"\r\ncall :dk_color %Blue% \"HWID activation needs working Windows updates, if you have used any tool to block updates, undo it.\"\r\necho:\r\n)\r\n)\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\n::  Check Internet related error codes\r\n\r\nif %keyerror% EQU 0 if not defined _perm if defined _int (\r\nif not defined wucorrupt if not defined wublock if not defined wuerror if not defined storeblock if not defined resfail (\r\necho \"%error_code%\" | findstr /i \"0x80072e 0x80072f 0x800704cf 0x87e10bcf 0x800705b4\" %nul% && (\r\ncall :dk_color %Red% \"Checking Internet Issues                [Found] %error_code%\"\r\nset fixes=%fixes% %mas%licensing-servers-issue\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%licensing-servers-issue\"\r\necho:\r\n)\r\n)\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\necho:\r\nif defined _perm (\r\ncall :dk_color %Green% \"%winos% is permanently activated with a digital license.\"\r\n) else (\r\ncall :dk_color %Red% \"Activation Failed %error_code%\"\r\nif defined notworking (\r\ncall :dk_color %Blue% \"At the time of writing, HWID Activation is not supported for this product.\"\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu instead.\"\r\n) else (\r\nif not defined error call :dk_color %Blue% \"%_fixmsg%\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:dl_final\r\n\r\necho:\r\n\r\nif defined regionchange (\r\n%psc% \"Set-WinHomeLocation -GeoId %nation%\" %nul%\r\nif !errorlevel! EQU 0 (\r\necho Restoring Windows Region                [Successful]\r\n) else (\r\ncall :dk_color %Red% \"Restoring Windows Region                [Failed] [%name% - %nation%]\"\r\n)\r\n)\r\n\r\nREM if %osSKU%==175 call :dk_color %Red% \"%winos% does not support activation on non-azure platforms.\"\r\n\r\n::  Trigger reevaluation of SPP's Scheduled Tasks\r\n\r\nif defined _perm (\r\ncall :dk_reeval %nul%\r\n)\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set variables\r\n\r\n:dk_setvar\r\n\r\nset ps=%SysPath%\\WindowsPowerShell\\v1.0\\powershell.exe\r\nset psc=%ps% -nop -c\r\nset winbuild=1\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset _NCS=1\r\nif %winbuild% LSS 10586 set _NCS=0\r\nif %winbuild% GEQ 10586 reg query \"HKCU\\Console\" /v ForceV2 %nul2% | find /i \"0x0\" %nul1% && (set _NCS=0)\r\n\r\necho \"%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%\" | find /i \"ARM64\" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)\r\n\r\nif %_NCS% EQU 1 (\r\nfor /F %%a in ('echo prompt $E ^| cmd') do set \"esc=%%a\"\r\nset     \"Red=\"41;97m\"\"\r\nset    \"Gray=\"100;97m\"\"\r\nset   \"Green=\"42;97m\"\"\r\nset    \"Blue=\"44;97m\"\"\r\nset   \"White=\"107;91m\"\"\r\nset    \"_Red=\"40;91m\"\"\r\nset  \"_White=\"40;37m\"\"\r\nset  \"_Green=\"40;92m\"\"\r\nset \"_Yellow=\"40;93m\"\"\r\n) else (\r\nset     \"Red=\"Red\" \"white\"\"\r\nset    \"Gray=\"Darkgray\" \"white\"\"\r\nset   \"Green=\"DarkGreen\" \"white\"\"\r\nset    \"Blue=\"Blue\" \"white\"\"\r\nset   \"White=\"White\" \"Red\"\"\r\nset    \"_Red=\"Black\" \"Red\"\"\r\nset  \"_White=\"Black\" \"Gray\"\"\r\nset  \"_Green=\"Black\" \"Green\"\"\r\nset \"_Yellow=\"Black\" \"Yellow\"\"\r\n)\r\n\r\nset \"nceline=echo: &echo ==== ERROR ==== &echo:\"\r\nset \"eline=echo: &call :dk_color %Red% \"==== ERROR ====\" &echo:\"\r\nif %~z0 GEQ 200000 (\r\nset \"_exitmsg=Go back\"\r\nset \"_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option.\"\r\n) else (\r\nset \"_exitmsg=Exit\"\r\nset \"_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option.\"\r\n)\r\nexit /b\r\n\r\n::  Show OS info\r\n\r\n:dk_showosinfo\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\" /v PROCESSOR_ARCHITECTURE') do set osarch=%%b\r\n\r\nfor /f \"tokens=6-7 delims=[]. \" %%i in ('ver') do if not \"%%j\"==\"\" (\r\nset fullbuild=%%i.%%j\r\n) else (\r\nfor /f \"tokens=3\" %%G in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR\" %nul6%') do if not errorlevel 1 set /a \"UBR=%%G\"\r\nfor /f \"skip=2 tokens=3,4 delims=. \" %%G in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildLabEx') do (\r\nif defined UBR (set \"fullbuild=%%G.!UBR!\") else (set \"fullbuild=%%G.%%H\")\r\n)\r\n)\r\n\r\necho Checking OS Info                        [%winos% ^| %fullbuild% ^| %osarch%]\r\nexit /b\r\n\r\n::  Check SKU value\r\n\r\n:dk_checksku\r\n\r\ncall :dk_reflection\r\n\r\nset osSKU=\r\nset slcSKU=\r\nset wmiSKU=\r\nset regSKU=\r\nset winsub=\r\n\r\nif %winbuild% GEQ 14393 (set info=Kernel-BrandingInfo) else (set info=Kernel-ProductInfo)\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3);\r\nset d1=%d1% $Sku = 0; [void]$TypeBuilder.CreateType()::SLGetWindowsInformationDWORD('%info%', [ref]$Sku); $Sku\r\nfor /f \"delims=\" %%s in ('\"%psc% %d1%\"') do if not errorlevel 1 (set slcSKU=%%s)\r\nset slcSKU=%slcSKU: =%\r\nif \"%slcSKU%\"==\"0\" set slcSKU=\r\nfor /f \"tokens=* delims=0123456789\" %%a in (\"%slcSKU%\") do (if not \"[%%a]\"==\"[]\" set slcSKU=)\r\n\r\nfor /f \"tokens=3 delims=.\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions\" /v OSProductPfn %nul6%') do set \"regSKU=%%a\"\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%a in ('\"wmic Path Win32_OperatingSystem Get OperatingSystemSKU /format:LIST\" %nul6%') do if not errorlevel 1 set \"wmiSKU=%%a\"\r\nif %_wmic% EQU 0 for /f \"tokens=1\" %%a in ('%psc% \"([WMI]'Win32_OperatingSystem=@').OperatingSystemSKU\" %nul6%') do if not errorlevel 1 set \"wmiSKU=%%a\"\r\n\r\nif %winbuild% GEQ 15063 %psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':winsubstatus\\:.*';. ([scriptblock]::Create($f[1]))\" %nul2% | find /i \"Subscription_is_activated\" %nul% && (\r\nif defined regSKU if defined slcSKU if not \"%regSKU%\"==\"%slcSKU%\" (\r\nset winsub=1\r\nset osSKU=%regSKU%\r\n)\r\n)\r\n\r\nif not defined osSKU set osSKU=%slcSKU%\r\nif not defined osSKU set osSKU=%wmiSKU%\r\nif not defined osSKU set osSKU=%regSKU%\r\nexit /b\r\n\r\n::  Get Windows Subscription status\r\n\r\n:winsubstatus:\r\n$DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(6, 1).DefineDynamicModule(4).DefineType(2)\r\n[void]$DM.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n$m = [System.Runtime.InteropServices.Marshal]\r\n$p = $m::AllocHGlobal(12)\r\n$r = $DM.CreateType()::ClipGetSubscriptionStatus([ref]$p)\r\nif ($r -eq 0) {\r\n  $enabled = $m::ReadInt32($p)\r\n  if ($enabled -ge 1) {\r\n    $state = $m::ReadInt32($p, 8)\r\n    if ($state -eq 1) {\r\n        \"Subscription_is_activated.\"\r\n    }\r\n  }\r\n}\r\n:winsubstatus:\r\n\r\n::  Get Windows permanent activation status\r\n\r\n:dk_checkperm\r\n\r\nif %_wmic% EQU 1 wmic path %spp% where (LicenseStatus='1' and GracePeriodRemaining='0' and PartialProductKey is not NULL AND LicenseDependsOn is NULL) get Name /value %nul2% | findstr /i \"Windows\" %nul1% && set _perm=1||set _perm=\r\nif %_wmic% EQU 0 %psc% \"(([WMISEARCHER]'SELECT Name FROM %spp% WHERE LicenseStatus=1 AND GracePeriodRemaining=0 AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Name | %% {echo ('Name='+$_)}\" %nul2% | findstr /i \"Windows\" %nul1% && set _perm=1||set _perm=\r\nexit /b\r\n\r\n::  Refresh license status\r\n\r\n:dk_refresh\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call RefreshLicenseStatus %nul%\r\nif %_wmic% EQU 0 %psc% \"$null=(([WMICLASS]'%sps%').GetInstances()).RefreshLicenseStatus()\" %nul%\r\nexit /b\r\n\r\n::  Install Key\r\n\r\n:dk_inskey\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey=\"%key%\" %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset keyerror=%errorlevel%\r\ncmd /c exit /b %keyerror%\r\nif %keyerror% NEQ 0 set \"keyerror=[0x%=ExitCode%]\"\r\n\r\nif defined generickey (set \"keyecho=Installing Generic Product Key         \") else (set \"keyecho=Installing Product Key                 \")\r\nif %keyerror% EQU 0 (\r\nif %sps%==SoftwareLicensingService call :dk_refresh\r\necho %keyecho% %~1 [Successful]\r\n) else (\r\ncall :dk_color %Red% \"%keyecho% %~1 [Failed] %keyerror%\"\r\nif not defined showfix (\r\nif defined altapplist call :dk_color %Red% \"Activation ID not found for this key.\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\nset showfix=1\r\n)\r\nset error=1\r\n)\r\n\r\nset generickey=\r\nexit /b\r\n\r\n::  Activation command\r\n\r\n:dk_act\r\n\r\nset error_code=\r\nif %_wmic% EQU 1 wmic path %spp% where \"ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL\" call Activate %nul%\r\nif %_wmic% EQU 0 %psc% \"try {$null=(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Activate(); exit 0} catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset error_code=%errorlevel%\r\ncmd /c exit /b %error_code%\r\nif %error_code% NEQ 0 (set \"error_code=[Error Code: 0x%=ExitCode%]\") else (set error_code=)\r\nexit /b\r\n\r\n::  Get all products Activation IDs\r\n\r\n:dk_actids\r\n\r\nset allapps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1') get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1''').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined allapps (call set \"allapps=!allapps! %%a\") else (call set \"allapps=%%a\"))\r\n\r\n::  Check potential script crash issue when user manually installs way too many licenses for Office (length limit in variable)\r\n\r\nif defined allapps if %1==0ff1ce15-a989-479d-af46-f275c6370663 (\r\nset len=0\r\necho:!allapps!> \"!_ttemp!\\chklen\"\r\nfor %%A in (\"!_ttemp!\\chklen\") do (set len=%%~zA)\r\ndel \"!_ttemp!\\chklen\" %nul%\r\n\r\nif !len! GTR 6000 (\r\n%eline%\r\necho Too many licenses are installed, the script may crash.\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ntimeout /t 30\r\n)\r\n)\r\nexit /b\r\n\r\n::  Get installed products Activation IDs\r\n\r\n:dk_actid\r\n\r\nset apps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1' and PartialProductKey is not null) get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1'' AND PartialProductKey IS NOT NULL').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined apps (call set \"apps=!apps! %%a\") else (call set \"apps=%%a\"))\r\nexit /b\r\n\r\n::  Trigger reevaluation, it helps in updating SPP tasks\r\n\r\n:dk_reeval\r\n\r\nif %winbuild% LSS 7600 exit /b\r\n\r\n::  This key is left by the system in rearm process and sppsvc sometimes fails to delete it, it causes issues in working of the Scheduled Tasks of SPP\r\n\r\nset \"ruleskey=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\PersistedSystemState\"\r\nreg delete \"%ruleskey%\" /v \"State\" /f %nul%\r\nreg delete \"%ruleskey%\" /v \"SuppressRulesEngine\" /f %nul%\r\n\r\nset r1=$TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);\r\nset r2=%r1% [void]$TB.DefinePInvokeMethod('SLpTriggerServiceWorker', 'sppc.dll', 22, 1, [Int32], @([UInt32], [IntPtr], [String], [UInt32]), 1, 3);\r\nset d1=%r2% [void]$TB.CreateType()::SLpTriggerServiceWorker(0, 0, 'reeval', 0)\r\n%psc% \"Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null; %d1%\"\r\nexit /b\r\n\r\n::  Get Activation IDs from licensing files if not found through WMI\r\n\r\n:getactivationid:\r\n$folderPath = \"$env:SysPath\\spp\\tokens\\skus\"\r\n$files = Get-ChildItem -Path $folderPath -Recurse -Filter \"*.xrm-ms\"\r\n$guids = @()\r\nforeach ($file in $files) {\r\n    $content = Get-Content -Path $file.FullName -Raw\r\n    $matches = [regex]::Matches($content, 'name=\"productSkuId\">\\{([0-9a-fA-F\\-]+)\\}')\r\n    foreach ($match in $matches) {\r\n        $guids += $match.Groups[1].Value\r\n    }\r\n}\r\n$guids = $guids | Select-Object -Unique\r\n$guidsString = $guids -join \" \"\r\n$guidsString\r\n:getactivationid:\r\n\r\n::  Install License files using Powershell/WMI instead of slmgr.vbs\r\n\r\n:xrm:\r\nfunction InstallLicenseFile($Lsc) {\r\n    try {\r\n        $null = $sls.InstallLicense([IO.File]::ReadAllText($Lsc))\r\n    } catch {\r\n        $host.SetShouldExit($_.Exception.HResult)\r\n    }\r\n}\r\nfunction InstallLicenseArr($Str) {\r\n    $a = $Str -split ';'\r\n    ForEach ($x in $a) {InstallLicenseFile \"$x\"}\r\n}\r\nfunction InstallLicenseDir($Loc) {\r\n\tGet-ChildItem $Loc -Recurse -Filter *.xrm-ms | ForEach-Object {InstallLicenseFile $_.FullName}\r\n}\r\nfunction ReinstallLicenses() {\r\n\t$Paths = @(\"$env:SysPath\\oem\", \"$env:SysPath\\licensing\", \"$env:SysPath\\spp\\tokens\")\r\n\tforeach ($Path in $Paths) {\r\n    if (Test-Path $Path) { InstallLicenseDir \"$Path\" }\r\n\t}\r\n}\r\n:xrm:\r\n\r\n::  Check wmic.exe\r\n\r\n:dk_ckeckwmic\r\n\r\nif %winbuild% LSS 9200 (set _wmic=1&exit /b)\r\nset _wmic=0\r\nfor %%# in (wmic.exe) do @if not \"%%~$PATH:#\"==\"\" (\r\ncmd /c \"wmic path Win32_ComputerSystem get CreationClassName /value\" %nul2% | find /i \"computersystem\" %nul1% && set _wmic=1\r\n)\r\nexit /b\r\n\r\n::  Show info for potential script stuck scenario\r\n\r\n:dk_sppissue\r\n\r\nsc start %_slser% %nul%\r\nset spperror=%errorlevel%\r\n\r\nif %spperror% NEQ 1056 if %spperror% NEQ 0 (\r\n%eline%\r\necho sc start %_slser% [Error Code: %spperror%]\r\nif %spperror% EQU 1053 (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\ncall :dk_color %Blue% \"If it still does not work, go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\n)\r\n)\r\n\r\necho:\r\n%psc% \"$job = Start-Job { (Get-WmiObject -Query 'SELECT * FROM %sps%').Version }; if (-not (Wait-Job $job -Timeout 30)) {write-host '%_slser% is not working correctly. Check this webpage for help - %mas%troubleshoot'}\"\r\nexit /b\r\n\r\n::  Get Product name (WMI/REG methods are not reliable in all conditions, hence winbrand.dll method is used)\r\n\r\n:dk_product\r\n\r\nset d1=%ref% $meth = $TypeBuilder.DefinePInvokeMethod('BrandingFormatString', 'winbrand.dll', 'Public, Static', 1, [String], @([String]), 1, 3);\r\nset d1=%d1% $meth.SetImplementationFlags(128); $TypeBuilder.CreateType()::BrandingFormatString('%%WINDOWS_LONG%%') -replace [string][char]0xa9, '' -replace [string][char]0xae, '' -replace [string][char]0x2122, ''\r\n\r\nset winos=\r\nfor /f \"delims=\" %%s in ('\"%psc% %d1%\"') do if not errorlevel 1 (set winos=%%s)\r\necho \"%winos%\" | find /i \"Windows\" %nul1% || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v ProductName %nul6%') do set \"winos=%%b\"\r\nif %winbuild% GEQ 22000 (\r\nset winos=!winos:Windows 10=Windows 11!\r\n)\r\n)\r\n\r\nif not defined winsub exit /b\r\n\r\n::  Check base edition product name if Windows subscription license is found\r\n\r\nfor %%# in (pkeyhelper.dll) do @if \"%%~$PATH:#\"==\"\" exit /b\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionNameFromId', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [IntPtr].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionNameFromId(%regSKU%, [ref]$out);$s=[Runtime.InteropServices.Marshal]::PtrToStringUni($out); $s\r\n\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (\r\nif %winbuild% GEQ 22000 (\r\nset winos=Windows 11 %%a\r\n) else (\r\nset winos=Windows 10 %%a\r\n)\r\n)\r\nexit /b\r\n\r\n::  Common lines used in PowerShell reflection code\r\n\r\n:dk_reflection\r\n\r\nset ref=$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1);\r\nset ref=%ref% $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False);\r\nset ref=%ref% $TypeBuilder = $ModuleBuilder.DefineType(0);\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_chkmal\r\n\r\n::  Many users unknowingly download mal-ware by using activators found through Google search.\r\n::  This code aims to notify users that their system has been affected by mal-ware.\r\n\r\nset w=\r\nset results=\r\nif exist \"%ProgramFiles%\\KM%w%Spico\" set pupfound= KM%w%Spico \r\nif not defined pupfound (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\" /f Path /s | find /i \"AutoPico\" %nul% && set pupfound= KM%w%Spico \r\n)\r\n\r\nset hcount=0\r\nfor %%# in (avira.com kaspersky.com virustotal.com mcafee.com) do (\r\nfind /i \"%%#\" %SysPath%\\drivers\\etc\\hosts %nul% && set /a hcount+=1)\r\nif %hcount%==4 set \"results=[Antivirus URLs are blocked in hosts]\"\r\n\r\nsc start %_slser% %nul%\r\necho \"%errorlevel%\" | findstr \"577 225\" %nul% && (\r\nset \"results=%results%[Likely File Infector]\"\r\n) || (\r\nif not exist %SysPath%\\%_slexe% if not exist %SysPath%\\alg.exe (set \"results=%results%[Likely File Infector]\")\r\n)\r\n\r\nif not \"%results%%pupfound%\"==\"\" (\r\nif defined pupfound call :dk_color %Gray% \"Checking PUP Activators                 [Found%pupfound%]\"\r\nif defined results call :dk_color %Red% \"Checking Probable Mal%w%ware Infection...\"\r\nif defined results (call :dk_color %Red% \"%results%\"&set showfix=1)\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\necho:\r\n)\r\n\r\n::  Remove the scheduled task of R@1n-KMS (old version) that runs the activation command every minute, as it leads to high CPU usage.\r\n\r\nif exist %SysPath%\\Tasks\\R@1n-KMS (\r\nfor /f %%A in ('dir /b /a:-d %SysPath%\\Tasks\\R@1n-KMS %nul6%') do (schtasks /delete /tn \\R@1n-KMS\\%%A /f %nul%)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_errorcheck\r\n\r\nset showfix=\r\ncall :dk_chkmal\r\n\r\n::==============================\r\n\r\n::  Check Sandboxing\r\n\r\nsc query Null %nul% || (\r\ncall :dk_color %Red% \"Checking Sandboxing                     [Found, script may not work properly]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"If you are using any third-party antivirus, check if it is blocking the script.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WinPE mode\r\n\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinPE\" /v InstRoot %nul% && (\r\n\r\ncall :dk_color %Red% \"Checking WinPE                          [Found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"WinPE mode found. Reboot the system and run in normal mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Safe mode\r\n\r\nif defined safeboot_option (\r\ncall :dk_color %Red% \"Checking Boot Mode                      [%safeboot_option%]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Safe mode found. Reboot the system and run in normal mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check ImageState\r\n::  https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-setup-states\r\n\r\nfor /f \"skip=2 tokens=2*\" %%A in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State\" /v ImageState') do (set imagestate=%%B)\r\n\r\nif /i not \"%imagestate%\"==\"IMAGE_STATE_COMPLETE\" (\r\ncall :dk_color %Gray% \"Checking Windows Setup State            [%imagestate%]\"\r\necho \"%imagestate%\" | find /i \"RESEAL\" %nul% && (\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"You need to run it in normal mode in case you are running it in Audit Mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\necho \"%imagestate%\" | find /i \"UNDEPLOYABLE\" %nul% && (\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If the activation fails, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check corrupt services\r\n\r\nset serv_cor=\r\nfor %%# in (%_serv%) do (\r\nset _regcorr=\r\nset _corrupt=\r\nsc start %%# %nul%\r\nif !errorlevel! EQU 1060 set _corrupt=1\r\nsc query %%# %nul% || set _corrupt=1\r\nfor %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type) do if not defined _regcorr (\r\nreg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%# /v %%G %nul% || (set _corrupt=1&set _regcorr=-RegistryError)\r\n)\r\n\r\nif defined _corrupt (if defined serv_cor (set \"serv_cor=!serv_cor! %%#!_regcorr!\") else (set \"serv_cor=%%#!_regcorr!\"))\r\n)\r\n\r\nif defined serv_cor (\r\ncall :dk_color %Red% \"Checking Corrupt Services               [%serv_cor%]\"\r\n\r\nif not defined showfix (\r\necho:\r\nif /i \"%serv_cor%\"==\"sppsvc-RegistryError\" (\r\nset fixes=%fixes% %mas%fix_service\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_service\"\r\n) else (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\necho:\r\n)\r\n\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check disabled services\r\n\r\nset serv_ste=\r\nfor %%# in (%_serv%) do (\r\nsc start %%# %nul%\r\nif !errorlevel! EQU 1058 (if defined serv_ste (set \"serv_ste=!serv_ste! %%#\") else (set \"serv_ste=%%#\"))\r\n)\r\n\r\n::  Change disabled services startup type to default\r\n\r\nset serv_csts=\r\nset serv_cste=\r\n\r\nif defined serv_ste (\r\nfor %%# in (%serv_ste%) do (\r\nif /i %%#==ClipSVC          (reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%#\" /v \"Start\" /t REG_DWORD /d \"3\" /f %nul% & sc config %%# start= demand %nul%)\r\nif /i %%#==wlidsvc          sc config %%# start= demand %nul%\r\nif /i %%#==sppsvc           (reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%#\" /v \"Start\" /t REG_DWORD /d \"2\" /f %nul% & sc config %%# start= delayed-auto %nul%)\r\nif /i %%#==SLsvc            sc config %%# start= auto %nul%\r\nif /i %%#==KeyIso           sc config %%# start= demand %nul%\r\nif /i %%#==LicenseManager   sc config %%# start= demand %nul%\r\nif /i %%#==Winmgmt          sc config %%# start= auto %nul%\r\nif !errorlevel!==0 (\r\nif defined serv_csts (set \"serv_csts=!serv_csts! %%#\") else (set \"serv_csts=%%#\")\r\n) else (\r\nif defined serv_cste (set \"serv_cste=!serv_cste! %%#\") else (set \"serv_cste=%%#\")\r\n)\r\n)\r\n)\r\n\r\nif defined serv_csts call :dk_color %Gray% \"Enabling Disabled Services              [Successful] [%serv_csts%]\"\r\n\r\nif defined serv_cste (\r\ncall :dk_color %Red% \"Enabling Disabled Services              [Failed] [%serv_cste%]\"\r\n\r\nif not defined showfix (\r\necho:\r\necho %serv_cste% | findstr /i \"ClipSVC sppsvc\" %nul% && (\r\necho A registry fix has been applied to enable the disabled service.\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\n) || (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\necho:\r\n)\r\n\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check if the services are able to run or not\r\n::  Workarounds are added to get correct status and error code because sc query doesn't output correct results in some conditions\r\n\r\nset serv_e=\r\nfor %%# in (%_serv%) do (\r\nset errorcode=\r\nset checkerror=\r\n\r\nsc query %%# | find /i \"RUNNING\" %nul% || (\r\n%psc% \"Start-Job { Start-Service %%# } | Wait-Job -Timeout 20 | Out-Null\"\r\nset errorcode=!errorlevel!\r\nsc query %%# | find /i \"RUNNING\" %nul% || set checkerror=1\r\n)\r\n\r\nsc start %%# %nul%\r\nif !errorlevel! NEQ 1056 if !errorlevel! NEQ 0 (set errorcode=!errorlevel!&set checkerror=1)\r\nif defined checkerror if defined serv_e (set \"serv_e=!serv_e!, %%#-!errorcode!\") else (set \"serv_e=%%#-!errorcode!\")\r\n)\r\n\r\nif defined serv_e (\r\ncall :dk_color %Red% \"Starting Services                       [Failed] [%serv_e%]\"\r\n\r\nif not defined showfix (\r\nset listwospp=%_serv:sppsvc=%\r\necho %serv_e% | findstr /i \"!listwospp!\" %nul% && (\r\nset showfix=1\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and run the script again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If service error is still not fixed, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\n)\r\nset error=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WMI\r\n\r\nset wmifailed=\r\nif %_wmic% EQU 1 wmic path Win32_ComputerSystem get CreationClassName /value %nul2% | find /i \"computersystem\" %nul1%\r\nif %_wmic% EQU 0 %psc% \"Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName\" %nul2% | find /i \"computersystem\" %nul1%\r\n\r\nif %errorlevel% NEQ 0 set wmifailed=1\r\n\r\nif %_wmic% EQU 1 wmic path %sps% get Version %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=([WMISEARCHER]'SELECT * FROM %sps%').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset error_code=%errorlevel%\r\ncmd /c exit /b %error_code%\r\nif %error_code% NEQ 0 set \"error_code=0x%=ExitCode%\"\r\n\r\necho \"%error_code%\" | findstr /i \"0x800410 0x800440 0x80131501\" %nul1% && set wmifailed=1& ::  https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants\r\n\r\nif defined wmifailed (\r\ncall :dk_color %Red% \"Checking WMI                            [Not Working]\"\r\n\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WMI option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SPP Registry Key\r\n\r\nif %winbuild% GEQ 7600 reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Plugins\\Objects\\msft:rm/algorithm/hwid/4.0\" /f ba02fed39662 /d %nul% || (\r\ncall :dk_color %Red% \"Checking SPP Registry Key               [Incorrect ModuleId Found] [Most likely caused by gaming spoofers]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%issues_due_to_gaming_spoofers\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%issues_due_to_gaming_spoofers\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check TokenStore registry key\r\n\r\nset tokenstore=\r\nif %winbuild% GEQ 7600 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v TokenStore %nul6%') do call set \"tokenstore=%%b\"\r\nif %winbuild% LSS 9200 set \"tokenstore=%Systemdrive%\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareProtectionPlatform\"\r\n\r\nif %winbuild% GEQ 9200 if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store\" if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store\\2.0\" if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store_test\\2.0\" (\r\ncall :dk_color %Red% \"Checking TokenStore Registry Key        [Correct Path Not Found] [!tokenstore!]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset toerr=1\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This code creates token folder only if it's missing and sets default permission for it\r\n\r\nif %winbuild% GEQ 7600 if not defined toerr if not exist \"%tokenstore%\\\" (\r\n\r\nmkdir \"%tokenstore%\" %nul%\r\n\r\nif %winbuild% LSS 9200 set \"d=$sddl = 'O:NSG:NSD:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;NS)';\"\r\nif %winbuild% GEQ 9200 set \"d=$sddl = 'O:BAG:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;GR;;;BU)(A;;FR;;;BU)(A;OICI;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)';\"\r\nset \"d=!d! $AclObject = New-Object System.Security.AccessControl.DirectorySecurity;\"\r\nset \"d=!d! $AclObject.SetSecurityDescriptorSddlForm($sddl);\"\r\nset \"d=!d! Set-Acl -Path %tokenstore% -AclObject $AclObject;\"\r\n%psc% \"!d!\" %nul%\r\n\r\nif exist \"%tokenstore%\\\" (\r\ncall :dk_color %Gray% \"Checking SPP Token Folder               [Not Found, Created Now] [%tokenstore%\\]\"\r\n) else (\r\ncall :dk_color %Red% \"Checking SPP Token Folder               [Not Found, Failed to Create] [%tokenstore%\\]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This code checks if SPP has permission access to tokens folder and required registry keys. It's often caused by gaming spoofers.\r\n\r\nset permerror=\r\nif %winbuild% GEQ 9200 if not defined toerr if not defined ps32onArm if exist \"%tokenstore%\\\" (\r\nfor %%# in (\r\n\"%tokenstore%+FullControl\"\r\n\"HKLM:\\SYSTEM\\WPA+QueryValues, EnumerateSubKeys, WriteKey\"\r\n\"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform+SetValue\"\r\n) do for /f \"tokens=1,2 delims=+\" %%A in (%%#) do if not defined permerror (\r\n%psc% \"$acl = (Get-Acl '%%A' | fl | Out-String); if (-not ($acl -match 'NT SERVICE\\\\sppsvc Allow  %%B') -or ($acl -match 'NT SERVICE\\\\sppsvc Deny')) {Exit 2}\" %nul%\r\nif !errorlevel!==2 (\r\nif \"%%A\"==\"%tokenstore%\" (\r\nset \"permerror=Error Found In Token Folder\"\r\n) else (\r\nset \"permerror=Error Found In SPP Registries\"\r\n)\r\n)\r\n)\r\n\r\nREM  https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application\r\n\r\nif not defined permerror (\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% && (\r\nset \"pol=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\"\r\nreg query \"!pol!\" %nul% || reg add \"!pol!\" %nul%\r\n%psc% \"$netServ = (New-Object Security.Principal.SecurityIdentifier('S-1-5-20')).Translate([Security.Principal.NTAccount]).Value; $aclString = Get-Acl 'Registry::!pol!' | Format-List | Out-String; if (-not ($aclString.Contains($netServ + ' Allow  FullControl') -or $aclString.Contains('NT SERVICE\\sppsvc Allow  FullControl')) -or ($aclString.Contains('Deny'))) {Exit 3}\" %nul%\r\nif !errorlevel!==3 set \"permerror=Error Found In S-1-5-20 SPP\"\r\n)\r\n)\r\n\r\nif defined permerror (\r\ncall :dk_color %Red% \"Checking SPP Permissions                [!permerror!]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WPA Registry Errors\r\n\r\nset chkalp=\r\nset wpainfo=NotFound\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wpatest\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (set wpainfo=%%a)\r\nfor /f \"delims=0123456789\" %%i in (\"%wpainfo%\") do set chkalp=%%i\r\n\r\nif defined chkalp (\r\ncall :dk_color %Red% \"Checking WPA Registry Errors            [%wpainfo%]\"\r\nif not defined showfix (\r\necho \"%wpainfo%\" | find /i \"Error Found\" %nul% && (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\necho:\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\nset wpainfo=a\r\n)\r\n\r\nif not defined chkalp (\r\nif %wpainfo% GEQ 5000 (\r\ncall :dk_color %Gray% \"Checking WPA Registry Count             [%wpainfo%]\"\r\ncall :dk_color %Blue% \"A large number of WPA registries have been found, which may cause high CPU usage.\"\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\necho:\r\n) else (\r\necho Checking WPA Registry Count             [%wpainfo%]\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Rearm\r\n\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\PersistedTSReArmed\" %nul% && (\r\ncall :dk_color %Red% \"Checking Rearm                          [System is Rearmed]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState\" %nul% && (\r\ncall :dk_color %Red% \"Checking ClipSVC PersistedSystemState   [Found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SoftwareLicensingService\r\n\r\nif %error_code% NEQ 0 (\r\ncall :dk_color %Red% \"Checking SoftwareLicensingService       [Not Working] [%error_code%]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Activation IDs\r\n\r\ncall :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nif not defined apps (\r\n%psc% \"if (-not $env:_vis) {Start-Job { Stop-Service %_slser% -force } | Wait-Job -Timeout 20 | Out-Null}; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif not defined _vis if !errorlevel! NEQ 0 set rlicfailed=1\r\ncall :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f\r\n)\r\n\r\nif not defined apps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nif not defined apps if defined allapps if not defined notwinact (\r\ncall :dk_color %Gray% \"Checking Activation IDs                 [Key Not Installed or Act ID Not Found]\"\r\n)\r\n\r\nif not defined apps if not defined allapps (\r\ncall :dk_color %Red% \"Checking Activation IDs                 [Not found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\nif not defined showfix if defined rlicfailed (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\n\r\nif %winbuild% GEQ 7600 if exist \"%tokenstore%\\\" if not exist \"%tokenstore%\\tokens.dat\" (\r\ncall :dk_color %Red% \"Checking SPP tokens.dat                 [Not Found] [%tokenstore%\\]\"\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Eval Windows\r\n\r\nif not defined notwinact if exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Eval\" %nul1% || (\r\ncall :dk_color %Red% \"Checking Eval Packages                  [License swapping found. Non-Eval licenses are installed in Eval Windows]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"License swapping is not the right way to upgrade to the full version. Learn the correct method at the link below.\"\r\nset fixes=%fixes% %mas%evaluation_editions\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%evaluation_editions\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check HKU\\S-1-5-20\\Software registry, in some systems it's missing and that causes Windows activation problems\r\n\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% || (\r\ncall :dk_color %Red% \"Checking HKU\\S-1-5-20 Registry          [Not Found]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check license and package files for the current edition\r\n\r\nset osedition=0\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do if not errorlevel 1 (call set \"osedition=%%a\")\r\n\r\nif %osedition%==0 for /f \"skip=2 tokens=3\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul6%') do set \"osedition=%%a\"\r\n\r\n::  Workaround for an issue in builds between 1607 and 1709 where ProfessionalEducation is shown as Professional\r\n\r\nif not %osedition%==0 (\r\nif \"%osSKU%\"==\"164\" set osedition=ProfessionalEducation\r\nif \"%osSKU%\"==\"165\" set osedition=ProfessionalEducationN\r\n)\r\n\r\nif not defined notwinact (\r\nif %osedition%==0 (\r\ncall :dk_color %Red% \"Checking Edition Name                   [Not Found In Registry]\"\r\n) else (\r\nif not exist \"%SysPath%\\spp\\tokens\\skus\\%osedition%\\%osedition%*.xrm-ms\" if not exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-%osedition%\\*-%osedition%-*.xrm-ms\" if not exist \"%SysPath%\\licensing\\skus\\Security-Licensing-SLC-Component-SKU-%osedition%\\*-%osedition%-*.xrm-ms\" (\r\nset skunotfound=1\r\ncall :dk_color %Red% \"Checking License Files                  [Not Found] [%osedition%]\"\r\n)\r\nif not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*-%osedition%-*.mum\" (\r\nif not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-%osedition%Edition*.mum\" (\r\ncall :dk_color %Red% \"Checking Package Files                  [Not Found] [%osedition%]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SKU value to find if there is any difference\r\n\r\nif not defined notwinact (\r\nif %winbuild% GEQ 10240 (\r\n%nul% set /a \"sum=%slcSKU%+%regSKU%+%wmiSKU%\"\r\nset /a \"sum/=3\"\r\nif not \"!sum!\"==\"%slcSKU%\" (\r\ncall :dk_color %Gray% \"Checking SLC/WMI/REG SKU                [Difference Found - SLC:%slcSKU% WMI:%wmiSKU% Reg:%regSKU%]\"\r\n)\r\n) else (\r\n%nul% set /a \"sum=%slcSKU%+%wmiSKU%\"\r\nset /a \"sum/=2\"\r\nif not \"!sum!\"==\"%slcSKU%\" (\r\ncall :dk_color %Gray% \"Checking SLC/WMI SKU                    [Difference Found - SLC:%slcSKU% WMI:%wmiSKU%]\"\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This \"WLMS\" service was included in previous Eval editions (which were activable) to automatically shut down the system every hour after the evaluation period expired and prevent SPPSVC from stopping.\r\n\r\nsc query wlms %nul%\r\n\r\nif %errorlevel% NEQ 1060 (\r\necho Checking Eval WLMS Service              [Found]\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SPP interference in IFEO\r\n\r\nfor %%# in (SppEx%w%tComObj.exe SLsvc.exe sppsvc.exe sppsvc.exe\\PerfOptions) do (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" %nul% && (if defined _sppint (set \"_sppint=!_sppint!, %%#\") else (set \"_sppint=%%#\"))\r\n)\r\nif defined _sppint (\r\necho %_sppint% | find /i \"PerfOptions\" %nul% && (\r\ncall :dk_color %Red% \"Checking SPP Interference In IFEO       [%_sppint% - System might deactivate later]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\nset showfix=1\r\n) || (\r\necho Checking SPP In IFEO                    [%_sppint%]\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check and fix SkipRearm registry value\r\n\r\nif %winbuild% GEQ 7600 for /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"SkipRearm\" %nul6%') do if /i %%b NEQ 0x0 (\r\nreg add \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"SkipRearm\" /t REG_DWORD /d \"0\" /f %nul%\r\ncall :dk_color %Gray% \"Checking SkipRearm                      [Default 0 Value Not Found. Changing To 0]\"\r\n%psc% \"Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null\"\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SvcRestartTask status, this task helps in making sure system remains activated\r\n\r\nif %winbuild% GEQ 9200 if not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\n%psc% \"Get-WmiObject -Query 'SELECT Description FROM SoftwareLicensingProduct WHERE PartialProductKey IS NOT NULL AND LicenseDependsOn IS NULL' | Select-Object -Property Description\" %nul2% | findstr /i \"KMS_\" %nul1% || (\r\nfor /f \"delims=\" %%a in ('%psc% \"$s=New-Object -ComObject 'Schedule.Service'; $s.Connect(); $state=$s.GetFolder('\\Microsoft\\Windows\\SoftwareProtectionPlatform').GetTask('SvcRestartTask').State; @{0='Unknown';1='Disabled';2='Queued';3='Ready';4='Running'}[$state]\" %nul6%') do (set taskinfo=%%a)\r\n\r\necho !taskinfo! | find /i \"Ready\" %nul% || (\r\nreg delete \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"actionlist\" /f %nul%\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\Microsoft\\Windows\\SoftwareProtectionPlatform\\SvcRestartTask\" %nul% || set taskinfo=Removed\r\nif \"!taskinfo!\"==\"\" set \"taskinfo=Not Found\"\r\n\r\ncall :dk_color %Gray% \"Checking SvcRestartTask Status          [!taskinfo!. System might deactivate later.]\"\r\nif not defined showfix (\r\necho \"!taskinfo!\" | findstr /i \"Removed Not Found\" %nul1% && (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n) || (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and run the script again.\"\r\n)\r\necho:\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\nexit /b\r\n\r\n::  This code checks for invalid registry keys in HKLM\\SYSTEM\\WPA. This issue may appear even on healthy systems\r\n\r\n:wpatest:\r\n$wpaKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME).OpenSubKey(\"SYSTEM\\\\WPA\")\r\n$count = 0\r\nforeach ($subkeyName in $wpaKey.GetSubKeyNames()) {\r\n    if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n        $count++\r\n    }\r\n}\r\n$osVersion = [System.Environment]::OSVersion.Version\r\n$minBuildNumber = 14393\r\nif ($osVersion.Build -ge $minBuildNumber) {\r\n    $subkeyHashTable = @{}\r\n    foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {\r\n        if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n            $keyNumber = $subkeyName -replace '.*-', ''\r\n            $subkeyHashTable[$keyNumber] = $true\r\n        }\r\n    }\r\n    for ($i=1; $i -le $count; $i++) {\r\n        if (-not $subkeyHashTable.ContainsKey(\"$i\")) {\r\n            Write-Output \"Total Keys $count. Error Found - $i key does not exist.\"\r\n\t\t\t$wpaKey.Close()\r\n\t\t\texit\r\n        }\r\n    }\r\n}\r\n$wpaKey.GetSubKeyNames() | ForEach-Object {\r\n    if ($_ -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n        if ($PSVersionTable.PSVersion.Major -lt 3) {\r\n            cmd /c \"reg query \"HKLM\\SYSTEM\\WPA\\$_\" /ve /t REG_BINARY >nul 2>&1\"\r\n\t\t\tif ($LASTEXITCODE -ne 0) {\r\n            Write-Host \"Total Keys $count. Error Found - Binary Data is corrupt.\"\r\n\t\t\t$wpaKey.Close()\r\n\t\t\texit\r\n\t\t\t}\r\n        } else {\r\n            $subkey = $wpaKey.OpenSubKey($_)\r\n            $p = $subkey.GetValueNames()\r\n            if (($p | Where-Object { $subkey.GetValueKind($_) -eq [Microsoft.Win32.RegistryValueKind]::Binary }).Count -eq 0) {\r\n                Write-Host \"Total Keys $count. Error Found - Binary Data is corrupt.\"\r\n\t\t\t\t$wpaKey.Close()\r\n\t\t\t\texit\r\n            }\r\n        }\r\n    }\r\n}\r\n$count\r\n$wpaKey.Close()\r\n:wpatest:\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_color\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3'\r\n) else if not exist %ps% (\r\necho %~3\r\n)\r\nexit /b\r\n\r\n:dk_color2\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[%~3%~4%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'\r\n) else if not exist %ps% (\r\necho %~3 %~6\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_done\r\n\r\necho:\r\nif %_unattended%==1 timeout /t 2 & exit /b\r\n\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 exit /b\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = Generic Retail/OEM/MAK Key\r\n::  3rd column = SKU ID\r\n::  4th column = Key part number\r\n::  5th column = 1 = activation is not working (at the time of writing this), 0 = activation is working\r\n::  6th column = Key Type\r\n::  7th column = WMI Edition ID (For reference only)\r\n::  8th column = Version name incase same Edition ID is used in different OS versions with different key\r\n::  Separator  = _\r\n\r\n\r\n:hwiddata\r\n\r\nset f=\r\nfor %%# in (\r\n8b351c9c-f398-4515-9900-09df49427262_XGVPP-NMH47-7TTHJ-W3FW7-8H%f%V2C___4_X19-99683_0_OEM:NONSLP_Enterprise\r\nc83cef07-6b72-4bbc-a28f-a00386872839_3V6Q6-NQXCX-V8YXR-9QCYV-QP%f%FCT__27_X19-98746_0_Volume:MAK_EnterpriseN\r\n4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T__48_X19-98841_0_____Retail_Professional\r\n9fbaf5d6-4d83-4422-870d-fdda6e5858aa_2B87N-8KFHP-DKV6R-Y2C8J-PK%f%CKT__49_X19-98859_0_____Retail_ProfessionalN\r\nf742e4ff-909d-4fe9-aacb-3231d24a0c58_4CPRK-NM3K3-X6XXQ-RXX86-WX%f%CHW__98_X19-98877_0_____Retail_CoreN\r\n1d1bac85-7365-4fea-949a-96978ec91ae0_N2434-X9D7W-8PF6X-8DV9T-8T%f%YMD__99_X19-99652_0_____Retail_CoreCountrySpecific\r\n3ae2cc14-ab2d-41f4-972f-5e20142771dc_BT79Q-G7N6G-PGBYW-4YWX6-6F%f%4BT_100_X19-99661_0_____Retail_CoreSingleLanguage\r\n2b1f36bb-c1cd-4306-bf5c-a0367c2d97d8_YTMG3-N6DKC-DKB77-7M9GH-8H%f%VX7_101_X19-98868_0_____Retail_Core\r\n2a6137f3-75c0-4f26-8e3e-d83d802865a4_XKCNC-J26Q9-KFHD2-FKTHY-KD%f%72Y_119_X19-99606_0_OEM:NONSLP_PPIPro\r\ne558417a-5123-4f6f-91e7-385c1c7ca9d4_YNMGQ-8RYV3-4PGQ3-C8XTP-7C%f%FBY_121_X19-98886_0_____Retail_Education\r\nc5198a66-e435-4432-89cf-ec777c9d0352_84NGF-MHBT6-FXBX8-QWJK7-DR%f%R8H_122_X19-98892_0_____Retail_EducationN\r\nf6e29426-a256-4316-88bf-cc5b0f95ec0c_PJB47-8PN2T-MCGDY-JTY3D-CB%f%CPV_125_X23-50331_1_Volume:MAK_EnterpriseS_Ge\r\ncce9d2de-98ee-4ce2-8113-222620c64a27_KCNVH-YKWX8-GJJB9-H9FDT-6F%f%7W2_125_X22-66075_1_Volume:MAK_EnterpriseS_VB\r\nd06934ee-5448-4fd1-964a-cd077618aa06_43TBQ-NH92J-XKTM7-KT3KK-P3%f%9PB_125_X21-83233_0_OEM:NONSLP_EnterpriseS_RS5\r\n706e0cfd-23f4-43bb-a9af-1a492b9f1302_NK96Y-D9CD8-W44CQ-R8YTK-DY%f%JWX_125_X21-05035_0_OEM:NONSLP_EnterpriseS_RS1\r\nfaa57748-75c8-40a2-b851-71ce92aa8b45_FWN7H-PF93Q-4GGP8-M8RF3-MD%f%WWW_125_X19-99617_0_OEM:NONSLP_EnterpriseS_TH\r\n3d1022d8-969f-4222-b54b-327f5a5af4c9_2DBW3-N2PJG-MVHW3-G7TDK-9H%f%KR4_126_X21-04921_0_Volume:MAK_EnterpriseSN_RS1\r\n60c243e1-f90b-4a1b-ba89-387294948fb6_NTX6B-BRYC2-K6786-F6MVQ-M7%f%V2X_126_X19-98770_0_Volume:MAK_EnterpriseSN_TH\r\n01eb852c-424d-4060-94b8-c10d799d7364_3XP6D-CRND4-DRYM2-GM84D-4G%f%G8Y_139_X23-37869_1_____Retail_ProfessionalCountrySpecific_Zn\r\neb6d346f-1c60-4643-b960-40ec31596c45_DXG7C-N36C4-C4HTG-X4T3X-2Y%f%V77_161_X21-43626_0_____Retail_ProfessionalWorkstation\r\n89e87510-ba92-45f6-8329-3afa905e3e83_WYPNQ-8C467-V2W6J-TX4WX-WT%f%2RQ_162_X21-43644_0_____Retail_ProfessionalWorkstationN\r\n62f0c100-9c53-4e02-b886-a3528ddfe7f6_8PTT6-RNW4C-6V7J2-C2D3X-MH%f%BPB_164_X21-04955_0_____Retail_ProfessionalEducation\r\n13a38698-4a49-4b9e-8e83-98fe51110953_GJTYN-HDMQY-FRR76-HVGC7-QP%f%F8P_165_X21-04956_0_____Retail_ProfessionalEducationN\r\ndf96023b-dcd9-4be2-afa0-c6c871159ebe_NJCF7-PW8QT-3324D-688JX-2Y%f%V66_175_X21-41295_0_____Retail_ServerRdsh\r\nd4ef7282-3d2c-4cf0-9976-8854e64a8d1e_V3WVW-N2PV2-CGWC3-34QGF-VM%f%J2C_178_X21-32983_0_____Retail_Cloud\r\naf5c9381-9240-417d-8d35-eb40cd03e484_NH9J3-68WK7-6FB93-4K3DF-DJ%f%4F6_179_X21-32987_0_____Retail_CloudN\r\n8ab9bdd1-1f67-4997-82d9-8878520837d9_XQQYW-NFFMW-XJPBH-K8732-CK%f%FFD_188_X21-99378_0_____OEM:DM_IoTEnterprise\r\ned655016-a9e8-4434-95d9-4345352c2552_QPM6N-7J2WJ-P88HH-P3YRH-YY%f%74H_191_X21-99682_0_OEM:NONSLP_IoTEnterpriseS_VB\r\n6c4de1b8-24bb-4c17-9a77-7b939414c298_CGK42-GYN6Y-VD22B-BX98W-J8%f%JXD_191_X23-12617_0_OEM:NONSLP_IoTEnterpriseS_Ge\r\nd4bdc678-0a4b-4a32-a5b3-aaa24c3b0f24_K9VKN-3BGWV-Y624W-MCRMQ-BH%f%DCD_202_X22-53884_0_____Retail_CloudEditionN\r\n92fb8726-92a8-4ffc-94ce-f82e07444653_KY7PN-VR6RX-83W6Y-6DDYQ-T6%f%R4W_203_X22-53847_0_____Retail_CloudEdition\r\n5a85300a-bfce-474f-ac07-a30983e3fb90_N979K-XWD77-YW3GB-HBGH6-D3%f%2MH_205_X23-15042_0_____OEM:DM_IoTEnterpriseSK\r\n80083eae-7031-4394-9e88-4901973d56fe_P8Q7T-WNK7X-PMFXY-VXHBG-RR%f%K69_206_X23-62084_0_____OEM:DM_IoTEnterpriseK\r\n1bc2140b-285b-4351-b99c-26a126104b29_TMP2N-KGFHJ-PWM6F-68KCQ-3P%f%JBP_210_X23-60513_0_____Retail_WNC\r\n) do (\r\nfor /f \"tokens=1-9 delims=_\" %%A in (\"%%#\") do (\r\n\r\nREM Detect key\r\n\r\nif %1==key if %osSKU%==%%C if not defined key (\r\necho \"!allapps! !altapplist!\" | find /i \"%%A\" %nul1% && (\r\nif %%E==1 set notworking=1\r\nset key=%%B\r\n)\r\n)\r\n\r\nREM Generate ticket\r\n\r\nif %1==ticket if \"%key%\"==\"%%B\" (\r\nset \"SessionIdStr=OSMajorVersion=5;OSMinorVersion=1;OSPlatformId=2;PP=0;Pfn=Microsoft.Windows.%%C.%%D_8wekyb3d8bbwe;PKeyIID=465145217131314304264339481117862266242033457260311819664735280;\"\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':sign\\:.*';. ([scriptblock]::Create($f[1]))\"\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:sign:\r\n$ErrorActionPreference = \"Stop\"\r\n\r\nfunction SignProperties {\r\n    param (\r\n        $Properties,\r\n        $rsa\r\n    )\r\n\r\n    $sha256 = [Security.Cryptography.SHA256]::Create()\r\n    $bytes = [Text.Encoding]::UTF8.GetBytes($Properties)\r\n    $hash = $sha256.ComputeHash($bytes)\r\n\r\n    $signature = $rsa.SignHash($hash, [Security.Cryptography.HashAlgorithmName]::SHA256, [Security.Cryptography.RSASignaturePadding]::Pkcs1)\r\n    return [Convert]::ToBase64String($signature)\r\n\r\n}\r\n\r\n[byte[]] $key = 0x07,0x02,0x00,0x00,0x00,0xA4,0x00,0x00,0x52,0x53,0x41,0x32,0x00,0x04,0x00,0x00,\r\n                0x01,0x00,0x01,0x00,0x29,0x87,0xBA,0x3F,0x52,0x90,0x57,0xD8,0x12,0x26,0x6B,0x38,\r\n                0xB2,0x3B,0xF9,0x67,0x08,0x4F,0xDD,0x8B,0xF5,0xE3,0x11,0xB8,0x61,0x3A,0x33,0x42,\r\n                0x51,0x65,0x05,0x86,0x1E,0x00,0x41,0xDE,0xC5,0xDD,0x44,0x60,0x56,0x3D,0x14,0x39,\r\n                0xB7,0x43,0x65,0xE9,0xF7,0x2B,0xA5,0xF0,0xA3,0x65,0x68,0xE9,0xE4,0x8B,0x5C,0x03,\r\n                0x2D,0x36,0xFE,0x28,0x4C,0xD1,0x3C,0x3D,0xC1,0x90,0x75,0xF9,0x6E,0x02,0xE0,0x58,\r\n                0x97,0x6A,0xCA,0x80,0x02,0x42,0x3F,0x6C,0x15,0x85,0x4D,0x83,0x23,0x6A,0x95,0x9E,\r\n                0x38,0x52,0x59,0x38,0x6A,0x99,0xF0,0xB5,0xCD,0x53,0x7E,0x08,0x7C,0xB5,0x51,0xD3,\r\n                0x8F,0xA3,0x0D,0xA0,0xFA,0x8D,0x87,0x3C,0xFC,0x59,0x21,0xD8,0x2E,0xD9,0x97,0x8B,\r\n                0x40,0x60,0xB1,0xD7,0x2B,0x0A,0x6E,0x60,0xB5,0x50,0xCC,0x3C,0xB1,0x57,0xE4,0xB7,\r\n                0xDC,0x5A,0x4D,0xE1,0x5C,0xE0,0x94,0x4C,0x5E,0x28,0xFF,0xFA,0x80,0x6A,0x13,0x53,\r\n                0x52,0xDB,0xF3,0x04,0x92,0x43,0x38,0xB9,0x1B,0xD9,0x85,0x54,0x7B,0x14,0xC7,0x89,\r\n                0x16,0x8A,0x4B,0x82,0xA1,0x08,0x02,0x99,0x23,0x48,0xDD,0x75,0x9C,0xC8,0xC1,0xCE,\r\n                0xB0,0xD7,0x1B,0xD8,0xFB,0x2D,0xA7,0x2E,0x47,0xA7,0x18,0x4B,0xF6,0x29,0x69,0x44,\r\n                0x30,0x33,0xBA,0xA7,0x1F,0xCE,0x96,0x9E,0x40,0xE1,0x43,0xF0,0xE0,0x0D,0x0A,0x32,\r\n                0xB4,0xEE,0xA1,0xC3,0x5E,0x9B,0xC7,0x7F,0xF5,0x9D,0xD8,0xF2,0x0F,0xD9,0x8F,0xAD,\r\n                0x75,0x0A,0x00,0xD5,0x25,0x43,0xF7,0xAE,0x51,0x7F,0xB7,0xDE,0xB7,0xAD,0xFB,0xCE,\r\n                0x83,0xE1,0x81,0xFF,0xDD,0xA2,0x77,0xFE,0xEB,0x27,0x1F,0x10,0xFA,0x82,0x37,0xF4,\r\n                0x7E,0xCC,0xE2,0xA1,0x58,0xC8,0xAF,0x1D,0x1A,0x81,0x31,0x6E,0xF4,0x8B,0x63,0x34,\r\n                0xF3,0x05,0x0F,0xE1,0xCC,0x15,0xDC,0xA4,0x28,0x7A,0x9E,0xEB,0x62,0xD8,0xD8,0x8C,\r\n                0x85,0xD7,0x07,0x87,0x90,0x2F,0xF7,0x1C,0x56,0x85,0x2F,0xEF,0x32,0x37,0x07,0xAB,\r\n                0xB0,0xE6,0xB5,0x02,0x19,0x35,0xAF,0xDB,0xD4,0xA2,0x9C,0x36,0x80,0xC6,0xDC,0x82,\r\n                0x08,0xE0,0xC0,0x5F,0x3C,0x59,0xAA,0x4E,0x26,0x03,0x29,0xB3,0x62,0x58,0x41,0x59,\r\n                0x3A,0x37,0x43,0x35,0xE3,0x9F,0x34,0xE2,0xA1,0x04,0x97,0x12,0x9D,0x8C,0xAD,0xF7,\r\n                0xFB,0x8C,0xA1,0xA2,0xE9,0xE4,0xEF,0xD9,0xC5,0xE5,0xDF,0x0E,0xBF,0x4A,0xE0,0x7A,\r\n                0x1E,0x10,0x50,0x58,0x63,0x51,0xE1,0xD4,0xFE,0x57,0xB0,0x9E,0xD7,0xDA,0x8C,0xED,\r\n                0x7D,0x82,0xAC,0x2F,0x25,0x58,0x0A,0x58,0xE6,0xA4,0xF4,0x57,0x4B,0xA4,0x1B,0x65,\r\n                0xB9,0x4A,0x87,0x46,0xEB,0x8C,0x0F,0x9A,0x48,0x90,0xF9,0x9F,0x76,0x69,0x03,0x72,\r\n                0x77,0xEC,0xC1,0x42,0x4C,0x87,0xDB,0x0B,0x3C,0xD4,0x74,0xEF,0xE5,0x34,0xE0,0x32,\r\n                0x45,0xB0,0xF8,0xAB,0xD5,0x26,0x21,0xD7,0xD2,0x98,0x54,0x8F,0x64,0x88,0x20,0x2B,\r\n                0x14,0xE3,0x82,0xD5,0x2A,0x4B,0x8F,0x4E,0x35,0x20,0x82,0x7E,0x1B,0xFE,0xFA,0x2C,\r\n                0x79,0x6C,0x6E,0x66,0x94,0xBB,0x0A,0xEB,0xBA,0xD9,0x70,0x61,0xE9,0x47,0xB5,0x82,\r\n                0xFC,0x18,0x3C,0x66,0x3A,0x09,0x2E,0x1F,0x61,0x74,0xCA,0xCB,0xF6,0x7A,0x52,0x37,\r\n                0x1D,0xAC,0x8D,0x63,0x69,0x84,0x8E,0xC7,0x70,0x59,0xDD,0x2D,0x91,0x1E,0xF7,0xB1,\r\n                0x56,0xED,0x7A,0x06,0x9D,0x5B,0x33,0x15,0xDD,0x31,0xD0,0xE6,0x16,0x07,0x9B,0xA5,\r\n                0x94,0x06,0x7D,0xC1,0xE9,0xD6,0xC8,0xAF,0xB4,0x1E,0x2D,0x88,0x06,0xA7,0x63,0xB8,\r\n                0xCF,0xC8,0xA2,0x6E,0x84,0xB3,0x8D,0xE5,0x47,0xE6,0x13,0x63,0x8E,0xD1,0x7F,0xD4,\r\n                0x81,0x44,0x38,0xBF\r\n\r\n$rsa = New-Object Security.Cryptography.RSACryptoServiceProvider\r\n$rsa.ImportCspBlob($key)\r\n$SessionId = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($env:SessionIdStr + [char]0))\r\n$PropertiesStr = \"OA3xOriginalProductId=;OA3xOriginalProductKey=;SessionId=$SessionId;TimeStampClient=2022-10-11T12:00:00Z\"\r\n$SignatureStr = SignProperties $PropertiesStr $rsa\r\n\r\n$xml = @\"\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?><genuineAuthorization xmlns=\"http://www.microsoft.com/DRM/SL/GenuineAuthorization/1.0\"><version>1.0</version><genuineProperties origin=\"sppclient\"><properties>$PropertiesStr</properties><signatures><signature name=\"clientLockboxKey\" method=\"rsa-sha256\">$SignatureStr</signature></signatures></genuineProperties></genuineAuthorization>\r\n\"@\r\n[System.IO.File]::WriteAllText(\"$env:ProgramData\\Microsoft\\Windows\\ClipSVC\\GenuineTicket\\GenuineTicket\", ($xml -join \"\"), [System.Text.Encoding]::ASCII)\r\n:sign:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Below code is used to get alternate edition name and key if current edition doesn't support HWID activation\r\n\r\n::  1st column = Current SKU ID\r\n::  2nd column = Current Edition Name\r\n::  3rd column = Current Edition Activation ID\r\n::  4th column = Alternate Edition Activation ID\r\n::  5th column = Alternate Edition HWID Key\r\n::  6th column = Alternate Edition Name\r\n::  Separator  = _\r\n\r\n\r\n:hwidfallback\r\n\r\nset notfoundaltactID=\r\nif %_NoEditionChange%==1 exit /b\r\n\r\nfor %%# in (\r\n125_EnterpriseS-2021_______________cce9d2de-98ee-4ce2-8113-222620c64a27_ed655016-a9e8-4434-95d9-4345352c2552_QPM6N-7J2WJ-P88HH-P3YRH-YY%f%74H_IoTEnterpriseS-2021\r\n125_EnterpriseS-2024_______________f6e29426-a256-4316-88bf-cc5b0f95ec0c_6c4de1b8-24bb-4c17-9a77-7b939414c298_CGK42-GYN6Y-VD22B-BX98W-J8%f%JXD_IoTEnterpriseS-2024\r\n138_ProfessionalSingleLanguage_____a48938aa-62fa-4966-9d44-9f04da3f72f2_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional\r\n139_ProfessionalCountrySpecific____f7af7d09-40e4-419c-a49b-eae366689ebd_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional\r\n139_ProfessionalCountrySpecific-Zn_01eb852c-424d-4060-94b8-c10d799d7364_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional\r\n) do (\r\nfor /f \"tokens=1-6 delims=_\" %%A in (\"%%#\") do if %osSKU%==%%A (\r\necho \"!allapps! !altapplist!\" | find /i \"%%C\" %nul1% && (\r\necho \"!allapps!\" | find /i \"%%D\" %nul1% && (\r\nset altkey=%%E\r\nset altedition=%%F\r\n) || (\r\nset altedition=%%F\r\nset notfoundaltactID=1\r\n)\r\n)\r\n)\r\n)\r\nexit /b\r\n\r\n:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n\r\n:OhookActivation\r\n\r\n::  To activate Office with Ohook activation, run the script with \"/Ohook\" parameter or change 0 to 1 in below line\r\nset _act=0\r\n\r\n::  To remove Ohook activation, run the script with /Ohook-Uninstall parameter or change 0 to 1 in below line\r\nset _rem=0\r\n\r\n::  If value is changed in above lines or parameter is used then script will run in unattended mode\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\ntitle  Ohook Activation %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args (\r\nfor %%A in (%_args%) do (\r\nif /i \"%%A\"==\"/Ohook\"                  set _act=1\r\nif /i \"%%A\"==\"/Ohook-Uninstall\"        set _rem=1\r\nif /i \"%%A\"==\"-el\"                     set _elev=1\r\n)\r\n)\r\n\r\nfor %%A in (%_act% %_rem%) do (if \"%%A\"==\"1\" set _unattended=1)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_rem%==1 goto :oh_uninstall\r\n\r\n:oh_menu\r\n\r\nif %_unattended%==0 (\r\ncls\r\nif not defined terminal mode 76, 25\r\ntitle  Ohook Activation %masver%\r\ncall :oh_checkapps\r\necho:\r\necho:\r\necho:\r\necho:\r\nif defined checknames (call :dk_color %_Yellow% \"                Close [!checknames!] before proceeding...\")\r\necho         ____________________________________________________________\r\necho:\r\necho                 [1] Install Ohook Office Activation\r\necho:\r\necho                 [2] Uninstall Ohook\r\necho                 ____________________________________________\r\necho:\r\necho                 [3] Download Office\r\necho:\r\necho                 [0] %_exitmsg%\r\necho         ____________________________________________________________\r\necho: \r\ncall :dk_color2 %_White% \"             \" %_Green% \"Choose a menu option using your keyboard [1,2,3,0]\"\r\nchoice /C:1230 /N\r\nset _el=!errorlevel!\r\nif !_el!==4  exit /b\r\nif !_el!==3  start %mas%genuine-installation-media &goto :oh_menu\r\nif !_el!==2  goto :oh_uninstall\r\nif !_el!==1  goto :oh_menu2\r\ngoto :oh_menu\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_menu2\r\n\r\ncls\r\nif not defined terminal (\r\nmode 140, 32\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=32;$B.Height=300;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\ntitle  Ohook Activation %masver%\r\n\r\necho:\r\necho Initializing...\r\ncall :dk_chkmal\r\n\r\nif not exist %SysPath%\\%_slexe% (\r\n%eline%\r\necho [%SysPath%\\%_slexe%] file is missing, aborting...\r\necho:\r\nif not defined results (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options.\"\r\ncall :dk_color %Blue% \"After that, restart system and try activation again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If it still shows the same error, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_reflection\r\ncall :dk_ckeckwmic\r\ncall :dk_product\r\ncall :dk_sppissue\r\n\r\n::========================================================================================================================================\r\n\r\nset error=\r\n\r\ncls\r\necho:\r\ncall :dk_showosinfo\r\n\r\n::========================================================================================================================================\r\n\r\necho Initiating Diagnostic Tests...\r\n\r\nset \"_serv=%_slser% Winmgmt\"\r\n\r\n::  Software Protection\r\n::  Windows Management Instrumentation\r\n\r\nset notwinact=1\r\nset ohookact=1\r\ncall :dk_errorcheck\r\n\r\ncall :oh_setspp\r\n\r\n::  Check unsupported office versions\r\n\r\nset o14c2r=\r\nset o16uwp=\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=Office 2010 MSI )\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=Office 2010 MSI )\r\n%nul% reg query %_68%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n%nul% reg query %_86%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n\r\nif %winbuild% GEQ 10240 (\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty InstallLocation)\" %nul6%') do (if exist \"%%a\\Integration\\Integrator.exe\" set o16uwp=Office UWP )\r\n)\r\n\r\nif not \"%o14c2r%%o16uwp%\"==\"\" (\r\necho:\r\ncall :dk_color %Red% \"Checking Unsupported Office Install     [ %o14c2r%%o16uwp%]\"\r\nif not \"%o16uwp%\"==\"\" call :dk_color %Blue% \"Use TSforge option to activate it.\"\r\n)\r\n\r\nif %winbuild% GEQ 10240 %psc% \"Get-AppxPackage -name \"Microsoft.MicrosoftOfficeHub\"\" | find /i \"Office\" %nul1% && (\r\nset ohub=1\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check supported office versions\r\n\r\ncall :oh_getpath\r\n\r\nsc query ClickToRunSvc %nul%\r\nset error1=%errorlevel%\r\n\r\nif defined o16c2r if %error1% EQU 1060 (\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 16.0 files found]\"\r\nset o16c2r=\r\nset error=1\r\n)\r\n\r\nsc query OfficeSvc %nul%\r\nset error2=%errorlevel%\r\n\r\nif defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 15.0 files found]\"\r\nset o15c2r=\r\nset error=1\r\n)\r\n\r\nif \"%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%\"==\"\" (\r\nset error=1\r\necho:\r\nif not \"%o14c2r%%o16uwp%\"==\"\" (\r\ncall :dk_color %Red% \"Checking Supported Office Install       [Not Found]\"\r\n) else (\r\ncall :dk_color %Red% \"Checking Installed Office               [Not Found]\"\r\n)\r\n\r\nif defined ohub (\r\necho:\r\necho You only have the Office Dashboard app installed; you need to install the full version of Office.\r\n)\r\ncall :dk_color %Blue% \"Download and install Office from the URL below, then try again.\"\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto dk_done\r\n)\r\n\r\nset multioffice=\r\nif not \"%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%\"==\"1\" set multioffice=1\r\nif not \"%o14c2r%%o16uwp%\"==\"\" set multioffice=1\r\n\r\nif defined multioffice (\r\ncall :dk_color %Gray% \"Checking Multiple Office Install        [Found, its recommended to install only one version]\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Windows Server\r\n\r\nset winserver=\r\nreg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions\" /v ProductType %nul2% | find /i \"WinNT\" %nul1% || set winserver=1\r\nif not defined winserver (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Server\" %nul1% && set winserver=1\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:: Check Smart App Control\r\n\r\nset \"sacstate=\"\r\nif %winbuild% GEQ 22621 (\r\nfor /f \"tokens=3\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\CI\\Policy\" /v VerifiedAndReputablePolicyState %nul6%') do set \"sacstate=%%a\"\r\n)\r\nif defined sacstate (\r\nif \"%sacstate%\"==\"0x1\" (\r\ncall :dk_color %Gray% \"Checking Smart App Control State        [Enabled]\"\r\ncall :dk_color %Blue% \"Smart App Control may prevent you from opening Office after Ohook activation.\"\r\ncall :dk_color %Blue% \"You will need to disable it from the Windows Defender settings if it does.\"\r\n) else if \"%sacstate%\"==\"0x2\" (\r\ncall :dk_color %Gray% \"Checking Smart App Control State        [Evaluation]\"\r\ncall :dk_color %Blue% \"Smart App Control may prevent you from opening Office in the future if it enables itself after the evaluation period.\"\r\ncall :dk_color %Blue% \"It is recommended that you disable it from the Windows Defender settings.\"\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Process Office 15.0 C2R\r\n\r\nif not defined o15c2r goto :starto16c2r\r\n\r\ncall :oh_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=15\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o15c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o15c2r_reg%\\Configuration\")\r\nif not defined _oArch   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nif not defined _version for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v version\" %nul6%') do (set \"_version=%%b\")\r\nif not defined _prids   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v ProductReleaseId\" %nul6%') do (set \"_prids=%o15c2r_reg%\\propertyBag /v ProductReleaseId\" & set \"_config=%o15c2r_reg%\\propertyBag\")\r\n\r\necho \"%o15c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=10) || (set _tok=9)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query %o15c2r_reg%\\ProductReleaseIDs\\Active %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\nif /i \"%_oArch%\"==\"x64\" (set \"_hookPath=%_oRoot%\\vfs\\System\"    & set \"_hook=sppc64.dll\")\r\nif /i \"%_oArch%\"==\"x86\" (set \"_hookPath=%_oRoot%\\vfs\\SystemX86\" & set \"_hook=sppc32.dll\")\r\n\r\ncall :oh_ppcpath\r\n\r\necho:\r\necho Activating Office...                    [C2R ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :starto16c2r\r\n)\r\n\r\nif defined noOsppc (\r\ncall :dk_color %Red% \"Checking OSPPC.DLL                      [Not found. Aborting activation...]\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\nset error=1\r\ngoto :starto16c2r\r\n)\r\n\r\ncall :oh_expiredpreview 2013\r\ncall :oh_fixprids\r\ncall :oh_process\r\nif defined isOspp (\r\ncall :oh_hookinstall_ospp\r\n) else (\r\ncall :oh_hookinstall\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:starto16c2r\r\n\r\n::  Process Office 16.0 C2R\r\n\r\nif not defined o16c2r goto :startmsi\r\n\r\ncall :oh_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=16\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v AudienceData\" %nul6%') do (set \"_AudienceData=^| %%b \")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o16c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o16c2r_reg%\\Configuration\")\r\n\r\necho \"%o16c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=9) || (set _tok=8)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query \"%o16c2r_reg%\\ProductReleaseIDs\" /s /f \".16\" /k %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\nset _oIds=%_oIds:.16=%\r\nset _o16c2rIds=%_oIds%\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses16\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\nif /i \"%_oArch%\"==\"x64\" (set \"_hookPath=%_oRoot%\\vfs\\System\"    & set \"_hook=sppc64.dll\")\r\nif /i \"%_oArch%\"==\"x86\" (set \"_hookPath=%_oRoot%\\vfs\\SystemX86\" & set \"_hook=sppc32.dll\")\r\n\r\ncall :oh_ppcpath\r\n\r\necho:\r\necho Activating Office...                    [C2R ^| %_version% %_AudienceData%^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :startmsi\r\n)\r\n\r\nif defined noOsppc (\r\ncall :dk_color %Red% \"Checking OSPPC.DLL                      [Not found. Aborting activation...]\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\nset error=1\r\ngoto :startmsi\r\n)\r\n\r\ncall :oh_expiredpreview 2016 2019 2021 2024\r\ncall :oh_fixprids\r\ncall :oh_process\r\nif defined isOspp (\r\ncall :oh_hookinstall_ospp\r\n) else (\r\ncall :oh_hookinstall\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Old version of Office with subscription license key may show a banner to sign in to fix license issue.\r\n::  Although script applies a Resiliency registry entry to fix that but it doesn't work on old office versions.\r\n::  Below code checks that condition and informs the user to update the Office.\r\n\r\nif defined _sublic (\r\nif not exist \"%_oLPath%\\Word2021VL_KMS_Client_AE*.xrm-ms\" (\r\ncall :dk_color %Gray% \"Checking Old Office With Sub License    [Found. Update Office, otherwise, it may show a licensing issue-related banner.]\"\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  mass{}grave{dot}dev/office-license-is-not-genuine\r\n::  Add registry keys for volume products so that 'non-genuine' banner won't appear \r\n::  Script already is using MAK instead of GVLK so it won't appear anyway, but registry keys are added incase Office installs default GVLK grace key for volume products\r\n\r\nset \"kmskey=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\0ff1ce15-a989-479d-af46-f275c6370663\"\r\necho \"%_oIds%\" | find /i \"Volume\" %nul1% && (\r\nif %winbuild% GEQ 9200 (\r\nif not \"%osarch%\"==\"x86\" (\r\nreg delete \"%kmskey%\" /f /reg:32 %nul%\r\nreg add \"%kmskey%\" /f /v KeyManagementServiceName /t REG_SZ /d \"10.0.0.10\" /reg:32 %nul%\r\n)\r\nreg delete \"%kmskey%\" /f %nul%\r\nreg add \"%kmskey%\" /f /v KeyManagementServiceName /t REG_SZ /d \"10.0.0.10\" %nul%\r\necho Adding a Registry to Prevent Banner     [Successful]\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:startmsi\r\n\r\nif defined o14msi call :oh_setspp 14\r\nif defined o14msi call :oh_processmsi 14 %o14msi_reg%\r\ncall :oh_setspp\r\nif defined o15msi call :oh_processmsi 15 %o15msi_reg%\r\nif defined o16msi call :oh_processmsi 16 %o16msi_reg%\r\n\r\n::========================================================================================================================================\r\n\r\ncall :oh_clearblock\r\ncall :oh_uninstkey\r\ncall :oh_licrefresh\r\n\r\n::========================================================================================================================================\r\n\r\necho:\r\nif not defined error (\r\ncall :dk_color %Green% \"Office is permanently activated.\"\r\nif defined ohub call :dk_color %Gray% \"Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app.\"\r\necho Help: %mas%troubleshoot\r\n) else (\r\ncall :dk_color %Red% \"Some errors were detected.\"\r\nif not defined ierror if not defined showfix call :dk_color %Blue% \"%_fixmsg%\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_uninstall\r\n\r\ncls\r\nif not defined terminal mode 145, 32\r\ntitle  Uninstall Ohook Activation %masver%\r\n\r\nset _present=\r\nset _unerror=\r\ncall :oh_reset\r\ncall :oh_getpath\r\n\r\necho:\r\necho Uninstalling Ohook activation...\r\necho:\r\n\r\nif defined o16c2r_reg (for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg% /v InstallPath\" %nul6%') do (set \"_16CHook=%%b\\root\\vfs\"))\r\nif defined o15c2r_reg (for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg% /v InstallPath\" %nul6%') do (set \"_15CHook=%%b\\root\\vfs\"))\r\nif defined o16msi_reg (for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16msi_reg%\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_16MHook=%%b\"))\r\nif defined o15msi_reg (for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15msi_reg%\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_15MHook=%%b\"))\r\nif defined o14msi_reg (for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o14msi_reg%\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_14MHook=%%b\"))\r\n\r\nif defined _16CHook (if exist \"%_16CHook%\\System\\sppc*dll\"    (set _present=1& del /s /f /q \"%_16CHook%\\System\\sppc*dll\"    & if exist \"%_16CHook%\\System\\sppc*dll\"    set _unerror=1))\r\nif defined _16CHook (if exist \"%_16CHook%\\SystemX86\\sppc*dll\" (set _present=1& del /s /f /q \"%_16CHook%\\SystemX86\\sppc*dll\" & if exist \"%_16CHook%\\SystemX86\\sppc*dll\" set _unerror=1))\r\nif defined _15CHook (if exist \"%_15CHook%\\System\\sppc*dll\"    (set _present=1& del /s /f /q \"%_15CHook%\\System\\sppc*dll\"    & if exist \"%_15CHook%\\System\\sppc*dll\"    set _unerror=1))\r\nif defined _15CHook (if exist \"%_15CHook%\\SystemX86\\sppc*dll\" (set _present=1& del /s /f /q \"%_15CHook%\\SystemX86\\sppc*dll\" & if exist \"%_15CHook%\\SystemX86\\sppc*dll\" set _unerror=1))\r\nif defined _16MHook (if exist \"%_16MHook%sppc*dll\"            (set _present=1& del /s /f /q \"%_16MHook%sppc*dll\"            & if exist \"%_16MHook%sppc*dll\"            set _unerror=1))\r\nif defined _15MHook (if exist \"%_15MHook%sppc*dll\"            (set _present=1& del /s /f /q \"%_15MHook%sppc*dll\"            & if exist \"%_15MHook%sppc*dll\"            set _unerror=1))\r\nif defined _14MHook (if exist \"%_14MHook%sppc*dll\"            (set _present=1& del /s /f /q \"%_14MHook%sppc*dll\"            & if exist \"%_14MHook%sppc*dll\"            set _unerror=1))\r\n\r\nfor %%# in (14 15 16) do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft Office\\Office%%#\\sppc*dll\" (set _present=1& del /s /f /q \"%%~A\\Microsoft Office\\Office%%#\\sppc*dll\" & if exist \"%%~A\\Microsoft Office\\Office%%#\\sppc*dll\" set _unerror=1)\r\n)\r\n)\r\n\r\nfor %%# in (System SystemX86) do (\r\nfor %%G in (\"Office 15\" \"Office\") do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft %%~G\\root\\vfs\\%%#\\sppc*dll\" (set _present=1& del /s /f /q \"%%~A\\Microsoft %%~G\\root\\vfs\\%%#\\sppc*dll\" & if exist \"%%~A\\Microsoft %%~G\\root\\vfs\\%%#\\sppc*dll\" set _unerror=1)\r\n)\r\n)\r\n)\r\n\r\n::==================================\r\n\r\nfor %%# in (OSPPC.DLL sppcs.dll) do (\r\nfor %%A in (\"%CommonProgramFiles%\" \"%CommonProgramW6432%\" \"%CommonProgramFiles(x86)%\") do (\r\nfor %%G in (\"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\%%#\") do (\r\nset size=0\r\nset size=%%~zG\r\nif !size! GEQ 1 if !size! LSS 100000 (\r\nset _present=1\r\ndel /f /q \"%%~G\"\r\nif exist \"%%~G\" (move /y \"%%~G\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%)\r\nif exist \"%%~G\" (set _unerror=1) else (echo Deleted file - %%~G)\r\n)\r\nif /i sppcs.dll==%%# if !size! GEQ 100000 (\r\nmove /y \"%%~G\" \"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\OSPPC.DLL\" %nul%\r\nif exist \"%%~G\" (move /y \"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\OSPPC.DLL\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%)\r\nmove /y \"%%~G\" \"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\OSPPC.DLL\" %nul%\r\nif exist \"%%~G\" (set _unerror=1&echo Failed to rename sppcs.dll back to \"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\OSPPC.DLL\") else (echo Renamed sppcs.dll back to \"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\OSPPC.DLL\")\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==================================\r\n\r\nreg query HKCU\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency %nul% && (\r\necho:\r\necho Deleting - Registry keys for skipping license check\r\n\r\nreg load HKU\\DEF_TEMP %SystemDrive%\\Users\\Default\\NTUSER.DAT %nul%\r\nreg query HKU\\DEF_TEMP\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency %nul% && reg delete HKU\\DEF_TEMP\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /f\r\nreg unload HKU\\DEF_TEMP %nul%\r\n\r\nset _sidlist=\r\nfor /f \"tokens=* delims=\" %%a in ('%psc% \"$p = 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty \"\"\"\"$p\\$($_.PSChildName)\"\"\"\").ProfileImagePath; if ($pi -like '*\\Users\\*' -and (Test-Path \"\"\"\"$pi\\NTUSER.DAT\"\"\"\") -and -not ($_.PSChildName -match '\\.bak$')) { Split-Path $_.PSPath -Leaf } }\" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))\r\n\r\nif not defined _sidlist (\r\nfor /f \"delims=\" %%a in ('%psc% \"$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid\" %nul6%') do (set _sidlist=%%a)\r\n)\r\n\r\nfor %%# in (!_sidlist!) do (\r\n\r\nreg query HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency %nul% && reg delete HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /f\r\n\r\nreg query HKU\\%%#\\Software %nul% || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nreg load HKU\\%%# \"%%b\\NTUSER.DAT\" %nul%\r\nreg query HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency %nul% && reg delete HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /f\r\nreg unload HKU\\%%# %nul%\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==================================\r\n\r\nset \"kmskey=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\0ff1ce15-a989-479d-af46-f275c6370663\"\r\nreg query \"%kmskey%\" %nul% && (\r\necho:\r\necho Deleting - Registry keys for preventing non-genuine banner\r\nreg delete \"%kmskey%\" /f\r\n)\r\n\r\nreg query \"%kmskey%\" /reg:32 %nul% && (\r\nreg delete \"%kmskey%\" /f /reg:32\r\n)\r\n\r\necho __________________________________________________________________________________________\r\necho:\r\n\r\nif not defined _present (\r\necho Ohook activation is not installed.\r\n) else (\r\nif defined _unerror (\r\ncall :dk_color %Red% \"Failed to uninstall Ohook activation.\"\r\ncall :oh_checkapps\r\nif defined checknames (\r\ncall :dk_color %Blue% \"Close [!checknames!] and try again.\"\r\ncall :dk_color %Blue% \"If it is still not fixed, reboot your machine using the restart option and try again.\"\r\n) else (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\n)\r\n) else (\r\ncall :dk_color %Green% \"Successfully uninstalled Ohook activation.\"\r\n)\r\n)\r\necho __________________________________________________________________________________________\r\n\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_reset\r\n\r\nset key=\r\nset _oRoot=\r\nset _oArch=\r\nset _oIds=\r\nset _oLPath=\r\nset _hookPath=\r\nset _hook=\r\nset _sppcPath=\r\nset _osppPath=\r\nset _actid=\r\nset _prod=\r\nset _lic=\r\nset _arr=\r\nset _prids=\r\nset _config=\r\nset _version=\r\nset _License=\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_getpath\r\n\r\nset o16c2r=\r\nset o15c2r=\r\nset o16msi=\r\nset o15msi=\r\nset o14msi=\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set o16c2r=1&set o16c2r_reg=%_86%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set o16c2r=1&set o16c2r_reg=%_68%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set o15c2r=1&set o15c2r_reg=%_86%\\15.0\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set o15c2r=1&set o15c2r_reg=%_68%\\15.0\\ClickToRun)\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o16msi=1&set o16msi_reg=%_86%\\16.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o16msi=1&set o16msi_reg=%_68%\\16.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o15msi=1&set o15msi_reg=%_86%\\15.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o15msi=1&set o15msi_reg=%_68%\\15.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=1&set o14msi_reg=%_86%\\14.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=1&set o14msi_reg=%_68%\\14.0)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_expiredpreview\r\n\r\necho %_oIds% | find /i \"Volume\" %nul% || exit /b\r\n\r\nfor %%# in (%*) do (\r\nif %%#==2013 set _offver=\r\nif %%#==2016 set _offver=\r\nif %%#==2019 set _offver=2019\r\nif %%#==2021 set _offver=2021\r\nif %%#==2024 set _offver=2024\r\nif exist \"!_oLPath!\\ProPlus!_offver!PreviewVL_*.xrm-ms\" if not exist \"!_oLPath!\\ProPlus!_offver!VL_*.xrm-ms\" (\r\nset error=1\r\nset showfix=1\r\ncall :dk_color %Red% \"Checking Expired Preview Products       [Office %%# Preview Found]\"\r\ncall :dk_color %Blue% \"Please run the Office updates first, and then attempt to activate it again.\"\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_ppcpath\r\n\r\nif not defined isOspp (\r\nif not \"%osarch%\"==\"x86\" (\r\nif /i \"%_oArch%\"==\"x64\" set \"_sppcPath=%SystemRoot%\\System32\\sppc.dll\"\r\nif /i \"%_oArch%\"==\"x86\" set \"_sppcPath=%SystemRoot%\\SysWOW64\\sppc.dll\"\r\n) else (\r\nset \"_sppcPath=%SystemRoot%\\System32\\sppc.dll\"\r\n)\r\n)\r\n\r\nset noOsppc=\r\nset _hook68=\r\nset _hook86=\r\nset _osppPath68=\r\nset _osppPath86=\r\n\r\nif defined isOspp (\r\nif not \"%osarch%\"==\"x86\" (\r\nif /i \"%_oArch%\"==\"x64\" (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform /v Path\" %nul6%') do (set \"_osppPath68=%%b\")\r\nif not exist \"!_osppPath68!OSPPC.DLL\" set noOsppc=1\r\n)\r\nif /i \"%_oArch%\"==\"x86\" (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform /v Path\" %nul6%') do (set \"_osppPath68=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\OfficeSoftwareProtectionPlatform /v Path\" %nul6%') do (set \"_osppPath86=%%b\")\r\nif not exist \"!_osppPath68!OSPPC.DLL\" set noOsppc=1\r\nif not exist \"!_osppPath86!OSPPC.DLL\" set noOsppc=1\r\n)\r\n) else (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform /v Path\" %nul6%') do (set \"_osppPath86=%%b\")\r\nif not exist \"!_osppPath86!OSPPC.DLL\" set noOsppc=1\r\n)\r\nif \"!_osppPath68:~-1!\"==\"\\\" set \"_osppPath68=!_osppPath68:~0,-1!\"\r\nif \"!_osppPath86:~-1!\"==\"\\\" set \"_osppPath86=!_osppPath86:~0,-1!\"\r\n)\r\n\r\nif defined _osppPath68 set _hook68=sppc64.dll\r\nif defined _osppPath86 set _hook86=sppc32.dll\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Some Office Retail to Volume converter tools may edit the ProductReleaseIds to add VL products. This code restores it because it may affect features.\r\n\r\n:oh_fixprids\r\n\r\nif not defined _prids (\r\ncall :dk_color %Gray% \"Checking ProductReleaseIds In Registry  [Not Found]\"\r\nexit /b\r\n)\r\n\r\nset _pridsR=\r\nset _pridsE=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_prids%\" %nul6%') do (set \"_pridsR=%%b\")\r\n\r\nset _pridsR=%_pridsR:,= %\r\nfor %%# in (%_pridsR%) do (echo %%# | findstr /I \"%_oIds%\" %nul1% || set _pridsE=1)\r\nfor %%# in (%_oIds%) do (echo %%# | findstr /I \"%_pridsR%\" %nul1% || set _pridsE=1)\r\n\r\nif not defined _pridsE exit /b\r\nreg add %_prids% /t REG_SZ /d \"\" /f %nul1%\r\n\r\nfor %%# in (%_oIds%) do (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query %_prids%') do if not \"%%b\"==\"\" (\r\nreg add %_prids% /t REG_SZ /d \"%%b,%%#\" /f %nul1%\r\n) else (\r\nreg add %_prids% /t REG_SZ /d \"%%#\" /f %nul1%\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_installlic\r\n\r\nif not defined _oLPath exit /b\r\n\r\nif defined _oIntegrator (\r\nif %oVer%==16 (\r\n\"!_oIntegrator!\" /I /License PRIDName=%_License%.16 PidKey=%key% %nul%\r\n) else (\r\n\"!_oIntegrator!\" /I /License PRIDName=%_License% PidKey=%key% %nul%\r\n)\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% && exit /b\r\n)\r\n\r\n::  Fallback to manual method to install licenses incase integrator.exe is not working\r\n\r\nset _License=%_License:XVolume=XC2RVL_%\r\n\r\nset _License=%_License:O365EduCloudRetail=O365EduCloudEDUR_%\r\n\r\nset _License=%_License:ProjectProRetail=ProjectProO365R_%\r\nset _License=%_License:ProjectStdRetail=ProjectStdO365R_%\r\nset _License=%_License:VisioProRetail=VisioProO365R_%\r\nset _License=%_License:VisioStdRetail=VisioStdO365R_%\r\n\r\nif defined _preview set _License=%_License:Volume=PreviewVL_%\r\n\r\nset _License=%_License:Retail=R_%\r\nset _License=%_License:Volume=VL_%\r\n\r\nfor %%# in (\"!_oLPath!\\client-issuance-*.xrm-ms\") do (\r\nif defined _arr (set \"_arr=!_arr!;\"!_oLPath!\\%%~nx#\"\") else (set \"_arr=\"!_oLPath!\\%%~nx#\"\")\r\n)\r\n\r\nfor %%# in (\"!_oLPath!\\%_License%*.xrm-ms\") do (\r\nif defined _arr (set \"_arr=!_arr!;\"!_oLPath!\\%%~nx#\"\") else (set \"_arr=\"!_oLPath!\\%%~nx#\"\")\r\n)\r\n\r\n%psc% \"$sls = Get-WmiObject %sps%; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); InstallLicenseArr '!_arr!'; InstallLicenseFile '\"!_oLPath!\\pkeyconfig-office.xrm-ms\"'\" %nul%\r\n\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% || (\r\nset error=1\r\ncall :dk_color %Red% \"Installing Missing License Files        [Office %oVer%.0 %_prod%] [Failed]\"\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_hookinstall\r\n\r\nset ierror=\r\nset hasherror=\r\n\r\nif %_hook%==sppc32.dll set offset=2564\r\nif %_hook%==sppc64.dll set offset=3076\r\n\r\n::======================================\r\n\r\n::  Remove previous Install\r\n\r\nfor %%# in (sppcs.dll sppc.dll) do (\r\ndel /f /q \"%_hookPath%\\%%#\" %nul%\r\nif exist \"%_hookPath%\\%%#\" (move /y \"%_hookPath%\\%%#\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%)\r\nif exist \"%_hookPath%\\%%#\" (set \"ierror=Remove Previous Ohook Install [%%#]\")\r\n)\r\n\r\nif defined ierror goto :oh_hookinstall_error\r\n\r\n::======================================\r\n\r\nmklink \"%_hookPath%\\sppcs.dll\" \"%_sppcPath%\" %nul%\r\nif not exist \"%_hookPath%\\sppcs.dll\" (\r\nset ierror=mklink sppcs.dll\r\ngoto :oh_hookinstall_error\r\n)\r\n\r\nset exhook=\r\nif exist \"!_work!\\BIN\\%_hook%\" set exhook=1\r\n\r\nif not exist \"%_hookPath%\\sppc.dll\" (\r\nif defined exhook (\r\npushd \"!_work!\\BIN\\\"\r\ncopy /y /b \"%_hook%\" \"%_hookPath%\\sppc.dll\" %nul%\r\npopd\r\n) else (\r\ncall :oh_extractdll \"%_hookPath%\\sppc.dll\" \"%offset%\"\r\n)\r\n)\r\nif not exist \"%_hookPath%\\sppc.dll\" (\r\nset ierror=Copy\r\ngoto :oh_hookinstall_error\r\n)\r\n\r\necho:\r\necho Symlinking System's sppc.dll            [\"%_hookPath%\\sppcs.dll\"] [Successful]\r\nif defined exhook (\r\necho Copying Custom %_hook% to            [\"%_hookPath%\\sppc.dll\"] [Successful]\r\n) else (\r\necho Extracting Custom %_hook% to         [\"%_hookPath%\\sppc.dll\"] [Successful]\r\n)\r\n\r\ngoto :oh_hookinstall_error\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_hookinstall_ospp\r\n\r\nset ierror=\r\nset hasherror=\r\n\r\nif defined _hook86 set offset86=2564\r\nif defined _hook68 set offset68=3076\r\n\r\n::======================================\r\n\r\n::  Remove previous Install\r\n\r\nfor %%# in (OSPPC.DLL sppcs.dll) do (\r\nfor %%A in (\"%_osppPath68%\\%%#\" \"%_osppPath86%\\%%#\") do (\r\nset size=0\r\nset size=%%~zA\r\nif !size! GEQ 1 if !size! LSS 100000 (\r\ndel /f /q \"%%~A\" %nul%\r\nif exist \"%%~A\" (move /y \"%%~A\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%)\r\nif exist \"%%~A\" (set \"ierror=Remove Previous Ohook Install [%%#]\")\r\n)\r\n)\r\n)\r\n\r\nif defined ierror goto :oh_hookinstall_error\r\n\r\nfor %%A in (\"%_osppPath68%\" \"%_osppPath86%\") do (\r\nif exist \"%%~A\\sppcs.dll\" (move /y \"%%~A\\sppcs.dll\" \"%%~A\\OSPPC.DLL\" %nul%)\r\nif exist \"%%~A\\sppcs.dll\" (\r\nmove /y \"%%~A\\OSPPC.DLL\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%\r\nmove /y \"%%~A\\sppcs.dll\" \"%%~A\\OSPPC.DLL\" %nul%\r\n)\r\nif exist \"%%~A\\sppcs.dll\" (set \"ierror=Move sppcs.dll back to OSPPC.DLL\")\r\n)\r\n\r\ndel /f /q \"%_hookPath%\\sppcs.dll\" %nul%\r\nif exist \"%_hookPath%\\sppcs.dll\" (move /y \"%_hookPath%\\sppcs.dll\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%)\r\nif exist \"%_hookPath%\\sppcs.dll\" (set \"ierror=Remove Previous Ohook mklink sppcs.dll\")\r\n\r\nif defined ierror goto :oh_hookinstall_error\r\n\r\n::======================================\r\n\r\nif defined _osppPath68 (move /y \"%_osppPath68%\\OSPPC.DLL\" \"%_osppPath68%\\sppcs.dll\" %nul% & if not exist \"%_osppPath68%\\sppcs.dll\" set ierror=1)\r\nif defined _osppPath86 (move /y \"%_osppPath86%\\OSPPC.DLL\" \"%_osppPath86%\\sppcs.dll\" %nul% & if not exist \"%_osppPath86%\\sppcs.dll\" set ierror=1)\r\n\r\nif defined ierror (\r\nset \"ierror=Rename OSPPC.DLL\"\r\ngoto :oh_hookinstall_error\r\n)\r\n\r\nif defined _osppPath68 if defined _osppPath86     (mklink \"%_hookPath%\\sppcs.dll\" \"%_osppPath86%\\sppcs.dll\" %nul%)\r\nif defined _osppPath68 if not defined _osppPath86 (mklink \"%_hookPath%\\sppcs.dll\" \"%_osppPath68%\\sppcs.dll\" %nul%)\r\nif defined _osppPath86 if not defined _osppPath68 (mklink \"%_hookPath%\\sppcs.dll\" \"%_osppPath86%\\sppcs.dll\" %nul%)\r\n\r\nif not exist \"%_hookPath%\\sppcs.dll\" (\r\nset ierror=mklink sppcs.dll\r\ngoto :oh_hookinstall_error\r\n)\r\n\r\nset exhook=\r\nif exist \"!_work!\\BIN\\%_hook68%\" if exist \"!_work!\\BIN\\%_hook86%\"  set exhook=1\r\n\r\nif defined exhook (\r\npushd \"!_work!\\BIN\\\"\r\nif defined _osppPath68 (copy /y /b \"%_hook68%\" \"%_osppPath68%\\OSPPC.DLL\" %nul%)\r\nif defined _osppPath86 (copy /y /b \"%_hook86%\" \"%_osppPath86%\\OSPPC.DLL\" %nul%)\r\npopd\r\n) else (\r\nif defined _osppPath68 (set _hook=%_hook68%&call :oh_extractdll \"%_osppPath68%\\OSPPC.DLL\" \"%offset68%\")\r\nif defined _osppPath86 (set _hook=%_hook86%&call :oh_extractdll \"%_osppPath86%\\OSPPC.DLL\" \"%offset86%\")\r\n)\r\n\r\nif defined _osppPath68 (if not exist \"%_osppPath68%\\OSPPC.DLL\" set ierror=1)\r\nif defined _osppPath86 (if not exist \"%_osppPath86%\\OSPPC.DLL\" set ierror=1)\r\n\r\nif defined ierror (\r\nset ierror=Copy\r\ngoto :oh_hookinstall_error\r\n)\r\n\r\necho:\r\nif defined _osppPath68 (echo Renaming OSPPC.DLL to sppcs.dll         [\"%_osppPath68%\\sppcs.dll\"])\r\nif defined _osppPath86 (echo Renaming OSPPC.DLL to sppcs.dll         [\"%_osppPath86%\\sppcs.dll\"])\r\nif defined exhook (\r\nif defined _osppPath68 (echo Copying Custom %_hook68% to            [\"%_osppPath68%\\OSPPC.DLL\"])\r\nif defined _osppPath86 (echo Copying Custom %_hook86% to            [\"%_osppPath86%\\OSPPC.DLL\"])\r\n) else (\r\nif defined _osppPath68 (echo Extracting Custom %_hook68% to         [\"%_osppPath68%\\OSPPC.DLL\"])\r\nif defined _osppPath86 (echo Extracting Custom %_hook86% to         [\"%_osppPath86%\\OSPPC.DLL\"])\r\n)\r\n\r\necho Symlinking Renamed sppcs.dll            [\"%_hookPath%\\sppcs.dll\"]\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_hookinstall_error\r\n\r\nif defined ierror (\r\nset error=1\r\ncall :dk_color %Red% \"Installing Ohook                        [Failed to %ierror%]\"\r\necho:\r\ncall :oh_checkapps\r\nif defined checknames (\r\ncall :dk_color %Blue% \"Close [!checknames!] and try again.\"\r\ncall :dk_color %Blue% \"If it is still not fixed, reboot your machine using the restart option and try again.\"\r\n) else (\r\nif /i not \"%ierror%\"==\"Copy\" call :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\nif /i \"%ierror%\"==\"Copy\" call :dk_color %Blue% \"If you are using any third-party antivirus, check if it is blocking the script.\"\r\n)\r\necho:\r\n)\r\n\r\nif not defined exhook if not defined ierror (\r\nif defined hasherror (\r\nset error=1\r\nset ierror=1\r\ncall :dk_color %Red% \"Modifying Hash of Custom sppcs.dll      [Failed]\"\r\n) else (\r\necho Modifying Hash of Custom sppcs.dll      [Successful]\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_setspp\r\n\r\nset isOspp=\r\nif %winbuild% GEQ 9200 (\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n) else (\r\nset isOspp=1\r\nset spp=OfficeSoftwareProtectionProduct\r\nset sps=OfficeSoftwareProtectionService\r\n)\r\nif \"%1\"==\"14\" (\r\nset isOspp=1\r\nset spp=OfficeSoftwareProtectionProduct\r\nset sps=OfficeSoftwareProtectionService\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_process\r\n\r\nfor %%# in (%_oIds%) do (\r\n\r\nset key=\r\nset _actid=\r\nset _lic=\r\nset _preview=\r\nset _License=%%#\r\n\r\necho %%# | find /i \"2024\" %nul% && (\r\nif exist \"!_oLPath!\\ProPlus2024PreviewVL_*.xrm-ms\" if not exist \"!_oLPath!\\ProPlus2024VL_*.xrm-ms\" set _preview=-Preview\r\n)\r\nset _prod=%%#!_preview!\r\n\r\ncall :ohookdata getinfo !_prod!\r\n\r\nif not \"!key!\"==\"\" (\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% || call :oh_installlic\r\nif not %oVer%==14 set generickey=1\r\ncall :dk_inskey \"[!key!] [!_prod!] [!_lic!]\"\r\n) else (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Product In Script              [Office %oVer%.0 !_prod! key not found in script]\"\r\ncall :dk_color %Blue% \"Make sure you are using the latest version of MAS.\"\r\nset fixes=%fixes% %mas%\r\ncall :dk_color %_Yellow% \"%mas%\"\r\n)\r\n)\r\n\r\n::  Add SharedComputerLicensing registry key if Retail Office C2R is installed on Windows Server\r\n::  https://learn.microsoft.com/en-us/office/troubleshoot/office-suite-issues/click-to-run-office-on-terminal-server\r\n\r\nif defined winserver if defined _config if exist \"%_oLPath%\\Word2019VL_KMS_Client_AE*.xrm-ms\" (\r\necho %_oIds% | find /i \"Retail\" %nul1% && (\r\nset scaIsNeeded=1\r\nreg add %_config% /v SharedComputerLicensing /t REG_SZ /d \"1\" /f %nul1%\r\necho Adding SharedComputerLicensing Reg      [Successful] [Needed on Server With Retail Office]\"\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_processmsi\r\n\r\n::  Process Office MSI Version\r\n\r\ncall :oh_reset\r\nif \"%1\"==\"14\" (\r\ncall :dk_actids 59a52881-a989-479d-af46-f275c6370663\r\n) else (\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n)\r\n\r\nset oVer=%1\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_oRoot=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\ProductVersion /v LastProduct\" %nul6%') do (set \"_version=%%b\")\r\nif \"%_oRoot:~-1%\"==\"\\\" set \"_oRoot=%_oRoot:~0,-1%\"\r\n\r\necho \"%2\" | find /i \"Wow6432Node\" %nul1% && set _oArch=x86\r\nif not \"%osarch%\"==\"x86\" if not defined _oArch set _oArch=x64\r\nif \"%osarch%\"==\"x86\" set _oArch=x86\r\n\r\nif /i \"%_oArch%\"==\"x64\" (set \"_hookPath=%_oRoot%\" & set \"_hook=sppc64.dll\")\r\nif /i \"%_oArch%\"==\"x86\" (set \"_hookPath=%_oRoot%\" & set \"_hook=sppc32.dll\")\r\n\r\ncall :oh_ppcpath\r\n\r\ncall :msiofficedata %2\r\n\r\necho:\r\necho Activating Office...                    [MSI ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found, aborting activation...]\"\r\nexit /b\r\n)\r\n\r\nif defined noOsppc (\r\ncall :dk_color %Red% \"Checking OSPPC.DLL                      [Not found. Aborting activation...]\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\nset error=1\r\nexit /b\r\n)\r\n\r\nif %oVer%==14 if defined SingleImage (\r\necho Checking Installed Products             [SingleImage product found, Professional Retail key will be used for activation]\r\n)\r\n\r\ncall :oh_process\r\nif defined isOspp (\r\ncall :oh_hookinstall_ospp\r\n) else (\r\ncall :oh_hookinstall\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_clearblock\r\n\r\n::  Find remnants of Office vNext/shared/device license block and remove it because it stops other licenses from appearing\r\n::  https://learn.microsoft.com/en-us/office/troubleshoot/activation/reset-office-365-proplus-activation-state\r\n\r\nset _sidlist=\r\nfor /f \"tokens=* delims=\" %%a in ('%psc% \"$p = 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty \"\"\"\"$p\\$($_.PSChildName)\"\"\"\").ProfileImagePath; if ($pi -like '*\\Users\\*' -and (Test-Path \"\"\"\"$pi\\NTUSER.DAT\"\"\"\") -and -not ($_.PSChildName -match '\\.bak$')) { Split-Path $_.PSPath -Leaf } }\" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))\r\n\r\nif not defined _sidlist (\r\nfor /f \"delims=\" %%a in ('%psc% \"$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid\" %nul6%') do (set _sidlist=%%a)\r\n)\r\n\r\n::==========================\r\n\r\n::  Load the unloaded useraccounts registry\r\n\r\nset loadedsids=\r\nset alrloadedsids=\r\n\r\nfor %%# in (%_sidlist%) do (\r\nreg query HKU\\%%#\\Software %nul% && (\r\ncall set \"alrloadedsids=%%alrloadedsids%% %%#\"\r\n) || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nreg load HKU\\%%# \"%%b\\NTUSER.DAT\" %nul%\r\nreg query HKU\\%%#\\Software %nul% && (\r\ncall set \"loadedsids=%%loadedsids%% %%#\"\r\n) || (\r\nreg unload HKU\\%%# %nul%\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==========================\r\n\r\nset \"_sidlist=%loadedsids% %alrloadedsids%\"\r\n\r\nset /a counter=0\r\nfor %%# in (%_sidlist%) do set /a counter+=1\r\n\r\nif %counter% EQU 0 (\r\nset error=1\r\ncall :dk_color %Red% \"Checking User Accounts SID              [Not Found]\"\r\nexit /b\r\n)\r\n\r\nif %counter% GTR 10 (\r\ncall :dk_color %Gray% \"Checking Total User Accounts            [%counter%]\"\r\n)\r\n\r\n::==========================\r\n\r\n::  Clear the vNext/shared/device license blocks which may prevent ohook activation\r\n\r\nset vnextexist=\r\nrmdir /s /q \"%ProgramData%\\Microsoft\\Office\\Licenses\\\" %nul%\r\n\r\nfor %%x in (15 16) do (\r\nfor %%# in (%_sidlist%) do (\r\nreg query HKU\\%%#\\Software\\Microsoft\\Office\\%%x.0\\Common\\Licensing /s %nul2% | findstr /i \"CIDToLicenseIdsMapping LicenseIdToEmailMapping @\" %nul% && set vnextexist=1\r\nreg delete HKU\\%%#\\Software\\Microsoft\\Office\\%%x.0\\Common\\Licensing /f %nul%\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nrmdir /s /q \"%%b\\AppData\\Local\\Microsoft\\Office\\Licenses\\\" %nul%\r\nrmdir /s /q \"%%b\\AppData\\Local\\Microsoft\\Office\\%%x.0\\Licensing\\\" %nul%\r\n)\r\n)\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f /reg:32 %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f /reg:32 %nul%\r\n)\r\n\r\n::  Clear vNext in UWP Office\r\n\r\nif defined o16uwpapplist (\r\nfor %%# in (%_sidlist%) do (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nrmdir /s /q \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\LocalCache\\Local\\Microsoft\\Office\\Licenses\\\" %nul%\r\nif exist \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\SystemAppData\\Helium\\User.dat\" (\r\nset defname=DEFTEMP-%%#\r\nreg load HKU\\!defname! \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\SystemAppData\\Helium\\User.dat\" %nul%\r\nreg query HKU\\!defname!\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing /s %nul2% | findstr /i \"CIDToLicenseIdsMapping LicenseIdToEmailMapping @\" %nul% && set vnextexist=1\r\nreg delete HKU\\!defname!\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing /f %nul%\r\nreg unload HKU\\!defname! %nul%\r\n)\r\n)\r\n)\r\n)\r\n\r\nif defined vnextexist (\r\necho:\r\ncall :dk_color %Gray% \"The logged-in Office account has a subscription license.\"\r\ncall :dk_color %Blue% \"If the subscription is active, it overrides other activation methods.\"\r\ncall :dk_color %Blue% \"If it is expiring soon, rerun the activation script after it expires.\"\r\ncall :dk_color2 %Blue% \"If it has already expired and activation fails, get help here - \" %_Yellow% \" %mas%troubleshoot\"\r\necho:\r\n)\r\n\r\n::  Clear SharedComputerLicensing for office\r\n::  https://learn.microsoft.com/en-us/deployoffice/overview-shared-computer-activation\r\n\r\nif not defined scaIsNeeded (\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration /v SharedComputerLicensing /f %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration /v SharedComputerLicensing /f /reg:32 %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\15.0\\ClickToRun\\Configuration /v SharedComputerLicensing /f %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\15.0\\ClickToRun\\Configuration /v SharedComputerLicensing /f /reg:32 %nul%\r\n)\r\n\r\n::  Clear device-based-licensing\r\n::  https://learn.microsoft.com/en-us/deployoffice/device-based-licensing\r\n\r\nfor /f %%# in ('reg query \"%o16c2r_reg%\\Configuration\" /f *.DeviceBasedLicensing %nul6% ^| findstr REG_') do reg delete \"%o16c2r_reg%\\Configuration\" /v %%# /f %nul%\r\n\r\n::  Remove OEM registry key\r\n::  https://support.microsoft.com/en-us/office/office-repeatedly-prompts-you-to-activate-on-a-new-pc-a9a6b05f-f6ce-4d1f-8d49-eb5007b64ba1\r\n\r\nfor %%# in (15 16) do (\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%#.0\\Common\\OEM\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%#.0\\Common\\OEM\" /f /reg:32 %nul%\r\n)\r\n\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\\0ff1ce15-a989-479d-af46-f275c6370663\" /f %nul%\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\OfficeSoftwareProtectionPlatform\\Policies\\0ff1ce15-a989-479d-af46-f275c6370663\" /f %nul%\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\OfficeSoftwareProtectionPlatform\\Policies\\59a52881-a989-479d-af46-f275c6370663\" /f %nul%\r\n\r\necho Clearing Office License Blocks          [Successfully cleared from all %counter% user accounts]\r\n\r\n::==========================\r\n\r\n::  Some retail products attempt to validate the license and may show a banner \"There was a problem checking this device's license status.\"\r\n::  Resiliency registry entry can skip this check\r\n\r\nset defname=DEFTEMP-%random%\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\" /v Default\" %nul6%') do call set \"defdat=%%b\"\r\n\r\nif defined o16c2r if defined ohookact (\r\nif exist \"%defdat%\\NTUSER.DAT\" (\r\nreg load HKU\\%defname% \"%defdat%\\NTUSER.DAT\" %nul%\r\nreg query HKU\\%defname%\\Software %nul% && (\r\nreg add HKU\\%defname%\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /v \"TimeOfLastHeartbeatFailure\" /t REG_SZ /d \"2040-01-01T00:00:00Z\" /f %nul%\r\n)\r\nreg unload HKU\\%defname% %nul%\r\n)\r\n\r\nfor %%# in (%_sidlist%) do (\r\nreg delete HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /f %nul%\r\nreg add HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /v \"TimeOfLastHeartbeatFailure\" /t REG_SZ /d \"2040-01-01T00:00:00Z\" /f %nul%\r\n)\r\necho Adding Registry to Skip License Check   [Successfully added to all %counter% ^& future new user accounts]\r\n)\r\n\r\n::==========================\r\n\r\n::  Unload the loaded useraccounts registry\r\n\r\nfor %%# in (%loadedsids%) do (\r\nreg unload HKU\\%%# %nul%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Uninstall other / grace Keys\r\n\r\n:oh_uninstkey\r\n\r\nset upk_result=0\r\ncall :dk_actid 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nif \"%_actprojvis%\"==\"1\" (\r\nfor /f \"delims=\" %%a in ('%psc% \"Get-WmiObject -Query 'SELECT ID, Description, LicenseFamily FROM %spp% WHERE ApplicationID=''0ff1ce15-a989-479d-af46-f275c6370663'' AND PartialProductKey IS NOT NULL' | Where-Object { $_.LicenseFamily -notmatch 'Project' -and $_.LicenseFamily -notmatch 'Visio' } | Select-Object -ExpandProperty ID\" %nul6%') do call set \"_allactid=%%a !_allactid!\"\r\nfor /f \"delims=\" %%a in ('%psc% \"Get-WmiObject -Query 'SELECT ID, Description, LicenseFamily FROM %spp% WHERE ApplicationID=''0ff1ce15-a989-479d-af46-f275c6370663'' AND PartialProductKey IS NOT NULL' | Where-Object { '!_allactid!' -contains $_.ID -and ($_.LicenseFamily -match 'Project' -or $_.LicenseFamily -match 'Visio') } | Select-Object -ExpandProperty ID\" %nul6%') do call set \"_allactid=%%a !_allactid!\"\r\n)\r\n\r\nfor %%# in (%apps%) do (\r\necho \"%_allactid%\" | find /i \"%%#\" %nul1% || (\r\n\r\nif %_wmic% EQU 1 wmic path %spp% where ID='%%#' call UninstallProductKey %nul%\r\nif %_wmic% EQU 0 %psc% \"$null=([WMI]'%spp%=''%%#''').UninstallProductKey()\" %nul%\r\n\r\nif !errorlevel!==0 (\r\nset upk_result=1\r\n) else (\r\nset error=1\r\nset upk_result=2\r\n)\r\n)\r\n)\r\n\r\nif defined ohookact if not %upk_result%==0 echo:\r\nif %upk_result%==1 echo Uninstalling Other/Grace Keys           [Successful]\r\nif %upk_result%==2 (\r\ncall :dk_color %Red% \"Uninstalling Other/Grace Keys           [Failed]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\nset showfix=1\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Refresh Windows Insider Preview Licenses\r\n::  It required in Insider versions otherwise office may not activate\r\n\r\n:oh_licrefresh\r\n\r\nif exist \"%SysPath%\\spp\\store_test\\2.0\\tokens.dat\" (\r\n%psc% \"Stop-Service sppsvc -force; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif !errorlevel! NEQ 0 %psc% \"$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check running office apps and notify user\r\n\r\n:oh_checkapps\r\n\r\nset checkapps=\r\nset checknames=\r\nfor /f \"tokens=1\" %%i in ('tasklist ^| findstr /I \".exe\" %nul6%') do (set \"checkapps=!checkapps! -%%i-\")\r\n\r\nfor %%# in (\r\nAccess_msaccess.exe\r\nExcel_excel.exe\r\nGroove_groove.exe\r\nLync_lync.exe\r\nOneNote_onenote.exe\r\nOutlook_outlook.exe\r\nPowerPoint_powerpnt.exe\r\nProject_winproj.exe\r\nPublisher_mspub.exe\r\nVisio_visio.exe\r\nWord_winword.exe\r\nLime_lime.exe\r\n) do (\r\nfor /f \"tokens=1-2 delims=_\" %%A in (\"%%#\") do (\r\necho !checkapps! | find /i \"-%%B-\" %nul1% && (if defined checknames (set \"checknames=!checknames! %%A\") else (set \"checknames=%%A\"))\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Office version number\r\n::  2nd column = Activation ID\r\n::  3rd column = For Office 2013 and later, the generated keys are listed. For Office 2010, the blocked keys sourced from the Internet are listed.\r\n::               For Office 2013 and later, key preference is given in this order, Retail:TB:Sub > Retail > OEM:NONSLP > Volume:MAK > Volume:GVLK\r\n::               For Office 2010, key preference is given in this order, Retail > Volume:MAK\r\n::  4th column = Last part of license description\r\n::  5th column = Edition\r\n::  6th column = Other Edition IDs if they are part of the same primary product (For reference only)\r\n::  Separator  = \"_\"\r\n\r\n::===============\r\n\r\n:: We couldn't find any keys (blocked/generic doesn't matter) for these Office 2010 products. If you have them, please share with us.\r\n\r\n14_4eaff0d0-c6cb-4187-94f3-c7656d49a0aa_Retail________ExcelR_[HSExcelR]\r\n14_7004b7f0-6407-4f45-8eac-966e5f868bde_Retail________GrooveR\r\n14_133c8359-4e93-4241-8118-30bb18737ea0_Retail________PowerPointR_[HSPowerPointR]\r\n14_db3bbc9c-ce52-41d1-a46f-1a1d68059119_Retail________WordR_[HSWordR]\r\n14_dbe3aee0-5183-4ff7-8142-66050173cb01_Retail________SmallBusBasicsR_[SmallBusBasicsMSDNR]\r\n\r\n:: These installers are not publicly available, so it doesn't matter if we don't have their keys.\r\n\r\n14_19316117-30a8-4773-8fd9-7f7231f4e060_SubPrepid_____HomeBusinessSubR\r\n14_4d06f72e-fd50-4bc2-a24b-d448d7f17ef2_SubPrepid_____ProjectProSubR\r\n14_e98ef0c0-71c4-42ce-8305-287d8721e26c_SubPrepid_____ProPlusSubR\r\n14_14f5946a-debc-4716-babc-7e2c240fec08_Retail________MondoR\r\n14_533b656a-4425-480b-8e30-1a2358898350_MAK___________MondoVL\r\n\r\n:ohookdata\r\n\r\nset f=\r\nfor %%# in (\r\n:: Office 2010\r\n14_4d463c2c-0505-4626-8cdb-a4da82e2d8ed_7KTYC-XR43P-C3MRW-BJKFD-XB%f%YPG_Retail________AccessR\r\n14_745fb377-0a59-4ca9-b9a9-c359557a2c4e_7XHPQ-BQMYG-YBP49-CY8B2-T8%f%CGQ_ByPass________AccessRuntimeR\r\n14_95ab3ec8-4106-4f9d-b632-03c019d1d23f_89RTQ-MT4GK-6CPTX-WWP7C-J9%f%KXR_MAK___________AccessVL\r\n14_71dc86ff-f056-40d0-8ffb-9592705c9b76_39TRR-C2F37-9WYJ2-MJQXH-B9%f%38K_MAK___________ExcelVL\r\n14_fdad0dfa-417d-4b4f-93e4-64ea8867b7fd_RCGT3-FPQDV-H49CD-PPDBF-TH%f%47G_MAK___________GrooveVL\r\n14_7b7d1f17-fdcb-4820-9789-9bec6e377821_3YR9B-D9W79-BY66R-R8XYP-QY%f%YYY_Retail________HomeBusinessR_[HomeBusinessDemoR]\r\n14_09e2d37e-474b-4121-8626-58ad9be5776f_3X43R-HHHXX-FRHRW-2M2WJ-8V%f%PHD_Retail________HomeStudentR_[HomeStudentDemoR]\r\n14_ef1da464-01c8-43a6-91af-e4e5713744f9_XDGJY-KFHW9-JWX9X-YM4GW-GC%f%8WR_Retail________InfoPathR\r\n14_85e22450-b741-430c-a172-a37962c938af_6GKT2-KMJPK-4RRBF-8VQKB-JB%f%6G6_MAK___________InfoPathVL\r\n14_3f7aa693-9a7e-44fc-9309-bb3d8e604925_2TG3P-9DB76-4YT99-8RXGD-CW%f%XBP_Retail________OneNoteR_[HSOneNoteR]\r\n14_6860b31f-6a67-48b8-84b9-e312b3485c4b_CV64P-F4VRH-BJ33D-PH6MR-X6%f%9RY_MAK___________OneNoteVL\r\n14_fbf4ac36-31c8-4340-8666-79873129cf40_9D8FR-7GYBW-4YG8M-V36JK-VD%f%7CM_Retail________OutlookR\r\n14_a9aeabd8-63b8-4079-a28e-f531807fd6b8_J8C9M-YXMH2-9CX44-2C3YG-V7%f%692_MAK___________OutlookVL\r\n14_acb51361-c0db-4895-9497-1831c41f31a6_GMBWM-WVX26-7WHV4-DB43D-WV%f%DY2_Retail________PersonalR_[PersonalDemoR,PersonalPrepaidR]\r\n14_38252940-718c-4aa6-81a4-135398e53851_HPBQP-RJHDR-Q3472-PT9Q6-PB%f%B72_MAK___________PowerPointVL\r\n14_8b559c37-0117-413e-921b-b853aeb6e210_367X9-9HP9R-TKHY6-DH4QH-K9%f%PY7_Retail________ProfessionalR_[ProfessionalAcadR,ProfessionalDemoR,OEM-SingleImage]\r\n14_725714d7-d58f-4d12-9fa8-35873c6f7215_6JD4G-KRW3J-48MGV-DM6FC-T9%f%WKR_Retail________ProjectProR_[ProjectProMSDNR]\r\n14_1cf57a59-c532-4e56-9a7d-ffa2fe94b474_3XDTH-MMGJ6-F9MKX-THP8D-G9%f%BP7_MAK___________ProjectProVL\r\n14_688f6589-2bd9-424e-a152-b13f36aa6de1_2W96V-RTQ9R-2BPVT-PT8H9-MV%f%68T_Retail________ProjectStdR\r\n14_11b39439-6b93-4642-9570-f2eb81be2238_4DTT4-D4MKX-23KFH-JKR6T-YK%f%G2J_MAK___________ProjectStdVL\r\n14_71af7e84-93e6-4363-9b69-699e04e74071_2J9H6-H4D3G-PCXD2-96XVM-TR%f%R73_Retail________ProPlusR_[ProPlusAcadR,ProPlusMSDNR,Sub4R]\r\n14_fdf3ecb9-b56f-43b2-a9b8-1b48b6bae1a7_6CD6C-9R8PB-T2D9Y-8RKKX-W7%f%DFK_MAK___________ProPlusVL_[ProPlusAcadVL]\r\n14_98677603-a668-4fa4-9980-3f1f05f78f69_CTRJP-P72VV-JBF8Y-4W6WW-HX%f%HVG_Retail________PublisherR\r\n14_3d014759-b128-4466-9018-e80f6320d9d0_32YG9-3VX77-YXJVV-PRVFW-TT%f%8BV_MAK___________PublisherVL\r\n14_8090771e-d41a-4482-929e-de87f1f47e46_7VKXH-9BWCG-RPTBB-JBRV3-GR%f%HYC_MAK___________SmallBusBasicsVL\r\n14_b78df69e-0966-40b1-ae85-30a5134dedd0_H48K6-FB4Y6-P83GH-9J7XG-HD%f%KKX_ByPass________SPDR\r\n14_b6d2565c-341d-4768-ad7d-addbe00bb5ce_W3BTX-H6BW7-Q6DFW-BXFFY-8R%f%VJP_Retail________StandardR_[StandardMSDNR][KeyisforMSDNR]\r\n14_1f76e346-e0be-49bc-9954-70ec53a4fcfe_2XTQP-GDR7C-GTXPC-6W6PV-4R%f%XGC_MAK___________StandardVL_[StandardAcadVL]\r\n14_2745e581-565a-4670-ae90-6bf7c57ffe43_VXHHB-W7HBD-7M342-RJ7P8-CH%f%BD6_ByPass________StarterR\r\n14_66cad568-c2dc-459d-93ec-2f3cb967ee34_2RDPT-WPYQM-C2WXF-BTPDW-2J%f%2HM_Retail________VisioSIR_Prem[Pro,Std]\r\n14_36756cb8-8e69-4d11-9522-68899507cd6a_7PKFT-X2MKQ-GT6X2-8CB2W-CH%f%C9K_MAK___________VisioSIVL_Prem[Pro,Std]\r\n14_98d4050e-9c98-49bf-9be1-85e12eb3ab13_6J3XK-DFKGK-X373V-QJHYM-V3%f%FC2_MAK___________WordVL\r\n:: Office 2013\r\n15_ab4d047b-97cf-4126-a69f-34df08e2f254_B7RFY-7NXPK-Q4342-Y9X2H-3J%f%X4X_Retail________AccessRetail\r\n15_259de5be-492b-44b3-9d78-9645f848f7b0_X3XNB-HJB7K-66THH-8DWQ3-XH%f%GJP_Bypass________AccessRuntimeRetail\r\n15_4374022d-56b8-48c1-9bb7-d8f2fc726343_9MF9G-CN32B-HV7XT-9XJ8T-9K%f%VF4_MAK___________AccessVolume\r\n15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_NT889-MBH4X-8MD4H-X8R2D-WQ%f%HF8_Retail________ExcelRetail\r\n15_ac1ae7fd-b949-4e04-a330-849bc40638cf_Y3N36-YCHDK-XYWBG-KYQVV-BD%f%TJ2_MAK___________ExcelVolume\r\n15_cfaf5356-49e3-48a8-ab3c-e729ab791250_BMK4W-6N88B-BP9QR-PHFCK-MG%f%7GF_Retail________GrooveRetail\r\n15_4825ac28-ce41-45a7-9e6e-1fed74057601_RN84D-7HCWY-FTCBK-JMXWM-HT%f%7GJ_MAK___________GrooveVolume\r\n15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_2WQNF-GBK4B-XVG6F-BBMX7-M4%f%F2Y_OEM-Perp______HomeBusinessPipcRetail\r\n15_a2b90e7a-a797-4713-af90-f0becf52a1dd_YWD4R-CNKVT-VG8VJ-9333B-RC%f%W9F_Subscription__HomeBusinessRetail\r\n15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_B92QY-NKYFQ-6KTKH-VWW2Q-3P%f%B3B_OEM-ARM_______HomeStudentARMRetail\r\n15_ebef9f05-5273-404a-9253-c5e252f50555_QPG96-CNT7M-KH36K-KY4HQ-M7%f%TBR_OEM-ARM_______HomeStudentPlusARMRetail\r\n15_f2de350d-3028-410a-bfae-283e00b44d0e_6WW3N-BDGM9-PCCHD-9QPP9-P3%f%4QG_Subscription__HomeStudentRetail\r\n15_44984381-406e-4a35-b1c3-e54f499556e2_RV7NQ-HY3WW-7CKWH-QTVMW-29%f%VHC_Retail________InfoPathRetail\r\n15_9e016989-4007-42a6-8051-64eb97110cf2_C4TGN-QQW6Y-FYKXC-6WJW7-X7%f%3VG_MAK___________InfoPathVolume\r\n15_9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY_PrepidBypass__LyncAcademicRetail\r\n15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_N42BF-CBY9F-W2C7R-X397X-DY%f%FQW_PrepidBypass__LyncEntryRetail\r\n15_fada6658-bfc6-4c4e-825a-59a89822cda8_89P23-2NK2R-JXM2M-3Q8R8-BW%f%M3Y_Retail________LyncRetail\r\n15_e1264e10-afaf-4439-a98b-256df8bb156f_3WKCD-RN489-4M7XJ-GJ2GQ-YB%f%FQ6_MAK___________LyncVolume\r\n15_69ec9152-153b-471a-bf35-77ec88683eae_VNWHF-FKFBW-Q2RGD-HYHWF-R3%f%HH2_Subscription__MondoRetail\r\n15_f33485a0-310b-4b72-9a0e-b1d605510dbd_2YNYQ-FQMVG-CB8KW-6XKYD-M7%f%RRJ_MAK___________MondoVolume\r\n15_3391e125-f6e4-4b1e-899c-a25e6092d40d_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%FF4_Bypass________OneNoteFreeRetail\r\n15_8b524bcc-67ea-4876-a509-45e46f6347e8_3KXXQ-PVN2C-8P7YY-HCV88-GV%f%GQ6_Retail________OneNoteRetail\r\n15_b067e965-7521-455b-b9f7-c740204578a2_JDMWF-NJC7B-HRCHY-WFT8G-BP%f%XD9_MAK___________OneNoteVolume\r\n15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_9N4RQ-CF8R2-HBVCB-J3C9V-94%f%P4D_Retail________OutlookRetail\r\n15_8d577c50-ae5e-47fd-a240-24986f73d503_HNG29-GGWRG-RFC8C-JTFP4-2J%f%9FH_MAK___________OutlookVolume\r\n15_5aab8561-1686-43f7-9ff5-2c861da58d17_9CYB3-NFMRW-YFDG6-XC7TF-BY%f%36J_OEM-Perp______PersonalPipcRetail\r\n15_17e9df2d-ed91-4382-904b-4fed6a12caf0_2NCQJ-MFRMH-TXV83-J7V4C-RV%f%RWC_Retail________PersonalRetail\r\n15_31743b82-bfbc-44b6-aa12-85d42e644d5b_HVMN2-KPHQH-DVQMK-7B3CM-FG%f%BFC_Retail________PowerPointRetail\r\n15_e40dcb44-1d5c-4085-8e8f-943f33c4f004_47DKN-HPJP7-RF9M3-VCYT2-TM%f%Q4G_MAK___________PowerPointVolume\r\n15_064383fa-1538-491c-859b-0ecab169a0ab_N3QMM-GKDT3-JQGX6-7X3MQ-4G%f%BG3_Retail________ProPlusRetail\r\n15_2b88c4f2-ea8f-43cd-805e-4d41346e18a7_QKHNX-M9GGH-T3QMW-YPK4Q-QR%f%P9V_MAK___________ProPlusVolume\r\n15_4e26cac1-e15a-4467-9069-cb47b67fe191_CF9DD-6CNW2-BJWJQ-CVCFX-Y7%f%TXD_OEM-Perp______ProfessionalPipcRetail\r\n15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_MBQBN-CQPT6-PXRMC-TYJFR-3C%f%8MY_Retail________ProfessionalRetail\r\n15_2f72340c-b555-418d-8b46-355944fe66b8_WPY8N-PDPY4-FC7TF-KMP7P-KW%f%YFY_Subscription__ProjectProRetail\r\n15_ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32_WFCT2-NBFQ7-JD7VV-MFJX6-6F%f%2CM_MAK___________ProjectProVolume\r\n15_58d95b09-6af6-453d-a976-8ef0ae0316b1_NTHQT-VKK6W-BRB87-HV346-Y9%f%6W8_Subscription__ProjectStdRetail\r\n15_2b9e4a37-6230-4b42-bee2-e25ce86c8c7a_3CNQX-T34TY-99RH4-C4YD2-KW%f%YGV_MAK___________ProjectStdVolume\r\n15_c3a0814a-70a4-471f-af37-2313a6331111_TWNCJ-YR84W-X7PPF-6DPRP-D6%f%7VC_Retail________PublisherRetail\r\n15_38ea49f6-ad1d-43f1-9888-99a35d7c9409_DJPHV-NCJV6-GWPT6-K26JX-C7%f%GX6_MAK___________PublisherVolume\r\n15_ba3e3833-6a7e-445a-89d0-7802a9a68588_3NY6J-WHT3F-47BDV-JHF36-23%f%43W_PrepidBypass__SPDRetail\r\n15_32255c0a-16b4-4ce2-b388-8a4267e219eb_V6VWN-KC2HR-YYDD6-9V7HQ-7T%f%7VP_Retail________StandardRetail\r\n15_a24cca51-3d54-4c41-8a76-4031f5338cb2_9TN6B-PCYH4-MCVDQ-KT83C-TM%f%Q7T_MAK___________StandardVolume\r\n15_a56a3b37-3a35-4bbb-a036-eee5f1898eee_NVK2G-2MY4G-7JX2P-7D6F2-VF%f%QBR_Subscription__VisioProRetail\r\n15_3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d_YN7CF-XRH6R-CGKRY-GKPV3-BG%f%7WF_MAK___________VisioProVolume\r\n15_980f9e3e-f5a8-41c8-8596-61404addf677_NCRB7-VP48F-43FYY-62P3R-36%f%7WK_Subscription__VisioStdRetail\r\n15_44a1f6ff-0876-4edb-9169-dbb43101ee89_RX63Y-4NFK2-XTYC8-C6B3W-YP%f%XPJ_MAK___________VisioStdVolume\r\n15_191509f2-6977-456f-ab30-cf0492b1e93a_NB77V-RPFQ6-PMMKQ-T87DV-M4%f%D84_Retail________WordRetail\r\n15_9cedef15-be37-4ff0-a08a-13a045540641_RPHPB-Y7NC4-3VYFM-DW7VD-G8%f%YJ8_MAK___________WordVolume\r\n:: Office 365 - 15.0 version\r\n15_742178ed-6b28-42dd-b3d7-b7c0ea78741b_Y9NF9-M2QWD-FF6RJ-QJW36-RR%f%F2T_SubTest_______O365BusinessRetail\r\n15_a96f8dae-da54-4fad-bdc6-108da592707a_3NMDC-G7C3W-68RGP-CB4MH-4C%f%XCH_SubTest1______O365HomePremRetail\r\n15_e3dacc06-3bc2-4e13-8e59-8e05f3232325_H8DN8-Y2YP3-CR9JT-DHDR9-C7%f%GP3_Subscription2_O365ProPlusRetail\r\n15_0bc1dae4-6158-4a1c-a893-807665b934b2_2QCNB-RMDKJ-GC8PB-7QGQV-7Q%f%TQJ_Subscription2_O365SmallBusPremRetail\r\n:: Office 365 - 16.0 version\r\n16_dabaa1f2-109b-496d-bf49-1536cc862900_3HYJN-9KG99-F8VG9-V3DT8-JF%f%MHV_Subscription__O365AppsBasicRetail\r\n16_742178ed-6b28-42dd-b3d7-b7c0ea78741b_Y9NF9-M2QWD-FF6RJ-QJW36-RR%f%F2T_SubTest_______O365BusinessRetail\r\n16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_W62NQ-267QR-RTF74-PF2MH-JQ%f%MTH_Subscription__O365EduCloudRetail\r\n16_a96f8dae-da54-4fad-bdc6-108da592707a_3NMDC-G7C3W-68RGP-CB4MH-4C%f%XCH_SubTest1______O365HomePremRetail\r\n16_e3dacc06-3bc2-4e13-8e59-8e05f3232325_H8DN8-Y2YP3-CR9JT-DHDR9-C7%f%GP3_Subscription2_O365ProPlusRetail\r\n16_0bc1dae4-6158-4a1c-a893-807665b934b2_2QCNB-RMDKJ-GC8PB-7QGQV-7Q%f%TQJ_Subscription2_O365SmallBusPremRetail\r\n:: Office 2016\r\n16_bfa358b0-98f1-4125-842e-585fa13032e6_WHK4N-YQGHB-XWXCC-G3HYC-6J%f%F94_Retail________AccessRetail\r\n16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_RNB7V-P48F4-3FYY6-2P3R3-63%f%BQV_PrepidBypass__AccessRuntimeRetail\r\n16_3b2fa33f-cd5a-43a5-bd95-f49f3f546b0b_JJ2Y4-N8KM3-Y8KY3-Y22FR-R3%f%KVK_MAK___________AccessVolume\r\n16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_RKJBN-VWTM2-BDKXX-RKQFD-JT%f%YQ2_Retail________ExcelRetail\r\n16_685062a7-6024-42e7-8c5f-6bb9e63e697f_FVGNR-X82B2-6PRJM-YT4W7-8H%f%V36_MAK___________ExcelVolume\r\n16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_2WQNF-GBK4B-XVG6F-BBMX7-M4%f%F2Y_OEM-Perp______HomeBusinessPipcRetail\r\n16_86834d00-7896-4a38-8fae-32f20b86fa2b_HM6FM-NVF78-KV9PM-F36B8-D9%f%MXD_Retail________HomeBusinessRetail\r\n16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_PBQPJ-NC22K-69MXD-KWMRF-WF%f%G77_OEM-ARM_______HomeStudentARMRetail\r\n16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_6F2NY-7RTX4-MD9KM-TJ43H-94%f%TBT_OEM-ARM_______HomeStudentPlusARMRetail\r\n16_c28acdb8-d8b3-4199-baa4-024d09e97c99_PNPRV-F2627-Q8JVC-3DGR9-WT%f%YRK_Retail________HomeStudentRetail\r\n16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_YWD4R-CNKVT-VG8VJ-9333B-RC%f%3B8_Retail________HomeStudentVNextRetail\r\n16_69ec9152-153b-471a-bf35-77ec88683eae_VNWHF-FKFBW-Q2RGD-HYHWF-R3%f%HH2_Subscription__MondoRetail\r\n16_2cd0ea7e-749f-4288-a05e-567c573b2a6c_FMTQQ-84NR8-2744R-MXF4P-PG%f%YR3_MAK___________MondoVolume\r\n16_436366de-5579-4f24-96db-3893e4400030_XYNTG-R96FY-369HX-YFPHY-F9%f%CPM_Bypass________OneNoteFreeRetail\r\n16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_FXF6F-CNC26-W643C-K6KB7-6X%f%XW3_Retail________OneNoteRetail\r\n16_23b672da-a456-4860-a8f3-e062a501d7e8_9TYVN-D76HK-BVMWT-Y7G88-9T%f%PPV_MAK___________OneNoteVolume\r\n16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_7N4KG-P2QDH-86V9C-DJFVF-36%f%9W9_Retail________OutlookRetail\r\n16_50059979-ac6f-4458-9e79-710bcb41721a_7QPNR-3HFDG-YP6T9-JQCKQ-KK%f%XXC_MAK___________OutlookVolume\r\n16_5aab8561-1686-43f7-9ff5-2c861da58d17_9CYB3-NFMRW-YFDG6-XC7TF-BY%f%36J_OEM-Perp______PersonalPipcRetail\r\n16_a9f645a1-0d6a-4978-926a-abcb363b72a6_FT7VF-XBN92-HPDJV-RHMBY-6V%f%KBF_Retail________PersonalRetail\r\n16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_N7GCB-WQT7K-QRHWG-TTPYD-7T%f%9XF_Retail________PowerPointRetail\r\n16_9b4060c9-a7f5-4a66-b732-faf248b7240f_X3RT9-NDG64-VMK2M-KQ6XY-DP%f%FGV_MAK___________PowerPointVolume\r\n16_de52bd50-9564-4adc-8fcb-a345c17f84f9_GM43N-F742Q-6JDDK-M622J-J8%f%GDV_Retail________ProPlusRetail\r\n16_c47456e3-265d-47b6-8ca0-c30abbd0ca36_FNVK8-8DVCJ-F7X3J-KGVQB-RC%f%2QY_MAK___________ProPlusVolume\r\n16_4e26cac1-e15a-4467-9069-cb47b67fe191_CF9DD-6CNW2-BJWJQ-CVCFX-Y7%f%TXD_OEM-Perp______ProfessionalPipcRetail\r\n16_d64edc00-7453-4301-8428-197343fafb16_NXFTK-YD9Y7-X9MMJ-9BWM6-J2%f%QVH_Retail________ProfessionalRetail\r\n16_2f72340c-b555-418d-8b46-355944fe66b8_WPY8N-PDPY4-FC7TF-KMP7P-KW%f%YFY_Subscription__ProjectProRetail\r\n16_82f502b5-b0b0-4349-bd2c-c560df85b248_PKC3N-8F99H-28MVY-J4RYY-CW%f%GDH_MAK___________ProjectProVolume\r\n16_16728639-a9ab-4994-b6d8-f81051e69833_JBNPH-YF2F7-Q9Y29-86CTG-C9%f%YGV_MAKC2R________ProjectProXVolume\r\n16_58d95b09-6af6-453d-a976-8ef0ae0316b1_NTHQT-VKK6W-BRB87-HV346-Y9%f%6W8_Subscription__ProjectStdRetail\r\n16_82e6b314-2a62-4e51-9220-61358dd230e6_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%G93_MAK___________ProjectStdVolume\r\n16_431058f0-c059-44c5-b9e7-ed2dd46b6789_N3W2Q-69MBT-27RD9-BH8V3-JT%f%2C8_MAKC2R________ProjectStdXVolume\r\n16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_WKWND-X6G9G-CDMTV-CPGYJ-6M%f%VBF_Retail________PublisherRetail\r\n16_fcc1757b-5d5f-486a-87cf-c4d6dedb6032_9QVN2-PXXRX-8V4W8-Q7926-TJ%f%GD8_MAK___________PublisherVolume\r\n16_9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY_PrepidBypass__SkypeServiceBypassRetail\r\n16_971cd368-f2e1-49c1-aedd-330909ce18b6_4N4D8-3J7Y3-YYW7C-73HD2-V8%f%RHY_PrepidBypass__SkypeforBusinessEntryRetail\r\n16_418d2b9f-b491-4d7f-84f1-49e27cc66597_PBJ79-77NY4-VRGFG-Y8WYC-CK%f%CRC_Retail________SkypeforBusinessRetail\r\n16_03ca3b9a-0869-4749-8988-3cbc9d9f51bb_DMTCJ-KNRKR-JV8TQ-V2CR2-VF%f%TFH_MAK___________SkypeforBusinessVolume\r\n16_4a31c291-3a12-4c64-b8ab-cd79212be45e_2FPWN-4H6CM-KD8QQ-8HCHC-P9%f%XYW_Retail________StandardRetail\r\n16_0ed94aac-2234-4309-ba29-74bdbb887083_WHGMQ-JNMGT-MDQVF-WDR69-KQ%f%BWC_MAK___________StandardVolume\r\n16_a56a3b37-3a35-4bbb-a036-eee5f1898eee_NVK2G-2MY4G-7JX2P-7D6F2-VF%f%QBR_Subscription__VisioProRetail\r\n16_295b2c03-4b1c-4221-b292-1411f468bd02_NRKT9-C8GP2-XDYXQ-YW72K-MG%f%92B_MAK___________VisioProVolume\r\n16_0594dc12-8444-4912-936a-747ca742dbdb_G98Q2-B6N77-CFH9J-K824G-XQ%f%CC4_MAKC2R________VisioProXVolume\r\n16_980f9e3e-f5a8-41c8-8596-61404addf677_NCRB7-VP48F-43FYY-62P3R-36%f%7WK_Subscription__VisioStdRetail\r\n16_44151c2d-c398-471f-946f-7660542e3369_XNCJB-YY883-JRW64-DPXMX-JX%f%CR6_MAK___________VisioStdVolume\r\n16_1d1c6879-39a3-47a5-9a6d-aceefa6a289d_B2HTN-JPH8C-J6Y6V-HCHKB-43%f%MGT_MAKC2R________VisioStdXVolume\r\n16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_P8K82-NQ7GG-JKY8T-6VHVY-88%f%GGD_Retail________WordRetail\r\n16_c3000759-551f-4f4a-bcac-a4b42cbf1de2_YHMWC-YN6V9-WJPXD-3WQKP-TM%f%VCV_MAK___________WordVolume\r\n:: Office 2019\r\n16_518687bd-dc55-45b9-8fa6-f918e1082e83_WRYJ6-G3NP7-7VH94-8X7KP-JB%f%7HC_Retail________Access2019Retail\r\n16_385b91d6-9c2c-4a2e-86b5-f44d44a48c5f_6FWHX-NKYXK-BW34Q-7XC9F-Q9%f%PX7_MAK-AE________Access2019Volume\r\n16_22e6b96c-1011-4cd5-8b35-3c8fb6366b86_FGQNJ-JWJCG-7Q8MG-RMRGJ-9T%f%QVF_PrepidBypass__AccessRuntime2019Retail\r\n16_c201c2b7-02a1-41a8-b496-37c72910cd4a_KBPNW-64CMM-8KWCB-23F44-8B%f%7HM_Retail________Excel2019Retail\r\n16_05cb4e1d-cc81-45d5-a769-f34b09b9b391_8NT4X-GQMCK-62X4P-TW6QP-YK%f%PYF_MAK-AE________Excel2019Volume\r\n16_7fe09eef-5eed-4733-9a60-d7019df11cac_QBN2Y-9B284-9KW78-K48PB-R6%f%2YT_Retail________HomeBusiness2019Retail\r\n16_6303d14a-afad-431f-8434-81052a65f575_DJTNY-4HDWM-TDWB2-8PWC2-W2%f%RRT_OEM-ARM_______HomeStudentARM2019Retail\r\n16_215c841d-ffc1-4f03-bd11-5b27b6ab64cc_NM8WT-CFHB2-QBGXK-J8W6J-GV%f%K8F_OEM-ARM_______HomeStudentPlusARM2019Retail\r\n16_4539aa2c-5c31-4d47-9139-543a868e5741_XNWPM-32XQC-Y7QJC-QGGBV-YY%f%7JK_Retail________HomeStudent2019Retail\r\n16_20e359d5-927f-47c0-8a27-38adbdd27124_WR43D-NMWQQ-HCQR2-VKXDR-37%f%B7H_Retail________Outlook2019Retail\r\n16_92a99ed8-2923-4cb7-a4c5-31da6b0b8cf3_RN3QB-GT6D7-YB3VH-F3RPB-3G%f%QYB_MAK-AE________Outlook2019Volume\r\n16_2747b731-0f1f-413e-a92d-386ec1277dd8_NMBY8-V3CV7-BX6K6-2922Y-43%f%M7T_Retail________Personal2019Retail\r\n16_7e63cc20-ba37-42a1-822d-d5f29f33a108_HN27K-JHJ8R-7T7KK-WJYC3-FM%f%7MM_Retail________PowerPoint2019Retail\r\n16_13c2d7bf-f10d-42eb-9e93-abf846785434_29GNM-VM33V-WR23K-HG2DT-KT%f%QYR_MAK-AE________PowerPoint2019Volume\r\n16_a3072b8f-adcc-4e75-8d62-fdeb9bdfae57_BN4XJ-R9DYY-96W48-YK8DM-MY%f%7PY_Retail________ProPlus2019Retail\r\n16_6755c7a7-4dfe-46f5-bce8-427be8e9dc62_T8YBN-4YV3X-KK24Q-QXBD7-T3%f%C63_MAK-AE________ProPlus2019Volume\r\n16_1717c1e0-47d3-4899-a6d3-1022db7415e0_9NXDK-MRY98-2VJV8-GF73J-TQ%f%9FK_Retail________Professional2019Retail\r\n16_0d270ef7-5aaf-4370-a372-bc806b96adb7_JDTNC-PP77T-T9H2W-G4J2J-VH%f%8JK_Retail________ProjectPro2019Retail\r\n16_d4ebadd6-401b-40d5-adf4-a5d4accd72d1_TBXBD-FNWKJ-WRHBD-KBPHH-XD%f%9F2_MAK-AE________ProjectPro2019Volume\r\n16_bb7ffe5f-daf9-4b79-b107-453e1c8427b5_R3JNT-8PBDP-MTWCK-VD2V8-HM%f%KF9_Retail________ProjectStd2019Retail\r\n16_fdaa3c03-dc27-4a8d-8cbf-c3d843a28ddc_RBRFX-MQNDJ-4XFHF-7QVDR-JH%f%XGC_MAK-AE________ProjectStd2019Volume\r\n16_f053a7c7-f342-4ab8-9526-a1d6e5105823_4QC36-NW3YH-D2Y9D-RJPC7-VV%f%B9D_Retail________Publisher2019Retail\r\n16_40055495-be00-444e-99cc-07446729b53e_K8F2D-NBM32-BF26V-YCKFJ-29%f%Y9W_MAK-AE________Publisher2019Volume\r\n16_b639e55c-8f3e-47fe-9761-26c6a786ad6b_JBDKF-6NCD6-49K3G-2TV79-BK%f%P73_Retail________SkypeforBusiness2019Retail\r\n16_15a430d4-5e3f-4e6d-8a0a-14bf3caee4c7_9MNQ7-YPQ3B-6WJXM-G83T3-CB%f%BDK_MAK-AE________SkypeforBusiness2019Volume\r\n16_f88cfdec-94ce-4463-a969-037be92bc0e7_N9722-BV9H6-WTJTT-FPB93-97%f%8MK_PrepidBypass__SkypeforBusinessEntry2019Retail\r\n16_fdfa34dd-a472-4b85-bee6-cf07bf0aaa1c_NDGVM-MD27H-2XHVC-KDDX2-YK%f%P74_Retail________Standard2019Retail\r\n16_beb5065c-1872-409e-94e2-403bcfb6a878_NT3V6-XMBK7-Q66MF-VMKR4-FC%f%33M_MAK-AE________Standard2019Volume\r\n16_a6f69d68-5590-4e02-80b9-e7233dff204e_2NWVW-QGF4T-9CPMB-WYDQ9-7X%f%P79_Retail________VisioPro2019Retail\r\n16_f41abf81-f409-4b0d-889d-92b3e3d7d005_33YF4-GNCQ3-J6GDM-J67P3-FM%f%7QP_MAK-AE________VisioPro2019Volume\r\n16_4a582021-18c2-489f-9b3d-5186de48f1cd_263WK-3N797-7R437-28BKG-3V%f%8M8_Retail________VisioStd2019Retail\r\n16_933ed0e3-747d-48b0-9c2c-7ceb4c7e473d_BGNHX-QTPRJ-F9C9G-R8QQG-8T%f%27F_MAK-AE________VisioStd2019Volume\r\n16_72cee1c2-3376-4377-9f25-4024b6baadf8_JXR8H-NJ3MK-X66W8-78CWD-QR%f%VR2_Retail________Word2019Retail\r\n16_fe5fe9d5-3b06-4015-aa35-b146f85c4709_9F36R-PNVHH-3DXGQ-7CD2H-R9%f%D3V_MAK-AE________Word2019Volume\r\n:: Office 2021\r\n16_f634398e-af69-48c9-b256-477bea3078b5_P286B-N3XYP-36QRQ-29CMP-RV%f%X9M_Retail________Access2021Retail\r\n16_ae17db74-16b0-430b-912f-4fe456e271db_JBH3N-P97FP-FRTJD-MGK2C-VF%f%WG6_MAK-AE________Access2021Volume\r\n16_844c36cb-851c-49e7-9079-12e62a049e2a_MNX9D-PB834-VCGY2-K2RW2-2D%f%P3D_Bypass________AccessRuntime2021Retail\r\n16_fb099c19-d48b-4a2f-a160-4383011060aa_V6QFB-7N7G9-PF7W9-M8FQM-MY%f%8G9_Retail________Excel2021Retail\r\n16_9da1ecdb-3a62-4273-a234-bf6d43dc0778_WNYR4-KMR9H-KVC8W-7HJ8B-K7%f%9DQ_MAK-AE________Excel2021Volume\r\n16_38b92b63-1dff-4be7-8483-2a839441a2bc_JM99N-4MMD8-DQCGJ-VMYFY-R6%f%3YK_Subscription__HomeBusiness2021Retail\r\n16_2f258377-738f-48dd-9397-287e43079958_N3CWD-38XVH-KRX2Y-YRP74-6R%f%BB2_Subscription__HomeStudent2021Retail\r\n16_279706f4-3a4b-4877-949b-f8c299cf0cc5_NB2TQ-3Y79C-77C6M-QMY7H-7Q%f%Y8P_Retail________OneNote2021Retail\r\n16_0c7af60d-0664-49fc-9b01-41b2dea81380_THNKC-KFR6C-Y86Q9-W8CB3-GF%f%7PD_MAK-AE________OneNote2021Volume\r\n16_778ccb9a-2f6a-44e5-853c-eb22b7609643_CNM3W-V94GB-QJQHH-BDQ3J-33%f%Y8H_Bypass________OneNoteFree2021Retail\r\n16_ecea2cfa-d406-4a7f-be0d-c6163250d126_4NCWR-9V92Y-34VB2-RPTHR-YT%f%GR7_Retail________Outlook2021Retail\r\n16_45bf67f9-0fc8-4335-8b09-9226cef8a576_JQ9MJ-QYN6B-67PX9-GYFVY-QJ%f%6TB_MAK-AE________Outlook2021Volume\r\n16_8f89391e-eedb-429d-af90-9d36fbf94de6_RRRYB-DN749-GCPW4-9H6VK-HC%f%HPT_Retail________Personal2021Retail\r\n16_c9bf5e86-f5e3-4ac6-8d52-e114a604d7bf_3KXXQ-PVN2C-8P7YY-HCV88-GV%f%M96_Retail1_______PowerPoint2021Retail\r\n16_716f2434-41b6-4969-ab73-e61e593a3875_39G2N-3BD9C-C4XCM-BD4QG-FV%f%YDY_MAK-AE________PowerPoint2021Volume\r\n16_c2f04adf-a5de-45c5-99a5-f5fddbda74a8_8WXTP-MN628-KY44G-VJWCK-C7%f%PCF_Retail________ProPlus2021Retail\r\n16_3f180b30-9b05-4fe2-aa8d-0c1c4790f811_RNHJY-DTFXW-HW9F8-4982D-MD%f%2CW_MAK-AE1_______ProPlus2021Volume\r\n16_96097a68-b5c5-4b19-8600-2e8d6841a0db_JRJNJ-33M7C-R73X3-P9XF7-R9%f%F6M_MAK-AE________ProPlusSPLA2021Volume\r\n16_711e48a6-1a79-4b00-af10-73f4ca3aaac4_DJPHV-NCJV6-GWPT6-K26JX-C7%f%PBG_Retail________Professional2021Retail\r\n16_3747d1d5-55a8-4bc3-b53d-19fff1913195_QKHNX-M9GGH-T3QMW-YPK4Q-QR%f%WMV_Retail________ProjectPro2021Retail\r\n16_17739068-86c4-4924-8633-1e529abc7efc_HVC34-CVNPG-RVCMT-X2JRF-CR%f%7RK_MAK-AE1_______ProjectPro2021Volume\r\n16_4ea64dca-227c-436b-813f-b6624be2d54c_2B96V-X9NJY-WFBRC-Q8MP2-7C%f%HRR_Retail________ProjectStd2021Retail\r\n16_84313d1e-47c8-4e27-8ced-0476b7ee46c4_3CNQX-T34TY-99RH4-C4YD2-KW%f%6WH_MAK-AE________ProjectStd2021Volume\r\n16_b769b746-53b1-4d89-8a68-41944dafe797_CDNFG-77T8D-VKQJX-B7KT3-KK%f%28V_Retail1_______Publisher2021Retail\r\n16_a0234cfe-99bd-4586-a812-4f296323c760_2KXJH-3NHTW-RDBPX-QFRXJ-MT%f%GXF_MAK-AE________Publisher2021Volume\r\n16_c3fb48b2-1fd4-4dc8-af39-819edf194288_DVBXN-HFT43-CVPRQ-J89TF-VM%f%MHG_Retail________SkypeforBusiness2021Retail\r\n16_6029109c-ceb8-4ee5-b324-f8eb2981e99a_R3FCY-NHGC7-CBPVP-8Q934-YT%f%GXG_MAK-AE________SkypeforBusiness2021Volume\r\n16_9e7e7b8e-a0e7-467b-9749-d0de82fb7297_HXNXB-J4JGM-TCF44-2X2CV-FJ%f%VVH_Retail________Standard2021Retail\r\n16_223a60d8-9002-4a55-abac-593f5b66ca45_2CJN4-C9XK2-HFPQ6-YH498-82%f%TXH_MAK-AE________Standard2021Volume\r\n16_b99ba8c4-e257-4b70-a31a-8bd308ce7073_BQWDW-NJ9YF-P7Y79-H6DCT-MK%f%Q9C_MAK-AE________StandardSPLA2021Volume\r\n16_814014d3-c30b-4f63-a493-3708e0dc0ba8_T6P26-NJVBR-76BK8-WBCDY-TX%f%3BC_Retail________VisioPro2021Retail\r\n16_c590605a-a08a-4cc7-8dc2-f1ffb3d06949_JNKBX-MH9P4-K8YYV-8CG2Y-VQ%f%2C8_MAK-AE________VisioPro2021Volume\r\n16_16d43989-a5ef-47e2-9ff1-272784caee24_89NYY-KB93R-7X22F-93QDF-DJ%f%6YM_Retail________VisioStd2021Retail\r\n16_d55f90ee-4ba2-4d02-b216-1300ee50e2af_BW43B-4PNFP-V637F-23TR2-J4%f%7TX_MAK-AE________VisioStd2021Volume\r\n16_fb33d997-4aa3-494e-8b58-03e9ab0f181d_VNCC4-CJQVK-BKX34-77Y8H-CY%f%XMR_Retail________Word2021Retail\r\n16_0c728382-95fb-4a55-8f12-62e605f91727_BJG97-NW3GM-8QQQ7-FH76G-68%f%6XM_MAK-AE________Word2021Volume\r\n:: Office 2024\r\n16_8fdb1f1e-663f-4f2e-8fdb-7c35aee7d5ea_GNXWX-DF797-B2JT3-82W27-KH%f%PXT_MAK-AE________ProPlus2024Volume-Preview\r\n16_33b11b14-91fd-4f7b-b704-e64a055cf601_X86XX-N3QMW-B4WGQ-QCB69-V2%f%6KW_MAK-AE________ProjectPro2024Volume-Preview\r\n16_eb074198-7384-4bdd-8e6c-c3342dac8435_DW99Y-H7NT6-6B29D-8JQ8F-R3%f%QT7_MAK-AE________VisioPro2024Volume-Preview\r\n16_e563d108-7b0e-418a-8390-20e1d133d6bb_P6NMW-JMTRC-R6MQ6-HH3F2-BT%f%HKB_Retail________Access2024Retail\r\n16_f748e2f7-5951-4bc2-8a06-5a1fbe42f5f4_CXNJT-98HPP-92HX7-MX6GY-2P%f%VFR_MAK-AE________Access2024Volume\r\n16_f3a5e86a-e4f8-4d88-8220-1440c3bbcefa_82CNJ-W82TW-BY23W-BVJ6W-W4%f%8GP_Retail________Excel2024Retail\r\n16_523fbbab-c290-460d-a6c9-48e49709cb8e_7Y287-9N2KC-8MRR3-BKY82-2D%f%QRV_MAK-AE________Excel2024Volume\r\n16_885f83e0-5e18-4199-b8be-56697d0debfb_N69X7-73KPT-899FD-P8HQ4-QG%f%TP4_Retail________Home2024Retail\r\n16_acd4eccb-ff89-4e6a-9350-d2d56276ec69_PRKQM-YNPQR-77QT6-328D7-BD%f%223_Retail________HomeBusiness2024Retail\r\n16_6f5fd645-7119-44a4-91b4-eccfeeb738bf_2CFK4-N44KG-7XG89-CWDG6-P7%f%P27_Retail________Outlook2024Retail\r\n16_9a1e1bac-2d8b-4890-832f-0a68b27c16e0_NQPXP-WVB87-H3MMB-FYBW2-9Q%f%FPB_MAK-AE________Outlook2024Volume\r\n16_da9a57ae-81a8-4cb3-b764-5840e6b5d0bf_CT2KT-GTNWH-9HFGW-J2PWJ-XW%f%7KJ_Retail________PowerPoint2024Retail\r\n16_eca0d8a6-e21b-4622-9a87-a7103ff14012_RRXFN-JJ26R-RVWD2-V7WMP-27%f%PWQ_MAK-AE________PowerPoint2024Volume\r\n16_295dcc21-151a-4b4d-8f50-2b627ea197f6_GNJ6P-Y4RBM-C32WW-2VJKJ-MT%f%HKK_Retail________ProjectPro2024Retail\r\n16_2141d341-41aa-4e45-9ca1-201e117d6495_WNFMR-HK4R7-7FJVM-VQ3JC-76%f%HF6_MAK-AE1_______ProjectPro2024Volume\r\n16_ead42f74-817d-45b4-af6b-3beeb36ba650_C2PNM-2GQFC-CY3XR-WXCP4-GX%f%3XM_Retail________ProjectStd2024Retail\r\n16_4b6d9b9b-c16e-429d-babe-8bb84c3c27d6_F2VNW-MW8TT-K622Q-4D96H-PW%f%J8X_MAK-AE________ProjectStd2024Volume\r\n16_db249714-bb54-4422-8c78-2cc8d4c4a19f_VWCNX-7FKBD-FHJYG-XBR4B-88%f%KC6_Retail________ProPlus2024Retail\r\n16_d77244dc-2b82-4f0a-b8ae-1fca00b7f3e2_4YV2J-VNG7W-YGTP3-443TK-TF%f%8CP_MAK-AE1_______ProPlus2024Volume\r\n16_3046a03e-2277-4a51-8ccd-a6609eae8c19_XKRBW-KN2FF-G8CKY-HXVG6-FV%f%Y2V_MAK-AE________SkypeforBusiness2024Volume\r\n16_44a07f51-8263-4b2f-b2a5-70340055c646_GVG6N-6WCHH-K2MVP-RQ78V-3J%f%7GJ_MAK-AE1_______Standard2024Volume\r\n16_282d8f34-1111-4a6f-80fe-c17f70dec567_HGRBX-N68QF-6DY8J-CGX4W-XW%f%7KP_Retail________VisioPro2024Retail\r\n16_4c2f32bf-9d0b-4d8c-8ab1-b4c6a0b9992d_GBNHB-B2G3Q-G42YB-3MFC2-7C%f%JCX_MAK-AE________VisioPro2024Volume\r\n16_8504167d-887a-41ae-bd1d-f849d834352d_VBXPJ-38NR3-C4DKF-C8RT7-RG%f%HKQ_Retail________VisioStd2024Retail\r\n16_0978336b-5611-497c-9414-96effaff4938_YNFTY-63K7P-FKHXK-28YYT-D3%f%2XB_MAK-AE________VisioStd2024Volume\r\n16_f6b24e61-6aa7-4fd2-ab9b-4046cee4230a_XN33R-RP676-GMY2F-T3MH7-GC%f%VKR_Retail________Word2024Retail\r\n16_06142aa2-e935-49ca-af5d-08069a3d84f3_WD8CQ-6KNQM-8W2CX-2RT63-KK%f%3TP_MAK-AE________Word2024Volume\r\n) do (\r\nfor /f \"tokens=1-5 delims=_\" %%A in (\"%%#\") do (\r\n\r\nif %1==getinfo if not defined key (\r\nif %oVer%==%%A if /i \"%2\"==\"%%E\" (\r\nset key=%%C\r\nset _actid=%%B\r\nset _allactid=!_allactid! %%B\r\nset _lic=%%D\r\nif %oVer%==16 (echo \"%%D\" | find /i \"Subscription\" %nul% && set _sublic=1)\r\n)\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  This code is used to modify the timestamp value of sppc dll file in order to change checksums\r\n::  It's done to lower the potential false positive detection by antivirus's. On each install, it will install a unique sppc dll file\r\n\r\n:oh_extractdll\r\n\r\nset b=\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':%_hook%\\:.*';$encoded = ($f[1]) -replace '-', 'A' -replace '_', 'a';$bytes = [Con%b%vert]::FromBas%b%e64String($encoded); $PePath='%1'; $offset='%2'; $m=[System.IO.File]::ReadAllText('!_batp!') -split ':hexedit\\:.*';. ([scriptblock]::Create($m[1]))\" %nul2% | find /i \"Error found\" %nul1% && set hasherror=1\r\nexit /b\r\n\r\n:hexedit:\r\n# Use a MemoryStream to perform operations on the bytes\r\n$MemoryStream = New-Object System.IO.MemoryStream\r\n$Writer = New-Object System.IO.BinaryWriter($MemoryStream)\r\n$Writer.Write($bytes)\r\n\r\n# Define dynamic assembly, module, and type\r\n$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)\r\n$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)\r\n$TypeBuilder = $ModuleBuilder.DefineType(0)\r\n\r\n# Define P/Invoke method\r\n[void]$TypeBuilder.DefinePInvokeMethod('MapFileAndCheckSum', 'imagehlp.dll', 'Public, Static', [Reflection.CallingConventions]::Standard, [int], @([string], [int].MakeByRefType(), [int].MakeByRefType()), [Runtime.InteropServices.CallingConvention]::Winapi, [Runtime.InteropServices.CharSet]::Auto)\r\n\r\n# Create the type\r\n$Imagehlp = $TypeBuilder.CreateType()\r\n\r\n# Offset information\r\n$timestampOffset = 136\r\n$exportTimestampOffset = $offset\r\n$checkSumOffset = 216\r\n\r\n# Calculate timestamp\r\n$currentTimestamp = [DateTime]::UtcNow\r\n$unixTimestamp = [int]($currentTimestamp - (Get-Date -Year 1970 -Month 1 -Day 1 -Hour 0 -Minute 0 -Second 0)).TotalSeconds\r\n\r\n# Change timestamps\r\n$Writer.BaseStream.Position = $timestampOffset\r\n$Writer.Write($unixTimestamp)\r\n\r\n$Writer.BaseStream.Position = $exportTimestampOffset\r\n$Writer.Write($unixTimestamp)\r\n\r\n$Writer.Flush()\r\n\r\n# Write the current state of the MemoryStream to a temporary file\r\n$tempFilePath = \"$env:windir\\Temp\\$([System.IO.Path]::GetRandomFileName())\"\r\n[System.IO.File]::WriteAllBytes($tempFilePath, $MemoryStream.ToArray())\r\n\r\n# Update hash using the temporary file\r\n[int]$HeaderSum = 0\r\n[int]$CheckSum = 0\r\n[void]$Imagehlp::MapFileAndCheckSum($tempFilePath, [ref]$HeaderSum, [ref]$CheckSum)\r\n\r\n# If the checksums don't match, update the checksum in the MemoryStream\r\nif ($HeaderSum -ne $CheckSum) {\r\n    $Writer.BaseStream.Position = $checkSumOffset\r\n    $Writer.Write($CheckSum)\r\n    $Writer.Flush()\r\n} else {\r\n    Write-host Error found\r\n}\r\n\r\n# Delete the temporary file\r\nRemove-Item -Path $tempFilePath -Force\r\n\r\n# Get the modified bytes\r\n$modifiedBytes = $MemoryStream.ToArray()\r\n\r\n# Write the modified bytes to the final file\r\n[System.IO.File]::WriteAllBytes($PePath, $modifiedBytes)\r\n\r\n[void]$Imagehlp::MapFileAndCheckSum($PePath, [ref]$HeaderSum, [ref]$CheckSum)\r\nif ($HeaderSum -ne $CheckSum) {\r\n    Write-host Error found\r\n}\r\n\r\n$MemoryStream.Close()\r\n:hexedit:\r\n\r\n::========================================================================================================================================\r\n::\r\n::  This below blocks of text is encoded in base64 format\r\n::  The blocks in labels \"sppc32.dll\" and \"sppc64.dll\" contains below files\r\n::\r\n::  09865ea5993215965e8f27a74b8a41d15fd0f60f5f404cb7a8b3c7757acdab02 *sppc32.dll\r\n::  393a1fa26deb3663854e41f2b687c188a9eacd87b23f17ea09422c4715cb5a9f *sppc64.dll\r\n::\r\n::  The files are encoded in base64 to make AIO version.\r\n::\r\n::  mass{}grave{dot}dev/ohook\r\n::  Here you can find the files source code and info on how to rebuild the identical sppc.dll files\r\n::\r\n::  stackoverflow.com/a/35335273\r\n::  Here you can check how to extract sppc.dll files from base64\r\n::\r\n::  For any further question, feel free to contact us on mass{}grave{dot}dev/contactus\r\n::\r\n::========================================================================================================================================\r\n::\r\n::  If you want to use a different sppc.dll or without base64 format, then create a folder named \"BIN\" where this script is located and \r\n::  place these two files in that \"BIN\" folder. sppc32.dll, sppc64.dll\r\n::  Script will auto pick that instead of using the below from base64 section. You can also delete the below code in that case.\r\n::\r\n::========================================================================================================================================\r\n::\r\n::  Replace \"-\" with \"A\" and \"_\" with \"a\" before base64 conversion\r\n::  It was changed to prevent antiviruses from detecting and flagging base64 encoding\r\n\r\n:sppc32.dll:\r\nTVqQ--M----E----//8--Lg---------Q-----------------------------------------------g-----4fug4-t-nNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4g_W4gRE9TIG1vZGUuDQ0KJ---------BQRQ--T-EH-MDc0GQ----------O--\r\nDiML-QIo--I----e--------RxE----Q----------C-_g-Q-----g--B-----E----G----------CQ----B---+dY---I-Q-E--C---B------E---E--------B------Q---jR----Bg---Y-Q---H---HgD-------------------------I---BQ---------\r\n----------------------------------------------------------BsY---H------------------------------------C50ZXh0----c-E----Q-----g----Q------------------C---G-ucmRhdGE--Bg-----I-----I----G----------------\r\n--B---B-LmVoX2ZyYW2------D-----C----C-------------------Q---QC5lZGF0YQ--jR----B-----Eg----o------------------E---E-u_WRhdGE--BgB----Y-----I----c------------------B---D-LnJzcmM---B4-w---H-----E----Hg--\r\n----------------Q---wC5yZWxvYw--F-----C------g---CI------------------E---EI-----------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n---------------------------------------------------------------------------------------------------------------------------------------------------------------------FWJ5VZTjUXwg+wwx0Xw-----IlEJBSNRfSJ\r\nRCQQi0UMx0QkD-----CJRCQEi0UIx0QkC--ggGqJBCTHRfQ-----6-oB--CLNXhggGqD7BiFwInDi0Xwd-qJBCQx2//WUesyi1X0x0QkB-oggGqJBCSJVCQI/xW-YIBqg+wMhcCLRfCJBCR0Cv/WuwE---BS6wP/1lCNZfiJ2FteXcNVieVXVlOD7DyLRRiLdRyJRCQQ\r\ni0UUiXQkFIlEJ-yLRRCJRCQIi0UMiUQkBItFCIkEJOiE----McmD7BiJx4X-dVyLRRg5CHZV_9koiwYB2IN4E-B0RYlEJ-SLRQiJTeSJBCTo+/7//4tN5IX-dSwDHsdDE-E---DHQxQ-----x0MY-----MdDH-----DHQy------x0Mk-----EHrpI1l9In4W15fXcIY\r\n-LgB----wgw-kP8lcGC-_pCQ/yVsYIBqkJD/////-----P////8-----------------------------------------------------------------------------------------------------------------------------------------------------\r\n------------------------------------------------TgBh-G0-ZQ---Ec-cgBh-GM-ZQ------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n-----------------------------------------------------------------------------------------------------------------------------------U----------F6Ug-Bf-gBGwwEBIgB---k----H----ODf//+d-----EEOCIUCQg0FSIYD\r\ngwQCj8NBxkHFD-QEK----EQ---BV4P//qg----BBDgiF-kINBU_H-4YEgwUCm8NBxkHHQcUMB-QQ----c----NPg//8I------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n------------------D-3NBk-----MZC---B----Qw---EM----oQ---NEE--EBC--DPQg--70I---VD---pQw--XUM--KFD--DpQw--F0Q--DVE--BnR---nUQ--ONE---tRQ--YUU--J9F--DTRQ--DUY--DtG--BxRg--r0Y--M9G--D7Rg--nR---FFH--BvRw--\r\nn0c--NNH---RS---TUg--G9I--ClS---zUg---VJ--BBSQ--bUk--KdJ--C7SQ--+0k--DlK--BPSg--dUo--J1K--DTSg--B0s--D1L--BpSw--pUs--ONL---NT---OUw--IlM--DRT---EU0--FlN--CjTQ--8U0--BtO--BHTg--h04--LtO--DnTg--K08--FtP\r\n--C1Tw--608--CdQ--BdU---4kI--P1C---_Qw--RkM--IJD--DIQw---0Q--ClE--BRR---hUQ--MNE---LRQ--SkU--INF--C8RQ--80U--CdG--BZRg--k0Y--MJG--DoRg--GUc--DFH--BjRw--ikc--LxH--D1Rw--Mkg--GFI--CNS---vEg--OxI---mSQ--\r\nWkk--I1J--C0SQ--3kk--B1K--BHSg--ZUo--IxK--C7Sg--8Eo--CVL--BWSw--iks--MdL--D7Sw--Jkw--GRM--CwT---9Ew--DhN--CBTQ--zU0---lO---0Tg--_k4--KRO--DUTg--DE8--EZP--CLTw--008---xQ--BFU---eF-------Q-C--M-B--F--Y-\r\nBw-I--k-Cg-L--w-DQ-O--8-E--R-BI-Ew-U-BU-Fg-X-Bg-GQ-_-Bs-H--d-B4-Hw-g-CE-Ig-j-CQ-JQ-m-Cc-K--p-Co-Kw-s-C0-Lg-v-D--MQ-y-DM-N--1-DY-Nw-4-Dk-Og-7-Dw-PQ-+-D8-Q-BB-EI-c3BwYy5kbGw-U1BQQ1MuU0xDYWxsU2VydmVy-FNM\r\nQ2FsbFNlcnZlcgBTUFBDUy5TTENsb3Nl-FNMQ2xvc2U-U1BQQ1MuU0xDb25zdW1lUmln_HQ-U0xDb25zdW1lUmln_HQ-U1BQQ1MuU0xEZXBvc2l0TWlncmF0_W9uQmxvYgBTTERlcG9z_XRN_WdyYXRpb25CbG9i-FNQUENTLlNMRGVwb3NpdE9mZmxpbmVDb25m_XJt\r\nYXRpb25JZ-BTTERlcG9z_XRPZmZs_W5lQ29uZmlybWF0_W9uSWQ-U1BQQ1MuU0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklkRXg-U0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklkRXg-U1BQQ1MuU0xEZXBvc2l0U3RvcmVUb2tlbgBTTERlcG9z_XRTdG9y\r\nZVRv_2Vu-FNQUENTLlNMRmlyZUV2ZW50-FNMRmlyZUV2ZW50-FNQUENTLlNMR2F0_GVyTWlncmF0_W9uQmxvYgBTTEdhdGhlck1pZ3JhdGlvbkJsb2I-U1BQQ1MuU0xHYXRoZXJN_WdyYXRpb25CbG9iRXg-U0xHYXRoZXJN_WdyYXRpb25CbG9iRXg-U1BQQ1MuU0xH\r\nZW5lcmF0ZU9mZmxpbmVJbnN0YWxsYXRpb25JZ-BTTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklk-FNQUENTLlNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWRFe-BTTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklkRXg-U1BQQ1MuU0xHZXRBY3Rp\r\ndmVM_WNlbnNlSW5mbwBTTEdldEFjdGl2ZUxpY2Vuc2VJbmZv-FNQUENTLlNMR2V0QXBwbGljYXRpb25JbmZvcm1hdGlvbgBTTEdldEFwcGxpY2F0_W9uSW5mb3JtYXRpb24-U1BQQ1MuU0xHZXRBcHBs_WNhdGlvblBvbGljeQBTTEdldEFwcGxpY2F0_W9uUG9s_WN5\r\n-FNQUENTLlNMR2V0QXV0_GVudGljYXRpb25SZXN1bHQ-U0xHZXRBdXRoZW50_WNhdGlvblJlc3Vsd-BTUFBDUy5TTEdldEVuY3J5cHRlZFBJREV4-FNMR2V0RW5jcnlwdGVkUElERXg-U1BQQ1MuU0xHZXRHZW51_W5lSW5mb3JtYXRpb24-U0xHZXRHZW51_W5lSW5m\r\nb3JtYXRpb24-U1BQQ1MuU0xHZXRJbnN0YWxsZWRQcm9kdWN0S2V5SWRz-FNMR2V0SW5zdGFsbGVkUHJvZHVjdEtleUlkcwBTUFBDUy5TTEdldExpY2Vuc2U-U0xHZXRM_WNlbnNl-FNQUENTLlNMR2V0TGljZW5zZUZpbGVJZ-BTTEdldExpY2Vuc2VG_WxlSWQ-U1BQ\r\nQ1MuU0xHZXRM_WNlbnNlSW5mb3JtYXRpb24-U0xHZXRM_WNlbnNlSW5mb3JtYXRpb24-U0xHZXRM_WNlbnNpbmdTdGF0dXNJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFBLZXlJZ-BTTEdldFBLZXlJZ-BTUFBDUy5TTEdldFBLZXlJbmZvcm1hdGlvbgBTTEdldFBLZXlJ\r\nbmZvcm1hdGlvbgBTUFBDUy5TTEdldFBvbGljeUluZm9ybWF0_W9u-FNMR2V0UG9s_WN5SW5mb3JtYXRpb24-U1BQQ1MuU0xHZXRQb2xpY3lJbmZvcm1hdGlvbkRXT1JE-FNMR2V0UG9s_WN5SW5mb3JtYXRpb25EV09SR-BTUFBDUy5TTEdldFByb2R1Y3RT_3VJbmZv\r\ncm1hdGlvbgBTTEdldFByb2R1Y3RT_3VJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFNMSURM_XN0-FNMR2V0U0xJRExpc3Q-U1BQQ1MuU0xHZXRTZXJ2_WNlSW5mb3JtYXRpb24-U0xHZXRTZXJ2_WNlSW5mb3JtYXRpb24-U1BQQ1MuU0xJbnN0YWxsTGljZW5zZQBTTElu\r\nc3RhbGxM_WNlbnNl-FNQUENTLlNMSW5zdGFsbFByb29mT2ZQdXJj_GFzZQBTTEluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U1BQQ1MuU0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNlRXg-U0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNlRXg-U1BQQ1MuU0xJc0dlbnVpbmVMb2Nh\r\nbEV4-FNMSXNHZW51_W5lTG9jYWxFe-BTUFBDUy5TTExvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNMTG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U1BQQ1MuU0xPcGVu-FNMT3BlbgBTUFBDUy5TTFBlcnNpc3RBcHBs_WNhdGlvblBvbGlj_WVz-FNMUGVyc2lzdEFwcGxp\r\nY2F0_W9uUG9s_WNpZXM-U1BQQ1MuU0xQZXJz_XN0UlRTUGF5bG9hZE92ZXJy_WRl-FNMUGVyc2lzdFJUU1BheWxvYWRPdmVycmlkZQBTUFBDUy5TTFJlQXJt-FNMUmVBcm0-U1BQQ1MuU0xSZWdpc3RlckV2ZW50-FNMUmVn_XN0ZXJFdmVud-BTUFBDUy5TTFJlZ2lz\r\ndGVyUGx1Z2lu-FNMUmVn_XN0ZXJQbHVn_W4-U1BQQ1MuU0xTZXRBdXRoZW50_WNhdGlvbkRhdGE-U0xTZXRBdXRoZW50_WNhdGlvbkRhdGE-U1BQQ1MuU0xTZXRDdXJyZW50UHJvZHVjdEtleQBTTFNldEN1cnJlbnRQcm9kdWN0S2V5-FNQUENTLlNMU2V0R2VudWlu\r\nZUluZm9ybWF0_W9u-FNMU2V0R2VudWluZUluZm9ybWF0_W9u-FNQUENTLlNMVW5pbnN0YWxsTGljZW5zZQBTTFVu_W5zdGFsbExpY2Vuc2U-U1BQQ1MuU0xVbmluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U0xVbmluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U1BQQ1MuU0xV\r\nbmxvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNMVW5sb2FkQXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5TTFVucmVn_XN0ZXJFdmVud-BTTFVucmVn_XN0ZXJFdmVud-BTUFBDUy5TTFVucmVn_XN0ZXJQbHVn_W4-U0xVbnJlZ2lzdGVyUGx1Z2lu-FNQUENTLlNMcEF1\r\ndGhlbnRpY2F0ZUdlbnVpbmVU_WNrZXRSZXNwb25zZQBTTHBBdXRoZW50_WNhdGVHZW51_W5lVGlj_2V0UmVzcG9uc2U-U1BQQ1MuU0xwQmVn_W5HZW51_W5lVGlj_2V0VHJhbnNhY3Rpb24-U0xwQmVn_W5HZW51_W5lVGlj_2V0VHJhbnNhY3Rpb24-U1BQQ1MuU0xw\r\nQ2xlYXJBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTTHBDbGVhckFjdGl2YXRpb25JblByb2dyZXNz-FNQUENTLlNMcERlcG9z_XREb3dubGV2ZWxHZW51_W5lVGlj_2V0-FNMcERlcG9z_XREb3dubGV2ZWxHZW51_W5lVGlj_2V0-FNQUENTLlNMcERlcG9z_XRUb2tlbkFj\r\ndGl2YXRpb25SZXNwb25zZQBTTHBEZXBvc2l0VG9rZW5BY3RpdmF0_W9uUmVzcG9uc2U-U1BQQ1MuU0xwR2VuZXJhdGVUb2tlbkFjdGl2YXRpb25D_GFsbGVuZ2U-U0xwR2VuZXJhdGVUb2tlbkFjdGl2YXRpb25D_GFsbGVuZ2U-U1BQQ1MuU0xwR2V0R2VudWluZUJs\r\nb2I-U0xwR2V0R2VudWluZUJsb2I-U1BQQ1MuU0xwR2V0R2VudWluZUxvY2Fs-FNMcEdldEdlbnVpbmVMb2Nhb-BTUFBDUy5TTHBHZXRM_WNlbnNlQWNxdWlz_XRpb25JbmZv-FNMcEdldExpY2Vuc2VBY3F1_XNpdGlvbkluZm8-U1BQQ1MuU0xwR2V0TVNQ_WRJbmZv\r\ncm1hdGlvbgBTTHBHZXRNU1BpZEluZm9ybWF0_W9u-FNQUENTLlNMcEdldE1hY2hpbmVVR1VJR-BTTHBHZXRNYWNo_W5lVUdVSUQ-U1BQQ1MuU0xwR2V0VG9rZW5BY3RpdmF0_W9uR3JhbnRJbmZv-FNMcEdldFRv_2VuQWN0_XZhdGlvbkdyYW50SW5mbwBTUFBDUy5T\r\nTHBJQUFjdGl2YXRlUHJvZHVjd-BTTHBJQUFjdGl2YXRlUHJvZHVjd-BTUFBDUy5TTHBJc0N1cnJlbnRJbnN0YWxsZWRQcm9kdWN0S2V5RGVmYXVsdEtleQBTTHBJc0N1cnJlbnRJbnN0YWxsZWRQcm9kdWN0S2V5RGVmYXVsdEtleQBTUFBDUy5TTHBQcm9jZXNzVk1Q\r\n_XBlTWVzc2FnZQBTTHBQcm9jZXNzVk1Q_XBlTWVzc2FnZQBTUFBDUy5TTHBTZXRBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTTHBTZXRBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTUFBDUy5TTHBUcmlnZ2VyU2VydmljZVdvcmtlcgBTTHBUcmlnZ2VyU2VydmljZVdvcmtlcgBT\r\nUFBDUy5TTHBWTEFjdGl2YXRlUHJvZHVjd-BTTHBWTEFjdGl2YXRlUHJvZHVjd-------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n-------------------------------------------------------------------------------------------------------------------------------------------------------------FBg-------------Ohg--BsY---XG--------------\r\n+G---Hhg--BkY--------------MYQ--gG------------------------------iG---Kpg--------yG--------DUY--------Ihg--CqY--------Mhg--------1G---------C-FNMR2V0TGljZW5z_W5nU3RhdHVzSW5mb3JtYXRpb24--QBTTEdldFByb2R1\r\nY3RT_3VJbmZvcm1hdGlvbg--3QNMb2NhbEZyZWU-RwFTdHJTdHJOSVc--G----Bg--BzcHBjcy5kbGw----UY---S0VSTkVMMzIuZGxs-----Chg--BTSExXQVBJLmRsb-----------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n-----------------------------------------------------------B-B-----Y--C--------------------B--E----w--C--------------------B--kE--BI----WH---BwD-------------BwDN----FY-UwBf-FY-RQBS-FM-SQBP-E4-XwBJ-E4-\r\nRgBP------C9BO/+---B--U---------BQ--------------------Q-B--C--------------------f-I---E-UwB0-HI-_QBu-Gc-RgBp-Gw-ZQBJ-G4-ZgBv----W-I---E-M--0-D--OQ-w-DQ-RQ-0----eg-t--E-QwBv-G0-c-Bh-G4-eQBO-GE-bQBl----\r\n--BB-G4-bwBt-GE-b-Bv-HU-cw-g-FM-bwBm-HQ-dwBh-HI-ZQ-g-EQ-ZQB0-GU-cgBp-G8-cgBh-HQ-_QBv-G4-I-BD-G8-cgBw-G8-cgBh-HQ-_QBv-G4------D4-Cw-B-EY-_QBs-GU-R-Bl-HM-YwBy-Gk-c-B0-Gk-bwBu------Bv-Gg-bwBv-Gs-I-BT-F--\r\nU-BD-------w--g--QBG-Gk-b-Bl-FY-ZQBy-HM-_QBv-G4------D--Lg-1-C4-M--u-D-----q--U--QBJ-G4-d-Bl-HI-bgBh-Gw-TgBh-G0-ZQ---HM-c-Bw-GM------Iw-N--B-Ew-ZQBn-GE-b-BD-G8-c-B5-HI-_QBn-Gg-d----Kk-I--y-D--Mg-0-C--\r\nQQBu-G8-bQBh-Gw-bwB1-HM-I-BT-G8-ZgB0-Hc-YQBy-GU-I-BE-GU-d-Bl-HI-_QBv-HI-YQB0-Gk-bwBu-C--QwBv-HI-c-Bv-HI-YQB0-Gk-bwBu----Og-J--E-TwBy-Gk-ZwBp-G4-YQBs-EY-_QBs-GU-bgBh-G0-ZQ---HM-c-Bw-GM-LgBk-Gw-b-------\r\nL--G--E-U-By-G8-Z-B1-GM-d-BO-GE-bQBl------Bv-Gg-bwBv-Gs----0--g--QBQ-HI-bwBk-HU-YwB0-FY-ZQBy-HM-_QBv-G4----w-C4-NQ-u-D--Lg-w----R-----E-VgBh-HI-RgBp-Gw-ZQBJ-G4-ZgBv-------k--Q---BU-HI-YQBu-HM-b-Bh-HQ-\r\n_QBv-G4-------kE5-Q-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n-------Q---U----MzBIMGkwdjBSMVox------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n----------------------------------------------------------------------------------------\r\n:sppc32.dll:\r\n\r\n:========================================================================================================================================\r\n\r\n::  Replace \"-\" with \"A\" and \"_\" with \"a\" before base64 conversion\r\n::  It was changed to prevent antiviruses from detecting and flagging base64 encoding\r\n\r\n:sppc64.dll:\r\nTVqQ--M----E----//8--Lg---------Q-----------------------------------------------g-----4fug4-t-nNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4g_W4gRE9TIG1vZGUuDQ0KJ---------BQRQ--ZIYH-MDc0GQ----------P--\r\nLiIL-gIo--I----e--------ExE----Q-----JIx-g-----Q-----g--B----------G----------CQ----B---LeY---I-Y-E--C---------Q-----------Q--------E--------------Q-----F---I0Q----c---U-E---C---B4-w---D---CQ---------\r\n--------------------------------------------------------------------------------iH---Dg------------------------------------udGV4d----H-B----E-----I----E-------------------g--BgLnJkYXRh---g-----C-----C\r\n----Bg------------------Q---QC5wZGF0YQ--J------w-----g----g------------------E---E-ueGRhdGE--CQ-----Q-----I----K------------------B---B-LmVkYXRh--CNE----F-----S----D-------------------Q---QC5pZGF0YQ--\r\nU-E---Bw-----g---B4------------------E---M-ucnNyYw---HgD----g-----Q----g------------------B---D---------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n---------------------------------------------------------------------------------------------------------------------------------------------------------------------EFUU0iD7EhFMclMjQXvDw--SI1EJDjHRCQ0\r\n-----EiJRCQoSI1EJDRIiUQkIEjHRCQ4-----OgF-Q--SItMJDhIix1ZY---hcBBicR0B//TRTHk6yhEi0QkNEiNF_kP--D/FUlg--BIi0wkOEiFwHQK/9NBv-E---Dr-v/TRIngSIPESFtBXMNBVUFUVVdWU0iD7Dgx9kyLrCSQ----SIusJJg---BMiWwkIEiJz0iJ\r\nbCQo6J----BBicSFwHVEQTl1-HY+SGveKEiLVQBI-dqDeh--dChIifnoIv///4X-dRxI-10-SMdDE-E---BIx0MY-----EjHQy------SP/G67xEieBIg8Q4W15fXUFcQV3Du-E---DDkJCQkJCQkP8lel8--JCQDx+E------D/JXpf--CQk-8fh-------/yVKXw--\r\nkJD/JTpf--CQkP//////////----------D//////////w----------------------------------------------------------------------------------------------------------------------------------------------------------\r\n------------------------------------------------TgBh-G0-ZQ---Ec-cgBh-GM-ZQ------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n------------------------------------------------------------------------------------------------------------------------------------E---iB----B---CIE---ExE---x----TEQ--GRE--CB-------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------EH-w-HggMw-s----EMBw-MYggwB2-Gc-VQBM-C0----Q----------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n-----------------------------------------------------------------------------------------------------MDc0GQ-----xlI---E---BD----Qw---ChQ---0UQ--QFI--M9S--DvUg--BVM--ClT--BdUw--oVM--OlT---XV---NVQ--GdU\r\n--CdV---41Q--C1V--BhVQ--n1U--NNV---NVg--O1Y--HFW--CvVg--z1Y--PtW--CIE---UVc--G9X--CfVw--01c--BFY--BNW---b1g--KVY--DNW---BVk--EFZ--BtWQ--p1k--LtZ--D7WQ--OVo--E9_--B1Wg--nVo--NN_---HWw--PVs--Glb--ClWw--\r\n41s---1c---5X---iVw--NFc---RXQ--WV0--KNd--DxXQ--G14--Ede--CHXg--u14--Ode---rXw--W18--LVf--DrXw--J2---F1g--DiUg--/VI--BpT--BGUw--glM--MhT---DV---KVQ--FFU--CFV---w1Q---tV--BKVQ--g1U--LxV--DzVQ--J1Y--FlW\r\n--CTVg--wlY--OhW---ZVw--MVc--GNX--CKVw--vFc--PVX---yW---YVg--I1Y--C8W---7Fg--CZZ--B_WQ--jVk--LRZ--DeWQ--HVo--Ed_--BlWg--jFo--Lt_--DwWg--JVs--FZb--CKWw--x1s--Ptb---mX---ZFw--LBc--D0X---OF0--IFd--DNXQ--\r\nCV4--DRe--BqXg--pF4--NRe---MXw--Rl8--Itf--DTXw--DG---EVg--B4Y------B--I--w-E--U-Bg-H--g-CQ-K--s-D--N--4-Dw-Q-BE-Eg-T-BQ-FQ-W-Bc-G--Z-Bo-Gw-c-B0-Hg-f-C--IQ-i-CM-J--l-CY-Jw-o-Ck-Kg-r-Cw-LQ-u-C8-M--x-DI-\r\nMw-0-DU-Ng-3-Dg-OQ-6-Ds-P--9-D4-PwB--EE-QgBzcHBjLmRsb-BTUFBDUy5TTENhbGxTZXJ2ZXI-U0xDYWxsU2VydmVy-FNQUENTLlNMQ2xvc2U-U0xDbG9zZQBTUFBDUy5TTENvbnN1bWVS_Wdod-BTTENvbnN1bWVS_Wdod-BTUFBDUy5TTERlcG9z_XRN_Wdy\r\nYXRpb25CbG9i-FNMRGVwb3NpdE1pZ3JhdGlvbkJsb2I-U1BQQ1MuU0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklk-FNMRGVwb3NpdE9mZmxpbmVDb25m_XJtYXRpb25JZ-BTUFBDUy5TTERlcG9z_XRPZmZs_W5lQ29uZmlybWF0_W9uSWRFe-BTTERlcG9z_XRP\r\nZmZs_W5lQ29uZmlybWF0_W9uSWRFe-BTUFBDUy5TTERlcG9z_XRTdG9yZVRv_2Vu-FNMRGVwb3NpdFN0b3JlVG9rZW4-U1BQQ1MuU0xG_XJlRXZlbnQ-U0xG_XJlRXZlbnQ-U1BQQ1MuU0xHYXRoZXJN_WdyYXRpb25CbG9i-FNMR2F0_GVyTWlncmF0_W9uQmxvYgBT\r\nUFBDUy5TTEdhdGhlck1pZ3JhdGlvbkJsb2JFe-BTTEdhdGhlck1pZ3JhdGlvbkJsb2JFe-BTUFBDUy5TTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklk-FNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWQ-U1BQQ1MuU0xHZW5lcmF0ZU9mZmxpbmVJbnN0\r\nYWxsYXRpb25JZEV4-FNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWRFe-BTUFBDUy5TTEdldEFjdGl2ZUxpY2Vuc2VJbmZv-FNMR2V0QWN0_XZlTGljZW5zZUluZm8-U1BQQ1MuU0xHZXRBcHBs_WNhdGlvbkluZm9ybWF0_W9u-FNMR2V0QXBwbGljYXRpb25J\r\nbmZvcm1hdGlvbgBTUFBDUy5TTEdldEFwcGxpY2F0_W9uUG9s_WN5-FNMR2V0QXBwbGljYXRpb25Qb2xpY3k-U1BQQ1MuU0xHZXRBdXRoZW50_WNhdGlvblJlc3Vsd-BTTEdldEF1dGhlbnRpY2F0_W9uUmVzdWx0-FNQUENTLlNMR2V0RW5jcnlwdGVkUElERXg-U0xH\r\nZXRFbmNyeXB0ZWRQSURFe-BTUFBDUy5TTEdldEdlbnVpbmVJbmZvcm1hdGlvbgBTTEdldEdlbnVpbmVJbmZvcm1hdGlvbgBTUFBDUy5TTEdldEluc3RhbGxlZFByb2R1Y3RLZXlJZHM-U0xHZXRJbnN0YWxsZWRQcm9kdWN0S2V5SWRz-FNQUENTLlNMR2V0TGljZW5z\r\nZQBTTEdldExpY2Vuc2U-U1BQQ1MuU0xHZXRM_WNlbnNlRmlsZUlk-FNMR2V0TGljZW5zZUZpbGVJZ-BTUFBDUy5TTEdldExpY2Vuc2VJbmZvcm1hdGlvbgBTTEdldExpY2Vuc2VJbmZvcm1hdGlvbgBTTEdldExpY2Vuc2luZ1N0YXR1c0luZm9ybWF0_W9u-FNQUENT\r\nLlNMR2V0UEtleUlk-FNMR2V0UEtleUlk-FNQUENTLlNMR2V0UEtleUluZm9ybWF0_W9u-FNMR2V0UEtleUluZm9ybWF0_W9u-FNQUENTLlNMR2V0UG9s_WN5SW5mb3JtYXRpb24-U0xHZXRQb2xpY3lJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFBvbGljeUluZm9ybWF0\r\n_W9uRFdPUkQ-U0xHZXRQb2xpY3lJbmZvcm1hdGlvbkRXT1JE-FNQUENTLlNMR2V0UHJvZHVjdFNrdUluZm9ybWF0_W9u-FNMR2V0UHJvZHVjdFNrdUluZm9ybWF0_W9u-FNQUENTLlNMR2V0U0xJRExpc3Q-U0xHZXRTTElETGlzd-BTUFBDUy5TTEdldFNlcnZpY2VJ\r\nbmZvcm1hdGlvbgBTTEdldFNlcnZpY2VJbmZvcm1hdGlvbgBTUFBDUy5TTEluc3RhbGxM_WNlbnNl-FNMSW5zdGFsbExpY2Vuc2U-U1BQQ1MuU0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNl-FNMSW5zdGFsbFByb29mT2ZQdXJj_GFzZQBTUFBDUy5TTEluc3RhbGxQcm9v\r\nZk9mUHVyY2hhc2VFe-BTTEluc3RhbGxQcm9vZk9mUHVyY2hhc2VFe-BTUFBDUy5TTElzR2VudWluZUxvY2FsRXg-U0xJc0dlbnVpbmVMb2NhbEV4-FNQUENTLlNMTG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xMb2FkQXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5T\r\nTE9wZW4-U0xPcGVu-FNQUENTLlNMUGVyc2lzdEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xQZXJz_XN0QXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5TTFBlcnNpc3RSVFNQYXlsb2FkT3ZlcnJpZGU-U0xQZXJz_XN0UlRTUGF5bG9hZE92ZXJy_WRl-FNQUENTLlNMUmVB\r\ncm0-U0xSZUFybQBTUFBDUy5TTFJlZ2lzdGVyRXZlbnQ-U0xSZWdpc3RlckV2ZW50-FNQUENTLlNMUmVn_XN0ZXJQbHVn_W4-U0xSZWdpc3RlclBsdWdpbgBTUFBDUy5TTFNldEF1dGhlbnRpY2F0_W9uRGF0YQBTTFNldEF1dGhlbnRpY2F0_W9uRGF0YQBTUFBDUy5T\r\nTFNldEN1cnJlbnRQcm9kdWN0S2V5-FNMU2V0Q3VycmVudFByb2R1Y3RLZXk-U1BQQ1MuU0xTZXRHZW51_W5lSW5mb3JtYXRpb24-U0xTZXRHZW51_W5lSW5mb3JtYXRpb24-U1BQQ1MuU0xVbmluc3RhbGxM_WNlbnNl-FNMVW5pbnN0YWxsTGljZW5zZQBTUFBDUy5T\r\nTFVu_W5zdGFsbFByb29mT2ZQdXJj_GFzZQBTTFVu_W5zdGFsbFByb29mT2ZQdXJj_GFzZQBTUFBDUy5TTFVubG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xVbmxvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNQUENTLlNMVW5yZWdpc3RlckV2ZW50-FNMVW5yZWdpc3Rl\r\nckV2ZW50-FNQUENTLlNMVW5yZWdpc3RlclBsdWdpbgBTTFVucmVn_XN0ZXJQbHVn_W4-U1BQQ1MuU0xwQXV0_GVudGljYXRlR2VudWluZVRpY2tldFJlc3BvbnNl-FNMcEF1dGhlbnRpY2F0ZUdlbnVpbmVU_WNrZXRSZXNwb25zZQBTUFBDUy5TTHBCZWdpbkdlbnVp\r\nbmVU_WNrZXRUcmFuc2FjdGlvbgBTTHBCZWdpbkdlbnVpbmVU_WNrZXRUcmFuc2FjdGlvbgBTUFBDUy5TTHBDbGVhckFjdGl2YXRpb25JblByb2dyZXNz-FNMcENsZWFyQWN0_XZhdGlvbkluUHJvZ3Jlc3M-U1BQQ1MuU0xwRGVwb3NpdERvd25sZXZlbEdlbnVpbmVU\r\n_WNrZXQ-U0xwRGVwb3NpdERvd25sZXZlbEdlbnVpbmVU_WNrZXQ-U1BQQ1MuU0xwRGVwb3NpdFRv_2VuQWN0_XZhdGlvblJlc3BvbnNl-FNMcERlcG9z_XRUb2tlbkFjdGl2YXRpb25SZXNwb25zZQBTUFBDUy5TTHBHZW5lcmF0ZVRv_2VuQWN0_XZhdGlvbkNoYWxs\r\nZW5nZQBTTHBHZW5lcmF0ZVRv_2VuQWN0_XZhdGlvbkNoYWxsZW5nZQBTUFBDUy5TTHBHZXRHZW51_W5lQmxvYgBTTHBHZXRHZW51_W5lQmxvYgBTUFBDUy5TTHBHZXRHZW51_W5lTG9jYWw-U0xwR2V0R2VudWluZUxvY2Fs-FNQUENTLlNMcEdldExpY2Vuc2VBY3F1\r\n_XNpdGlvbkluZm8-U0xwR2V0TGljZW5zZUFjcXVpc2l0_W9uSW5mbwBTUFBDUy5TTHBHZXRNU1BpZEluZm9ybWF0_W9u-FNMcEdldE1TUGlkSW5mb3JtYXRpb24-U1BQQ1MuU0xwR2V0TWFj_GluZVVHVUlE-FNMcEdldE1hY2hpbmVVR1VJR-BTUFBDUy5TTHBHZXRU\r\nb2tlbkFjdGl2YXRpb25HcmFudEluZm8-U0xwR2V0VG9rZW5BY3RpdmF0_W9uR3JhbnRJbmZv-FNQUENTLlNMcElBQWN0_XZhdGVQcm9kdWN0-FNMcElBQWN0_XZhdGVQcm9kdWN0-FNQUENTLlNMcElzQ3VycmVudEluc3RhbGxlZFByb2R1Y3RLZXlEZWZhdWx0S2V5\r\n-FNMcElzQ3VycmVudEluc3RhbGxlZFByb2R1Y3RLZXlEZWZhdWx0S2V5-FNQUENTLlNMcFByb2Nlc3NWTVBpcGVNZXNzYWdl-FNMcFByb2Nlc3NWTVBpcGVNZXNzYWdl-FNQUENTLlNMcFNldEFjdGl2YXRpb25JblByb2dyZXNz-FNMcFNldEFjdGl2YXRpb25JblBy\r\nb2dyZXNz-FNQUENTLlNMcFRy_WdnZXJTZXJ2_WNlV29y_2Vy-FNMcFRy_WdnZXJTZXJ2_WNlV29y_2Vy-FNQUENTLlNMcFZMQWN0_XZhdGVQcm9kdWN0-FNMcFZMQWN0_XZhdGVQcm9kdWN0--------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n----------------------------------------UH--------------IHE--Ihw--Boc--------------wcQ--oH---Hhw-------------ERx--Cwc-----------------------------D-c--------OJw--------------------cQ------------------\r\nDHE------------------MBw--------4n--------------------Bx-------------------McQ-------------------gBTTEdldExpY2Vuc2luZ1N0YXR1c0luZm9ybWF0_W9u--E-U0xHZXRQcm9kdWN0U2t1SW5mb3JtYXRpb24--OgDTG9jYWxGcmVl-FEB\r\nU3RyU3RyTklX--Bw----c---c3BwY3MuZGxs----FH---EtFUk5FTDMyLmRsb------oc---U0hMV0FQSS5kbGw-----------------------------------------------------------------------------------------------------------------\r\n----------------------------------------------------------------------------------------------------------------------------------------------E-E----Bg--I--------------------E--Q---D---I--------------\r\n------E-CQQ--Eg---BYg---H-M-------------H-M0----VgBT-F8-VgBF-FI-UwBJ-E8-TgBf-Ek-TgBG-E8------L0E7/4---E-BQ---------F--------------------B--E--I-------------------B8-g---QBT-HQ-cgBp-G4-ZwBG-Gk-b-Bl-Ek-\r\nbgBm-G8---BY-g---Q-w-DQ-M--5-D--N-BF-DQ---B6-C0--QBD-G8-bQBw-GE-bgB5-E4-YQBt-GU------EE-bgBv-G0-YQBs-G8-dQBz-C--UwBv-GY-d-B3-GE-cgBl-C--R-Bl-HQ-ZQBy-Gk-bwBy-GE-d-Bp-G8-bg-g-EM-bwBy-H--bwBy-GE-d-Bp-G8-\r\nbg------Pg-L--E-RgBp-Gw-ZQBE-GU-cwBj-HI-_QBw-HQ-_QBv-G4------G8-_-Bv-G8-_w-g-FM-U-BQ-EM------D--C--B-EY-_QBs-GU-VgBl-HI-cwBp-G8-bg------M--u-DU-Lg-w-C4-M----Co-BQ-B-Ek-bgB0-GU-cgBu-GE-b-BO-GE-bQBl----\r\ncwBw-H--Yw------j--0--E-T-Bl-Gc-YQBs-EM-bwBw-Hk-cgBp-Gc-_-B0----qQ-g-DI-M--y-DQ-I-BB-G4-bwBt-GE-b-Bv-HU-cw-g-FM-bwBm-HQ-dwBh-HI-ZQ-g-EQ-ZQB0-GU-cgBp-G8-cgBh-HQ-_QBv-G4-I-BD-G8-cgBw-G8-cgBh-HQ-_QBv-G4-\r\n---6--k--QBP-HI-_QBn-Gk-bgBh-Gw-RgBp-Gw-ZQBu-GE-bQBl----cwBw-H--Yw-u-GQ-b-Bs-------s--Y--QBQ-HI-bwBk-HU-YwB0-E4-YQBt-GU------G8-_-Bv-G8-_w---DQ-C--B-F--cgBv-GQ-dQBj-HQ-VgBl-HI-cwBp-G8-bg---D--Lg-1-C4-\r\nM--u-D----BE-----QBW-GE-cgBG-Gk-b-Bl-Ek-bgBm-G8------CQ-B----FQ-cgBh-G4-cwBs-GE-d-Bp-G8-bg------CQTkB---------------------------------------------------------------------------------------------------\r\n----------------------------------------------------------------------------------------\r\n:sppc64.dll:\r\n\r\n:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n\r\n:TSforgeActivation\r\n\r\n::  To activate Windows, run the script with \"/Z-Windows\" parameter or change 0 to 1 in below line\r\nset _actwin=0\r\n\r\n::  To activate Windows ESU, run the script with \"/Z-ESU\" parameter or change 0 to 1 in below line\r\nset _actesu=0\r\n\r\n::  To activate all Office apps (including Project/Visio), run the script with \"/Z-Office\" parameter or change 0 to 1 in below line\r\nset _actoff=0\r\n\r\n::  To activate only Project/Visio, run the script with \"/Z-ProjectVisio\" parameter or change 0 to 1 in below line\r\nset _actprojvis=0\r\n\r\n::  To activate all Windows/ESU/Office, run the script with \"/Z-WindowsESUOffice\" parameter or change 0 to 1 in below line\r\nset _actwinesuoff=0\r\n\r\n::  Advanced options:\r\n::  To activate Windows K-M-S host (csvlk), run the script with \"/Z-WinHost\" parameter or change 0 to 1 in below line\r\nset _actwinhost=0\r\n\r\n::  To activate Office K-M-S host (csvlk), run the script with \"/Z-OffHost\" parameter or change 0 to 1 in below line\r\nset _actoffhost=0\r\n\r\n::  To activate Windows 8/8.1 APPX Sideloading (APPXLOB), run the script with \"/Z-APPX\" parameter or change 0 to 1 in below line\r\nset _actappx=0\r\n\r\n::  To activate certain activation IDs, change 0 to 1 in below line and set activation IDs in \"tsids\" variable, you can enter multiple by adding a space after each of them\r\n::  or run the script with \"/Z-ID-ActivationIdGoesHere\" parameter. If you want to add multiple through parameter, pass each of them in separate parameters\r\nset _actman=\r\nset tsids=\r\n\r\n::  To reset rearm counter, evaluation period and clear the tamper state, key lock, run the script with \"/Z-Reset\" parameter or change 0 to 1 in below line\r\nset _resall=0\r\n\r\n::  Choose activation method:\r\n::  In builds 26100 and later, the script will auto select StaticCID (requires internet). If no internet is detected, it will then auto select the KMS4k method. For builds lower than 26100, the script will auto select ZeroCID.\r\n::  To change the activation method, run the script with the parameters \"/Z-SCID\", \"/Z-ZCID\", or \"/Z-KMS4k\", or modify the option from Auto to SCID, ZCID, or KMS4k in the line below.\r\nset _actmethod=Auto\r\n\r\n::  Debug Mode:\r\n::  To run the script in debug mode, change 0 to any parameter above that you want to run, in below line\r\nset \"_debug=0\"\r\n\r\n::  Script will run in unattended mode if parameters are used OR value is changed in above lines.\r\n::  If multiple options are selected then script will only pick one from the advanced option.\r\n\r\n\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\nset KS=K%blank%MS\r\ntitle  TSforge Activation %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args for %%A in (%_args%) do (\r\nif /i \"%%A\"==\"-el\"                     (set _elev=1)\r\nif /i \"%%A\"==\"/Z-Windows\"              (set _actwin=1)\r\nif /i \"%%A\"==\"/Z-ESU\"                  (set _actesu=1)\r\nif /i \"%%A\"==\"/Z-Office\"               (set _actoff=1)\r\nif /i \"%%A\"==\"/Z-ProjectVisio\"         (set _actprojvis=1)\r\nif /i \"%%A\"==\"/Z-WindowsESUOffice\"     (set _actwinesuoff=1)\r\nif /i \"%%A\"==\"/Z-WinHost\"              (set _actwinhost=1)\r\nif /i \"%%A\"==\"/Z-OffHost\"              (set _actoffhost=1)\r\nif /i \"%%A\"==\"/Z-APPX\"                 (set _actappx=1)\r\necho \"%%A\" | find /i \"/Z-ID-\"  >nul && (set _actman=1& set \"filtsids=%%A\" & call set \"filtsids=%%filtsids:~6%%\" & if defined filtsids call set tsids=%%filtsids%% %%tsids%%)\r\nif /i \"%%A\"==\"/Z-Reset\"                (set _resall=1)\r\nif /i \"%%A\"==\"/Z-SCID\"                 (set _actmethod=SCID)\r\nif /i \"%%A\"==\"/Z-ZCID\"                 (set _actmethod=ZCID)\r\nif /i \"%%A\"==\"/Z-KMS4k\"                (set _actmethod=KMS4k)\r\n)\r\n\r\nif not defined tsids set _actman=0\r\nfor %%A in (%_actwin% %_actesu% %_actoff% %_actprojvis% %_actwinesuoff% %_actwinhost% %_actoffhost% %_actappx% %_actman% %_resall%) do (if \"%%A\"==\"1\" set _unattended=1)\r\nif /i not %_actmethod%==Auto set _unattended=1\r\n\r\nif %winbuild% LSS 7600 (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5\" /v Install %nul2% | find /i \"0x1\" %nul1% || (\r\n%eline%\r\necho .NET 3.5 Framework is not installed in your system.\r\necho Install it using the following URL.\r\necho:\r\necho https://www.microsoft.com/en-us/download/details.aspx?id=25150\r\nif %_unattended%==0 start https://www.microsoft.com/en-us/download/details.aspx?id=25150\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_menu\r\n\r\nif %_unattended%==0 (\r\ncls\r\nif not defined terminal mode 76, 33\r\ntitle  TSforge Activation %masver%\r\n\r\necho:\r\necho:\r\necho:\r\necho        ______________________________________________________________\r\necho: \r\necho               [1] Activate - Windows\r\necho               [2] Activate - ESU\r\necho               [3] Activate - Office [All]\r\necho               [4] Activate - Office [Project/Visio]\r\necho               [5] Activate - All\r\necho               _______________________________________________  \r\necho: \r\necho                   Advanced Options:\r\necho:\r\necho               [A] Activate - Windows %KS% Host\r\necho               [B] Activate - Office %KS% Host\r\necho               [C] Activate - Windows 8/8.1 APPX Sideloading\r\necho               [D] Activate - Manually Select Products\r\nif defined _vis (\r\necho               [E] Reset    - Rearm/Timers\r\n) else (\r\necho               [E] Reset    - Rearm/Timers/Tamper/Lock\r\n)\r\necho               [F] Change   - Activation Method [%_actmethod%]\r\necho               _______________________________________________       \r\necho:\r\necho               [6] Remove TSforge Activation\r\necho               [7] Download Office\r\necho               [0] %_exitmsg%\r\necho        ______________________________________________________________\r\necho:\r\ncall :dk_color2 %_White% \"            \" %_Green% \"Choose a menu option using your keyboard...\"\r\nchoice /C:12345ABCDEF670 /N\r\nset _el=!errorlevel!\r\n\r\nif !_el!==14 exit /b\r\nif !_el!==13 start %mas%genuine-installation-media & goto :ts_menu\r\nif !_el!==12 call :ts_remove & cls & goto :ts_menu\r\nif !_el!==11 goto :ts_changemethod\r\nif !_el!==10 cls & setlocal & set \"_resall=1\"       & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==9  cls & setlocal & set \"_actman=1\"       & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==8  cls & setlocal & set \"_actappx=1\"      & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==7  cls & setlocal & set \"_actoffhost=1\"   & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==6  cls & setlocal & set \"_actwinhost=1\"   & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==5  cls & setlocal & set \"_actwinesuoff=1\" & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==4  cls & setlocal & set \"_actprojvis=1\"   & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==3  cls & setlocal & set \"_actoff=1\"       & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==2  cls & setlocal & set \"_actesu=1\"       & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==1  cls & setlocal & set \"_actwin=1\"       & call :ts_start & endlocal & cls & goto :ts_menu\r\ngoto :ts_menu\r\n)\r\n\r\ngoto :ts_start\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_changemethod\r\n\r\ncls\r\nif not defined terminal mode 76, 36\r\n\r\necho:\r\necho:\r\necho:\r\necho        ______________________________________________________________\r\necho: \r\ncall :dk_color2 %_White% \"             [1] \" %_Green% \"Auto\"\r\necho                  Builds ^>= 26100 - StaticCID (KMS4k if offline)\r\necho                  Builds ^<  26100 - ZeroCID\r\necho              __________________________________________________\r\necho: \r\necho              [2] StaticCID\r\necho                  Needs Internet\r\necho                  Not for Windows 7 or older\r\necho              __________________________________________________\r\necho:\r\necho              [3] ZeroCID\r\necho                  Works reliably on builds below 26100\r\necho                  Does not work on builds above 26100.4188\r\necho              __________________________________________________\r\necho:\r\necho              [4] KMS4k\r\necho                  Volume licenses only\r\necho                  Activates for 4000+ years\r\necho              __________________________________________________\r\necho:\r\necho              [5] Learn More\r\necho              [0] %_exitmsg%\r\necho        ______________________________________________________________\r\necho:\r\ncall :dk_color2 %_White% \"            \" %_Green% \"Choose a menu option using your keyboard...\"\r\nchoice /C:123450 /N\r\nset _el=!errorlevel!\r\n\r\nif !_el!==6 goto :ts_menu\r\nif !_el!==5  cls & start %mas%tsforge &goto :ts_menu\r\nif !_el!==4  cls & set \"_actmethod=KMS4k\" & goto :ts_menu\r\nif !_el!==3  cls & set \"_actmethod=ZCID\"  & goto :ts_menu\r\nif !_el!==2  cls & set \"_actmethod=SCID\"  & goto :ts_menu\r\nif !_el!==1  cls & set \"_actmethod=Auto\"  & goto :ts_menu\r\ngoto :ts_changemethod\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_start\r\n\r\ncls\r\n\r\nif %_actwinesuoff%==1 (set height=38) else (set height=32)\r\nif not defined terminal (\r\nmode 125, %height%\r\nif exist \"%SysPath%\\spp\\store_test\\\" mode 134, %height%\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=%height%;$B.Height=300;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\ntitle  TSforge Activation %masver%\r\n\r\necho:\r\necho Initializing...\r\ncall :dk_chkmal\r\n\r\nif not exist %SysPath%\\%_slexe% (\r\n%eline%\r\necho [%SysPath%\\%_slexe%] file is missing, aborting...\r\necho:\r\nif not defined results (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options.\"\r\ncall :dk_color %Blue% \"After that, restart system and try activation again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If it still shows the same error, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\ngoto dk_done\r\n)\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"[System.Environment]::Version.Major\" %nul6%') do if \"%%a\"==\"2\" (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5\" /v Install %nul2% | find /i \"0x1\" %nul1% || (\r\n%eline%\r\necho .NET 3.5 Framework is corrupt or missing. Aborting...\r\nif exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-Embedded\" (\r\necho Install .NET Framework 4.8 and Windows Management Framework 5.1\r\n)\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 9200 if exist \"%SysPath%\\wlms\\wlms.exe\" (\r\nsc query wlms | find /i \"RUNNING\" %nul% && (\r\nsc stop %_slser% %nul%\r\nif !errorlevel! EQU 1051 (\r\n%eline%\r\necho Evaluation WLMS service is running, %_slser% service can not be stopped. Aborting...\r\necho Install Non-Eval version for Windows build %winbuild%.\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_actwinesuoff%==1 (set \"_actwin=1\" & set \"_actesu=1\" & set \"_actoff=1\")\r\nif %_actprojvis%==1   (set \"_actoff=1\")\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_ckeckwmic\r\ncall :dk_checksku\r\ncall :dk_product\r\ncall :dk_sppissue\r\n\r\n::========================================================================================================================================\r\n\r\nset error=\r\n\r\ncls\r\necho:\r\ncall :dk_showosinfo\r\n\r\nif /i %_actmethod%==SCID set tsmethod=StaticCID\r\nif /i %_actmethod%==ZCID set tsmethod=ZeroCID\r\nif /i %_actmethod%==KMS4k set tsmethod=KMS4k\r\n\r\nif /i %_actmethod%==Auto (\r\nif %winbuild% GEQ 26100 (\r\nset tsmethod=StaticCID\r\n) else (\r\nset tsmethod=ZeroCID\r\n)\r\n)\r\n\r\nif %winbuild% LSS 9200 if /i %tsmethod%==StaticCID (\r\n%eline%\r\necho StaticCID method is supported only on Windows 8 and later.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Internet connection\r\n\r\nif /i %tsmethod%==StaticCID (\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)\r\n)\r\n\r\nif defined _int (\r\necho Checking Internet Connection            [Connected!ping_f!]\r\n) else (\r\nif /i %_actmethod%==Auto if not %_actman%==1 set tsmethod=KMS4k\r\nif /i !tsmethod!==KMS4k (\r\ncall :dk_color %Red% \"Checking Internet Connection            [Not Connected]\"\r\ncall :dk_color %Blue% \"Switching To KMS4k activation because Internet is needed for StaticCID method.\"\r\n) else (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Internet Connection            [Not Connected]\"\r\ncall :dk_color %Blue% \"Internet is required for TSforge StaticCID option.\"\r\n)\r\necho:\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\necho Initiating Diagnostic Tests...\r\n\r\nset \"_serv=%_slser% Winmgmt\"\r\n\r\n::  Software Protection\r\n::  Windows Management Instrumentation\r\n\r\ncall :dk_errorcheck\r\n\r\ncall :ts_getedition\r\nif not defined tsedition (\r\ncall :dk_color %Red% \"Checking Windows Edition ID             [Not found in installed licenses, aborting...]\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto :dk_done\r\n)\r\n\r\nif /i !tsmethod!==KMS4k (\r\ncall :_taskclear-cache\r\necho Clearing %KS% Cache                      [Successful]\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_resall%==1 goto :ts_resetall\r\nif %_actman%==1 goto :ts_actman\r\nif %_actappx%==1 goto :ts_appxlob\r\nif %_actwinhost%==1 goto :ts_whost\r\nif %_actoffhost%==1 goto :ts_ohost\r\nif not %_actwin%==1 goto :ts_esu\r\n\r\n::========================================================================================================================================\r\n\r\n::  Process Windows\r\n::  Check if system is permanently activated or not\r\n\r\necho:\r\necho Processing Windows...\r\n\r\necho %tsedition% | find /i \"Eval\" %nul1% && (\r\ngoto :ts_wineval\r\n)\r\n\r\nset /a UBR=0\r\nif %winbuild% EQU 26100 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR %nul6%') do if not errorlevel 1 set /a UBR=%%b\r\nif !UBR! LSS 4188 (set dontcheckact=1)\r\n)\r\n\r\nif not defined dontcheckact call :ts_checkwinperm\r\nif defined _perm (\r\ncall :dk_color %Gray% \"Checking OS Activation                  [Windows is already permanently activated]\"\r\ngoto :ts_esu\r\n)\r\n\r\nif %winbuild% LSS 9200 if /i %tsmethod%==KMS4k goto :ts_oldks\r\nif defined _vis goto :ts_winvista\r\n\r\nset tempid=\r\nif /i %tsmethod%==KMS4k (set keytype=ks) else (set keytype=zero)\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wintsid\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (\r\necho \"%%a\" | findstr /r \".*-.*-.*-.*-.*\" %nul1% && (set tsids=!tsids! %%a& set tempid=%%a)\r\n)\r\n\r\nif defined tempid (\r\necho Checking Activation ID                  [%tempid%] [%tsedition%]\r\n) else (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Not Found] [%tsedition%] [%osSKU%]\"\r\nset error=1\r\nif /i %tsmethod%==KMS4k (\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\n)\r\ngoto :ts_esu\r\n)\r\n\r\nif defined winsub (\r\ncall :dk_color %Blue% \"Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%].\"\r\necho:\r\n)\r\n\r\ngoto :ts_esu\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_oldks\r\n\r\n::  KMS keys for KMS4k method because TSforge cannot install KMS key on Windows Vista and 7\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = Generic key\r\n::  3rd column = Edition ID\r\n::  Separator  = _\r\n\r\nset f=\r\nset key=\r\nset tempid=\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nfor %%# in (\r\n:: Windows 7\r\nae2ee509-1b34-41c0-acb7-6d4650168915_33PXH-7Y6KF-2VJC9-XBBR8-HV%f%THH_Enterprise\r\n1cb6d605-11b3-4e14-bb30-da91c8e3983a_YDRBP-3D83W-TY26F-D46B2-XC%f%KRJ_EnterpriseN\r\nb92e9980-b9d5-4821-9c94-140f632f6312_FJ82H-XT6CR-J8D7P-XQJJ2-GP%f%DD4_Professional\r\n54a09a0d-d57b-4c10-8b69-a842d6590ad5_MRPKT-YTG23-K7D7T-X2JMM-QY%f%7MG_ProfessionalN\r\ndb537896-376f-48ae-a492-53d0547773d0_YBYF6-BHCR3-JPKRB-CDW7B-F9%f%BK4_Embedded_POSReady\r\naa6dd3aa-c2b4-40e2-a544-a6bbb3f5c395_73KQT-CD9G6-K7TQG-66MRP-CQ%f%22C_Embedded_ThinPC\r\n5a041529-fef8-4d07-b06f-b59b573b32d2_W82YF-2Q76Y-63HXB-FGJG9-GF%f%7QX_ProfessionalE\r\n46bbed08-9c7b-48fc-a614-95250573f4ea_C29WB-22CC8-VJ326-GHFJW-H9%f%DH4_EnterpriseE\r\n:: Windows Server 2008 R2\r\n68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC_ServerStandard\r\n7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648_ServerDatacenter\r\n620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y_ServerEnterprise\r\n7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648_ServerDatacenterCore\r\n68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC_ServerStandardCore\r\n620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y_ServerEnterpriseCore\r\n8a26851c-1c7e-48d3-a687-fbca9b9ac16b_GT63C-RJFQ3-4GMB6-BRFB9-CB%f%83V_ServerEnterpriseIA64\r\na78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4_ServerWeb\r\ncda18cf3-c196-46ad-b289-60c072869994_TT8MH-CG224-D3D7Q-498W2-9Q%f%CTX_ServerHPC\r\na78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4_ServerWebCore\r\nf772515c-0e87-48d5-a676-e6962c3e1195_736RG-XDKJK-V34PF-BHK87-J6%f%X3K_ServerEmbeddedSolution\r\n:: Windows Vista\r\ncfd8ff08-c0d7-452b-9f60-ef5c70c32094_VKK3X-68KWM-X2YGT-QR4M6-4B%f%WMV_Enterprise\r\n4f3d1606-3fea-4c01-be3c-8d671c401e3b_YFKBB-PQJJV-G996G-VWGXY-2V%f%3X8_Business\r\n2c682dc2-8b68-4f63-a165-ae291d4cf138_HMBQG-8H2RH-C77VX-27R82-VM%f%QBT_BusinessN\r\nd4f54950-26f2-4fb4-ba21-ffab16afcade_VTC42-BM838-43QHV-84HX6-XJ%f%XKV_EnterpriseN\r\n:: Windows Server 2008\r\nad2542d4-9154-4c6d-8a44-30f11ee96989_TM24T-X9RMF-VWXK6-X8JC9-BF%f%GM2_ServerStandard\r\n68b6e220-cf09-466b-92d3-45cd964b9509_7M67G-PC374-GR742-YH8V4-TC%f%BY3_ServerDatacenter\r\nc1af4d90-d1bc-44ca-85d4-003ba33db3b9_YQGMW-MPWTJ-34KDK-48M3W-X4%f%Q6V_ServerEnterprise\r\n01ef176b-3e0d-422a-b4f8-4ea880035e8f_4DWFP-JF3DJ-B7DTH-78FJB-PD%f%RHK_ServerEnterpriseIA64\r\nddfa9f7c-f09e-40b9-8c1a-be877a9a7f4b_WYR28-R7TFJ-3X2YQ-YCY4H-M2%f%49D_ServerWeb\r\n7afb1156-2c1d-40fc-b260-aab7442b62fe_RCTX3-KWVHP-BR6TB-RB6DM-6X%f%7HP_ServerComputeCluster\r\n2401e3d0-c50a-4b58-87b2-7e794b7d2607_W7VD6-7JFBR-RX26B-YKQ3Y-6F%f%FFJ_ServerStandardV\r\nfd09ef77-5647-4eff-809c-af2b64659a45_22XQ2-VRXRG-P8D42-K34TD-G3%f%QQC_ServerDatacenterV\r\n8198490a-add0-47b2-b3ba-316b12d647b4_39BXF-X8Q23-P2WWT-38T2F-G3%f%FPG_ServerEnterpriseV\r\n) do (\r\nfor /f \"tokens=1-3 delims=_\" %%A in (\"%%#\") do if %tsedition%==%%C if not defined key (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\nset key=%%B\r\nset tempid=%%A\r\n)\r\n)\r\n)\r\n\r\nif not defined key (\r\ncall :dk_color %Red% \"Checking Activation ID                  [%tsedition% SKU-%osSKU% %KS% key is not available]\"\r\ncall :dk_color %Blue% \"Use ZeroCID activation method from the previous menu.\"\r\ngoto :ts_esu\r\n)\r\n\r\necho Checking Activation ID                  [%tempid%] [%tsedition%]\r\n\r\nset oldks=1\r\nset generickey=1\r\ncall :dk_inskey \"[%key%]\"\r\nset tsids=%tsids% %tempid%\r\ngoto :ts_esu\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_winvista\r\n\r\n::  Process Windows Vista\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = Generic key\r\n::  3rd column = Key channel\r\n::  4th column = Edition ID\r\n::  Separator  = _\r\n\r\n::  Keys aren't available for these editions, but since these editions aren't publicly available, it doesn't matter\r\n::  a797d61e-1475-470b-86c8-f737a72c188d StarterN\r\n::  5e9f548a-c8a9-44e6-a6c2-3f8d0a7a99dd ServerComputeClusterV\r\n\r\nset f=\r\nset key=\r\nset tempid=\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nfor %%# in (\r\n::  WindowsVista\r\n9de9abe2-d01d-4538-af84-4498bdbc2ba3_4D2XH-PRBMM-8Q22B-K8BM3-MR%f%W4W_____Retail_Business\r\ndb442be4-81ed-4ab3-9d66-2417e8a5c81c_76884-QXFY2-6Q2WX-2QTQ8-QX%f%X44_____Retail_BusinessN\r\nb51791c2-b562-4b73-97b0-735a0e4429a6_YQPQV-RW8R3-XMPFG-RXG9R-JG%f%TVF_____Retail_Enterprise\r\n58c37517-42f8-4723-bb44-30b05791ff2a_Q7J9R-G63R4-BFMHF-FWM9R-RW%f%DMV_____Retail_EnterpriseN\r\n95c6e80a-0ff8-4bd0-95f2-c4a39b79d09e_RCG7P-TX42D-HM8FM-TCFCW-3V%f%4VD_____Retail_HomeBasic\r\nd0333dad-c14e-46f2-b62a-8b47a1b9768b_HY2VV-XC6FF-MD6WV-FPYBQ-GF%f%JBT_____Retail_HomeBasicN\r\n9e042223-03bf-49ae-808f-ff37f128d40d_X9HTF-MKJQQ-XK376-TJ7T4-76%f%PKF_____Retail_HomePremium\r\n92d8977c-d506-4e63-b500-6d39283b6cd5_KJ6TP-PF9W2-23T3Q-XTV7M-PX%f%DT2_____Retail_HomePremiumN\r\n89e51a3c-76c0-4beb-a650-53d34c8f8186_X9PYV-YBQRV-9BXWV-TQDMK-QD%f%WK4_____Retail_Starter\r\n30fab9cc-8614-4339-989f-7ce61fb7a5c4_VMCB9-FDRV6-6CDQM-RV23K-RP%f%8F7_____Retail_Ultimate\r\n1eefed20-8ac0-478c-8774-70cd44782ea1_CVX38-P27B4-2X8BT-RXD4J-V7%f%CKX_____Retail_UltimateN\r\n::  WindowsServer2008\r\nc9ad502b-ef48-41d1-a2a0-38a38e82fed0_24FV9-H7JW8-C8Q6X-BQKMK-K9%f%77J_____Retail_ServerComputeCluster\r\n866e924e-c2a3-4872-aca1-6b48c13962d5_6QBHY-DXTPJ-T9W3P-DTJXX-4V%f%QMB_____Retail_ServerDatacenter\r\nd020c729-07f0-4f8f-87ce-bf803275c786_83TWG-TD3TC-HRDP2-K93FJ-Y3%f%4YC_OEM:NONSLP_ServerDatacenterV\r\n32b40e5e-0c6d-4c6f-ab12-a031933fd2c6_MRB7H-QJRHG-FXTBR-B2Q2M-8W%f%MTJ_____Retail_ServerEnterprise\r\n256cc990-1692-4ea8-965c-2d423d5dd24e_H4VB6-QPRWH-VDCYM-996P8-MH%f%KFY_OEM:NONSLP_ServerEnterpriseIA64\r\n1ba5e036-e386-42c4-b7eb-16bdb4fa1945_H8H7M-HDPQT-PJHQF-M7B83-9C%f%VGV_____Retail_ServerEnterpriseV\r\n8df04457-07c8-4301-bce9-d61eb76cb2d6_RGBMC-PQBVF-94Q9K-HD63B-VY%f%6MP_____Retail_ServerHomePremium\r\n5bd23b19-aa71-4a5b-8b68-c8801c2baff6_6C8KR-MD3QK-9GWFW-44CY2-W9%f%CBM_____Retail_ServerHomeStandard\r\nb86c7736-91ff-4de9-bfa9-b32b8a09acac_7XRBY-6MP2K-VQPT8-F37JV-YY%f%Q83_____Retail_ServerMediumBusinessManagement\r\nd3f5642f-081d-40b2-a4b9-efd3054d4584_6PDTD-JK48J-662TF-8J2QV-R4%f%CRB_____Retail_ServerMediumBusinessMessaging\r\nc6936a36-69f3-4994-9857-3069c7b9ec7a_D694V-CMWKH-PY92X-PFQKQ-JC%f%B69_____Retail_ServerMediumBusinessSecurity\r\ncc4c2cf8-ef29-4d8e-b168-2b65a3db3309_MRDK3-YYQF3-88BQJ-D6FJG-69%f%YJY_____Retail_ServerSBSPremium\r\nb3827b27-bd38-4284-98af-e4f4d1c051a0_2KB23-GJRBD-W3T9C-6CH2W-39%f%B7V_____Retail_ServerSBSPrime\r\n5dad0eff-3f6f-4310-8844-422f9dc7c84b_H4XDD-B27GY-667P6-XWVV7-GY%f%G8J_____Retail_ServerSBSStandard\r\n603504f9-109f-49f0-9271-8c66f7878f58_8YVM4-YQBDH-7WDQM-R27WR-WV%f%CWG_____Retail_ServerStandard\r\n65ab7338-9ad0-43fe-af1b-190b577495e2_H9MW3-6V7GK-94P9G-7FTPJ-VK%f%CKF_____Retail_ServerStandardV\r\n2be204da-24a0-4943-b66c-81e8464acd7e_2264C-TD9T8-P8HPW-CC9GH-MH%f%M2V_____Retail_ServerStorageEnterprise\r\n60207eba-8b4a-486c-a013-023b4b742c2f_RCYMT-YX342-8T6YY-XYHYC-3D%f%D7X_____Retail_ServerStorageExpress\r\n368856e9-43f7-4601-8358-e561f36c7dd8_FKFT2-WXYY9-WBPY7-6YMY4-X4%f%8JF_____Retail_ServerStorageStandard\r\n4bf433fa-ab04-4c6c-b55b-00170e14b8cd_8X9J7-HCJ7J-3WDJT-QM7D8-46%f%4YH_____Retail_ServerStorageWorkgroup\r\na77a6806-f59e-4953-97d7-229317b8e6a6_BGT39-9FYH7-X2CYD-T628F-QP%f%QPW_____Retail_ServerWeb\r\nf92f836d-4d3e-4e90-a08f-2d612d65e716_HPH76-FHFPP-DRW9D-7W2V4-HW%f%GKT_____Retail_ServerWinSB\r\n3059a9fd-b068-4f0d-acaf-66324dca67ac_2V8G6-KRXYR-MMGXJ-6RWM3-GX%f%CCG_____Retail_ServerWinSBV\r\n) do (\r\nfor /f \"tokens=1-4 delims=_\" %%A in (\"%%#\") do if %tsedition%==%%D if not defined key (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\nset key=%%B\r\nset tempid=%%A\r\n)\r\n)\r\n)\r\n\r\nif not defined key (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Activation ID                  [%tsedition% SKU-%osSKU% not found in the system]\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ngoto :ts_esu\r\n)\r\n\r\necho Checking Activation ID                  [%tempid%] [%tsedition%]\r\n\r\nset generickey=1\r\ncall :dk_inskey \"[%key%]\"\r\nset tsids=%tsids% %tempid%\r\ngoto :ts_esu\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_wineval\r\n\r\ncall :dk_color %Gray% \"Checking OS Edition                     [%tsedition%] [Evaluation edition found]\"\r\ncall :dk_color %Blue% \"Evaluation editions cannot be activated outside of evaluation period.\"\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" (\r\ncall :dk_color %Blue% \"Script will reset evaluation period, but to permanently activate Windows,\"\r\ncall :dk_color %Blue% \"Go back to main menu and use [Change Edition] option and change to Non-eval edition.\"\r\n) else (\r\ncall :dk_color %Blue% \"Script will reset evaluation period, but to permanently activate Windows, install Non-eval edition.\"\r\ncall :dk_color %_Yellow% \"%mas%evaluation_editions\"\r\n)\r\n\r\n::  Check Internet connection\r\n\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)\r\n)\r\n\r\nif defined _int (\r\necho Checking Internet Connection            [Connected%ping_f%]\r\n) else (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Internet Connection            [Not Connected]\"\r\ncall :dk_color %Blue% \"Internet is required for Windows Evaluation activation.\"\r\n)\r\n\r\n::  List of products lacking activable evaluation keys and ISOs\r\n\r\n::  c4b908d2-c4b9-439d-8ff0-48b656a24da4_EmbeddedIndustryEEval_8.1\r\n::  9b74255b-afe1-4da7-a143-98d1874b2a6c_EnterpriseNEval_8\r\n::  7fd0a88b-fb89-415f-9b79-84adc6a7cd56_EnterpriseNEval_8.1\r\n::  994578eb-193c-4c99-bea0-2483274c9afd_EnterpriseSNEval_2015\r\n::  b9f3109c-bfa9-4f37-9824-6dba9ee62056_ServerStorageStandardEval_2012R2\r\n::  2d3b7269-65f4-467d-9d51-dbe0e5a4e668_ServerStorageWorkgroupEval_2012R2\r\n\r\n:: --------\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = Activable evaluation key\r\n::  3rd column = Edition ID\r\n::  4th column = Windows version (for reference only)\r\n::  5th column = NoAct = activation is not working\r\n::  Separator  = _\r\n\r\nset f=\r\nset key=\r\nset eval=\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nfor %%# in (\r\nd9eea459-1e6b-499d-8486-e68163f2a8be_N3QJR-YCWKK-RVJGK-GQFMX-T8%f%2BF_EmbeddedIndustryEval_8.1\r\nfbd4c5c6-adc6-4740-bc65-b2dc6dc249c1_MJ8TN-42JH8-886MT-8THCF-36%f%67B_EnterpriseEval_8_NoAct_          REM New time based activation not available\r\n0eebbb45-29d4-49cb-ba87-a23db0cce40a_76FKW-8NR3K-QDH4P-3C87F-JH%f%TTW_EnterpriseEval_8.1\r\n3f4c0546-36c6-46a8-a37f-be13cdd0cf25_7HBDQ-QNKVG-K4RBF-HMBY6-YG%f%9R6_EnterpriseEval_10\r\n1f8dbfe8-defa-4676-b5a6-f76949a01540_4N8VT-7Y686-43DGV-THTW9-M9%f%8W7_EnterpriseNEval_10\r\n57a4ebb6-8e0c-41f8-b79e-8872ddc971ef_W63GF-7N4D9-GQH3K-K4FP7-9B%f%T6C_EnterpriseSEval_2015\r\nb47dd250-fd6a-44c8-9217-03aca6e4812e_N4DMT-RJKDQ-XR6H7-3DKKP-3Y%f%JWT_EnterpriseSEval_2016\r\n267bf82d-08e8-4046-b061-9ef3f8ac2b5a_N7HMH-MK36Q-M4X93-76KQ2-6J%f%HWR_EnterpriseSEval_2019\r\naff25f1f-fb53-4e27-95ef-b8e5aca10ac6_9V4NK-624Y3-VK47R-Q27GP-27%f%PGF_EnterpriseSEval_2021\r\n399f0697-886b-4881-894c-4ff6c52e7d8f_CYPB3-XNV9V-QR4G4-Q3B8K-KQ%f%FGJ_EnterpriseSEval_2024\r\n6162e8c2-3c30-46e1-b964-0de603498e2d_R34N9-HJ6Q3-GBX4F-Q24KQ-49%f%DF7_EnterpriseSNEval_2016\r\naed14fc8-907d-44fb-a3a1-d5d8e638acb3_MHN9Q-RD9PW-BFHDQ-9FTWQ-WQ%f%PF8_EnterpriseSNEval_2019\r\n5dd0c869-eae9-40ce-af48-736692cd8e43_XCN62-29X92-C4T8X-WP82X-DY%f%MJ8_EnterpriseSNEval_2021\r\n522cc0dc-3c7b-4258-ae68-f297ca63b64e_Y8DJM-NPXF3-QG4MH-W7WJK-KQ%f%FGM_EnterpriseSNEval_2024\r\naa708397-8618-42de-b120-a44190ef456d_R63DV-9NPDX-QVWJF-HMR8V-M4%f%K7D_IoTEnterpriseSEval_2024\r\ncd25b1e8-5839-4a96-a769-b6abe3aa5dee_73BMN-332G9-DX6B8-FGDT3-GF%f%YT6_ServerDatacenterEval_2012\r\ne628c5e8-2300-4429-8b80-a8b21bd7ce0a_WPR94-KN3J7-MRB7X-JPJV8-RX%f%7J2_ServerDatacenterEval_2012R2\r\n01398239-85ff-487f-9e90-0e3cc5bcc92e_QVTQ9-GNRBH-JQ9G7-W7FBW-RX%f%9QR_ServerDatacenterEval_2016\r\n5ea4af9e-fd59-4691-b61c-1fc1ff3e309e_KNW3G-22YD2-7QKQJ-2RF2X-H6%f%F8M_ServerDatacenterEval_2019\r\n1d02774d-66ab-4c57-8b14-e254fdce09d4_PK7JN-24236-FH7JP-V792F-37%f%CYR_ServerDatacenterEval_2021\r\n96794a98-097f-42fe-8f28-2c38ea115229_M4RNW-CRTHF-TY7BG-DDHG6-J2%f%T92_ServerDatacenterEval_2025\r\n38d172c7-36b3-4e4b-b435-fd0b06b95c6e_RNFGD-WFFQR-XQ8BG-K7QQK-GJ%f%CP9_ServerStandardEval_2012\r\n4fc45a88-26b5-4cf9-9eef-769ee3f0a016_79M8M-N36BX-8YGJY-2G9KP-3Y%f%GPC_ServerStandardEval_2012R2\r\n9dfa8ec0-7665-4b9d-b2cb-bfc2dc37c9f4_9PBKX-4NHGT-QWV4C-4JD94-TV%f%KQ6_ServerStandardEval_2016\r\n7783a126-c108-4cf7-b59f-13c78c7a7337_J4WNC-H9BG3-6XRX4-3XD8K-Y7%f%XRX_ServerStandardEval_2019\r\nc1a197b6-ba5e-4394-b9bf-b659a6c1b873_7PBJM-MNVPD-MBQD7-TYTY4-W8%f%JDY_ServerStandardEval_2021\r\n753c53a2-4274-4339-8c2e-f66c0b9646c5_YPBVM-HFNWQ-CTF9M-FR4RR-7H%f%9YG_ServerStandardEval_2025\r\n0de5ff31-2d62-4912-b1a8-3ea01d2461fd_3CKBN-3GJ8X-7YT4X-D8DDC-D6%f%69B_ServerStorageStandardEval_2012\r\nfb08f53a-e597-40dc-9f08-8bbf99f19b92_NCJ6J-J23VR-DBYB3-QQBJF-W8%f%CP7_ServerStorageWorkgroupEval_2012\r\n) do (\r\nfor /f \"tokens=1-5 delims=_\" %%A in (\"%%#\") do if %tsedition%==%%C if not defined key (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\nset key=%%B\r\nset eval=1\r\nif /i \"%%E\"==\"NoAct\" set noact=1\r\necho Checking Activation ID                  [%%A] [%%C]\r\n)\r\n)\r\n)\r\n\r\nif not defined key (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Activation ID                  [%tsedition% not found in the script]\"\r\ncall :dk_color %Blue% \"Make sure you are using the updated version of the script.\"\r\ngoto :ts_esu\r\n)\r\n\r\nset resetstuff=1\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':tsforge\\:.*';. ([scriptblock]::Create($f[1]))\"\r\nset resetstuff=\r\nif !errorlevel!==3 (\r\nset error=1\r\ncall :dk_color %Red% \"Resetting Rearm / GracePeriod           [Failed]\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ngoto :ts_esu\r\n) else (\r\necho Resetting Rearm / GracePeriod           [Successful]\r\n)\r\n\r\nset generickey=1\r\ncall :dk_inskey \"[%key%]\"\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_esu\r\n\r\nif not %_actesu%==1 goto :ts_off\r\nif /i %tsmethod%==KMS4k (\r\ncall :dk_color %Red% \"Skipping Windows ESU                    [KMS4k method is not supported with Windows ESU]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\ngoto :ts_off\r\n)\r\n\r\n::  Process Windows ESU\r\n\r\necho:\r\necho Processing Windows ESU...\r\n\r\nset esuexist=\r\nset esuexistsup=\r\nset esueditionlist=\r\nset esuexistbutnosup=\r\n\r\nfor %%# in (EnterpriseS IoTEnterpriseS IoTEnterpriseSK) do (if /i %tsedition%==%%# set isltsc=1)\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" set isServer=1\r\n\r\nif /i %tsedition%==Embedded (\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\WinEmb-Branding-Embedded-ThinPC-Package*.mum\" set isThinpc=1\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\WinEmb-Branding-Embedded-POSReady7-Package*.mum\" set subEdition=[POS]\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\WinEmb-Branding-Embedded-Standard-Package*.mum\" set subEdition=[Standard]\r\n)\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nset w10EsuEditions=Education-EducationN-Enterprise-EnterpriseN-Professional-ProfessionalEducation-ProfessionalEducationN-ProfessionalN-ProfessionalWorkstation-ProfessionalWorkstationN\r\n\r\nset minbuild=0\r\nif /i %tsedition%==ServerRdsh set minbuild=5552\r\nfor %%# in (Core CoreN CoreCountrySpecific CoreSingleLanguage IoTEnterprise) do (if /i %tsedition%==%%# set minbuild=6156)\r\nif /i %tsedition%==PPIPro set minbuild=6388\r\n\r\nset /a UBR=0\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR %nul6%') do if not errorlevel 1 set /a UBR=%%b\r\nif %winbuild% EQU 19045 if %minbuild% GTR 0 if %UBR% GEQ %minbuild% (\r\nset w10EsuEditionsLaterAdded=%tsedition%-\r\n)\r\n\r\nif not defined isThinpc if not defined isltsc for %%# in (\r\nREM Windows7\r\n4220f546-f522-46df-8202-4d07afd26454_Client-ESU-Year3[1-3y]_-Enterprise-EnterpriseE-EnterpriseN-Professional-ProfessionalE-ProfessionalN-Ultimate-UltimateE-UltimateN-\r\n7e94be23-b161-4956-a682-146ab291774c_Client-ESU-Year6[4-6y]_-Enterprise-EnterpriseE-EnterpriseN-Professional-ProfessionalE-ProfessionalN-Ultimate-UltimateE-UltimateN-\r\nREM Windows7EmbeddedPOSReady7\r\n4f1f646c-1e66-4908-acc7-d1606229b29e_POS-ESU-Year3[1-3y]_-Embedded[POS]-\r\nREM Windows7EmbeddedStandard\r\n6aaf1c7d-527f-4ed5-b908-9fc039dfc654_WES-ESU-Year3[1-3y]_-Embedded[Standard]-\r\nREM WindowsServer2008/WindowsServer2008R2\r\n8e7bfb1e-acc1-4f56-abae-b80fce56cd4b_Server-ESU-PA[1-6y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-ServerEnterprise-ServerEnterpriseCore-ServerEnterpriseV-ServerEnterpriseVCore-\r\nREM Windows8.1\r\n4afc620f-12a4-48ad-8015-2aebfbd6e47c_Client-ESU-Year3[1-3y]_-Enterprise-EnterpriseN-Professional-ProfessionalN-\r\n11be7019-a309-4763-9a09-091d1722ffe3_Client-FES-ESU-Year3[1-3y]_-EmbeddedIndustry-EmbeddedIndustryE-\r\nREM WindowsServer2012/2012R2\r\n55b1dd2d-2209-4ea0-a805-06298bad25b3_Server-ESU-Year3[1-3y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-\r\nREM Windows10\r\nf520e45e-7413-4a34-a497-d2765967d094_Client-ESU-Year1_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%\r\n1043add5-23b1-4afb-9a0f-64343c8f3f8d_Client-ESU-Year2_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%\r\n83d49986-add3-41d7-ba33-87c7bfb5c0fb_Client-ESU-Year3_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%\r\n0b533b5e-08b6-44f9-b885-c2de291ba456_Client-ESU-Year6[4-6y]_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%\r\nREM WindowsServer2016\r\n91bcac0a-d7d3-4d2b-bd0c-72fed675f01b_Server-ESU-Year3[1-3y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-\r\n4cd0ab30-73a4-4dde-972c-512f05be31df_Server-ESU-Year6[4-6y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-\r\n) do (\r\nfor /f \"tokens=1-3 delims=_\" %%A in (\"%%#\") do (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\nset esuexist=1\r\necho \"%%C\" | find /i \"-%tsedition%%subEdition%-\" %nul1% && (\r\nset esuexistsup=1\r\nset esueditionlist=\r\nset esuexistbutnosup=\r\nset tsids=!tsids! %%A\r\necho Checking Activation ID                  [%%A] [%%B]\r\n) || (\r\nif not defined esueditionlist set esueditionlist=%%C\r\nset esuexistbutnosup=1\r\n)\r\n)\r\n)\r\n)\r\n\r\nif defined esuexistsup if defined _vis (\r\nset key=9FPV7-MWGT8-7XPDF-JC23W-WT7TW\r\nREM This is a non-generic blocked MAK key for Server-ESU-PA\r\ncall :dk_inskey \"[!key!]\"\r\ngoto :ts_off\r\n)\r\n\r\nif defined esuexistsup (\r\necho \"%tsids%\" | find /i \"4220f546-f522-46df-8202-4d07afd26454\" %nul1% && (\r\necho \"%tsids%\" | find /i \"7e94be23-b161-4956-a682-146ab291774c\" %nul1% || (\r\ncall :dk_color %Gray% \"To get Client-ESU-Year6[4-6y] license, install updates from the below URL.\"\r\ncall :dk_color %Blue% \"%mas%tsforge#windows-esu\"\r\n)\r\n)\r\ngoto :ts_off\r\n)\r\n\r\nif defined isltsc (\r\ncall :dk_color %Gray% \"Checking Activation ID                  [%tsedition% LTSC already has longer support, ESU is not applicable]\"\r\ngoto :ts_off\r\n)\r\n\r\nif defined esuexistbutnosup (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Currently installed ESU License is not supported for %tsedition%]\"\r\necho:\r\nif %winbuild% EQU 19045 if not defined w10EsuEditionsLaterAdded (\r\ncall :dk_color %Blue% \"To get latest version, go to Windows settings and run Windows Update. After that, try the script again.\"\r\ngoto :ts_off\r\n)\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Change Windows Edition option and change to any of the below listed editions.\"\r\necho [%esueditionlist%]\r\ngoto :ts_off\r\n)\r\n\r\nset esuavail=\r\nif defined _vis if defined isServer set esuavail=1\r\nif %winbuild% LEQ 7602 if not defined _vis if not defined isThinpc set esuavail=1\r\nif %winbuild% GTR 7602 if %winbuild% LSS 14393 if defined isServer set esuavail=1\r\nif %winbuild% GEQ 10240 if %winbuild% LEQ 19045 if not defined isServer set esuavail=1\r\nif %winbuild% EQU 9600 set esuavail=1\r\n\r\nif defined esuavail (\r\ncall :dk_color %Red% \"Checking Activation ID                  [ESU license is not found, make sure Windows is fully updated]\"\r\nset fixes=%fixes% %mas%tsforge#windows-esu\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%tsforge#windows-esu\"\r\n) else (\r\ncall :dk_color %Gray% \"Checking Activation ID                  [ESU is not available for %winos%]\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_off\r\n\r\nif not %_actoff%==1 goto :ts_act\r\n\r\nif %winbuild% LSS 9200 (\r\necho:\r\ncall :dk_color %Gray% \"Checking Supported Office               [TSforge for Office is supported on Windows 8 and later versions]\"\r\ncall :dk_color %Blue% \"On Windows Vista / 7, use Ohook activation option for Office instead.\"\r\ngoto :ts_act\r\n)\r\n\r\n::  Check ohook install\r\n\r\nset ohook=\r\nfor %%# in (15 16) do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft Office\\Office%%#\\sppc*dll\" set ohook=1\r\n)\r\n)\r\n\r\nfor %%# in (System SystemX86) do (\r\nfor %%G in (\"Office 15\" \"Office\") do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft %%~G\\root\\vfs\\%%#\\sppc*dll\" set ohook=1\r\n)\r\n)\r\n)\r\n\r\nif defined ohook (\r\necho:\r\ncall :dk_color %Gray% \"Checking Ohook                          [Ohook activation is already installed for Office]\"\r\n)\r\n\r\n::  Check unsupported office versions\r\n\r\nset o14msi=\r\nset o14c2r=\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=Office 2010 MSI )\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=Office 2010 MSI )\r\n%nul% reg query %_68%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n%nul% reg query %_86%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n\r\nif not \"%o14msi%%o14c2r%\"==\"\" (\r\necho:\r\ncall :dk_color %Red% \"Checking Unsupported Office Install     [ %o14msi%%o14c2r%]\"\r\nif defined o14msi call :dk_color %Blue% \"Use Ohook activation option for Office 2010.\"\r\n)\r\n\r\nif %winbuild% GEQ 10240 %psc% \"Get-AppxPackage -name \"Microsoft.MicrosoftOfficeHub\"\" | find /i \"Office\" %nul1% && (\r\nset ohub=1\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check supported office versions\r\n\r\ncall :ts_getpath\r\n\r\nset o16uwp=\r\nset o16uwp_path=\r\n\r\nif %winbuild% GEQ 10240 (\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty InstallLocation)\" %nul6%') do (if exist \"%%a\\Integration\\Integrator.exe\" (set o16uwp=1&set \"o16uwp_path=%%a\"))\r\n)\r\n\r\nsc query ClickToRunSvc %nul%\r\nset error1=%errorlevel%\r\n\r\nif defined o16c2r if %error1% EQU 1060 (\r\necho:\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 16.0 files found]\"\r\nset o16c2r=\r\nset error=1\r\n)\r\n\r\nsc query OfficeSvc %nul%\r\nset error2=%errorlevel%\r\n\r\nif defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (\r\necho:\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 15.0 files found]\"\r\nset o15c2r=\r\nset error=1\r\n)\r\n\r\nif \"%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%\"==\"\" (\r\nset error=1\r\nset showfix=1\r\necho:\r\nif not \"%o14msi%%o14c2r%\"==\"\" (\r\ncall :dk_color %Red% \"Checking Supported Office Install       [Not Found]\"\r\n) else (\r\nif %_actwin%==0 (\r\ncall :dk_color %Red% \"Checking Installed Office               [Not Found]\"\r\n) else (\r\ncall :dk_color %Gray% \"Checking Installed Office               [Not Found]\"\r\n)\r\n)\r\n\r\nif defined ohub (\r\necho:\r\necho You only have the Office Dashboard app installed; you need to install the full version of Office.\r\n)\r\ncall :dk_color %Blue% \"Download and install Office from the URL below, then try again.\"\r\nif %_actwin%==0 set fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto :ts_act\r\n)\r\n\r\nset multioffice=\r\nif not \"%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%\"==\"1\" set multioffice=1\r\nif not \"%o14c2r%%o14msi%\"==\"\" set multioffice=1\r\n\r\nif defined multioffice (\r\necho:\r\ncall :dk_color %Gray% \"Checking Multiple Office Install        [Found. Recommended to install one version only]\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Windows Server\r\n\r\nset winserver=\r\nreg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions\" /v ProductType %nul2% | find /i \"WinNT\" %nul1% || set winserver=1\r\nif not defined winserver (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Server\" %nul1% && set winserver=1\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Process Office UWP\r\n\r\nif not defined o16uwp goto :ts_starto15c2r\r\n\r\ncall :ts_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=16\r\nset \"_oLPath=%o16uwp_path%\\Licenses16\"\r\nset \"pkeypath=%o16uwp_path%\\Office16\\pkeyconfig-office.xrm-ms\"\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty Dependencies) | Select-Object PackageFullName\" %nul6%') do (set \"o16uwpapplist=!o16uwpapplist! %%a\")\r\n\r\necho \"%o16uwpapplist%\" | findstr /i \"Access Excel OneNote Outlook PowerPoint Publisher SkypeForBusiness Word\" %nul% && set \"_oIds=O365HomePremRetail\"\r\n\r\nfor %%# in (Project Visio) do (\r\necho \"%o16uwpapplist%\" | findstr /i \"%%#\" %nul% && (\r\nset _lat=\r\nif exist \"%_oLPath%\\%%#Pro2024VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2024Retail \" & set _lat=1\r\nif not defined _lat if exist \"%_oLPath%\\%%#Pro2021VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2021Retail \" & set _lat=1\r\nif not defined _lat if exist \"%_oLPath%\\%%#Pro2019VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2019Retail \" & set _lat=1\r\nif not defined _lat set \"_oIds= !_oIds! %%#ProRetail \"\r\n)\r\n)\r\n\r\nset uwpinfo=%o16uwp_path:C:\\Program Files\\WindowsApps\\Microsoft.Office.Desktop_=%\r\n\r\necho:\r\necho Processing Office...                    [UWP ^| %uwpinfo%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ts_starto15c2r\r\n)\r\n\r\ncall :ts_process\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_starto15c2r\r\n\r\n::  Process Office 15.0 C2R\r\n\r\nif not defined o15c2r goto :ts_starto16c2r\r\n\r\ncall :ts_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=15\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o15c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o15c2r_reg%\\Configuration\")\r\nif not defined _oArch   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nif not defined _version for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v version\" %nul6%') do (set \"_version=%%b\")\r\nif not defined _prids   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v ProductReleaseId\" %nul6%') do (set \"_prids=%o15c2r_reg%\\propertyBag /v ProductReleaseId\" & set \"_config=%o15c2r_reg%\\propertyBag\")\r\n\r\necho \"%o15c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=10) || (set _tok=9)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query %o15c2r_reg%\\ProductReleaseIDs\\Active %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses\"\r\nset \"pkeypath=%_oRoot%\\Office15\\pkeyconfig-office.xrm-ms\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\necho:\r\necho Processing Office...                    [C2R ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ts_starto16c2r\r\n)\r\n\r\ncall :oh_expiredpreview 2013\r\nif \"%_actprojvis%\"==\"0\" call :oh_fixprids\r\ncall :ts_process\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_starto16c2r\r\n\r\n::  Process Office 16.0 C2R\r\n\r\nif not defined o16c2r goto :ts_startmsi\r\n\r\ncall :ts_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=16\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v AudienceData\" %nul6%') do (set \"_AudienceData=^| %%b \")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o16c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o16c2r_reg%\\Configuration\")\r\n\r\necho \"%o16c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=9) || (set _tok=8)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query \"%o16c2r_reg%\\ProductReleaseIDs\" /s /f \".16\" /k %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\nset _oIds=%_oIds:.16=%\r\nset _o16c2rIds=%_oIds%\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses16\"\r\nset \"pkeypath=%_oRoot%\\Office16\\pkeyconfig-office.xrm-ms\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\necho:\r\necho Processing Office...                    [C2R ^| %_version% %_AudienceData%^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ts_startmsi\r\n)\r\n\r\ncall :oh_expiredpreview 2016 2019 2021 2024\r\nif \"%_actprojvis%\"==\"0\" call :oh_fixprids\r\ncall :ts_process\r\n\r\n::========================================================================================================================================\r\n\r\n::  mass{}grave{dot}dev/office-license-is-not-genuine\r\n::  Add registry keys for volume products so that 'non-genuine' banner won't appear \r\n\r\nset \"kmskey=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\0ff1ce15-a989-479d-af46-f275c6370663\"\r\nif /i %tsmethod%==KMS4k (\r\nif %winbuild% GEQ 9200 (\r\nif not \"%osarch%\"==\"x86\" (\r\nreg delete \"%kmskey%\" /f /reg:32 %nul%\r\nreg add \"%kmskey%\" /f /v KeyManagementServiceName /t REG_SZ /d \"10.0.0.10\" /reg:32 %nul%\r\n)\r\nreg delete \"%kmskey%\" /f %nul%\r\nreg add \"%kmskey%\" /f /v KeyManagementServiceName /t REG_SZ /d \"10.0.0.10\" %nul%\r\necho Adding a Registry to Prevent Banner     [Successful]\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_startmsi\r\n\r\nif defined o15msi call :ts_processmsi 15 %o15msi_reg%\r\nif defined o16msi call :ts_processmsi 16 %o16msi_reg%\r\n\r\n::========================================================================================================================================\r\n\r\necho:\r\ncall :oh_clearblock\r\nif \"%o16msi%%o15msi%\"==\"\" if not \"%o16uwp%%o16c2r%%o15c2r%\"==\"\" call :oh_uninstkey\r\ncall :oh_licrefresh\r\n\r\ngoto :ts_act\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_whost\r\n\r\n::  Process Windows K-M-S host\r\n\r\necho:\r\necho Processing Windows %KS% Host...\r\n\r\nif /i %tsmethod%==KMS4k (\r\necho:\r\ncall :dk_color %Red% \"Skipping Windows %KS% Host               [KMS4k method is not supported with Windows %KS% Host]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\ngoto :ts_act\r\n)\r\n\r\necho:\r\nif %winbuild% GEQ 10586 (\r\ncall :dk_color %Gray% \"With %KS% Host license, system may randomly change Windows Edition later. It is a Windows issue and can be safely ignored.\"\r\n)\r\ncall :dk_color %Gray% \"%KS% Host [Not to be confused with %KS% Client] license causes the %_slser% service to run continuously.\"\r\ncall :dk_color %Blue% \"Only use this activation when necessary, you can revert to normal activation from the previous menu.\"\r\n\r\nif %_unattended%==0 (\r\necho:\r\nchoice /C:0F /N /M \"> [0] Go back  [F] Continue : \"\r\nif !errorlevel!==1 exit /b\r\necho:\r\n)\r\n\r\nset _arr=\r\nset tempid=\r\nset keytype=kmshost\r\n\r\nif defined _vis goto :ts_whost_vista\r\n\r\n::  Install current edition csvlk license so that correct edition can reflect for csvlk\r\n\r\nif %winbuild% GEQ 10586 (\r\nfor %%# in (\"%SysPath%\\spp\\tokens\\skus\\%tsedition%\\*CSVLK*.xrm-ms\") do (\r\nif defined _arr (set \"_arr=!_arr!;\"%SysPath%\\spp\\tokens\\skus\\%tsedition%\\%%~nx#\"\") else (set \"_arr=\"%SysPath%\\spp\\tokens\\skus\\%tsedition%\\%%~nx#\"\")\r\n)\r\nif defined _arr %psc% \"$sls = Get-WmiObject %sps%; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); InstallLicenseArr '!_arr!'\" %nul%\r\n)\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wintsid\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (\r\necho \"%%a\" | findstr /r \".*-.*-.*-.*-.*\" %nul1% && (set tsids=!tsids! %%a& set tempid=%%a)\r\n)\r\n\r\nif defined tempid (\r\necho Checking Activation ID                  [%tempid%] [%tsedition%]\r\n) else (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Not Found] [%tsedition%] [%osSKU%]\"\r\ncall :dk_color %Blue% \"%KS% Host license is not found on your system. It is available for the below editions.\"\r\ncall :dk_color %Blue% \"Professional, Education, ProfessionalWorkstation, Enterprise, EnterpriseS, and Server editions, etc.\"\r\ngoto :ts_act\r\n)\r\n\r\nif defined winsub (\r\necho:\r\ncall :dk_color %Blue% \"Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%].\"\r\n)\r\n\r\ngoto :ts_act\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_whost_vista\r\n\r\n::  Process Windows K-M-S host for Vista\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = CSVLK key\r\n::  3rd column = Edition IDs\r\n::  Separator  = _\r\n\r\nset f=\r\nset key=\r\nset tempid=\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nfor %%# in (\r\n::  WindowsVista\r\n212a64dc-43b1-4d3d-a30c-2fc69d2095c6_TWVG3-9Q4P8-W9XJF-Y76FJ-DW%f%Q4R_-Business-BusinessN-Enterprise-EnterpriseN-\r\n::  WindowsServer2008\r\nc90d1b4e-8aa8-439e-8b9e-b6d6b6a6d975_BHC4Q-6D7B7-QMVH7-4MKQH-Y9%f%VK7_-ServerComputeCluster-ServerDatacenter-ServerDatacenterV-ServerEnterprise-ServerEnterpriseIA64-ServerEnterpriseV-ServerStandard-ServerStandardV-ServerWeb-\r\n56df4151-1f9f-41bf-acaa-2941c071872b_PVGKG-2R7XQ-7WTFD-FXTJR-DQ%f%BQ3_-ServerComputeCluster-ServerEnterprise-ServerEnterpriseV-ServerStandard-ServerStandardV-ServerWeb-\r\nc448fa06-49d1-44ec-82bb-0085545c3b51_KH4PC-KJFX6-XFVHQ-GDK2G-JC%f%JY9_-ServerComputeCluster-ServerWeb-\r\n) do (\r\nfor /f \"tokens=1-3 delims=_\" %%A in (\"%%#\") do if not defined key (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\necho \"%%C\" | find /i \"-%tsedition%-\" %nul1% && (\r\nset key=%%B\r\nset tempid=%%A\r\n)\r\n)\r\n)\r\n)\r\n\r\nif defined key (\r\necho Checking Activation ID                  [%tempid%] [%tsedition%]\r\n) else (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Not Found] [%tsedition%] [%osSKU%]\"\r\ncall :dk_color %Blue% \"%KS% Host license is not found on your system. It is available for the below editions.\"\r\ncall :dk_color %Blue% \"Business, BusinessN, Enterprise, EnterpriseN, and Server editions, etc.\"\r\ngoto :ts_act\r\n)\r\n\r\ncall :dk_inskey \"[%key%]\"\r\nset tsids=%tsids% %tempid%\r\ngoto :ts_act\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_ohost\r\n\r\n::  Process Office K-M-S host\r\n\r\necho:\r\necho Processing Office %KS% Host...\r\n\r\nif defined _vis (\r\necho:\r\ncall :dk_color %Blue% \"Windows Vista and Server 2008 do not support the installation of Office KMS Host.\"\r\ngoto :ts_act\r\n)\r\n\r\nif /i %tsmethod%==KMS4k (\r\necho:\r\ncall :dk_color %Red% \"Skipping Office %KS% Host                [KMS4k method is not supported with Office %KS% Host]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\ngoto :ts_act\r\n)\r\n\r\nset ohostexist=\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\nset ohostids=%allapps%\r\ncall :dk_actids 59a52881-a989-479d-af46-f275c6370663\r\nset ohostids=%ohostids% %allapps%\r\n\r\nfor %%# in (\r\nbfe7a195-4f8f-4f0b-a622-cf13c7d16864_KMSHost2010-ProPlusVL\r\nf3d89bbf-c0ec-47ce-a8fa-e5a5f97e447f_KMSHost2024Volume\r\n47f3b983-7c53-4d45-abc6-bcd91e2dd90a_KMSHost2021Volume\r\n70512334-47b4-44db-a233-be5ea33b914c_KMSHost2019Volume\r\n98ebfe73-2084-4c97-932c-c0cd1643bea7_KMSHost2016Volume\r\n2e28138a-847f-42bc-9752-61b03fff33cd_KMSHost2013Volume\r\n) do (\r\nfor /f \"tokens=1-2 delims=_\" %%A in (\"%%#\") do (\r\necho \"%ohostids%\" | find /i \"%%A\" %nul1% && (\r\nset ohostexist=1\r\nset tsids=!tsids! %%A\r\necho Checking Activation ID                  [%%A] [%%B]\r\n)\r\n)\r\n)\r\n\r\nif not defined ohostexist (\r\ncall :dk_color %Gray% \"Checking Activation ID                  [Not found for Office %KS% Host]\"\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%tsforge#office-kms-host\"\r\n)\r\n\r\necho:\r\ncall :dk_color %Gray% \"%KS% Host [Not to be confused with %KS% Client] license causes the sppsvc service to run continuously.\"\r\ncall :dk_color %Gray% \"Only use this activation when necessary.\"\r\n\r\ngoto :ts_act\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_appxlob\r\n\r\n::  Process Windows 8/8.1 APPX Sideloading\r\n\r\necho:\r\necho Processing Windows 8/8.1 APPX Sideloading...\r\n\r\nif %winbuild% LSS 9200 set noappx=1\r\nif %winbuild% GTR 9600 set noappx=1\r\n\r\necho:\r\nif defined noappx (\r\ncall :dk_color %Gray% \"Checking Activation ID                  [APPX Sideloading feature is available only on Windows 8/8.1]\"\r\ngoto :dk_done\r\n)\r\n\r\nif /i %tsmethod%==KMS4k (\r\necho:\r\ncall :dk_color %Red% \"Skipping Windows 8/8.1 APPX             [KMS4k method is not supported with Windows 8/8.1 APPX]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\ngoto :dk_done\r\n)\r\n\r\nset appxexist=\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nfor %%# in (\r\nec67814b-30e6-4a50-bf7b-d55daf729d1e_APPXLOB-Client\r\n251ef9bf-2005-442f-94c4-86307de7bb32_APPXLOB-Embedded-Industry\r\n1e58c9d7-e3f1-4f69-9039-1f162463ac2c_APPXLOB-Embedded-Standard\r\n3502d53e-5d43-436a-84af-714e8d334f8d_APPXLOB-Server\r\n) do (\r\nfor /f \"tokens=1-2 delims=_\" %%A in (\"%%#\") do (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\nset appxexist=1\r\nset tsids=!tsids! %%A\r\necho Checking Activation ID                  [%%A] [%%B]\r\n)\r\n)\r\n)\r\n\r\nif not defined appxexist (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Not found]\"\r\ncall :dk_color %Blue% \"APPX Sideloading feature is available only on Pro and higher level editions.\"\r\n)\r\n\r\ngoto :ts_act\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_resetall\r\n\r\necho:\r\nif defined _vis (\r\necho Processing Reset of Rearm / Timers...\r\n) else (\r\necho Processing Reset of Rearm / Timers / Tamper / Lock...\r\n)\r\necho:\r\n\r\nset resetstuff=1\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':tsforge\\:.*';. ([scriptblock]::Create($f[1]))\"\r\n\r\nif %errorlevel%==3 (\r\ncall :dk_color %Red% \"Reset Failed.\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n) else (\r\ncall :dk_color %Green% \"Reset process has been successfully done.\"\r\n)\r\n\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_actman\r\n\r\necho:\r\necho Processing Manual Activation...\r\necho:\r\n\r\nif /i %tsmethod%==KMS4k (\r\necho:\r\ncall :dk_color %Red% \"Skipping Manual Activation              [KMS4k method is not supported with it]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\ngoto :dk_done\r\n)\r\n\r\ncall :dk_color %Gray% \"This option is for advanced users, those who already know what they are doing.\"\r\ncall :dk_color %Blue% \"Some activation IDs may cause system crash [MUI mismatch], or irreversible changes [CloudEdition etc].\"\r\n\r\nif %_unattended%==1 (\r\necho:\r\nfor %%# in (%tsids%) do (echo Activation ID - %%#)\r\ngoto :ts_act\r\n)\r\n\r\ncall :dk_color %Blue% \"Although the script will try to remove those IDs from the list, it is not fully guaranteed.\"\r\necho:\r\nchoice /C:0F /N /M \"> [0] Go back  [F] Continue : \"\r\nif %errorlevel%==1 exit /b\r\n\r\necho:\r\necho Fetching Supported Activation IDs list. Please wait...\r\n\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':listactids\\:.*';. ([scriptblock]::Create($f[1]))\"\r\nif %errorlevel%==3 (\r\ncall :dk_color %Gray% \"No supported activation ID found, aborting...\"\r\ngoto :dk_done\r\n)\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"$ids = Get-WmiObject -Query 'SELECT ID FROM SoftwareLicensingProduct' | Select-Object -ExpandProperty ID; $ids\" %nul6%') do call set \"allactids= %%a !allactids! \"\r\n\r\nif defined _vis (\r\necho:\r\ncall :dk_color %Blue% \"On Windows Vista and Server 2008, you must manually install the key before activating it.\"\r\n)\r\necho:\r\ncall :dk_color %Gray% \"Enter / Paste the Activation ID shown in first column in the opened text file, or just press Enter to return:\"\r\necho Add space after each Activation ID if you are adding multiple:\r\necho:\r\nset /p tsids=\r\n\r\ndel /f /q \"%SystemRoot%\\Temp\\actids_159_*\" %nul%\r\nif not defined tsids goto :dk_done\r\n\r\nfor %%# in (%tsids%) do (\r\necho \"%allactids%\" | find /i \" %%# \" %nul1% || (\r\ncall :dk_color %Red% \"[%%#] Incorrect Activation ID entered, aborting...\"\r\ngoto :dk_done\r\n)\r\n)\r\n\r\ngoto :ts_act\r\n\r\n:listactids:\r\n$t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)\r\n$t.DefinePInvokeMethod('SLOpen', 'slc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n$t.DefinePInvokeMethod('SLClose', 'slc.dll', 22, 1, [IntPtr], @([IntPtr]), 1, 3).SetImplementationFlags(128)\r\n$t.DefinePInvokeMethod('SLGetProductSkuInformation', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n$t.DefinePInvokeMethod('SLGetLicense', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n$w = $t.CreateType()\r\n$m = [Runtime.InteropServices.Marshal]\r\n\r\nfunction slGetSkuInfo($SkuId) {\r\n    $c = 0; $b = 0\r\n    $r = $w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, \"msft:sl/EUL/PHONE/PUBLIC\", [ref]$null, [ref]$c, [ref]$b)\r\n    return ($r -eq 0)\r\n}\r\n\r\nfunction IsMuiNotLocked($SkuId) {\r\n    $r = $true; $c = 0; $b = 0\r\n\r\n    $LicId = [Guid]::Empty\r\n    [void]$w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, \"fileId\", [ref]$null, [ref]$c, [ref]$b)\r\n    $FileId = $m::PtrToStringUni($b)\r\n\r\n    $c = 0; $b = 0\r\n    [void]$w::SLGetLicense($hSLC, [ref][Guid]$FileId, [ref]$c, [ref]$b)\r\n    $blob = New-Object byte[] $c; $m::Copy($b, $blob, 0, $c)\r\n    $cont = [Text.Encoding]::UTF8.GetString($blob)\r\n    $xml = [xml]$cont.SubString($cont.IndexOf('<r'))\r\n\r\n    $xml.licenseGroup.license[0].grant | foreach {\r\n        $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Kernel-MUI-Language-Allowed' } | foreach {\r\n            if ($_.InnerText -ne 'EMPTY') { $r = $false }\r\n        }\r\n    }\r\n    return $r\r\n}\r\n\r\n$hSLC = 0; [void]$w::SLOpen([ref]$hSLC)\r\n$results = Get-WmiObject -Query \"SELECT ID, Name, Description FROM SoftwareLicensingProduct\"\r\n$maxNameWidth = 60\r\n\r\n$filteredResults = $results | Where-Object {\r\n    if ($env:tsedition -like \"*CountrySpecific*\") {\r\n        $true\r\n    }\r\n    else {\r\n        $_.Name -like \"*ESU*\" -or $_.Name -notlike \"*CountrySpecific*\"\r\n    }\r\n} | Where-Object {\r\n    if ($env:tsedition -like \"*CloudEdition*\") {\r\n        $true\r\n    }\r\n    else {\r\n        $_.Name -like \"*ESU*\" -or $_.Name -notlike \"*CloudEdition*\"\r\n    }\r\n} | Where-Object {\r\n    $_.Name -like \"*CountrySpecific*\" -or (IsMuiNotLocked $_.ID)\r\n} | Where-Object {\r\n    slGetSkuInfo $_.ID\r\n} | ForEach-Object {\r\n    \"$($_.ID)`t$($_.Name.PadRight($maxNameWidth))`t$($_.Description)\"\r\n}\r\n\r\n[void]$w::SLClose($hSLC)\r\nif (-not $filteredResults) {\r\n    Exit 3\r\n}\r\n\r\n$sortedResults = $filteredResults | Sort-Object { $_.Split(\"`t\")[1].Trim() }\r\n$output = $sortedResults -join \"`r`n\"\r\n$newGuid = [Guid]::NewGuid().Guid\r\n$filename = \"$env:SystemRoot\\Temp\\actids_159_$newGuid.txt\"\r\n$output | Set-Content -Path $filename -Encoding ASCII\r\nStart-Process notepad.exe $filename\r\n:listactids:\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_act\r\n\r\nif defined eval (\r\necho:\r\necho Activating...\r\necho:\r\ncall :dk_act\r\n\r\nset gpr=0\r\nset gprdays=0\r\nset actdone=\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-WmiObject -Query 'SELECT GracePeriodRemaining FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').GracePeriodRemaining\" %nul6%') do set \"gpr=%%a\"\r\nset /a \"gprdays=(!gpr!+1440-1)/1440\"\r\n\r\nif !gprdays! EQU 90 set actdone=1\r\nif !gprdays! EQU 180 set actdone=1\r\n\r\nif defined actdone (\r\ncall :dk_color %Green% \"[%winos%] has been reset and activated successfully for !gprdays! days.\"\r\n) else (\r\nset error=1\r\nset showfix=1\r\ncall :dk_color %Red% \"[%winos%] Activation Failed %error_code%. Remaining Period: !gprdays! days [!gpr! minutes].\"\r\nif not defined noact (\r\ncall :dk_color %Gray% \"To activate, check your internet connection and ensure the date and time are correct.\"\r\n) else (\r\ncall :dk_color %Blue% \"This Windows version is known to not activate due to MS Windows/Server issues.\"\r\n)\r\nif not defined showfix call :dk_color %Blue% \"%_fixmsg%\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n)\r\n\r\nif defined tsids (\r\necho:\r\nif not defined _vis if not defined oldks echo Installing Forged Product Key Data...\r\nif /i %tsmethod%==KMS4k (\r\necho Writing TrustedStore data...\r\n) else (\r\nif /i %tsmethod%==StaticCID (echo Depositing Static Confirmation ID...) else (echo Depositing Zero Confirmation ID...)\r\n)\r\necho:\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':tsforge\\:.*';. ([scriptblock]::Create($f[1])) %tsids%\"\r\nif !errorlevel!==3 (\r\nif %_actman%==0 (if not defined showfix call :dk_color %Blue% \"%_fixmsg%\")\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n) else (\r\nif /i %tsmethod%==KMS4k if %winbuild% GEQ 26100 (\r\necho:\r\ncall :dk_color %Gray% \"In Windows settings, you may see a renewal notification for activation that can be ignored.\"\r\nif /i %_actmethod%==Auto call :dk_color %Gray% \"To avoid this notification, run the script with an internet connection to use the StaticCID method.\"\r\n)\r\necho \"%tsids%\" | find /i \"7e94be23-b161-4956-a682-146ab291774c\" %nul1% && (\r\ncall :dk_color %Gray% \"Windows Update gets 1-3 years of ESU; 4-6 are unofficial but let you install Server 2008 R2 updates manually.\"\r\n)\r\necho \"%tsids%\" | findstr /i \"4afc620f-12a4-48ad-8015-2aebfbd6e47c 11be7019-a309-4763-9a09-091d1722ffe3\" %nul1% && (\r\ncall :dk_color %Gray% \"ESU is not officially supported on Windows 8.1, but updates can be installed manually until January 2024.\"\r\n)\r\necho \"%tsids%\" | findstr /i \"83d49986-add3-41d7-ba33-87c7bfb5c0fb 0b533b5e-08b6-44f9-b885-c2de291ba456\" %nul1% && (\r\ncall :dk_color %Gray% \"Windows Update gets 1-3 years of ESU; 4-6 are unofficial but may let you install LTSC updates manually.\"\r\nif exist %SysPath%\\ClipESUConsumer.exe (%SysPath%\\ClipESUConsumer.exe -evaluateEligibility)\r\nif exist %SysPath%\\ClipESU.exe (%SysPath%\\ClipESU.exe %nul%)\r\n)\r\n)\r\n\r\nif defined esuexistsup echo Help: %mas%tsforge#windows-esu\r\n\r\nif %_actwin%==1 for %%# in (407) do if %osSKU%==%%# (\r\ncall :dk_color %Red% \"%winos% does not support activation on non-azure platforms.\"\r\n)\r\n\r\nif %_actoff%==1 if not defined error if defined ohub (\r\necho:\r\ncall :dk_color %Gray% \"Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app.\"\r\n)\r\n\r\nREM Trigger reevaluation of SPP's Scheduled Tasks\r\ncall :dk_reeval %nul%\r\n)\r\n\r\nif not defined tsids if defined error if not defined showfix (\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_remove\r\n\r\ncls\r\nif not defined terminal (\r\nmode 100, 30\r\n)\r\ntitle  Remove TSforge Activation %masver%\r\n\r\necho:\r\necho TSforge activation doesn't modify any Windows components and doesn't install any new files.\r\necho:\r\necho Instead, it appends data to one of data files used by Software Protection Platform.\r\necho:\r\ncall :dk_color %Gray% \"If you want to reset the activation status,\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_reset\r\n\r\nset key=\r\nset _oRoot=\r\nset _oArch=\r\nset _oIds=\r\nset _oLPath=\r\nset _actid=\r\nset _prod=\r\nset _lic=\r\nset _arr=\r\nset _prids=\r\nset _config=\r\nset _version=\r\nset _License=\r\nset _oMSI=\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_getpath\r\n\r\nset o16c2r=\r\nset o15c2r=\r\nset o16msi=\r\nset o15msi=\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set o16c2r=1&set o16c2r_reg=%_86%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set o16c2r=1&set o16c2r_reg=%_68%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set o15c2r=1&set o15c2r_reg=%_86%\\15.0\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set o15c2r=1&set o15c2r_reg=%_68%\\15.0\\ClickToRun)\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o16msi=1&set o16msi_reg=%_86%\\16.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o16msi=1&set o16msi_reg=%_68%\\16.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o15msi=1&set o15msi_reg=%_86%\\15.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o15msi=1&set o15msi_reg=%_68%\\15.0)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_process\r\n\r\nif not exist \"%pkeypath%\" (\r\ncall :dk_color %Red% \"Checking pkeyconfig-office.xrm-ms       [Not found. Aborting activation...]\"\r\nset error=1\r\nexit /b\r\n)\r\n\r\nfor %%# in (%_oIds%) do (\r\nset _actid=\r\nset _preview=\r\nset _License=%%#\r\n\r\nset skipprocess=\r\n\r\nset foundprod=\r\ncall :tsksdata chkprod %%#\r\nif defined _oMSI if not defined foundprod if /i %tsmethod%==KMS4k (\r\nset skipprocess=1\r\ncall :dk_color %Red% \"Checking Product In Script              [%%# MSI Retail is not supported with KMS4k]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\n)\r\n\r\nif \"%_actprojvis%\"==\"1\" (\r\necho %%# | findstr /i \"Project Visio\" %nul% || (\r\nset skipprocess=1\r\ncall :dk_color %Gray% \"Skipping Because Project/Visio Mode     [%%#]\"\r\n)\r\n)\r\n\r\nif \"%_actprojvis%\"==\"0\" if /i %tsmethod%==KMS4k echo %_oIds% | findstr /i \"O365\" %nul% && (\r\necho %%# | findstr /i \"Project Visio\" %nul% && (\r\nset skipprocess=1\r\necho Skipping Because Mondo Is Available     [%%#]\r\n)\r\n)\r\n\r\n\r\nif not defined skipprocess (\r\n\r\nif /i not %tsmethod%==KMS4k (\r\nset no365=\r\nif \"%oVer%\"==\"15\" (echo %%# | findstr /i \"O365HomePremRetail\" %nul% && set no365=1)\r\nif \"%oVer%\"==\"16\" (echo %%# | findstr /i \"O365\" %nul% && set no365=1)\r\n\r\nif defined no365 (\r\nset _License=MondoRetail\r\nset _altoffid=MondoRetail\r\ncall :ks_osppready\r\necho Converting Unsupported O365 Office      [%%# To MondoRetail]\r\nif \"%oVer%\"==\"15\" (call :dk_color %Gray% \"Mondo 2013 is equivalent to O365 [15.0 version] in terms of the latest features.\")\r\nif \"%oVer%\"==\"16\" (call :dk_color %Gray% \"Mondo 2016 is equivalent to O365 in terms of the latest features.\")\r\n)\r\n\r\nif not defined _oMSI (\r\necho %%# | findstr /i \"ARM\" %nul% && (\r\nset _License=MondoRetail\r\nset _altoffid=MondoRetail\r\ncall :ks_osppready\r\necho Converting Unsupported OEM-ARM Office   [%%# To MondoRetail]\r\n)\r\n)\r\n)\r\n\r\nif not defined _oMSI if /i %tsmethod%==KMS4k if not defined foundprod (\r\ncall :tsksdata getinfo %%#\r\nif defined _altoffid (\r\necho Converting Retail To Volume             [%%# To !_altoffid!]\r\n) else (\r\nset _License=MondoVolume\r\nset _altoffid=MondoVolume\r\necho Converting Retail To Volume             [%%# To !_altoffid!] [Using Mondo because %%# is not found in the script]\r\n)\r\necho %%# | find /i \"O365\" %nul% && (\r\nif \"%oVer%\"==\"15\" (call :dk_color %Gray% \"Mondo 2013 is equivalent to O365 [15.0 version] in terms of the latest features.\")\r\nif \"%oVer%\"==\"16\" (call :dk_color %Gray% \"Mondo 2016 is equivalent to O365 in terms of the latest features.\")\r\n)\r\ncall :ks_osppready\r\n)\r\n\r\nif /i %tsmethod%==KMS4k (\r\necho !_License! | find /i \"Retail\" %nul% && (set keytype=zero) || (set keytype=ks)\r\n) else (\r\nset keytype=zero\r\n)\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':offtsid\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (\r\necho \"%%a\" | findstr /r \".*-.*-.*-.*-.*\" %nul1% && (set tsids=!tsids! %%a& set _actid=%%a)\r\n)\r\nset \"_allactid=!tsids!\"\r\n\r\nif defined _actid (\r\necho Checking Activation ID                  [!_actid!] [!_License!]\r\n) else (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Office %oVer%.0 !_License! not found]\"\r\nset error=1\r\nset showfix=1\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\necho %%# | find /i \"2024\" %nul% && (\r\nif exist \"!_oLPath!\\ProPlus2024PreviewVL_*.xrm-ms\" if not exist \"!_oLPath!\\ProPlus2024VL_*.xrm-ms\" set _preview=1\r\n)\r\n\r\nif defined _actid (\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% || call :oh_installlic\r\n)\r\n)\r\n)\r\n\r\n::  Add SharedComputerLicensing registry key if Retail Office C2R is installed on Windows Server\r\n::  https://learn.microsoft.com/en-us/office/troubleshoot/office-suite-issues/click-to-run-office-on-terminal-server\r\n\r\nif /i not %tsmethod%==KMS4k if defined winserver if defined _config if exist \"%_oLPath%\\Word2019VL_KMS_Client_AE*.xrm-ms\" (\r\necho %_oIds% | find /i \"Retail\" %nul1% && (\r\nset scaIsNeeded=1\r\nreg add %_config% /v SharedComputerLicensing /t REG_SZ /d \"1\" /f %nul1%\r\necho Adding SharedComputerLicensing Reg      [Successful] [Needed on Server With Retail Office]\"\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_processmsi\r\n\r\n::  Process Office MSI Version\r\n\r\ncall :ts_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset _oMSI=1\r\nset oVer=%1\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_oRoot=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\ProductVersion /v LastProduct\" %nul6%') do (set \"_version=%%b\")\r\nif \"%_oRoot:~-1%\"==\"\\\" set \"_oRoot=%_oRoot:~0,-1%\"\r\n\r\necho \"%2\" | find /i \"Wow6432Node\" %nul1% && set _oArch=x86\r\nif not \"%osarch%\"==\"x86\" if not defined _oArch set _oArch=x64\r\nif \"%osarch%\"==\"x86\" set _oArch=x86\r\n\r\nset \"_common=%CommonProgramFiles%\"\r\nif defined PROCESSOR_ARCHITEW6432 set \"_common=%CommonProgramW6432%\"\r\nset \"_common2=%CommonProgramFiles(x86)%\"\r\n\r\nif exist \"%_common%\\Microsoft Shared\\OFFICE%oVer%\\Office Setup Controller\\pkeyconfig-office.xrm-ms\" (\r\nset \"pkeypath=%_common%\\Microsoft Shared\\OFFICE%oVer%\\Office Setup Controller\\pkeyconfig-office.xrm-ms\"\r\n) else if exist \"%_common2%\\Microsoft Shared\\OFFICE%oVer%\\Office Setup Controller\\pkeyconfig-office.xrm-ms\" (\r\nset \"pkeypath=%_common2%\\Microsoft Shared\\OFFICE%oVer%\\Office Setup Controller\\pkeyconfig-office.xrm-ms\"\r\n)\r\n\r\ncall :msiofficedata %2\r\n\r\necho:\r\necho Processing Office...                    [MSI ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nexit /b\r\n)\r\n\r\ncall :ts_process\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get Windows permanent activation status (not counting csvlk)\r\n\r\n:ts_checkwinperm\r\n\r\n%psc% \"Get-WmiObject -Query 'SELECT Name, Description FROM SoftwareLicensingProduct WHERE LicenseStatus=''1'' AND GracePeriodRemaining=''0'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn IS NULL' | Where-Object { $_.Description -notmatch 'KMS' } | Select-Object -Property Name\" %nul2% | findstr /i \"Windows\" %nul1% && set _perm=1||set _perm=\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:tsforge:\r\n$src = @'\r\n#if !POWERSHELL2\r\nnamespace ActivationWs\r\n{\r\n\r\n/*\r\n\r\nThis code is adapted from ActivationWs.\r\nOriginal Repository: https://github.com/dadorner-msft/activationws\r\n\r\nMIT License\r\n\r\nCopyright (c) Daniel Dorner\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\nSOFTWARE.\r\n\r\n*/\r\n\r\nusing System;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Net;\r\nusing System.Security.Cryptography;\r\nusing System.Text;\r\nusing System.Xml.Linq;\r\n\r\n    public static class ActivationHelper {\r\n        // Key for HMAC/SHA256 signature.\r\n        private static readonly byte[] MacKey = new byte[64] {\r\n            254,  49, 152, 117, 251,  72, 132, 134,\r\n            156, 243, 241, 206, 153, 168, 144, 100,\r\n            171,  87,  31, 202,  71,   4,  80,  88,\r\n            48,   36, 226,  20,  98, 135, 121, 160,\r\n            0,     0,   0,   0,   0,   0,   0,   0,\r\n            0,     0,   0,   0,   0,   0,   0,   0,\r\n            0,     0,   0,   0,   0,   0,   0,   0,\r\n            0,     0,   0,   0,   0,   0,   0,   0\r\n        };\r\n\r\n        private const string Action = \"http://www.microsoft.com/BatchActivationService/BatchActivate\";\r\n\r\n        private static readonly Uri Uri = new Uri(\"https://activation.sls.microsoft.com/BatchActivation/BatchActivation.asmx\");\r\n\r\n        private static readonly XNamespace SoapSchemaNs = \"http://schemas.xmlsoap.org/soap/envelope/\";\r\n        private static readonly XNamespace XmlSchemaInstanceNs = \"http://www.w3.org/2001/XMLSchema-instance\";\r\n        private static readonly XNamespace XmlSchemaNs = \"http://www.w3.org/2001/XMLSchema\";\r\n        private static readonly XNamespace BatchActivationServiceNs = \"http://www.microsoft.com/BatchActivationService\";\r\n        private static readonly XNamespace BatchActivationRequestNs = \"http://www.microsoft.com/DRM/SL/BatchActivationRequest/1.0\";\r\n        private static readonly XNamespace BatchActivationResponseNs = \"http://www.microsoft.com/DRM/SL/BatchActivationResponse/1.0\";\r\n\r\n        public static string CallWebService(int requestType, string installationId, string extendedProductId) {\r\n            XDocument soapRequest = CreateSoapRequest(requestType, installationId, extendedProductId);\r\n            HttpWebRequest webRequest = CreateWebRequest(soapRequest);\r\n            XDocument soapResponse = new XDocument();\r\n\r\n            try {\r\n                IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);\r\n                asyncResult.AsyncWaitHandle.WaitOne();\r\n\r\n                // Read data from the response stream.\r\n                using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))\r\n                using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream())) {\r\n                    soapResponse = XDocument.Parse(streamReader.ReadToEnd());\r\n                }\r\n\r\n                return ParseSoapResponse(soapResponse);\r\n\r\n            } catch {\r\n                throw;\r\n            }\r\n        }\r\n\r\n        private static XDocument CreateSoapRequest(int requestType, string installationId, string extendedProductId) {\r\n            // Create an activation request.           \r\n            XElement activationRequest = new XElement(BatchActivationRequestNs + \"ActivationRequest\",\r\n                new XElement(BatchActivationRequestNs + \"VersionNumber\", \"2.0\"),\r\n                new XElement(BatchActivationRequestNs + \"RequestType\", requestType),\r\n                new XElement(BatchActivationRequestNs + \"Requests\",\r\n                    new XElement(BatchActivationRequestNs + \"Request\",\r\n                        new XElement(BatchActivationRequestNs + \"PID\", extendedProductId),\r\n                        requestType == 1 ? new XElement(BatchActivationRequestNs + \"IID\", installationId) : null)\r\n                )\r\n            );\r\n\r\n            // Get the unicode byte array of activationRequest and convert it to Base64.\r\n            byte[] bytes = Encoding.Unicode.GetBytes(activationRequest.ToString());\r\n            string requestXml = Convert.ToBase64String(bytes);\r\n\r\n            XDocument soapRequest = new XDocument();\r\n\r\n            using (HMACSHA256 hMACSHA = new HMACSHA256(MacKey)) {\r\n                // Convert the HMAC hashed data to Base64.\r\n                string digest = Convert.ToBase64String(hMACSHA.ComputeHash(bytes));\r\n\r\n                soapRequest = new XDocument(\r\n                new XDeclaration(\"1.0\", \"UTF-8\", \"no\"),\r\n                new XElement(SoapSchemaNs + \"Envelope\",\r\n                    new XAttribute(XNamespace.Xmlns + \"soap\", SoapSchemaNs),\r\n                    new XAttribute(XNamespace.Xmlns + \"xsi\", XmlSchemaInstanceNs),\r\n                    new XAttribute(XNamespace.Xmlns + \"xsd\", XmlSchemaNs),\r\n                    new XElement(SoapSchemaNs + \"Body\",\r\n                        new XElement(BatchActivationServiceNs + \"BatchActivate\",\r\n                            new XElement(BatchActivationServiceNs + \"request\",\r\n                                new XElement(BatchActivationServiceNs + \"Digest\", digest),\r\n                                new XElement(BatchActivationServiceNs + \"RequestXml\", requestXml)\r\n                            )\r\n                        )\r\n                    )\r\n                ));\r\n\r\n            }\r\n\r\n            return soapRequest;\r\n        }\r\n\r\n        private static HttpWebRequest CreateWebRequest(XDocument soapRequest) {\r\n            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Uri);\r\n            webRequest.Accept = \"text/xml\";\r\n            webRequest.ContentType = \"text/xml; charset=\\\"utf-8\\\"\";\r\n            webRequest.Headers.Add(\"SOAPAction\", Action);\r\n            webRequest.Host = \"activation.sls.microsoft.com\";\r\n            webRequest.Method = \"POST\";\r\n\r\n            try {\r\n                // Insert SOAP envelope\r\n                using (Stream stream = webRequest.GetRequestStream()) {\r\n                    soapRequest.Save(stream);\r\n                }\r\n\r\n                return webRequest;\r\n\r\n            } catch {\r\n                throw;\r\n            }\r\n        }\r\n\r\n        private static string ParseSoapResponse(XDocument soapResponse) {\r\n            if (soapResponse == null) {\r\n                throw new ArgumentNullException(\"soapResponse\", \"The remote server returned an unexpected response.\");\r\n            }\r\n\r\n            if (!soapResponse.Descendants(BatchActivationServiceNs + \"ResponseXml\").Any()) {\r\n                throw new Exception(\"The remote server returned an unexpected response\");\r\n            }\r\n\r\n            try {\r\n                XDocument responseXml = XDocument.Parse(soapResponse.Descendants(BatchActivationServiceNs + \"ResponseXml\").First().Value);\r\n\r\n                if (responseXml.Descendants(BatchActivationResponseNs + \"ErrorCode\").Any()) {\r\n                    string errorCode = responseXml.Descendants(BatchActivationResponseNs + \"ErrorCode\").First().Value;\r\n\r\n                    switch (errorCode) {\r\n                        case \"0x7F\":\r\n                            throw new Exception(\"The Multiple Activation Key has exceeded its limit\");\r\n\r\n                        case \"0x67\":\r\n                            throw new Exception(\"The product key has been blocked\");\r\n\r\n                        case \"0x68\":\r\n                            throw new Exception(\"Invalid product key\");\r\n\r\n                        case \"0x86\":\r\n                            throw new Exception(\"Invalid key type\");\r\n\r\n                        case \"0x90\":\r\n                            throw new Exception(\"Please check the Installation ID and try again\");\r\n\r\n                        default:\r\n                            throw new Exception(string.Format(\"The remote server reported an error ({0})\", errorCode));\r\n                    }\r\n\r\n                } else if (responseXml.Descendants(BatchActivationResponseNs + \"ResponseType\").Any()) {\r\n                    string responseType = responseXml.Descendants(BatchActivationResponseNs + \"ResponseType\").First().Value;\r\n\r\n                    switch (responseType) {\r\n                        case \"1\":\r\n                            string confirmationId = responseXml.Descendants(BatchActivationResponseNs + \"CID\").First().Value;\r\n                            return confirmationId;\r\n\r\n                        case \"2\":\r\n                            string activationsRemaining = responseXml.Descendants(BatchActivationResponseNs + \"ActivationRemaining\").First().Value;\r\n                            return activationsRemaining;\r\n\r\n                        default:\r\n                            throw new Exception(\"The remote server returned an unrecognized response\");\r\n                    }\r\n\r\n                } else {\r\n                    throw new Exception(\"The remote server returned an unrecognized response\");\r\n                }\r\n\r\n            } catch {\r\n                throw;\r\n            }\r\n        }\r\n    }\r\n}\r\n#endif\r\n\r\n// LibTSforge/Common.cs\r\nnamespace LibTSforge\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using System.Runtime.InteropServices;\r\n    using System.Text;\r\n\r\n    public enum PSVersion\r\n    {\r\n        Vista,\r\n        Win7,\r\n        Win8,\r\n        WinBlue,\r\n        WinModern\r\n    }\r\n\r\n    public static class Constants\r\n    {\r\n        public static readonly byte[] UniversalHWIDBlock =\r\n        {\r\n            0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00,\r\n            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n            0x00, 0x00, 0x01, 0x0c, 0x01, 0x00\r\n        };\r\n\r\n        public static readonly byte[] KMSv4Response =\r\n        {\r\n            0x00, 0x00, 0x04, 0x00, 0x62, 0x00, 0x00, 0x00, 0x30, 0x00, 0x35, 0x00, 0x34, 0x00, 0x32, 0x00,\r\n            0x36, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x30, 0x00, 0x32, 0x00, 0x30, 0x00, 0x36, 0x00, 0x2D, 0x00,\r\n            0x31, 0x00, 0x36, 0x00, 0x31, 0x00, 0x2D, 0x00, 0x36, 0x00, 0x35, 0x00, 0x35, 0x00, 0x35, 0x00,\r\n            0x30, 0x00, 0x36, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x33, 0x00, 0x2D, 0x00, 0x31, 0x00, 0x30, 0x00,\r\n            0x33, 0x00, 0x33, 0x00, 0x2D, 0x00, 0x39, 0x00, 0x32, 0x00, 0x30, 0x00, 0x30, 0x00, 0x2E, 0x00,\r\n            0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x36, 0x00, 0x35, 0x00,\r\n            0x32, 0x00, 0x30, 0x00, 0x31, 0x00, 0x33, 0x00, 0x00, 0x00, 0xDE, 0x19, 0x02, 0xCF, 0x1F, 0x35,\r\n            0x97, 0x4E, 0x8A, 0x8F, 0xB8, 0x07, 0xB1, 0x92, 0xB5, 0xB5, 0x97, 0x42, 0xEC, 0x3A, 0x76, 0x84,\r\n            0xD5, 0x01, 0x32, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x60, 0x27, 0x00, 0x00, 0xC4, 0x1E,\r\n            0xAA, 0x8B, 0xDD, 0x0C, 0xAB, 0x55, 0x6A, 0xCE, 0xAF, 0xAC, 0x7F, 0x5F, 0xBD, 0xE9\r\n        };\r\n\r\n        public static readonly byte[] KMSv5Response =\r\n        {\r\n            0x00, 0x00, 0x05, 0x00, 0xBE, 0x96, 0xF9, 0x04, 0x54, 0x17, 0x3F, 0xAF, 0xE3, 0x08, 0x50, 0xEB,\r\n            0x22, 0xBA, 0x53, 0xBF, 0xF2, 0x6A, 0x7B, 0xC9, 0x05, 0x1D, 0xB5, 0x19, 0xDF, 0x98, 0xE2, 0x71,\r\n            0x4D, 0x00, 0x61, 0xE9, 0x9D, 0x03, 0xFB, 0x31, 0xF9, 0x1F, 0x2E, 0x60, 0x59, 0xC7, 0x73, 0xC8,\r\n            0xE8, 0xB6, 0xE1, 0x2B, 0x39, 0xC6, 0x35, 0x0E, 0x68, 0x7A, 0xAA, 0x4F, 0x28, 0x23, 0x12, 0x18,\r\n            0xE3, 0xAA, 0x84, 0x81, 0x6E, 0x82, 0xF0, 0x3F, 0xD9, 0x69, 0xA9, 0xDF, 0xBA, 0x5F, 0xCA, 0x32,\r\n            0x54, 0xB2, 0x52, 0x3B, 0x3E, 0xD1, 0x5C, 0x65, 0xBC, 0x3E, 0x59, 0x0D, 0x15, 0x9F, 0x37, 0xEC,\r\n            0x30, 0x9C, 0xCC, 0x1B, 0x39, 0x0D, 0x21, 0x32, 0x29, 0xA2, 0xDD, 0xC7, 0xC1, 0x69, 0xF2, 0x72,\r\n            0x3F, 0x00, 0x98, 0x1E, 0xF8, 0x9A, 0x79, 0x44, 0x5D, 0x25, 0x80, 0x7B, 0xF5, 0xE1, 0x7C, 0x68,\r\n            0x25, 0xAA, 0x0D, 0x67, 0x98, 0xE5, 0x59, 0x9B, 0x04, 0xC1, 0x23, 0x33, 0x48, 0xFB, 0x28, 0xD0,\r\n            0x76, 0xDF, 0x01, 0x56, 0xE7, 0xEC, 0xBF, 0x1A, 0xA2, 0x22, 0x28, 0xCA, 0xB1, 0xB4, 0x4C, 0x30,\r\n            0x14, 0x6F, 0xD2, 0x2E, 0x01, 0x2A, 0x04, 0xE3, 0xBD, 0xA7, 0x41, 0x2F, 0xC9, 0xEF, 0x53, 0xC0,\r\n            0x70, 0x48, 0xF1, 0xB2, 0xB6, 0xEA, 0xE7, 0x0F, 0x7A, 0x15, 0xD1, 0xA6, 0xFE, 0x23, 0xC8, 0xF3,\r\n            0xE1, 0x02, 0x9E, 0xA0, 0x4E, 0xBD, 0xF5, 0xEA, 0x53, 0x74, 0x8E, 0x74, 0xA1, 0xA1, 0xBD, 0xBE,\r\n            0x66, 0xC4, 0x73, 0x8F, 0x24, 0xA7, 0x2A, 0x2F, 0xE3, 0xD9, 0xF4, 0x28, 0xD9, 0xF8, 0xA3, 0x93,\r\n            0x03, 0x9E, 0x29, 0xAB\r\n        };\r\n\r\n        public static readonly byte[] KMSv6Response =\r\n        {\r\n            0x00, 0x00, 0x06, 0x00, 0x54, 0xD3, 0x40, 0x08, 0xF3, 0xCD, 0x03, 0xEF, 0xC8, 0x15, 0x87, 0x9E,\r\n            0xCA, 0x2E, 0x85, 0xFB, 0xE6, 0xF6, 0x73, 0x66, 0xFB, 0xDA, 0xBB, 0x7B, 0xB1, 0xBC, 0xD6, 0xF9,\r\n            0x5C, 0x41, 0xA0, 0xFE, 0xE1, 0x74, 0xC4, 0xBB, 0x91, 0xE5, 0xDE, 0x6D, 0x3A, 0x11, 0xD5, 0xFC,\r\n            0x68, 0xC0, 0x7B, 0x82, 0xB2, 0x24, 0xD1, 0x85, 0xBA, 0x45, 0xBF, 0xF1, 0x26, 0xFA, 0xA5, 0xC6,\r\n            0x61, 0x70, 0x69, 0x69, 0x6E, 0x0F, 0x0B, 0x60, 0xB7, 0x3D, 0xE8, 0xF1, 0x47, 0x0B, 0x65, 0xFD,\r\n            0xA7, 0x30, 0x1E, 0xF6, 0xA4, 0xD0, 0x79, 0xC4, 0x58, 0x8D, 0x81, 0xFD, 0xA7, 0xE7, 0x53, 0xF1,\r\n            0x67, 0x78, 0xF0, 0x0F, 0x60, 0x8F, 0xC8, 0x16, 0x35, 0x22, 0x94, 0x48, 0xCB, 0x0F, 0x8E, 0xB2,\r\n            0x1D, 0xF7, 0x3E, 0x28, 0x42, 0x55, 0x6B, 0x07, 0xE3, 0xE8, 0x51, 0xD5, 0xFA, 0x22, 0x0C, 0x86,\r\n            0x65, 0x0D, 0x3F, 0xDD, 0x8D, 0x9B, 0x1B, 0xC9, 0xD3, 0xB8, 0x3A, 0xEC, 0xF1, 0x11, 0x19, 0x25,\r\n            0xF7, 0x84, 0x4A, 0x4C, 0x0A, 0xB5, 0x31, 0x94, 0x37, 0x76, 0xCE, 0xE7, 0xAB, 0xA9, 0x69, 0xDF,\r\n            0xA4, 0xC9, 0x22, 0x6C, 0x23, 0xFF, 0x6B, 0xFC, 0xDA, 0x78, 0xD8, 0xC4, 0x8F, 0x74, 0xBB, 0x26,\r\n            0x05, 0x00, 0x98, 0x9B, 0xE5, 0xE2, 0xAD, 0x0D, 0x57, 0x95, 0x80, 0x66, 0x8E, 0x43, 0x74, 0x87,\r\n            0x93, 0x1F, 0xF4, 0xB2, 0x2C, 0x20, 0x5F, 0xD8, 0x9C, 0x4C, 0x56, 0xB3, 0x57, 0x44, 0x62, 0x68,\r\n            0x8D, 0xAA, 0x40, 0x11, 0x9D, 0x84, 0x62, 0x0E, 0x43, 0x8A, 0x1D, 0xF0, 0x1C, 0x49, 0xD8, 0x56,\r\n            0xEF, 0x4C, 0xD3, 0x64, 0xBA, 0x0D, 0xEF, 0x87, 0xB5, 0x2C, 0x88, 0xF3, 0x18, 0xFF, 0x3A, 0x8C,\r\n            0xF5, 0xA6, 0x78, 0x5C, 0x62, 0xE3, 0x9E, 0x4C, 0xB6, 0x31, 0x2D, 0x06, 0x80, 0x92, 0xBC, 0x2E,\r\n            0x92, 0xA6, 0x56, 0x96\r\n        };\r\n\r\n        // 2^31 - 8 minutes\r\n        public static readonly ulong TimerMax = (ulong)TimeSpan.FromMinutes(2147483640).Ticks;\r\n\r\n        public static readonly string ZeroCID = new string('0', 48);\r\n    }\r\n\r\n    public static class BinaryReaderExt\r\n    {\r\n        public static void Align(this BinaryReader reader, int to)\r\n        {\r\n            int pos = (int)reader.BaseStream.Position;\r\n            reader.BaseStream.Seek(-pos & (to - 1), SeekOrigin.Current);\r\n        }\r\n\r\n        public static string ReadNullTerminatedString(this BinaryReader reader, int maxLen)\r\n        {\r\n            return Encoding.Unicode.GetString(reader.ReadBytes(maxLen)).Split(new char[] { '\\0' }, 2)[0];\r\n        }\r\n    }\r\n\r\n    public static class BinaryWriterExt\r\n    {\r\n        public static void Align(this BinaryWriter writer, int to)\r\n        {\r\n            int pos = (int)writer.BaseStream.Position;\r\n            writer.WritePadding(-pos & (to - 1));\r\n        }\r\n\r\n        public static void WritePadding(this BinaryWriter writer, int len)\r\n        {\r\n            writer.Write(Enumerable.Repeat((byte)0, len).ToArray());\r\n        }\r\n\r\n        public static void WriteFixedString(this BinaryWriter writer, string str, int bLen)\r\n        {\r\n            writer.Write(Encoding.ASCII.GetBytes(str));\r\n            writer.WritePadding(bLen - str.Length);\r\n        }\r\n\r\n        public static void WriteFixedString16(this BinaryWriter writer, string str, int bLen)\r\n        {\r\n            byte[] bstr = Utils.EncodeString(str);\r\n            writer.Write(bstr);\r\n            writer.WritePadding(bLen - bstr.Length);\r\n        }\r\n\r\n        public static byte[] GetBytes(this BinaryWriter writer)\r\n        {\r\n            return ((MemoryStream)writer.BaseStream).ToArray();\r\n        }\r\n    }\r\n\r\n    public static class ByteArrayExt\r\n    {\r\n        public static byte[] CastToArray<T>(this T data) where T : struct\r\n        {\r\n            int size = Marshal.SizeOf(typeof(T));\r\n            byte[] result = new byte[size];\r\n            GCHandle handle = GCHandle.Alloc(result, GCHandleType.Pinned);\r\n            try\r\n            {\r\n                Marshal.StructureToPtr(data, handle.AddrOfPinnedObject(), false);\r\n            }\r\n            finally\r\n            {\r\n                handle.Free();\r\n            }\r\n            return result;\r\n        }\r\n    }\r\n\r\n    public static class FileStreamExt\r\n    {\r\n        public static byte[] ReadAllBytes(this FileStream fs)\r\n        {\r\n            BinaryReader br = new BinaryReader(fs);\r\n            return br.ReadBytes((int)fs.Length);\r\n        }\r\n\r\n        public static void WriteAllBytes(this FileStream fs, byte[] data)\r\n        {\r\n            fs.Seek(0, SeekOrigin.Begin);\r\n            fs.SetLength(data.Length);\r\n            fs.Write(data, 0, data.Length);\r\n        }\r\n    }\r\n\r\n    public static class Utils\r\n    {\r\n        [DllImport(\"kernel32.dll\")]\r\n        public static extern uint GetSystemDefaultLCID();\r\n\r\n        [DllImport(\"kernel32.dll\")]\r\n        public static extern bool Wow64EnableWow64FsRedirection(bool Wow64FsEnableRedirection);\r\n\r\n        public static string DecodeString(byte[] data)\r\n        {\r\n            return Encoding.Unicode.GetString(data).Trim('\\0');\r\n        }\r\n\r\n        public static byte[] EncodeString(string str)\r\n        {\r\n            return Encoding.Unicode.GetBytes(str + '\\0');\r\n        }\r\n\r\n        public static uint CRC32(byte[] data)\r\n        {\r\n            const uint polynomial = 0x04C11DB7;\r\n            uint crc = 0xffffffff;\r\n\r\n            foreach (byte b in data)\r\n            {\r\n                crc ^= (uint)b << 24;\r\n                for (int bit = 0; bit < 8; bit++)\r\n                {\r\n                    if ((crc & 0x80000000) != 0)\r\n                    {\r\n                        crc = (crc << 1) ^ polynomial;\r\n                    }\r\n                    else\r\n                    {\r\n                        crc <<= 1;\r\n                    }\r\n                }\r\n            }\r\n            return ~crc;\r\n        }\r\n\r\n        public static string GetArchitecture()\r\n        {\r\n            string arch = Environment.GetEnvironmentVariable(\"PROCESSOR_ARCHITECTURE\", EnvironmentVariableTarget.Machine).ToUpperInvariant();\r\n            return arch == \"AMD64\" ? \"X64\" : arch;\r\n        }\r\n\r\n        public static PSVersion DetectVersion()\r\n        {\r\n            int build = Environment.OSVersion.Version.Build;\r\n\r\n            if (build >= 9600) return PSVersion.WinModern;\r\n            if (build >= 6000 && build <= 6003) return PSVersion.Vista;\r\n            if (build >= 7600 && build <= 7602) return PSVersion.Win7;\r\n            if (build == 9200) return PSVersion.Win8;\r\n\r\n            throw new NotSupportedException(\"Unable to auto-detect version info\");\r\n        }\r\n    }\r\n\r\n    public static class Logger\r\n    {\r\n        public static bool HideOutput = false;\r\n\r\n        public static void WriteLine(string line)\r\n        {\r\n            if (!HideOutput) Console.WriteLine(line);\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/SPP/PKeyConfig.cs\r\nnamespace LibTSforge.SPP\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using System.Text;\r\n    using System.Xml;\r\n\r\n    public enum PKeyAlgorithm\r\n    {\r\n        PKEY2005,\r\n        PKEY2009\r\n    }\r\n\r\n    public class KeyRange\r\n    {\r\n        public int Start;\r\n        public int End;\r\n        public string EulaType;\r\n        public string PartNumber;\r\n        public bool Valid;\r\n\r\n        public bool Contains(int n)\r\n        {\r\n            return Start <= n && n <= End;\r\n        }\r\n    }\r\n\r\n    public class ProductConfig\r\n    {\r\n        public int GroupId;\r\n        public string Edition;\r\n        public string Description;\r\n        public string Channel;\r\n        public bool Randomized;\r\n        public PKeyAlgorithm Algorithm;\r\n        public List<KeyRange> Ranges;\r\n        public Guid ActivationId;\r\n\r\n        private List<KeyRange> GetPkeyRanges()\r\n        {\r\n            if (Ranges.Count == 0)\r\n            {\r\n                throw new ArgumentException(\"No key ranges.\");\r\n            }\r\n\r\n            if (Algorithm == PKeyAlgorithm.PKEY2005)\r\n            {\r\n                return Ranges;\r\n            }\r\n\r\n            List<KeyRange> FilteredRanges = Ranges.Where(r => !r.EulaType.Contains(\"WAU\")).ToList();\r\n\r\n            if (FilteredRanges.Count == 0)\r\n            {\r\n                throw new NotSupportedException(\"Specified Activation ID is usable only for Windows Anytime Upgrade. Please use a non-WAU Activation ID instead.\");\r\n            }\r\n\r\n            return FilteredRanges;\r\n        }\r\n\r\n        public ProductKey GetRandomKey()\r\n        {\r\n            List<KeyRange> KeyRanges = GetPkeyRanges();\r\n            Random rnd = new Random();\r\n\r\n            KeyRange range = KeyRanges[rnd.Next(KeyRanges.Count)];\r\n            int serial = rnd.Next(range.Start, range.End);\r\n\r\n            return new ProductKey(serial, 0, false, Algorithm, this, range);\r\n        }\r\n    }\r\n\r\n    public class PKeyConfig\r\n    {\r\n        public readonly Dictionary<Guid, ProductConfig> Products = new Dictionary<Guid, ProductConfig>();\r\n        private readonly List<Guid> loadedPkeyConfigs = new List<Guid>();\r\n\r\n        public void LoadConfig(Guid actId)\r\n        {\r\n            string pkcData;\r\n            Guid pkcFileId = SLApi.GetPkeyConfigFileId(actId);\r\n\r\n            if (loadedPkeyConfigs.Contains(pkcFileId)) return;\r\n\r\n            string licConts = SLApi.GetLicenseContents(pkcFileId);\r\n\r\n            using (TextReader tr = new StringReader(licConts))\r\n            {\r\n                XmlDocument lic = new XmlDocument();\r\n                lic.Load(tr);\r\n\r\n                XmlNamespaceManager nsmgr = new XmlNamespaceManager(lic.NameTable);\r\n                nsmgr.AddNamespace(\"rg\", \"urn:mpeg:mpeg21:2003:01-REL-R-NS\");\r\n                nsmgr.AddNamespace(\"r\", \"urn:mpeg:mpeg21:2003:01-REL-R-NS\");\r\n                nsmgr.AddNamespace(\"tm\", \"http://www.microsoft.com/DRM/XrML2/TM/v2\");\r\n\r\n                XmlNode root = lic.DocumentElement;\r\n                XmlNode pkcDataNode = root.SelectSingleNode(\"/rg:licenseGroup/r:license/r:otherInfo/tm:infoTables/tm:infoList/tm:infoBin[@name=\\\"pkeyConfigData\\\"]\", nsmgr);\r\n                pkcData = Encoding.UTF8.GetString(Convert.FromBase64String(pkcDataNode.InnerText));\r\n            }\r\n\r\n            using (TextReader tr = new StringReader(pkcData))\r\n            {\r\n                XmlDocument lic = new XmlDocument();\r\n                lic.Load(tr);\r\n\r\n                XmlNamespaceManager nsmgr = new XmlNamespaceManager(lic.NameTable);\r\n                nsmgr.AddNamespace(\"p\", \"http://www.microsoft.com/DRM/PKEY/Configuration/2.0\");\r\n                XmlNodeList configNodes = lic.SelectNodes(\"//p:ProductKeyConfiguration/p:Configurations/p:Configuration\", nsmgr);\r\n                XmlNodeList rangeNodes = lic.SelectNodes(\"//p:ProductKeyConfiguration/p:KeyRanges/p:KeyRange\", nsmgr);\r\n                XmlNodeList pubKeyNodes = lic.SelectNodes(\"//p:ProductKeyConfiguration/p:PublicKeys/p:PublicKey\", nsmgr);\r\n\r\n                Dictionary<int, PKeyAlgorithm> algorithms = new Dictionary<int, PKeyAlgorithm>();\r\n                Dictionary<string, List<KeyRange>> ranges = new Dictionary<string, List<KeyRange>>();\r\n\r\n                Dictionary<string, PKeyAlgorithm> algoConv = new Dictionary<string, PKeyAlgorithm>\r\n                {\r\n                    { \"msft:rm/algorithm/pkey/2005\", PKeyAlgorithm.PKEY2005 },\r\n                    { \"msft:rm/algorithm/pkey/2009\", PKeyAlgorithm.PKEY2009 }\r\n                };\r\n\r\n                foreach (XmlNode pubKeyNode in pubKeyNodes)\r\n                {\r\n                    int group = int.Parse(pubKeyNode.SelectSingleNode(\"./p:GroupId\", nsmgr).InnerText);\r\n                    algorithms[group] = algoConv[pubKeyNode.SelectSingleNode(\"./p:AlgorithmId\", nsmgr).InnerText];\r\n                }\r\n\r\n                foreach (XmlNode rangeNode in rangeNodes)\r\n                {\r\n                    string refActIdStr = rangeNode.SelectSingleNode(\"./p:RefActConfigId\", nsmgr).InnerText;\r\n\r\n                    if (!ranges.ContainsKey(refActIdStr))\r\n                    {\r\n                        ranges[refActIdStr] = new List<KeyRange>();\r\n                    }\r\n\r\n                    KeyRange keyRange = new KeyRange\r\n                    {\r\n                        Start = int.Parse(rangeNode.SelectSingleNode(\"./p:Start\", nsmgr).InnerText),\r\n                        End = int.Parse(rangeNode.SelectSingleNode(\"./p:End\", nsmgr).InnerText),\r\n                        EulaType = rangeNode.SelectSingleNode(\"./p:EulaType\", nsmgr).InnerText,\r\n                        PartNumber = rangeNode.SelectSingleNode(\"./p:PartNumber\", nsmgr).InnerText,\r\n                        Valid = rangeNode.SelectSingleNode(\"./p:IsValid\", nsmgr).InnerText.ToLower() == \"true\"\r\n                    };\r\n\r\n                    ranges[refActIdStr].Add(keyRange);\r\n                }\r\n\r\n                foreach (XmlNode configNode in configNodes)\r\n                {\r\n                    string refActIdStr = configNode.SelectSingleNode(\"./p:ActConfigId\", nsmgr).InnerText;\r\n                    Guid refActId = new Guid(refActIdStr);\r\n                    int group = int.Parse(configNode.SelectSingleNode(\"./p:RefGroupId\", nsmgr).InnerText);\r\n                    List<KeyRange> keyRanges;\r\n                    ranges.TryGetValue(refActIdStr, out keyRanges);\r\n\r\n                    if (keyRanges == null) \r\n                    {\r\n                        continue;\r\n                    }\r\n\r\n                    if (keyRanges.Count > 0 && !Products.ContainsKey(refActId))\r\n                    {\r\n                        PKeyAlgorithm algorithm;\r\n                        algorithms.TryGetValue(group, out algorithm);\r\n\r\n                        ProductConfig productConfig = new ProductConfig\r\n                        {\r\n                            GroupId = group,\r\n                            Edition = configNode.SelectSingleNode(\"./p:EditionId\", nsmgr).InnerText,\r\n                            Description = configNode.SelectSingleNode(\"./p:ProductDescription\", nsmgr).InnerText,\r\n                            Channel = configNode.SelectSingleNode(\"./p:ProductKeyType\", nsmgr).InnerText,\r\n                            Randomized = configNode.SelectSingleNode(\"./p:ProductKeyType\", nsmgr).InnerText.ToLower() == \"true\",\r\n                            Algorithm = algorithm,\r\n                            Ranges = keyRanges,\r\n                            ActivationId = refActId\r\n                        };\r\n\r\n                        Products[refActId] = productConfig;\r\n                    }\r\n                }\r\n            }\r\n\r\n            loadedPkeyConfigs.Add(pkcFileId);\r\n        }\r\n\r\n        public ProductConfig MatchParams(int group, int serial)\r\n        {\r\n            foreach (ProductConfig config in Products.Values)\r\n            {\r\n                if (config.GroupId == group)\r\n                {\r\n                    foreach (KeyRange range in config.Ranges)\r\n                    {\r\n                        if (range.Contains(serial))\r\n                        {\r\n                            return config;\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n\r\n            throw new FileNotFoundException(\"Failed to find product matching supplied product key parameters.\");\r\n        }\r\n\r\n        public void LoadAllConfigs(Guid appId)\r\n        {\r\n            foreach (Guid actId in SLApi.GetActivationIds(appId))\r\n            {\r\n                try\r\n                {\r\n                    LoadConfig(actId);\r\n                } \r\n                catch (ArgumentException)\r\n                {\r\n\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/SPP/ProductKey.cs\r\nnamespace LibTSforge.SPP\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using Crypto;\r\n    using PhysicalStore;\r\n\r\n    public class ProductKey\r\n    {\r\n        private static readonly string ALPHABET = \"BCDFGHJKMPQRTVWXY2346789\";\r\n\r\n        private readonly ulong klow;\r\n        private readonly ulong khigh;\r\n\r\n        public int Group;\r\n        public int Serial;\r\n        public ulong Security;\r\n        public bool Upgrade;\r\n        public PKeyAlgorithm Algorithm;\r\n        public readonly string EulaType;\r\n        public readonly string PartNumber;\r\n        public readonly string Edition;\r\n        public readonly string Channel;\r\n        public readonly Guid ActivationId;\r\n\r\n        private string mpc;\r\n        private string pid2;\r\n\r\n        public byte[] KeyBytes\r\n        {\r\n            get { return BitConverter.GetBytes(klow).Concat(BitConverter.GetBytes(khigh)).ToArray(); }\r\n        }\r\n\r\n        public ProductKey()\r\n        {\r\n\r\n        }\r\n\r\n        public ProductKey(int serial, ulong security, bool upgrade, PKeyAlgorithm algorithm, ProductConfig config, KeyRange range)\r\n        {\r\n            Group = config.GroupId;\r\n            Serial = serial;\r\n            Security = security;\r\n            Upgrade = upgrade;\r\n            Algorithm = algorithm;\r\n            EulaType = range.EulaType;\r\n            PartNumber = range.PartNumber.Split(':', ';')[0];\r\n            Edition = config.Edition;\r\n            Channel = config.Channel;\r\n            ActivationId = config.ActivationId;\r\n\r\n            klow = ((security & 0x3fff) << 50 | ((ulong)serial & 0x3fffffff) << 20 | ((ulong)Group & 0xfffff));\r\n            khigh = ((upgrade ? (ulong)1 : 0) << 49 | ((security >> 14) & 0x7fffffffff));\r\n\r\n            uint checksum = Utils.CRC32(KeyBytes) & 0x3ff;\r\n\r\n            khigh |= ((ulong)checksum << 39);\r\n        }\r\n\r\n        public string GetAlgoUri()\r\n        {\r\n            return \"msft:rm/algorithm/pkey/\" + (Algorithm == PKeyAlgorithm.PKEY2005 ? \"2005\" : (Algorithm == PKeyAlgorithm.PKEY2009 ? \"2009\" : \"Unknown\"));\r\n        }\r\n\r\n        public Guid GetPkeyId()\r\n        {\r\n            VariableBag pkb = new VariableBag(PSVersion.WinModern);\r\n            pkb.Blocks.AddRange(new[]\r\n            {\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyBindingProductKey\",\r\n                    ValueAsStr = ToString()\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = \"SppPkeyBindingMiscData\",\r\n                    Value = new byte[] { }\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyBindingAlgorithm\",\r\n                    ValueAsStr = GetAlgoUri()\r\n                }\r\n            });\r\n\r\n            return new Guid(CryptoUtils.SHA256Hash(pkb.Serialize()).Take(16).ToArray());\r\n        }\r\n\r\n        public string GetMPC()\r\n        {\r\n            if (mpc != null)\r\n            {\r\n                return mpc;\r\n            }\r\n\r\n            int build = Environment.OSVersion.Version.Build;\r\n\r\n            mpc = build >= 10240 ? \"03612\" :\r\n                    build >= 9600 ? \"06401\" :\r\n                    build >= 9200 ? \"05426\" :\r\n                    \"55041\";\r\n\r\n            // setup.cfg doesn't exist in Windows 8+\r\n            string setupcfg = string.Format(@\"{0}\\oobe\\{1}\", Environment.SystemDirectory, \"setup.cfg\");\r\n\r\n            if (!File.Exists(setupcfg) || Edition.Contains(\";\"))\r\n            {\r\n                return mpc;\r\n            }\r\n\r\n            string mpcKey = string.Format(\"{0}.{1}=\", Utils.GetArchitecture(), Edition);\r\n            string localMPC = File.ReadAllLines(setupcfg).FirstOrDefault(line => line.Contains(mpcKey));\r\n            if (localMPC != null)\r\n            {\r\n                mpc = localMPC.Split('=')[1].Trim();\r\n            }\r\n\r\n            return mpc;\r\n        }\r\n\r\n        public string GetPid2()\r\n        {\r\n            if (pid2 != null)\r\n            {\r\n                return pid2;\r\n            }\r\n\r\n            pid2 = \"\";\r\n\r\n            if (Algorithm == PKeyAlgorithm.PKEY2005)\r\n            {\r\n                string mpc = GetMPC();\r\n                string serialHigh;\r\n                int serialLow;\r\n                int lastPart;\r\n\r\n                if (EulaType == \"OEM\")\r\n                {\r\n                    serialHigh = \"OEM\";\r\n                    serialLow = ((Group / 2) % 100) * 10000 + (Serial / 100000);\r\n                    lastPart = Serial % 100000;\r\n                }\r\n                else\r\n                {\r\n                    serialHigh = (Serial / 1000000).ToString(\"D3\");\r\n                    serialLow = Serial % 1000000;\r\n                    lastPart = ((Group / 2) % 100) * 1000 + new Random().Next(1000);\r\n                }\r\n\r\n                int checksum = 0;\r\n\r\n                foreach (char c in serialLow.ToString())\r\n                {\r\n                    checksum += int.Parse(c.ToString());\r\n                }\r\n                checksum = 7 - (checksum % 7);\r\n\r\n                pid2 = string.Format(\"{0}-{1}-{2:D6}{3}-{4:D5}\", mpc, serialHigh, serialLow, checksum, lastPart);\r\n            }\r\n\r\n            return pid2;\r\n        }\r\n\r\n        public byte[] GetPid3()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(0xA4);\r\n            writer.Write(0x3);\r\n            writer.WriteFixedString(GetPid2(), 24);\r\n            writer.Write(Group);\r\n            writer.WriteFixedString(PartNumber, 16);\r\n            writer.WritePadding(0x6C);\r\n            byte[] data = writer.GetBytes();\r\n            byte[] crc = BitConverter.GetBytes(~Utils.CRC32(data.Reverse().ToArray())).Reverse().ToArray();\r\n            writer.Write(crc);\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public byte[] GetPid4()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(0x4F8);\r\n            writer.Write(0x4);\r\n            writer.WriteFixedString16(GetExtendedPid(), 0x80);\r\n            writer.WriteFixedString16(ActivationId.ToString(), 0x80);\r\n            writer.WritePadding(0x10);\r\n            writer.WriteFixedString16(Edition, 0x208);\r\n            writer.Write(Upgrade ? (ulong)1 : 0);\r\n            writer.WritePadding(0x50);\r\n            writer.WriteFixedString16(PartNumber, 0x80);\r\n            writer.WriteFixedString16(Channel, 0x80);\r\n            writer.WriteFixedString16(EulaType, 0x80);\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public string GetExtendedPid()\r\n        {\r\n            string mpc = GetMPC();\r\n            int serialHigh = Serial / 1000000;\r\n            int serialLow = Serial % 1000000;\r\n            int licenseType;\r\n            uint lcid = Utils.GetSystemDefaultLCID();\r\n            int build = Environment.OSVersion.Version.Build;\r\n            int dayOfYear = DateTime.Now.DayOfYear;\r\n            int year = DateTime.Now.Year;\r\n\r\n            switch (EulaType)\r\n            {\r\n                case \"OEM\":\r\n                    licenseType = 2;\r\n                    break;\r\n\r\n                case \"Volume\":\r\n                    licenseType = 3;\r\n                    break;\r\n\r\n                default:\r\n                    licenseType = 0;\r\n                    break;\r\n            }\r\n\r\n            return string.Format(\r\n                \"{0}-{1:D5}-{2:D3}-{3:D6}-{4:D2}-{5:D4}-{6:D4}.0000-{7:D3}{8:D4}\",\r\n                mpc,\r\n                Group,\r\n                serialHigh,\r\n                serialLow,\r\n                licenseType,\r\n                lcid,\r\n                build,\r\n                dayOfYear,\r\n                year\r\n            );\r\n        }\r\n\r\n        public byte[] GetPhoneData(PSVersion version)\r\n        {\r\n            if (version == PSVersion.Win7)\r\n            {\r\n                ulong shortauth = ((ulong)Group << 41) | (Security << 31) | ((ulong)Serial << 1) | (Upgrade ? (ulong)1 : 0);\r\n                return BitConverter.GetBytes(shortauth);\r\n            }\r\n\r\n            int serialHigh = Serial / 1000000;\r\n            int serialLow = Serial % 1000000;\r\n\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            string algoId = Algorithm == PKeyAlgorithm.PKEY2005 ? \"B8731595-A2F6-430B-A799-FBFFB81A8D73\" : \"660672EF-7809-4CFD-8D54-41B7FB738988\";\r\n\r\n            writer.Write(new Guid(algoId).ToByteArray());\r\n            writer.Write(Group);\r\n            writer.Write(serialHigh);\r\n            writer.Write(serialLow);\r\n            writer.Write(Upgrade ? 1 : 0);\r\n            writer.Write(Security);\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public override string ToString()\r\n        {\r\n            string keyStr = \"\";\r\n            Random rnd = new Random(Group * 1000000000 + Serial);\r\n\r\n            if (Algorithm == PKeyAlgorithm.PKEY2005)\r\n            {\r\n                keyStr = \"H4X3DH4X3DH4X3DH4X3D\";\r\n\r\n                for (int i = 0; i < 5; i++)\r\n                {\r\n                    keyStr += ALPHABET[rnd.Next(24)];\r\n                }\r\n            }\r\n            else if (Algorithm == PKeyAlgorithm.PKEY2009)\r\n            {\r\n                int last = 0;\r\n                byte[] bKey = KeyBytes;\r\n\r\n                for (int i = 24; i >= 0; i--)\r\n                {\r\n                    int current = 0;\r\n\r\n                    for (int j = 14; j >= 0; j--)\r\n                    {\r\n                        current *= 0x100;\r\n                        current += bKey[j];\r\n                        bKey[j] = (byte)(current / 24);\r\n                        current %= 24;\r\n                        last = current;\r\n                    }\r\n\r\n                    keyStr = ALPHABET[current] + keyStr;\r\n                }\r\n\r\n                keyStr = keyStr.Substring(1, last) + \"N\" + keyStr.Substring(last + 1, keyStr.Length - last - 1);\r\n            }\r\n\r\n            for (int i = 5; i < keyStr.Length; i += 6)\r\n            {\r\n                keyStr = keyStr.Insert(i, \"-\");\r\n            }\r\n\r\n            return keyStr;\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/SPP/SLAPI.cs\r\nnamespace LibTSforge.SPP\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.Linq;\r\n    using System.Runtime.InteropServices;\r\n    using System.Text;\r\n\r\n    public static class SLApi\r\n    {\r\n        private enum SLIDTYPE\r\n        {\r\n            SL_ID_APPLICATION,\r\n            SL_ID_PRODUCT_SKU,\r\n            SL_ID_LICENSE_FILE,\r\n            SL_ID_LICENSE,\r\n            SL_ID_PKEY,\r\n            SL_ID_ALL_LICENSES,\r\n            SL_ID_ALL_LICENSE_FILES,\r\n            SL_ID_STORE_TOKEN,\r\n            SL_ID_LAST\r\n        }\r\n\r\n        private enum SLDATATYPE\r\n        {\r\n            SL_DATA_NONE,\r\n            SL_DATA_SZ,\r\n            SL_DATA_DWORD,\r\n            SL_DATA_BINARY,\r\n            SL_DATA_MULTI_SZ,\r\n            SL_DATA_SUM\r\n        }\r\n\r\n        [StructLayout(LayoutKind.Sequential)]\r\n        private struct SL_LICENSING_STATUS\r\n        {\r\n            public Guid SkuId;\r\n            public uint eStatus;\r\n            public uint dwGraceTime;\r\n            public uint dwTotalGraceDays;\r\n            public uint hrReason;\r\n            public ulong qwValidityExpiration;\r\n        }\r\n\r\n        public static readonly Guid WINDOWS_APP_ID = new Guid(\"55c92734-d682-4d71-983e-d6ec3f16059f\");\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode, PreserveSig = false)]\r\n        private static extern void SLOpen(out IntPtr hSLC);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode, PreserveSig = false)]\r\n        private static extern void SLClose(IntPtr hSLC);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetWindowsInformationDWORD(string ValueName, ref int Value);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLInstallProofOfPurchase(IntPtr hSLC, string pwszPKeyAlgorithm, string pwszPKeyString, uint cbPKeySpecificData, byte[] pbPKeySpecificData, ref Guid PKeyId);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLUninstallProofOfPurchase(IntPtr hSLC, ref Guid PKeyId);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetPKeyInformation(IntPtr hSLC, ref Guid pPKeyId, string pwszValueName, out SLDATATYPE peDataType, out uint pcbValue, out IntPtr ppbValue);\r\n\r\n        [DllImport(\"slcext.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLActivateProduct(IntPtr hSLC, ref Guid pProductSkuId, byte[] cbAppSpecificData, byte[] pvAppSpecificData, byte[] pActivationInfo, string pwszProxyServer, ushort wProxyPort);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGenerateOfflineInstallationId(IntPtr hSLC, ref Guid pProductSkuId, ref string ppwszInstallationId);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLDepositOfflineConfirmationId(IntPtr hSLC, ref Guid pProductSkuId, string pwszInstallationId, string pwszConfirmationId);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetSLIDList(IntPtr hSLC, SLIDTYPE eQueryIdType, ref Guid pQueryId, SLIDTYPE eReturnIdType, out uint pnReturnIds, out IntPtr ppReturnIds);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode, PreserveSig = false)]\r\n        private static extern void SLGetLicensingStatusInformation(IntPtr hSLC, ref Guid pAppID, IntPtr pProductSkuId, string pwszRightName, out uint pnStatusCount, out IntPtr ppLicensingStatus);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetInstalledProductKeyIds(IntPtr hSLC, ref Guid pProductSkuId, out uint pnProductKeyIds, out IntPtr ppProductKeyIds);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLConsumeWindowsRight(uint unknown);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetProductSkuInformation(IntPtr hSLC, ref Guid pProductSkuId, string pwszValueName, out SLDATATYPE peDataType, out uint pcbValue, out IntPtr ppbValue);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetLicense(IntPtr hSLC, ref Guid pLicenseFileId, out uint pcbLicenseFile, out IntPtr ppbLicenseFile);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLSetCurrentProductKey(IntPtr hSLC, ref Guid pProductSkuId, ref Guid pProductKeyId);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLFireEvent(IntPtr hSLC, string pwszEventId, ref Guid pApplicationId);\r\n\r\n        private class SLContext : IDisposable\r\n        {\r\n            public readonly IntPtr Handle;\r\n\r\n            public SLContext()\r\n            {\r\n                SLOpen(out Handle);\r\n            }\r\n\r\n            public void Dispose()\r\n            {\r\n                SLClose(Handle);\r\n                GC.SuppressFinalize(this);\r\n            }\r\n\r\n            ~SLContext()\r\n            {\r\n                Dispose();\r\n            }\r\n        }\r\n\r\n        public static Guid GetDefaultActivationID(Guid appId, bool includeActivated)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                IntPtr pLicStat;\r\n\r\n                SLGetLicensingStatusInformation(sl.Handle, ref appId, IntPtr.Zero, null, out count, out pLicStat);\r\n\r\n                unsafe\r\n                {\r\n                    SL_LICENSING_STATUS* licensingStatuses = (SL_LICENSING_STATUS*)pLicStat;\r\n                    for (int i = 0; i < count; i++)\r\n                    {\r\n                        SL_LICENSING_STATUS slStatus = licensingStatuses[i];\r\n\r\n                        Guid actId = slStatus.SkuId;\r\n                        if (GetInstalledPkeyID(actId) == Guid.Empty) continue;\r\n                        if (IsAddon(actId)) continue;\r\n                        if (!includeActivated && (slStatus.eStatus == 1)) continue;\r\n\r\n                        return actId;\r\n                    }\r\n                }\r\n\r\n                return Guid.Empty;\r\n            }\r\n        }\r\n\r\n        public static string GetInstallationID(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                string installationId = null;\r\n                return SLGenerateOfflineInstallationId(sl.Handle, ref actId, ref installationId) == 0 ? installationId : null;\r\n            }\r\n        }\r\n\r\n        public static Guid GetInstalledPkeyID(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                IntPtr pProductKeyIds;\r\n\r\n                uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_PKEY, out count, out pProductKeyIds);\r\n\r\n                if (status != 0 || count == 0)\r\n                {\r\n                    return Guid.Empty;\r\n                }\r\n\r\n                unsafe { return *(Guid*)pProductKeyIds; }\r\n            }\r\n        }\r\n\r\n        public static uint DepositConfirmationID(Guid actId, string installationId, string confirmationId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                return SLDepositOfflineConfirmationId(sl.Handle, ref actId, installationId, confirmationId);\r\n            }\r\n        }\r\n\r\n        public static void RefreshLicenseStatus()\r\n        {\r\n            SLConsumeWindowsRight(0);\r\n        }\r\n\r\n        public static void RefreshTrustedTime(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                SLDATATYPE type;\r\n                uint count;\r\n                IntPtr ppbValue;\r\n\r\n                SLGetProductSkuInformation(sl.Handle, ref actId, \"TrustedTime\", out type, out count, out ppbValue);\r\n            }\r\n        }\r\n\r\n        public static void FireStateChangedEvent(Guid appId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                SLFireEvent(sl.Handle, \"msft:rm/event/licensingstatechanged\", ref appId);\r\n            }\r\n        }\r\n\r\n        public static Guid GetAppId(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                IntPtr pAppIds;\r\n\r\n                uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_APPLICATION, out count, out pAppIds);\r\n\r\n                if (status != 0 || count == 0)\r\n                {\r\n                    return Guid.Empty;\r\n                }\r\n\r\n                unsafe { return *(Guid*)pAppIds; }\r\n            }\r\n        }\r\n\r\n        public static bool IsAddon(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                SLDATATYPE type;\r\n                IntPtr ppbValue;\r\n\r\n                uint status = SLGetProductSkuInformation(sl.Handle, ref actId, \"DependsOn\", out type, out count, out ppbValue);\r\n                return (int)status >= 0 && status != 0xC004F012;\r\n            }\r\n        }\r\n\r\n        public static Guid GetLicenseFileId(Guid licId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                IntPtr ppReturnLics;\r\n\r\n                uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_LICENSE, ref licId, SLIDTYPE.SL_ID_LICENSE_FILE, out count, out ppReturnLics);\r\n\r\n                if (status != 0 || count == 0)\r\n                {\r\n                    return Guid.Empty;\r\n                }\r\n\r\n                unsafe { return *(Guid*)ppReturnLics; }\r\n            }\r\n        }\r\n\r\n        public static Guid GetPkeyConfigFileId(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                SLDATATYPE type;\r\n                uint len;\r\n                IntPtr ppReturnLics;\r\n\r\n                uint status = SLGetProductSkuInformation(sl.Handle, ref actId, \"pkeyConfigLicenseId\", out type, out len, out ppReturnLics);\r\n\r\n                if (status != 0 || len == 0)\r\n                {\r\n                    return Guid.Empty;\r\n                }\r\n\r\n                Guid pkcId = new Guid(Marshal.PtrToStringAuto(ppReturnLics));\r\n                return GetLicenseFileId(pkcId);\r\n            }\r\n        }\r\n\r\n        public static string GetLicenseContents(Guid fileId)\r\n        {\r\n            if (fileId == Guid.Empty) throw new ArgumentException(\"License contents could not be retrieved.\");\r\n\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint dataLen;\r\n                IntPtr dataPtr;\r\n\r\n                if (SLGetLicense(sl.Handle, ref fileId, out dataLen, out dataPtr) != 0)\r\n                {\r\n                    return null;\r\n                }\r\n\r\n                byte[] data = new byte[dataLen];\r\n                Marshal.Copy(dataPtr, data, 0, (int)dataLen);\r\n\r\n                data = data.Skip(Array.IndexOf(data, (byte)'<')).ToArray();\r\n                return Encoding.UTF8.GetString(data);\r\n            }\r\n        }\r\n\r\n        public static bool IsPhoneActivatable(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                SLDATATYPE type;\r\n                IntPtr ppbValue;\r\n\r\n                uint status = SLGetProductSkuInformation(sl.Handle, ref actId, \"msft:sl/EUL/PHONE/PUBLIC\", out type, out count, out ppbValue);\r\n                return status != 0xC004F012;\r\n            }\r\n        }\r\n\r\n        public static string GetPKeyChannel(Guid pkeyId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                SLDATATYPE type;\r\n                uint len;\r\n                IntPtr ppbValue;\r\n\r\n                uint status = SLGetPKeyInformation(sl.Handle, ref pkeyId, \"Channel\", out type, out len, out ppbValue);\r\n\r\n                if (status != 0 || len == 0)\r\n                {\r\n                    return null;\r\n                }\r\n\r\n                return Marshal.PtrToStringAuto(ppbValue);\r\n            }\r\n        }\r\n\r\n        public static string GetMetaStr(Guid actId, string value)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint len;\r\n                SLDATATYPE type;\r\n                IntPtr ppbValue;\r\n\r\n                uint status = SLGetProductSkuInformation(sl.Handle, ref actId, value, out type, out len, out ppbValue);\r\n\r\n                if (status != 0 || len == 0 || type != SLDATATYPE.SL_DATA_SZ)\r\n                {\r\n                    return null;\r\n                }\r\n\r\n                return Marshal.PtrToStringAuto(ppbValue);\r\n            }\r\n        }\r\n\r\n        public static List<Guid> GetActivationIds(Guid appId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                IntPtr pLicStat;\r\n\r\n                SLGetLicensingStatusInformation(sl.Handle, ref appId, IntPtr.Zero, null, out count, out pLicStat);\r\n\r\n                List<Guid> result = new List<Guid>();\r\n\r\n                unsafe\r\n                {\r\n                    SL_LICENSING_STATUS* licensingStatuses = (SL_LICENSING_STATUS*)pLicStat;\r\n                    for (int i = 0; i < count; i++)\r\n                    {\r\n                        result.Add(licensingStatuses[i].SkuId);\r\n                    }\r\n                }\r\n\r\n                return result;\r\n            }\r\n        }\r\n\r\n        public static uint SetCurrentProductKey(Guid actId, Guid pkeyId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                return SLSetCurrentProductKey(sl.Handle, ref actId, ref pkeyId);\r\n            }\r\n        }\r\n\r\n        public static uint InstallProductKey(ProductKey pkey)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                Guid pkeyId = Guid.Empty;\r\n                return SLInstallProofOfPurchase(sl.Handle, pkey.GetAlgoUri(), pkey.ToString(), 0, null, ref pkeyId);\r\n            }\r\n        }\r\n\r\n        public static void UninstallProductKey(Guid pkeyId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                SLUninstallProofOfPurchase(sl.Handle, ref pkeyId);\r\n            }\r\n        }\r\n\r\n        public static void UninstallAllProductKeys(Guid appId)\r\n        {\r\n            foreach (Guid actId in GetActivationIds(appId))\r\n            {\r\n                Guid pkeyId = GetInstalledPkeyID(actId);\r\n                if (pkeyId == Guid.Empty) continue;\r\n                if (IsAddon(actId)) continue;\r\n                UninstallProductKey(pkeyId);\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/SPP/SPPUtils.cs\r\nnamespace LibTSforge.SPP\r\n{\r\n    using Microsoft.Win32;\r\n    using System;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using System.ServiceProcess;\r\n    using Crypto;\r\n    using PhysicalStore;\r\n    using TokenStore;\r\n\r\n    public static class SPPUtils\r\n    {\r\n        public static void KillSPP(PSVersion version)\r\n        {\r\n            ServiceController sc;\r\n\r\n            string svcName = version == PSVersion.Vista ? \"slsvc\" : \"sppsvc\";\r\n\r\n            try\r\n            {\r\n                sc = new ServiceController(svcName);\r\n\r\n                if (sc.Status == ServiceControllerStatus.Stopped)\r\n                    return;\r\n            }\r\n            catch (InvalidOperationException ex)\r\n            {\r\n                throw new InvalidOperationException(string.Format(\"Unable to access {0}: \", svcName) + ex.Message);\r\n            }\r\n\r\n            Logger.WriteLine(string.Format(\"Stopping {0}...\", svcName));\r\n\r\n            bool stopped = false;\r\n\r\n            for (int i = 0; stopped == false && i < 1080; i++)\r\n            {\r\n                try\r\n                {\r\n                    if (sc.Status != ServiceControllerStatus.StopPending)\r\n                        sc.Stop();\r\n\r\n                    sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(500));\r\n                }\r\n                catch (System.ServiceProcess.TimeoutException)\r\n                {\r\n                    continue;\r\n                }\r\n                catch (InvalidOperationException ex)\r\n                {\r\n                    Logger.WriteLine(\"Warning: Stopping sppsvc failed, retrying. Details: \" + ex.Message);\r\n                    System.Threading.Thread.Sleep(500);\r\n                    continue;\r\n                }\r\n\r\n                stopped = true;\r\n            }\r\n\r\n            if (!stopped)\r\n                throw new System.TimeoutException(string.Format(\"Failed to stop {0}\", svcName));\r\n\r\n            Logger.WriteLine(string.Format(\"{0} stopped successfully.\", svcName));\r\n\r\n            if (version == PSVersion.Vista && SPSys.IsSpSysRunning())\r\n            {\r\n                Logger.WriteLine(\"Unloading spsys...\");\r\n\r\n                int status = SPSys.ControlSpSys(false);\r\n\r\n                if (status < 0)\r\n                {\r\n                    throw new IOException(\"Failed to unload spsys\");\r\n                }\r\n\r\n                Logger.WriteLine(\"spsys unloaded successfully.\");\r\n            }\r\n        }\r\n\r\n        public static void RestartSPP(PSVersion version)\r\n        {\r\n            if (version == PSVersion.Vista)\r\n            {\r\n                ServiceController sc;\r\n\r\n                try\r\n                {\r\n                    sc = new ServiceController(\"slsvc\");\r\n\r\n                    if (sc.Status == ServiceControllerStatus.Running)\r\n                        return;\r\n                }\r\n                catch (InvalidOperationException ex)\r\n                {\r\n                    throw new InvalidOperationException(\"Unable to access slsvc: \" + ex.Message);\r\n                }\r\n\r\n                Logger.WriteLine(\"Starting slsvc...\");\r\n\r\n                bool started = false;\r\n\r\n                for (int i = 0; started == false && i < 360; i++)\r\n                {\r\n                    try\r\n                    {\r\n                        if (sc.Status != ServiceControllerStatus.StartPending)\r\n                            sc.Start();\r\n\r\n                        sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMilliseconds(500));\r\n                    }\r\n                    catch (System.ServiceProcess.TimeoutException)\r\n                    {\r\n                        continue;\r\n                    }\r\n                    catch (InvalidOperationException ex)\r\n                    {\r\n                        Logger.WriteLine(\"Warning: Starting slsvc failed, retrying. Details: \" + ex.Message);\r\n                        System.Threading.Thread.Sleep(500);\r\n                        continue;\r\n                    }\r\n\r\n                    started = true;\r\n                }\r\n\r\n                if (!started)\r\n                    throw new System.TimeoutException(\"Failed to start slsvc\");\r\n\r\n                Logger.WriteLine(\"slsvc started successfully.\");\r\n            }\r\n\r\n            SLApi.RefreshLicenseStatus();\r\n        }\r\n\r\n        public static bool DetectCurrentKey()\r\n        {\r\n            SLApi.RefreshLicenseStatus();\r\n\r\n            using (RegistryKey wpaKey = Registry.LocalMachine.OpenSubKey(@\"SYSTEM\\WPA\"))\r\n            {\r\n                foreach (string subKey in wpaKey.GetSubKeyNames())\r\n                {\r\n                    if (subKey.StartsWith(\"8DEC0AF1\"))\r\n                    {\r\n                        return subKey.Contains(\"P\");\r\n                    }\r\n                }\r\n            }\r\n\r\n            throw new FileNotFoundException(\"Failed to autodetect key type, specify physical store key with /prod or /test arguments.\");\r\n        }\r\n\r\n        public static string GetPSPath(PSVersion version)\r\n        {\r\n            switch (version)\r\n            {\r\n                case PSVersion.Vista:\r\n                case PSVersion.Win7:\r\n                    return Directory.GetFiles(\r\n                        Environment.GetFolderPath(Environment.SpecialFolder.System),\r\n                        \"7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0\")\r\n                    .FirstOrDefault() ?? \"\";\r\n                default:\r\n                    string psDir = Environment.ExpandEnvironmentVariables(\r\n                        (string)Registry.GetValue(\r\n                            @\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\",\r\n                            \"TokenStore\",\r\n                            \"\"\r\n                        )\r\n                    );\r\n                    string psPath = Path.Combine(psDir, \"data.dat\");\r\n\r\n                    if (string.IsNullOrEmpty(psDir) || !File.Exists(psPath))\r\n                    {\r\n                        string[] psDirs =\r\n                        {\r\n                            @\"spp\\store\",\r\n                            @\"spp\\store\\2.0\",\r\n                            @\"spp\\store_test\",\r\n                            @\"spp\\store_test\\2.0\"\r\n                        };\r\n\r\n                        foreach (string dir in psDirs)\r\n                        {\r\n                            psPath = Path.Combine(\r\n                                Path.Combine(\r\n                                    Environment.GetFolderPath(Environment.SpecialFolder.System),\r\n                                    dir\r\n                                ),\r\n                                \"data.dat\"\r\n                            );\r\n\r\n                            if (File.Exists(psPath)) return psPath;\r\n                        }\r\n                    } \r\n                    else\r\n                    {\r\n                        return psPath;\r\n                    }\r\n\r\n                    throw new FileNotFoundException(\"Failed to locate physical store.\");\r\n            }\r\n        }\r\n\r\n        public static string GetTokensPath(PSVersion version)\r\n        {\r\n            switch (version)\r\n            {\r\n                case PSVersion.Vista:\r\n                    return Path.Combine(\r\n                        Environment.ExpandEnvironmentVariables(\"%WINDIR%\"),\r\n                        @\"ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareLicensing\\tokens.dat\"\r\n                    );\r\n                case PSVersion.Win7:\r\n                    return Path.Combine(\r\n                        Environment.ExpandEnvironmentVariables(\"%WINDIR%\"),\r\n                        @\"ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareProtectionPlatform\\tokens.dat\"\r\n                    );\r\n                default:\r\n                    string tokDir = Environment.ExpandEnvironmentVariables(\r\n                        (string)Registry.GetValue(\r\n                            @\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\",\r\n                            \"TokenStore\",\r\n                            \"\"\r\n                        )\r\n                    );\r\n                    string tokPath = Path.Combine(tokDir, \"tokens.dat\");\r\n\r\n                    if (string.IsNullOrEmpty(tokDir) || !File.Exists(tokPath))\r\n                    {\r\n                        string[] tokDirs =\r\n                        {\r\n                            @\"spp\\store\",\r\n                            @\"spp\\store\\2.0\",\r\n                            @\"spp\\store_test\",\r\n                            @\"spp\\store_test\\2.0\"\r\n                        };\r\n\r\n                        foreach (string dir in tokDirs)\r\n                        {\r\n                            tokPath = Path.Combine(\r\n                                Path.Combine(\r\n                                    Environment.GetFolderPath(Environment.SpecialFolder.System),\r\n                                    dir\r\n                                ),\r\n                                \"tokens.dat\"\r\n                            );\r\n\r\n                            if (File.Exists(tokPath)) return tokPath;\r\n                        }\r\n                    }\r\n                    else\r\n                    {\r\n                        return tokPath;\r\n                    }\r\n\r\n                    throw new FileNotFoundException(\"Failed to locate token store.\");\r\n            }\r\n        }\r\n\r\n        public static IPhysicalStore GetStore(PSVersion version, bool production)\r\n        {\r\n            string psPath = GetPSPath(version);\r\n\r\n            switch (version)\r\n            {\r\n                case PSVersion.Vista:\r\n                    return new PhysicalStoreVista(psPath, production);\r\n                case PSVersion.Win7:\r\n                    return new PhysicalStoreWin7(psPath, production);\r\n                default:\r\n                    return new PhysicalStoreModern(psPath, production, version);\r\n            }\r\n        }\r\n\r\n        public static ITokenStore GetTokenStore(PSVersion version)\r\n        {\r\n            string tokPath = GetTokensPath(version);\r\n\r\n            return new TokenStoreModern(tokPath);\r\n        }\r\n\r\n        public static void DumpStore(PSVersion version, bool production, string filePath, string encrFilePath)\r\n        {\r\n            bool manageSpp = false;\r\n\r\n            if (encrFilePath == null)\r\n            {\r\n                encrFilePath = GetPSPath(version);\r\n                manageSpp = true;\r\n                KillSPP(version);\r\n            }\r\n\r\n            if (string.IsNullOrEmpty(encrFilePath) || !File.Exists(encrFilePath))\r\n            {\r\n                throw new FileNotFoundException(\"Store does not exist at expected path '\" + encrFilePath + \"'.\");\r\n            }\r\n\r\n            try\r\n            {\r\n                using (FileStream fs = File.Open(encrFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))\r\n                {\r\n                    byte[] encrData = fs.ReadAllBytes();\r\n                    File.WriteAllBytes(filePath, PhysStoreCrypto.DecryptPhysicalStore(encrData, production, version));\r\n                }\r\n                Logger.WriteLine(\"Store dumped successfully to '\" + filePath + \"'.\");\r\n            }\r\n            finally\r\n            {\r\n                if (manageSpp)\r\n                {\r\n                    RestartSPP(version);\r\n                }\r\n            }\r\n        }\r\n\r\n        public static void LoadStore(PSVersion version, bool production, string filePath)\r\n        {\r\n            if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))\r\n            {\r\n                throw new FileNotFoundException(\"Store file '\" + filePath + \"' does not exist.\");\r\n            }\r\n\r\n            KillSPP(version);\r\n\r\n            using (IPhysicalStore store = GetStore(version, production))\r\n            {\r\n                store.WriteRaw(File.ReadAllBytes(filePath));\r\n            }\r\n\r\n            RestartSPP(version);\r\n\r\n            Logger.WriteLine(\"Loaded store file successfully.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/SPP/SPSys.cs\r\nnamespace LibTSforge.SPP\r\n{\r\n    using Microsoft.Win32.SafeHandles;\r\n    using System;\r\n    using System.Runtime.InteropServices;\r\n\r\n    public class SPSys\r\n    {\r\n        [DllImport(\"kernel32.dll\", CharSet = CharSet.Auto, SetLastError = true)]\r\n        private static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);\r\n        private static SafeFileHandle CreateFileSafe(string device)\r\n        {\r\n            return new SafeFileHandle(CreateFile(device, 0xC0000000, 0, IntPtr.Zero, 3, 0, IntPtr.Zero), true);\r\n        }\r\n\r\n        [return: MarshalAs(UnmanagedType.Bool)]\r\n        [DllImport(\"kernel32.dll\", CharSet = CharSet.Auto, SetLastError = true)]\r\n        private static extern bool DeviceIoControl([In] SafeFileHandle hDevice, [In] uint dwIoControlCode, [In] IntPtr lpInBuffer, [In] int nInBufferSize, [Out] IntPtr lpOutBuffer, [In] int nOutBufferSize, out int lpBytesReturned, [In] IntPtr lpOverlapped);\r\n\r\n        public static bool IsSpSysRunning()\r\n        {\r\n            SafeFileHandle file = CreateFileSafe(@\"\\\\.\\SpDevice\");\r\n            IntPtr buffer = Marshal.AllocHGlobal(1);\r\n            int bytesReturned;\r\n            DeviceIoControl(file, 0x80006008, IntPtr.Zero, 0, buffer, 1, out bytesReturned, IntPtr.Zero);\r\n            bool running = Marshal.ReadByte(buffer) != 0;\r\n            Marshal.FreeHGlobal(buffer);\r\n            file.Close();\r\n            return running;\r\n        }\r\n\r\n        public static int ControlSpSys(bool start)\r\n        {\r\n            SafeFileHandle file = CreateFileSafe(@\"\\\\.\\SpDevice\");\r\n            IntPtr buffer = Marshal.AllocHGlobal(4);\r\n            int bytesReturned;\r\n            DeviceIoControl(file, start ? 0x8000a000 : 0x8000a004, IntPtr.Zero, 0, buffer, 4, out bytesReturned, IntPtr.Zero);\r\n            int result = Marshal.ReadInt32(buffer);\r\n            Marshal.FreeHGlobal(buffer);\r\n            file.Close();\r\n            return result;\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Crypto/CryptoUtils.cs\r\nnamespace LibTSforge.Crypto\r\n{\r\n    using System;\r\n    using System.Linq;\r\n    using System.Security.Cryptography;\r\n\r\n    public static class CryptoUtils\r\n    {\r\n        public static byte[] GenerateRandomKey(int len)\r\n        {\r\n            byte[] rand = new byte[len];\r\n            Random r = new Random();\r\n            r.NextBytes(rand);\r\n\r\n            return rand;\r\n        }\r\n\r\n        public static byte[] AESEncrypt(byte[] data, byte[] key)\r\n        {\r\n            using (Aes aes = Aes.Create())\r\n            {\r\n                aes.Key = key;\r\n                aes.Mode = CipherMode.CBC;\r\n                aes.Padding = PaddingMode.PKCS7;\r\n\r\n                ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, Enumerable.Repeat((byte)0, 16).ToArray());\r\n                byte[] encryptedData = encryptor.TransformFinalBlock(data, 0, data.Length);\r\n                return encryptedData;\r\n            }\r\n        }\r\n\r\n        public static byte[] AESDecrypt(byte[] data, byte[] key)\r\n        {\r\n            using (Aes aes = Aes.Create())\r\n            {\r\n                aes.Key = key;\r\n                aes.Mode = CipherMode.CBC;\r\n                aes.Padding = PaddingMode.PKCS7;\r\n\r\n                ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, Enumerable.Repeat((byte)0, 16).ToArray());\r\n                byte[] decryptedData = decryptor.TransformFinalBlock(data, 0, data.Length);\r\n                return decryptedData;\r\n            }\r\n        }\r\n\r\n        public static byte[] RSADecrypt(byte[] rsaKey, byte[] data)\r\n        {\r\n\r\n            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())\r\n            {\r\n                rsa.ImportCspBlob(rsaKey);\r\n                return rsa.Decrypt(data, false);\r\n            }\r\n        }\r\n\r\n        public static byte[] RSAEncrypt(byte[] rsaKey, byte[] data)\r\n        {\r\n            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())\r\n            {\r\n                rsa.ImportCspBlob(rsaKey);\r\n                return rsa.Encrypt(data, false);\r\n            }\r\n        }\r\n\r\n        public static byte[] RSASign(byte[] rsaKey, byte[] data)\r\n        {\r\n            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())\r\n            {\r\n                rsa.ImportCspBlob(rsaKey);\r\n                RSAPKCS1SignatureFormatter formatter = new RSAPKCS1SignatureFormatter(rsa);\r\n                formatter.SetHashAlgorithm(\"SHA1\");\r\n\r\n                byte[] hash;\r\n                using (SHA1 sha1 = SHA1.Create())\r\n                {\r\n                    hash = sha1.ComputeHash(data);\r\n                }\r\n\r\n                return formatter.CreateSignature(hash);\r\n            }\r\n        }\r\n\r\n        public static bool RSAVerifySignature(byte[] rsaKey, byte[] data, byte[] signature)\r\n        {\r\n            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())\r\n            {\r\n                rsa.ImportCspBlob(rsaKey);\r\n                RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(rsa);\r\n                deformatter.SetHashAlgorithm(\"SHA1\");\r\n\r\n                byte[] hash;\r\n                using (SHA1 sha1 = SHA1.Create())\r\n                {\r\n                    hash = sha1.ComputeHash(data);\r\n                }\r\n\r\n                return deformatter.VerifySignature(hash, signature);\r\n            }\r\n        }\r\n\r\n        public static byte[] HMACSign(byte[] key, byte[] data)\r\n        {\r\n            HMACSHA1 hmac = new HMACSHA1(key);\r\n            return hmac.ComputeHash(data);\r\n        }\r\n\r\n        public static bool HMACVerify(byte[] key, byte[] data, byte[] signature)\r\n        {\r\n            return Enumerable.SequenceEqual(signature, HMACSign(key, data));\r\n        }\r\n\r\n        public static byte[] SaltSHASum(byte[] salt, byte[] data)\r\n        {\r\n            SHA1 sha1 = SHA1.Create();\r\n            byte[] sha_data = salt.Concat(data).ToArray();\r\n            return sha1.ComputeHash(sha_data);\r\n        }\r\n\r\n        public static bool SaltSHAVerify(byte[] salt, byte[] data, byte[] checksum)\r\n        {\r\n            return Enumerable.SequenceEqual(checksum, SaltSHASum(salt, data));\r\n        }\r\n\r\n        public static byte[] SHA256Hash(byte[] data)\r\n        {\r\n            using (SHA256 sha256 = SHA256.Create())\r\n            {\r\n                return sha256.ComputeHash(data);\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Crypto/Keys.cs\r\nnamespace LibTSforge.Crypto\r\n{\r\n    public static class Keys\r\n    {\r\n        public static readonly byte[] PRODUCTION = {\r\n            0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00,\r\n            0x01, 0x00, 0x01, 0x00, 0x29, 0x87, 0xBA, 0x3F, 0x52, 0x90, 0x57, 0xD8, 0x12, 0x26, 0x6B, 0x38,\r\n            0xB2, 0x3B, 0xF9, 0x67, 0x08, 0x4F, 0xDD, 0x8B, 0xF5, 0xE3, 0x11, 0xB8, 0x61, 0x3A, 0x33, 0x42,\r\n            0x51, 0x65, 0x05, 0x86, 0x1E, 0x00, 0x41, 0xDE, 0xC5, 0xDD, 0x44, 0x60, 0x56, 0x3D, 0x14, 0x39,\r\n            0xB7, 0x43, 0x65, 0xE9, 0xF7, 0x2B, 0xA5, 0xF0, 0xA3, 0x65, 0x68, 0xE9, 0xE4, 0x8B, 0x5C, 0x03,\r\n            0x2D, 0x36, 0xFE, 0x28, 0x4C, 0xD1, 0x3C, 0x3D, 0xC1, 0x90, 0x75, 0xF9, 0x6E, 0x02, 0xE0, 0x58,\r\n            0x97, 0x6A, 0xCA, 0x80, 0x02, 0x42, 0x3F, 0x6C, 0x15, 0x85, 0x4D, 0x83, 0x23, 0x6A, 0x95, 0x9E,\r\n            0x38, 0x52, 0x59, 0x38, 0x6A, 0x99, 0xF0, 0xB5, 0xCD, 0x53, 0x7E, 0x08, 0x7C, 0xB5, 0x51, 0xD3,\r\n            0x8F, 0xA3, 0x0D, 0xA0, 0xFA, 0x8D, 0x87, 0x3C, 0xFC, 0x59, 0x21, 0xD8, 0x2E, 0xD9, 0x97, 0x8B,\r\n            0x40, 0x60, 0xB1, 0xD7, 0x2B, 0x0A, 0x6E, 0x60, 0xB5, 0x50, 0xCC, 0x3C, 0xB1, 0x57, 0xE4, 0xB7,\r\n            0xDC, 0x5A, 0x4D, 0xE1, 0x5C, 0xE0, 0x94, 0x4C, 0x5E, 0x28, 0xFF, 0xFA, 0x80, 0x6A, 0x13, 0x53,\r\n            0x52, 0xDB, 0xF3, 0x04, 0x92, 0x43, 0x38, 0xB9, 0x1B, 0xD9, 0x85, 0x54, 0x7B, 0x14, 0xC7, 0x89,\r\n            0x16, 0x8A, 0x4B, 0x82, 0xA1, 0x08, 0x02, 0x99, 0x23, 0x48, 0xDD, 0x75, 0x9C, 0xC8, 0xC1, 0xCE,\r\n            0xB0, 0xD7, 0x1B, 0xD8, 0xFB, 0x2D, 0xA7, 0x2E, 0x47, 0xA7, 0x18, 0x4B, 0xF6, 0x29, 0x69, 0x44,\r\n            0x30, 0x33, 0xBA, 0xA7, 0x1F, 0xCE, 0x96, 0x9E, 0x40, 0xE1, 0x43, 0xF0, 0xE0, 0x0D, 0x0A, 0x32,\r\n            0xB4, 0xEE, 0xA1, 0xC3, 0x5E, 0x9B, 0xC7, 0x7F, 0xF5, 0x9D, 0xD8, 0xF2, 0x0F, 0xD9, 0x8F, 0xAD,\r\n            0x75, 0x0A, 0x00, 0xD5, 0x25, 0x43, 0xF7, 0xAE, 0x51, 0x7F, 0xB7, 0xDE, 0xB7, 0xAD, 0xFB, 0xCE,\r\n            0x83, 0xE1, 0x81, 0xFF, 0xDD, 0xA2, 0x77, 0xFE, 0xEB, 0x27, 0x1F, 0x10, 0xFA, 0x82, 0x37, 0xF4,\r\n            0x7E, 0xCC, 0xE2, 0xA1, 0x58, 0xC8, 0xAF, 0x1D, 0x1A, 0x81, 0x31, 0x6E, 0xF4, 0x8B, 0x63, 0x34,\r\n            0xF3, 0x05, 0x0F, 0xE1, 0xCC, 0x15, 0xDC, 0xA4, 0x28, 0x7A, 0x9E, 0xEB, 0x62, 0xD8, 0xD8, 0x8C,\r\n            0x85, 0xD7, 0x07, 0x87, 0x90, 0x2F, 0xF7, 0x1C, 0x56, 0x85, 0x2F, 0xEF, 0x32, 0x37, 0x07, 0xAB,\r\n            0xB0, 0xE6, 0xB5, 0x02, 0x19, 0x35, 0xAF, 0xDB, 0xD4, 0xA2, 0x9C, 0x36, 0x80, 0xC6, 0xDC, 0x82,\r\n            0x08, 0xE0, 0xC0, 0x5F, 0x3C, 0x59, 0xAA, 0x4E, 0x26, 0x03, 0x29, 0xB3, 0x62, 0x58, 0x41, 0x59,\r\n            0x3A, 0x37, 0x43, 0x35, 0xE3, 0x9F, 0x34, 0xE2, 0xA1, 0x04, 0x97, 0x12, 0x9D, 0x8C, 0xAD, 0xF7,\r\n            0xFB, 0x8C, 0xA1, 0xA2, 0xE9, 0xE4, 0xEF, 0xD9, 0xC5, 0xE5, 0xDF, 0x0E, 0xBF, 0x4A, 0xE0, 0x7A,\r\n            0x1E, 0x10, 0x50, 0x58, 0x63, 0x51, 0xE1, 0xD4, 0xFE, 0x57, 0xB0, 0x9E, 0xD7, 0xDA, 0x8C, 0xED,\r\n            0x7D, 0x82, 0xAC, 0x2F, 0x25, 0x58, 0x0A, 0x58, 0xE6, 0xA4, 0xF4, 0x57, 0x4B, 0xA4, 0x1B, 0x65,\r\n            0xB9, 0x4A, 0x87, 0x46, 0xEB, 0x8C, 0x0F, 0x9A, 0x48, 0x90, 0xF9, 0x9F, 0x76, 0x69, 0x03, 0x72,\r\n            0x77, 0xEC, 0xC1, 0x42, 0x4C, 0x87, 0xDB, 0x0B, 0x3C, 0xD4, 0x74, 0xEF, 0xE5, 0x34, 0xE0, 0x32,\r\n            0x45, 0xB0, 0xF8, 0xAB, 0xD5, 0x26, 0x21, 0xD7, 0xD2, 0x98, 0x54, 0x8F, 0x64, 0x88, 0x20, 0x2B,\r\n            0x14, 0xE3, 0x82, 0xD5, 0x2A, 0x4B, 0x8F, 0x4E, 0x35, 0x20, 0x82, 0x7E, 0x1B, 0xFE, 0xFA, 0x2C,\r\n            0x79, 0x6C, 0x6E, 0x66, 0x94, 0xBB, 0x0A, 0xEB, 0xBA, 0xD9, 0x70, 0x61, 0xE9, 0x47, 0xB5, 0x82,\r\n            0xFC, 0x18, 0x3C, 0x66, 0x3A, 0x09, 0x2E, 0x1F, 0x61, 0x74, 0xCA, 0xCB, 0xF6, 0x7A, 0x52, 0x37,\r\n            0x1D, 0xAC, 0x8D, 0x63, 0x69, 0x84, 0x8E, 0xC7, 0x70, 0x59, 0xDD, 0x2D, 0x91, 0x1E, 0xF7, 0xB1,\r\n            0x56, 0xED, 0x7A, 0x06, 0x9D, 0x5B, 0x33, 0x15, 0xDD, 0x31, 0xD0, 0xE6, 0x16, 0x07, 0x9B, 0xA5,\r\n            0x94, 0x06, 0x7D, 0xC1, 0xE9, 0xD6, 0xC8, 0xAF, 0xB4, 0x1E, 0x2D, 0x88, 0x06, 0xA7, 0x63, 0xB8,\r\n            0xCF, 0xC8, 0xA2, 0x6E, 0x84, 0xB3, 0x8D, 0xE5, 0x47, 0xE6, 0x13, 0x63, 0x8E, 0xD1, 0x7F, 0xD4,\r\n            0x81, 0x44, 0x38, 0xBF\r\n        };\r\n\r\n        public static readonly byte[] TEST = {\r\n            0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00,\r\n            0x01, 0x00, 0x01, 0x00, 0x0F, 0xBE, 0x77, 0xB8, 0xDD, 0x54, 0x36, 0xDD, 0x67, 0xD4, 0x17, 0x66,\r\n            0xC4, 0x13, 0xD1, 0x3F, 0x1E, 0x16, 0x0C, 0x16, 0x35, 0xAB, 0x6D, 0x3D, 0x34, 0x51, 0xED, 0x3F,\r\n            0x57, 0x14, 0xB6, 0xB7, 0x08, 0xE9, 0xD9, 0x7A, 0x80, 0xB3, 0x5F, 0x9B, 0x3A, 0xFD, 0x9E, 0x37,\r\n            0x3A, 0x53, 0x72, 0x67, 0x92, 0x60, 0xC3, 0xEF, 0xB5, 0x8E, 0x1E, 0xCF, 0x9D, 0x9C, 0xD3, 0x90,\r\n            0xE5, 0xDD, 0xF4, 0xDB, 0xF3, 0xD6, 0x65, 0xB3, 0xC1, 0xBD, 0x69, 0xE1, 0x76, 0x95, 0xD9, 0x37,\r\n            0xB8, 0x5E, 0xCA, 0x3D, 0x98, 0xFC, 0x50, 0x5C, 0x98, 0xAE, 0xE3, 0x7C, 0x4C, 0x27, 0xC3, 0xD0,\r\n            0xCE, 0x78, 0x06, 0x51, 0x68, 0x23, 0xE6, 0x70, 0xF8, 0x7C, 0xAE, 0x36, 0xBE, 0x41, 0x57, 0xE2,\r\n            0xC3, 0x2D, 0xAF, 0x21, 0xB1, 0xB3, 0x15, 0x81, 0x19, 0x26, 0x6B, 0x10, 0xB3, 0xE9, 0xD1, 0x45,\r\n            0x21, 0x77, 0x9C, 0xF6, 0xE1, 0xDD, 0xB6, 0x78, 0x9D, 0x1D, 0x32, 0x61, 0xBC, 0x2B, 0xDB, 0x86,\r\n            0xFB, 0x07, 0x24, 0x10, 0x19, 0x4F, 0x09, 0x6D, 0x03, 0x90, 0xD4, 0x5E, 0x30, 0x85, 0xC5, 0x58,\r\n            0x7E, 0x5D, 0xAE, 0x9F, 0x64, 0x93, 0x04, 0x82, 0x09, 0x0E, 0x1C, 0x66, 0xA8, 0x95, 0x91, 0x51,\r\n            0xB2, 0xED, 0x9A, 0x75, 0x04, 0x87, 0x50, 0xAC, 0xCC, 0x20, 0x06, 0x45, 0xB9, 0x7B, 0x42, 0x53,\r\n            0x9A, 0xD1, 0x29, 0xFC, 0xEF, 0xB9, 0x47, 0x16, 0x75, 0x69, 0x05, 0x87, 0x2B, 0xCB, 0x54, 0x9C,\r\n            0x21, 0x2D, 0x50, 0x8E, 0x12, 0xDE, 0xD3, 0x6B, 0xEC, 0x92, 0xA1, 0xB1, 0xE9, 0x4B, 0xBF, 0x6B,\r\n            0x9A, 0x38, 0xC7, 0x13, 0xFA, 0x78, 0xA1, 0x3C, 0x1E, 0xBB, 0x38, 0x31, 0xBB, 0x0C, 0x9F, 0x70,\r\n            0x1A, 0x31, 0x00, 0xD7, 0x5A, 0xA5, 0x84, 0x24, 0x89, 0x80, 0xF5, 0x88, 0xC2, 0x31, 0x18, 0xDC,\r\n            0x53, 0x05, 0x5D, 0xFA, 0x81, 0xDC, 0xE1, 0xCE, 0xA4, 0xAA, 0xBA, 0x07, 0xDA, 0x28, 0x4F, 0x64,\r\n            0x0E, 0x84, 0x9B, 0x06, 0xDE, 0xC8, 0x78, 0x66, 0x2F, 0x17, 0x25, 0xA8, 0x9C, 0x99, 0xFC, 0xBC,\r\n            0x7D, 0x01, 0x42, 0xD7, 0x35, 0xBF, 0x19, 0xF6, 0x3F, 0x20, 0xD9, 0x98, 0x9B, 0x5D, 0xDD, 0x39,\r\n            0xBE, 0x81, 0x00, 0x0B, 0xDE, 0x6F, 0x14, 0xCA, 0x7E, 0xF8, 0xC0, 0x26, 0xA8, 0x1D, 0xD1, 0x16,\r\n            0x88, 0x64, 0x87, 0x36, 0x45, 0x37, 0x50, 0xDA, 0x6C, 0xEB, 0x85, 0xB5, 0x43, 0x29, 0x88, 0x6F,\r\n            0x2F, 0xFE, 0x8D, 0x12, 0x8B, 0x72, 0xB7, 0x5A, 0xCB, 0x66, 0xC2, 0x2E, 0x1D, 0x7D, 0x42, 0xA6,\r\n            0xF4, 0xFE, 0x26, 0x5D, 0x54, 0x9E, 0x77, 0x1D, 0x97, 0xC2, 0xF3, 0xFD, 0x60, 0xB3, 0x22, 0x88,\r\n            0xCA, 0x27, 0x99, 0xDF, 0xC8, 0xB1, 0xD7, 0xC6, 0x54, 0xA6, 0x50, 0xB9, 0x54, 0xF5, 0xDE, 0xFE,\r\n            0xE1, 0x81, 0xA2, 0xBE, 0x81, 0x9F, 0x48, 0xFF, 0x2F, 0xB8, 0xA4, 0xB3, 0x17, 0xD8, 0xC1, 0xB9,\r\n            0x5D, 0x21, 0x3D, 0xA2, 0xED, 0x1C, 0x96, 0x66, 0xEE, 0x1F, 0x47, 0xCF, 0x62, 0xFA, 0xD6, 0xC1,\r\n            0x87, 0x5B, 0xC4, 0xE5, 0xD9, 0x08, 0x38, 0x22, 0xFA, 0x21, 0xBD, 0xF2, 0x88, 0xDA, 0xE2, 0x24,\r\n            0x25, 0x1F, 0xF1, 0x0B, 0x2D, 0xAE, 0x04, 0xBE, 0xA6, 0x7F, 0x75, 0x8C, 0xD9, 0x97, 0xE1, 0xCA,\r\n            0x35, 0xB9, 0xFC, 0x6F, 0x01, 0x68, 0x11, 0xD3, 0x68, 0x32, 0xD0, 0xC1, 0x69, 0xA3, 0xCF, 0x9B,\r\n            0x10, 0xE4, 0x69, 0xA7, 0xCF, 0xE1, 0xFE, 0x2A, 0x07, 0x9E, 0xC1, 0x37, 0x84, 0x68, 0xE5, 0xC5,\r\n            0xAB, 0x25, 0xEC, 0x7D, 0x7D, 0x74, 0x6A, 0xD1, 0xD5, 0x4D, 0xD7, 0xE1, 0x7D, 0xDE, 0x30, 0x4B,\r\n            0xE6, 0x5D, 0xCD, 0x91, 0x59, 0xF6, 0x80, 0xFD, 0xC6, 0x3C, 0xDD, 0x94, 0x7F, 0x15, 0x9D, 0xEF,\r\n            0x2F, 0x00, 0x62, 0xD7, 0xDA, 0xB9, 0xB3, 0xD9, 0x8D, 0xE8, 0xD7, 0x3C, 0x96, 0x45, 0x5D, 0x1E,\r\n            0x50, 0xFB, 0xAA, 0x43, 0xD3, 0x47, 0x77, 0x81, 0xE9, 0x67, 0xE4, 0xFE, 0xDF, 0x42, 0x79, 0xCB,\r\n            0xA7, 0xAD, 0x5D, 0x48, 0xF5, 0xB7, 0x74, 0x96, 0x12, 0x23, 0x06, 0x70, 0x42, 0x68, 0x7A, 0x44,\r\n            0xFC, 0xA0, 0x31, 0x7F, 0x68, 0xCA, 0xA2, 0x14, 0x5D, 0xA3, 0xCF, 0x42, 0x23, 0xAB, 0x47, 0xF6,\r\n            0xB2, 0xFC, 0x6D, 0xF1\r\n        };\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Crypto/PhysStoreCrypto.cs\r\nnamespace LibTSforge.Crypto\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using System.Text;\r\n\r\n    public static class PhysStoreCrypto\r\n    {\r\n        public static byte[] DecryptPhysicalStore(byte[] data, bool production, PSVersion version)\r\n        {\r\n            byte[] rsaKey = production ? Keys.PRODUCTION : Keys.TEST;\r\n            BinaryReader br = new BinaryReader(new MemoryStream(data));\r\n            br.BaseStream.Seek(0x10, SeekOrigin.Begin);\r\n            byte[] aesKeySig = br.ReadBytes(0x80);\r\n            byte[] encAesKey = br.ReadBytes(0x80);\r\n\r\n            if (!CryptoUtils.RSAVerifySignature(rsaKey, encAesKey, aesKeySig))\r\n            {\r\n                throw new Exception(\"Failed to decrypt physical store.\");\r\n            }\r\n\r\n            byte[] aesKey = CryptoUtils.RSADecrypt(rsaKey, encAesKey);\r\n            byte[] decData = CryptoUtils.AESDecrypt(br.ReadBytes((int)br.BaseStream.Length - 0x110), aesKey);\r\n            byte[] hmacKey = decData.Take(0x10).ToArray(); // SHA-1 salt on Vista\r\n            byte[] hmacSig = decData.Skip(0x10).Take(0x14).ToArray(); // SHA-1 hash on Vista\r\n            byte[] psData = decData.Skip(0x28).ToArray();\r\n\r\n            if (version != PSVersion.Vista)\r\n            {\r\n                if (!CryptoUtils.HMACVerify(hmacKey, psData, hmacSig))\r\n                {\r\n                    throw new InvalidDataException(\"Failed to verify HMAC. Physical store is corrupt.\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                if (!CryptoUtils.SaltSHAVerify(hmacKey, psData, hmacSig))\r\n                {\r\n                    throw new InvalidDataException(\"Failed to verify checksum. Physical store is corrupt.\");\r\n                }\r\n            }\r\n\r\n            return psData;\r\n        }\r\n\r\n        public static byte[] EncryptPhysicalStore(byte[] data, bool production, PSVersion version)\r\n        {\r\n            Dictionary<PSVersion, int> versionTable = new Dictionary<PSVersion, int>\r\n            {\r\n                {PSVersion.Vista, 2},\r\n                {PSVersion.Win7, 5},\r\n                {PSVersion.Win8, 1},\r\n                {PSVersion.WinBlue, 2},\r\n                {PSVersion.WinModern, 3}\r\n            };\r\n\r\n            byte[] rsaKey = production ? Keys.PRODUCTION : Keys.TEST;\r\n\r\n            byte[] aesKey = Encoding.UTF8.GetBytes(\"massgrave.dev :3\");\r\n            byte[] hmacKey = CryptoUtils.GenerateRandomKey(0x10);\r\n\r\n            byte[] encAesKey = CryptoUtils.RSAEncrypt(rsaKey, aesKey);\r\n            byte[] aesKeySig = CryptoUtils.RSASign(rsaKey, encAesKey);\r\n            byte[] hmacSig = version != PSVersion.Vista ? CryptoUtils.HMACSign(hmacKey, data) : CryptoUtils.SaltSHASum(hmacKey, data);\r\n\r\n            byte[] decData = { };\r\n            decData = decData.Concat(hmacKey).Concat(hmacSig).Concat(BitConverter.GetBytes(0)).Concat(data).ToArray();\r\n            byte[] encData = CryptoUtils.AESEncrypt(decData, aesKey);\r\n\r\n            BinaryWriter bw = new BinaryWriter(new MemoryStream());\r\n            bw.Write(versionTable[version]);\r\n            bw.Write(Encoding.UTF8.GetBytes(\"UNTRUSTSTORE\"));\r\n            bw.Write(aesKeySig);\r\n            bw.Write(encAesKey);\r\n            bw.Write(encData);\r\n\r\n            return bw.GetBytes();\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/GenPKeyInstall.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using Microsoft.Win32;\r\n    using PhysicalStore;\r\n    using SPP;\r\n    using TokenStore;\r\n\r\n    public static class GenPKeyInstall\r\n    {\r\n        private static void WritePkey2005RegistryValues(PSVersion version, ProductKey pkey)\r\n        {\r\n            Logger.WriteLine(\"Writing registry data for Windows product key...\");\r\n            Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\", \"ProductId\", pkey.GetPid2());\r\n            Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\", \"DigitalProductId\", pkey.GetPid3());\r\n            Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\", \"DigitalProductId4\", pkey.GetPid4());\r\n\r\n            if (Registry.GetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Registration\", \"ProductId\", null) != null)\r\n            {\r\n                Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Registration\", \"ProductId\", pkey.GetPid2());\r\n                Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Registration\", \"DigitalProductId\", pkey.GetPid3());\r\n                Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Registration\", \"DigitalProductId4\", pkey.GetPid4());\r\n            }\r\n\r\n            if (pkey.Channel == \"Volume:CSVLK\" && version != PSVersion.Win7)\r\n            {\r\n                Registry.SetValue(@\"HKEY_USERS\\S-1-5-20\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\", \"KmsHostConfig\", 1);\r\n            }\r\n        }\r\n\r\n        public static void InstallGenPKey(PSVersion version, bool production, Guid actId)\r\n        {\r\n            if (version == PSVersion.Vista) throw new NotSupportedException(\"This feature is not supported on Windows Vista/Server 2008.\");\r\n            if (actId == Guid.Empty) throw new ArgumentException(\"Activation ID must be specified for generated product key install.\");\r\n\r\n            PKeyConfig pkc = new PKeyConfig();\r\n            \r\n            try\r\n            {\r\n                pkc.LoadConfig(actId);\r\n            }\r\n            catch (ArgumentException)\r\n            {\r\n                pkc.LoadAllConfigs(SLApi.GetAppId(actId));\r\n            }\r\n\r\n            ProductConfig config;\r\n            pkc.Products.TryGetValue(actId, out config);\r\n\r\n            if (config == null) throw new ArgumentException(\"Activation ID \" + actId + \" not found in PKeyConfig.\");\r\n\r\n            ProductKey pkey = config.GetRandomKey();\r\n\r\n            Guid instPkeyId = SLApi.GetInstalledPkeyID(actId);\r\n            if (instPkeyId != Guid.Empty) SLApi.UninstallProductKey(instPkeyId);\r\n\r\n            if (pkey.Algorithm == PKeyAlgorithm.PKEY2009)\r\n            {\r\n                uint status = SLApi.InstallProductKey(pkey);\r\n                Logger.WriteLine(string.Format(\"Installing generated product key {0} status {1:X}\", pkey, status));\r\n\r\n                if ((int)status < 0)\r\n                {\r\n                    throw new ApplicationException(\"Failed to install generated product key.\");\r\n                }\r\n\r\n                Logger.WriteLine(\"Successfully deposited generated product key.\");\r\n                return;\r\n            }\r\n\r\n            Logger.WriteLine(\"Key range is PKEY2005, creating fake key data...\");\r\n\r\n            if (pkey.Channel == \"Volume:GVLK\" && version == PSVersion.Win7) throw new NotSupportedException(\"Fake GVLK generation is not supported on Windows 7.\");\r\n\r\n            VariableBag pkb = new VariableBag(version);\r\n            pkb.Blocks.AddRange(new[]\r\n            {\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyBindingProductKey\",\r\n                    ValueAsStr = pkey.ToString()\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyBindingMPC\",\r\n                    ValueAsStr = pkey.GetMPC()\r\n                },\r\n                new CRCBlockModern {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = \"SppPkeyBindingPid2\",\r\n                    ValueAsStr = pkey.GetPid2()\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = \"SppPkeyBindingPid3\",\r\n                    Value = pkey.GetPid3()\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = \"SppPkeyBindingPid4\",\r\n                    Value = pkey.GetPid4()\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyChannelId\",\r\n                    ValueAsStr = pkey.Channel\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyBindingEditionId\",\r\n                    ValueAsStr = pkey.Edition\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = (version == PSVersion.Win7) ? \"SppPkeyShortAuthenticator\" : \"SppPkeyPhoneActivationData\",\r\n                    Value = pkey.GetPhoneData(version)\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = \"SppPkeyBindingMiscData\",\r\n                    Value = new byte[] { }\r\n                }\r\n            });\r\n\r\n            Guid appId = SLApi.GetAppId(actId);\r\n            string pkeyId = pkey.GetPkeyId().ToString();\r\n            bool isAddon = SLApi.IsAddon(actId);\r\n            string currEdition = SLApi.GetMetaStr(actId, \"Family\");\r\n\r\n            if (appId == SLApi.WINDOWS_APP_ID && !isAddon)\r\n            {\r\n                SLApi.UninstallAllProductKeys(appId);\r\n            }\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            using (IPhysicalStore ps = SPPUtils.GetStore(version, production))\r\n            {\r\n                using (ITokenStore tks = SPPUtils.GetTokenStore(version))\r\n                {\r\n                    Logger.WriteLine(\"Writing to physical store and token store...\");\r\n\r\n                    string suffix = (version == PSVersion.Win8 || version == PSVersion.WinBlue || version == PSVersion.WinModern) ? \"_--\" : \"\";\r\n                    string metSuffix = suffix + \"_met\";\r\n\r\n                    if (appId == SLApi.WINDOWS_APP_ID && !isAddon)\r\n                    {\r\n                        string edTokName = \"msft:spp/token/windows/productkeyid/\" + currEdition;\r\n\r\n                        TokenMeta edToken = tks.GetMetaEntry(edTokName);\r\n                        edToken.Data[\"windowsComponentEditionPkeyId\"] = pkeyId;\r\n                        edToken.Data[\"windowsComponentEditionSkuId\"] = actId.ToString();\r\n                        tks.SetEntry(edTokName, \"xml\", edToken.Serialize());\r\n\r\n                        WritePkey2005RegistryValues(version, pkey);\r\n                    }\r\n\r\n                    string uriMapName = \"msft:spp/token/PKeyIdUriMapper\" + metSuffix;\r\n                    TokenMeta uriMap = tks.GetMetaEntry(uriMapName);\r\n                    uriMap.Data[pkeyId] = pkey.GetAlgoUri();\r\n                    tks.SetEntry(uriMapName, \"xml\", uriMap.Serialize());\r\n\r\n                    string skuMetaName = actId + metSuffix;\r\n                    TokenMeta skuMeta = tks.GetMetaEntry(skuMetaName);\r\n\r\n                    foreach (string k in skuMeta.Data.Keys)\r\n                    {\r\n                        if (k.StartsWith(\"pkeyId_\"))\r\n                        {\r\n                            skuMeta.Data.Remove(k);\r\n                            break;\r\n                        }\r\n                    }\r\n\r\n                    skuMeta.Data[\"pkeyId\"] = pkeyId;\r\n                    skuMeta.Data[\"pkeyIdList\"] = pkeyId;\r\n                    tks.SetEntry(skuMetaName, \"xml\", skuMeta.Serialize());\r\n\r\n                    string psKey = string.Format(\"SPPSVC\\\\{0}\\\\{1}\", appId, actId);\r\n                    ps.DeleteBlock(psKey, pkeyId);\r\n                    ps.AddBlock(new PSBlock\r\n                    {\r\n                        Type = BlockType.NAMED,\r\n                        Flags = (version == PSVersion.WinModern) ? (uint)0x402 : 0x2,\r\n                        KeyAsStr = psKey,\r\n                        ValueAsStr = pkeyId,\r\n                        Data = pkb.Serialize()\r\n                    });\r\n\r\n                    string cachePath = SPPUtils.GetTokensPath(version).Replace(\"tokens.dat\", @\"cache\\cache.dat\");\r\n                    if (File.Exists(cachePath)) File.Delete(cachePath);\r\n                }\r\n            }\r\n\r\n            SLApi.RefreshTrustedTime(actId);\r\n            Logger.WriteLine(\"Successfully deposited fake product key.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/GracePeriodReset.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System.Collections.Generic;\r\n    using System.Linq;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class GracePeriodReset\r\n    {\r\n        public static void Reset(PSVersion version, bool production)\r\n        {\r\n            SPPUtils.KillSPP(version);\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                string value = \"msft:sl/timer\";\r\n                List<PSBlock> blocks = store.FindBlocks(value).ToList();\r\n\r\n                foreach (PSBlock block in blocks)\r\n                {\r\n                    store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);\r\n                }\r\n            }\r\n\r\n            SPPUtils.RestartSPP(version);\r\n            Logger.WriteLine(\"Successfully reset all grace and evaluation period timers.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/KeyChangeLockDelete.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System.Collections.Generic;\r\n    using System.Linq;\r\n    using PhysicalStore;\r\n    using SPP;\r\n    using System;\r\n\r\n    public static class KeyChangeLockDelete\r\n    {\r\n        public static void Delete(PSVersion version, bool production)\r\n        {\r\n            if (version == PSVersion.Vista) throw new NotSupportedException(\"This feature is not supported on Windows Vista/Server 2008.\");\r\n\r\n            SPPUtils.KillSPP(version);\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                List<string> values = new List<string>\r\n                {\r\n                    \"msft:spp/timebased/AB\",\r\n                    \"msft:spp/timebased/CD\"\r\n                };\r\n                List<PSBlock> blocks = new List<PSBlock>();\r\n                foreach (string value in values)\r\n                {\r\n                    blocks.AddRange(store.FindBlocks(value).ToList());\r\n                }\r\n                foreach (PSBlock block in blocks)\r\n                {\r\n                    store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);\r\n                }\r\n            }\r\n            Logger.WriteLine(\"Successfully removed the key change lock.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/KMSHostCharge.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class KMSHostCharge\r\n    {\r\n        public static void Charge(PSVersion version, bool production, Guid actId)\r\n        {\r\n            if (actId == Guid.Empty)\r\n            {\r\n                actId = SLApi.GetDefaultActivationID(SLApi.WINDOWS_APP_ID, true);\r\n\r\n                if (actId == Guid.Empty)\r\n                {\r\n                    throw new NotSupportedException(\"No applicable activation IDs found.\");\r\n                }\r\n            }\r\n\r\n            if (SLApi.GetPKeyChannel(SLApi.GetInstalledPkeyID(actId)) != \"Volume:CSVLK\")\r\n            {\r\n                throw new NotSupportedException(\"Non-Volume:CSVLK product key installed.\");\r\n            }\r\n\r\n            Guid appId = SLApi.GetAppId(actId);\r\n            int totalClients = 50;\r\n            int currClients = 25;\r\n            byte[] hwidBlock = Constants.UniversalHWIDBlock;\r\n            string key = string.Format(\"SPPSVC\\\\{0}\", appId);\r\n            long ldapTimestamp = DateTime.Now.ToFileTime();\r\n\r\n            byte[] cmidGuids = { };\r\n            byte[] reqCounts = { };\r\n            byte[] kmsChargeData = { };\r\n\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n\r\n            if (version == PSVersion.Vista)\r\n            {\r\n                writer.Write(new byte[44]);\r\n                writer.Seek(0, SeekOrigin.Begin);\r\n\r\n                writer.Write(totalClients);\r\n                writer.Write(43200);\r\n                writer.Write(32);\r\n\r\n                writer.Seek(20, SeekOrigin.Begin);\r\n                writer.Write((byte)currClients);\r\n\r\n                writer.Seek(32, SeekOrigin.Begin);\r\n                writer.Write((byte)currClients);\r\n\r\n                writer.Seek(0, SeekOrigin.End);\r\n\r\n                for (int i = 0; i < currClients; i++)\r\n                {\r\n                    writer.Write(Guid.NewGuid().ToByteArray());\r\n                    writer.Write(ldapTimestamp - (10 * (i + 1)));\r\n                }\r\n\r\n                kmsChargeData = writer.GetBytes();\r\n            } \r\n            else\r\n            {\r\n                for (int i = 0; i < currClients; i++)\r\n                {\r\n                    writer.Write(ldapTimestamp - (10 * (i + 1)));\r\n                    writer.Write(Guid.NewGuid().ToByteArray());\r\n                }\r\n\r\n                cmidGuids = writer.GetBytes();\r\n\r\n                writer = new BinaryWriter(new MemoryStream());\r\n\r\n                writer.Write(new byte[40]);\r\n\r\n                writer.Seek(4, SeekOrigin.Begin);\r\n                writer.Write((byte)currClients);\r\n\r\n                writer.Seek(24, SeekOrigin.Begin);\r\n                writer.Write((byte)currClients);\r\n\r\n                reqCounts = writer.GetBytes();\r\n            }\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                if (version != PSVersion.Vista)\r\n                {\r\n                    VariableBag kmsCountData = new VariableBag(version);\r\n                    kmsCountData.Blocks.AddRange(new[]\r\n                    {\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.BINARY,\r\n                            KeyAsStr = \"SppBindingLicenseData\",\r\n                            Value = hwidBlock\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.UINT,\r\n                            Key = new byte[] { },\r\n                            ValueAsInt = (uint)totalClients\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.UINT,\r\n                            Key = new byte[] { },\r\n                            ValueAsInt = 1051200000\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.UINT,\r\n                            Key = new byte[] { },\r\n                            ValueAsInt = (uint)currClients\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.BINARY,\r\n                            Key = new byte[] { },\r\n                            Value = cmidGuids\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.BINARY,\r\n                            Key = new byte[] { },\r\n                            Value = reqCounts\r\n                        }\r\n                    });\r\n\r\n                    kmsChargeData = kmsCountData.Serialize();\r\n                }\r\n\r\n                string countVal = version == PSVersion.Vista ? \"C8F6FFF1-79CE-404C-B150-F97991273DF1\" : string.Format(\"msft:spp/kms/host/2.0/store/counters/{0}\", appId);\r\n\r\n                store.DeleteBlock(key, countVal);\r\n                store.AddBlock(new PSBlock\r\n                {\r\n                    Type = BlockType.NAMED,\r\n                    Flags = (version == PSVersion.WinModern) ? (uint)0x400 : 0,\r\n                    KeyAsStr = key,\r\n                    ValueAsStr = countVal,\r\n                    Data = kmsChargeData\r\n                });\r\n\r\n                Logger.WriteLine(string.Format(\"Set charge count to {0} successfully.\", currClients));\r\n            }\r\n\r\n            SPPUtils.RestartSPP(version);\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/RearmReset.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System.Collections.Generic;\r\n    using System.Linq;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class RearmReset\r\n    {\r\n        public static void Reset(PSVersion version, bool production)\r\n        {\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                List<PSBlock> blocks;\r\n\r\n                if (version == PSVersion.Vista)\r\n                {\r\n                    blocks = store.FindBlocks(\"740D70D8-6448-4b2f-9063-4A7A463600C5\").ToList();\r\n                }\r\n                else if (version == PSVersion.Win7)\r\n                {\r\n                    blocks = store.FindBlocks(0xA0000).ToList();\r\n                }\r\n                else\r\n                {\r\n                    blocks = store.FindBlocks(\"__##USERSEP-RESERVED##__$$REARM-COUNT$$\").ToList();\r\n                }\r\n\r\n                foreach (PSBlock block in blocks)\r\n                {\r\n                    if (version == PSVersion.Vista)\r\n                    {\r\n                        store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);\r\n                    }\r\n                    else if (version == PSVersion.Win7)\r\n                    {\r\n                        store.SetBlock(block.KeyAsStr, block.ValueAsInt, new byte[8]);\r\n                    }\r\n                    else\r\n                    {\r\n                        store.SetBlock(block.KeyAsStr, block.ValueAsStr, new byte[8]);\r\n                    }\r\n                }\r\n\r\n                Logger.WriteLine(\"Successfully reset all rearm counters.\");\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/SetIIDParams.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using PhysicalStore;\r\n    using SPP;\r\n    using System.IO;\r\n    using System;\r\n\r\n    public static class SetIIDParams\r\n    {\r\n        public static void SetParams(PSVersion version, bool production, Guid actId, PKeyAlgorithm algorithm, int group, int serial, ulong security)\r\n        {\r\n            if (version == PSVersion.Vista) throw new NotSupportedException(\"This feature is not supported on Windows Vista/Server 2008.\");\r\n\r\n            Guid appId;\r\n\r\n            if (actId == Guid.Empty)\r\n            {\r\n                appId = SLApi.WINDOWS_APP_ID;\r\n                actId = SLApi.GetDefaultActivationID(appId, true);\r\n\r\n                if (actId == Guid.Empty)\r\n                {\r\n                    throw new Exception(\"No applicable activation IDs found.\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                appId = SLApi.GetAppId(actId);\r\n            }\r\n\r\n            Guid pkeyId = SLApi.GetInstalledPkeyID(actId);\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                string key = string.Format(\"SPPSVC\\\\{0}\\\\{1}\", appId, actId);\r\n                PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());\r\n\r\n                if (keyBlock == null)\r\n                {\r\n                    throw new InvalidDataException(\"Failed to get product key data for activation ID \" + actId + \".\");\r\n                }\r\n\r\n                VariableBag pkb = new VariableBag(keyBlock.Data, version);\r\n\r\n                ProductKey pkey = new ProductKey\r\n                {\r\n                    Group = group,\r\n                    Serial = serial,\r\n                    Security = security,\r\n                    Algorithm = algorithm,\r\n                    Upgrade = false\r\n                };\r\n\r\n                string blockName = version == PSVersion.Win7 ? \"SppPkeyShortAuthenticator\" : \"SppPkeyPhoneActivationData\";\r\n                pkb.SetBlock(blockName, pkey.GetPhoneData(version));\r\n                store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());\r\n            }\r\n\r\n            Logger.WriteLine(\"Successfully set IID parameters.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/TamperedFlagsDelete.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System.Linq;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class TamperedFlagsDelete\r\n    {\r\n        public static void DeleteTamperFlags(PSVersion version, bool production)\r\n        {\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                if (version == PSVersion.Vista)\r\n                {\r\n                    DeleteFlag(store, \"6BE8425B-E3CF-4e86-A6AF-5863E3DCB606\");\r\n                }\r\n                else if (version == PSVersion.Win7)\r\n                {\r\n                    SetFlag(store, 0xA0001);\r\n                }\r\n                else\r\n                {\r\n                    DeleteFlag(store, \"__##USERSEP-RESERVED##__$$RECREATED-FLAG$$\");\r\n                    DeleteFlag(store, \"__##USERSEP-RESERVED##__$$RECOVERED-FLAG$$\");\r\n                }\r\n\r\n                Logger.WriteLine(\"Successfully cleared the tamper state.\");\r\n            }\r\n\r\n            SPPUtils.RestartSPP(version);\r\n        }\r\n\r\n        private static void DeleteFlag(IPhysicalStore store, string flag)\r\n        {\r\n            store.FindBlocks(flag).ToList().ForEach(block => store.DeleteBlock(block.KeyAsStr, block.ValueAsStr));\r\n        }\r\n\r\n        private static void SetFlag(IPhysicalStore store, uint flag)\r\n        {\r\n            store.FindBlocks(flag).ToList().ForEach(block => store.SetBlock(block.KeyAsStr, block.ValueAsInt, new byte[8]));\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/UniqueIdDelete.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class UniqueIdDelete\r\n    {\r\n        public static void DeleteUniqueId(PSVersion version, bool production, Guid actId)\r\n        {\r\n            if (version == PSVersion.Vista) throw new NotSupportedException(\"This feature is not supported on Windows Vista/Server 2008.\");\r\n\r\n            Guid appId;\r\n\r\n            if (actId == Guid.Empty)\r\n            {\r\n                appId = SLApi.WINDOWS_APP_ID;\r\n                actId = SLApi.GetDefaultActivationID(appId, true);\r\n\r\n                if (actId == Guid.Empty)\r\n                {\r\n                    throw new Exception(\"No applicable activation IDs found.\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                appId = SLApi.GetAppId(actId);\r\n            }\r\n\r\n            Guid pkeyId = SLApi.GetInstalledPkeyID(actId);\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                string key = string.Format(\"SPPSVC\\\\{0}\\\\{1}\", appId, actId);\r\n                PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());\r\n\r\n                if (keyBlock == null)\r\n                {\r\n                    throw new Exception(\"No product key found.\");\r\n                }\r\n\r\n                VariableBag pkb = new VariableBag(keyBlock.Data, version);\r\n\r\n                pkb.DeleteBlock(\"SppPkeyUniqueIdToken\");\r\n\r\n                store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());\r\n            }\r\n\r\n            Logger.WriteLine(\"Successfully removed Unique ID for product key ID \" + pkeyId);\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Activators/KMS4K.cs\r\nnamespace LibTSforge.Activators\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public class KMS4k\r\n    {\r\n        public static void Activate(PSVersion version, bool production, Guid actId)\r\n        {\r\n            Guid appId;\r\n            if (actId == Guid.Empty)\r\n            {\r\n                appId = SLApi.WINDOWS_APP_ID;\r\n                actId = SLApi.GetDefaultActivationID(appId, true);\r\n\r\n                if (actId == Guid.Empty)\r\n                {\r\n                    throw new NotSupportedException(\"No applicable activation IDs found.\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                appId = SLApi.GetAppId(actId);\r\n            }\r\n\r\n            if (SLApi.GetPKeyChannel(SLApi.GetInstalledPkeyID(actId)) != \"Volume:GVLK\")\r\n            {\r\n                throw new NotSupportedException(\"Non-Volume:GVLK product key installed.\");\r\n            }\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                string key = string.Format(\"SPPSVC\\\\{0}\\\\{1}\", appId, actId);\r\n\r\n                ulong unknown = 0;\r\n                ulong time1;\r\n                ulong time2 = (ulong)DateTime.UtcNow.ToFileTime();\r\n                ulong expiry = Constants.TimerMax;\r\n\r\n                if (version == PSVersion.Vista || version == PSVersion.Win7)\r\n                {\r\n                    unknown = 0x800000000;\r\n                    time1 = 0;\r\n                }\r\n                else\r\n                {\r\n                    long creationTime = BitConverter.ToInt64(store.GetBlock(\"__##USERSEP##\\\\$$_RESERVED_$$\\\\NAMESPACE__\", \"__##USERSEP-RESERVED##__$$GLOBAL-CREATION-TIME$$\").Data, 0);\r\n                    long tickCount = BitConverter.ToInt64(store.GetBlock(\"__##USERSEP##\\\\$$_RESERVED_$$\\\\NAMESPACE__\", \"__##USERSEP-RESERVED##__$$GLOBAL-TICKCOUNT-UPTIME$$\").Data, 0);\r\n                    long deltaTime = BitConverter.ToInt64(store.GetBlock(key, \"__##USERSEP-RESERVED##__$$UP-TIME-DELTA$$\").Data, 0);\r\n\r\n                    time1 = (ulong)(creationTime + tickCount + deltaTime);\r\n                    time2 /= 10000;\r\n                    expiry /= 10000;\r\n                }\r\n\r\n                if (version == PSVersion.Vista)\r\n                {\r\n                    VistaTimer vistaTimer = new VistaTimer\r\n                    {\r\n                        Time = time2,\r\n                        Expiry = Constants.TimerMax\r\n                    };\r\n\r\n                    string vistaTimerName = string.Format(\"msft:sl/timer/VLExpiration/VOLUME/{0}/{1}\", appId, actId);\r\n\r\n                    store.DeleteBlock(key, vistaTimerName);\r\n                    store.DeleteBlock(key, actId.ToString());\r\n\r\n                    BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n                    writer.Write(Constants.KMSv4Response.Length);\r\n                    writer.Write(Constants.KMSv4Response);\r\n                    writer.Write(Constants.UniversalHWIDBlock);\r\n                    byte[] kmsData = writer.GetBytes();\r\n\r\n                    store.AddBlocks(new[]\r\n                    {\r\n                        new PSBlock\r\n                        {\r\n                            Type = BlockType.TIMER,\r\n                            Flags = 0,\r\n                            KeyAsStr = key,\r\n                            ValueAsStr = vistaTimerName,\r\n                            Data = vistaTimer.CastToArray()\r\n                        },\r\n                        new PSBlock\r\n                        {\r\n                            Type = BlockType.NAMED,\r\n                            Flags = 0,\r\n                            KeyAsStr = key,\r\n                            ValueAsStr = actId.ToString(),\r\n                            Data = kmsData\r\n                        }\r\n                    });\r\n                }\r\n                else\r\n                {\r\n                    byte[] hwidBlock = Constants.UniversalHWIDBlock;\r\n                    byte[] kmsResp;\r\n\r\n                    switch (version)\r\n                    {\r\n                        case PSVersion.Win7:\r\n                            kmsResp = Constants.KMSv4Response;\r\n                            break;\r\n                        case PSVersion.Win8:\r\n                            kmsResp = Constants.KMSv5Response;\r\n                            break;\r\n                        case PSVersion.WinBlue:\r\n                        case PSVersion.WinModern:\r\n                            kmsResp = Constants.KMSv6Response;\r\n                            break;\r\n                        default:\r\n                            throw new NotSupportedException(\"Unsupported PSVersion.\");\r\n                    }\r\n\r\n                    VariableBag kmsBinding = new VariableBag(version);\r\n\r\n                    kmsBinding.Blocks.AddRange(new[]\r\n                    {\r\n                    new CRCBlockModern\r\n                    {\r\n                        DataType = CRCBlockType.BINARY,\r\n                        Key = new byte[] { },\r\n                        Value = kmsResp\r\n                    },\r\n                    new CRCBlockModern\r\n                    {\r\n                        DataType = CRCBlockType.STRING,\r\n                        Key = new byte[] { },\r\n                        ValueAsStr = \"msft:rm/algorithm/hwid/4.0\"\r\n                    },\r\n                    new CRCBlockModern\r\n                    {\r\n                        DataType = CRCBlockType.BINARY,\r\n                        KeyAsStr = \"SppBindingLicenseData\",\r\n                        Value = hwidBlock\r\n                    }\r\n                    });\r\n\r\n                    if (version == PSVersion.WinModern)\r\n                    {\r\n                        kmsBinding.Blocks.AddRange(new[]\r\n                        {\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.STRING,\r\n                            Key = new byte[] { },\r\n                            ValueAsStr = \"massgrave.dev\"\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.STRING,\r\n                            Key = new byte[] { },\r\n                            ValueAsStr = \"6969\"\r\n                        }\r\n                        });\r\n                    }\r\n\r\n                    byte[] kmsBindingData = kmsBinding.Serialize();\r\n\r\n                    Timer kmsTimer = new Timer\r\n                    {\r\n                        Unknown = unknown,\r\n                        Time1 = time1,\r\n                        Time2 = time2,\r\n                        Expiry = expiry\r\n                    };\r\n\r\n                    string storeVal = string.Format(\"msft:spp/kms/bind/2.0/store/{0}/{1}\", appId, actId);\r\n                    string timerVal = string.Format(\"msft:spp/kms/bind/2.0/timer/{0}/{1}\", appId, actId);\r\n\r\n                    store.DeleteBlock(key, storeVal);\r\n                    store.DeleteBlock(key, timerVal);\r\n\r\n                    store.AddBlocks(new[]\r\n                    {\r\n                    new PSBlock\r\n                    {\r\n                        Type = BlockType.NAMED,\r\n                        Flags = (version == PSVersion.WinModern) ? (uint)0x400 : 0,\r\n                        KeyAsStr = key,\r\n                        ValueAsStr = storeVal,\r\n                        Data = kmsBindingData\r\n                    },\r\n                    new PSBlock\r\n                    {\r\n                        Type = BlockType.TIMER,\r\n                        Flags = (version == PSVersion.Win7) ? (uint)0 : 0x4,\r\n                        KeyAsStr = key,\r\n                        ValueAsStr = timerVal,\r\n                        Data = kmsTimer.CastToArray()\r\n                    }\r\n                    });\r\n                }\r\n            }\r\n\r\n            SPPUtils.RestartSPP(version);\r\n            SLApi.FireStateChangedEvent(appId);\r\n            Logger.WriteLine(\"Activated using KMS4k successfully.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Activators/ZeroCID.cs\r\nnamespace LibTSforge.Activators\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using Crypto;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class ZeroCID\r\n    {\r\n        private static void Deposit(Guid actId, string instId)\r\n        {\r\n            uint status = SLApi.DepositConfirmationID(actId, instId, Constants.ZeroCID);\r\n            Logger.WriteLine(string.Format(\"Depositing fake CID status {0:X}\", status));\r\n\r\n            if (status != 0)\r\n            {\r\n                throw new InvalidOperationException(\"Failed to deposit fake CID.\");\r\n            }\r\n        }\r\n\r\n        public static void Activate(PSVersion version, bool production, Guid actId)\r\n        {\r\n            Guid appId;\r\n\r\n            if (actId == Guid.Empty)\r\n            {\r\n                appId = SLApi.WINDOWS_APP_ID;\r\n                actId = SLApi.GetDefaultActivationID(appId, false);\r\n\r\n                if (actId == Guid.Empty)\r\n                {\r\n                    throw new NotSupportedException(\"No applicable activation IDs found.\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                appId = SLApi.GetAppId(actId);\r\n            }\r\n\r\n            if (!SLApi.IsPhoneActivatable(actId))\r\n            {\r\n                throw new NotSupportedException(\"Phone license is unavailable for this product.\");\r\n            }\r\n\r\n            string instId = SLApi.GetInstallationID(actId);\r\n            Guid pkeyId = SLApi.GetInstalledPkeyID(actId);\r\n\r\n            if (version == PSVersion.Vista || version == PSVersion.Win7)\r\n            {\r\n                Deposit(actId, instId);\r\n            }\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                byte[] hwidBlock = Constants.UniversalHWIDBlock;\r\n\r\n                Logger.WriteLine(\"Activation ID: \" + actId);\r\n                Logger.WriteLine(\"Installation ID: \" + instId);\r\n                Logger.WriteLine(\"Product Key ID: \" + pkeyId);\r\n\r\n                byte[] iidHash;\r\n\r\n                if (version == PSVersion.Vista)\r\n                {\r\n                    iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId)).Take(0x10).ToArray();\r\n                }\r\n                else if (version == PSVersion.Win7)\r\n                {\r\n                    iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId));\r\n                }\r\n                else\r\n                {\r\n                    iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId + '\\0' + Constants.ZeroCID));\r\n                }\r\n\r\n                string key = string.Format(\"SPPSVC\\\\{0}\\\\{1}\", appId, actId);\r\n                PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());\r\n\r\n                if (keyBlock == null)\r\n                {\r\n                    throw new InvalidDataException(\"Failed to get product key data for activation ID \" + actId + \".\");\r\n                }\r\n\r\n                VariableBag pkb = new VariableBag(keyBlock.Data, version);\r\n\r\n                byte[] pkeyData;\r\n\r\n                if (version == PSVersion.Vista)\r\n                {\r\n                    pkeyData = pkb.GetBlock(\"PKeyBasicInfo\").Value;\r\n                    string uniqueId = Utils.DecodeString(pkeyData.Skip(0x120).Take(0x80).ToArray());\r\n                    string extPid = Utils.DecodeString(pkeyData.Skip(0x1A0).Take(0x80).ToArray());\r\n\r\n                    uint group;\r\n                    uint.TryParse(extPid.Split('-')[1], out group);\r\n\r\n                    if (group == 0)\r\n                    {\r\n                        throw new FormatException(\"Extended PID has invalid format.\");\r\n                    }\r\n\r\n                    ulong shortauth;\r\n\r\n                    try\r\n                    {\r\n                        shortauth = BitConverter.ToUInt64(Convert.FromBase64String(uniqueId.Split('&')[1]), 0);\r\n                    } \r\n                    catch\r\n                    {\r\n                        throw new FormatException(\"Key Unique ID has invalid format.\");\r\n                    }\r\n\r\n                    shortauth |= (ulong)group << 41;\r\n                    pkeyData = BitConverter.GetBytes(shortauth);\r\n                }\r\n                else if (version == PSVersion.Win7)\r\n                {\r\n                    pkeyData = pkb.GetBlock(\"SppPkeyShortAuthenticator\").Value;\r\n                }\r\n                else\r\n                {\r\n                    pkeyData = pkb.GetBlock(\"SppPkeyPhoneActivationData\").Value;\r\n                }\r\n\r\n                pkb.DeleteBlock(\"SppPkeyVirtual\");\r\n                store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());\r\n\r\n                BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n                writer.Write(iidHash.Length);\r\n                writer.Write(iidHash);\r\n                writer.Write(hwidBlock.Length);\r\n                writer.Write(hwidBlock);\r\n                byte[] tsHwidData = writer.GetBytes();\r\n\r\n                writer = new BinaryWriter(new MemoryStream());\r\n                writer.Write(iidHash.Length);\r\n                writer.Write(iidHash);\r\n                writer.Write(pkeyData.Length);\r\n                writer.Write(pkeyData);\r\n                byte[] tsPkeyInfoData = writer.GetBytes();\r\n\r\n                string phoneVersion = version == PSVersion.Vista ? \"6.0\" : \"7.0\";\r\n                Guid indexSlid = version == PSVersion.Vista ? actId : pkeyId;\r\n                string hwidBlockName = string.Format(\"msft:Windows/{0}/Phone/Cached/HwidBlock/{1}\", phoneVersion, indexSlid);\r\n                string pkeyInfoName = string.Format(\"msft:Windows/{0}/Phone/Cached/PKeyInfo/{1}\", phoneVersion, indexSlid);\r\n\r\n                store.DeleteBlock(key, hwidBlockName);\r\n                store.DeleteBlock(key, pkeyInfoName);\r\n\r\n                store.AddBlocks(new[] {\r\n                    new PSBlock\r\n                    {\r\n                        Type = BlockType.NAMED,\r\n                        Flags = 0,\r\n                        KeyAsStr = key,\r\n                        ValueAsStr = hwidBlockName,\r\n                        Data = tsHwidData\r\n                    }, \r\n                    new PSBlock\r\n                    {\r\n                        Type = BlockType.NAMED,\r\n                        Flags = 0,\r\n                        KeyAsStr = key,\r\n                        ValueAsStr = pkeyInfoName,\r\n                        Data = tsPkeyInfoData\r\n                    }\r\n                });\r\n            }\r\n\r\n            if (version != PSVersion.Vista && version != PSVersion.Win7)\r\n            {\r\n                Deposit(actId, instId);\r\n            }\r\n\r\n            SPPUtils.RestartSPP(version);\r\n            SLApi.FireStateChangedEvent(appId);\r\n            Logger.WriteLine(\"Activated using ZeroCID successfully.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/TokenStore/Common.cs\r\nnamespace LibTSforge.TokenStore\r\n{\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n\r\n    public class TokenEntry\r\n    {\r\n        public string Name;\r\n        public string Extension;\r\n        public byte[] Data;\r\n        public bool Populated;\r\n    }\r\n\r\n    public class TokenMeta\r\n    {\r\n        public string Name;\r\n        public readonly Dictionary<string, string> Data = new Dictionary<string, string>();\r\n\r\n        public byte[] Serialize()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(1);\r\n            byte[] nameBytes = Utils.EncodeString(Name);\r\n            writer.Write(nameBytes.Length);\r\n            writer.Write(nameBytes);\r\n\r\n            foreach (KeyValuePair<string, string> kv in Data)\r\n            {\r\n                byte[] keyBytes = Utils.EncodeString(kv.Key);\r\n                byte[] valueBytes = Utils.EncodeString(kv.Value);\r\n                writer.Write(keyBytes.Length);\r\n                writer.Write(valueBytes.Length);\r\n                writer.Write(keyBytes);\r\n                writer.Write(valueBytes);\r\n            }\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        private void Deserialize(byte[] data)\r\n        {\r\n            BinaryReader reader = new BinaryReader(new MemoryStream(data));\r\n            reader.ReadInt32();\r\n            int nameLen = reader.ReadInt32();\r\n            Name = reader.ReadNullTerminatedString(nameLen);\r\n\r\n            while (reader.BaseStream.Position < data.Length - 0x8)\r\n            {\r\n                int keyLen = reader.ReadInt32();\r\n                int valueLen = reader.ReadInt32();\r\n                string key = reader.ReadNullTerminatedString(keyLen);\r\n                string value = reader.ReadNullTerminatedString(valueLen);\r\n                Data[key] = value;\r\n            }\r\n        }\r\n\r\n        public TokenMeta(byte[] data)\r\n        {\r\n            Deserialize(data);\r\n        }\r\n\r\n        public TokenMeta()\r\n        {\r\n\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/TokenStore/ITokenStore.cs\r\nnamespace LibTSforge.TokenStore\r\n{\r\n    using System;\r\n\r\n    public interface ITokenStore : IDisposable\r\n    {\r\n        void Deserialize();\r\n        void Serialize();\r\n        void AddEntry(TokenEntry entry);\r\n        void AddEntries(TokenEntry[] entries);\r\n        void DeleteEntry(string name, string ext);\r\n        void DeleteUnpopEntry(string name, string ext);\r\n        TokenEntry GetEntry(string name, string ext);\r\n        TokenMeta GetMetaEntry(string name);\r\n        void SetEntry(string name, string ext, byte[] data);\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/TokenStore/TokenStoreModern.cs\r\nnamespace LibTSforge.TokenStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using Crypto;\r\n\r\n    public class TokenStoreModern : ITokenStore\r\n    {\r\n        private static readonly uint VERSION = 3;\r\n        private static readonly int ENTRY_SIZE = 0x9E;\r\n        private static readonly int BLOCK_SIZE = 0x4020;\r\n        private static readonly int ENTRIES_PER_BLOCK = BLOCK_SIZE / ENTRY_SIZE;\r\n        private static readonly int BLOCK_PAD_SIZE = 0x66;\r\n\r\n        private static readonly byte[] CONTS_HEADER = Enumerable.Repeat((byte)0x55, 0x20).ToArray();\r\n        private static readonly byte[] CONTS_FOOTER = Enumerable.Repeat((byte)0xAA, 0x20).ToArray();\r\n\r\n        private List<TokenEntry> Entries = new List<TokenEntry>();\r\n        private readonly FileStream TokensFile;\r\n\r\n        public void Deserialize()\r\n        {\r\n            if (TokensFile.Length < BLOCK_SIZE) return;\r\n\r\n            TokensFile.Seek(0x24, SeekOrigin.Begin);\r\n            uint nextBlock;\r\n\r\n            BinaryReader reader = new BinaryReader(TokensFile);\r\n            do\r\n            {\r\n                reader.ReadUInt32();\r\n                nextBlock = reader.ReadUInt32();\r\n\r\n                for (int i = 0; i < ENTRIES_PER_BLOCK; i++)\r\n                {\r\n                    uint curOffset = reader.ReadUInt32();\r\n                    bool populated = reader.ReadUInt32() == 1;\r\n                    uint contentOffset = reader.ReadUInt32();\r\n                    uint contentLength = reader.ReadUInt32();\r\n                    uint allocLength = reader.ReadUInt32();\r\n                    byte[] contentData = { };\r\n\r\n                    if (populated)\r\n                    {\r\n                        reader.BaseStream.Seek(contentOffset + 0x20, SeekOrigin.Begin);\r\n                        uint dataLength = reader.ReadUInt32();\r\n\r\n                        if (dataLength != contentLength)\r\n                        {\r\n                            throw new FormatException(\"Data length in tokens content is inconsistent with entry.\");\r\n                        }\r\n\r\n                        reader.ReadBytes(0x20);\r\n                        contentData = reader.ReadBytes((int)contentLength);\r\n                    }\r\n\r\n                    reader.BaseStream.Seek(curOffset + 0x14, SeekOrigin.Begin);\r\n\r\n                    Entries.Add(new TokenEntry\r\n                    {\r\n                        Name = reader.ReadNullTerminatedString(0x82),\r\n                        Extension = reader.ReadNullTerminatedString(0x8),\r\n                        Data = contentData,\r\n                        Populated = populated\r\n                    });\r\n                }\r\n\r\n                reader.BaseStream.Seek(nextBlock, SeekOrigin.Begin);\r\n            } while (nextBlock != 0);\r\n        }\r\n\r\n        public void Serialize()\r\n        {\r\n            MemoryStream tokens = new MemoryStream();\r\n\r\n            using (BinaryWriter writer = new BinaryWriter(tokens))\r\n            {\r\n                writer.Write(VERSION);\r\n                writer.Write(CONTS_HEADER);\r\n\r\n                int curBlockOffset = (int)writer.BaseStream.Position;\r\n                int curEntryOffset = curBlockOffset + 0x8;\r\n                int curContsOffset = curBlockOffset + BLOCK_SIZE;\r\n\r\n                for (int eIndex = 0; eIndex < ((Entries.Count / ENTRIES_PER_BLOCK) + 1) * ENTRIES_PER_BLOCK; eIndex++)\r\n                {\r\n                    TokenEntry entry;\r\n\r\n                    if (eIndex < Entries.Count)\r\n                    {\r\n                        entry = Entries[eIndex];\r\n                    }\r\n                    else\r\n                    {\r\n                        entry = new TokenEntry\r\n                        {\r\n                            Name = \"\",\r\n                            Extension = \"\",\r\n                            Populated = false,\r\n                            Data = new byte[] { }\r\n                        };\r\n                    }\r\n\r\n                    writer.BaseStream.Seek(curBlockOffset, SeekOrigin.Begin);\r\n                    writer.Write(curBlockOffset);\r\n                    writer.Write(0);\r\n\r\n                    writer.BaseStream.Seek(curEntryOffset, SeekOrigin.Begin);\r\n                    writer.Write(curEntryOffset);\r\n                    writer.Write(entry.Populated ? 1 : 0);\r\n                    writer.Write(entry.Populated ? curContsOffset : 0);\r\n                    writer.Write(entry.Populated ? entry.Data.Length : -1);\r\n                    writer.Write(entry.Populated ? entry.Data.Length : -1);\r\n                    writer.WriteFixedString16(entry.Name, 0x82);\r\n                    writer.WriteFixedString16(entry.Extension, 0x8);\r\n                    curEntryOffset = (int)writer.BaseStream.Position;\r\n\r\n                    if (entry.Populated)\r\n                    {\r\n                        writer.BaseStream.Seek(curContsOffset, SeekOrigin.Begin);\r\n                        writer.Write(CONTS_HEADER);\r\n                        writer.Write(entry.Data.Length);\r\n                        writer.Write(CryptoUtils.SHA256Hash(entry.Data));\r\n                        writer.Write(entry.Data);\r\n                        writer.Write(CONTS_FOOTER);\r\n                        curContsOffset = (int)writer.BaseStream.Position;\r\n                    }\r\n\r\n                    if ((eIndex + 1) % ENTRIES_PER_BLOCK == 0 && eIndex != 0)\r\n                    {\r\n                        if (eIndex < Entries.Count)\r\n                        {\r\n                            writer.BaseStream.Seek(curBlockOffset + 0x4, SeekOrigin.Begin);\r\n                            writer.Write(curContsOffset);\r\n                        }\r\n\r\n                        writer.BaseStream.Seek(curEntryOffset, SeekOrigin.Begin);\r\n                        writer.WritePadding(BLOCK_PAD_SIZE);\r\n\r\n                        writer.BaseStream.Seek(curBlockOffset, SeekOrigin.Begin);\r\n                        byte[] blockData = new byte[BLOCK_SIZE - 0x20];\r\n\r\n                        tokens.Read(blockData, 0, BLOCK_SIZE - 0x20);\r\n                        byte[] blockHash = CryptoUtils.SHA256Hash(blockData);\r\n\r\n                        writer.BaseStream.Seek(curBlockOffset + BLOCK_SIZE - 0x20, SeekOrigin.Begin);\r\n                        writer.Write(blockHash);\r\n\r\n                        curBlockOffset = curContsOffset;\r\n                        curEntryOffset = curBlockOffset + 0x8;\r\n                        curContsOffset = curBlockOffset + BLOCK_SIZE;\r\n                    }\r\n                }\r\n\r\n                tokens.SetLength(curBlockOffset);\r\n            }\r\n\r\n            byte[] tokensData = tokens.ToArray();\r\n            byte[] tokensHash = CryptoUtils.SHA256Hash(tokensData.Take(0x4).Concat(tokensData.Skip(0x24)).ToArray());\r\n\r\n            tokens = new MemoryStream(tokensData);\r\n\r\n            BinaryWriter tokWriter = new BinaryWriter(TokensFile);\r\n            using (BinaryReader reader = new BinaryReader(tokens))\r\n            {\r\n                TokensFile.Seek(0, SeekOrigin.Begin);\r\n                TokensFile.SetLength(tokens.Length);\r\n                tokWriter.Write(reader.ReadBytes(0x4));\r\n                reader.ReadBytes(0x20);\r\n                tokWriter.Write(tokensHash);\r\n                tokWriter.Write(reader.ReadBytes((int)reader.BaseStream.Length - 0x4));\r\n            }\r\n        }\r\n\r\n        public void AddEntry(TokenEntry entry)\r\n        {\r\n            Entries.Add(entry);\r\n        }\r\n\r\n        public void AddEntries(TokenEntry[] entries)\r\n        {\r\n            Entries.AddRange(entries);\r\n        }\r\n\r\n        public void DeleteEntry(string name, string ext)\r\n        {\r\n            foreach (TokenEntry entry in Entries)\r\n            {\r\n                if (entry.Name == name && entry.Extension == ext)\r\n                {\r\n                    Entries.Remove(entry);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void DeleteUnpopEntry(string name, string ext)\r\n        {\r\n            List<TokenEntry> delEntries = new List<TokenEntry>();\r\n            foreach (TokenEntry entry in Entries)\r\n            {\r\n                if (entry.Name == name && entry.Extension == ext && !entry.Populated)\r\n                {\r\n                    delEntries.Add(entry);\r\n                }\r\n            }\r\n\r\n            Entries = Entries.Except(delEntries).ToList();\r\n        }\r\n\r\n        public TokenEntry GetEntry(string name, string ext)\r\n        {\r\n            foreach (TokenEntry entry in Entries)\r\n            {\r\n                if (entry.Name == name && entry.Extension == ext)\r\n                {\r\n                    if (!entry.Populated) continue;\r\n                    return entry;\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public TokenMeta GetMetaEntry(string name)\r\n        {\r\n            DeleteUnpopEntry(name, \"xml\");\r\n            TokenEntry entry = GetEntry(name, \"xml\");\r\n            TokenMeta meta;\r\n\r\n            if (entry == null)\r\n            {\r\n                meta = new TokenMeta\r\n                {\r\n                    Name = name\r\n                };\r\n            }\r\n            else\r\n            {\r\n                meta = new TokenMeta(entry.Data);\r\n            }\r\n\r\n            return meta;\r\n        }\r\n\r\n        public void SetEntry(string name, string ext, byte[] data)\r\n        {\r\n            for (int i = 0; i < Entries.Count; i++)\r\n            {\r\n                TokenEntry entry = Entries[i];\r\n\r\n                if (entry.Name == name && entry.Extension == ext && entry.Populated)\r\n                {\r\n                    entry.Data = data;\r\n                    Entries[i] = entry;\r\n                    return;\r\n                }\r\n            }\r\n\r\n            Entries.Add(new TokenEntry\r\n            {\r\n                Populated = true,\r\n                Name = name,\r\n                Extension = ext,\r\n                Data = data\r\n            });\r\n        }\r\n\r\n        public TokenStoreModern(string tokensPath)\r\n        {\r\n            TokensFile = File.Open(tokensPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            Deserialize();\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            Serialize();\r\n            TokensFile.Close();\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/Common.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System.Runtime.InteropServices;\r\n\r\n    public enum BlockType : uint\r\n    {\r\n        NONE,\r\n        NAMED,\r\n        ATTRIBUTE,\r\n        TIMER\r\n    }\r\n\r\n    [StructLayout(LayoutKind.Sequential, Pack = 1)]\r\n    public struct Timer\r\n    {\r\n        public ulong Unknown;\r\n        public ulong Time1;\r\n        public ulong Time2;\r\n        public ulong Expiry;\r\n    }\r\n\r\n    [StructLayout(LayoutKind.Sequential, Pack = 1)]\r\n    public struct VistaTimer\r\n    {\r\n        public ulong Time;\r\n        public ulong Expiry;\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/IPhysicalStore.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n\r\n    public class PSBlock\r\n    {\r\n        public BlockType Type;\r\n        public uint Flags;\r\n        public uint Unknown = 0;\r\n        public byte[] Key;\r\n        public string KeyAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Key);\r\n            }\r\n            set\r\n            {\r\n                Key = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public byte[] Value;\r\n        public string ValueAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Value);\r\n            }\r\n            set\r\n            {\r\n                Value = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint ValueAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Value, 0);\r\n            }\r\n            set\r\n            {\r\n                Value = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n        public byte[] Data;\r\n        public string DataAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Data);\r\n            }\r\n            set\r\n            {\r\n                Data = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint DataAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Data, 0);\r\n            }\r\n            set\r\n            {\r\n                Data = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n    }\r\n\r\n    public interface IPhysicalStore : IDisposable\r\n    {\r\n        PSBlock GetBlock(string key, string value);\r\n        PSBlock GetBlock(string key, uint value);\r\n        void AddBlock(PSBlock block);\r\n        void AddBlocks(IEnumerable<PSBlock> blocks);\r\n        void SetBlock(string key, string value, byte[] data);\r\n        void SetBlock(string key, string value, string data);\r\n        void SetBlock(string key, string value, uint data);\r\n        void SetBlock(string key, uint value, byte[] data);\r\n        void SetBlock(string key, uint value, string data);\r\n        void SetBlock(string key, uint value, uint data);\r\n        void DeleteBlock(string key, string value);\r\n        void DeleteBlock(string key, uint value);\r\n        byte[] Serialize();\r\n        void Deserialize(byte[] data);\r\n        byte[] ReadRaw();\r\n        void WriteRaw(byte[] data);\r\n        IEnumerable<PSBlock> FindBlocks(string valueSearch);\r\n        IEnumerable<PSBlock> FindBlocks(uint valueSearch);\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/PhysicalStoreModern.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using Crypto;\r\n\r\n    public class ModernBlock\r\n    {\r\n        public BlockType Type;\r\n        public uint Flags;\r\n        public uint Unknown;\r\n        public byte[] Value;\r\n        public string ValueAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Value);\r\n            }\r\n            set\r\n            {\r\n                Value = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint ValueAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Value, 0);\r\n            }\r\n            set\r\n            {\r\n                Value = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n        public byte[] Data;\r\n        public string DataAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Data);\r\n            }\r\n            set\r\n            {\r\n                Data = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint DataAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Data, 0);\r\n            }\r\n            set\r\n            {\r\n                Data = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n\r\n        public void Encode(BinaryWriter writer)\r\n        {\r\n            writer.Write((uint)Type);\r\n            writer.Write(Flags);\r\n            writer.Write((uint)Value.Length);\r\n            writer.Write((uint)Data.Length);\r\n            writer.Write(Unknown);\r\n            writer.Write(Value);\r\n            writer.Write(Data);\r\n        }\r\n\r\n        public static ModernBlock Decode(BinaryReader reader)\r\n        {\r\n            uint type = reader.ReadUInt32();\r\n            uint flags = reader.ReadUInt32();\r\n\r\n            uint valueLen = reader.ReadUInt32();\r\n            uint dataLen = reader.ReadUInt32();\r\n            uint unk3 = reader.ReadUInt32();\r\n\r\n            byte[] value = reader.ReadBytes((int)valueLen);\r\n            byte[] data = reader.ReadBytes((int)dataLen);\r\n\r\n            return new ModernBlock\r\n            {\r\n                Type = (BlockType)type,\r\n                Flags = flags,\r\n                Unknown = unk3,\r\n                Value = value,\r\n                Data = data,\r\n            };\r\n        }\r\n    }\r\n\r\n    public sealed class PhysicalStoreModern : IPhysicalStore\r\n    {\r\n        private byte[] PreHeaderBytes = { };\r\n        private readonly Dictionary<string, List<ModernBlock>> Data = new Dictionary<string, List<ModernBlock>>();\r\n        private readonly FileStream TSFile;\r\n        private readonly PSVersion Version;\r\n        private readonly bool Production;\r\n\r\n        public byte[] Serialize()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(PreHeaderBytes);\r\n            writer.Write(Data.Keys.Count);\r\n\r\n            foreach (string key in Data.Keys)\r\n            {\r\n                List<ModernBlock> blocks = Data[key];\r\n                byte[] keyNameEnc = Utils.EncodeString(key);\r\n\r\n                writer.Write(keyNameEnc.Length);\r\n                writer.Write(keyNameEnc);\r\n                writer.Write(blocks.Count);\r\n                writer.Align(4);\r\n\r\n                foreach (ModernBlock block in blocks)\r\n                {\r\n                    block.Encode(writer);\r\n                    writer.Align(4);\r\n                }\r\n            }\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public void Deserialize(byte[] data)\r\n        {\r\n            BinaryReader reader = new BinaryReader(new MemoryStream(data));\r\n            PreHeaderBytes = reader.ReadBytes(8);\r\n\r\n            while (reader.BaseStream.Position < data.Length - 0x4)\r\n            {\r\n                uint numKeys = reader.ReadUInt32();\r\n\r\n                for (int i = 0; i < numKeys; i++)\r\n                {\r\n                    uint lenKeyName = reader.ReadUInt32();\r\n                    string keyName = Utils.DecodeString(reader.ReadBytes((int)lenKeyName)); uint numValues = reader.ReadUInt32();\r\n\r\n                    reader.Align(4);\r\n\r\n                    Data[keyName] = new List<ModernBlock>();\r\n\r\n                    for (int j = 0; j < numValues; j++)\r\n                    {\r\n                        Data[keyName].Add(ModernBlock.Decode(reader));\r\n                        reader.Align(4);\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        public void AddBlock(PSBlock block)\r\n        {\r\n            if (!Data.ContainsKey(block.KeyAsStr))\r\n            {\r\n                Data[block.KeyAsStr] = new List<ModernBlock>();\r\n            }\r\n\r\n            Data[block.KeyAsStr].Add(new ModernBlock\r\n            {\r\n                Type = block.Type,\r\n                Flags = block.Flags,\r\n                Unknown = block.Unknown,\r\n                Value = block.Value,\r\n                Data = block.Data\r\n            });\r\n        }\r\n\r\n        public void AddBlocks(IEnumerable<PSBlock> blocks)\r\n        {\r\n            foreach (PSBlock block in blocks)\r\n            {\r\n                AddBlock(block);\r\n            }\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, string value)\r\n        {\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            foreach (ModernBlock block in blocks)\r\n            {\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = Utils.EncodeString(key),\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, uint value)\r\n        {\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            foreach (ModernBlock block in blocks)\r\n            {\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = Utils.EncodeString(key),\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public void SetBlock(string key, string value, byte[] data)\r\n        {\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            for (int i = 0; i < blocks.Count; i++)\r\n            {\r\n                ModernBlock block = blocks[i];\r\n\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    block.Data = data;\r\n                    blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n\r\n            Data[key] = blocks;\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, byte[] data)\r\n        {\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            for (int i = 0; i < blocks.Count; i++)\r\n            {\r\n                ModernBlock block = blocks[i];\r\n\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    block.Data = data;\r\n                    blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n\r\n            Data[key] = blocks;\r\n        }\r\n\r\n        public void SetBlock(string key, string value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, string value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void DeleteBlock(string key, string value)\r\n        {\r\n            if (!Data.ContainsKey(key))\r\n            {\r\n                return;\r\n            }\r\n\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            foreach (ModernBlock block in blocks)\r\n            {\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    blocks.Remove(block);\r\n                    break;\r\n                }\r\n            }\r\n\r\n            Data[key] = blocks;\r\n        }\r\n\r\n        public void DeleteBlock(string key, uint value)\r\n        {\r\n            if (!Data.ContainsKey(key))\r\n            {\r\n                return;\r\n            }\r\n\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            foreach (ModernBlock block in blocks)\r\n            {\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    blocks.Remove(block);\r\n                    break;\r\n                }\r\n            }\r\n\r\n            Data[key] = blocks;\r\n        }\r\n\r\n        public PhysicalStoreModern(string tsPath, bool production, PSVersion version)\r\n        {\r\n            TSFile = File.Open(tsPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSFile.ReadAllBytes(), production, version));\r\n            TSFile.Seek(0, SeekOrigin.Begin);\r\n            Version = version;\r\n            Production = production;\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            if (TSFile.CanWrite)\r\n            {\r\n                byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, Version);\r\n                TSFile.SetLength(data.LongLength);\r\n                TSFile.Seek(0, SeekOrigin.Begin);\r\n                TSFile.WriteAllBytes(data);\r\n                TSFile.Close();\r\n            }\r\n        }\r\n\r\n        public byte[] ReadRaw()\r\n        {\r\n            byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSFile.ReadAllBytes(), Production, Version);\r\n            TSFile.Seek(0, SeekOrigin.Begin);\r\n            return data;\r\n        }\r\n\r\n        public void WriteRaw(byte[] data)\r\n        {\r\n            byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, Version);\r\n            TSFile.SetLength(encrData.LongLength);\r\n            TSFile.Seek(0, SeekOrigin.Begin);\r\n            TSFile.WriteAllBytes(encrData);\r\n            TSFile.Close();\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(string valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (string key in Data.Keys)\r\n            {\r\n                List<ModernBlock> values = Data[key];\r\n\r\n                foreach (ModernBlock block in values)\r\n                {\r\n                    if (block.ValueAsStr.Contains(valueSearch))\r\n                    {\r\n                        results.Add(new PSBlock\r\n                        {\r\n                            Type = block.Type,\r\n                            Flags = block.Flags,\r\n                            KeyAsStr = key,\r\n                            Value = block.Value,\r\n                            Data = block.Data\r\n                        });\r\n                    }\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(uint valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (string key in Data.Keys)\r\n            {\r\n                List<ModernBlock> values = Data[key];\r\n\r\n                foreach (ModernBlock block in values)\r\n                {\r\n                    if (block.ValueAsInt == valueSearch)\r\n                    {\r\n                        results.Add(new PSBlock\r\n                        {\r\n                            Type = block.Type,\r\n                            Flags = block.Flags,\r\n                            KeyAsStr = key,\r\n                            Value = block.Value,\r\n                            Data = block.Data\r\n                        });\r\n                    }\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/PhysicalStoreVista.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using Crypto;\r\n\r\n    public class VistaBlock\r\n    {\r\n        public BlockType Type;\r\n        public uint Flags;\r\n        public byte[] Value;\r\n        public string ValueAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Value);\r\n            }\r\n            set\r\n            {\r\n                Value = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint ValueAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Value, 0);\r\n            }\r\n            set\r\n            {\r\n                Value = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n        public byte[] Data;\r\n        public string DataAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Data);\r\n            }\r\n            set\r\n            {\r\n                Data = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint DataAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Data, 0);\r\n            }\r\n            set\r\n            {\r\n                Data = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n\r\n        internal void Encode(BinaryWriter writer)\r\n        {\r\n            writer.Write((uint)Type);\r\n            writer.Write(Flags);\r\n            writer.Write(Value.Length);\r\n            writer.Write(Data.Length);\r\n            writer.Write(Value);\r\n            writer.Write(Data);\r\n        }\r\n\r\n        internal static VistaBlock Decode(BinaryReader reader)\r\n        {\r\n            uint type = reader.ReadUInt32();\r\n            uint flags = reader.ReadUInt32();\r\n\r\n            int valueLen = reader.ReadInt32();\r\n            int dataLen = reader.ReadInt32();\r\n\r\n            byte[] value = reader.ReadBytes(valueLen);\r\n            byte[] data = reader.ReadBytes(dataLen);\r\n            return new VistaBlock\r\n            {\r\n                Type = (BlockType)type,\r\n                Flags = flags,\r\n                Value = value,\r\n                Data = data,\r\n            };\r\n        }\r\n    }\r\n\r\n    public sealed class PhysicalStoreVista : IPhysicalStore\r\n    {\r\n        private byte[] PreHeaderBytes = { };\r\n        private readonly List<VistaBlock> Blocks = new List<VistaBlock>();\r\n        private readonly FileStream TSPrimary;\r\n        private readonly FileStream TSSecondary;\r\n        private readonly bool Production;\r\n\r\n        public byte[] Serialize()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(PreHeaderBytes);\r\n\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                block.Encode(writer);\r\n                writer.Align(4);\r\n            }\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public void Deserialize(byte[] data)\r\n        {\r\n            int len = data.Length;\r\n\r\n            BinaryReader reader = new BinaryReader(new MemoryStream(data));\r\n            PreHeaderBytes = reader.ReadBytes(8);\r\n\r\n            while (reader.BaseStream.Position < len - 0x14)\r\n            {\r\n                Blocks.Add(VistaBlock.Decode(reader));\r\n                reader.Align(4);\r\n            }\r\n        }\r\n\r\n        public void AddBlock(PSBlock block)\r\n        {\r\n            Blocks.Add(new VistaBlock\r\n            {\r\n                Type = block.Type,\r\n                Flags = block.Flags,\r\n                Value = block.Value,\r\n                Data = block.Data\r\n            });\r\n        }\r\n\r\n        public void AddBlocks(IEnumerable<PSBlock> blocks)\r\n        {\r\n            foreach (PSBlock block in blocks)\r\n            {\r\n                AddBlock(block);\r\n            }\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, string value)\r\n        {\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = new byte[0],\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, uint value)\r\n        {\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = new byte[0],\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public void SetBlock(string key, string value, byte[] data)\r\n        {\r\n            for (int i = 0; i < Blocks.Count; i++)\r\n            {\r\n                VistaBlock block = Blocks[i];\r\n\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    block.Data = data;\r\n                    Blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, byte[] data)\r\n        {\r\n            for (int i = 0; i < Blocks.Count; i++)\r\n            {\r\n                VistaBlock block = Blocks[i];\r\n\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    block.Data = data;\r\n                    Blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void SetBlock(string key, string value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, string value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void DeleteBlock(string key, string value)\r\n        {\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    Blocks.Remove(block);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void DeleteBlock(string key, uint value)\r\n        {\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    Blocks.Remove(block);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public PhysicalStoreVista(string primaryPath, bool production)\r\n        {\r\n            TSPrimary = File.Open(primaryPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            TSSecondary = File.Open(primaryPath.Replace(\"-0.\", \"-1.\"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            Production = production;\r\n\r\n            Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), production, PSVersion.Vista));\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            if (TSPrimary.CanWrite && TSSecondary.CanWrite)\r\n            {\r\n                byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, PSVersion.Vista);\r\n\r\n                TSPrimary.SetLength(data.LongLength);\r\n                TSSecondary.SetLength(data.LongLength);\r\n\r\n                TSPrimary.Seek(0, SeekOrigin.Begin);\r\n                TSSecondary.Seek(0, SeekOrigin.Begin);\r\n\r\n                TSPrimary.WriteAllBytes(data);\r\n                TSSecondary.WriteAllBytes(data);\r\n\r\n                TSPrimary.Close();\r\n                TSSecondary.Close();\r\n            }\r\n        }\r\n\r\n        public byte[] ReadRaw()\r\n        {\r\n            byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), Production, PSVersion.Vista);\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n            return data;\r\n        }\r\n\r\n        public void WriteRaw(byte[] data)\r\n        {\r\n            byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, PSVersion.Vista);\r\n\r\n            TSPrimary.SetLength(encrData.LongLength);\r\n            TSSecondary.SetLength(encrData.LongLength);\r\n\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n            TSSecondary.Seek(0, SeekOrigin.Begin);\r\n\r\n            TSPrimary.WriteAllBytes(encrData);\r\n            TSSecondary.WriteAllBytes(encrData);\r\n\r\n            TSPrimary.Close();\r\n            TSSecondary.Close();\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(string valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsStr.Contains(valueSearch))\r\n                {\r\n                    results.Add(new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = new byte[0],\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    });\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(uint valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsInt == valueSearch)\r\n                {\r\n                    results.Add(new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = new byte[0],\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    });\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/PhysicalStoreWin7.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using Crypto;\r\n\r\n    public class Win7Block\r\n    {\r\n        public BlockType Type;\r\n        public uint Flags;\r\n        public byte[] Key;\r\n        public string KeyAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Key);\r\n            }\r\n            set\r\n            {\r\n                Key = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public byte[] Value;\r\n        public string ValueAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Value);\r\n            }\r\n            set\r\n            {\r\n                Value = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint ValueAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Value, 0);\r\n            }\r\n            set\r\n            {\r\n                Value = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n        public byte[] Data;\r\n        public string DataAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Data);\r\n            }\r\n            set\r\n            {\r\n                Data = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint DataAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Data, 0);\r\n            }\r\n            set\r\n            {\r\n                Data = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n\r\n        internal void Encode(BinaryWriter writer)\r\n        {\r\n            writer.Write((uint)Type);\r\n            writer.Write(Flags);\r\n            writer.Write(Key.Length);\r\n            writer.Write(Value.Length);\r\n            writer.Write(Data.Length);\r\n            writer.Write(Key);\r\n            writer.Write(Value);\r\n            writer.Write(Data);\r\n        }\r\n\r\n        internal static Win7Block Decode(BinaryReader reader)\r\n        {\r\n            uint type = reader.ReadUInt32();\r\n            uint flags = reader.ReadUInt32();\r\n\r\n            int keyLen = reader.ReadInt32();\r\n            int valueLen = reader.ReadInt32();\r\n            int dataLen = reader.ReadInt32();\r\n\r\n            byte[] key = reader.ReadBytes(keyLen);\r\n            byte[] value = reader.ReadBytes(valueLen);\r\n            byte[] data = reader.ReadBytes(dataLen);\r\n            return new Win7Block\r\n            {\r\n                Type = (BlockType)type,\r\n                Flags = flags,\r\n                Key = key,\r\n                Value = value,\r\n                Data = data,\r\n            };\r\n        }\r\n    }\r\n\r\n    public sealed class PhysicalStoreWin7 : IPhysicalStore\r\n    {\r\n        private byte[] PreHeaderBytes = { };\r\n        private readonly List<Win7Block> Blocks = new List<Win7Block>();\r\n        private readonly FileStream TSPrimary;\r\n        private readonly FileStream TSSecondary;\r\n        private readonly bool Production;\r\n\r\n        public byte[] Serialize()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(PreHeaderBytes);\r\n\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                block.Encode(writer);\r\n                writer.Align(4);\r\n            }\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public void Deserialize(byte[] data)\r\n        {\r\n            int len = data.Length;\r\n\r\n            BinaryReader reader = new BinaryReader(new MemoryStream(data));\r\n            PreHeaderBytes = reader.ReadBytes(8);\r\n\r\n            while (reader.BaseStream.Position < len - 0x14)\r\n            {\r\n                Blocks.Add(Win7Block.Decode(reader));\r\n                reader.Align(4);\r\n            }\r\n        }\r\n\r\n        public void AddBlock(PSBlock block)\r\n        {\r\n            Blocks.Add(new Win7Block\r\n            {\r\n                Type = block.Type,\r\n                Flags = block.Flags,\r\n                Key = block.Key,\r\n                Value = block.Value,\r\n                Data = block.Data\r\n            });\r\n        }\r\n\r\n        public void AddBlocks(IEnumerable<PSBlock> blocks)\r\n        {\r\n            foreach (PSBlock block in blocks)\r\n            {\r\n                AddBlock(block);\r\n            }\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, string value)\r\n        {\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key && block.ValueAsStr == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = block.Key,\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, uint value)\r\n        {\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key && block.ValueAsInt == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = block.Key,\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public void SetBlock(string key, string value, byte[] data)\r\n        {\r\n            for (int i = 0; i < Blocks.Count; i++)\r\n            {\r\n                Win7Block block = Blocks[i];\r\n\r\n                if (block.KeyAsStr == key && block.ValueAsStr == value)\r\n                {\r\n                    block.Data = data;\r\n                    Blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, byte[] data)\r\n        {\r\n            for (int i = 0; i < Blocks.Count; i++)\r\n            {\r\n                Win7Block block = Blocks[i];\r\n\r\n                if (block.KeyAsStr == key && block.ValueAsInt == value)\r\n                {\r\n                    block.Data = data;\r\n                    Blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void SetBlock(string key, string value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, string value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void DeleteBlock(string key, string value)\r\n        {\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key && block.ValueAsStr == value)\r\n                {\r\n                    Blocks.Remove(block);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void DeleteBlock(string key, uint value)\r\n        {\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key && block.ValueAsInt == value)\r\n                {\r\n                    Blocks.Remove(block);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public PhysicalStoreWin7(string primaryPath, bool production)\r\n        {\r\n            TSPrimary = File.Open(primaryPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            TSSecondary = File.Open(primaryPath.Replace(\"-0.\", \"-1.\"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            Production = production;\r\n\r\n            Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), production, PSVersion.Win7));\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            if (TSPrimary.CanWrite && TSSecondary.CanWrite)\r\n            {\r\n                byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, PSVersion.Win7);\r\n\r\n                TSPrimary.SetLength(data.LongLength);\r\n                TSSecondary.SetLength(data.LongLength);\r\n\r\n                TSPrimary.Seek(0, SeekOrigin.Begin);\r\n                TSSecondary.Seek(0, SeekOrigin.Begin);\r\n\r\n                TSPrimary.WriteAllBytes(data);\r\n                TSSecondary.WriteAllBytes(data);\r\n\r\n                TSPrimary.Close();\r\n                TSSecondary.Close();\r\n            }\r\n        }\r\n\r\n        public byte[] ReadRaw()\r\n        {\r\n            byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), Production, PSVersion.Win7);\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n            return data;\r\n        }\r\n\r\n        public void WriteRaw(byte[] data)\r\n        {\r\n            byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, PSVersion.Win7);\r\n\r\n            TSPrimary.SetLength(encrData.LongLength);\r\n            TSSecondary.SetLength(encrData.LongLength);\r\n\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n            TSSecondary.Seek(0, SeekOrigin.Begin);\r\n\r\n            TSPrimary.WriteAllBytes(encrData);\r\n            TSSecondary.WriteAllBytes(encrData);\r\n\r\n            TSPrimary.Close();\r\n            TSSecondary.Close();\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(string valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.ValueAsStr.Contains(valueSearch))\r\n                {\r\n                    results.Add(new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = block.Key,\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    });\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(uint valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.ValueAsInt == valueSearch)\r\n                {\r\n                    results.Add(new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = block.Key,\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    });\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/VariableBag.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n\r\n    public enum CRCBlockType : uint\r\n    {\r\n        UINT = 1 << 0,\r\n        STRING = 1 << 1,\r\n        BINARY = 1 << 2\r\n    }\r\n\r\n    public abstract class CRCBlock\r\n    {\r\n        public CRCBlockType DataType;\r\n        public byte[] Key;\r\n        public string KeyAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Key);\r\n            }\r\n            set\r\n            {\r\n                Key = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public byte[] Value;\r\n        public string ValueAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Value);\r\n            }\r\n            set\r\n            {\r\n                Value = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint ValueAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Value, 0);\r\n            }\r\n            set\r\n            {\r\n                Value = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n\r\n        public abstract void Encode(BinaryWriter writer);\r\n        public abstract void Decode(BinaryReader reader);\r\n        public abstract uint CRC();\r\n    }\r\n\r\n    public class CRCBlockVista : CRCBlock\r\n    {\r\n        public override void Encode(BinaryWriter writer)\r\n        {\r\n            uint crc = CRC();\r\n            writer.Write((uint)DataType);\r\n            writer.Write(0);\r\n            writer.Write(Key.Length);\r\n            writer.Write(Value.Length);\r\n            writer.Write(crc);\r\n\r\n            writer.Write(Key);\r\n\r\n            writer.Write(Value);\r\n        }\r\n\r\n        public override void Decode(BinaryReader reader)\r\n        {\r\n            uint type = reader.ReadUInt32();\r\n            reader.ReadUInt32();\r\n            uint lenName = reader.ReadUInt32();\r\n            uint lenVal = reader.ReadUInt32();\r\n            uint crc = reader.ReadUInt32();\r\n\r\n            byte[] key = reader.ReadBytes((int)lenName);\r\n            byte[] value = reader.ReadBytes((int)lenVal);\r\n\r\n            DataType = (CRCBlockType)type;\r\n            Key = key;\r\n            Value = value;\r\n\r\n            if (CRC() != crc)\r\n            {\r\n                throw new InvalidDataException(\"Invalid CRC in variable bag.\");\r\n            }\r\n        }\r\n\r\n        public override uint CRC()\r\n        {\r\n            return Utils.CRC32(Value);\r\n        }\r\n    }\r\n\r\n    public class CRCBlockModern : CRCBlock\r\n    {\r\n        public override void Encode(BinaryWriter writer)\r\n        {\r\n            uint crc = CRC();\r\n            writer.Write(crc);\r\n            writer.Write((uint)DataType);\r\n            writer.Write(Key.Length);\r\n            writer.Write(Value.Length);\r\n\r\n            writer.Write(Key);\r\n            writer.Align(8);\r\n\r\n            writer.Write(Value);\r\n            writer.Align(8);\r\n        }\r\n\r\n        public override void Decode(BinaryReader reader)\r\n        {\r\n            uint crc = reader.ReadUInt32();\r\n            uint type = reader.ReadUInt32();\r\n            uint lenName = reader.ReadUInt32();\r\n            uint lenVal = reader.ReadUInt32();\r\n\r\n            byte[] key = reader.ReadBytes((int)lenName);\r\n            reader.Align(8);\r\n\r\n            byte[] value = reader.ReadBytes((int)lenVal);\r\n            reader.Align(8);\r\n\r\n            DataType = (CRCBlockType)type;\r\n            Key = key;\r\n            Value = value;\r\n\r\n            if (CRC() != crc)\r\n            {\r\n                throw new InvalidDataException(\"Invalid CRC in variable bag.\");\r\n            }\r\n        }\r\n\r\n        public override uint CRC()\r\n        {\r\n            BinaryWriter wtemp = new BinaryWriter(new MemoryStream());\r\n            wtemp.Write(0);\r\n            wtemp.Write((uint)DataType);\r\n            wtemp.Write(Key.Length);\r\n            wtemp.Write(Value.Length);\r\n            wtemp.Write(Key);\r\n            wtemp.Write(Value);\r\n            return Utils.CRC32(wtemp.GetBytes());\r\n        }\r\n    }\r\n\r\n    public class VariableBag\r\n    {\r\n        public List<CRCBlock> Blocks = new List<CRCBlock>();\r\n        private readonly PSVersion Version;\r\n\r\n        private void Deserialize(byte[] data)\r\n        {\r\n            int len = data.Length;\r\n\r\n            BinaryReader reader = new BinaryReader(new MemoryStream(data));\r\n\r\n            while (reader.BaseStream.Position < len - 0x10)\r\n            {\r\n                CRCBlock block;\r\n\r\n                if (Version == PSVersion.Vista)\r\n                {\r\n                    block = new CRCBlockVista();\r\n                }\r\n                else\r\n                {\r\n                    block = new CRCBlockModern();\r\n                }\r\n\r\n                block.Decode(reader);\r\n                Blocks.Add(block);\r\n            }\r\n        }\r\n\r\n        public byte[] Serialize()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n\r\n            foreach (CRCBlock block in Blocks)\r\n            {\r\n                if (Version == PSVersion.Vista)\r\n                {\r\n                    ((CRCBlockVista)block).Encode(writer);\r\n                } else\r\n                {\r\n                    ((CRCBlockModern)block).Encode(writer);\r\n                }\r\n            }\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public CRCBlock GetBlock(string key)\r\n        {\r\n            foreach (CRCBlock block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key)\r\n                {\r\n                    return block;\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public void SetBlock(string key, byte[] value)\r\n        {\r\n            for (int i = 0; i < Blocks.Count; i++)\r\n            {\r\n                CRCBlock block = Blocks[i];\r\n\r\n                if (block.KeyAsStr == key)\r\n                {\r\n                    block.Value = value;\r\n                    Blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void DeleteBlock(string key)\r\n        {\r\n            foreach (CRCBlock block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key)\r\n                {\r\n                    Blocks.Remove(block);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public VariableBag(byte[] data, PSVersion version)\r\n        {\r\n            Version = version;\r\n            Deserialize(data);\r\n        }\r\n\r\n        public VariableBag(PSVersion version)\r\n        {\r\n            Version = version;\r\n        }\r\n    }\r\n}\r\n'@\r\n$ErrorActionPreference = 'Stop'\r\n$binPath = \"$env:_work\\BIN\\LibTSforge.dll\"\r\n$psMajorVer = (Get-Host).Version.Major\r\n$build = [System.Environment]::OSVersion.Version.Build\r\n\r\nif (Test-Path -LiteralPath $binPath) {\r\n    Write-Host \"LibTSforge.dll found in BIN folder. Loading the DLL...\"\r\n    Add-Type -Path $binPath\r\n}\r\nelse {\r\n    $cp = [CodeDom.Compiler.CompilerParameters] [string[]]@(\"System.dll\", \"System.Core.dll\", \"System.ServiceProcess.dll\", \"System.Xml.dll\", \"System.Xml.Linq.dll\")\r\n    if ($psMajorVer -le 2) { $cp.CompilerOptions = \"/define:POWERSHELL2 /unsafe\" } else { $cp.CompilerOptions = \"/unsafe\" }\r\n    $lang = if ($psMajorVer -gt 2) { \"CSharp\" } else { \"CSharpVersion3\" }\r\n\r\n    $ctemp = \"$env:SystemRoot\\Temp\\\"\r\n    if (-Not (Test-Path -Path $ctemp)) { New-Item -Path $ctemp -ItemType Directory > $null }\r\n    $env:TMP = $ctemp\r\n    $env:TEMP = $ctemp\r\n\r\n    $cp.GenerateInMemory = $true\r\n    Add-Type -Language $lang -TypeDefinition $src -CompilerParameters $cp\r\n}\r\n\r\nif ($env:_debug -eq '0') {\r\n    [LibTSforge.Logger]::HideOutput = $true\r\n}\r\n[void][LibTSforge.Utils]::Wow64EnableWow64FsRedirection($false)\r\n$ver = [LibTSforge.Utils]::DetectVersion()\r\n$prod = [LibTSforge.SPP.SPPUtils]::DetectCurrentKey()\r\n$tsactids = @($args)\r\n\r\nfunction Get-WmiInfo {\r\n    param ([string]$tsactid, [string]$property)\r\n    \r\n    $query = \"SELECT ID, $property FROM SoftwareLicensingProduct WHERE ID='$tsactid'\"\r\n    $record = Get-WmiObject -Query $query\r\n    if ($record) {\r\n        return $record.$property\r\n    }\r\n}\r\n\r\nfunction slGetSkuInfo($SkuId) {\r\n    $t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)\r\n    $t.DefinePInvokeMethod('SLOpen', 'slc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n    $t.DefinePInvokeMethod('SLClose', 'slc.dll', 22, 1, [IntPtr], @([IntPtr]), 1, 3).SetImplementationFlags(128)\r\n    $t.DefinePInvokeMethod('SLGetProductSkuInformation', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n    $w = $t.CreateType()\r\n    $hSLC = 0\r\n    try {\r\n        [void]$w::SLOpen([ref]$hSLC)\r\n        $c = 0; $b = 0\r\n        $r = $w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, \"msft:sl/EUL/PHONE/PUBLIC\", [ref]$null, [ref]$c, [ref]$b)\r\n        return ($r -eq 0)\r\n    }\r\n    finally {\r\n        [void]$w::SLClose($hSLC)\r\n    }\r\n}\r\n\r\nif (-not $env:resetstuff) {\r\n    foreach ($tsactid in $tsactids) {\r\n        try {\r\n            $activated = $null\r\n            $prodDes = Get-WmiInfo -tsactid $tsactid -property \"Description\"\r\n            $prodName = Get-WmiInfo -tsactid $tsactid -property \"Name\"\r\n            if ($prodName) {\r\n                $nameParts = $prodName -split ',', 2\r\n                $prodName = if ($nameParts.Count -gt 1) { ($nameParts[1].Trim() -split '[ ,]')[0] } else { $null }\r\n            }\r\n            if (-not $env:_vis -and -not $env:oldks) {\r\n                [LibTSforge.Modifiers.GenPKeyInstall]::InstallGenPKey($ver, $prod, $tsactid)\r\n            }\r\n            if ($prodName -match 'Office' -and $prodDes -notmatch 'KMS' -and -not (slGetSkuInfo($tsactid))) {\r\n                $licenseStatus = Get-WmiInfo -tsactid $tsactid -property \"LicenseStatus\"\r\n                if ($licenseStatus -eq 1) {\r\n                    Write-Host \"[$prodName] is already permanently activated.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                    continue\r\n                }\r\n            }\r\n            if ($env:tsmethod -eq \"StaticCID\") {\r\n                [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\r\n                $attempts = @(\r\n                    @(100055, 1000043, 1338662172562478),\r\n                    @(1345, 1003020, 6311608238084405)\r\n                )\r\n                foreach ($params in $attempts) {\r\n                    [LibTSforge.Modifiers.SetIIDParams]::SetParams($ver, $prod, $tsactid, [LibTSforge.SPP.PKeyAlgorithm]::PKEY2009, $params[0], $params[1], $params[2])\r\n                    $instId = [LibTSforge.SPP.SLApi]::GetInstallationID($tsactid)\r\n                    $confId = [ActivationWs.ActivationHelper]::CallWebService(1, $instId, \"31337-42069-123-456789-04-1337-2600.0000-2542001\")\r\n                    $result = [LibTSforge.SPP.SLApi]::DepositConfirmationID($tsactid, $instId, $confId)\r\n                    if ($result -eq 0) { break }\r\n                }\r\n                [LibTSforge.SPP.SPPUtils]::RestartSPP($ver)\r\n            }\r\n            elseif ($env:tsmethod -eq \"KMS4k\") {\r\n                [LibTSforge.Activators.KMS4k]::Activate($ver, $prod, $tsactid)\r\n            }\r\n            else {\r\n                [LibTSforge.Activators.ZeroCID]::Activate($ver, $prod, $tsactid)\r\n            }\r\n            if ($env:tsmethod -eq \"KMS4k\") {\r\n                $GracePeriodStatus = Get-WmiInfo -tsactid $tsactid -property \"GracePeriodRemaining\"\r\n                if ($GracePeriodStatus -eq 259200 -or ([datetime]::Now.AddMinutes($GracePeriodStatus)).Year -gt 2038) {\r\n                    if ((($build -ge 26100 -and $GracePeriodStatus -ge 259200) -or \r\n                            ($build -lt 26100 -and $GracePeriodStatus -gt 259200))) {\r\n                        $activated = 1\r\n                    }\r\n                }\r\n            }\r\n            else {\r\n                $licenseStatus = Get-WmiInfo -tsactid $tsactid -property \"LicenseStatus\"\r\n                if ($licenseStatus -eq 1) { $activated = 1 }\r\n            }\r\n            if ($activated) {\r\n                if ($prodDes -match 'KMS' -and $prodDes -notmatch 'CLIENT') {\r\n                    [LibTSforge.Modifiers.KMSHostCharge]::Charge($ver, $prod, $tsactid)\r\n                    Write-Host \"[$prodName] CSVLK is permanently activated with $env:tsmethod.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                    Write-Host \"[$prodName] CSVLK is charged with 25 clients for 30 days.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                }\r\n                else {\r\n                    if ($env:tsmethod -eq \"KMS4k\") {\r\n                        if ($build -ge 26100) {\r\n                            Write-Host \"[$prodName] is activated with KMS4k for over 4,000 years.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                            Write-Host \"From build 26100.7019, Windows will always display and stay at 180 days remaining if the actual period is longer.\" -ForegroundColor White -BackgroundColor Darkgray\r\n                        }\r\n                        else {\r\n                            Write-Host \"[$prodName] is activated till $([DateTime]::Now.AddMinutes($GracePeriodStatus).ToString('yyyy-MM-dd HH:mm:ss')) with $env:tsmethod.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                        }\r\n                    }\r\n                    else {\r\n                        Write-Host \"[$prodName] is permanently activated with $env:tsmethod.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                    }\r\n                }\r\n            }\r\n            else {\r\n                Write-Host \"[$prodName] activation has failed.\" -ForegroundColor White -BackgroundColor DarkRed\r\n                $errcode = 3\r\n            }\r\n        }\r\n        catch {\r\n            $errcode = 3\r\n            Write-Host \"$($_.Exception.Message)\" -ForegroundColor Red -BackgroundColor Black\r\n            Write-Host \"[$prodName] activation has failed.\" -ForegroundColor White -BackgroundColor DarkRed\r\n        }\r\n    }\r\n}\r\n\r\nif ($env:resetstuff) {\r\n    try {\r\n        if (-not $env:_vis) { [LibTSforge.Modifiers.TamperedFlagsDelete]::DeleteTamperFlags($ver, $prod) }\r\n        [LibTSforge.SPP.SLApi]::RefreshLicenseStatus()\r\n        [LibTSforge.Modifiers.RearmReset]::Reset($ver, $prod)\r\n        [LibTSforge.Modifiers.GracePeriodReset]::Reset($ver, $prod)\r\n        if (-not $env:_vis) { [LibTSforge.Modifiers.KeyChangeLockDelete]::Delete($ver, $prod) }\r\n    }\r\n    catch {\r\n        $errcode = 3\r\n        Write-Host \"$($_.Exception.Message)\" -ForegroundColor Red -BackgroundColor Black\r\n    }\r\n}\r\n\r\nExit $errcode\r\n:tsforge:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get Windows Activation ID\r\n\r\n:wintsid:\r\n$SysPath = \"$env:SystemRoot\\System32\"\r\nif (Test-Path \"$env:SystemRoot\\Sysnative\\reg.exe\") {\r\n    $SysPath = \"$env:SystemRoot\\Sysnative\"\r\n}\r\n\r\nfunction Windows-ActID {\r\n    param (\r\n        [string]$edition,\r\n        [string]$keytype\r\n    )\r\n    \r\n    $filePatterns = @(\r\n        \"$SysPath\\spp\\tokens\\skus\\$edition\\$edition*.xrm-ms\",\r\n        \"$SysPath\\spp\\tokens\\skus\\Security-SPP-Component-SKU-$edition\\*-$edition-*.xrm-ms\"\r\n    )\r\n    \r\n    switch ($keytype) {\r\n        \"zero\" {\r\n            $licenseTypes = @('OEM_DM', 'OEM_COA_SLP', 'OEM_COA_NSLP', 'MAK', 'RETAIL')\r\n        }\r\n        \"ks\" {\r\n            $licenseTypes = @('KMSCLIENT')\r\n        }\r\n        \"avma\" {\r\n            $licenseTypes = @('VIRTUAL_MACHINE')\r\n        }\r\n        \"kmshost\" {\r\n            $licenseTypes = @('KMS_')\r\n        }\r\n    }\r\n    \r\n    $softwareLicensingProducts = Get-WmiObject -Query \"SELECT ID, Description, LicenseFamily FROM SoftwareLicensingProduct WHERE ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f'\" | Where-Object { $_.LicenseFamily -eq $edition }\r\n    \r\n    $orderedLicenses = @()\r\n    foreach ($type in $licenseTypes) {\r\n        $orderedLicenses += $softwareLicensingProducts | Where-Object { $_.Description -match $type } | Select-Object -ExpandProperty ID\r\n    }\r\n    \r\n    $fileIds = @()\r\n    $muiLockedIds = @()\r\n    $kmsCountedIdCounts = @{}\r\n\r\n    $t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)\r\n\r\n    $methods = @(\r\n        @{name = 'SLOpen'; returnType = [Int32]; parameters = @([IntPtr].MakeByRefType()) },\r\n        @{name = 'SLClose'; returnType = [Int32]; parameters = @([IntPtr]) },\r\n        @{name = 'SLGetProductSkuInformation'; returnType = [Int32]; parameters = @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()) },\r\n        @{name = 'SLGetLicense'; returnType = [Int32]; parameters = @([IntPtr], [Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()) }\r\n    )\r\n    \r\n    foreach ($method in $methods) {\r\n        $t.DefinePInvokeMethod($method.name, 'slc.dll', 22, 1, $method.returnType, $method.parameters, 1, 3).SetImplementationFlags(128)\r\n    }\r\n    \r\n    $w = $t.CreateType()\r\n    $m = [Runtime.InteropServices.Marshal]\r\n\r\n    function GetLicenseInfo($SkuId, $checkType) {\r\n        $result = $false\r\n        $c = 0; $b = 0\r\n        \r\n        [void]$w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, \"fileId\", [ref]$null, [ref]$c, [ref]$b)\r\n        $FileId = $m::PtrToStringUni($b)\r\n        \r\n        $c = 0; $b = 0\r\n        [void]$w::SLGetLicense($hSLC, [ref][Guid]$FileId, [ref]$c, [ref]$b)\r\n        $blob = New-Object byte[] $c; $m::Copy($b, $blob, 0, $c)\r\n        $cont = [Text.Encoding]::UTF8.GetString($blob)\r\n        $xml = [xml]$cont.SubString($cont.IndexOf('<r'))\r\n        \r\n        if ($checkType -eq 'MUI') {\r\n            $xml.licenseGroup.license[0].grant | foreach {\r\n                $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Kernel-MUI-Language-Allowed' } | foreach {\r\n                    if ($_.InnerText -ne 'EMPTY') { $result = $true }\r\n                }\r\n            }\r\n        }\r\n        elseif ($checkType -eq 'KMS') {\r\n            $xml.licenseGroup.license[0].grant | foreach {\r\n                $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Security-SPP-KmsCountedIdList' } | foreach {\r\n                    $result = ($_.InnerText.Replace(' ', '').Replace(\"`n\", '') -split ',').Count\r\n                }\r\n            }\r\n        }\r\n        \r\n        return $result\r\n    }\r\n\r\n    $hSLC = 0; [void]$w::SLOpen([ref]$hSLC)\r\n\r\n    foreach ($id in $orderedLicenses) {\r\n        if ($keytype -eq 'kmshost') {\r\n            $kmsCount = GetLicenseInfo $id 'KMS'\r\n            if ($kmsCount -gt 0) {\r\n                $kmsCountedIdCounts[$id] = $kmsCount\r\n            }\r\n        }\r\n        if ($edition -notcontains \"CountrySpecific\" -and (GetLicenseInfo $id 'MUI')) {\r\n            $muiLockedIds += $id\r\n        }\r\n    }\r\n    \r\n    foreach ($filePattern in $filePatterns) {\r\n        $files = Get-ChildItem -Path $filePattern -Filter '*.xrm-ms' -ErrorAction SilentlyContinue\r\n        foreach ($file in $files) {\r\n            if ($null -ne $file.FullName) {\r\n                $content = Get-Content -Path $file.FullName -ErrorAction SilentlyContinue | Out-String\r\n                foreach ($id in $orderedLicenses) {\r\n                    if ($content -match \"name=`\"productSkuId`\">\\{$id\\}\" -and -not ($file.Name -match 'Beta|Test')) {\r\n                        $fileIds += $id\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n    \r\n    if ($kmsCountedIdCounts.Count -gt 0) {\r\n        $idWithMostIds = $kmsCountedIdCounts.GetEnumerator() | Sort-Object Value -Descending\r\n        $fileIds = $idWithMostIds | Select-Object -ExpandProperty Key\r\n    }\r\n    else {\r\n        if ($fileIds.Count -eq 0) {\r\n            $fileIds = $orderedLicenses\r\n        }\r\n    \r\n        $fileIds = $orderedLicenses | Where-Object { $fileIds -contains $_ -and $muiLockedIds -notcontains $_ } | Select-Object -Unique\r\n    }\r\n    \r\n    [void]$w::SLClose($hSLC)\r\n    \r\n    $pkeyconfig = \"$SysPath\\spp\\tokens\\pkeyconfig\\pkeyconfig.xrm-ms\"\r\n    if ($keytype -eq 'kmshost') {\r\n        $csvlkPath = \"$SysPath\\spp\\tokens\\pkeyconfig\\pkeyconfig-csvlk.xrm-ms\"\r\n        if (Test-Path $csvlkPath) {\r\n            $pkeyconfig = $csvlkPath\r\n        }\r\n    }\r\n    \r\n    $data = [xml][Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(([xml](get-content $pkeyconfig)).licenseGroup.license.otherInfo.infoTables.infoList.infoBin.InnerText))\r\n    \r\n    $betaIds = @()\r\n    $excludedIds = @()\r\n    $checkedIds = @()\r\n    \r\n    foreach ($id in $fileIds) {\r\n        $actConfig = $data.ProductKeyConfiguration.Configurations.Configuration | Where-Object { $_.ActConfigId -eq \"{$id}\" }\r\n        if ($actConfig) {\r\n            $productDescription = $actConfig.ProductDescription\r\n            $productEditionID = $actConfig.EditionID\r\n            if ($productDescription -match 'MUI locked|Tencent|Qihoo|WAU') {\r\n                $excludedIds += $id\r\n                continue\r\n            }\r\n    \r\n            if ($productDescription -match 'Beta|RC |Next |Test|Pre-') {\r\n                $betaIds += $id\r\n                continue\r\n            }\r\n    \r\n            if ($keytype -ne 'kmshost' -and $productEditionID -eq '$edition') {\r\n                $checkedIds += $id\r\n                continue\r\n            }\r\n    \r\n            $refGroupId = $actConfig.RefGroupId\r\n            $publicKey = $data.ProductKeyConfiguration.PublicKeys.PublicKey | Where-Object { $_.GroupId -eq $refGroupId -and $_.AlgorithmId -eq 'msft:rm/algorithm/pkey/2009' }\r\n            if ($publicKey) {\r\n                $keyRanges = $data.ProductKeyConfiguration.KeyRanges.KeyRange | Where-Object { $_.RefActConfigId -eq \"{$id}\" }\r\n                foreach ($keyRange in $keyRanges) {\r\n                    if ($keyRange.EulaType -match 'WAU') {\r\n                        $excludedIds += $id\r\n                        break\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n    \r\n    $prefinalIds = @()\r\n    $finalIds = @()\r\n    \r\n    $prefinalIds = $fileIds | Where-Object { $excludedIds -notcontains $_ } | Select-Object -Unique\r\n    $finalIds = $prefinalIds | Where-Object { $betaIds -notcontains $_ } | Select-Object -Unique\r\n    \r\n    if ($finalIds.Count -eq 0) {\r\n        $finalIds = $prefinalIds\r\n    }\r\n    \r\n    if ($checkedIds.Count -gt 0) {\r\n        $finalIds = $checkedIds + $finalIds\r\n    }\r\n    \r\n    $firstId = $finalIds | Select-Object -First 1\r\n    return $firstId.ToLower()\r\n}\r\n\r\nWindows-ActID -edition \"$env:tsedition\" -keytype \"$env:keytype\"\r\n:wintsid:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get Office Activation ID\r\n\r\n:offtsid:\r\nfunction Office-ActID {\r\n    param (\r\n        [string]$pkeypath,\r\n        [string]$edition,\r\n        [string]$keytype\r\n    )\r\n\r\n    switch ($keytype) {\r\n        \"zero\" { $productKeyTypes = @(\"OEM:NONSLP\",\"Volume:MAK\",\"Retail\") }\r\n        \"ks\" { $productKeyTypes = @(\"Volume:GVLK\") }\r\n    }\r\n\r\n    $data = [xml][Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(([xml](Get-Content $pkeypath)).licenseGroup.license.otherInfo.infoTables.infoList.infoBin.InnerText))\r\n    $configurations = $data.ProductKeyConfiguration.Configurations.Configuration\r\n\r\n    $filteredConfigs = @()\r\n    foreach ($type in $productKeyTypes) {\r\n        $filteredConfigs += $configurations | Where-Object { \r\n            $_.EditionId -eq $edition -and \r\n            $_.ProductKeyType -eq $type -and \r\n            $_.ProductDescription -notmatch 'demo|MSDN|PIN'\r\n        }\r\n    }\r\n\r\n    $filterPreview = $filteredConfigs | Where-Object { $_.ProductDescription -notmatch 'preview|c2r' }\r\n\r\n    if ($filterPreview.Count -ne 0) {\r\n        $filteredConfigs = $filterPreview\r\n    } \r\n\r\n    $firstConfig = ($filteredConfigs | Select-Object -First 1).ActConfigID -replace '^\\{|\\}$', ''\r\n    return $firstConfig.ToLower()\r\n}\r\n\r\nOffice-ActID -pkeypath \"$env:pkeypath\" -edition \"$env:_License\" -keytype \"$env:keytype\"\r\n:offtsid:\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Office version\r\n::  2nd column = Volume or free retail product\r\n::  3rd column = Retail product names that needs to be converted to the Volume product mentioned in 2nd column\r\n::  Separator  = \"_\"\r\n\r\n:tsksdata\r\n\r\nset f=\r\nfor %%# in (\r\n:: Office 2013\r\n15_AccessVolume_-AccessRetail-\r\n15_AccessRuntimeRetail\r\n15_ExcelVolume_-ExcelRetail-\r\n15_GrooveVolume_-GrooveRetail-\r\n15_InfoPathVolume_-InfoPathRetail-\r\n15_LyncAcademicRetail\r\n15_LyncEntryRetail\r\n15_LyncVolume_-LyncRetail-\r\n15_MondoRetail\r\n15_MondoVolume_-O365BusinessRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-\r\n15_OneNoteFreeRetail\r\n15_OneNoteVolume_-OneNoteRetail-\r\n15_OutlookVolume_-OutlookRetail-\r\n15_PowerPointVolume_-PowerPointRetail-\r\n15_ProjectProVolume_-ProjectProRetail-\r\n15_ProjectStdVolume_-ProjectStdRetail-\r\n15_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-\r\n15_PublisherVolume_-PublisherRetail-\r\n15_SPDRetail\r\n15_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-PersonalPipcRetail-PersonalRetail-\r\n15_VisioProVolume_-VisioProRetail-\r\n15_VisioStdVolume_-VisioStdRetail-\r\n15_WordVolume_-WordRetail-\r\n:: Office 2016\r\n16_AccessRuntimeRetail\r\n16_AccessVolume_-AccessRetail-\r\n16_ExcelVolume_-ExcelRetail-\r\n16_MondoRetail\r\n16_MondoVolume_-O365AppsBasicRetail-O365BusinessRetail-O365EduCloudRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-\r\n16_OneNoteFreeRetail\r\n16_OneNoteVolume_-OneNoteRetail-OneNote2021Retail-\r\n16_OutlookVolume_-OutlookRetail-\r\n16_PowerPointVolume_-PowerPointRetail-\r\n16_ProjectProVolume_-ProjectProRetail-\r\n16_ProjectProXVolume\r\n16_ProjectStdVolume_-ProjectStdRetail-\r\n16_ProjectStdXVolume\r\n16_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-\r\n16_PublisherVolume_-PublisherRetail-\r\n16_SkypeServiceBypassRetail\r\n16_SkypeforBusinessEntryRetail\r\n16_SkypeforBusinessVolume_-SkypeforBusinessRetail-\r\n16_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-HomeStudentVNextRetail-PersonalPipcRetail-PersonalRetail-\r\n16_VisioProVolume_-VisioProRetail-\r\n16_VisioProXVolume\r\n16_VisioStdVolume_-VisioStdRetail-\r\n16_VisioStdXVolume\r\n16_WordVolume_-WordRetail-\r\n:: Office 2019\r\n16_AccessRuntime2019Retail\r\n16_Access2019Volume_-Access2019Retail-\r\n16_Excel2019Volume_-Excel2019Retail-\r\n16_Outlook2019Volume_-Outlook2019Retail-\r\n16_PowerPoint2019Volume_-PowerPoint2019Retail-\r\n16_ProjectPro2019Volume_-ProjectPro2019Retail-\r\n16_ProjectStd2019Volume_-ProjectStd2019Retail-\r\n16_ProPlus2019Volume_-ProPlus2019Retail-Professional2019Retail-\r\n16_Publisher2019Volume_-Publisher2019Retail-\r\n16_SkypeforBusiness2019Volume_-SkypeforBusiness2019Retail-\r\n16_SkypeforBusinessEntry2019Retail\r\n16_Standard2019Volume_-Standard2019Retail-HomeBusiness2019Retail-HomeStudentARM2019Retail-HomeStudentPlusARM2019Retail-HomeStudent2019Retail-Personal2019Retail-\r\n16_VisioPro2019Volume_-VisioPro2019Retail-\r\n16_VisioStd2019Volume_-VisioStd2019Retail-\r\n16_Word2019Volume_-Word2019Retail-\r\n:: Office 2021\r\n:: OneNote2021Volume KMS license is not available\r\n16_AccessRuntime2021Retail\r\n16_Access2021Volume_-Access2021Retail-\r\n16_Excel2021Volume_-Excel2021Retail-\r\n16_Outlook2021Volume_-Outlook2021Retail-\r\n16_OneNoteFree2021Retail\r\n16_PowerPoint2021Volume_-PowerPoint2021Retail-\r\n16_ProjectPro2021Volume_-ProjectPro2021Retail-\r\n16_ProjectStd2021Volume_-ProjectStd2021Retail-\r\n16_ProPlus2021Volume_-ProPlus2021Retail-Professional2021Retail-\r\n16_Publisher2021Volume_-Publisher2021Retail-\r\n16_SkypeforBusiness2021Volume_-SkypeforBusiness2021Retail-\r\n16_Standard2021Volume_-Standard2021Retail-HomeBusiness2021Retail-HomeStudent2021Retail-Personal2021Retail-\r\n16_VisioPro2021Volume_-VisioPro2021Retail-\r\n16_VisioStd2021Volume_-VisioStd2021Retail-\r\n16_Word2021Volume_-Word2021Retail-\r\n:: Office 2024\r\n16_Access2024Volume_-Access2024Retail-\r\n16_Excel2024Volume_-Excel2024Retail-\r\n16_Outlook2024Volume_-Outlook2024Retail-\r\n16_PowerPoint2024Volume_-PowerPoint2024Retail-\r\n16_ProjectPro2024Volume_-ProjectPro2024Retail-\r\n16_ProjectStd2024Volume_-ProjectStd2024Retail-\r\n16_ProPlus2024Volume_-ProPlus2024Retail-\r\n16_SkypeforBusiness2024Volume\r\n16_Standard2024Volume_-Home2024Retail-HomeBusiness2024Retail-\r\n16_VisioPro2024Volume_-VisioPro2024Retail-\r\n16_VisioStd2024Volume_-VisioStd2024Retail-\r\n16_Word2024Volume_-Word2024Retail-\r\n) do (\r\nfor /f \"tokens=1-3 delims=_\" %%A in (\"%%#\") do (\r\n\r\nif %1==chkprod if \"%oVer%\"==\"%%A\" if not defined foundprod (\r\nif /i \"%%B\"==\"%2\" set foundprod=1\r\n)\r\n\r\nif %1==getinfo if \"%oVer%\"==\"%%A\" (\r\necho: %%C | find /i \"-%2-\" %nul% && (\r\nset _License=%%B\r\nset _altoffid=%%B\r\n)\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_getedition\r\n\r\nset tsedition=\r\nset _wtarget=\r\n\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do if not errorlevel 1 call set \"_wtarget= !_wtarget! %%a \"\r\n\r\n::  SKU and Edition ID database\r\n\r\nfor %%# in (\r\n1:Ultimate\r\n2:HomeBasic\r\n3:HomePremium\r\n4:Enterprise\r\n5:HomeBasicN\r\n6:Business\r\n7:ServerStandard\r\n8:ServerDatacenter\r\n9:ServerSBSStandard\r\n10:ServerEnterprise\r\n11:Starter\r\n12:ServerDatacenterCore\r\n13:ServerStandardCore\r\n14:ServerEnterpriseCore\r\n15:ServerEnterpriseIA64\r\n16:BusinessN\r\n17:ServerWeb\r\n18:ServerHPC\r\n19:ServerHomeStandard\r\n20:ServerStorageExpress\r\n21:ServerStorageStandard\r\n22:ServerStorageWorkgroup\r\n23:ServerStorageEnterprise\r\n24:ServerWinSB\r\n25:ServerSBSPremium\r\n26:HomePremiumN\r\n27:EnterpriseN\r\n28:UltimateN\r\n29:ServerWebCore\r\n30:ServerMediumBusinessManagement\r\n31:ServerMediumBusinessSecurity\r\n32:ServerMediumBusinessMessaging\r\n33:ServerWinFoundation\r\n34:ServerHomePremium\r\n35:ServerWinSBV\r\n36:ServerStandardV\r\n37:ServerDatacenterV\r\n38:ServerEnterpriseV\r\n39:ServerDatacenterVCore\r\n40:ServerStandardVCore\r\n41:ServerEnterpriseVCore\r\n42:ServerHyperCore\r\n43:ServerStorageExpressCore\r\n44:ServerStorageStandardCore\r\n45:ServerStorageWorkgroupCore\r\n46:ServerStorageEnterpriseCore\r\n47:StarterN\r\n48:Professional\r\n49:ProfessionalN\r\n50:ServerSolution\r\n51:ServerForSBSolutions\r\n52:ServerSolutionsPremium\r\n53:ServerSolutionsPremiumCore\r\n54:ServerSolutionEM\r\n55:ServerForSBSolutionsEM\r\n56:ServerEmbeddedSolution\r\n57:ServerEmbeddedSolutionCore\r\n58:ProfessionalEmbedded\r\n59:ServerEssentialManagement\r\n60:ServerEssentialAdditional\r\n61:ServerEssentialManagementSvc\r\n62:ServerEssentialAdditionalSvc\r\n63:ServerSBSPremiumCore\r\n64:ServerHPCV\r\n65:Embedded\r\n66:StarterE\r\n67:HomeBasicE\r\n68:HomePremiumE\r\n69:ProfessionalE\r\n70:EnterpriseE\r\n71:UltimateE\r\n72:EnterpriseEval\r\n74:Prerelease\r\n76:ServerMultiPointStandard\r\n77:ServerMultiPointPremium\r\n79:ServerStandardEval\r\n80:ServerDatacenterEval\r\n81:PrereleaseARM\r\n82:PrereleaseN\r\n84:EnterpriseNEval\r\n85:EmbeddedAutomotive\r\n86:EmbeddedIndustryA\r\n87:ThinPC\r\n88:EmbeddedA\r\n89:EmbeddedIndustry\r\n90:EmbeddedE\r\n91:EmbeddedIndustryE\r\n92:EmbeddedIndustryAE\r\n93:ProfessionalPlus\r\n95:ServerStorageWorkgroupEval\r\n96:ServerStorageStandardEval\r\n97:CoreARM\r\n98:CoreN\r\n99:CoreCountrySpecific\r\n100:CoreSingleLanguage\r\n101:Core\r\n103:ProfessionalWMC\r\n104:MobileCore\r\n105:EmbeddedIndustryEval\r\n106:EmbeddedIndustryEEval\r\n107:EmbeddedEval\r\n108:EmbeddedEEval\r\n109:CoreSystemServer\r\n110:ServerCloudStorage\r\n111:CoreConnected\r\n112:ProfessionalStudent\r\n113:CoreConnectedN\r\n114:ProfessionalStudentN\r\n115:CoreConnectedSingleLanguage\r\n116:CoreConnectedCountrySpecific\r\n117:ConnectedCar\r\n118:IndustryHandheld\r\n119:PPIPRO\r\n120:ServerARM64\r\n121:Education\r\n122:EducationN\r\n123:IoTUAP\r\n124:ServerHI\r\n125:EnterpriseS\r\n126:EnterpriseSN\r\n127:ProfessionalS\r\n128:ProfessionalSN\r\n129:EnterpriseSEval\r\n130:EnterpriseSNEval\r\n131:IoTUAPCommercial\r\n133:MobileEnterprise\r\n134:AnalogOneCoreEnterprise\r\n135:AnalogOneCore\r\n136:Holographic\r\n138:ProfessionalSingleLanguage\r\n139:ProfessionalCountrySpecific\r\n140:EnterpriseSubscription\r\n141:EnterpriseSubscriptionN\r\n143:ServerDatacenterNano\r\n144:ServerStandardNano\r\n145:ServerDatacenterACor\r\n146:ServerStandardACor\r\n147:ServerDatacenterCor\r\n148:ServerStandardCor\r\n149:UtilityVM\r\n159:ServerDatacenterEvalCor\r\n160:ServerStandardEvalCor\r\n161:ProfessionalWorkstation\r\n162:ProfessionalWorkstationN\r\n163:ServerAzure\r\n164:ProfessionalEducation\r\n165:ProfessionalEducationN\r\n168:ServerAzureCor\r\n169:ServerAzureNano\r\n171:EnterpriseG\r\n172:EnterpriseGN\r\n173:BusinessSubscription\r\n174:BusinessSubscriptionN\r\n175:ServerRdsh\r\n178:Cloud\r\n179:CloudN\r\n180:HubOS\r\n182:OneCoreUpdateOS\r\n183:CloudE\r\n184:Andromeda\r\n185:IoTOS\r\n186:CloudEN\r\n187:IoTEdgeOS\r\n188:IoTEnterprise\r\n189:ModernPC\r\n191:IoTEnterpriseS\r\n192:SystemOS\r\n193:NativeOS\r\n194:GameCoreXbox\r\n195:GameOS\r\n196:DurangoHostOS\r\n197:ScarlettHostOS\r\n198:Keystone\r\n199:CloudHost\r\n200:CloudMOS\r\n201:CloudCore\r\n202:CloudEditionN\r\n203:CloudEdition\r\n204:WinVOS\r\n205:IoTEnterpriseSK\r\n206:IoTEnterpriseK\r\n207:IoTEnterpriseSEval\r\n208:AgentBridge\r\n209:NanoHost\r\n210:WNC\r\n406:ServerAzureStackHCICor\r\n407:ServerTurbine\r\n408:ServerTurbineCor\r\n\r\nREM Some old edition names with same SKU ID\r\n\r\n4:ProEnterprise\r\n6:ProStandard\r\n10:ProSBS\r\n16:ProStandardN\r\n18:ServerComputeCluster\r\n19:ServerHome\r\n30:ServerMidmarketStandard\r\n31:ServerMidmarketEdge\r\n32:ServerMidmarketPremium\r\n33:ServerSBSPrime\r\n42:ServerHyper\r\n64:ServerComputeClusterV\r\n85:EmbeddedIapetus\r\n86:EmbeddedTethys\r\n88:EmbeddedDione\r\n89:EmbeddedRhea\r\n90:EmbeddedEnceladus\r\n109:ServerNano\r\n124:ServerCloudHostInfrastructure\r\n133:MobileBusiness\r\n134:HololensEnterprise\r\n145:ServerDatacenterSCor\r\n146:ServerStandardSCor\r\n147:ServerDatacenterWSCor\r\n148:ServerStandardWSCor\r\n189:Lite\r\n) do (\r\nfor /f \"tokens=1-2 delims=:\" %%A in (\"%%#\") do if \"%osSKU%\"==\"%%A\" if not defined tsedition (\r\necho \"%_wtarget%\" | find /i \" %%B \" %nul% && set tsedition=%%B\r\n)\r\n)\r\n\r\nif defined tsedition exit /b\r\n\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionNameFromId', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [IntPtr].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionNameFromId(%osSKU%, [ref]$out);$s=[Runtime.InteropServices.Marshal]::PtrToStringUni($out); $s\r\n\r\nfor %%# in (pkeyhelper.dll) do @if not \"%%~$PATH:#\"==\"\" (\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (\r\necho \"%_wtarget%\" | find /i \" %%a \" %nul% && set tsedition=%%a\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n\r\n:KMSActivation\r\n\r\n::  To activate Windows with K-M-S activation, run the script with \"/K-Windows\" parameter or change 0 to 1 in below line\r\nset _actwin=0\r\n\r\n::  To activate all Office apps (including Project/Visio) with K-M-S activation, run the script with \"/K-Office\" parameter or change 0 to 1 in below line\r\nset _actoff=0\r\n\r\n::  To activate only Project/Visio with K-M-S activation, run the script with \"/K-ProjectVisio\" parameter or change 0 to 1 in below line\r\nset _actprojvis=0\r\n\r\n::  To activate all Windows/Office with K-M-S activation, run the script with \"/K-WindowsOffice\" parameter or change 0 to 1 in below line\r\nset _actwinoff=0\r\n\r\n::  To disable changing Windows/Office edition if current edition doesn't support K-M-S activation, run the script with \"/K-NoEditionChange\" parameter or change 0 to 1 in below line\r\nset _NoEditionChange=0\r\n\r\n::  To NOT auto-install renewal task with activation, run the script with \"/K-NoRenewalTask\" parameter or change 0 to 1 in below line\r\nset _norentsk=0\r\n\r\n::  To uninstall K-M-S, run the script with \"/K-Uninstall\" parameter or change 0 to 1 in below line. It'll take preference over any other parameter.\r\nset _uni=0\r\n\r\n::  Advanced options:\r\n::  Don't use renewal task option if you are going to use a specific server name instead of public servers used in the script\r\n\r\n::  To specify a server address for activation, run the script with \"/K-Server-YOURKMSSERVERNAME\" parameter or add it in below line after = sign\r\nset _server=\r\n\r\n::  To specify a port for activation, run the script with \"/K-Port-YOURPORTNAME\" parameter or add it in below line after = sign\r\nset _port=\r\n\r\n::  Script will run in unattended mode if parameters are used OR value is changed in above lines FOR activation or uninstall.\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\nset KS=K%blank%MS\r\ntitle  Online %KS% Activation %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args for %%A in (%_args%) do (\r\nif /i \"%%A\"==\"-el\"                        (set _elev=1)\r\nif /i \"%%A\"==\"/K-Windows\"                 (set _actwin=1)\r\nif /i \"%%A\"==\"/K-Office\"                  (set _actoff=1)\r\nif /i \"%%A\"==\"/K-ProjectVisio\"            (set _actprojvis=1)\r\nif /i \"%%A\"==\"/K-WindowsOffice\"           (set _actwinoff=1)\r\nif /i \"%%A\"==\"/K-NoEditionChange\"         (set _NoEditionChange=1)\r\nif /i \"%%A\"==\"/K-NoRenewalTask\"           (set _norentsk=1)\r\nif /i \"%%A\"==\"/K-Uninstall\"               (set _uni=1)\r\necho \"%%A\" | find /i \"/K-Port-\"   >nul && (set \"_port=%%A\"   & call set \"_port=%%_port:~8%%\")\r\necho \"%%A\" | find /i \"/K-Server-\" >nul && (set \"_server=%%A\" & call set \"_server=%%_server:~10%%\")\r\n)\r\n\r\nfor %%A in (%_actwin% %_actoff% %_actprojvis% %_actwinoff% %_uni%) do (if \"%%A\"==\"1\" set _unattended=1)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_uni%==1 goto :ks_uninstall\r\n\r\n:ks_menu\r\n\r\nif defined _server set _norentsk=1\r\nif not defined _server set _port=\r\n\r\nif %_unattended%==0 (\r\ncls\r\nif not defined terminal mode 76, 30\r\ntitle  Online %KS% Activation %masver%\r\n\r\necho:\r\necho:\r\necho:\r\necho:\r\nif exist \"%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd\" (\r\nfind /i \"Ver:2.7\" \"%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd\" %nul% || (\r\ncall :dk_color %_Yellow% \"              Old renewal task found, run activation to update it.\"\r\n)\r\n)\r\necho        ______________________________________________________________\r\necho: \r\necho               [1] Activate - Windows\r\necho               [2] Activate - Office [All]\r\necho               [3] Activate - Office [Project/Visio]\r\necho               [4] Activate - All\r\necho               _______________________________________________  \r\necho: \r\nif %_norentsk%==0 (\r\necho               [5] Renewal Task With Activation       [Yes]\r\n) else (\r\ncall :dk_color2 %_White% \"              [5] Renewal Task With Activation        \" %_Yellow% \"[No]\"\r\n)\r\nif %_NoEditionChange%==0 (\r\necho               [6] Change Edition If Needed           [Yes]\r\n) else (\r\ncall :dk_color2 %_White% \"              [6] Change Edition If Needed            \" %_Yellow% \"[No]\"\r\n)\r\necho               [7] Uninstall Online %KS%\r\necho               _______________________________________________       \r\necho:\r\nif defined _server (\r\necho               [8] Set %KS% Server/Port [%_server%] [%_port%]\r\n) else (\r\necho               [8] Set %KS% Server/Port\r\n)\r\necho               [9] Download Office\r\necho               [0] %_exitmsg%\r\necho        ______________________________________________________________\r\necho:\r\ncall :dk_color2 %_White% \"       \" %_Green% \"Choose a menu option using your keyboard [1,2,3,4,5,6,7,8,9,0]\"\r\nchoice /C:1234567890 /N\r\nset _el=!errorlevel!\r\n\r\nif !_el!==10 exit /b\r\nif !_el!==9 start %mas%genuine-installation-media & goto :ks_menu\r\nif !_el!==8 goto :ks_ip\r\nif !_el!==7 cls & call :ks_uninstall & cls & goto :ks_menu\r\nif !_el!==6 (if %_NoEditionChange%==0 (set _NoEditionChange=1) else (set _NoEditionChange=0)) & goto :ks_menu\r\nif !_el!==5 (if %_norentsk%==0 (set _norentsk=1) else (set _norentsk=0)) & goto :ks_menu\r\nif !_el!==4 cls & setlocal & set \"_actwin=1\" & set \"_actoff=1\" & set \"_actprojvis=0\" & call :ks_start & endlocal & cls & goto :ks_menu\r\nif !_el!==3 cls & setlocal & set \"_actwin=0\" & set \"_actoff=0\" & set \"_actprojvis=1\" & call :ks_start & endlocal & cls & goto :ks_menu\r\nif !_el!==2 cls & setlocal & set \"_actwin=0\" & set \"_actoff=1\" & set \"_actprojvis=0\" & call :ks_start & endlocal & cls & goto :ks_menu\r\nif !_el!==1 cls & setlocal & set \"_actwin=1\" & set \"_actoff=0\" & set \"_actprojvis=0\" & call :ks_start & endlocal & cls & goto :ks_menu\r\ngoto :ks_menu\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_start\r\n\r\ncls\r\nif not defined terminal (\r\nmode 115, 32\r\nif exist \"%SysPath%\\spp\\store_test\\\" mode 135, 32\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=32;$B.Height=300;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\ntitle  Online %KS% Activation %masver%\r\n\r\necho:\r\necho Initializing...\r\ncall :dk_chkmal\r\n\r\nif not exist %SysPath%\\%_slexe% (\r\n%eline%\r\necho [%SysPath%\\%_slexe%] file is missing, aborting...\r\necho:\r\nif not defined results (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options.\"\r\ncall :dk_color %Blue% \"After that, restart system and try activation again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If it still shows the same error, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_actprojvis%==1 (set \"_actoff=1\")\r\nif %_actwinoff%==1 (set \"_actwin=1\" & set \"_actoff=1\")\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_ckeckwmic\r\ncall :dk_checksku\r\ncall :dk_product\r\ncall :dk_sppissue\r\n\r\n::========================================================================================================================================\r\n\r\nset error=\r\n\r\ncls\r\necho:\r\ncall :dk_showosinfo\r\n\r\n::  Check Internet connection\r\n\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)\r\n)\r\n\r\nif defined _int (\r\necho Checking Internet Connection            [Connected%ping_f%]\r\n) else (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Internet Connection            [Not Connected]\"\r\ncall :dk_color %Blue% \"Internet is required for Online %KS% Activation.\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\necho Initiating Diagnostic Tests...\r\n\r\nset \"_serv=%_slser% Winmgmt\"\r\n\r\n::  Software Protection\r\n::  Windows Management Instrumentation\r\n\r\nif %_actwin%==0 set notwinact=1\r\ncall :dk_errorcheck\r\n\r\n::========================================================================================================================================\r\n\r\ncall :_taskclear-cache\r\ncall :_tasksetserv\r\n\r\nif not %_actwin%==1 goto :ks_office\r\n\r\n::  Process Windows\r\n::  Check if system is permanently activated or not\r\n\r\necho:\r\necho Processing Windows...\r\ncall :dk_checkperm\r\nif defined _perm (\r\ncall :dk_color %Gray% \"Checking OS Activation                  [Windows is already permanently activated]\"\r\ngoto :ks_office\r\n)\r\n\r\n::  Check Evaluation version\r\n\r\nset _eval=\r\nset _evalserv=\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" set _eval=1\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*EvalEdition~*.mum\" set _evalserv=1\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*EvalCorEdition~*.mum\" set _eval=1 & set _evalserv=1\r\n\r\nif defined _eval (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Eval\" %nul1% && (\r\ncall :dk_color %Red% \"Checking Evaluation Edition             [Evaluation editions cannot be activated outside of evaluation period.]\"\r\n\r\nif defined _evalserv (\r\ncall :dk_color %Blue% \"Go back to main menu and use [Change Edition] option.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu to reset evaluation period.\"\r\nset fixes=%fixes% %mas%evaluation_editions\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%evaluation_editions\"\r\n)\r\n\r\ngoto :ks_office\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check if GVLK is already installed or not\r\n\r\ncall :k_channel\r\n\r\n::  Detect Key\r\n\r\nset key=\r\nset pkey=\r\nset altkey=\r\nset changekey=\r\nset altedition=\r\n\r\ncall :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\nif defined allapps call :ksdata winkey\r\nif not defined key call :k_gvlk %nul%\r\nif defined allapps if not defined key call :kmsfallback\r\n\r\nif defined altkey (set key=%altkey%&set changekey=1)\r\n\r\nset /a UBR=0\r\nif %osSKU%==191 if defined altkey if defined altedition (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR %nul6%') do if not errorlevel 1 set /a UBR=%%b\r\nif %winbuild% LSS 22598 if !UBR! LSS 2788 (\r\ncall :dk_color %Blue% \"Windows must be updated to build 19044.2788 or higher for IotEnterpriseS %KS% activation.\"\r\n)\r\n)\r\n\r\nif not defined key if defined notfoundaltactID (\r\ncall :dk_color %Red% \"Checking Alternate Edition For %KS%      [%altedition% Activation ID Not Found]\"\r\n)\r\n\r\nif not defined key if not defined _gvlk (\r\necho [%winos% ^| %winbuild% ^| SKU:%osSKU%]\r\n\r\nif %winbuild% GEQ 9200 if exist \"%SysPath%\\spp\\tokens\\skus\\%osedition%\\*GVLK*.xrm-ms\" set sppks=1\r\nif %winbuild% LSS 9200 if exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-%osedition%\\*VLKMS*.xrm-ms\" set sppks=1\r\nif %winbuild% LSS 9200 if exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-%osedition%\\*VL-BYPASS*.xrm-ms\" set sppks=1\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\licensing\\skus\\Security-Licensing-SLC-Component-SKU-%osedition%\\*KMS*.xrm-ms\" set sppks=1\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\licensing\\skus\\Security-Licensing-SLC-Component-SKU-%osedition%\\*VL-BYPASS*.xrm-ms\" set sppks=1\r\n\r\nif defined skunotfound (\r\ncall :dk_color %Red% \"Required license files not found.\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\nif defined sppks (\r\ncall :dk_color %Red% \"%KS% activation is supported but failed to find the %KS% key.\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\nif not defined skunotfound if not defined sppks (\r\ncall :dk_color %Red% \"This product does not support %KS% activation.\"\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu.\"\r\n)\r\necho:\r\ngoto :ks_office\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Install key\r\n\r\nif defined changekey (\r\ncall :dk_color %Blue% \"[%altedition%] edition product key will be used to enable %KS% activation.\"\r\necho:\r\n)\r\n\r\nif defined winsub (\r\ncall :dk_color %Blue% \"Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%].\"\r\necho:\r\n)\r\n\r\nset _partial=\r\nif not defined key (\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%# in ('wmic path %spp% where \"ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' and PartialProductKey<>null AND LicenseDependsOn is NULL\" Get PartialProductKey /value %nul6%') do set \"_partial=%%#\"\r\nif %_wmic% EQU 0 for /f \"tokens=2 delims==\" %%# in ('%psc% \"(([WMISEARCHER]'SELECT PartialProductKey FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).PartialProductKey | %% {echo ('PartialProductKey='+$_)}\" %nul6%') do set \"_partial=%%#\"\r\ncall echo Checking Installed Product Key          [Partial Key - %%_partial%%] [Volume:GVLK]\r\n)\r\n\r\nif defined key (\r\nset generickey=1\r\ncall :dk_inskey \"[%key%]\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_office\r\n\r\nif not %_actoff%==1 goto :ks_activate\r\n\r\ncall :oh_setspp\r\n\r\n::  Check ohook install\r\n\r\nset ohook=\r\nfor %%# in (15 16) do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft Office\\Office%%#\\sppc*dll\" set ohook=1\r\n)\r\n)\r\n\r\nfor %%# in (System SystemX86) do (\r\nfor %%G in (\"Office 15\" \"Office\") do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft %%~G\\root\\vfs\\%%#\\sppc*dll\" set ohook=1\r\n)\r\n)\r\n)\r\n\r\nif defined ohook (\r\necho:\r\ncall :dk_color %Gray% \"Checking Ohook                          [Ohook activation is already installed for Office]\"\r\n)\r\n\r\n::  Check unsupported office versions\r\n\r\nset o14c2r=\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n%nul% reg query %_68%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n%nul% reg query %_86%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n\r\nif not \"%o14c2r%\"==\"\" (\r\necho:\r\ncall :dk_color %Red% \"Checking Unsupported Office Install     [ %o14c2r%]\"\r\n)\r\n\r\nif %winbuild% GEQ 10240 %psc% \"Get-AppxPackage -name \"Microsoft.MicrosoftOfficeHub\"\" | find /i \"Office\" %nul1% && (\r\nset ohub=1\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check supported office versions\r\n\r\ncall :oh_getpath\r\n\r\nset o16uwp=\r\nset o16uwp_path=\r\n\r\nif %winbuild% GEQ 10240 (\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty InstallLocation)\" %nul6%') do (if exist \"%%a\\Integration\\Integrator.exe\" (set o16uwp=1&set \"o16uwp_path=%%a\"))\r\n)\r\n\r\nsc query ClickToRunSvc %nul%\r\nset error1=%errorlevel%\r\n\r\nif defined o16c2r if %error1% EQU 1060 (\r\necho:\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 16.0 files found]\"\r\nset o16c2r=\r\nset error=1\r\n)\r\n\r\nsc query OfficeSvc %nul%\r\nset error2=%errorlevel%\r\n\r\nif defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (\r\necho:\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 15.0 files found]\"\r\nset o15c2r=\r\nset error=1\r\n)\r\n\r\nif \"%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%\"==\"\" (\r\nset error=1\r\necho:\r\nif not \"%o14c2r%\"==\"\" (\r\ncall :dk_color %Red% \"Checking Supported Office Install       [Not Found]\"\r\n) else (\r\ncall :dk_color %Red% \"Checking Installed Office               [Not Found]\"\r\n)\r\n\r\nif defined ohub (\r\necho:\r\necho You only have the Office Dashboard app installed; you need to install the full version of Office.\r\n)\r\ncall :dk_color %Blue% \"Download and install Office from the URL below, then try again.\"\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto :ks_activate\r\n)\r\n\r\nset multioffice=\r\nif not \"%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%\"==\"1\" set multioffice=1\r\nif not \"%o14c2r%\"==\"\" set multioffice=1\r\n\r\nif defined multioffice (\r\necho:\r\ncall :dk_color %Gray% \"Checking Multiple Office Install        [Found. Recommended to install one version only]\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Process Office UWP\r\n\r\nif not defined o16uwp goto :ks_starto15c2r\r\n\r\ncall :ks_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=16\r\nset \"_oLPath=%o16uwp_path%\\Licenses16\"\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty Dependencies) | Select-Object PackageFullName\" %nul6%') do (set \"o16uwpapplist=!o16uwpapplist! %%a\")\r\n\r\necho \"%o16uwpapplist%\" | findstr /i \"Access Excel OneNote Outlook PowerPoint Publisher SkypeForBusiness Word\" %nul% && set \"_oIds=O365HomePremRetail\"\r\n\r\nfor %%# in (Project Visio) do (\r\necho \"%o16uwpapplist%\" | findstr /i \"%%#\" %nul% && (\r\nset _lat=\r\nif exist \"%_oLPath%\\%%#Pro2024VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2024Retail \" & set _lat=1\r\nif not defined _lat if exist \"%_oLPath%\\%%#Pro2021VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2021Retail \" & set _lat=1\r\nif not defined _lat if exist \"%_oLPath%\\%%#Pro2019VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2019Retail \" & set _lat=1\r\nif not defined _lat set \"_oIds= !_oIds! %%#ProRetail \"\r\n)\r\n)\r\n\r\nset uwpinfo=%o16uwp_path:C:\\Program Files\\WindowsApps\\Microsoft.Office.Desktop_=%\r\n\r\necho:\r\necho Processing Office...                    [UWP ^| %uwpinfo%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ks_starto15c2r\r\n)\r\n\r\ncall :ks_process\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_starto15c2r\r\n\r\n::  Process Office 15.0 C2R\r\n\r\nif not defined o15c2r goto :ks_starto16c2r\r\n\r\ncall :ks_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=15\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o15c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o15c2r_reg%\\Configuration\")\r\nif not defined _oArch   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nif not defined _version for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v version\" %nul6%') do (set \"_version=%%b\")\r\nif not defined _prids   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v ProductReleaseId\" %nul6%') do (set \"_prids=%o15c2r_reg%\\propertyBag /v ProductReleaseId\" & set \"_config=%o15c2r_reg%\\propertyBag\")\r\n\r\necho \"%o15c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=10) || (set _tok=9)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query %o15c2r_reg%\\ProductReleaseIDs\\Active %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\necho:\r\necho Processing Office...                    [C2R ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ks_starto16c2r\r\n)\r\n\r\ncall :oh_expiredpreview 2013\r\nif \"%_actprojvis%\"==\"0\" call :oh_fixprids\r\ncall :ks_process\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_starto16c2r\r\n\r\n::  Process Office 16.0 C2R\r\n\r\nif not defined o16c2r goto :ks_startmsi\r\n\r\ncall :ks_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=16\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v AudienceData\" %nul6%') do (set \"_AudienceData=^| %%b \")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o16c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o16c2r_reg%\\Configuration\")\r\n\r\necho \"%o16c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=9) || (set _tok=8)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query \"%o16c2r_reg%\\ProductReleaseIDs\" /s /f \".16\" /k %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\nset _oIds=%_oIds:.16=%\r\nset _o16c2rIds=%_oIds%\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses16\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\necho:\r\necho Processing Office...                    [C2R ^| %_version% %_AudienceData%^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ks_startmsi\r\n)\r\n\r\ncall :oh_expiredpreview 2016 2019 2021 2024\r\nif \"%_actprojvis%\"==\"0\" call :oh_fixprids\r\ncall :ks_process\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_startmsi\r\n\r\nif defined o14msi call :oh_setspp 14\r\nif defined o14msi call :ks_processmsi 14 %o14msi_reg%\r\ncall :oh_setspp\r\nif defined o15msi call :ks_processmsi 15 %o15msi_reg%\r\nif defined o16msi call :ks_processmsi 16 %o16msi_reg%\r\n\r\n::========================================================================================================================================\r\n\r\necho:\r\ncall :oh_clearblock\r\nif \"%o16msi%%o15msi%\"==\"\" if not \"%o16uwp%%o16c2r%%o15c2r%\"==\"\" if \"%keyerror%\"==\"0\" if %_NoEditionChange%==0 call :oh_uninstkey\r\ncall :oh_licrefresh\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_activate\r\n\r\n::  Opt out of sending KMSclient activation data to Microsoft\r\n::  https://learn.microsoft.com/en-us/windows/privacy/manage-connections-from-windows-operating-system-components-to-microsoft-services#19-software-protection-platform\r\n\r\nif %winbuild% GEQ 9600 (\r\nreg add \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows NT\\CurrentVersion\\Software Protection Platform\" /v NoGenTicket /t REG_DWORD /d 1 /f %nul%\r\nif %winbuild% EQU 14393 reg add \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows NT\\CurrentVersion\\Software Protection Platform\" /v NoAcquireGT /t REG_DWORD /d 1 /f %nul%\r\necho Turn off %KS% AVS Validation             [Successful]\r\n)\r\n\r\nset \"slp=SoftwareLicensingProduct\"\r\nset \"ospp=OfficeSoftwareProtectionProduct\"\r\n\r\necho:\r\necho Activating Volume Products...\r\nif %_actwin%==1 call :_taskgetids sppwid %slp% windows\r\nif %_actoff%==1 call :_taskgetids sppoid %slp% office\r\nif %_actoff%==1 call :_taskgetids osppid %ospp% office\r\n\r\nif not defined sppwid if not defined sppoid if not defined osppid (\r\nif not defined keyerror (\r\necho No installed Volume Windows / Office products found.\r\n) else (\r\ncall :dk_color %Red% \"Failed to get installed Volume Windows / Office products.\"\r\n)\r\ncall :_taskgetserv\r\ncall :_taskregserv\r\n)\r\n\r\ncall :_taskact\r\nif not defined showfix if defined _tserror (call :dk_color %Blue% \"%_fixmsg%\" & set showfix=1)\r\n\r\n::  Don't create renewal task if Windows/Office volume IDs are not found, even if script is set to create it by default\r\n::  Don't create renewal task if only Windows volume ID is found and OEM BIOS error is present on Windows 7, even if script is set to create it by default\r\n\r\nset _deltask=\r\nif not %_norentsk%==0 set _deltask=1\r\nif not defined _deltask (\r\nif %_actwin%==0 call :_taskgetids sppwid %slp% windows\r\nif %_actoff%==0 call :_taskgetids sppoid %slp% office\r\nif %_actoff%==0 call :_taskgetids osppid %ospp% office\r\n)\r\n\r\nif not defined sppwid if not defined sppoid if not defined osppid (set _deltask=1)\r\nif defined oemerr if not defined sppoid if not defined osppid (set _deltask=1)\r\n\r\nif not defined _deltask (\r\ncall :ks_renewal\r\n) else (\r\nif exist \"%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd\" call :dk_color %Gray% \"Deleting activation renewal task...\"\r\ncall :dk_color %Gray% \"Skipping creation of activation renewal task...\"\r\ncall :ks_clearstuff %nul%\r\nif not defined _server (\r\nif %winbuild% GEQ 9200 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" set \"_C16R=1\"\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun /v InstallPath /reg:32\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" set \"_C16R=1\"\r\nif defined _C16R (\r\nREM  mass{}grave{dot}dev/office-license-is-not-genuine\r\nset _server=10.0.0.10\r\ncall :_taskregserv\r\necho Keeping the non-existent IP address 10.0.0.10 as %KS% Server.\r\n)\r\n)\r\nif not defined _C16R (\r\ncall :_taskclear-cache\r\necho Cleared %KS% Server from the registry.\r\n)\r\n)\r\n)\r\n\r\n::  https://learn.microsoft.com/en-us/azure/virtual-desktop/windows-10-multisession-faq\r\n\r\nif %_actwin%==1 for %%# in (407) do if %osSKU%==%%# (\r\ncall :dk_color %Red% \"%winos% does not support activation on non-azure platforms.\"\r\n)\r\n\r\nif %_actoff%==1 if defined sppoid if not defined _tserror if %_NoEditionChange%==0 if defined ohub (\r\necho:\r\ncall :dk_color %Gray% \"Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app.\"\r\n)\r\n\r\n::  Trigger reevaluation of SPP's Scheduled Tasks\r\n\r\ncall :dk_reeval %nul%\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_ip\r\n\r\ncls\r\nset _server=\r\necho:\r\necho Enter / Paste the %KS% Server address, or just press Enter to return:\r\necho:\r\nset /p _server=\r\nif not defined _server goto :ks_menu\r\nset \"_server=%_server: =%\"\r\n\r\necho:\r\necho Enter / Paste the %KS% Port address, or just press Enter to use default:\r\necho:\r\nset /p _port=\r\nif not defined _port goto :ks_menu\r\nset \"_port=%_port: =%\"\r\n\r\ngoto :ks_menu\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_reset\r\n\r\nset key=\r\nset _oRoot=\r\nset _oArch=\r\nset _oIds=\r\nset _oLPath=\r\nset _actid=\r\nset _prod=\r\nset _lic=\r\nset _arr=\r\nset _prids=\r\nset _config=\r\nset _version=\r\nset _License=\r\nset _oMSI=\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  After retail to volume conversion, new product ID needs .OSPPReady key in registry, otherwise product info may not fully reflect \r\n\r\n:ks_osppready\r\n\r\nif not defined _config exit /b\r\n\r\necho: %_config% | find /i \"propertyBag\" %nul1% && (\r\nset \"_osppt=REG_DWORD\"\r\nset \"_osppready=%o15c2r_reg%\"\r\n) || (\r\nset \"_osppt=REG_SZ\"\r\nset \"_osppready=%_config%\"\r\n)\r\n\r\nreg add %_osppready% /f /v %_altoffid%.OSPPReady /t %_osppt% /d 1 %nul1%\r\n\r\n::  Office builds before 16.0.10730.20102 need the Installed license product ID in ProductReleaseIds, otherwise product info may not fully reflect \r\n\r\nif exist \"%_oLPath%\\Word2019VL_KMS_Client_AE*.xrm-ms\" exit /b\r\n\r\nreg query %_prids% | findstr /I \"%_altoffid%\" %nul1%\r\nif %errorlevel% NEQ 0 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query %_prids%') do reg add %_prids% /t REG_SZ /d \"%%b,%_altoffid%\" /f %nul1%\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_setspp\r\n\r\nset isOspp=\r\nif %winbuild% GEQ 9200 (\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n) else (\r\nset isOspp=1\r\nset spp=OfficeSoftwareProtectionProduct\r\nset sps=OfficeSoftwareProtectionService\r\n)\r\nif \"%1\"==\"14\" (\r\nset isOspp=1\r\nset spp=OfficeSoftwareProtectionProduct\r\nset sps=OfficeSoftwareProtectionService\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_process\r\n\r\nfor %%# in (%_oIds%) do (\r\n\r\nset skipprocess=\r\nif %_NoEditionChange%==1 if not defined _oMSI (\r\nset foundprod=\r\ncall :ksdata chkprod %%#\r\nif not defined foundprod (\r\nset skipprocess=1\r\ncall :dk_color %Gray% \"Skipping Because NoEditionChange Mode   [%%#]\"\r\n)\r\n)\r\n\r\n\r\nif \"%_actprojvis%\"==\"1\" if not defined skipprocess (\r\necho %%# | findstr /i \"Project Visio\" %nul% || (\r\nset skipprocess=1\r\ncall :dk_color %Gray% \"Skipping Because Project/Visio Mode     [%%#]\"\r\n)\r\n)\r\n\r\nif \"%_actprojvis%\"==\"0\" if not defined skipprocess echo %_oIds% | findstr /i \"O365\" %nul% && (\r\necho %%# | findstr /i \"Project Visio\" %nul% && (\r\nset skipprocess=1\r\necho Skipping Because Mondo Is Available     [%%#]\r\n)\r\n)\r\n\r\nif not defined skipprocess (\r\nset key=\r\nset _actid=\r\nset _preview=\r\nset _License=%%#\r\nset _altoffid=\r\n\r\necho %%# | find /i \"2024\" %nul% && (\r\nif exist \"!_oLPath!\\ProPlus2024PreviewVL_*.xrm-ms\" if not exist \"!_oLPath!\\ProPlus2024VL_*.xrm-ms\" set _preview=-Preview\r\n)\r\nset _prod=%%#!_preview!\r\n\r\ncall :ksdata getinfo !_prod!\r\n\r\nif defined _altoffid (\r\nset _License=!_altoffid!\r\necho Converting Retail To Volume             [!_prod! To !_altoffid!]\r\necho %%# | find /i \"O365\" %nul% && (\r\nif \"%oVer%\"==\"15\" (call :dk_color %Gray% \"Mondo 2013 is equivalent to O365 [15.0 version] in terms of the latest features.\")\r\nif \"%oVer%\"==\"16\" (call :dk_color %Gray% \"Mondo 2016 is equivalent to O365 in terms of the latest features.\")\r\n)\r\nset _prod=!_altoffid!\r\ncall :ks_osppready\r\n)\r\n\r\nif not \"!key!\"==\"\" (\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% || call :oh_installlic\r\nset generickey=1\r\ncall :dk_inskey \"[!key!] [!_prod!]\"\r\n) else (\r\nif not defined _oMSI (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Product In Script              [Office %oVer%.0 !_prod! not found in script]\"\r\ncall :dk_color %Blue% \"Make sure you are using Latest MAS script.\"\r\n) else (\r\ncall :dk_color %Red% \"Checking Product In Script              [!_prod! MSI Retail is not supported]\"\r\ncall :dk_color %Blue% \"Use Ohook option to activate it. To activate with %KS%, you need to install Volume version of Office.\"\r\n)\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\n)\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_processmsi\r\n\r\n::  Process Office MSI Version\r\n\r\ncall :ks_reset\r\nset _oMSI=1\r\n\r\nif \"%1\"==\"14\" (\r\ncall :dk_actids 59a52881-a989-479d-af46-f275c6370663\r\n) else (\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n)\r\n\r\nset oVer=%1\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_oRoot=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\ProductVersion /v LastProduct\" %nul6%') do (set \"_version=%%b\")\r\nif \"%_oRoot:~-1%\"==\"\\\" set \"_oRoot=%_oRoot:~0,-1%\"\r\n\r\necho \"%2\" | find /i \"Wow6432Node\" %nul1% && set _oArch=x86\r\nif not \"%osarch%\"==\"x86\" if not defined _oArch set _oArch=x64\r\nif \"%osarch%\"==\"x86\" set _oArch=x86\r\n\r\ncall :msiofficedata %2\r\n\r\necho:\r\necho Processing Office...                    [MSI ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nexit /b\r\n)\r\n\r\ncall :ks_process\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_uninstall\r\n\r\ncls\r\nif not defined terminal mode 91, 30\r\ntitle  Online %KS% Complete Uninstall %masver%\r\n\r\nset \"uline=__________________________________________________________________________________________\"\r\n\r\nset \"_C16R=\"\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun /v InstallPath\" 2^>nul') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" set \"_C16R=1\"\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun /v InstallPath /reg:32\" 2^>nul') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" set \"_C16R=1\"\r\nif %winbuild% GEQ 9200 if defined _C16R (\r\necho:\r\ncall :dk_color %Gray% \"Notice-\"\r\necho:\r\necho To make sure Office programs do not show a non-genuine banner,\r\necho please run the activation option once, and don't uninstall afterward.\r\necho %uline%\r\n)\r\n\r\necho:\r\nset error_=\r\ncall :_taskclear-cache\r\ncall :ks_clearstuff\r\n\r\n:: check KMS38 lock\r\n\r\n%nul% reg query \"HKLM\\%SPPk%\\%_wApp%\" && (\r\nset error_=9\r\necho Failed to completely clear %KS% Cache.\r\nreg query \"HKLM\\%SPPk%\\%_wApp%\" /s %nul2% | findstr /i \"127.0.0.2\" %nul1% && echo KMS38 activation is locked.\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n) || (\r\necho Cleared %KS% Cache successfully.\r\n)\r\n\r\nif defined error_ (\r\nif \"%error_%\"==\"1\" (\r\necho %uline%\r\n%eline%\r\necho Try Again / Restart the System\r\necho %uline%\r\n)\r\n) else (\r\necho %uline%\r\necho:\r\ncall :dk_color %Green% \"Online %KS% has been successfully uninstalled.\"\r\necho:\r\ncall :dk_color %Gray% \"If you want to reset the activation status,\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\necho %uline%\r\n)\r\n\r\ngoto :dk_done\r\n\r\n:ks_clearstuff\r\n\r\nset \"key=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\"\r\n\r\nreg query \"%key%\" /f Path /s | find /i \"\\Activation-Renewal\" %nul1% && (\r\necho Deleting [Task] Activation-Renewal\r\nschtasks /delete /tn Activation-Renewal /f %nul%\r\n)\r\n\r\nreg query \"%key%\" /f Path /s | find /i \"\\Activation-Run_Once\" %nul1% && (\r\necho Deleting [Task] Activation-Run_Once\r\nschtasks /delete /tn Activation-Run_Once /f %nul%\r\n)\r\n\r\nIf exist \"%ProgramFiles%\\Activation-Renewal\\\" (\r\necho Deleting [Folder] %ProgramFiles%\\Activation-Renewal\\\r\nrmdir /s /q \"%ProgramFiles%\\Activation-Renewal\\\" %nul%\r\n)\r\n\r\n::  Stuff from old MAS versions\r\n\r\nschtasks /delete /tn Online_%KS%_Activation_Script-Renewal /f %nul%\r\nschtasks /delete /tn Online_%KS%_Activation_Script-Run_Once /f %nul%\r\ndel /f /q \"%ProgramData%\\Online_%KS%_Activation.cmd\" %nul%\r\nrmdir /s /q \"%ProgramData%\\Activation-Renewal\\\" %nul%\r\nrmdir /s /q \"%ProgramData%\\Online_%KS%_Activation\\\" %nul%\r\nrmdir /s /q \"%windir%\\Online_%KS%_Activation_Script\\\" %nul%\r\nreg delete \"HKCR\\DesktopBackground\\shell\\Activate Windows - Office\" /f %nul%\r\n\r\n::  Check if all is removed\r\n\r\nreg query \"%key%\" /f Path /s | find /i \"\\Activation-Renewal\" %nul1% && (set error_=1)\r\nreg query \"%key%\" /f Path /s | find /i \"\\Activation-Run_Once\" %nul1% && (set error_=1)\r\nreg query \"%key%\" /f Path /s | find /i \"\\Online_%KS%_Activation_Script\" %nul1% && (set error_=1)\r\nIf exist \"%windir%\\Online_%KS%_Activation_Script\\\" (set error_=1)\r\nreg query \"HKCR\\DesktopBackground\\shell\\Activate Windows - Office\" %nul% && (set error_=1)\r\nif exist \"%ProgramData%\\Online_%KS%_Activation.cmd\" (set error_=1)\r\nif exist \"%ProgramData%\\Online_%KS%_Activation\\\" (set error_=1)\r\nif exist \"%ProgramData%\\Activation-Renewal\\\" (set error_=1)\r\nif exist \"%ProgramFiles%\\Activation-Renewal\\\" (set error_=1)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_extracttask:\r\n@echo off\r\n\r\n::   Renew K-M-S activation with Online servers via scheduled task\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\nif not \"%~1\"==\"Task\" (\r\necho:\r\necho ====== Error ======\r\necho:\r\necho This file is supposed to be run only by the scheduled task.\r\necho:\r\necho Press any key to exit\r\npause >nul\r\nexit /b\r\n)\r\n\r\n::  Set Environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\n>nul fltmc || exit /b\r\n\r\n::========================================================================================================================================\r\n\r\nset _tserror=\r\nset winbuild=1\r\nset \"nul=>nul 2>&1\"\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\nset psc=powershell.exe -nop -c\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset run_once=\r\nset t_name=Renewal Task\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\" /f Path /s | find /i \"\\Activation-Run_Once\" >nul && (\r\nset run_once=1\r\nset t_name=Run Once Task\r\n)\r\n\r\nset _wmic=0\r\nfor %%# in (wmic.exe) do @if not \"%%~$PATH:#\"==\"\" (\r\ncmd /c \"wmic path Win32_ComputerSystem get CreationClassName /value\" 2>nul | find /i \"computersystem\" 1>nul && set _wmic=1\r\n)\r\nif %winbuild% LSS 9200 set _wmic=1\r\n\r\nsetlocal EnableDelayedExpansion\r\nif exist \"%ProgramFiles%\\Activation-Renewal\\\" call :_taskstart>>\"%ProgramFiles%\\Activation-Renewal\\Logs.txt\"\r\nexit\r\n\r\n::========================================================================================================================================\r\n\r\n:_taskstart\r\n\r\necho:\r\necho %date%, %time%\r\n\r\nset /a loop=1\r\nset /a max_loop=4\r\n\r\ncall :_tasksetserv\r\n\r\n:_intrepeat\r\n\r\n::  Check Internet connection. Works even if ICMP echo is disabled.\r\n\r\nfor %%a in (%srvlist%) do (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (\r\nif not \"%%#\"==\"\" goto _taskIntConnected\r\n)\r\n)\r\n\r\nnslookup dns.msftncsi.com 2>nul | find \"131.107.255.255\" 1>nul\r\nif \"%errorlevel%\"==\"0\" goto _taskIntConnected\r\n\r\nif %loop%==%max_loop% (\r\nset _tserror=1\r\ngoto _taskend\r\n)\r\n\r\necho:\r\necho Error: Internet is not connected\r\necho Waiting 30 seconds\r\n\r\ntimeout /t 30 >nul\r\nset /a loop=%loop%+1\r\ngoto _intrepeat\r\n\r\n:_taskIntConnected\r\n\r\n::========================================================================================================================================\r\n\r\ncall :_taskclear-cache\r\n\r\n::  Check WMI and sppsvc Errors\r\n\r\nset applist=\r\nnet start %_slser% /y %nul%\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %slp% where (ApplicationID='%_wApp%') get ID /VALUE\" 2^>nul')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %slp% WHERE ApplicationID=''%_wApp%''').Get()).ID ^| %% {echo ('ID='+$_)}\" 2^>nul')\"\r\n%chkapp% do (if defined applist (call set \"applist=!applist! %%a\") else (call set \"applist=%%a\"))\r\n\r\nif not defined applist (\r\nset _tserror=1\r\nif %_wmic% EQU 1 wmic path Win32_ComputerSystem get CreationClassName /value 2>nul | find /i \"computersystem\" 1>nul\r\nif %_wmic% EQU 0 %psc% \"Get-CIMInstance -Class Win32_ComputerSystem | Select-Object -Property CreationClassName\" 2>nul | find /i \"computersystem\" 1>nul\r\nif !errorlevel! NEQ 0 (set e_wmispp=WMI, SPP) else (set e_wmispp=SPP)\r\necho:\r\necho Error: Not Respoding- !e_wmispp!\r\necho:\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check installed volume products activation ID's\r\n\r\ncall :_taskgetids sppwid %slp% windows\r\ncall :_taskgetids sppoid %slp% office\r\ncall :_taskgetids osppid %ospp% office\r\n\r\n::========================================================================================================================================\r\n\r\necho:\r\necho Renewing K-M-S activation for all installed Volume products\r\n\r\nif not defined sppwid if not defined sppoid if not defined osppid (\r\necho:\r\necho No installed Volume Windows / Office product found\r\necho:\r\necho Renewing K-M-S server\r\ncall :_taskgetserv\r\ncall :_taskregserv\r\ngoto :_skipact\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\ncall :_taskact\r\n\r\n:_skipact\r\n\r\n::========================================================================================================================================\r\n\r\nif defined run_once (\r\necho:\r\necho Deleting Scheduled Task Activation-Run_Once\r\nschtasks /delete /tn Activation-Run_Once /f %nul%\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:_taskend\r\n\r\necho:\r\necho Exiting\r\necho ______________________________________________________________________\r\n\r\nif defined _tserror (exit /b 123456789) else (exit /b 0)\r\n\r\n::========================================================================================================================================\r\n\r\n:_act\r\n\r\nset prodname=\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%# in ('\"wmic path !_path! where ID='!_actid!' get LicenseFamily /VALUE\" 2^>nul') do (call set \"prodname=%%#\")\r\nif %_wmic% EQU 0 for /f \"tokens=2 delims==\" %%# in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM !_path! WHERE ID=''!_actid!''').Get()).LicenseFamily | %% {echo ('LicenseFamily='+$_)}\" 2^>nul') do (call set \"prodname=%%#\")\r\nfor /f \"tokens=1 delims=-_\" %%a in (\"%prodname%\") do set \"prodname=%%a\"\r\n\r\nset _taskskip=\r\nif \"%_actprojvis%\"==\"1\" (\r\necho: %prodname% | find /i \"Office\" %nul% && (\r\necho: %prodname% | findstr /i \"Project Visio\" %nul% || (set _taskskip=1& exit /b)\r\n)\r\n)\r\n\r\nif defined t_name Activating: %prodname%\r\n\r\nset errorcode=12345\r\nset /a act_attempt=0\r\n\r\n:_act2\r\n\r\nif %act_attempt% GTR 4 exit /b\r\n\r\nif not \"%act_ok%\"==\"1\" (\r\nif not defined _server call :_taskgetserv\r\ncall :_taskregserv\r\n)\r\n\r\nif not !server_num! GTR %max_servers% (\r\n\r\nif \"%1\"==\"act_win\" if %_kms38% EQU 1 (\r\nset act_ok=1\r\nexit /b\r\n)\r\n\r\nif %_wmic% EQU 1 wmic path !_path! where ID='!_actid!' call Activate %nul%\r\nif %_wmic% EQU 0 %psc% \"try {$null=(([WMISEARCHER]'SELECT ID FROM !_path! where ID=''!_actid!''').Get()).Activate(); exit 0} catch { exit $_.Exception.InnerException.HResult }\"\r\n\r\ncall set errorcode=!errorlevel!\r\n\r\nif !errorcode! EQU 0 (\r\nset act_ok=1\r\nexit /b\r\n)\r\nif \"%1\"==\"act_win\" if !errorcode! EQU -1073418187 if %winbuild% LSS 9200 (\r\nset act_ok=1\r\nexit /b\r\n)\r\n\r\nset act_ok=0\r\nset /a act_attempt+=1\r\nif not defined _server goto _act2\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_actinfo\r\n\r\nif \"%1\"==\"act_win\" if not defined t_name (set prodname=%winos%)\r\n\r\nif \"%1\"==\"act_win\" if %_kms38% EQU 1 (\r\nif defined t_name (\r\necho %prodname% is already activated with KMS38.\r\n) else (\r\ncall :dk_color %Green% \"%prodname% is already activated with KMS38.\"\r\n)\r\nexit /b\r\n)\r\n\r\nif %errorcode% EQU 12345 (\r\nif defined t_name (\r\necho %prodname% activation failed due to restricted or no Internet.\r\n) else (\r\ncall :dk_color %Red% \"%prodname% activation failed due to restricted or no Internet.\"\r\n)\r\nset showfix=1\r\nset _tserror=1\r\nexit /b\r\n)\r\n\r\nif %errorcode% EQU -1073418187 if \"%1\"==\"act_win\" if %winbuild% LSS 9200 (\r\nif defined t_name (\r\necho %prodname% cannot be KMS-activated on this computer due to unqualified OEM BIOS [0xC004F035].\r\n) else (\r\ncall :dk_color %Red% \"%prodname% cannot be KMS-activated on this computer due to unqualified OEM BIOS [0xC004F035].\"\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu.\"\r\n)\r\nset oemerr=1\r\nset showfix=1\r\nexit /b\r\n)\r\n\r\nif %errorcode% EQU -1073418124 (\r\nif defined t_name (\r\necho %prodname% activation failed due to Internet issue [0xC004F074].\r\n) else (\r\ncall :dk_color %Red% \"%prodname% activation failed due to Internet issue [0xC004F074].\"\r\nif not defined _tserror (\r\ncall :dk_color %Blue% \"Make sure that system files are not blocked by firewall.\"\r\ncall :dk_color %Blue% \"If the issue persists, try another Internet connection or VPN such as https://1.1.1.1\"\r\n)\r\n)\r\nset showfix=1\r\nset _tserror=1\r\nexit /b\r\n)\r\n\r\n\r\nset gpr=0\r\nset gpr2=0\r\ncall :_taskgetgrace\r\nset /a \"gpr2=(%gpr%+1440-1)/1440\"\r\n\r\nif %errorcode% EQU 0 if %gpr% EQU 0 (\r\nif defined t_name (\r\necho %prodname% activation succeeded, but Remaining Period failed to increase.\r\n) else (\r\ncall :dk_color %Red% \"%prodname% activation succeeded, but Remaining Period failed to increase.\"\r\n)\r\nset _tserror=1\r\nexit /b\r\n)\r\n\r\nset _actpass=1\r\nif %gpr% EQU 43200  if \"%1\"==\"act_win\" if %winbuild% GEQ 9200 set _actpass=0\r\nif %gpr% EQU 64800  set _actpass=0\r\nif %gpr% GTR 259200 if \"%1\"==\"act_win\" call :_taskchkEnterpriseG _actpass\r\nif %gpr% EQU 259200 set _actpass=0\r\n\r\nif %errorcode% EQU 0 if %_actpass% EQU 0 (\r\nif defined t_name (\r\necho %prodname% is successfully activated for %gpr2% days.\r\n) else (\r\ncall :dk_color %Green% \"%prodname% is successfully activated for %gpr2% days.\"\r\n)\r\nexit /b\r\n)\r\n\r\ncmd /c exit /b %errorcode%\r\nif defined t_name (\r\necho %prodname% has failed to activate [0x!=ExitCode!]. Remaining Period: %gpr2% days [%gpr% minutes].\r\n) else (\r\ncall :dk_color %Red% \"%prodname% has failed to activate [0x!=ExitCode!]. Remaining Period: %gpr2% days [%gpr% minutes].\"\r\n)\r\nset _tserror=1\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_taskact\r\n\r\n:: Check KMS38 activation\r\n\r\nset gpr=0\r\nset _kms38=0\r\nif defined sppwid if %winbuild% GEQ 14393 (\r\nset _path=%slp%\r\nset _actid=%sppwid%\r\ncall :_taskgetgrace\r\n)\r\n\r\nif %gpr% NEQ 0 if %gpr% GTR 259200 (\r\nset _kms38=1\r\ncall :_taskchkEnterpriseG _kms38\r\n)\r\n\r\n:: Set specific K-M-S host to Local Host so that global K-M-S IP can not replace KMS38 activation but can be used with Office and other Windows Editions.\r\n\r\nif %_kms38% EQU 1 (\r\n%nul% reg add \"HKLM\\%SPPk%\\%_wApp%\\%sppwid%\" /f /v KeyManagementServiceName /t REG_SZ /d \"127.0.0.2\"\r\n%nul% reg add \"HKLM\\%SPPk%\\%_wApp%\\%sppwid%\" /f /v KeyManagementServicePort /t REG_SZ /d \"1688\"\r\n)\r\n\r\necho:\r\nif defined sppwid (\r\nset _path=%slp%\r\nset _actid=%sppwid%\r\ncall :_act act_win\r\ncall :_actinfo act_win\r\n) else (\r\nif defined t_name echo Checking: Volume version of Windows is not installed\r\n)\r\n\r\nif defined sppoid (\r\nset _path=%slp%\r\nfor %%# in (%sppoid%) do (\r\nset _actid=%%#\r\ncall :_act\r\nif not defined _taskskip call :_actinfo\r\n)\r\n)\r\n\r\nif defined osppid (\r\nset _path=%ospp%\r\nfor %%# in (%osppid%) do (\r\nset _actid=%%#\r\ncall :_act\r\nif not defined _taskskip call :_actinfo\r\n)\r\n)\r\n\r\nif not defined sppoid if not defined osppid if defined t_name (\r\necho:\r\necho Checking: Volume version of Office is not installed\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_taskgetids\r\n\r\nset %1=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %2 where (Name like '%%%3%%' and Description like '%%KMSCLIENT%%' and PartialProductKey is not NULL AND LicenseDependsOn is NULL) get ID /VALUE\" 2^>nul')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %2 WHERE Name like ''%%%3%%'' and Description like ''%%KMSCLIENT%%'' and PartialProductKey is not NULL AND LicenseDependsOn is NULL').Get()).ID ^| %% {echo ('ID='+$_)}\" 2^>nul')\"\r\n%chkapp% do (if defined %1 (call set \"%1=!%1! %%a\") else (call set \"%1=%%a\"))\r\nexit /b\r\n\r\n:_taskgetgrace\r\n\r\nset gpr=0\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%# in ('\"wmic path !_path! where ID='!_actid!' get GracePeriodRemaining /VALUE\" 2^>nul') do call set \"gpr=%%#\"\r\nif %_wmic% EQU 0 for /f \"tokens=2 delims==\" %%# in ('%psc% \"(([WMISEARCHER]'SELECT GracePeriodRemaining FROM !_path! where ID=''!_actid!''').Get()).GracePeriodRemaining | %% {echo ('GracePeriodRemaining='+$_)}\" 2^>nul') do call set \"gpr=%%#\"\r\nexit /b\r\n\r\n:_taskchkEnterpriseG\r\n\r\nfor %%# in (e0b2d383-d112-413f-8a80-97f373a5820c e38454fb-41a4-4f59-a5dc-25080e354730) do (if %sppwid%==%%# set %1=0)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Clean existing K-M-S cache from the registry\r\n\r\n:_taskclear-cache\r\n\r\nset w=\r\nfor %%# in (SppE%w%xtComObj.exe sppsvc.exe SLsvc.exe) do (\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" /f %nul%\r\n)\r\n\r\nset \"OPPk=SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform\"\r\n\r\nif %winbuild% LSS 7600 (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\" %nul% && (\r\nset \"SPPk=SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\"\r\n)\r\n)\r\nif not defined SPPk (\r\nset \"SPPk=SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\"\r\n)\r\n\r\nset \"slp=SoftwareLicensingProduct\"\r\nset \"ospp=OfficeSoftwareProtectionProduct\"\r\n\r\nset \"_wApp=55c92734-d682-4d71-983e-d6ec3f16059f\"\r\nset \"_oApp=0ff1ce15-a989-479d-af46-f275c6370663\"\r\nset \"_oA14=59a52881-a989-479d-af46-f275c6370663\"\r\n\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName /reg:32\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort /reg:32\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v DisableDnsPublishing\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v DisableKeyManagementServiceHostCaching\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_wApp%\" /f\r\nif %winbuild% GEQ 9200 (\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_oApp%\" /f\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_oApp%\" /f /reg:32\r\n)\r\nif %winbuild% GEQ 9600 (\r\n%nul% reg delete \"HKU\\S-1-5-20\\%SPPk%\\%_wApp%\" /f\r\n%nul% reg delete \"HKU\\S-1-5-20\\%SPPk%\\%_oApp%\" /f\r\n)\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v KeyManagementServiceName\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v KeyManagementServicePort\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v DisableDnsPublishing\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v DisableKeyManagementServiceHostCaching\r\n%nul% reg delete \"HKLM\\%OPPk%\\%_oA14%\" /f\r\n%nul% reg delete \"HKLM\\%OPPk%\\%_oApp%\" /f\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_taskregserv\r\n\r\nif defined _server (set KMS_IP=%_server%)\r\nif not defined _port set _port=1688\r\n\r\n%nul% reg add \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName /t REG_SZ /d \"%KMS_IP%\"\r\n%nul% reg add \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName /t REG_SZ /d \"%KMS_IP%\" /reg:32\r\n%nul% reg add \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort /t REG_SZ /d \"%_port%\"\r\n%nul% reg add \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort /t REG_SZ /d \"%_port%\" /reg:32\r\n\r\n%nul% reg add \"HKLM\\%OPPk%\" /f /v KeyManagementServiceName /t REG_SZ /d \"%KMS_IP%\"\r\n%nul% reg add \"HKLM\\%OPPk%\" /f /v KeyManagementServicePort /t REG_SZ /d \"%_port%\"\r\n\r\nif %winbuild% GEQ 9200 (\r\n%nul% reg add \"HKLM\\%SPPk%\\%_oApp%\" /f /v KeyManagementServiceName /t REG_SZ /d \"%KMS_IP%\"\r\n%nul% reg add \"HKLM\\%SPPk%\\%_oApp%\" /f /v KeyManagementServiceName /t REG_SZ /d \"%KMS_IP%\" /reg:32\r\n%nul% reg add \"HKLM\\%SPPk%\\%_oApp%\" /f /v KeyManagementServicePort /t REG_SZ /d \"%_port%\"\r\n%nul% reg add \"HKLM\\%SPPk%\\%_oApp%\" /f /v KeyManagementServicePort /t REG_SZ /d \"%_port%\" /reg:32\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_tasksetserv\r\n\r\n::  Multi K-M-S servers integration and servers randomization\r\n\r\nset srvlist=\r\nset -=\r\n\r\nset \"srvlist=kms.03%-%k.org kms-default.cangs%-%hui.net kms.six%-%yin.com kms.moe%-%club.org kms.cgt%-%soft.com\"\r\nset \"srvlist=%srvlist% kms.id%-%ina.cn kms.moe%-%yuuko.com xinch%-%eng213618.cn kms.lol%-%i.best kms.mc%-%06.net\"\r\nset \"srvlist=%srvlist% kms.0%-%t.net.cn win.k%-%ms.pub kms.wx%-%lost.com kms.moe%-%yuuko.top kms.gh%-%xi.com\"\r\n\r\nset n=1\r\nfor %%a in (%srvlist%) do (set %%a=&set server!n!=%%a&set /a n+=1)\r\nset max_servers=15\r\nset /a server_num=0\r\nexit /b\r\n\r\n:_taskgetserv\r\n\r\nif %server_num% geq %max_servers% (set /a server_num+=1&set KMS_IP=222.184.9.98&exit /b)\r\nset /a rand=%Random%%%(15+1-1)+1\r\nif defined !server%rand%! goto :_taskgetserv\r\nset KMS_IP=!server%rand%!\r\nset !server%rand%!=1\r\n\r\n::  Get IPv4 address of K-M-S server to use for the activation, works even if ICMP echo is disabled.\r\n::  Microsoft and Antivirus's may flag the issue if public K-M-S server host name is directly used for the activation.\r\n\r\nset /a server_num+=1\r\n(for /f \"delims=[] tokens=2\" %%a in ('ping -4 -n 1 %KMS_IP% 2^>nul') do set \"KMS_IP=%%a\"\r\nif \"%KMS_IP%\"==\"!KMS_IP!\" for /f \"delims=[] tokens=2\" %%# in ('pathping -4 -h 1 -n -p 1 -q 1 -w 1 %KMS_IP% 2^>nul') do set \"KMS_IP=%%#\"\r\nif not \"%KMS_IP%\"==\"!KMS_IP!\" exit /b\r\ngoto :_taskgetserv\r\n)\r\n::Ver:2.7\r\n:_extracttask:\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_renewal\r\n\r\nset error_=\r\nset \"_dest=%ProgramFiles%\\Activation-Renewal\"\r\nset \"key=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\"\r\n\r\ncall :ks_clearstuff %nul%\r\n\r\nif defined error_ (\r\nset error=1\r\ncall :dk_color %Red% \"Failed to remove previous Renewal Task. Restart system / Try again.\"\r\nexit /b\r\n)\r\n\r\nif not exist \"%_dest%\\\" md \"%_dest%\\\" %nul%\r\nfor /f %%G in ('%psc% \"[Guid]::NewGuid().Guid\"') do set \"randguid=%%G\"\r\nset \"_temp=%SystemRoot%\\Temp\\%Random%%randguid%\"\r\n\r\nset nil=\r\nif %winbuild% LSS 7600 (set _vista=_vista)\r\nif exist \"%_temp%\\.*\" rmdir /s /q \"%_temp%\\\" %nul%\r\nmd \"%_temp%\\\" %nul%\r\ncall :ks_RenExport renewal%_vista% \"%_temp%\\Renewal.xml\" Unicode\r\nif not defined _int (call :ks_RenExport run_once%_vista% \"%_temp%\\Run_Once.xml\" Unicode)\r\ns%nil%cht%nil%asks /cre%nil%ate /tn \"Activation-Renewal\" /ru \"SYS%nil%TEM\" /xml \"%_temp%\\Renewal.xml\" %nul%\r\nif not defined _int (s%nil%cht%nil%asks /cre%nil%ate /tn \"Activation-Run_Once\" /ru \"SYS%nil%TEM\" /xml \"%_temp%\\Run_Once.xml\" %nul%)\r\nif exist \"%_temp%\\.*\" rmdir /s /q \"%_temp%\\\" %nul%\r\n\r\ncall :ks_createInfo.txt\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split \\\":_extracttask\\:.*`r`n\\\"; [io.file]::WriteAllText('%_dest%\\Activation_task.cmd', '@::%randguid%' + [Environment]::NewLine + $f[1].Trim(), [System.Text.Encoding]::ASCII)\"\r\n\r\n::========================================================================================================================================\r\n\r\nreg query \"%key%\" /f Path /s | find /i \"\\Activation-Renewal\" >nul || (set error_=1)\r\nif not defined _int reg query \"%key%\" /f Path /s | find /i \"\\Activation-Run_Once\" >nul || (set error_=1)\r\n\r\nIf not exist \"%_dest%\\Activation_task.cmd\" (set error_=1)\r\nIf not exist \"%_dest%\\Info.txt\" (set error_=1)\r\n\r\nif defined error_ (\r\nschtasks /delete /tn Activation-Renewal /f %nul%\r\nschtasks /delete /tn Activation-Run_Once /f %nul%\r\nrmdir /s /q \"%_dest%\\\" %nul%\r\nset error=1\r\ncall :dk_color %Red% \"Failed to install Renewal Task. Restart system / Try again.\"\r\nexit /b\r\n)\r\n\r\nif \"%keyerror%\"==\"0\" if not defined _tserror (\r\ncall :dk_color %Green% \"Renewal Task for lifetime activation is successfully installed in %_dest%\"\r\nexit /b\r\n)\r\necho Renewal Task for lifetime activation is successfully installed in %_dest%\r\nexit /b\r\n\r\n::  Extract the text from batch script without character and file encoding issue\r\n\r\n:ks_RenExport\r\n\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split \\\":%~1\\:.*`r`n\\\"; [io.file]::WriteAllText('%~2',$f[1].Trim(),[System.Text.Encoding]::%~3);\"\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_createInfo.txt\r\n\r\n(\r\necho   The use of this script is to renew your Windows/Office license using online K-M-S.\r\necho:\r\necho   If renewal/activation Scheduled tasks were created then following would exist,\r\necho:\r\necho   - Scheduled tasks\r\necho     Activation-Renewal    [Renewal / Weekly]\r\necho     Activation-Run_Once   [Activation Task - deletes itself once activated]\r\necho     The scheduled tasks runs only if the system is connected to the Internet.\r\necho:\r\necho   - Files\r\necho     C:\\Program Files\\Activation-Renewal\\Activation_task.cmd\r\necho     C:\\Program Files\\Activation-Renewal\\Info.txt\r\necho     C:\\Program Files\\Activation-Renewal\\Logs.txt\r\necho ______________________________________________________________________________________________\r\necho:\r\necho   This Script is a part of MAS project.\r\necho:   \r\necho   Homepage: mass%w%grave%w%.dev\r\n)>\"%_dest%\\Info.txt\"\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:renewal:\r\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<Task version=\"1.3\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\r\n  <RegistrationInfo>\r\n    <Source>Microsoft Corporation</Source>\r\n    <Date>1999-01-01T12:00:00.34375</Date>\r\n    <Author>WindowsAddict</Author>\r\n    <Version>1.0</Version>\r\n    <Description>Online K-M-S Activation-Renewal - Weekly Task</Description>\r\n    <URI>\\Activation-Renewal</URI>\r\n    <SecurityDescriptor>D:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FRFX;;;LS)(A;;FRFW;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)(A;;FR;;;S-1-5-4)</SecurityDescriptor>\r\n  </RegistrationInfo>\r\n  <Triggers>\r\n    <CalendarTrigger>\r\n      <StartBoundary>1999-01-01T12:00:00</StartBoundary>\r\n      <Enabled>true</Enabled>\r\n      <ScheduleByWeek>\r\n        <DaysOfWeek>\r\n          <Sunday />\r\n        </DaysOfWeek>\r\n        <WeeksInterval>1</WeeksInterval>\r\n      </ScheduleByWeek>\r\n    </CalendarTrigger>\r\n  </Triggers>\r\n  <Principals>\r\n    <Principal id=\"LocalSystem\">\r\n      <UserId>S-1-5-18</UserId>\r\n      <RunLevel>HighestAvailable</RunLevel>\r\n    </Principal>\r\n  </Principals>\r\n  <Settings>\r\n    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\r\n    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\r\n    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>\r\n    <AllowHardTerminate>true</AllowHardTerminate>\r\n    <StartWhenAvailable>true</StartWhenAvailable>\r\n    <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>\r\n    <IdleSettings>\r\n      <StopOnIdleEnd>false</StopOnIdleEnd>\r\n      <RestartOnIdle>false</RestartOnIdle>\r\n    </IdleSettings>\r\n    <AllowStartOnDemand>true</AllowStartOnDemand>\r\n    <Enabled>true</Enabled>\r\n    <Hidden>true</Hidden>\r\n    <RunOnlyIfIdle>false</RunOnlyIfIdle>\r\n    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>\r\n    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>\r\n    <WakeToRun>false</WakeToRun>\r\n    <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>\r\n    <Priority>7</Priority>\r\n    <RestartOnFailure>\r\n      <Interval>PT2M</Interval>\r\n      <Count>3</Count>\r\n    </RestartOnFailure>\r\n  </Settings>\r\n  <Actions Context=\"LocalSystem\">\r\n    <Exec>\r\n      <Command>%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd</Command>\r\n    <Arguments>Task</Arguments>\r\n    </Exec>\r\n  </Actions>\r\n</Task>\r\n:renewal:\r\n\r\n:run_once:\r\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<Task version=\"1.3\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\r\n  <RegistrationInfo>\r\n    <Source>Microsoft Corporation</Source>\r\n    <Date>1999-01-01T12:00:00.34375</Date>\r\n    <Author>WindowsAddict</Author>\r\n    <Version>1.0</Version>\r\n    <Description>Online K-M-S Activation Run Once - Run and Delete itself on first Internet Contact</Description>\r\n    <URI>\\Activation-Run_Once</URI>\r\n    <SecurityDescriptor>D:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FRFX;;;LS)(A;;FRFW;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)(A;;FR;;;S-1-5-4)</SecurityDescriptor>\r\n  </RegistrationInfo>\r\n  <Triggers>\r\n    <LogonTrigger>\r\n      <Enabled>true</Enabled>\r\n    </LogonTrigger>\r\n  </Triggers>\r\n  <Principals>\r\n    <Principal id=\"LocalSystem\">\r\n      <UserId>S-1-5-18</UserId>\r\n      <RunLevel>HighestAvailable</RunLevel>\r\n    </Principal>\r\n  </Principals>\r\n  <Settings>\r\n    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\r\n    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\r\n    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>\r\n    <AllowHardTerminate>true</AllowHardTerminate>\r\n    <StartWhenAvailable>true</StartWhenAvailable>\r\n    <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>\r\n    <IdleSettings>\r\n      <StopOnIdleEnd>false</StopOnIdleEnd>\r\n      <RestartOnIdle>false</RestartOnIdle>\r\n    </IdleSettings>\r\n    <AllowStartOnDemand>true</AllowStartOnDemand>\r\n    <Enabled>true</Enabled>\r\n    <Hidden>true</Hidden>\r\n    <RunOnlyIfIdle>false</RunOnlyIfIdle>\r\n    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>\r\n    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>\r\n    <WakeToRun>false</WakeToRun>\r\n    <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>\r\n    <Priority>7</Priority>\r\n    <RestartOnFailure>\r\n      <Interval>PT2M</Interval>\r\n      <Count>3</Count>\r\n    </RestartOnFailure>\r\n  </Settings>\r\n  <Actions Context=\"LocalSystem\">\r\n    <Exec>\r\n      <Command>%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd</Command>\r\n    <Arguments>Task</Arguments>\r\n    </Exec>\r\n  </Actions>\r\n</Task>\r\n:run_once:\r\n\r\n:renewal_vista:\r\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<Task version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\r\n  <RegistrationInfo>\r\n    <Date>1999-01-01T12:00:00.34375</Date>\r\n    <Author>WindowsAddict</Author>\r\n    <Description>Online K-M-S Activation-Renewal - Weekly Task</Description>\r\n  </RegistrationInfo>\r\n  <Triggers>\r\n    <CalendarTrigger>\r\n      <StartBoundary>1999-01-01T12:00:00.34375</StartBoundary>\r\n      <Enabled>true</Enabled>\r\n      <ScheduleByWeek>\r\n        <DaysOfWeek>\r\n          <Sunday />\r\n        </DaysOfWeek>\r\n        <WeeksInterval>1</WeeksInterval>\r\n      </ScheduleByWeek>\r\n    </CalendarTrigger>\r\n  </Triggers>\r\n  <Principals>\r\n    <Principal id=\"Author\">\r\n      <UserId>S-1-5-18</UserId>\r\n      <RunLevel>HighestAvailable</RunLevel>\r\n    </Principal>\r\n  </Principals>\r\n  <Settings>\r\n    <IdleSettings>\r\n      <Duration>PT10M</Duration>\r\n      <WaitTimeout>PT1H</WaitTimeout>\r\n      <StopOnIdleEnd>true</StopOnIdleEnd>\r\n      <RestartOnIdle>false</RestartOnIdle>\r\n    </IdleSettings>\r\n    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\r\n    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\r\n    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>\r\n    <AllowHardTerminate>true</AllowHardTerminate>\r\n    <StartWhenAvailable>true</StartWhenAvailable>\r\n    <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>\r\n    <NetworkSettings />\r\n    <AllowStartOnDemand>true</AllowStartOnDemand>\r\n    <Enabled>true</Enabled>\r\n    <Hidden>false</Hidden>\r\n    <RunOnlyIfIdle>false</RunOnlyIfIdle>\r\n    <WakeToRun>false</WakeToRun>\r\n    <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>\r\n    <Priority>7</Priority>\r\n    <RestartOnFailure>\r\n      <Interval>PT5M</Interval>\r\n      <Count>3</Count>\r\n    </RestartOnFailure>\r\n  </Settings>\r\n  <Actions Context=\"Author\">\r\n    <Exec>\r\n      <Command>%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd</Command>\r\n      <Arguments>Task</Arguments>\r\n    </Exec>\r\n  </Actions>\r\n</Task>\r\n:renewal_vista:\r\n\r\n:run_once_vista:\r\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<Task version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\r\n  <RegistrationInfo>\r\n    <Date>1999-01-01T12:00:00.34375</Date>\r\n    <Author>WindowsAddict</Author>\r\n    <Description>Online K-M-S Activation Run Once - Run and Delete itself on first Internet Contact</Description>\r\n  </RegistrationInfo>\r\n  <Triggers>\r\n    <LogonTrigger>\r\n      <Enabled>true</Enabled>\r\n    </LogonTrigger>\r\n  </Triggers>\r\n  <Principals>\r\n    <Principal id=\"Author\">\r\n      <UserId>S-1-5-18</UserId>\r\n      <RunLevel>HighestAvailable</RunLevel>\r\n    </Principal>\r\n  </Principals>\r\n  <Settings>\r\n    <IdleSettings>\r\n      <Duration>PT10M</Duration>\r\n      <WaitTimeout>PT1H</WaitTimeout>\r\n      <StopOnIdleEnd>true</StopOnIdleEnd>\r\n      <RestartOnIdle>false</RestartOnIdle>\r\n    </IdleSettings>\r\n    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\r\n    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\r\n    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>\r\n    <AllowHardTerminate>true</AllowHardTerminate>\r\n    <StartWhenAvailable>true</StartWhenAvailable>\r\n    <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>\r\n    <NetworkSettings />\r\n    <AllowStartOnDemand>true</AllowStartOnDemand>\r\n    <Enabled>true</Enabled>\r\n    <Hidden>false</Hidden>\r\n    <RunOnlyIfIdle>false</RunOnlyIfIdle>\r\n    <WakeToRun>false</WakeToRun>\r\n    <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>\r\n    <Priority>7</Priority>\r\n    <RestartOnFailure>\r\n      <Interval>PT5M</Interval>\r\n      <Count>3</Count>\r\n    </RestartOnFailure>\r\n  </Settings>\r\n  <Actions Context=\"Author\">\r\n    <Exec>\r\n      <Command>%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd</Command>\r\n      <Arguments>Task</Arguments>\r\n    </Exec>\r\n  </Actions>\r\n</Task>\r\n:run_once_vista:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get Windows installed key channel\r\n\r\n:k_channel\r\n\r\nset _gvlk=\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%# in ('wmic path %spp% where \"ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' and PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL and Description like '%%KMSCLIENT%%'\" Get Name /value %nul6%') do (echo %%# findstr /i \"Windows\" %nul1% && set _gvlk=1)\r\nif %_wmic% EQU 0 for /f \"tokens=2 delims==\" %%# in ('%psc% \"(([WMISEARCHER]'SELECT Name FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL and Description like ''%%KMSCLIENT%%''').Get()).Name | %% {echo ('Name='+$_)}\" %nul6%') do (echo %%# findstr /i \"Windows\" %nul1% && set _gvlk=1)\r\nexit /b\r\n\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get Product Key from pkeyhelper.dll for future new editions\r\n::  It works on Windows 10 1803 (17134) and later builds.\r\n\r\n:k_pkey\r\n\r\ncall :dk_reflection\r\n\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SkuGetProductKeyForEdition', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [String], [String].MakeByRefType(), [String].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = ''; [void]$TypeBuilder.CreateType()::SkuGetProductKeyForEdition(%1, %2, [ref]$out, [ref]$null); $out\r\n\r\nset pkey=\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (set pkey=%%a)\r\nexit /b\r\n\r\n::  Get channel name for the key which was extracted from pkeyhelper.dll\r\n\r\n:k_pkeychannel\r\n\r\nset k=%1\r\nset m=[Runtime.InteropServices.Marshal]\r\nset p=%SysPath%\\spp\\tokens\\pkeyconfig\\pkeyconfig.xrm-ms\r\n\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('PidGenX', 'pidgenx.dll', 'Public, Static', 1, [int], @([String], [String], [String], [int], [IntPtr], [IntPtr], [IntPtr]), 1, 3);\r\nset d1=%d1% $r = [byte[]]::new(0x04F8); $r[0] = 0xF8; $r[1] = 0x04; $f = %m%::AllocHGlobal(0x04F8); %m%::Copy($r, 0, $f, 0x04F8);\r\nset d1=%d1% [void]$TypeBuilder.CreateType()::PidGenX('%k%', '%p%', '00000', 0, 0, 0, $f); %m%::Copy($f, $r, 0, 0x04F8); %m%::FreeHGlobal($f); [Text.Encoding]::Unicode.GetString($r, 1016, 128)\r\n\r\nset pkeychannel=\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (set pkeychannel=%%a)\r\nexit /b\r\n\r\n:k_gvlk\r\n\r\nfor %%# in (pkeyhelper.dll) do @if \"%%~$PATH:#\"==\"\" exit /b\r\nfor %%# in (Volume:GVLK) do (\r\ncall :k_pkey %osSKU% '%%#'\r\nif defined pkey call :k_pkeychannel !pkey!\r\nif /i \"!pkeychannel!\"==\"%%#\" (\r\nset key=!pkey!\r\nexit /b\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Office version number\r\n::  2nd column = Activation ID\r\n::  3rd column = Product ID from branding.xml\r\n::  4th column = Edition\r\n::  5th column = Other Edition IDs if they are part of the same primary product (For reference only)\r\n::  Separator  = \"_\"\r\n\r\n:msiofficedata\r\n\r\nfor %%# in (\r\n14_4d463c2c-0505-4626-8cdb-a4da82e2d8ed_0015_AccessR\r\n14_745fb377-0a59-4ca9-b9a9-c359557a2c4e_001C_AccessRuntimeR\r\n14_95ab3ec8-4106-4f9d-b632-03c019d1d23f_0015_AccessVL\r\n14_4eaff0d0-c6cb-4187-94f3-c7656d49a0aa_0016_ExcelR_[HSExcelR]\r\n14_71dc86ff-f056-40d0-8ffb-9592705c9b76_0016_ExcelVL\r\n14_7004b7f0-6407-4f45-8eac-966e5f868bde_00BA_GrooveR\r\n14_fdad0dfa-417d-4b4f-93e4-64ea8867b7fd_00BA_GrooveVL\r\n14_7b7d1f17-fdcb-4820-9789-9bec6e377821_0013_HomeBusinessR_[HomeBusinessDemoR]\r\n14_19316117-30a8-4773-8fd9-7f7231f4e060_011E_HomeBusinessSubR\r\n14_09e2d37e-474b-4121-8626-58ad9be5776f_002F_HomeStudentR_[HomeStudentDemoR]\r\n14_ef1da464-01c8-43a6-91af-e4e5713744f9_0044_InfoPathR\r\n14_85e22450-b741-430c-a172-a37962c938af_0044_InfoPathVL\r\n14_14f5946a-debc-4716-babc-7e2c240fec08_000F_MondoR\r\n14_533b656a-4425-480b-8e30-1a2358898350_000F_MondoVL\r\n14_c1ceda8b-c578-4d5d-a4aa-23626be4e234_003D_ProfessionalR_[OEM-SingleImage]Exception\r\n14_3f7aa693-9a7e-44fc-9309-bb3d8e604925_00A1_OneNoteR_[HSOneNoteR]\r\n14_6860b31f-6a67-48b8-84b9-e312b3485c4b_00A1_OneNoteVL\r\n14_fbf4ac36-31c8-4340-8666-79873129cf40_001A_OutlookR\r\n14_a9aeabd8-63b8-4079-a28e-f531807fd6b8_001A_OutlookVL\r\n14_acb51361-c0db-4895-9497-1831c41f31a6_0033_PersonalR_[PersonalDemoR,PersonalPrepaidR]\r\n14_133c8359-4e93-4241-8118-30bb18737ea0_0018_PowerPointR_[HSPowerPointR]\r\n14_38252940-718c-4aa6-81a4-135398e53851_0018_PowerPointVL\r\n14_8b559c37-0117-413e-921b-b853aeb6e210_0014_ProfessionalR_[ProfessionalAcadR,ProfessionalDemoR]\r\n14_725714d7-d58f-4d12-9fa8-35873c6f7215_003B_ProjectProR_[ProjectProMSDNR]\r\n14_4d06f72e-fd50-4bc2-a24b-d448d7f17ef2_011F_ProjectProSubR\r\n14_1cf57a59-c532-4e56-9a7d-ffa2fe94b474_003B_ProjectProVL\r\n14_688f6589-2bd9-424e-a152-b13f36aa6de1_003A_ProjectStdR\r\n14_11b39439-6b93-4642-9570-f2eb81be2238_003A_ProjectStdVL\r\n14_71af7e84-93e6-4363-9b69-699e04e74071_0011_ProPlusR_[ProPlusAcadR,ProPlusMSDNR,Sub4R]\r\n14_e98ef0c0-71c4-42ce-8305-287d8721e26c_011D_ProPlusSubR\r\n14_fdf3ecb9-b56f-43b2-a9b8-1b48b6bae1a7_0011_ProPlusVL_[ProPlusAcadVL]\r\n14_98677603-a668-4fa4-9980-3f1f05f78f69_0019_PublisherR\r\n14_3d014759-b128-4466-9018-e80f6320d9d0_0019_PublisherVL\r\n14_dbe3aee0-5183-4ff7-8142-66050173cb01_008B_SmallBusBasicsR_[SmallBusBasicsMSDNR]\r\n14_8090771e-d41a-4482-929e-de87f1f47e46_008B_SmallBusBasicsVL\r\n14_b78df69e-0966-40b1-ae85-30a5134dedd0_0017_SPDR\r\n14_d3422cfb-8d8b-4ead-99f9-eab0ccd990d7_0012_StandardR\r\n14_1f76e346-e0be-49bc-9954-70ec53a4fcfe_0012_StandardVL_[StandardAcadVL]\r\n14_2745e581-565a-4670-ae90-6bf7c57ffe43_0066_StarterR\r\n14_66cad568-c2dc-459d-93ec-2f3cb967ee34_0057_VisioSIR_Prem[Pro,Std]Exception\r\n14_36756cb8-8e69-4d11-9522-68899507cd6a_0057_VisioSIVL_Prem[Pro,Std]Exception\r\n14_db3bbc9c-ce52-41d1-a46f-1a1d68059119_001B_WordR_[HSWordR]\r\n14_98d4050e-9c98-49bf-9be1-85e12eb3ab13_001B_WordVL\r\n:: Office 2013\r\n15_ab4d047b-97cf-4126-a69f-34df08e2f254_0015_AccessRetail\r\n15_259de5be-492b-44b3-9d78-9645f848f7b0_001C_AccessRuntimeRetail\r\n15_4374022d-56b8-48c1-9bb7-d8f2fc726343_0015_AccessVolume\r\n15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_0016_ExcelRetail\r\n15_ac1ae7fd-b949-4e04-a330-849bc40638cf_0016_ExcelVolume\r\n15_cfaf5356-49e3-48a8-ab3c-e729ab791250_00BA_GrooveRetail\r\n15_4825ac28-ce41-45a7-9e6e-1fed74057601_00BA_GrooveVolume\r\n15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_00E7_HomeBusinessPipcRetail\r\n15_cd256150-a898-441f-aac0-9f8f33390e45_0013_HomeBusinessRetail\r\n15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_00CE_HomeStudentARMRetail\r\n15_ebef9f05-5273-404a-9253-c5e252f50555_00DA_HomeStudentPlusARMRetail\r\n15_98685d21-78bd-4c62-bc4f-653344a63035_002F_HomeStudentRetail\r\n15_44984381-406e-4a35-b1c3-e54f499556e2_0044_InfoPathRetail\r\n15_9e016989-4007-42a6-8051-64eb97110cf2_0044_InfoPathVolume\r\n15_9103f3ce-1084-447a-827e-d6097f68c895_00EA_LyncAcademicRetail\r\n15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_012D_LyncEntryRetail\r\n15_fada6658-bfc6-4c4e-825a-59a89822cda8_012C_LyncRetail\r\n15_e1264e10-afaf-4439-a98b-256df8bb156f_012C_LyncVolume\r\n15_3169c8df-f659-4f95-9cc6-3115e6596e83_000F_MondoRetail\r\n15_f33485a0-310b-4b72-9a0e-b1d605510dbd_000F_MondoVolume\r\n15_3391e125-f6e4-4b1e-899c-a25e6092d40d_00A1_OneNoteFreeRetail\r\n15_8b524bcc-67ea-4876-a509-45e46f6347e8_00A1_OneNoteRetail\r\n15_b067e965-7521-455b-b9f7-c740204578a2_00A1_OneNoteVolume\r\n15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_001A_OutlookRetail\r\n15_8d577c50-ae5e-47fd-a240-24986f73d503_001A_OutlookVolume\r\n15_5aab8561-1686-43f7-9ff5-2c861da58d17_00E6_PersonalPipcRetail\r\n15_17e9df2d-ed91-4382-904b-4fed6a12caf0_0033_PersonalRetail\r\n15_31743b82-bfbc-44b6-aa12-85d42e644d5b_0018_PowerPointRetail\r\n15_e40dcb44-1d5c-4085-8e8f-943f33c4f004_0018_PowerPointVolume\r\n15_4e26cac1-e15a-4467-9069-cb47b67fe191_00E8_ProfessionalPipcRetail\r\n15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_0014_ProfessionalRetail\r\n15_f2435de4-5fc0-4e5b-ac97-34f515ec5ee7_003B_ProjectProRetail\r\n15_ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32_003B_ProjectProVolume\r\n15_5517e6a2-739b-4822-946f-7f0f1c5934b1_003A_ProjectStdRetail\r\n15_2b9e4a37-6230-4b42-bee2-e25ce86c8c7a_003A_ProjectStdVolume\r\n15_064383fa-1538-491c-859b-0ecab169a0ab_0011_ProPlusRetail\r\n15_2b88c4f2-ea8f-43cd-805e-4d41346e18a7_0011_ProPlusVolume\r\n15_c3a0814a-70a4-471f-af37-2313a6331111_0019_PublisherRetail\r\n15_38ea49f6-ad1d-43f1-9888-99a35d7c9409_0019_PublisherVolume\r\n15_ba3e3833-6a7e-445a-89d0-7802a9a68588_0017_SPDRetail\r\n15_32255c0a-16b4-4ce2-b388-8a4267e219eb_0012_StandardRetail\r\n15_a24cca51-3d54-4c41-8a76-4031f5338cb2_0012_StandardVolume\r\n15_15d12ad4-622d-4257-976c-5eb3282fb93d_0051_VisioProRetail\r\n15_3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d_0051_VisioProVolume\r\n15_dae597ce-5823-4c77-9580-7268b93a4b23_0053_VisioStdRetail\r\n15_44a1f6ff-0876-4edb-9169-dbb43101ee89_0053_VisioStdVolume\r\n15_191509f2-6977-456f-ab30-cf0492b1e93a_001B_WordRetail\r\n15_9cedef15-be37-4ff0-a08a-13a045540641_001B_WordVolume\r\n:: Office 365 - 15.0 version\r\n15_befee371-a2f5-4648-85db-a2c55fdf324c_00E9_O365BusinessRetail\r\n15_537ea5b5-7d50-4876-bd38-a53a77caca32_00D6_O365HomePremRetail\r\n15_149dbce7-a48e-44db-8364-a53386cd4580_00D4_O365ProPlusRetail\r\n15_bacd4614-5bef-4a5e-bafc-de4c788037a2_00D5_O365SmallBusPremRetail\r\n:: Office 365 - 16.0 version\r\n16_6337137e-7c07-4197-8986-bece6a76fc33_00E9_O365BusinessRetail\r\n16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_00D6_O365EduCloudRetail\r\n16_537ea5b5-7d50-4876-bd38-a53a77caca32_00D6_O365HomePremRetail\r\n16_149dbce7-a48e-44db-8364-a53386cd4580_00D4_O365ProPlusRetail\r\n16_bacd4614-5bef-4a5e-bafc-de4c788037a2_00D5_O365SmallBusPremRetail\r\n:: Office 2016\r\n16_bfa358b0-98f1-4125-842e-585fa13032e6_0015_AccessRetail\r\n16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_001C_AccessRuntimeRetail\r\n16_3b2fa33f-cd5a-43a5-bd95-f49f3f546b0b_0015_AccessVolume\r\n16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_0016_ExcelRetail\r\n16_685062a7-6024-42e7-8c5f-6bb9e63e697f_0016_ExcelVolume\r\n16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_00E7_HomeBusinessPipcRetail\r\n16_86834d00-7896-4a38-8fae-32f20b86fa2b_0013_HomeBusinessRetail\r\n16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_00CE_HomeStudentARMRetail\r\n16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_00DA_HomeStudentPlusARMRetail\r\n16_c28acdb8-d8b3-4199-baa4-024d09e97c99_002F_HomeStudentRetail\r\n16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_002F_HomeStudentVNextRetail\r\n16_b21367df-9545-4f02-9f24-240691da0e58_000F_MondoRetail\r\n16_2cd0ea7e-749f-4288-a05e-567c573b2a6c_000F_MondoVolume\r\n16_436366de-5579-4f24-96db-3893e4400030_00A3_OneNoteFreeRetail\r\n16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_00A1_OneNoteRetail\r\n16_23b672da-a456-4860-a8f3-e062a501d7e8_00A1_OneNoteVolume\r\n16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_001A_OutlookRetail\r\n16_50059979-ac6f-4458-9e79-710bcb41721a_001A_OutlookVolume\r\n16_5aab8561-1686-43f7-9ff5-2c861da58d17_00E6_PersonalPipcRetail\r\n16_a9f645a1-0d6a-4978-926a-abcb363b72a6_0033_PersonalRetail\r\n16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_0018_PowerPointRetail\r\n16_9b4060c9-a7f5-4a66-b732-faf248b7240f_0018_PowerPointVolume\r\n16_4e26cac1-e15a-4467-9069-cb47b67fe191_00E8_ProfessionalPipcRetail\r\n16_d64edc00-7453-4301-8428-197343fafb16_0014_ProfessionalRetail\r\n16_0f42f316-00b1-48c5-ada4-2f52b5720ad0_003B_ProjectProRetail\r\n16_82f502b5-b0b0-4349-bd2c-c560df85b248_003B_ProjectProVolume\r\n16_16728639-a9ab-4994-b6d8-f81051e69833_003B_ProjectProXVolume\r\n16_e9f0b3fc-962f-4944-ad06-05c10b6bcd5e_003A_ProjectStdRetail\r\n16_82e6b314-2a62-4e51-9220-61358dd230e6_003A_ProjectStdVolume\r\n16_431058f0-c059-44c5-b9e7-ed2dd46b6789_003A_ProjectStdXVolume\r\n16_de52bd50-9564-4adc-8fcb-a345c17f84f9_0011_ProPlusRetail\r\n16_c47456e3-265d-47b6-8ca0-c30abbd0ca36_0011_ProPlusVolume\r\n16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_0019_PublisherRetail\r\n16_fcc1757b-5d5f-486a-87cf-c4d6dedb6032_0019_PublisherVolume\r\n16_971cd368-f2e1-49c1-aedd-330909ce18b6_012D_SkypeforBusinessEntryRetail\r\n16_418d2b9f-b491-4d7f-84f1-49e27cc66597_012C_SkypeforBusinessRetail\r\n16_03ca3b9a-0869-4749-8988-3cbc9d9f51bb_012C_SkypeforBusinessVolume\r\n16_9103f3ce-1084-447a-827e-d6097f68c895_012C_SkypeServiceBypassRetail\r\n16_4a31c291-3a12-4c64-b8ab-cd79212be45e_0012_StandardRetail\r\n16_0ed94aac-2234-4309-ba29-74bdbb887083_0012_StandardVolume\r\n16_2dfe2075-2d04-4e43-816a-eb60bbb77574_0051_VisioProRetail\r\n16_295b2c03-4b1c-4221-b292-1411f468bd02_0051_VisioProVolume\r\n16_0594dc12-8444-4912-936a-747ca742dbdb_0051_VisioProXVolume\r\n16_c76dbcbc-d71b-4f45-b5b3-b7494cb4e23e_0053_VisioStdRetail\r\n16_44151c2d-c398-471f-946f-7660542e3369_0053_VisioStdVolume\r\n16_1d1c6879-39a3-47a5-9a6d-aceefa6a289d_0053_VisioStdXVolume\r\n16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_001B_WordRetail\r\n16_c3000759-551f-4f4a-bcac-a4b42cbf1de2_001B_WordVolume\r\n) do (\r\nfor /f \"tokens=1-5 delims=_\" %%A in (\"%%#\") do (\r\n\r\nif \"%oVer%\"==\"%%A\" (\r\nreg query \"%1\\Registration\\{%%B}\" /v ProductCode %nul2% | find /i \"-%%C-\" %nul% && (\r\nreg query \"%1\\Common\\InstalledPackages\" %nul2% | find /i \"-%%C-\" %nul% && (\r\nif defined _oIds (set _oIds=!_oIds! %%D) else (set _oIds=%%D)\r\nif /i 003D==%%C set SingleImage=1\r\n)\r\n)\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = GVLK / Free Office products keys\r\n::  3rd column = In case of Windows, its SKU ID. In case of Office, its Office version\r\n::  4th column = Edition ID\r\n::  5th column = In case of Windows, its Build Branch name in case same Edition ID is used in different OS versions with different key (For reference only)\r\n::               In case of Office, its either a key type if its a free Office product or Retail product names that needs to be converted to the Edition ID mentioned in 4th column\r\n::               In Office 2010, one highest VL edition from each primary product ID is selected, that's why Visio Prem key is mentioned but not for Visio Pro, Std\r\n::  Separator  = \"_\"\r\n\r\n:ksdata\r\n\r\nset f=\r\nfor %%# in (\r\n:: Windows 10/11\r\n73111121-5638-40f6-bc11-f1d7b0d64300_NPPR9-FWDCX-D2C8J-H872K-2Y%f%T43___4_Enterprise\r\ne272e3e2-732f-4c65-a8f0-484747d0d947_DPH2V-TTNVB-4X9Q3-TJR4H-KH%f%JW4__27_EnterpriseN\r\n2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX__48_Professional\r\na80b5abf-76ad-428b-b05d-a47d2dffeebf_MH37W-N47XK-V7XM9-C7227-GC%f%QG9__49_ProfessionalN\r\n7b9e1751-a8da-4f75-9560-5fadfe3d8e38_3KHY7-WNT83-DGQKR-F7HPR-84%f%4BM__98_CoreN\r\na9107544-f4a0-4053-a96a-1479abdef912_PVMJN-6DFY6-9CCP6-7BKTT-D3%f%WVR__99_CoreCountrySpecific\r\ncd918a57-a41b-4c82-8dce-1a538e221a83_7HNRX-D7KGG-3K4RQ-4WPJ4-YT%f%DFH_100_CoreSingleLanguage\r\n58e97c99-f377-4ef1-81d5-4ad5522b5fd8_TX9XD-98N7V-6WMQ6-BX7FG-H8%f%Q99_101_Core\r\ne0c42288-980c-4788-a014-c080d2e1926e_NW6C2-QMPVW-D7KKK-3GKT6-VC%f%FB2_121_Education\r\n3c102355-d027-42c6-ad23-2e7ef8a02585_2WH4N-8QGBV-H22JP-CT43Q-MD%f%WWJ_122_EducationN\r\n32d2fab3-e4a8-42c2-923b-4bf4fd13e6ee_M7XTQ-FN8P6-TTKYV-9D4CC-J4%f%62D_125_EnterpriseS_RS5,VB,Ge\r\n2d5a5a60-3040-48bf-beb0-fcd770c20ce0_DCPHK-NFMTC-H88MJ-PFHPY-QJ%f%4BJ_125_EnterpriseS_RS1\r\n7b51a46c-0c04-4e8f-9af4-8496cca90d5e_WNMTR-4C88C-JK8YV-HQ7T2-76%f%DF9_125_EnterpriseS_TH1\r\n7103a333-b8c8-49cc-93ce-d37c09687f92_92NFX-8DJQP-P6BBQ-THF9C-7C%f%G2H_126_EnterpriseSN_RS5,VB,Ge\r\n9f776d83-7156-45b2-8a5c-359b9c9f22a3_QFFDN-GRT3P-VKWWX-X7T3R-8B%f%639_126_EnterpriseSN_RS1\r\n87b838b7-41b6-4590-8318-5797951d8529_2F77B-TNFGY-69QQF-B8YKP-D6%f%9TJ_126_EnterpriseSN_TH1\r\n82bbc092-bc50-4e16-8e18-b74fc486aec3_NRG8B-VKK3Q-CXVCJ-9G2XF-6Q%f%84J_161_ProfessionalWorkstation\r\n4b1571d3-bafb-4b40-8087-a961be2caf65_9FNHH-K3HBT-3W4TD-6383H-6X%f%YWF_162_ProfessionalWorkstationN\r\n3f1afc82-f8ac-4f6c-8005-1d233e606eee_6TP4R-GNPTD-KYYHQ-7B7DP-J4%f%47Y_164_ProfessionalEducation\r\n5300b18c-2e33-4dc2-8291-47ffcec746dd_YVWGF-BXNMC-HTQYQ-CPQ99-66%f%QFC_165_ProfessionalEducationN\r\ne0b2d383-d112-413f-8a80-97f373a5820c_YYVX9-NTFWV-6MDM3-9PT4T-4M%f%68B_171_EnterpriseG\r\ne38454fb-41a4-4f59-a5dc-25080e354730_44RPN-FTY23-9VTTB-MP9BX-T8%f%4FV_172_EnterpriseGN\r\nec868e65-fadf-4759-b23e-93fe37f2cc29_CPWHC-NT2C7-VYW78-DHDB2-PG%f%3GK_175_ServerRdsh_RS5\r\ne4db50ea-bda1-4566-b047-0ca50abc6f07_7NBT4-WGBQX-MP4H7-QXFF8-YP%f%3KX_175_ServerRdsh_RS3\r\n0df4f814-3f57-4b8b-9a9d-fddadcd69fac_NBTWJ-3DR69-3C4V8-C26MC-GQ%f%9M6_183_CloudE\r\n59eb965c-9150-42b7-a0ec-22151b9897c5_KBN8V-HFGQ4-MGXVD-347P6-PD%f%QGT_191_IoTEnterpriseS_VB,NI\r\nd30136fc-cb4b-416e-a23d-87207abc44a9_6XN7V-PCBDC-BDBRH-8DQY7-G6%f%R44_202_CloudEditionN\r\nca7df2e3-5ea0-47b8-9ac1-b1be4d8edd69_37D7F-N49CB-WQR8W-TBJ73-FM%f%8RX_203_CloudEdition\r\n:: Windows 2016/19/22/25 LTSC/SAC\r\n7dc26449-db21-4e09-ba37-28f2958506a6_TVRH6-WHNXV-R9WG3-9XRFY-MY%f%832___7_ServerStandard_Ge\r\n9bd77860-9b31-4b7b-96ad-2564017315bf_VDYBN-27WPP-V4HQT-9VMD4-VM%f%K7H___7_ServerStandard_FE\r\nde32eafd-aaee-4662-9444-c1befb41bde2_N69G4-B89J2-4G8F4-WWYCC-J4%f%64C___7_ServerStandard_RS5\r\n8c1c5410-9f39-4805-8c9d-63a07706358f_WC2BQ-8NRM3-FDDYY-2BFGV-KH%f%KQY___7_ServerStandard_RS1\r\nc052f164-cdf6-409a-a0cb-853ba0f0f55a_D764K-2NDRG-47T6Q-P8T8W-YP%f%6DF___8_ServerDatacenter_Ge\r\nef6cfc9f-8c5d-44ac-9aad-de6a2ea0ae03_WX4NM-KYWYW-QJJR4-XV3QB-6V%f%M33___8_ServerDatacenter_FE\r\n34e1ae55-27f8-4950-8877-7a03be5fb181_WMDGN-G9PQG-XVVXX-R3X43-63%f%DFG___8_ServerDatacenter_RS5\r\n21c56779-b449-4d20-adfc-eece0e1ad74b_CB7KF-BWN84-R7R2Y-793K2-8X%f%DDG___8_ServerDatacenter_RS1\r\n034d3cbb-5d4b-4245-b3f8-f84571314078_WVDHN-86M7X-466P6-VHXV7-YY%f%726__50_ServerSolution_RS5\r\n2b5a1b0f-a5ab-4c54-ac2f-a6d94824a283_JCKRF-N37P4-C2D82-9YXRT-4M%f%63B__50_ServerSolution_RS1\r\n7b4433f4-b1e7-4788-895a-c45378d38253_QN4C6-GBJD2-FB422-GHWJK-GJ%f%G2R_110_ServerCloudStorage\r\n8de8eb62-bbe0-40ac-ac17-f75595071ea3_GRFBW-QNDC4-6QBHG-CCK3B-2P%f%R88_120_ServerARM64_RS5\r\n43d9af6e-5e86-4be8-a797-d072a046896c_K9FYF-G6NCK-73M32-XMVPY-F9%f%DRR_120_ServerARM64_RS4\r\n39e69c41-42b4-4a0a-abad-8e3c10a797cc_QFND9-D3Y9C-J3KKY-6RPVP-2D%f%PYV_145_ServerDatacenterACor_FE\r\n90c362e5-0da1-4bfd-b53b-b87d309ade43_6NMRW-2C8FM-D24W7-TQWMY-CW%f%H2D_145_ServerDatacenterACor_RS5\r\ne49c08e7-da82-42f8-bde2-b570fbcae76c_2HXDN-KRXHB-GPYC7-YCKFJ-7F%f%VDG_145_ServerDatacenterACor_RS3\r\nf5e9429c-f50b-4b98-b15c-ef92eb5cff39_67KN8-4FYJW-2487Q-MQ2J7-4C%f%4RG_146_ServerStandardACor_FE\r\n73e3957c-fc0c-400d-9184-5f7b6f2eb409_N2KJX-J94YW-TQVFB-DG9YT-72%f%4CC_146_ServerStandardACor_RS5\r\n61c5ef22-f14f-4553-a824-c4b31e84b100_PTXN8-JFHJM-4WC78-MPCBR-9W%f%4KR_146_ServerStandardACor_RS3\r\n45b5aff2-60a0-42f2-bc4b-ec6e5f7b527e_FCNV3-279Q9-BQB46-FTKXX-9H%f%PRH_168_ServerAzureCor_Ge\r\n8c8f0ad3-9a43-4e05-b840-93b8d1475cbc_6N379-GGTMK-23C6M-XVVTC-CK%f%FRQ_168_ServerAzureCor_FE\r\na99cc1f0-7719-4306-9645-294102fbff95_FDNH6-VW9RW-BXPJ7-4XTYG-23%f%9TB_168_ServerAzureCor_RS5\r\n3dbf341b-5f6c-4fa7-b936-699dce9e263f_VP34G-4NPPG-79JTQ-864T4-R3%f%MQX_168_ServerAzureCor_RS1\r\nc2e946d1-cfa2-4523-8c87-30bc696ee584_XGN3F-F394H-FD2MY-PP6FD-8M%f%CRC_407_ServerTurbine_Ge\r\n19b5e0fb-4431-46bc-bac1-2f1873e4ae73_NTBV8-9K7Q8-V27C6-M2BTV-KH%f%MXV_407_ServerTurbine_RS5\r\n:: Windows 8.1\r\n81671aaf-79d1-4eb1-b004-8cbbe173afea_MHF9N-XY6XB-WVXMC-BTDCT-MK%f%KG7___4_Enterprise\r\n113e705c-fa49-48a4-beea-7dd879b46b14_TT4HM-HN7YT-62K67-RGRQJ-JF%f%FXW__27_EnterpriseN\r\nc06b6981-d7fd-4a35-b7b4-054742b7af67_GCRJD-8NW9H-F2CDX-CCM8D-9D%f%6T9__48_Professional\r\n7476d79f-8e48-49b4-ab63-4d0b813a16e4_HMCNV-VVBFX-7HMBH-CTY9B-B4%f%FXY__49_ProfessionalN\r\nf7e88590-dfc7-4c78-bccb-6f3865b99d1a_VHXM3-NR6FT-RY6RT-CK882-KW%f%2CJ__86_EmbeddedIndustryA\r\n0ab82d54-47f4-4acb-818c-cc5bf0ecb649_NMMPB-38DD4-R2823-62W8D-VX%f%KJB__89_EmbeddedIndustry\r\ncd4e2d9f-5059-4a50-a92d-05d5bb1267c7_FNFKF-PWTVT-9RC8H-32HB2-JB%f%34X__91_EmbeddedIndustryE\r\nffee456a-cd87-4390-8e07-16146c672fd0_XYTND-K6QKT-K2MRH-66RTM-43%f%JKP__97_CoreARM\r\n78558a64-dc19-43fe-a0d0-8075b2a370a3_7B9N3-D94CG-YTVHR-QBPX3-RJ%f%P64__98_CoreN\r\ndb78b74f-ef1c-4892-abfe-1e66b8231df6_NCTT7-2RGK8-WMHRF-RY7YQ-JT%f%XG3__99_CoreCountrySpecific\r\nc72c6a1d-f252-4e7e-bdd1-3fca342acb35_BB6NG-PQ82V-VRDPW-8XVD2-V8%f%P66_100_CoreSingleLanguage\r\nfe1c3238-432a-43a1-8e25-97e7d1ef10f3_M9Q9P-WNJJT-6PXPY-DWX8H-6X%f%WKK_101_Core\r\n096ce63d-4fac-48a9-82a9-61ae9e800e5f_789NJ-TQK6T-6XTH8-J39CJ-J8%f%D3P_103_ProfessionalWMC\r\ne9942b32-2e55-4197-b0bd-5ff58cba8860_3PY8R-QHNP9-W7XQD-G6DPH-3J%f%2C9_111_CoreConnected\r\nc6ddecd6-2354-4c19-909b-306a3058484e_Q6HTR-N24GM-PMJFP-69CD8-2G%f%XKR_113_CoreConnectedN\r\nb8f5e3a3-ed33-4608-81e1-37d6c9dcfd9c_KF37N-VDV38-GRRTV-XH8X6-6F%f%3BB_115_CoreConnectedSingleLanguage\r\nba998212-460a-44db-bfb5-71bf09d1c68b_R962J-37N87-9VVK2-WJ74P-XT%f%MHR_116_CoreConnectedCountrySpecific\r\ne58d87b5-8126-4580-80fb-861b22f79296_MX3RK-9HNGX-K3QKC-6PJ3F-W8%f%D7B_112_ProfessionalStudent\r\ncab491c7-a918-4f60-b502-dab75e334f40_TNFGH-2R6PB-8XM3K-QYHX2-J4%f%296_114_ProfessionalStudentN\r\n:: Windows Server 2012 R2\r\nb3ca044e-a358-4d68-9883-aaa2941aca99_D2N9P-3P6X9-2R39C-7RTCD-MD%f%VJX___7_ServerStandard\r\n00091344-1ea4-4f37-b789-01750ba6988c_W3GGN-FT8W3-Y4M27-J84CP-Q3%f%VJ9___8_ServerDatacenter\r\n21db6ba4-9a7b-4a14-9e29-64a60c59301d_KNC87-3J2TX-XB4WP-VCPJV-M4%f%FWM__50_ServerSolution\r\nb743a2be-68d4-4dd3-af32-92425b7bb623_3NPTF-33KPT-GGBPR-YX76B-39%f%KDD_110_ServerCloudStorage\r\n:: Windows 8\r\n458e1bec-837a-45f6-b9d5-925ed5d299de_32JNW-9KQ84-P47T8-D8GGY-CW%f%CK7___4_Enterprise\r\ne14997e7-800a-4cf7-ad10-de4b45b578db_JMNMF-RHW7P-DMY6X-RF3DR-X2%f%BQT__27_EnterpriseN\r\na98bcd6d-5343-4603-8afe-5908e4611112_NG4HW-VH26C-733KW-K6F98-J8%f%CK4__48_Professional\r\nebf245c1-29a8-4daf-9cb1-38dfc608a8c8_XCVCF-2NXM9-723PB-MHCB7-2R%f%YQQ__49_ProfessionalN\r\n10018baf-ce21-4060-80bd-47fe74ed4dab_RYXVT-BNQG7-VD29F-DBMRY-HT%f%73M__89_EmbeddedIndustry\r\n18db1848-12e0-4167-b9d7-da7fcda507db_NKB3R-R2F8T-3XCDP-7Q2KW-XW%f%YQ2__91_EmbeddedIndustryE\r\naf35d7b7-5035-4b63-8972-f0b747b9f4dc_DXHJF-N9KQX-MFPVR-GHGQK-Y7%f%RKV__97_CoreARM\r\n197390a0-65f6-4a95-bdc4-55d58a3b0253_8N2M2-HWPGY-7PGT9-HGDD8-GV%f%GGY__98_CoreN\r\n9d5584a2-2d85-419a-982c-a00888bb9ddf_4K36P-JN4VD-GDC6V-KDT89-DY%f%FKP__99_CoreCountrySpecific\r\n8860fcd4-a77b-4a20-9045-a150ff11d609_2WN2H-YGCQR-KFX6K-CD6TF-84%f%YXQ_100_CoreSingleLanguage\r\nc04ed6bf-55c8-4b47-9f8e-5a1f31ceee60_BN3D2-R7TKB-3YPBD-8DRP2-27%f%GG4_101_Core\r\na00018a3-f20f-4632-bf7c-8daa5351c914_GNBB8-YVD74-QJHX6-27H4K-8Q%f%HDG_103_ProfessionalWMC\r\n:: Windows Server 2012\r\nf0f5ec41-0d55-4732-af02-440a44a3cf0f_XC9B7-NBPP2-83J2H-RHMBY-92%f%BT4___7_ServerStandard\r\nd3643d60-0c42-412d-a7d6-52e6635327f6_48HP8-DN98B-MYWDG-T2DCC-8W%f%83P___8_ServerDatacenter\r\n8f365ba6-c1b9-4223-98fc-282a0756a3ed_HTDQM-NBMMG-KGYDT-2DTKT-J2%f%MPV__50_ServerSolution\r\n7d5486c7-e120-4771-b7f1-7b56c6d3170c_HM7DN-YVMH3-46JC3-XYTG7-CY%f%QJJ__76_ServerMultiPointStandard\r\n95fd1c83-7df5-494a-be8b-1300e1c9d1cd_XNH6W-2V9GX-RGJ4K-Y8X6F-QG%f%J2G__77_ServerMultiPointPremium\r\n:: Windows 7\r\nae2ee509-1b34-41c0-acb7-6d4650168915_33PXH-7Y6KF-2VJC9-XBBR8-HV%f%THH___4_Enterprise\r\n1cb6d605-11b3-4e14-bb30-da91c8e3983a_YDRBP-3D83W-TY26F-D46B2-XC%f%KRJ__27_EnterpriseN\r\nb92e9980-b9d5-4821-9c94-140f632f6312_FJ82H-XT6CR-J8D7P-XQJJ2-GP%f%DD4__48_Professional\r\n54a09a0d-d57b-4c10-8b69-a842d6590ad5_MRPKT-YTG23-K7D7T-X2JMM-QY%f%7MG__49_ProfessionalN\r\ndb537896-376f-48ae-a492-53d0547773d0_YBYF6-BHCR3-JPKRB-CDW7B-F9%f%BK4__65_Embedded_POSReady\r\naa6dd3aa-c2b4-40e2-a544-a6bbb3f5c395_73KQT-CD9G6-K7TQG-66MRP-CQ%f%22C__65_Embedded_ThinPC\r\n5a041529-fef8-4d07-b06f-b59b573b32d2_W82YF-2Q76Y-63HXB-FGJG9-GF%f%7QX__69_ProfessionalE\r\n46bbed08-9c7b-48fc-a614-95250573f4ea_C29WB-22CC8-VJ326-GHFJW-H9%f%DH4__70_EnterpriseE\r\n:: Windows Server 2008 R2\r\n68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC___7_ServerStandard\r\n7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648___8_ServerDatacenter\r\n620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y__10_ServerEnterprise\r\n7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648__12_ServerDatacenterCore\r\n68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC__13_ServerStandardCore\r\n620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y__14_ServerEnterpriseCore\r\n8a26851c-1c7e-48d3-a687-fbca9b9ac16b_GT63C-RJFQ3-4GMB6-BRFB9-CB%f%83V__15_ServerEnterpriseIA64\r\na78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4__17_ServerWeb\r\ncda18cf3-c196-46ad-b289-60c072869994_TT8MH-CG224-D3D7Q-498W2-9Q%f%CTX__18_ServerHPC\r\na78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4__29_ServerWebCore\r\nf772515c-0e87-48d5-a676-e6962c3e1195_736RG-XDKJK-V34PF-BHK87-J6%f%X3K__56_ServerEmbeddedSolution\r\n:: Windows Vista\r\ncfd8ff08-c0d7-452b-9f60-ef5c70c32094_VKK3X-68KWM-X2YGT-QR4M6-4B%f%WMV___4_Enterprise\r\n4f3d1606-3fea-4c01-be3c-8d671c401e3b_YFKBB-PQJJV-G996G-VWGXY-2V%f%3X8___6_Business\r\n2c682dc2-8b68-4f63-a165-ae291d4cf138_HMBQG-8H2RH-C77VX-27R82-VM%f%QBT__16_BusinessN\r\nd4f54950-26f2-4fb4-ba21-ffab16afcade_VTC42-BM838-43QHV-84HX6-XJ%f%XKV__27_EnterpriseN\r\n:: Windows Server 2008\r\nad2542d4-9154-4c6d-8a44-30f11ee96989_TM24T-X9RMF-VWXK6-X8JC9-BF%f%GM2___7_ServerStandard\r\n68b6e220-cf09-466b-92d3-45cd964b9509_7M67G-PC374-GR742-YH8V4-TC%f%BY3___8_ServerDatacenter\r\nc1af4d90-d1bc-44ca-85d4-003ba33db3b9_YQGMW-MPWTJ-34KDK-48M3W-X4%f%Q6V__10_ServerEnterprise\r\n01ef176b-3e0d-422a-b4f8-4ea880035e8f_4DWFP-JF3DJ-B7DTH-78FJB-PD%f%RHK__15_ServerEnterpriseIA64\r\nddfa9f7c-f09e-40b9-8c1a-be877a9a7f4b_WYR28-R7TFJ-3X2YQ-YCY4H-M2%f%49D__17_ServerWeb\r\n7afb1156-2c1d-40fc-b260-aab7442b62fe_RCTX3-KWVHP-BR6TB-RB6DM-6X%f%7HP__18_ServerComputeCluster\r\n2401e3d0-c50a-4b58-87b2-7e794b7d2607_W7VD6-7JFBR-RX26B-YKQ3Y-6F%f%FFJ__36_ServerStandardV\r\nfd09ef77-5647-4eff-809c-af2b64659a45_22XQ2-VRXRG-P8D42-K34TD-G3%f%QQC__37_ServerDatacenterV\r\n8198490a-add0-47b2-b3ba-316b12d647b4_39BXF-X8Q23-P2WWT-38T2F-G3%f%FPG__38_ServerEnterpriseV\r\n::=======================================================================================================================================\r\n:: Office 2010\r\n8ce7e872-188c-4b98-9d90-f8f90b7aad02_V7Y44-9T38C-R2VJK-666HK-T7%f%DDX__14_AccessVL\r\ncee5d470-6e3b-4fcc-8c2b-d17428568a9f_H62QG-HXVKF-PP4HP-66KMR-CW%f%9BM__14_ExcelVL\r\n8947d0b8-c33b-43e1-8c56-9b674c052832_QYYW6-QP4CB-MBV6G-HYMCJ-4T%f%3J4__14_GrooveVL\r\nca6b6639-4ad6-40ae-a575-14dee07f6430_K96W8-67RPQ-62T9Y-J8FQJ-BT%f%37T__14_InfoPathVL\r\n09ed9640-f020-400a-acd8-d7d867dfd9c2_YBJTT-JG6MD-V9Q7P-DBKXJ-38%f%W9R__14_MondoVL\r\nab586f5c-5256-4632-962f-fefd8b49e6f4_Q4Y4M-RHWJM-PY37F-MTKWH-D3%f%XHX__14_OneNoteVL\r\necb7c192-73ab-4ded-acf4-2399b095d0cc_7YDC2-CWM8M-RRTJC-8MDVC-X3%f%DWQ__14_OutlookVL\r\n45593b1d-dfb1-4e91-bbfb-2d5d0ce2227a_RC8FX-88JRY-3PF7C-X8P67-P4%f%VTT__14_PowerPointVL\r\ndf133ff7-bf14-4f95-afe3-7b48e7e331ef_YGX6F-PGV49-PGW3J-9BTGG-VH%f%KC6__14_ProjectProVL\r\n5dc7bf61-5ec9-4996-9ccb-df806a2d0efe_4HP3K-88W3F-W2K3D-6677X-F9%f%PGB__14_ProjectStdVL\r\n6f327760-8c5c-417c-9b61-836a98287e0c_VYBBJ-TRJPB-QFQRF-QFT4D-H3%f%GVB__14_ProPlusVL\r\nb50c4f75-599b-43e8-8dcd-1081a7967241_BFK7F-9MYHM-V68C7-DRQ66-83%f%YTP__14_PublisherVL\r\nea509e87-07a1-4a45-9edc-eba5a39f36af_D6QFG-VBYP2-XQHM7-J97RH-VV%f%RCK__14_SmallBusBasicsVL\r\n9da2a678-fb6b-4e67-ab84-60dd6a9c819a_V7QKV-4XVVR-XYV4D-F7DFM-8R%f%6BM__14_StandardVL\r\n92236105-bb67-494f-94c7-7f7a607929bd_D9DWC-HPYVV-JGF4P-BTWQB-WX%f%8BJ__14_VisioSIVL\r\n2d0882e7-a4e7-423b-8ccc-70d91e0158b1_HVHB3-C6FV7-KQX9W-YQG79-CR%f%Y7T__14_WordVL\r\n:: Office 2013\r\n6ee7622c-18d8-4005-9fb7-92db644a279b_NG2JY-H4JBT-HQXYP-78QH9-4J%f%M2D__15_AccessVolume_-AccessRetail-\r\n259de5be-492b-44b3-9d78-9645f848f7b0_X3XNB-HJB7K-66THH-8DWQ3-XH%f%GJP__15_AccessRuntimeRetail_[Bypass]\r\nf7461d52-7c2b-43b2-8744-ea958e0bd09a_VGPNG-Y7HQW-9RHP7-TKPV3-BG%f%7GB__15_ExcelVolume_-ExcelRetail-\r\nfb4875ec-0c6b-450f-b82b-ab57d8d1677f_H7R7V-WPNXQ-WCYYC-76BGV-VT%f%7GH__15_GrooveVolume_-GrooveRetail-\r\na30b8040-d68a-423f-b0b5-9ce292ea5a8f_DKT8B-N7VXH-D963P-Q4PHY-F8%f%894__15_InfoPathVolume_-InfoPathRetail-\r\n9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY__15_LyncAcademicRetail_[PrepidBypass]\r\nff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_N42BF-CBY9F-W2C7R-X397X-DY%f%FQW__15_LyncEntryRetail_[PrepidBypass]\r\n1b9f11e3-c85c-4e1b-bb29-879ad2c909e3_2MG3G-3BNTT-3MFW9-KDQW3-TC%f%K7R__15_LyncVolume_-LyncRetail-\r\n1dc00701-03af-4680-b2af-007ffc758a1f_CWH2Y-NPYJW-3C7HD-BJQWB-G2%f%8JJ__15_MondoRetail\r\ndc981c6b-fc8e-420f-aa43-f8f33e5c0923_42QTK-RN8M7-J3C4G-BBGYM-88%f%CYV__15_MondoVolume_-O365BusinessRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-\r\n3391e125-f6e4-4b1e-899c-a25e6092d40d_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%FF4__15_OneNoteFreeRetail_[Bypass]\r\nefe1f3e6-aea2-4144-a208-32aa872b6545_TGN6P-8MMBC-37P2F-XHXXK-P3%f%4VW__15_OneNoteVolume_-OneNoteRetail-\r\n771c3afa-50c5-443f-b151-ff2546d863a0_QPN8Q-BJBTJ-334K3-93TGY-2P%f%MBT__15_OutlookVolume_-OutlookRetail-\r\n8c762649-97d1-4953-ad27-b7e2c25b972e_4NT99-8RJFH-Q2VDH-KYG2C-4R%f%D4F__15_PowerPointVolume_-PowerPointRetail-\r\n4a5d124a-e620-44ba-b6ff-658961b33b9a_FN8TT-7WMH6-2D4X9-M337T-23%f%42K__15_ProjectProVolume_-ProjectProRetail-\r\n427a28d1-d17c-4abf-b717-32c780ba6f07_6NTH3-CW976-3G3Y2-JK3TX-8Q%f%HTT__15_ProjectStdVolume_-ProjectStdRetail-\r\nb322da9c-a2e2-4058-9e4e-f59a6970bd69_YC7DK-G2NP3-2QQC3-J6H88-GV%f%GXT__15_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-\r\n00c79ff1-6850-443d-bf61-71cde0de305f_PN2WF-29XG2-T9HJ7-JQPJR-FC%f%XK4__15_PublisherVolume_-PublisherRetail-\r\nba3e3833-6a7e-445a-89d0-7802a9a68588_3NY6J-WHT3F-47BDV-JHF36-23%f%43W__15_SPDRetail_[PrepidBypass]\r\nb13afb38-cd79-4ae5-9f7f-eed058d750ca_KBKQT-2NMXY-JJWGP-M62JB-92%f%CD4__15_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-PersonalPipcRetail-PersonalRetail-\r\ne13ac10e-75d0-4aff-a0cd-764982cf541c_C2FG9-N6J68-H8BTJ-BW3QX-RM%f%3B3__15_VisioProVolume_-VisioProRetail-\r\nac4efaf0-f81f-4f61-bdf7-ea32b02ab117_J484Y-4NKBF-W2HMG-DBMJC-PG%f%WR7__15_VisioStdVolume_-VisioStdRetail-\r\nd9f5b1c6-5386-495a-88f9-9ad6b41ac9b3_6Q7VD-NX8JD-WJ2VH-88V73-4G%f%BJ7__15_WordVolume_-WordRetail-\r\n:: Office 2016\r\n9d9faf9e-d345-4b49-afce-68cb0a539c7c_RNB7V-P48F4-3FYY6-2P3R3-63%f%BQV__16_AccessRuntimeRetail_[PrepidBypass]\r\n67c0fc0c-deba-401b-bf8b-9c8ad8395804_GNH9Y-D2J4T-FJHGG-QRVH7-QP%f%FDW__16_AccessVolume_-AccessRetail-\r\nc3e65d36-141f-4d2f-a303-a842ee756a29_9C2PK-NWTVB-JMPW8-BFT28-7F%f%TBF__16_ExcelVolume_-ExcelRetail-\r\ne914ea6e-a5fa-4439-a394-a9bb3293ca09_DMTCJ-KNRKX-26982-JYCKT-P7%f%KB6__16_MondoRetail\r\n9caabccb-61b1-4b4b-8bec-d10a3c3ac2ce_HFTND-W9MK4-8B7MJ-B6C4G-XQ%f%BR2__16_MondoVolume_-O365AppsBasicRetail-O365BusinessRetail-O365EduCloudRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-\r\n436366de-5579-4f24-96db-3893e4400030_XYNTG-R96FY-369HX-YFPHY-F9%f%CPM__16_OneNoteFreeRetail_[Bypass]\r\nd8cace59-33d2-4ac7-9b1b-9b72339c51c8_DR92N-9HTF2-97XKM-XW2WJ-XW%f%3J6__16_OneNoteVolume_-OneNoteRetail-OneNote2021Retail-\r\nec9d9265-9d1e-4ed0-838a-cdc20f2551a1_R69KK-NTPKF-7M3Q4-QYBHW-6M%f%T9B__16_OutlookVolume_-OutlookRetail-\r\nd70b1bba-b893-4544-96e2-b7a318091c33_J7MQP-HNJ4Y-WJ7YM-PFYGF-BY%f%6C6__16_PowerPointVolume_-PowerPointRetail-\r\n4f414197-0fc2-4c01-b68a-86cbb9ac254c_YG9NW-3K39V-2T3HJ-93F3Q-G8%f%3KT__16_ProjectProVolume_-ProjectProRetail-\r\n829b8110-0e6f-4349-bca4-42803577788d_WGT24-HCNMF-FQ7XH-6M8K7-DR%f%TW9__16_ProjectProXVolume\r\nda7ddabc-3fbe-4447-9e01-6ab7440b4cd4_GNFHQ-F6YQM-KQDGJ-327XX-KQ%f%BVC__16_ProjectStdVolume_-ProjectStdRetail-\r\ncbbaca45-556a-4416-ad03-bda598eaa7c8_D8NRQ-JTYM3-7J2DX-646CT-68%f%36M__16_ProjectStdXVolume\r\nd450596f-894d-49e0-966a-fd39ed4c4c64_XQNVK-8JYDB-WJ9W3-YJ8YR-WF%f%G99__16_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-\r\n041a06cb-c5b8-4772-809f-416d03d16654_F47MM-N3XJP-TQXJ9-BP99D-8K%f%837__16_PublisherVolume_-PublisherRetail-\r\n9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY__16_SkypeServiceBypassRetail_[PrepidBypass]\r\n971cd368-f2e1-49c1-aedd-330909ce18b6_4N4D8-3J7Y3-YYW7C-73HD2-V8%f%RHY__16_SkypeforBusinessEntryRetail_[PrepidBypass]\r\n83e04ee1-fa8d-436d-8994-d31a862cab77_869NQ-FJ69K-466HW-QYCP2-DD%f%BV6__16_SkypeforBusinessVolume_-SkypeforBusinessRetail-\r\ndedfa23d-6ed1-45a6-85dc-63cae0546de6_JNRGM-WHDWX-FJJG3-K47QV-DR%f%TFM__16_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-HomeStudentVNextRetail-PersonalPipcRetail-PersonalRetail-\r\n6bf301c1-b94a-43e9-ba31-d494598c47fb_PD3PC-RHNGV-FXJ29-8JK7D-RJ%f%RJK__16_VisioProVolume_-VisioProRetail-\r\nb234abe3-0857-4f9c-b05a-4dc314f85557_69WXN-MBYV6-22PQG-3WGHK-RM%f%6XC__16_VisioProXVolume\r\naa2a7821-1827-4c2c-8f1d-4513a34dda97_7WHWN-4T7MP-G96JF-G33KR-W8%f%GF4__16_VisioStdVolume_-VisioStdRetail-\r\n361fe620-64f4-41b5-ba77-84f8e079b1f7_NY48V-PPYYH-3F4PX-XJRKJ-W4%f%423__16_VisioStdXVolume\r\nbb11badf-d8aa-470e-9311-20eaf80fe5cc_WXY84-JN2Q9-RBCCQ-3Q3J3-3P%f%FJ6__16_WordVolume_-WordRetail-\r\n:: Office 2019\r\n22e6b96c-1011-4cd5-8b35-3c8fb6366b86_FGQNJ-JWJCG-7Q8MG-RMRGJ-9T%f%QVF__16_AccessRuntime2019Retail_[PrepidBypass]\r\n9e9bceeb-e736-4f26-88de-763f87dcc485_9N9PT-27V4Y-VJ2PD-YXFMF-YT%f%FQT__16_Access2019Volume_-Access2019Retail-\r\n237854e9-79fc-4497-a0c1-a70969691c6b_TMJWT-YYNMB-3BKTF-644FC-RV%f%XBD__16_Excel2019Volume_-Excel2019Retail-\r\nc8f8a301-19f5-4132-96ce-2de9d4adbd33_7HD7K-N4PVK-BHBCQ-YWQRW-XW%f%4VK__16_Outlook2019Volume_-Outlook2019Retail-\r\n3131fd61-5e4f-4308-8d6d-62be1987c92c_RRNCX-C64HY-W2MM7-MCH9G-TJ%f%HMQ__16_PowerPoint2019Volume_-PowerPoint2019Retail-\r\n2ca2bf3f-949e-446a-82c7-e25a15ec78c4_B4NPR-3FKK7-T2MBV-FRQ4W-PK%f%D2B__16_ProjectPro2019Volume_-ProjectPro2019Retail-\r\n1777f0e3-7392-4198-97ea-8ae4de6f6381_C4F7P-NCP8C-6CQPT-MQHV9-JX%f%D2M__16_ProjectStd2019Volume_-ProjectStd2019Retail-\r\n85dd8b5f-eaa4-4af3-a628-cce9e77c9a03_NMMKJ-6RK4F-KMJVX-8D9MJ-6M%f%WKP__16_ProPlus2019Volume_-ProPlus2019Retail-Professional2019Retail-\r\n9d3e4cca-e172-46f1-a2f4-1d2107051444_G2KWX-3NW6P-PY93R-JXK2T-C9%f%Y9V__16_Publisher2019Volume_-Publisher2019Retail-\r\n734c6c6e-b0ba-4298-a891-671772b2bd1b_NCJ33-JHBBY-HTK98-MYCV8-HM%f%KHJ__16_SkypeforBusiness2019Volume_-SkypeforBusiness2019Retail-\r\nf88cfdec-94ce-4463-a969-037be92bc0e7_N9722-BV9H6-WTJTT-FPB93-97%f%8MK__16_SkypeforBusinessEntry2019Retail_[PrepidBypass]\r\n6912a74b-a5fb-401a-bfdb-2e3ab46f4b02_6NWWJ-YQWMR-QKGCB-6TMB3-9D%f%9HK__16_Standard2019Volume_-Standard2019Retail-HomeBusiness2019Retail-HomeStudentARM2019Retail-HomeStudentPlusARM2019Retail-HomeStudent2019Retail-Personal2019Retail-\r\n5b5cf08f-b81a-431d-b080-3450d8620565_9BGNQ-K37YR-RQHF2-38RQ3-7V%f%CBB__16_VisioPro2019Volume_-VisioPro2019Retail-\r\ne06d7df3-aad0-419d-8dfb-0ac37e2bdf39_7TQNQ-K3YQQ-3PFH7-CCPPM-X4%f%VQ2__16_VisioStd2019Volume_-VisioStd2019Retail-\r\n059834fe-a8ea-4bff-b67b-4d006b5447d3_PBX3G-NWMT6-Q7XBW-PYJGG-WX%f%D33__16_Word2019Volume_-Word2019Retail-\r\n:: Office 2021\r\n:: OneNote2021Volume KMS license is not available\r\n844c36cb-851c-49e7-9079-12e62a049e2a_MNX9D-PB834-VCGY2-K2RW2-2D%f%P3D__16_AccessRuntime2021Retail_[Bypass]\r\n1fe429d8-3fa7-4a39-b6f0-03dded42fe14_WM8YG-YNGDD-4JHDC-PG3F4-FC%f%4T4__16_Access2021Volume_-Access2021Retail-\r\nea71effc-69f1-4925-9991-2f5e319bbc24_NWG3X-87C9K-TC7YY-BC2G7-G6%f%RVC__16_Excel2021Volume_-Excel2021Retail-\r\na5799e4c-f83c-4c6e-9516-dfe9b696150b_C9FM6-3N72F-HFJXB-TM3V9-T8%f%6R9__16_Outlook2021Volume_-Outlook2021Retail-\r\n778ccb9a-2f6a-44e5-853c-eb22b7609643_CNM3W-V94GB-QJQHH-BDQ3J-33%f%Y8H__16_OneNoteFree2021Retail_[Bypass]\r\n6e166cc3-495d-438a-89e7-d7c9e6fd4dea_TY7XF-NFRBR-KJ44C-G83KF-GX%f%27K__16_PowerPoint2021Volume_-PowerPoint2021Retail-\r\n76881159-155c-43e0-9db7-2d70a9a3a4ca_FTNWT-C6WBT-8HMGF-K9PRX-QV%f%9H8__16_ProjectPro2021Volume_-ProjectPro2021Retail-\r\n6dd72704-f752-4b71-94c7-11cec6bfc355_J2JDC-NJCYY-9RGQ4-YXWMH-T3%f%D4T__16_ProjectStd2021Volume_-ProjectStd2021Retail-\r\nfbdb3e18-a8ef-4fb3-9183-dffd60bd0984_FXYTK-NJJ8C-GB6DW-3DYQT-6F%f%7TH__16_ProPlus2021Volume_-ProPlus2021Retail-Professional2021Retail-\r\naa66521f-2370-4ad8-a2bb-c095e3e4338f_2MW9D-N4BXM-9VBPG-Q7W6M-KF%f%BGQ__16_Publisher2021Volume_-Publisher2021Retail-\r\n1f32a9af-1274-48bd-ba1e-1ab7508a23e8_HWCXN-K3WBT-WJBKY-R8BD9-XK%f%29P__16_SkypeforBusiness2021Volume_-SkypeforBusiness2021Retail-\r\n080a45c5-9f9f-49eb-b4b0-c3c610a5ebd3_KDX7X-BNVR8-TXXGX-4Q7Y8-78%f%VT3__16_Standard2021Volume_-Standard2021Retail-HomeBusiness2021Retail-HomeStudent2021Retail-Personal2021Retail-\r\nfb61ac9a-1688-45d2-8f6b-0674dbffa33c_KNH8D-FGHT4-T8RK3-CTDYJ-K2%f%HT4__16_VisioPro2021Volume_-VisioPro2021Retail-\r\n72fce797-1884-48dd-a860-b2f6a5efd3ca_MJVNY-BYWPY-CWV6J-2RKRT-4M%f%8QG__16_VisioStd2021Volume_-VisioStd2021Retail-\r\nabe28aea-625a-43b1-8e30-225eb8fbd9e5_TN8H9-M34D3-Y64V9-TR72V-X7%f%9KV__16_Word2021Volume_-Word2021Retail-\r\n:: Office 2024\r\nfceda083-1203-402a-8ec4-3d7ed9f3648c_2TDPW-NDQ7G-FMG99-DXQ7M-TX%f%3T2__16_ProPlus2024Volume-Preview\r\naaea0dc8-78e1-4343-9f25-b69b83dd1bce_D9GTG-NP7DV-T6JP3-B6B62-JB%f%89R__16_ProjectPro2024Volume-Preview\r\n4ab4d849-aabc-43fb-87ee-3aed02518891_YW66X-NH62M-G6YFP-B7KCT-WX%f%GKQ__16_VisioPro2024Volume-Preview\r\n72e9faa7-ead1-4f3d-9f6e-3abc090a81d7_82FTR-NCHR7-W3944-MGRHM-JM%f%CWD__16_Access2024Volume_-Access2024Retail-\r\ncbbba2c3-0ff5-4558-846a-043ef9d78559_F4DYN-89BP2-WQTWJ-GR8YC-CK%f%GJG__16_Excel2024Volume_-Excel2024Retail-\r\nbef3152a-8a04-40f2-a065-340c3f23516d_D2F8D-N3Q3B-J28PV-X27HD-RJ%f%WB9__16_Outlook2024Volume_-Outlook2024Retail-\r\nb63626a4-5f05-4ced-9639-31ba730a127e_CW94N-K6GJH-9CTXY-MG2VC-FY%f%CWP__16_PowerPoint2024Volume_-PowerPoint2024Retail-\r\nf510af75-8ab7-4426-a236-1bfb95c34ff8_FQQ23-N4YCY-73HQ3-FM9WC-76%f%HF4__16_ProjectPro2024Volume_-ProjectPro2024Retail-\r\n9f144f27-2ac5-40b9-899d-898c2b8b4f81_PD3TT-NTHQQ-VC7CY-MFXK3-G8%f%7F8__16_ProjectStd2024Volume_-ProjectStd2024Retail-\r\n8d368fc1-9470-4be2-8d66-90e836cbb051_XJ2XN-FW8RK-P4HMP-DKDBV-GC%f%VGB__16_ProPlus2024Volume_-ProPlus2024Retail-\r\n0002290a-2091-4324-9e53-3cfe28884cde_4NKHF-9HBQF-Q3B6C-7YV34-F6%f%4P3__16_SkypeforBusiness2024Volume\r\nbbac904f-6a7e-418a-bb4b-24c85da06187_V28N4-JG22K-W66P8-VTMGK-H6%f%HGR__16_Standard2024Volume_-Home2024Retail-HomeBusiness2024Retail-\r\nfa187091-8246-47b1-964f-80a0b1e5d69a_B7TN8-FJ8V3-7QYCP-HQPMV-YY%f%89G__16_VisioPro2024Volume_-VisioPro2024Retail-\r\n923fa470-aa71-4b8b-b35c-36b79bf9f44b_JMMVY-XFNQC-KK4HK-9H7R3-WQ%f%QTV__16_VisioStd2024Volume_-VisioStd2024Retail-\r\nd0eded01-0881-4b37-9738-190400095098_MQ84N-7VYDM-FXV7C-6K7CC-VF%f%W9J__16_Word2024Volume_-Word2024Retail-\r\n) do (\r\nfor /f \"tokens=1-5 delims=_\" %%A in (\"%%#\") do (\r\n\r\nif %1==winkey if %osSKU%==%%C if not defined key (\r\necho \"!allapps!\" | find /i \"%%A\" %nul1% && set key=%%B\r\n)\r\n\r\nif %1==chkprod if \"%oVer%\"==\"%%C\" if not defined foundprod (\r\necho \"%%D\" | findstr /I \"\\<%2.*\" %nul% && set foundprod=1\r\n)\r\n\r\nif %1==getinfo if not defined key if \"%oVer%\"==\"%%C\" (\r\nif /i \"%2\"==\"%%D\" (\r\nset key=%%B\r\nset _actid=%%A\r\nset _allactid=!_allactid! %%A\r\n) else if not defined _oMSI if %_NoEditionChange%==0 (\r\necho: %%E | find /i \"-%2-\" %nul% && (\r\nset key=%%B\r\nset _altoffid=%%D\r\nset _actid=%%A\r\nset _allactid=!_allactid! %%A\r\n)\r\n)\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Below code is used to get alternate edition name and key if current edition doesn't support K-M-S activation\r\n\r\n::  1st column = Current SKU ID\r\n::  2nd column = Current Edition Name\r\n::  3rd column = Current Edition Activation ID\r\n::  4th column = Alternate Edition Activation ID\r\n::  5th column = Alternate Edition GVLK\r\n::  6th column = Alternate Edition Name\r\n::  Separator  = _\r\n\r\n\r\n:kmsfallback\r\n\r\nset notfoundaltactID=\r\nif %_NoEditionChange%==1 exit /b\r\n\r\nfor %%# in (\r\n205_IoTEnterpriseSK________________d4f9b41f-205c-405e-8e08-3d16e88e02be_59eb965c-9150-42b7-a0ec-22151b9897c5_KBN8V-HFGQ4-MGXVD-347P6-PD%f%QGT_IoTEnterpriseS\r\n138_ProfessionalSingleLanguage_____a48938aa-62fa-4966-9d44-9f04da3f72f2_2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX_Professional\r\n139_ProfessionalCountrySpecific____f7af7d09-40e4-419c-a49b-eae366689ebd_2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX_Professional\r\n139_ProfessionalCountrySpecific-Zn_01eb852c-424d-4060-94b8-c10d799d7364_2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX_Professional\r\n) do (\r\nfor /f \"tokens=1-6 delims=_\" %%A in (\"%%#\") do if %osSKU%==%%A (\r\necho \"!allapps!\" | find /i \"%%C\" %nul1% && (\r\necho \"!allapps!\" | find /i \"%%D\" %nul1% && (\r\nset altkey=%%E\r\nset altedition=%%F\r\n) || (\r\nset altedition=%%F\r\nset notfoundaltactID=1\r\n)\r\n)\r\n)\r\n)\r\nexit /b\r\n\r\n:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n\r\n:check_actstatus\r\n\r\ncls\r\nif not defined terminal (\r\nmode 100, 36\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=35;$B.Height=300;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\n\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':sppmgr\\:.*';. ([scriptblock]::Create($f[1]))\"\r\ngoto dk_done\r\n\r\n:sppmgr:\r\nparam (\r\n    [Parameter()]\r\n    [switch]\r\n    $All,\r\n    [Parameter()]\r\n    [switch]\r\n    $Dlv,\r\n    [Parameter()]\r\n    [switch]\r\n    $IID,\r\n    [Parameter()]\r\n    [switch]\r\n    $Pass\r\n)\r\n\r\nfunction CONOUT($strObj)\r\n{\r\n\tOut-Host -Input $strObj\r\n}\r\n\r\nfunction ExitScript($ExitCode = 0)\r\n{\r\n\tExit $ExitCode\r\n}\r\n\r\nif (-Not $PSVersionTable) {\r\n\t\"==== ERROR ====`r`n\"\r\n\t\"Windows PowerShell 1.0 is not supported by this script.\"\r\n\tExitScript 1\r\n}\r\n\r\nif ($ExecutionContext.SessionState.LanguageMode.value__ -NE 0) {\r\n\t\"==== ERROR ====`r`n\"\r\n\t\"Windows PowerShell is not running in Full Language Mode.\"\r\n\tExitScript 1\r\n}\r\n\r\n$winbuild = 1\r\ntry {\r\n\t$winbuild = [System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"$env:SystemRoot\\System32\\kernel32.dll\").FileBuildPart\r\n} catch {\r\n\t$winbuild = [int]([wmi]'Win32_OperatingSystem=@').BuildNumber\r\n}\r\n\r\nif ($winbuild -EQ 1) {\r\n\t\"==== ERROR ====`r`n\"\r\n\t\"Could not detect Windows build.\"\r\n\tExitScript 1\r\n}\r\n\r\nif ($winbuild -LT 2600) {\r\n\t\"==== ERROR ====`r`n\"\r\n\t\"This build of Windows is not supported by this script.\"\r\n\tExitScript 1\r\n}\r\n\r\nif ($All.IsPresent)\r\n{\r\n\t$isAll = {CONOUT \"`r\"}\r\n\t$noAll = {$null}\r\n}\r\nelse\r\n{\r\n\t$isAll = {$null}\r\n\t$noAll = {CONOUT \"`r\"}\r\n}\r\n$Dlv = $Dlv.IsPresent\r\n$IID = $IID.IsPresent -Or $Dlv.IsPresent\r\n\r\n$NT6 = $winbuild -GE 6000\r\n$NT7 = $winbuild -GE 7600\r\n$NT8 = $winbuild -GE 9200\r\n$NT9 = $winbuild -GE 9600\r\n\r\n$Admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)\r\n\r\n$line2 = \"============================================================\"\r\n$line3 = \"____________________________________________________________\"\r\n\r\nfunction echoWindows\r\n{\r\n\tCONOUT \"$line2\"\r\n\tCONOUT \"===                   Windows Status                     ===\"\r\n\tCONOUT \"$line2\"\r\n\t& $noAll\r\n}\r\n\r\nfunction echoOffice\r\n{\r\n\tif ($doMSG -EQ 0) {\r\n\t\treturn\r\n\t}\r\n\r\n\t& $isAll\r\n\tCONOUT \"$line2\"\r\n\tCONOUT \"===                   Office Status                      ===\"\r\n\tCONOUT \"$line2\"\r\n\t& $noAll\r\n\r\n\t$script:doMSG = 0\r\n}\r\n\r\nfunction strGetRegistry($strKey, $strName)\r\n{\r\n\ttry {\r\n\t\treturn [Microsoft.Win32.Registry]::GetValue($strKey, $strName, $null)\r\n\t} catch {\r\n\t\treturn $null\r\n\t}\r\n}\r\n\r\nfunction CheckOhook\r\n{\r\n\t$ohook = 0\r\n\t$paths = \"${env:ProgramFiles}\", \"${env:ProgramW6432}\", \"${env:ProgramFiles(x86)}\"\r\n\r\n\t15, 16 | foreach `\r\n\t{\r\n\t\t$A = $_; $paths | foreach `\r\n\t\t{\r\n\t\t\tif (Test-Path \"$($_)$('\\Microsoft Office\\Office')$($A)$('\\sppc*dll')\") {$ohook = 1}\r\n\t\t}\r\n\t}\r\n\r\n\t\"System\", \"SystemX86\" | foreach `\r\n\t{\r\n\t\t$A = $_; \"Office 15\", \"Office\" | foreach `\r\n\t\t{\r\n\t\t\t$B = $_; $paths | foreach `\r\n\t\t\t{\r\n\t\t\t\tif (Test-Path \"$($_)$('\\Microsoft ')$($B)$('\\root\\vfs\\')$($A)$('\\sppc*dll')\") {$ohook = 1}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tif ($ohook -EQ 0) {\r\n\t\treturn\r\n\t}\r\n\r\n\t& $isAll\r\n\tCONOUT \"$line2\"\r\n\tCONOUT \"===                Office Ohook Status                   ===\"\r\n\tCONOUT \"$line2\"\r\n\t$host.UI.WriteLine('Yellow', 'Black', \"`r`nOhook for permanent Office activation is installed.`r`nYou can ignore the below mentioned Office activation status.\")\r\n\t& $noAll\r\n}\r\n\r\n#region SSSS\r\nfunction BoolToWStr($bVal) {\r\n\t(\"TRUE\", \"FALSE\")[!$bVal]\r\n}\r\n\r\nfunction InitializePInvoke($LaDll, $bOffice) {\r\n\t$LaName = [IO.Path]::GetFileNameWithoutExtension($LaDll)\r\n\t$SLApp = $NT7 -Or $bOffice -Or ($LaName -EQ 'sppc' -And [Diagnostics.FileVersionInfo]::GetVersionInfo(\"$SysPath\\sppc.dll\").FilePrivatePart -GE 16501)\r\n\t$Win32 = $null\r\n\r\n\t$Marshal = [System.Runtime.InteropServices.Marshal]\r\n\t$Module = [AppDomain]::CurrentDomain.DefineDynamicAssembly(($LaName+\"_Assembly\"), 'Run').DefineDynamicModule(($LaName+\"_Module\"), $False)\r\n\t$Class = $Module.DefineType(($LaName+\"_Methods\"), 'Public, Abstract, Sealed, BeforeFieldInit', [Object], 0)\r\n\r\n\t$Class.DefinePInvokeMethod('SLClose', $LaDll, 22, 1, [Int32], @([IntPtr]), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLOpen', $LaDll, 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGenerateOfflineInstallationId', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGetSLIDList', $LaDll, 22, 1, [Int32], @([IntPtr], [UInt32], [Guid].MakeByRefType(), [UInt32], [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGetLicensingStatusInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [Guid].MakeByRefType(), [IntPtr], [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGetPKeyInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGetProductSkuInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGetServiceInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\tif ($SLApp) {\r\n\t\t$Class.DefinePInvokeMethod('SLGetApplicationInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t}\r\n\tif ($bOffice) {\r\n\t\t$Win32 = $Class.CreateType()\r\n\t\treturn\r\n\t}\r\n\tif ($NT6) {\r\n\t\t$Class.DefinePInvokeMethod('SLGetWindowsInformation', 'slc.dll', 22, 1, [Int32], @([String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t\t$Class.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 22, 1, [Int32], @([String], [UInt32].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t\t$Class.DefinePInvokeMethod('SLIsGenuineLocal', 'slwga.dll', 22, 1, [Int32], @([Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr]), 1, 3).SetImplementationFlags(128)\r\n\t}\r\n\tif ($NT7) {\r\n\t\t$Class.DefinePInvokeMethod('SLIsWindowsGenuineLocal', 'slc.dll', 'Public, Static', 'Standard', [Int32], @([UInt32].MakeByRefType()), 'Winapi', 'Unicode').SetImplementationFlags('PreserveSig')\r\n\t}\r\n\r\n\tif ($DllSubscription) {\r\n\t\t$Class.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t\t$Struct = $Class.DefineNestedType('SubStatus', 'NestedPublic, SequentialLayout, Sealed, BeforeFieldInit', [ValueType], 0)\r\n\t\t[void]$Struct.DefineField('dwEnabled', [UInt32], 'Public')\r\n\t\t[void]$Struct.DefineField('dwSku', [UInt32], 6)\r\n\t\t[void]$Struct.DefineField('dwState', [UInt32], 6)\r\n\t\t$SubStatus = $Struct.CreateType()\r\n\t}\r\n\r\n\t$Win32 = $Class.CreateType()\r\n}\r\n\r\nfunction SlGetInfoIID($SkuId)\r\n{\r\n\t$bData = 0\r\n\r\n\tif ($Win32::SLGenerateOfflineInstallationId(\r\n\t\t$hSLC,\r\n\t\t[ref][Guid]$SkuId,\r\n\t\t[ref]$bData\r\n\t))\r\n\t{\r\n\t\treturn $null\r\n\t}\r\n\telse\r\n\t{\r\n\t\treturn $Marshal::PtrToStringUni($bData)\r\n\t}\r\n}\r\n\r\nfunction SlReturnData($hrRet, $tData, $cData, $bData) {\r\n\tif ($hrRet -NE 0 -Or $cData -EQ 0)\r\n\t{\r\n\t\treturn $null\r\n\t}\r\n\tif ($tData -EQ 1)\r\n\t{\r\n\t\treturn $Marshal::PtrToStringUni($bData)\r\n\t}\r\n\telseif ($tData -EQ 4)\r\n\t{\r\n\t\treturn $Marshal::ReadInt32($bData)\r\n\t}\r\n\telseif ($tData -EQ 3 -And $cData -EQ 8)\r\n\t{\r\n\t\treturn $Marshal::ReadInt64($bData)\r\n\t}\r\n\telse\r\n\t{\r\n\t\treturn $null\r\n\t}\r\n}\r\n\r\nfunction SlGetInfoPKey($PkeyId, $Value)\r\n{\r\n\t$tData = 0\r\n\t$cData = 0\r\n\t$bData = 0\r\n\r\n\t$hrRet = $Win32::SLGetPKeyInformation(\r\n\t\t$hSLC,\r\n\t\t[ref][Guid]$PkeyId,\r\n\t\t$Value,\r\n\t\t[ref]$tData,\r\n\t\t[ref]$cData,\r\n\t\t[ref]$bData\r\n\t)\r\n\r\n\treturn SlReturnData $hrRet $tData $cData $bData\r\n}\r\n\r\nfunction SlGetInfoSku($SkuId, $Value)\r\n{\r\n\t$tData = 0\r\n\t$cData = 0\r\n\t$bData = 0\r\n\r\n\t$hrRet = $Win32::SLGetProductSkuInformation(\r\n\t\t$hSLC,\r\n\t\t[ref][Guid]$SkuId,\r\n\t\t$Value,\r\n\t\t[ref]$tData,\r\n\t\t[ref]$cData,\r\n\t\t[ref]$bData\r\n\t)\r\n\r\n\treturn SlReturnData $hrRet $tData $cData $bData\r\n}\r\n\r\nfunction SlGetInfoApp($AppId, $Value)\r\n{\r\n\t$tData = 0\r\n\t$cData = 0\r\n\t$bData = 0\r\n\r\n\t$hrRet = $Win32::SLGetApplicationInformation(\r\n\t\t$hSLC,\r\n\t\t[ref][Guid]$AppId,\r\n\t\t$Value,\r\n\t\t[ref]$tData,\r\n\t\t[ref]$cData,\r\n\t\t[ref]$bData\r\n\t)\r\n\r\n\treturn SlReturnData $hrRet $tData $cData $bData\r\n}\r\n\r\nfunction SlGetInfoService($Value)\r\n{\r\n\t$tData = 0\r\n\t$cData = 0\r\n\t$bData = 0\r\n\r\n\t$hrRet = $Win32::SLGetServiceInformation(\r\n\t\t$hSLC,\r\n\t\t$Value,\r\n\t\t[ref]$tData,\r\n\t\t[ref]$cData,\r\n\t\t[ref]$bData\r\n\t)\r\n\r\n\treturn SlReturnData $hrRet $tData $cData $bData\r\n}\r\n\r\nfunction SlGetInfoSvcApp($strApp, $Value)\r\n{\r\n\tif ($SLApp)\r\n\t{\r\n\t\treturn SlGetInfoApp $strApp $Value\r\n\t}\r\n\telse\r\n\t{\r\n\t\treturn SlGetInfoService $Value\r\n\t}\r\n}\r\n\r\nfunction SlGetInfoLicensing($AppId, $SkuId)\r\n{\r\n\t$dwStatus = 0\r\n\t$dwGrace = 0\r\n\t$hrReason = 0\r\n\t$qwValidity = 0\r\n\r\n\t$cStatus = 0\r\n\t$pStatus = 0\r\n\r\n\t$hrRet = $Win32::SLGetLicensingStatusInformation(\r\n\t\t$hSLC,\r\n\t\t[ref][Guid]$AppId,\r\n\t\t[ref][Guid]$SkuId,\r\n\t\t0,\r\n\t\t[ref]$cStatus,\r\n\t\t[ref]$pStatus\r\n\t)\r\n\r\n\tif ($hrRet -NE 0 -Or $cStatus -EQ 0)\r\n\t{\r\n\t\treturn\r\n\t}\r\n\r\n\t[IntPtr]$ppStatus = [Int64]$pStatus + [Int64]40 * ($cStatus - 1)\r\n\t$dwStatus = $Marshal::ReadInt32($ppStatus, 16)\r\n\t$dwGrace = $Marshal::ReadInt32($ppStatus, 20)\r\n\t$hrReason = $Marshal::ReadInt32($ppStatus, 28)\r\n\t$qwValidity = $Marshal::ReadInt64($ppStatus, 32)\r\n\r\n\tif ($dwStatus -EQ 3)\r\n\t{\r\n\t\t$dwStatus = 5\r\n\t}\r\n\tif ($dwStatus -EQ 2)\r\n\t{\r\n\t\tif ($hrReason -EQ 0x4004F00D)\r\n\t\t{\r\n\t\t\t$dwStatus = 3\r\n\t\t}\r\n\t\telseif ($hrReason -EQ 0x4004F065)\r\n\t\t{\r\n\t\t\t$dwStatus = 4\r\n\t\t}\r\n\t\telseif ($hrReason -EQ 0x4004FC06)\r\n\t\t{\r\n\t\t\t$dwStatus = 6\r\n\t\t}\r\n\t}\r\n\r\n\treturn\r\n}\r\n\r\nfunction SlGetInfoSLID($AppId)\r\n{\r\n\t$cReturnIds = 0\r\n\t$pReturnIds = 0\r\n\r\n\t$hrRet = $Win32::SLGetSLIDList(\r\n\t\t$hSLC,\r\n\t\t0,\r\n\t\t[ref][Guid]$AppId,\r\n\t\t1,\r\n\t\t[ref]$cReturnIds,\r\n\t\t[ref]$pReturnIds\r\n\t)\r\n\r\n\tif ($hrRet -NE 0 -Or $cReturnIds -EQ 0)\r\n\t{\r\n\t\treturn\r\n\t}\r\n\r\n\t$a1List = @()\r\n\t$a2List = @()\r\n\t$a3List = @()\r\n\t$a4List = @()\r\n\r\n\tforeach ($i in 0..($cReturnIds - 1))\r\n\t{\r\n\t\t$bytes = New-Object byte[] 16\r\n\t\t$Marshal::Copy([Int64]$pReturnIds + [Int64]16 * $i, $bytes, 0, 16)\r\n\t\t$actid = ([Guid]$bytes).Guid\r\n\t\t$gPPK = SlGetInfoSku $actid \"pkeyId\"\r\n\t\t$gAdd = SlGetInfoSku $actid \"DependsOn\"\r\n\t\tif ($All.IsPresent) {\r\n\t\t\tif ($null -EQ $gPPK -And $null -NE $gAdd) { $a1List += @{id = $actid; pk = $null; ex = $true} }\r\n\t\t\tif ($null -EQ $gPPK -And $null -EQ $gAdd) { $a2List += @{id = $actid; pk = $null; ex = $false} }\r\n\t\t}\r\n\t\tif ($null -NE $gPPK -And $null -NE $gAdd) { $a3List += @{id = $actid; pk = $gPPK; ex = $true} }\r\n\t\tif ($null -NE $gPPK -And $null -EQ $gAdd) { $a4List += @{id = $actid; pk = $gPPK; ex = $false} }\r\n\t}\r\n\r\n\treturn ($a1List + $a2List + $a3List + $a4List)\r\n}\r\n\r\nfunction DetectSubscription {\r\n\ttry\r\n\t{\r\n\t\t$objSvc = New-Object PSObject\r\n\t\t$wmiSvc = [wmisearcher]\"SELECT SubscriptionType, SubscriptionStatus, SubscriptionEdition, SubscriptionExpiry FROM SoftwareLicensingService\"\r\n\t\t$wmiSvc.Options.Rewindable = $false\r\n\t\t$wmiSvc.Get() | select -Expand Properties -EA 0 | foreach { $objSvc | Add-Member 8 $_.Name $_.Value }\r\n\t\t$wmiSvc.Dispose()\r\n\t}\r\n\tcatch\r\n\t{\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($null -EQ $objSvc.SubscriptionType -Or $objSvc.SubscriptionType -EQ 120) {\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($objSvc.SubscriptionType -EQ 1) {\r\n\t\t$SubMsgType = \"Device based\"\r\n\t} else {\r\n\t\t$SubMsgType = \"User based\"\r\n\t}\r\n\r\n\tif ($objSvc.SubscriptionStatus -EQ 120) {\r\n\t\t$SubMsgStatus = \"Expired\"\r\n\t} elseif ($objSvc.SubscriptionStatus -EQ 100) {\r\n\t\t$SubMsgStatus = \"Disabled\"\r\n\t} elseif ($objSvc.SubscriptionStatus -EQ 1) {\r\n\t\t$SubMsgStatus = \"Active\"\r\n\t} else {\r\n\t\t$SubMsgStatus = \"Not active\"\r\n\t}\r\n\r\n\t$SubMsgExpiry = \"Unknown\"\r\n\tif ($objSvc.SubscriptionExpiry) {\r\n\t\tif ($objSvc.SubscriptionExpiry.Contains(\"unspecified\") -EQ $false) {$SubMsgExpiry = $objSvc.SubscriptionExpiry}\r\n\t}\r\n\r\n\t$SubMsgEdition = \"Unknown\"\r\n\tif ($objSvc.SubscriptionEdition) {\r\n\t\tif ($objSvc.SubscriptionEdition.Contains(\"UNKNOWN\") -EQ $false) {$SubMsgEdition = $objSvc.SubscriptionEdition}\r\n\t}\r\n\r\n\tCONOUT \"`nSubscription information:\"\r\n\tCONOUT \"    Type   : $SubMsgType\"\r\n\tCONOUT \"    Status : $SubMsgStatus\"\r\n\tCONOUT \"    Edition: $SubMsgEdition\"\r\n\tCONOUT \"    Expiry : $SubMsgExpiry\"\r\n}\r\n\r\nfunction DetectAdbaClient\r\n{\r\n\t$propADBA | foreach { set $_ (SlGetInfoSku $licID $_) }\r\n\tDetectActType\r\n\tCONOUT \"`nAD Activation client information:\"\r\n\tCONOUT \"    Object Name: $ADActivationObjectName\"\r\n\tCONOUT \"    Domain Name: $ADActivationObjectDN\"\r\n\tCONOUT \"    CSVLK Extended PID: $ADActivationCsvlkPID\"\r\n\tCONOUT \"    CSVLK Activation ID: $ADActivationCsvlkSkuID\"\r\n}\r\n\r\nfunction DetectAvmClient\r\n{\r\n\t$propAVMA | foreach { set $_ (SlGetInfoSku $licID $_) }\r\n\tCONOUT \"`nAutomatic VM Activation client information:\"\r\n\tif (-Not [String]::IsNullOrEmpty($InheritedActivationId)) {\r\n\t\tCONOUT \"    Guest IAID: $InheritedActivationId\"\r\n\t} else {\r\n\t\tCONOUT \"    Guest IAID: Not Available\"\r\n\t}\r\n\tif (-Not [String]::IsNullOrEmpty($InheritedActivationHostMachineName)) {\r\n\t\tCONOUT \"    Host machine name: $InheritedActivationHostMachineName\"\r\n\t} else {\r\n\t\tCONOUT \"    Host machine name: Not Available\"\r\n\t}\r\n\tif (-Not [String]::IsNullOrEmpty($InheritedActivationHostDigitalPid2)) {\r\n\t\tCONOUT \"    Host Digital PID2: $InheritedActivationHostDigitalPid2\"\r\n\t} else {\r\n\t\tCONOUT \"    Host Digital PID2: Not Available\"\r\n\t}\r\n\tif ($InheritedActivationActivationTime) {\r\n\t\t$IAAT = [DateTime]::FromFileTime($InheritedActivationActivationTime).ToString('yyyy-MM-dd hh:mm:ss tt')\r\n\t\tCONOUT \"    Activation time: $IAAT\"\r\n\t} else {\r\n\t\tCONOUT \"    Activation time: Not Available\"\r\n\t}\r\n}\r\n\r\nfunction DetectKmsHost\r\n{\r\n\t$IsKeyManagementService = SlGetInfoSvcApp $strApp 'IsKeyManagementService'\r\n\tif (-Not $IsKeyManagementService) {\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($Vista -Or $NT5) {\r\n\t\t$regk = $SLKeyPath\r\n\t} elseif ($strSLP -EQ $oslp) {\r\n\t\t$regk = $OPKeyPath\r\n\t} else {\r\n\t\t$regk = $SPKeyPath\r\n\t}\r\n\t$KMSListening = strGetRegistry $regk \"KeyManagementServiceListeningPort\"\r\n\t$KMSPublishing = strGetRegistry $regk \"DisableDnsPublishing\"\r\n\t$KMSPriority = strGetRegistry $regk \"EnableKmsLowPriority\"\r\n\r\n\tif (-Not $KMSListening) {$KMSListening = 1688}\r\n\tif (-Not $KMSPublishing) {$KMSPublishing = \"TRUE\"} else {$KMSPublishing = BoolToWStr (!$KMSPublishing)}\r\n\tif (-Not $KMSPriority) {$KMSPriority = \"FALSE\"} else {$KMSPriority = BoolToWStr $KMSPriority}\r\n\r\n\tif ($KMSPublishing -EQ \"TRUE\") {$KMSPublishing = \"Enabled\"} else {$KMSPublishing = \"Disabled\"}\r\n\tif ($KMSPriority -EQ \"TRUE\") {$KMSPriority = \"Low\"} else {$KMSPriority = \"Normal\"}\r\n\r\n\tif ($SLApp)\r\n\t{\r\n\t\t$propKMSServer | foreach { set $_ (SlGetInfoApp $strApp $_) }\r\n\t}\r\n\telse\r\n\t{\r\n\t\t$propKMSServer | foreach { set $_ (SlGetInfoService $_) }\r\n\t}\r\n\r\n\t$KMSRequests = $KeyManagementServiceTotalRequests\r\n\t$NoRequests = ($null -EQ $KMSRequests) -Or ($KMSRequests -EQ -1) -Or ($KMSRequests -EQ 4294967295)\r\n\r\n\tCONOUT \"`nKey Management Service host information:\"\r\n\tCONOUT \"    Current count: $KeyManagementServiceCurrentCount\"\r\n\tCONOUT \"    Listening on Port: $KMSListening\"\r\n\tCONOUT \"    DNS publishing: $KMSPublishing\"\r\n\tCONOUT \"    KMS priority: $KMSPriority\"\r\n\tif ($NoRequests) {\r\n\t\treturn\r\n\t}\r\n\tCONOUT \"`nKey Management Service cumulative requests received from clients:\"\r\n\tCONOUT \"    Total: $KeyManagementServiceTotalRequests\"\r\n\tCONOUT \"    Failed: $KeyManagementServiceFailedRequests\"\r\n\tCONOUT \"    Unlicensed: $KeyManagementServiceUnlicensedRequests\"\r\n\tCONOUT \"    Licensed: $KeyManagementServiceLicensedRequests\"\r\n\tCONOUT \"    Initial grace period: $KeyManagementServiceOOBGraceRequests\"\r\n\tCONOUT \"    Expired or Hardware out of tolerance: $KeyManagementServiceOOTGraceRequests\"\r\n\tCONOUT \"    Non-genuine grace period: $KeyManagementServiceNonGenuineGraceRequests\"\r\n\tif ($null -NE $KeyManagementServiceNotificationRequests) {CONOUT \"    Notification: $KeyManagementServiceNotificationRequests\"}\r\n}\r\n\r\nfunction DetectActType\r\n{\r\n\t$VLType = strGetRegistry ($SPKeyPath + '\\' + $strApp + '\\' + $licID) \"VLActivationType\"\r\n\tif ($null -EQ $VLType) {$VLType = strGetRegistry ($SPKeyPath + '\\' + $strApp) \"VLActivationType\"}\r\n\tif ($null -EQ $VLType) {$VLType = strGetRegistry ($SPKeyPath) \"VLActivationType\"}\r\n\tif ($null -EQ $VLType -Or $VLType -GT 3) {$VLType = 0}\r\n\tif ($null -NE $VLType) {CONOUT \"Configured Activation Type: $($VLActTypes[$VLType])\"}\r\n}\r\n\r\nfunction DetectKmsClient\r\n{\r\n\tif ($win8) {DetectActType}\r\n\tCONOUT \"`r\"\r\n\tif ($LicenseStatus -NE 1) {\r\n\t\tCONOUT \"Please activate the product in order to update KMS client information values.\"\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($NT7 -Or $strSLP -EQ $oslp) {\r\n\t\t$propKMSClient | foreach { set $_ (SlGetInfoSku $licID $_) }\r\n\t\tif ($strSLP -EQ $oslp) {$regk = $OPKeyPath} else {$regk = $SPKeyPath}\r\n\t\t$KMSCaching = strGetRegistry $regk \"DisableKeyManagementServiceHostCaching\"\r\n\t\tif (-Not $KMSCaching) {$KMSCaching = \"TRUE\"} else {$KMSCaching = BoolToWStr (!$KMSCaching)}\r\n\t}\r\n\r\n\t\"ClientMachineID\" | foreach { set $_ (SlGetInfoService $_) }\r\n\r\n\tif ($Vista) {\r\n\t\t$propKMSVista | foreach { set $_ (SlGetInfoService $_) }\r\n\t\t$KeyManagementServicePort = strGetRegistry $SLKeyPath \"KeyManagementServicePort\"\r\n\t\t$DiscoveredKeyManagementServiceName = strGetRegistry $NSKeyPath \"DiscoveredKeyManagementServiceName\"\r\n\t\t$DiscoveredKeyManagementServicePort = strGetRegistry $NSKeyPath \"DiscoveredKeyManagementServicePort\"\r\n\t}\r\n\r\n\tif ([String]::IsNullOrEmpty($KeyManagementServiceName)) {\r\n\t\t$KmsReg = $null\r\n\t} else {\r\n\t\tif (-Not $KeyManagementServicePort) {$KeyManagementServicePort = 1688}\r\n\t\t$KmsReg = \"Registered KMS machine name: ${KeyManagementServiceName}:${KeyManagementServicePort}\"\r\n\t}\r\n\r\n\tif ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceName)) {\r\n\t\t$KmsDns = \"DNS auto-discovery: KMS name not available\"\r\n\t\tif ($Vista -And -Not $Admin) {$KmsDns = \"DNS auto-discovery: Run the script as administrator to retrieve info\"}\r\n\t} else {\r\n\t\tif (-Not $DiscoveredKeyManagementServicePort) {$DiscoveredKeyManagementServicePort = 1688}\r\n\t\t$KmsDns = \"KMS machine name from DNS: ${DiscoveredKeyManagementServiceName}:${DiscoveredKeyManagementServicePort}\"\r\n\t}\r\n\r\n\tif ($null -NE $KMSCaching) {\r\n\t\tif ($KMSCaching -EQ \"TRUE\") {$KMSCaching = \"Enabled\"} else {$KMSCaching = \"Disabled\"}\r\n\t}\r\n\r\n\tif ($strSLP -EQ $wslp -And $NT9) {\r\n\t\tif ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceIpAddress)) {\r\n\t\t\t$DiscoveredKeyManagementServiceIpAddress = \"not available\"\r\n\t\t}\r\n\t}\r\n\r\n\tCONOUT \"Key Management Service client information:\"\r\n\tCONOUT \"    Client Machine ID (CMID): $ClientMachineID\"\r\n\tif ($null -EQ $KmsReg) {\r\n\t\tCONOUT \"    $KmsDns\"\r\n\t\tCONOUT \"    Registered KMS machine name: KMS name not available\"\r\n\t} else {\r\n\t\tCONOUT \"    $KmsReg\"\r\n\t}\r\n\tif ($null -NE $DiscoveredKeyManagementServiceIpAddress) {CONOUT \"    KMS machine IP address: $DiscoveredKeyManagementServiceIpAddress\"}\r\n\tCONOUT \"    KMS machine extended PID: $CustomerPID\"\r\n\tCONOUT \"    Activation interval: $VLActivationInterval minutes\"\r\n\tCONOUT \"    Renewal interval: $VLRenewalInterval minutes\"\r\n\tif ($null -NE $KMSCaching) {CONOUT \"    KMS host caching: $KMSCaching\"}\r\n\tif (-Not [String]::IsNullOrEmpty($KeyManagementServiceLookupDomain)) {CONOUT \"    KMS SRV record lookup domain: $KeyManagementServiceLookupDomain\"}\r\n}\r\n\r\nfunction GetResult($strSLP, $strApp, $entry)\r\n{\r\n\t$licID = $entry.id\r\n\t$propPrd | foreach { set $_ (SlGetInfoSku $licID $_) }\r\n\t. SlGetInfoLicensing $strApp $licID\r\n\t$LicenseStatus = $dwStatus\r\n\t$LicReason = $hrReason\r\n\t$EvaluationEndDate = $qwValidity\r\n\t$gprMnt = $dwGrace\r\n\r\n\t$pkid = $entry.pk\r\n\t$isPPK = $null -NE $pkid\r\n\r\n\t$add_on = $Name.IndexOf(\"add-on for\", 5)\r\n\tif ($add_on -NE -1) {\r\n\t\t$Name = $Name.Substring(0, $add_on + 7)\r\n\t}\r\n\r\n\t$licPHN = \"empty\"\r\n\tif ($Dlv -Or $All.IsPresent) {\r\n\t\t$licPHN = SlGetInfoSku $licID \"msft:sl/EUL/PHONE/PUBLIC\"\r\n\t}\r\n\r\n\tif ($LicenseStatus -EQ 0 -And !$isPPK) {\r\n\t\t& $isAll\r\n\t\tCONOUT \"Name: $Name\"\r\n\t\tCONOUT \"Description: $Description\"\r\n\t\tCONOUT \"Activation ID: $licID\"\r\n\t\tCONOUT \"License Status: Unlicensed\"\r\n\t\tif ($licPHN -NE \"empty\") {\r\n\t\t\t$gPHN = [String]::IsNullOrEmpty($licPHN) -NE $true\r\n\t\t\tCONOUT \"Phone activatable: $($gPHN.ToString())\"\r\n\t\t}\r\n\t\treturn\r\n\t}\r\n\r\n\t$winID = ($strApp -EQ $winApp)\r\n\t$winPR = ($winID -And -Not $entry.ex)\r\n\t$Vista = ($winID -And $NT6 -And -Not $NT7)\r\n\t$NT5 = ($strSLP -EQ $wslp -And $winbuild -LT 6001)\r\n\t$win8 = ($strSLP -EQ $wslp -And $NT8)\r\n\t$reapp = (\"Windows\", \"App\")[!$winID]\r\n\t$prmnt = (\"machine\", \"product\")[!$winPR]\r\n\r\n\tif ($Description.Contains(\"VOLUME_KMSCLIENT\")) {$cKmsClient = 1; $actTag = \"Volume\"}\r\n\tif ($Description.Contains(\"TIMEBASED_\")) {$cTblClient = 1; $actTag = \"Timebased\"}\r\n\tif ($Description.Contains(\"VIRTUAL_MACHINE_ACTIVATION\")) {$cAvmClient = 1; $actTag = \"Automatic VM\"}\r\n\tif ($null -EQ $cKmsClient -And $Description.Contains(\"VOLUME_KMS\")) {$cKmsServer = 1}\r\n\r\n\t$gprDay = [Math]::Round($gprMnt/1440)\r\n\t$_xpr = \"\"\r\n\t$inGrace = $false\r\n\tif ($gprMnt -GT 0) {\r\n\t\t$_xpr = [DateTime]::Now.AddMinutes($gprMnt).ToString('yyyy-MM-dd hh:mm:ss tt')\r\n\t\t$inGrace = $true\r\n\t}\r\n\r\n\t$LicenseMsg = \"Time remaining: $gprMnt minute(s) ($gprDay day(s))\"\r\n\tif ($LicenseStatus -EQ 0) {\r\n\t\t$LicenseInf = \"Unlicensed\"\r\n\t\t$LicenseMsg = $null\r\n\t}\r\n\tif ($LicenseStatus -EQ 1) {\r\n\t\t$LicenseInf = \"Licensed\"\r\n\t\tif ($gprMnt -EQ 0) {\r\n\t\t\t$LicenseMsg = $null\r\n\t\t\t$ExpireMsg = \"The $prmnt is permanently activated.\"\r\n\t\t} else {\r\n\t\t\t$LicenseMsg = \"$actTag activation expiration: $gprMnt minute(s) ($gprDay day(s))\"\r\n\t\t\tif ($inGrace) {$ExpireMsg = \"$actTag activation will expire $_xpr\"}\r\n\t\t}\r\n\t}\r\n\tif ($LicenseStatus -EQ 2) {\r\n\t\t$LicenseInf = \"Initial grace period\"\r\n\t\tif ($inGrace) {$ExpireMsg = \"$LicenseInf ends $_xpr\"}\r\n\t}\r\n\tif ($LicenseStatus -EQ 3) {\r\n\t\t$LicenseInf = \"Additional grace period (KMS license expired or hardware out of tolerance)\"\r\n\t\tif ($inGrace) {$ExpireMsg = \"Additional grace period ends $_xpr\"}\r\n\t}\r\n\tif ($LicenseStatus -EQ 4) {\r\n\t\t$LicenseInf = \"Non-genuine grace period\"\r\n\t\tif ($inGrace) {$ExpireMsg = \"$LicenseInf ends $_xpr\"}\r\n\t}\r\n\tif ($LicenseStatus -EQ 5 -And -Not $NT5) {\r\n\t\t$LicenseReason = '0x{0:X}' -f $LicReason\r\n\t\t$LicenseInf = \"Notification\"\r\n\t\t$LicenseMsg = \"Notification Reason: $LicenseReason\"\r\n\t\tif ($LicenseReason -EQ \"0xC004F00F\") {if ($null -NE $cKmsClient) {$LicenseMsg = $LicenseMsg + \" (KMS license expired).\"} else {$LicenseMsg = $LicenseMsg + \" (hardware out of tolerance).\"}}\r\n\t\tif ($LicenseReason -EQ \"0xC004F200\") {$LicenseMsg = $LicenseMsg + \" (non-genuine).\"}\r\n\t\tif ($LicenseReason -EQ \"0xC004F009\" -Or $LicenseReason -EQ \"0xC004F064\") {$LicenseMsg = $LicenseMsg + \" (grace time expired).\"}\r\n\t}\r\n\tif ($LicenseStatus -GT 5 -Or ($LicenseStatus -GT 4 -And $NT5)) {\r\n\t\t$LicenseInf = \"Unknown\"\r\n\t\t$LicenseMsg = $null\r\n\t}\r\n\tif ($LicenseStatus -EQ 6 -And -Not $Vista -And -Not $NT5) {\r\n\t\t$LicenseInf = \"Extended grace period\"\r\n\t\tif ($inGrace) {$ExpireMsg = \"$LicenseInf ends $_xpr\"}\r\n\t}\r\n\r\n\tif ($isPPK) {\r\n\t\t$propPkey | foreach { set $_ (SlGetInfoPKey $pkid $_) }\r\n\t}\r\n\r\n\tif ($winPR -And $isPPK -And -Not $NT8) {\r\n\t\t$uxd = SlGetInfoSku $licID 'UXDifferentiator'\r\n\t\t$script:primary += @{\r\n\t\t\taid = $licID;\r\n\t\t\tppk = $PartialProductKey;\r\n\t\t\tchn = $Channel;\r\n\t\t\tlst = $LicenseStatus;\r\n\t\t\tlcr = $LicReason;\r\n\t\t\tged = $gprMnt;\r\n\t\t\tevl = $EvaluationEndDate;\r\n\t\t\tdff = $uxd\r\n\t\t}\r\n\t}\r\n\r\n\tif ($IID -And $isPPK) {\r\n\t\t$OfflineInstallationId = SlGetInfoIID $licID\r\n\t}\r\n\r\n\tif ($Dlv) {\r\n\t\tif ($win8)\r\n\t\t{\r\n\t\t\t$RemainingSkuReArmCount = SlGetInfoSku $licID 'RemainingRearmCount'\r\n\t\t\t$RemainingAppReArmCount = SlGetInfoApp $strApp 'RemainingRearmCount'\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tif (($winID -And $NT7) -Or $strSLP -EQ $oslp)\r\n\t\t\t{\r\n\t\t\t\t$RemainingSLReArmCount = SlGetInfoApp $strApp 'RemainingRearmCount'\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t$RemainingSLReArmCount = SlGetInfoService 'RearmCount'\r\n\t\t\t}\r\n\t\t}\r\n\t\tif ($null -EQ $TrustedTime)\r\n\t\t{\r\n\t\t\t$TrustedTime = SlGetInfoSvcApp $strApp 'TrustedTime'\r\n\t\t}\r\n\t}\r\n\r\n\t& $isAll\r\n\tCONOUT \"Name: $Name\"\r\n\tCONOUT \"Description: $Description\"\r\n\tCONOUT \"Activation ID: $licID\"\r\n\tif ($null -NE $DigitalPID) {CONOUT \"Extended PID: $DigitalPID\"}\r\n\tif ($null -NE $DigitalPID2 -And $Dlv) {CONOUT \"Product ID: $DigitalPID2\"}\r\n\tif ($null -NE $OfflineInstallationId -And $IID) {CONOUT \"Installation ID: $OfflineInstallationId\"}\r\n\tif ($null -NE $Channel) {CONOUT \"Product Key Channel: $Channel\"}\r\n\tif ($null -NE $PartialProductKey) {CONOUT \"Partial Product Key: $PartialProductKey\"}\r\n\tCONOUT \"License Status: $LicenseInf\"\r\n\tif ($null -NE $LicenseMsg) {CONOUT \"$LicenseMsg\"}\r\n\tif ($LicenseStatus -NE 0 -And $EvaluationEndDate) {\r\n\t\t$EED = [DateTime]::FromFileTimeUtc($EvaluationEndDate).ToString('yyyy-MM-dd hh:mm:ss tt')\r\n\t\tCONOUT \"Evaluation End Date: $EED UTC\"\r\n\t}\r\n\tif ($LicenseStatus -NE 1 -And $licPHN -NE \"empty\") {\r\n\t\t$gPHN = [String]::IsNullOrEmpty($licPHN) -NE $true\r\n\t\tCONOUT \"Phone activatable: $($gPHN.ToString())\"\r\n\t}\r\n\tif ($Dlv) {\r\n\t\tif ($null -NE $RemainingSLReArmCount) {\r\n\t\t\tCONOUT \"Remaining $reapp rearm count: $RemainingSLReArmCount\"\r\n\t\t}\r\n\t\tif ($null -NE $RemainingSkuReArmCount) {\r\n\t\t\tCONOUT \"Remaining $reapp rearm count: $RemainingAppReArmCount\"\r\n\t\t\tCONOUT \"Remaining SKU rearm count: $RemainingSkuReArmCount\"\r\n\t\t}\r\n\t\tif ($LicenseStatus -NE 0 -And $TrustedTime) {\r\n\t\t\t$TTD = [DateTime]::FromFileTime($TrustedTime).ToString('yyyy-MM-dd hh:mm:ss tt')\r\n\t\t\tCONOUT \"Trusted time: $TTD\"\r\n\t\t}\r\n\t}\r\n\tif (!$isPPK) {\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($win8 -And $VLActivationType -EQ 1) {\r\n\t\tDetectAdbaClient\r\n\t\t$cKmsClient = $null\r\n\t}\r\n\r\n\tif ($winID -And $null -NE $cAvmClient) {\r\n\t\tDetectAvmClient\r\n\t}\r\n\r\n\t$chkSub = ($winPR -And $isSub)\r\n\r\n\t$chkSLS = ($null -NE $cKmsClient -Or $null -NE $cKmsServer -Or $chkSub)\r\n\r\n\tif (!$chkSLS) {\r\n\t\tif ($null -NE $ExpireMsg) {CONOUT \"`n    $ExpireMsg\"}\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($null -NE $cKmsClient) {\r\n\t\tDetectKmsClient\r\n\t}\r\n\r\n\tif ($null -NE $cKmsServer) {\r\n\t\tif ($null -NE $ExpireMsg) {CONOUT \"`n    $ExpireMsg\"}\r\n\t\tDetectKmsHost\r\n\t} else {\r\n\t\tif ($null -NE $ExpireMsg) {CONOUT \"`n    $ExpireMsg\"}\r\n\t}\r\n\r\n\tif ($chkSub) {\r\n\t\tDetectSubscription\r\n\t}\r\n\r\n}\r\n\r\nfunction ParseList($strSLP, $strApp, $arrList)\r\n{\r\n\tforeach ($entry in $arrList)\r\n\t{\r\n\t\tGetResult $strSLP $strApp $entry\r\n\t\tCONOUT \"$line3\"\r\n\t\t& $noAll\r\n\t}\r\n}\r\n#endregion\r\n\r\n#region vNextDiag\r\nif ($PSVersionTable.PSVersion.Major -Lt 3)\r\n{\r\n\tfunction ConvertFrom-Json\r\n\t{\r\n\t\t[CmdletBinding()]\r\n\t\tParam(\r\n\t\t\t[Parameter(ValueFromPipeline=$true)][Object]$item\r\n\t\t)\r\n\t\t[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Web.Extensions\")\r\n\t\t$psjs = New-Object System.Web.Script.Serialization.JavaScriptSerializer\r\n\t\tReturn ,$psjs.DeserializeObject($item)\r\n\t}\r\n\tfunction ConvertTo-Json\r\n\t{\r\n\t\t[CmdletBinding()]\r\n\t\tParam(\r\n\t\t\t[Parameter(ValueFromPipeline=$true)][Object]$item\r\n\t\t)\r\n\t\t[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Web.Extensions\")\r\n\t\t$psjs = New-Object System.Web.Script.Serialization.JavaScriptSerializer\r\n\t\tReturn $psjs.Serialize($item)\r\n\t}\r\n}\r\n\r\nfunction PrintModePerPridFromRegistry\r\n{\r\n\t$vNextRegkey = \"HKCU:\\SOFTWARE\\Microsoft\\Office\\16.0\\Common\\Licensing\\LicensingNext\"\r\n\t$vNextPrids = Get-Item -Path $vNextRegkey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty 'property' -ErrorAction SilentlyContinue | Where-Object -FilterScript {$_.ToLower() -like \"*retail\" -or $_.ToLower() -like \"*volume\"}\r\n\tIf ($null -Eq $vNextPrids)\r\n\t{\r\n\t\tCONOUT \"`nNo registry keys found.\"\r\n\t\tReturn\r\n\t}\r\n\tCONOUT \"`r\"\r\n\t$vNextPrids | ForEach `\r\n\t{\r\n\t\t$mode = (Get-ItemProperty -Path $vNextRegkey -Name $_).$_\r\n\t\tSwitch ($mode)\r\n\t\t{\r\n\t\t\t2 { $mode = \"vNext\"; Break }\r\n\t\t\t3 { $mode = \"Device\"; Break }\r\n\t\t\tDefault { $mode = \"Legacy\"; Break }\r\n\t\t}\r\n\t\tCONOUT \"$_ = $mode\"\r\n\t}\r\n}\r\n\r\nfunction PrintSharedComputerLicensing\r\n{\r\n\t$scaRegKey = \"HKLM:\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration\"\r\n\t$scaValue = Get-ItemProperty -Path $scaRegKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty \"SharedComputerLicensing\" -ErrorAction SilentlyContinue\r\n\t$scaRegKey2 = \"HKLM:\\SOFTWARE\\Microsoft\\Office\\16.0\\Common\\Licensing\"\r\n\t$scaValue2 = Get-ItemProperty -Path $scaRegKey2 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty \"SharedComputerLicensing\" -ErrorAction SilentlyContinue\r\n\t$scaPolicyKey = \"HKLM:\\SOFTWARE\\Policies\\Microsoft\\Office\\16.0\\Common\\Licensing\"\r\n\t$scaPolicyValue = Get-ItemProperty -Path $scaPolicyKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty \"SharedComputerLicensing\" -ErrorAction SilentlyContinue\r\n\tIf ($null -Eq $scaValue -And $null -Eq $scaValue2 -And $null -Eq $scaPolicyValue)\r\n\t{\r\n\t\tCONOUT \"`nNo registry keys found.\"\r\n\t\tReturn\r\n\t}\r\n\t$scaModeValue = $scaValue -Or $scaValue2 -Or $scaPolicyValue\r\n\tIf ($scaModeValue -Eq 0)\r\n\t{\r\n\t\t$scaMode = \"Disabled\"\r\n\t}\r\n\tIf ($scaModeValue -Eq 1)\r\n\t{\r\n\t\t$scaMode = \"Enabled\"\r\n\t}\r\n\tCONOUT \"`nStatus: $scaMode\"\r\n\tCONOUT \"`r\"\r\n\t$tokenFiles = $null\r\n\t$tokenPath = \"${env:LOCALAPPDATA}\\Microsoft\\Office\\16.0\\Licensing\"\r\n\tIf (Test-Path $tokenPath)\r\n\t{\r\n\t\t$tokenFiles = Get-ChildItem -Path $tokenPath -Filter \"*authString*\" -Recurse | Where-Object { !$_.PSIsContainer }\r\n\t}\r\n\tIf ($null -Eq $tokenFiles -Or $tokenFiles.Length -Eq 0)\r\n\t{\r\n\t\tCONOUT \"No tokens found.\"\r\n\t\tReturn\r\n\t}\r\n\t$tokenFiles | ForEach `\r\n\t{\r\n\t\t$tokenParts = (Get-Content -Encoding Unicode -Path $_.FullName).Split('_')\r\n\t\t$output = New-Object PSObject\r\n\t\t$output | Add-Member 8 'ACID' $tokenParts[0];\r\n\t\t$output | Add-Member 8 'User' $tokenParts[3];\r\n\t\t$output | Add-Member 8 'NotBefore' $tokenParts[4];\r\n\t\t$output | Add-Member 8 'NotAfter' $tokenParts[5];\r\n\t\tWrite-Output $output\r\n\t}\r\n}\r\n\r\nfunction PrintLicensesInformation\r\n{\r\n\tParam(\r\n\t\t[ValidateSet(\"NUL\", \"Device\")]\r\n\t\t[String]$mode\r\n\t)\r\n\tIf ($mode -Eq \"NUL\")\r\n\t{\r\n\t\t$licensePath = \"${env:LOCALAPPDATA}\\Microsoft\\Office\\Licenses\"\r\n\t}\r\n\tElseIf ($mode -Eq \"Device\")\r\n\t{\r\n\t\t$licensePath = \"${env:PROGRAMDATA}\\Microsoft\\Office\\Licenses\"\r\n\t}\r\n\t$licenseFiles = $null\r\n\tIf (Test-Path $licensePath)\r\n\t{\r\n\t\t$licenseFiles = Get-ChildItem -Path $licensePath -Recurse | Where-Object { !$_.PSIsContainer }\r\n\t}\r\n\tIf ($null -Eq $licenseFiles -Or $licenseFiles.Length -Eq 0)\r\n\t{\r\n\t\tCONOUT \"`nNo licenses found.\"\r\n\t\tReturn\r\n\t}\r\n\t$licenseFiles | ForEach `\r\n\t{\r\n\t\t$license = (Get-Content -Encoding Unicode $_.FullName | ConvertFrom-Json).License\r\n\t\t$decodedLicense = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($license)) | ConvertFrom-Json\r\n\t\t$licenseType = $decodedLicense.LicenseType\r\n\t\tIf ($null -Ne $decodedLicense.ExpiresOn)\r\n\t\t{\r\n\t\t\t$expiry = [System.DateTime]::Parse($decodedLicense.ExpiresOn, $null, 'AdjustToUniversal')\r\n\t\t}\r\n\t\tElse\r\n\t\t{\r\n\t\t\t$expiry = New-Object System.DateTime\r\n\t\t}\r\n\t\t$licenseState = \"Grace\"\r\n\t\tIf ((Get-Date) -Gt (Get-Date $decodedLicense.Metadata.NotAfter))\r\n\t\t{\r\n\t\t\t$licenseState = \"RFM\"\r\n\t\t}\r\n\t\tElseIf ((Get-Date) -Lt (Get-Date $expiry))\r\n\t\t{\r\n\t\t\t$licenseState = \"Licensed\"\r\n\t\t}\r\n\t\t$output = New-Object PSObject\r\n\t\t$output | Add-Member 8 'File' $_.PSChildName;\r\n\t\t$output | Add-Member 8 'Version' $_.Directory.Name;\r\n\t\t$output | Add-Member 8 'Type' \"User|${licenseType}\";\r\n\t\t$output | Add-Member 8 'Product' $decodedLicense.ProductReleaseId;\r\n\t\t$output | Add-Member 8 'Acid' $decodedLicense.Acid;\r\n\t\tIf ($mode -Eq \"Device\") { $output | Add-Member 8 'DeviceId' $decodedLicense.Metadata.DeviceId; }\r\n\t\t$output | Add-Member 8 'LicenseState' $licenseState;\r\n\t\t$output | Add-Member 8 'EntitlementStatus' $decodedLicense.Status;\r\n\t\t$output | Add-Member 8 'EntitlementExpiration' (\"N/A\", $decodedLicense.ExpiresOn)[!($null -eq $decodedLicense.ExpiresOn)];\r\n\t\t$output | Add-Member 8 'ReasonCode' (\"N/A\", $decodedLicense.ReasonCode)[!($null -eq $decodedLicense.ReasonCode)];\r\n\t\t$output | Add-Member 8 'NotBefore' $decodedLicense.Metadata.NotBefore;\r\n\t\t$output | Add-Member 8 'NotAfter' $decodedLicense.Metadata.NotAfter;\r\n\t\t$output | Add-Member 8 'NextRenewal' $decodedLicense.Metadata.RenewAfter;\r\n\t\t$output | Add-Member 8 'TenantId' (\"N/A\", $decodedLicense.Metadata.TenantId)[!($null -eq $decodedLicense.Metadata.TenantId)];\r\n\t\t#$output.PSObject.Properties | foreach { $ht = @{} } { $ht[$_.Name] = $_.Value } { $output = $ht | ConvertTo-Json }\r\n\t\tWrite-Output $output\r\n\t}\r\n}\r\n\r\nfunction vNextDiagRun\r\n{\r\n\t$fNUL = ([IO.Directory]::Exists(\"${env:LOCALAPPDATA}\\Microsoft\\Office\\Licenses\")) -and ([IO.Directory]::GetFiles(\"${env:LOCALAPPDATA}\\Microsoft\\Office\\Licenses\", \"*\", 1).Length -GT 0)\r\n\t$fDev = ([IO.Directory]::Exists(\"${env:PROGRAMDATA}\\Microsoft\\Office\\Licenses\")) -and ([IO.Directory]::GetFiles(\"${env:PROGRAMDATA}\\Microsoft\\Office\\Licenses\", \"*\", 1).Length -GT 0)\r\n\t$rPID = $null -NE (GP \"HKCU:\\SOFTWARE\\Microsoft\\Office\\16.0\\Common\\Licensing\\LicensingNext\" -EA 0 | select -Expand 'property' -EA 0 | where -Filter {$_.ToLower() -like \"*retail\" -or $_.ToLower() -like \"*volume\"})\r\n\t$rSCA = $null -NE (GP \"HKLM:\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration\" -EA 0 | select -Expand \"SharedComputerLicensing\" -EA 0)\r\n\t$rSCL = $null -NE (GP \"HKLM:\\SOFTWARE\\Microsoft\\Office\\16.0\\Common\\Licensing\" -EA 0 | select -Expand \"SharedComputerLicensing\" -EA 0)\r\n\r\n\tif (($fNUL -Or $fDev -Or $rPID -Or $rSCA -Or $rSCL) -EQ $false) {\r\n\t\tReturn\r\n\t}\r\n\r\n\t& $isAll\r\n\tCONOUT \"$line2\"\r\n\tCONOUT \"===                  Office vNext Status                 ===\"\r\n\tCONOUT \"$line2\"\r\n\tCONOUT \"`n========== Mode per ProductReleaseId ==========\"\r\n\tPrintModePerPridFromRegistry\r\n\tCONOUT \"`n========== Shared Computer Licensing ==========\"\r\n\tPrintSharedComputerLicensing\r\n\tCONOUT \"`n========== vNext licenses ===========\"\r\n\tPrintLicensesInformation -Mode \"NUL\"\r\n\tCONOUT \"`n========== Device licenses ==========\"\r\n\tPrintLicensesInformation -Mode \"Device\"\r\n\tCONOUT \"$line3\"\r\n\tCONOUT \"`r\"\r\n}\r\n#endregion\r\n\r\n#region clic\r\n\r\n<#\r\n;;; Source: https://github.com/asdcorp/clic\r\n;;; Powershell port: abbodi1406\r\n\r\nCopyright 2023 asdcorp\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of\r\nthis software and associated documentation files (the \"Software\"), to deal in\r\nthe Software without restriction, including without limitation the rights to\r\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r\nthe Software, and to permit persons to whom the Software is furnished to do so,\r\nsubject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n#>\r\n\r\nfunction InitializeDigitalLicenseCheck {\r\n\t$CAB = [System.Reflection.Emit.CustomAttributeBuilder]\r\n\r\n\t$ICom = $Module.DefineType('EUM.IEUM', 'Public, Interface, Abstract, Import')\r\n\t$ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.ComImportAttribute].GetConstructor(@()), @()))\r\n\t$ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.GuidAttribute].GetConstructor(@([String])), @('F2DCB80D-0670-44BC-9002-CD18688730AF')))\r\n\t$ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.InterfaceTypeAttribute].GetConstructor(@([Int16])), @([Int16]1)))\r\n\r\n\t1..4 | % { [void]$ICom.DefineMethod('VF'+$_, 'Public, Virtual, HideBySig, NewSlot, Abstract', 'Standard, HasThis', [Void], @()) }\r\n\t[void]$ICom.DefineMethod('AcquireModernLicenseForWindows', 1478, 33, [Int32], @([Int32], [Int32].MakeByRefType()))\r\n\r\n\t$IEUM = $ICom.CreateType()\r\n}\r\n\r\nfunction PrintStateData {\r\n\t$pwszStateData = 0\r\n\t$cbSize = 0\r\n\r\n\tif ($Win32::SLGetWindowsInformation(\r\n\t\t\"Security-SPP-Action-StateData\",\r\n\t\t[ref]$null,\r\n\t\t[ref]$cbSize,\r\n\t\t[ref]$pwszStateData\r\n\t)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\t[string[]]$pwszStateString = $Marshal::PtrToStringUni($pwszStateData) -replace \";\", \"`n    \"\r\n\tCONOUT (\"    $pwszStateString\")\r\n\r\n\t$Marshal::FreeHGlobal($pwszStateData)\r\n\treturn $TRUE\r\n}\r\n\r\nfunction PrintLastActivationHResult {\r\n\t$pdwLastHResult = 0\r\n\t$cbSize = 0\r\n\r\n\tif ($Win32::SLGetWindowsInformation(\r\n\t\t\"Security-SPP-LastWindowsActivationHResult\",\r\n\t\t[ref]$null,\r\n\t\t[ref]$cbSize,\r\n\t\t[ref]$pdwLastHResult\r\n\t)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\tCONOUT (\"    LastActivationHResult=0x{0:x8}\" -f $Marshal::ReadInt32($pdwLastHResult))\r\n\r\n\t$Marshal::FreeHGlobal($pdwLastHResult)\r\n\treturn $TRUE\r\n}\r\n\r\nfunction PrintLastActivationTime {\r\n\t$pqwLastTime = 0\r\n\t$cbSize = 0\r\n\r\n\tif ($Win32::SLGetWindowsInformation(\r\n\t\t\"Security-SPP-LastWindowsActivationTime\",\r\n\t\t[ref]$null,\r\n\t\t[ref]$cbSize,\r\n\t\t[ref]$pqwLastTime\r\n\t)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\t$actTime = $Marshal::ReadInt64($pqwLastTime)\r\n\tif ($actTime -ne 0) {\r\n\t\tCONOUT (\"    LastActivationTime={0}\" -f [DateTime]::FromFileTimeUtc($actTime).ToString(\"yyyy/MM/dd:HH:mm:ss\"))\r\n\t}\r\n\r\n\t$Marshal::FreeHGlobal($pqwLastTime)\r\n\treturn $TRUE\r\n}\r\n\r\nfunction PrintIsWindowsGenuine {\r\n\t$dwGenuine = 0\r\n\r\n\tif ($Win32::SLIsWindowsGenuineLocal([ref]$dwGenuine)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\tif ($dwGenuine -lt 5) {\r\n\t\tCONOUT (\"    IsWindowsGenuine={0}\" -f $ppwszGenuineStates[$dwGenuine])\r\n\t} else {\r\n\t\tCONOUT (\"    IsWindowsGenuine={0}\" -f $dwGenuine)\r\n\t}\r\n\r\n\treturn $TRUE\r\n}\r\n\r\nfunction PrintDigitalLicenseStatus {\r\n\ttry {\r\n\t\t. InitializeDigitalLicenseCheck\r\n\t\t$ComObj = New-Object -Com EditionUpgradeManagerObj.EditionUpgradeManager\r\n\t} catch {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\t$parameters = 1, $null\r\n\r\n\tif ([EUM.IEUM].GetMethod(\"AcquireModernLicenseForWindows\").Invoke($ComObj, $parameters)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\t$dwReturnCode = $parameters[1]\r\n\t[bool]$bDigitalLicense = $FALSE\r\n\r\n\t$bDigitalLicense = (($dwReturnCode -ge 0) -and ($dwReturnCode -ne 1))\r\n\tCONOUT (\"    IsDigitalLicense={0}\" -f (BoolToWStr $bDigitalLicense))\r\n\r\n\treturn $TRUE\r\n}\r\n\r\nfunction PrintSubscriptionStatus {\r\n\t$dwSupported = 0\r\n\r\n\tif ($winbuild -ge 15063) {\r\n\t\t$pwszPolicy = \"ConsumeAddonPolicySet\"\r\n\t} else {\r\n\t\t$pwszPolicy = \"Allow-WindowsSubscription\"\r\n\t}\r\n\r\n\tif ($Win32::SLGetWindowsInformationDWORD($pwszPolicy, [ref]$dwSupported)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\tCONOUT (\"    SubscriptionSupportedEdition={0}\" -f (BoolToWStr $dwSupported))\r\n\r\n\t$pStatus = $Marshal::AllocHGlobal($Marshal::SizeOf([Type]$SubStatus))\r\n\tif ($Win32::ClipGetSubscriptionStatus([ref]$pStatus)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\t$sStatus = [Activator]::CreateInstance($SubStatus)\r\n\t$sStatus = $Marshal::PtrToStructure($pStatus, [Type]$SubStatus)\r\n\t$Marshal::FreeHGlobal($pStatus)\r\n\r\n\tCONOUT (\"    SubscriptionEnabled={0}\" -f (BoolToWStr $sStatus.dwEnabled))\r\n\r\n\tif ($sStatus.dwEnabled -eq 0) {\r\n\t\treturn $TRUE\r\n\t}\r\n\r\n\tCONOUT (\"    SubscriptionSku={0}\" -f $sStatus.dwSku)\r\n\tCONOUT (\"    SubscriptionState={0}\" -f $sStatus.dwState)\r\n\r\n\treturn $TRUE\r\n}\r\n\r\nfunction ClicRun\r\n{\r\n\t& $isAll\r\n\tCONOUT \"Client Licensing Check information:\"\r\n\r\n\t$null = PrintStateData\r\n\t$null = PrintLastActivationHResult\r\n\t$null = PrintLastActivationTime\r\n\t$null = PrintIsWindowsGenuine\r\n\r\n\tif ($DllDigital) {\r\n\t\t$null = PrintDigitalLicenseStatus\r\n\t}\r\n\r\n\tif ($DllSubscription) {\r\n\t\t$null = PrintSubscriptionStatus\r\n\t}\r\n\r\n\tCONOUT \"$line3\"\r\n\t& $noAll\r\n}\r\n#endregion\r\n\r\n#region clc\r\nfunction clcGetExpireKrn\r\n{\r\n\t$tData = 0\r\n\t$cData = 0\r\n\t$bData = 0\r\n\r\n\t$hrRet = $Win32::SLGetWindowsInformation(\r\n\t\t\"Kernel-ExpirationDate\",\r\n\t\t[ref]$tData,\r\n\t\t[ref]$cData,\r\n\t\t[ref]$bData\r\n\t)\r\n\r\n\tif ($hrRet -Or !$cData -Or $tData -NE 3)\r\n\t{\r\n\t\treturn $null\r\n\t}\r\n\r\n\t$year = $Marshal::ReadInt16($bData, 0)\r\n\tif ($year -EQ 0 -Or $year -EQ 1601)\r\n\t{\r\n\t\t$rData = $null\r\n\t}\r\n\telse\r\n\t{\r\n\t\t$rData = '{0}/{1}/{2}:{3}:{4}:{5}' -f $year, $Marshal::ReadInt16($bData, 2), $Marshal::ReadInt16($bData, 4), $Marshal::ReadInt16($bData, 6), $Marshal::ReadInt16($bData, 8), $Marshal::ReadInt16($bData, 10)\r\n\t}\r\n\r\n\t#$Marshal::FreeHGlobal($bData)\r\n\treturn $rData\r\n}\r\n\r\nfunction clcGetExpireSys\r\n{\r\n\t$kuser = $Marshal::ReadInt64((New-Object IntPtr(0x7FFE02C8)))\r\n\r\n\tif ($kuser -EQ 0)\r\n\t{\r\n\t\treturn $null\r\n\t}\r\n\r\n\t$rData = [DateTime]::FromFileTimeUtc($kuser).ToString('yyyy/MM/dd:HH:mm:ss')\r\n\treturn $rData\r\n}\r\n\r\nfunction clcGetLicensingState($dwState)\r\n{\r\n\tif ($dwState -EQ 5) {\r\n\t\t$dwState = 3\r\n\t} elseif ($dwState -EQ 3 -Or $dwState -EQ 4 -Or $dwState -EQ 6) {\r\n\t\t$dwState = 2\r\n\t} elseif ($dwState -GT 6) {\r\n\t\t$dwState = 4\r\n\t}\r\n\r\n\t$rData = '{0}' -f $ppwszLicensingStates[$dwState]\r\n\treturn $rData\r\n}\r\n\r\nfunction clcGetGenuineState($AppId)\r\n{\r\n\t$dwGenuine = 0\r\n\r\n\tif ($NT7) {\r\n\t\t$hrRet = $Win32::SLIsWindowsGenuineLocal([ref]$dwGenuine)\r\n\t} else {\r\n\t\t$hrRet = $Win32::SLIsGenuineLocal([ref][Guid]$AppId, [ref]$dwGenuine, 0)\r\n\t}\r\n\r\n\tif ($hrRet)\r\n\t{\r\n\t\t$dwGenuine = 4\r\n\t}\r\n\r\n\tif ($dwGenuine -LT 5) {\r\n\t\t$rData = '{0}' -f $ppwszGenuineStates[$dwGenuine]\r\n\t} else {\r\n\t\t$rData = $dwGenuine\r\n\t}\r\n\treturn $rData\r\n}\r\n\r\nfunction ClcRun\r\n{\r\n\t$prs = $script:primary[0]\r\n\tif ($null -EQ $prs) {\r\n\t\treturn\r\n\t}\r\n\r\n\t$lState = clcGetLicensingState $prs.lst\r\n\t$uState = clcGetGenuineState $winApp\r\n\t$TbbKrn = clcGetExpireKrn\r\n\t$TbbSys = clcGetExpireSys\r\n\tif ($null -NE $TbbKrn) {\r\n\t\t$ked = $TbbKrn\r\n\t} elseif ($null -NE $TbbSys) {\r\n\t\t$ked = $TbbSys\r\n\t}\r\n\r\n\t& $isAll\r\n\tCONOUT \"Client Licensing Check information:\"\r\n\r\n\tCONOUT (\"    AppId={0}\" -f $winApp)\r\n\tif ($prs.ged) { CONOUT (\"    GraceEndDate={0}\" -f ([DateTime]::UtcNow.AddMinutes($prs.ged).ToString('yyyy/MM/dd:HH:mm:ss'))) }\r\n\tif ($null -NE $ked) { CONOUT (\"    KernelTimebombDate={0}\" -f $ked) }\r\n\tCONOUT (\"    LastConsumptionReason=0x{0:x8}\" -f $prs.lcr)\r\n\tif ($prs.evl) { CONOUT (\"    LicenseExpirationDate={0}\" -f ([DateTime]::FromFileTimeUtc($prs.evl).ToString('yyyy/MM/dd:HH:mm:ss'))) }\r\n\tCONOUT (\"    LicenseState={0}\" -f $lState)\r\n\tCONOUT (\"    PartialProductKey={0}\" -f $prs.ppk)\r\n\tCONOUT (\"    ProductKeyType={0}\" -f $prs.chn)\r\n\tCONOUT (\"    SkuId={0}\" -f $prs.aid)\r\n\tCONOUT (\"    uxDifferentiator={0}\" -f $prs.dff)\r\n\tCONOUT (\"    IsWindowsGenuine={0}\" -f $uState)\r\n\r\n\tCONOUT \"$line3\"\r\n\t& $noAll\r\n}\r\n#endregion\r\n\r\n$Host.UI.RawUI.WindowTitle = \"Check Activation Status\"\r\nif ($All.IsPresent) {\r\n\t$B=$Host.UI.RawUI.BufferSize;$B.Height=3000;$Host.UI.RawUI.BufferSize=$B;\r\n\tif (!$Pass.IsPresent) {clear;}\r\n}\r\n\r\n$SysPath = \"$env:SystemRoot\\System32\"\r\nif (Test-Path \"$env:SystemRoot\\Sysnative\\reg.exe\") {\r\n\t$SysPath = \"$env:SystemRoot\\Sysnative\"\r\n}\r\n\r\n$wslp = \"SoftwareLicensingProduct\"\r\n$wsls = \"SoftwareLicensingService\"\r\n$oslp = \"OfficeSoftwareProtectionProduct\"\r\n$osls = \"OfficeSoftwareProtectionService\"\r\n$winApp = \"55c92734-d682-4d71-983e-d6ec3f16059f\"\r\n$o14App = \"59a52881-a989-479d-af46-f275c6370663\"\r\n$o15App = \"0ff1ce15-a989-479d-af46-f275c6370663\"\r\n$isSub = ($winbuild -GE 26000) -And (Select-String -Path \"$SysPath\\wbem\\sppwmi.mof\" -Encoding unicode -Pattern \"SubscriptionType\")\r\n$DllDigital = ($winbuild -GE 14393) -And (Test-Path \"$SysPath\\EditionUpgradeManagerObj.dll\")\r\n$DllSubscription = ($winbuild -GE 14393) -And (Test-Path \"$SysPath\\Clipc.dll\")\r\n$VLActTypes = @(\"All\", \"AD\", \"KMS\", \"Token\")\r\n$OPKeyPath = \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform\"\r\n$SPKeyPath = \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\"\r\n$SLKeyPath = \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\"\r\n$NSKeyPath = \"HKEY_USERS\\S-1-5-20\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\"\r\n$propPrd = 'Name', 'Description', 'TrustedTime', 'VLActivationType'\r\n$propPkey = 'PartialProductKey', 'Channel', 'DigitalPID', 'DigitalPID2'\r\n$propKMSServer = 'KeyManagementServiceCurrentCount', 'KeyManagementServiceTotalRequests', 'KeyManagementServiceFailedRequests', 'KeyManagementServiceUnlicensedRequests', 'KeyManagementServiceLicensedRequests', 'KeyManagementServiceOOBGraceRequests', 'KeyManagementServiceOOTGraceRequests', 'KeyManagementServiceNonGenuineGraceRequests', 'KeyManagementServiceNotificationRequests'\r\n$propKMSClient = 'CustomerPID', 'KeyManagementServiceName', 'KeyManagementServicePort', 'DiscoveredKeyManagementServiceName', 'DiscoveredKeyManagementServicePort', 'DiscoveredKeyManagementServiceIpAddress', 'VLActivationInterval', 'VLRenewalInterval', 'KeyManagementServiceLookupDomain'\r\n$propKMSVista  = 'CustomerPID', 'KeyManagementServiceName', 'VLActivationInterval', 'VLRenewalInterval'\r\n$propADBA = 'ADActivationObjectName', 'ADActivationObjectDN', 'ADActivationCsvlkPID', 'ADActivationCsvlkSkuID'\r\n$propAVMA = 'InheritedActivationId', 'InheritedActivationHostMachineName', 'InheritedActivationHostDigitalPid2', 'InheritedActivationActivationTime'\r\n$primary = @()\r\n$ppwszGenuineStates = @(\r\n\t\"SL_GEN_STATE_IS_GENUINE\",\r\n\t\"SL_GEN_STATE_INVALID_LICENSE\",\r\n\t\"SL_GEN_STATE_TAMPERED\",\r\n\t\"SL_GEN_STATE_OFFLINE\",\r\n\t\"SL_GEN_STATE_LAST\"\r\n)\r\n$ppwszLicensingStates = @(\r\n\t\"SL_LICENSING_STATUS_UNLICENSED\",\r\n\t\"SL_LICENSING_STATUS_LICENSED\",\r\n\t\"SL_LICENSING_STATUS_IN_GRACE_PERIOD\",\r\n\t\"SL_LICENSING_STATUS_NOTIFICATION\",\r\n\t\"SL_LICENSING_STATUS_LAST\"\r\n)\r\n\r\n'cW1nd0ws', 'c0ff1ce15', 'c0ff1ce14', 'ospp14', 'ospp15' | foreach {set $_ @()}\r\n\r\n$offsvc = \"osppsvc\"\r\nif ($NT7 -Or -Not $NT6) {$winsvc = \"sppsvc\"} else {$winsvc = \"slsvc\"}\r\n\r\ntry {gsv $winsvc -EA 1 | Out-Null; $WsppHook = 1} catch {$WsppHook = 0}\r\ntry {gsv $offsvc -EA 1 | Out-Null; $OsppHook = 1} catch {$OsppHook = 0}\r\n\r\nif (Test-Path \"$SysPath\\sppc.dll\") {\r\n\t$SLdll = 'sppc.dll'\r\n} elseif (Test-Path \"$SysPath\\slc.dll\") {\r\n\t$SLdll = 'slc.dll'\r\n} else {\r\n\t$WsppHook = 0\r\n}\r\n\r\nif ($OsppHook -NE 0) {\r\n\t$OLdll = (strGetRegistry $OPKeyPath \"Path\") + 'osppc.dll'\r\n\tif (!(Test-Path \"$OLdll\")) {$OsppHook = 0}\r\n}\r\n\r\nif ($WsppHook -NE 0) {\r\n\tif ($NT6 -And -Not $NT7 -And -Not $Admin) {\r\n\t\tif ($null -EQ [Diagnostics.Process]::GetProcessesByName(\"$winsvc\")[0].ProcessName) {$WsppHook = 0; CONOUT \"`nError: failed to start $winsvc Service.`n\"}\r\n\t} else {\r\n\t\ttry {sasv $winsvc -EA 1} catch {$WsppHook = 0; CONOUT \"`nError: failed to start $winsvc Service.`n\"}\r\n\t}\r\n}\r\n\r\nif ($WsppHook -NE 0) {\r\n\t. InitializePInvoke $SLdll $false\r\n\t$hSLC = 0\r\n\t[void]$Win32::SLOpen([ref]$hSLC)\r\n\r\n\t$cW1nd0ws  = SlGetInfoSLID $winApp\r\n\t$c0ff1ce15 = SlGetInfoSLID $o15App\r\n\t$c0ff1ce14 = SlGetInfoSLID $o14App\r\n}\r\n\r\nif ($cW1nd0ws.Count -GT 0)\r\n{\r\n\techoWindows\r\n\tParseList $wslp $winApp $cW1nd0ws\r\n}\r\nelseif ($NT6)\r\n{\r\n\techoWindows\r\n\tCONOUT \"Error: product key not found.`n\"\r\n}\r\n\r\nif ($NT6 -And -Not $NT8) {\r\n\tClcRun\r\n}\r\n\r\nif ($NT8) {\r\n\tClicRun\r\n}\r\n\r\n$doMSG = 1\r\n\r\nif ($c0ff1ce15.Count -GT 0)\r\n{\r\n\tCheckOhook\r\n\techoOffice\r\n\tParseList $wslp $o15App $c0ff1ce15\r\n}\r\n\r\nif ($c0ff1ce14.Count -GT 0)\r\n{\r\n\techoOffice\r\n\tParseList $wslp $o14App $c0ff1ce14\r\n}\r\n\r\nif ($hSLC) {\r\n\t[void]$Win32::SLClose($hSLC)\r\n}\r\n\r\nif ($OsppHook -NE 0) {\r\n\ttry {sasv $offsvc -EA 1} catch {$OsppHook = 0; CONOUT \"`nError: failed to start $offsvc Service.`n\"}\r\n}\r\n\r\nif ($OsppHook -NE 0) {\r\n\t. InitializePInvoke \"$OLdll\" $true\r\n\t$hSLC = 0\r\n\t[void]$Win32::SLOpen([ref]$hSLC)\r\n\r\n\t$ospp15 = SlGetInfoSLID $o15App\r\n\t$ospp14 = SlGetInfoSLID $o14App\r\n}\r\n\r\nif ($ospp15.Count -GT 0)\r\n{\r\n\techoOffice\r\n\tParseList $oslp $o15App $ospp15\r\n}\r\n\r\nif ($ospp14.Count -GT 0)\r\n{\r\n\techoOffice\r\n\tParseList $oslp $o14App $ospp14\r\n}\r\n\r\nif ($hSLC) {\r\n\t[void]$Win32::SLClose($hSLC)\r\n}\r\n\r\nif ($NT7) {\r\n\tvNextDiagRun\r\n}\r\n\r\nExitScript 0\r\n:sppmgr:\r\n\r\n:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n\r\n:troubleshoot\r\n\r\nset \"line=_________________________________________________________________________________________________\"\r\n\r\n:at_menu\r\n\r\ncls\r\ntitle  Troubleshoot %masver%\r\nif not defined terminal mode 77, 30\r\n\r\necho:\r\necho:\r\necho:\r\necho:\r\necho:       _______________________________________________________________\r\necho:                                                   \r\ncall :dk_color2 %_White% \"             [1] \" %_Green% \"Help\"\r\necho:             ___________________________________________________\r\necho:                                                                      \r\necho:             [2] Dism RestoreHealth\r\necho:             [3] SFC Scannow\r\necho:                                                                      \r\necho:             [4] Fix WMI\r\necho:             [5] Fix Licensing\r\necho:             [6] Fix WPA Registry\r\necho:             ___________________________________________________\r\necho:\r\necho:             [0] %_exitmsg%\r\necho:       _______________________________________________________________\r\necho:          \r\ncall :dk_color2 %_White% \"            \" %_Green% \"Choose a menu option using your keyboard :\"\r\nchoice /C:1234560 /N\r\nset _erl=%errorlevel%\r\n\r\nif %_erl%==7 exit /b\r\nif %_erl%==6 start %mas%fix-wpa-registry &goto at_menu\r\nif %_erl%==5 goto:retokens\r\nif %_erl%==4 goto:fixwmi\r\nif %_erl%==3 goto:sfcscan\r\nif %_erl%==2 goto:dism_rest\r\nif %_erl%==1 (start %selfgit% & start %github% & start %mas%troubleshoot & goto at_menu)\r\ngoto :at_menu\r\n\r\n::========================================================================================================================================\r\n\r\n:dism_rest\r\n\r\ncls\r\nif not defined terminal mode 98, 30\r\ntitle  Dism /English /Online /Cleanup-Image /RestoreHealth\r\n\r\nif %winbuild% LSS 9200 (\r\n%eline%\r\necho Unsupported OS version detected.\r\necho This command only works on Windows 8/8.1/10/11 and their Server equivalents.\r\ngoto :at_back\r\n)\r\n\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\necho:\r\nif defined _int (\r\necho      Checking Internet Connection  [Connected]\r\n) else (\r\ncall :dk_color2 %_White% \"     \" %Red% \"Checking Internet Connection  [Not connected]\"\r\n)\r\n\r\necho %line%\r\necho:\r\necho      DISM uses Windows Update to provide replacement files required to fix corruption.\r\necho      This will take 5-15 minutes or more..\r\necho %line%\r\necho:\r\necho      Notes:\r\necho:\r\ncall :dk_color2 %_White% \"     - \" %Gray% \"Make sure the internet is connected.\"\r\ncall :dk_color2 %_White% \"     - \" %Gray% \"Make sure that Windows update is properly working.\"\r\necho:\r\necho %line%\r\necho:\r\nchoice /C:09 /N /M \">    [9] Continue [0] Go back : \"\r\nif %errorlevel%==1 goto at_menu\r\n\r\ncls\r\nif not defined terminal mode 110, 30\r\n\r\nfor /f %%a in ('%psc% \"(Get-Date).ToString('yyyyMMdd-HHmmssfff')\"') do set _time=%%a\r\n\r\n%psc% Stop-Service TrustedInstaller -force %nul%\r\n\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\backup_cbs_%_time%.log\" %nul%\r\ncopy /y /b \"%SystemRoot%\\logs\\DISM\\dism.log\" \"%SystemRoot%\\logs\\DISM\\backup_dism_%_time%.log\" %nul%\r\ndel /f /q \"%SystemRoot%\\logs\\cbs\\cbs.log\" %nul%\r\ndel /f /q \"%SystemRoot%\\logs\\DISM\\dism.log\" %nul%\r\n\r\necho:\r\necho Applying the command...\r\necho dism /english /online /cleanup-image /restorehealth\r\ndism /english /online /cleanup-image /restorehealth\r\n\r\ntimeout /t 5 %nul1%\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\cbs_%_time%.log\" %nul%\r\ncopy /y /b \"%SystemRoot%\\logs\\DISM\\dism.log\" \"%SystemRoot%\\logs\\DISM\\dism_%_time%.log\" %nul%\r\n\r\nif not exist \"!desktop!\\AT_Logs\\\" md \"!desktop!\\AT_Logs\\\" %nul%\r\ncall :compresslog cbs\\cbs_%_time%.log AT_Logs\\RHealth_CBS %nul%\r\ncall :compresslog DISM\\dism_%_time%.log AT_Logs\\RHealth_DISM %nul%\r\n\r\nif not exist \"!desktop!\\AT_Logs\\RHealth_CBS_%_time%.cab\" (\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"!desktop!\\AT_Logs\\RHealth_CBS_%_time%.log\" %nul%\r\n)\r\n\r\nif not exist \"!desktop!\\AT_Logs\\RHealth_DISM_%_time%.cab\" (\r\ncopy /y /b \"%SystemRoot%\\logs\\DISM\\dism.log\" \"!desktop!\\AT_Logs\\RHealth_DISM_%_time%.log\" %nul%\r\n)\r\n\r\necho:\r\ncall :dk_color %Gray% \"CBS and DISM logs are copied to the AT_Logs folder on your desktop.\"\r\ngoto :at_back\r\n\r\n::========================================================================================================================================\r\n\r\n:sfcscan\r\n\r\ncls\r\nif not defined terminal mode 98, 30\r\ntitle  sfc /scannow\r\n\r\necho:\r\necho %line%\r\necho:    \r\necho      SFC will repair missing or corrupted system files.\r\necho      It is recommended you run the DISM option first before this one.\r\necho      This will take 10-15 minutes or more..\r\necho:\r\necho      If SFC could not fix something, then run the command again to see if it may be able \r\necho      to the next time. Sometimes it may take running the sfc /scannow command 3 times\r\necho      restarting the PC after each time to completely fix everything that it's able to.\r\necho:   \r\necho %line%\r\necho:\r\nchoice /C:09 /N /M \">    [9] Continue [0] Go back : \"\r\nif %errorlevel%==1 goto at_menu\r\n\r\ncls\r\nfor /f %%a in ('%psc% \"(Get-Date).ToString('yyyyMMdd-HHmmssfff')\"') do set _time=%%a\r\n\r\n%psc% Stop-Service TrustedInstaller -force %nul%\r\n\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\backup_cbs_%_time%.log\" %nul%\r\ndel /f /q \"%SystemRoot%\\logs\\cbs\\cbs.log\" %nul%\r\n\r\necho:\r\necho Applying the command...\r\necho sfc /scannow\r\nsfc /scannow\r\n\r\ntimeout /t 5 %nul1%\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\cbs_%_time%.log\" %nul%\r\n\r\nif not exist \"!desktop!\\AT_Logs\\\" md \"!desktop!\\AT_Logs\\\" %nul%\r\ncall :compresslog cbs\\cbs_%_time%.log AT_Logs\\SFC_CBS %nul%\r\n\r\nif not exist \"!desktop!\\AT_Logs\\SFC_CBS_%_time%.cab\" (\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"!desktop!\\AT_Logs\\SFC_CBS_%_time%.log\" %nul%\r\n)\r\n\r\necho:\r\ncall :dk_color %Gray% \"The CBS log was copied to the AT_Logs folder on your Desktop.\"\r\ngoto :at_back\r\n\r\n::========================================================================================================================================\r\n\r\n:retokens\r\n\r\ncls\r\nif not defined terminal (\r\nmode 125, 32\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\ntitle  Fix Licensing ^(ClipSVC ^+ SPP ^+ OSPP^)\r\n\r\nif %winbuild% EQU 6001 (\r\n%eline%\r\necho This option is not supported on Windows Vista SP1.\r\necho Upgrade to Windows Vista SP2.\r\ngoto :at_back\r\n)\r\n\r\necho:\r\necho %line%\r\necho:   \r\necho      Notes:\r\necho:\r\necho       - This option helps in troubleshooting activation issues.\r\necho:\r\necho       - This option will:\r\necho            - Deactivate Windows and Office, you may need to reactivate.\r\necho              If Windows is activated with motherboard / OEM / Digital license\r\necho              then Windows will activate itself again.\r\necho:\r\necho            - Clear ClipSVC, SPP and OSPP licenses.\r\necho            - Fix permissions of SPP tokens folder and registries.\r\necho            - Trigger the repair option for Office.\r\necho:\r\ncall :dk_color2 %_White% \"      - \" %Blue% \"Apply this option only when it is necessary.\"\r\necho:\r\necho %line%\r\necho:\r\nchoice /C:09 /N /M \">    [9] Continue [0] Go back : \"\r\nif %errorlevel%==1 goto at_menu\r\n\r\n::========================================================================================================================================\r\n\r\n::  Rebuild ClipSVC Licences\r\n\r\ncls\r\n:cleanlicensing\r\n\r\necho:\r\necho %line%\r\necho:\r\ncall :dk_color %Blue% \"Rebuilding ClipSVC Licenses...\"\r\necho:\r\n\r\nif %winbuild% LSS 10240 (\r\necho ClipSVC license rebuilding is supported only on Windows 10/11.\r\necho Skipping...\r\ngoto :rebuildspptok\r\n)\r\n\r\n%psc% \"(([WMISEARCHER]'SELECT Name FROM SoftwareLicensingProduct WHERE LicenseStatus=1 AND GracePeriodRemaining=0 AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Name\" %nul2% | findstr /i \"Windows\" %nul1% && (\r\necho Windows is permanently activated.\r\necho Skipping...\r\ngoto :rebuildspptok\r\n)\r\n\r\nset _partial=\r\nset _keymatch=\r\nfor /f \"tokens=2 delims==\" %%# in ('%psc% \"(([WMISEARCHER]'SELECT PartialProductKey FROM SoftwareLicensingProduct WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).PartialProductKey | %% {echo ('PartialProductKey='+$_)}\" %nul6%') do set \"_partial=%%#\"\r\nfor %%# in (8HV2C QPFCT 3V66T PKCKT WXCHW 8TYMD 6F4BT 8HVX7 KD72Y 7CFBY DRR8H P39PB DYJWX MDWWW 9HKR4 M7V2X 2YV77 WT2RQ MHBPB QPF8P 2YV66 VMJ2C DJ4F6 CKFFD YY74H J8JXD BHDCD T6R4W D32MH RRK69 3PJBP) do if /i \"%_partial%\"==\"%%#\" set _keymatch=1\r\n\r\nif not defined _keymatch (\r\necho HWID activation key is not installed.\r\necho Skipping...\r\ngoto :rebuildspptok\r\n)\r\n\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif errorlevel 1 (\r\necho Internet is not connected.\r\necho Skipping...\r\ngoto :rebuildspptok\r\n)\r\n\r\nset resfail=\r\nfor %%# in (\r\nlicensing.mp.microsoft.com/v7.0/licenses/content\r\nlogin.live.com/ppsecure/deviceaddcredential.srf\r\npurchase.mp.microsoft.com/v7.0/users/me/orders\r\n) do if not defined resfail (\r\n%psc% \"try { [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; irm https://%%# -Method POST } catch { if ($_.Exception.Response -eq $null) { Write-Host \"\"\"\"[%%#] $($_.Exception.Message)\"\"\"\" -ForegroundColor Red -BackgroundColor Black; exit 3 } }\"\r\nif !errorlevel!==3 set resfail=1\r\n)\r\n\r\nif defined resfail (\r\necho Failed to connect to licensing servers.\r\necho Skipping...\r\ngoto :rebuildspptok\r\n)\r\n\r\necho Stopping ClipSVC service...\r\n%psc% Stop-Service ClipSVC -force %nul%\r\ntimeout /t 2 %nul%\r\n\r\necho:\r\necho Applying the command to clean ClipSVC Licenses...\r\necho rundll32 clipc.dll,ClipCleanUpState\r\n\r\nrundll32 clipc.dll,ClipCleanUpState\r\n\r\nif %winbuild% LEQ 10240 (\r\necho [Successful]\r\n) else (\r\nif exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\tokens.dat\" (\r\ncall :dk_color %Red% \"[Failed]\"\r\n) else (\r\necho [Successful]\r\n)\r\n)\r\n\r\n::  Below registry key (Volatile & Protected) gets created after the ClipSVC License cleanup command, and gets automatically deleted after \r\n::  system restart. It needs to be deleted to activate the system without restart.\r\n\r\nset \"RegKey=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState\"\r\nset \"_ident=HKU\\S-1-5-19\\SOFTWARE\\Microsoft\\IdentityCRL\"\r\n\r\nreg query \"%RegKey%\" %nul% && %nul% call :regownstart\r\nreg delete \"%RegKey%\" /f %nul% \r\n\r\necho:\r\necho Deleting a Volatile ^& Protected Registry Key...\r\necho [%RegKey%]\r\nreg query \"%RegKey%\" %nul% && (\r\ncall :dk_color %Red% \"[Failed]\"\r\necho Reboot your machine using the restart option, that will delete this registry key automatically.\r\n) || (\r\necho [Successful]\r\n)\r\n\r\n::   Clear HWID token related registry to fix activation incase there is any corruption\r\n\r\necho:\r\necho Deleting IdentityCRL Registry Key...\r\necho [%_ident%]\r\nreg delete \"%_ident%\" /f %nul%\r\nreg query \"%_ident%\" %nul% && (\r\ncall :dk_color %Red% \"[Failed]\"\r\n) || (\r\necho [Successful]\r\n)\r\n\r\n%psc% Stop-Service ClipSVC -force %nul%\r\n\r\n::  Rebuild ClipSVC folder to fix permission issues\r\n\r\necho:\r\nif %winbuild% GTR 10240 (\r\necho Deleting folder %ProgramData%\\Microsoft\\Windows\\ClipSVC\\\r\nrmdir /s /q \"C:\\ProgramData\\Microsoft\\Windows\\ClipSvc\" %nul%\r\n\r\nif exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\\" (\r\ncall :dk_color %Red% \"[Failed]\"\r\n) else (\r\necho [Successful]\r\n)\r\n\r\necho:\r\necho Rebuilding the %ProgramData%\\Microsoft\\Windows\\ClipSVC\\ folder...\r\n%psc% Start-Service ClipSVC %nul%\r\ntimeout /t 3 %nul%\r\nif not exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\\" timeout /t 5 %nul%\r\nif not exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\\" (\r\ncall :dk_color %Red% \"[Failed]\"\r\n) else (\r\necho [Successful]\r\n)\r\n)\r\n\r\necho:\r\necho Restarting wlidsvc ^& LicenseManager services...\r\nfor %%# in (wlidsvc LicenseManager) do (%psc% \"Start-Job { Restart-Service %%# } | Wait-Job -Timeout 20 | Out-Null\")\r\n\r\n::========================================================================================================================================\r\n\r\n::  Rebuild SPP Tokens\r\n\r\n:rebuildspptok\r\n\r\necho:\r\necho %line%\r\necho:\r\ncall :dk_color %Blue% \"Rebuilding SPP licensing tokens...\"\r\necho:\r\n\r\necho Clearing KMS Cache...\r\necho:\r\ncall :_taskclear-cache\r\n\r\n%nul% reg query \"HKLM\\%SPPk%\\%_wApp%\" && (\r\necho Removing KMS38 protection...\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':regdel\\:.*';. ([scriptblock]::Create($f[1]))\"\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_wApp%\" /f\r\n%nul% reg query \"HKLM\\%SPPk%\\%_wApp%\" && (\r\ncall :dk_color %Red% \"Failed to remove KMS38 protection.\"\r\n) || (\r\necho Successfully removed KMS38 protection.\r\necho Successfully cleared KMS Cache.\r\n)\r\n) || (\r\necho Successfully cleared KMS Cache.\r\n)\r\necho:\r\n\r\ncall :scandat check\r\n\r\nif not defined token (\r\ncall :dk_color %Red% \"tokens.dat file not found.\"\r\n) else (\r\necho tokens.dat file: [%token%]\r\n)\r\n\r\nset tokenstore=\r\nset badregistry=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v TokenStore %nul6%') do call set \"tokenstore=%%b\"\r\nif %winbuild% GEQ 9200 if /i not \"%tokenstore%\"==\"%SysPath%\\spp\\store\" if /i not \"%tokenstore%\"==\"%SysPath%\\spp\\store\\2.0\" if /i not \"%tokenstore%\"==\"%SysPath%\\spp\\store_test\\2.0\" (\r\nset badregistry=1\r\necho:\r\ncall :dk_color %Red% \"Correct path not found in TokenStore Registry [%tokenstore%]\"\r\n)\r\n\r\n::  Check sppsvc permissions and apply fixes\r\n\r\nif %winbuild% GEQ 9200 if not defined badregistry (\r\necho:\r\necho Checking SPP permission related issues...\r\ncall :checkperms\r\nif defined permerror (\r\ncall :dk_color %Red% \"[!permerror!]\"\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':fixsppperms\\:.*';. ([scriptblock]::Create($f[1]))\" %nul%\r\ncall :checkperms\r\nif defined permerror (\r\ncall :dk_color %Red% \"[!permerror!] [Failed To Fix]\"\r\n) else (\r\ncall :dk_color %Green% \"[Successfully Fixed]\"\r\n)\r\n) else (\r\necho [No Error Found]\r\n)\r\n)\r\n\r\necho:\r\necho Stopping %_slser% service...\r\n%psc% Stop-Service %_slser% -force %nul%\r\n\r\nset w=\r\nset _sppint=\r\nfor %%# in (SppEx%w%tComObj.exe %_slexe%) do (reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" %nul% && (set _sppint=1))\r\nif defined _sppint (\r\necho:\r\necho Removing SPP IFEO registry keys...\r\nfor %%# in (SppE%w%xtComObj.exe %_slexe%) do (reg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" /f %nul%)\r\n)\r\n\r\nif %winbuild% LSS 9200 if not defined _vis (\r\nREM Fix issues caused by Update KB971033 in Windows 7\r\nREM https://support.microsoft.com/en-us/help/4487266\r\necho:\r\necho Checking Update KB971033...\r\n%psc% \"if (Get-Hotfix -Id KB971033 -ErrorAction SilentlyContinue) {Exit 3}\" %nul%\r\nif !errorlevel!==3 (\r\necho Found, uninstalling it...\r\nwusa /uninstall /quiet /norestart /kb:971033\r\n) else (\r\necho [Not Found]\r\n)\r\n%psc% Stop-Service sppuinotify -force %nul%\r\nsc config sppuinotify start= disabled\r\ndel /f /q %SysPath%\\7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0 /ah\r\n)\r\n\r\n::  Delete registry keys that are not deleted by activation scripts\r\n\r\nif not defined _vis (\r\necho:\r\necho Cleaning some licensing-related registry keys...\r\n%nul% reg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"ServiceSessionId\" /f\r\n%nul% reg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"LicStatusArray\" /f\r\n%nul% reg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"PolicyValuesArray\" /f\r\n%nul% reg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"actionlist\" /f\r\n%nul% reg delete \"HKLM\\SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform\\data\" /f\r\n)\r\n\r\necho:\r\ncall :scandat delete\r\ncall :scandat check\r\n\r\nif defined token (\r\necho:\r\ncall :dk_color %Red% \"Failed to delete .dat files.\"\r\necho:\r\n)\r\n\r\nif defined _vis (\r\n%psc% Start-Service %_slser% %nul%\r\n)\r\n\r\necho:\r\necho Reinstalling system licenses...\r\n%psc% \"$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif %errorlevel% NEQ 0 %psc% \"$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif %errorlevel% EQU 0 (\r\necho [Successful]\r\n) else (\r\ncall :dk_color %Red% \"[Failed]\"\r\n)\r\n\r\ncall :scandat check\r\n\r\necho:\r\nif not defined token (\r\ncall :dk_color %Red% \"Failed to rebuild tokens.dat file.\"\r\n) else (\r\necho tokens.dat file was rebuilt successfully.\r\n)\r\n\r\nif %winbuild% LSS 9200 if not defined _vis (\r\nsc config sppuinotify start= demand\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Rebuild OSPP Tokens\r\n\r\necho:\r\necho %line%\r\necho:\r\ncall :dk_color %Blue% \"Rebuilding OSPP licensing tokens...\"\r\necho:\r\n\r\nsc qc osppsvc %nul% || (\r\necho OSPP-based Office is not installed.\r\necho Skipping rebuilding OSPP tokens...\r\ngoto :repairoffice\r\n)\r\n\r\ncall :scandatospp check\r\n\r\nif not defined token (\r\ncall :dk_color %Red% \"tokens.dat file not found.\"\r\n) else (\r\necho tokens.dat file: [%token%]\r\n)\r\n\r\necho:\r\necho Stopping osppsvc service...\r\n%psc% Stop-Service osppsvc -force %nul%\r\n\r\necho:\r\ncall :scandatospp delete\r\ncall :scandatospp check\r\n\r\nif defined token (\r\necho:\r\ncall :dk_color %Red% \"Failed to delete .dat files.\"\r\necho:\r\n)\r\n\r\necho:\r\necho Starting osppsvc service to generate tokens.dat...\r\n%psc% Start-Service osppsvc %nul%\r\ncall :scandatospp check\r\nif not defined token (\r\n%psc% Stop-Service osppsvc -force %nul%\r\n%psc% Start-Service osppsvc %nul%\r\ntimeout /t 3 %nul%\r\n)\r\n\r\ncall :scandatospp check\r\n\r\necho:\r\nif not defined token (\r\ncall :dk_color %Red% \"Failed to rebuild tokens.dat file.\"\r\n) else (\r\necho tokens.dat file was rebuilt successfully.\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:repairoffice\r\n\r\necho:\r\necho %line%\r\necho:\r\ncall :dk_color %Blue% \"Repairing Office licenses...\"\r\necho:\r\n\r\nfor %%# in (68 86) do (\r\nfor %%A in (msi14 msi15 msi16 c2r14 c2r15 c2r16) do (set %%A_%%#=&set %%Arepair%%#=)\r\n)\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n\r\nreg query %_68%\\14.0\\CVH /f Click2run /k %nul% && (set \"c2r14_68=Office 14.0 C2R x86/x64\"  & set \"c2r14repair68=\")\r\nreg query %_86%\\14.0\\CVH /f Click2run /k %nul% && (set \"c2r14_86=Office 14.0 C2R x86\"      & set \"c2r14repair86=\")\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi14_86=Office 14.0 MSI x86\"      & call :getrepairsetup msi14repair86 14)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi14_68=Office 14.0 MSI x86/x64\"  & call :getrepairsetup msi14repair68 14)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi15_86=Office 15.0 MSI x86\"      & call :getrepairsetup msi15repair86 15)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi15_68=Office 15.0 MSI x86/x64\"  & call :getrepairsetup msi15repair68 15)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi16_86=Office 16.0 MSI x86\"      & call :getrepairsetup msi16repair86 16)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi16_68=Office 16.0 MSI x86/x64\"  & call :getrepairsetup msi16repair68 16)\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set \"c2r15_86=Office 15.0 C2R x86\"      & call :getc2rrepair c2r15repair86 integratedoffice.exe)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set \"c2r15_68=Office 15.0 C2R x86/x64\"  & call :getc2rrepair c2r15repair68 integratedoffice.exe)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set \"c2r16_86=Office 16.0 C2R x86\"      & call :getc2r16repair c2r16repair86 OfficeClickToRun.exe)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set \"c2r16_68=Office 16.0 C2R x86/x64\"  & call :getc2r16repair c2r16repair68 OfficeClickToRun.exe)\r\n\r\nset uwp16=\r\nif %winbuild% GEQ 10240 (\r\n%psc% \"Get-AppxPackage -name \"Microsoft.Office.Desktop\"\" | find /i \"Office\" %nul1% && set uwp16=Office 16.0 UWP\r\n)\r\n\r\nset /a counter=0\r\necho Checking installed Office versions...\r\necho:\r\n\r\nfor %%# in (\r\n\"%msi14_68%\"\r\n\"%msi14_86%\"\r\n\"%msi15_68%\"\r\n\"%msi15_86%\"\r\n\"%msi16_68%\"\r\n\"%msi16_86%\"\r\n\"%c2r14_68%\"\r\n\"%c2r14_86%\"\r\n\"%c2r15_68%\"\r\n\"%c2r15_86%\"\r\n\"%c2r16_68%\"\r\n\"%c2r16_86%\"\r\n\"%uwp16%\"\r\n) do (\r\nif not \"%%#\"==\"\"\"\" (\r\nset insoff=%%#\r\nset insoff=!insoff:\"=!\r\necho [!insoff!]\r\nset /a counter+=1\r\n)\r\n)\r\n\r\nif %counter% GTR 1 (\r\n%eline%\r\necho Multiple Office versions found.\r\necho It is recommended to only install one version of Office.\r\necho ________________________________________________________________\r\necho:\r\n)\r\n\r\necho:\r\nif %counter% EQU 0 (\r\necho Office ^(2010 and later^) is not installed.\r\ngoto :repairend\r\n) else if not defined c2r16_68 if not defined c2r16_86 (\r\ncall :dk_color %_Yellow% \"A new window will appear, in that window you need to select [Quick Repair] option.\"\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] to continue...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to continue...\"\r\npause %nul1%\r\n)\r\n)\r\n\r\nif defined uwp16 (\r\necho:\r\necho Skipping repair for Office 16.0 UWP... \r\necho:\r\n)\r\n\r\nset c2r14=\r\nif defined c2r14_68 set c2r14=1\r\nif defined c2r14_86 set c2r14=1\r\n\r\nif defined c2r14 (\r\necho:\r\necho Skipping repair for Office 14.0 C2R...\r\necho:\r\n)\r\n\r\nif defined msi14_68 if exist \"%msi14repair68%\" echo Running - \"%msi14repair68%\"                                        & \"%msi14repair68%\"\r\nif defined msi14_86 if exist \"%msi14repair86%\" echo Running - \"%msi14repair86%\"                                        & \"%msi14repair86%\"\r\nif defined msi15_68 if exist \"%msi15repair68%\" echo Running - \"%msi15repair68%\"                                        & \"%msi15repair68%\"\r\nif defined msi15_86 if exist \"%msi15repair86%\" echo Running - \"%msi15repair86%\"                                        & \"%msi15repair86%\"\r\nif defined msi16_68 if exist \"%msi16repair68%\" echo Running - \"%msi16repair68%\"                                        & \"%msi16repair68%\"\r\nif defined msi16_86 if exist \"%msi16repair86%\" echo Running - \"%msi16repair86%\"                                        & \"%msi16repair86%\"\r\nif defined c2r15_68 if exist \"%c2r15repair68%\" echo Running - \"%c2r15repair68%\" REPAIRUI RERUNMODE                     & \"%c2r15repair68%\" REPAIRUI RERUNMODE\r\nif defined c2r15_86 if exist \"%c2r15repair86%\" echo Running - \"%c2r15repair86%\" REPAIRUI RERUNMODE                     & \"%c2r15repair86%\" REPAIRUI RERUNMODE\r\nif defined c2r16_68 if exist \"%c2r16repair68%\" echo Running - \"%c2r16repair68%\" Scenario=Repair RepairType=QuickRepair & \"%c2r16repair68%\" Scenario=Repair RepairType=QuickRepair\r\nif defined c2r16_86 if exist \"%c2r16repair86%\" echo Running - \"%c2r16repair86%\" Scenario=Repair RepairType=QuickRepair & \"%c2r16repair86%\" Scenario=Repair RepairType=QuickRepair\r\n\r\n:repairend\r\n\r\necho:\r\necho %line%\r\necho:\r\necho:\r\ncall :dk_color %Green% \"Finished\"\r\ngoto :at_back\r\n\r\n:getc2rrepair\r\n\r\nfor %%# in (X86 X64) do (\r\nif exist \"%systemdrive%\\Program Files\\Microsoft Office 15\\Client%%#\\%2\" (\r\nset \"%1=%systemdrive%\\Program Files\\Microsoft Office 15\\Client%%#\\%2\"\r\n)\r\n)\r\nexit /b\r\n\r\n:getc2r16repair\r\n\r\nfor %%# in (%_68% %_86%) do (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %%#\\ClickToRun\\Configuration /v ClientFolder\" %nul6%') do if exist \"%%b\\%2\" (set \"%1=%%b\\%2\")\r\n)\r\nexit /b\r\n\r\n:getrepairsetup\r\n\r\nset \"_common86=%systemdrive%\\Program Files (x86)\\Common Files\\Microsoft Shared\\OFFICE%2\\Office Setup Controller\\setup.exe\"\r\nset \"_common68=%systemdrive%\\Program Files\\Common Files\\Microsoft Shared\\OFFICE%2\\Office Setup Controller\\setup.exe\"\r\n\r\nif exist \"%_common86%\" set \"%1=%_common86%\"\r\nif exist \"%_common68%\" set \"%1=%_common68%\"\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:fixwmi\r\n\r\ncls\r\nif not defined terminal mode 98, 34\r\ntitle  Fix WMI\r\n\r\n::  https://techcommunity.microsoft.com/t5/ask-the-performance-team/wmi-repository-corruption-or-not/ba-p/375484\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" (\r\n%eline%\r\necho Rebuilding WMI is not recommended on Windows Server, aborting...\r\ngoto :at_back\r\n)\r\n\r\necho:\r\necho Checking WMI\r\ncall :checkwmi\r\n\r\n::  Apply basic fix first and check\r\n\r\nif defined error (\r\n%psc% Stop-Service Winmgmt -force %nul%\r\nwinmgmt /salvagerepository %nul%\r\ncall :checkwmi\r\n)\r\n\r\nif not defined error (\r\necho [Working]\r\necho No need to apply this option, aborting...\r\ngoto :at_back\r\n)\r\n\r\ncall :dk_color %Red% \"[Not Responding]\"\r\n\r\nset _corrupt=\r\nsc start Winmgmt %nul%\r\nif %errorlevel% EQU 1060 set _corrupt=1\r\nsc query Winmgmt %nul% || set _corrupt=1\r\nfor %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type) do if not defined _corrupt (reg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\Winmgmt /v %%G %nul% || set _corrupt=1)\r\n\r\necho:\r\nif defined _corrupt (\r\n%eline%\r\necho Winmgmt service is corrupted, aborting...\r\ngoto :at_back\r\n)\r\n\r\necho Disabling Winmgmt service\r\nsc config Winmgmt start= disabled %nul%\r\nif %errorlevel% EQU 0 (\r\necho [Successful]\r\n) else (\r\ncall :dk_color %Red% \"[Failed] Aborting...\"\r\nsc config Winmgmt start= auto %nul%\r\ngoto :at_back\r\n)\r\n\r\necho:\r\necho Stopping Winmgmt service\r\n%psc% Stop-Service Winmgmt -force %nul%\r\n%psc% Stop-Service Winmgmt -force %nul%\r\n%psc% Stop-Service Winmgmt -force %nul%\r\nsc query Winmgmt | find /i \"STOPPED\" %nul% && (\r\necho [Successful]\r\n) || (\r\ncall :dk_color %Red% \"[Failed]\"\r\ncall :dk_color %Blue% \"Its recommended to select [Restart] option and then apply Fix WMI option again.\"\r\necho %line%\r\necho:\r\nchoice /C:21 /N /M \"> [1] Restart  [2] Revert Back Changes :\"\r\nif !errorlevel!==1 (sc config Winmgmt start= auto %nul%&goto :at_back)\r\necho:\r\necho Restarting...\r\nshutdown -t 5 -r\r\nexit\r\n)\r\n\r\necho:\r\necho Deleting WMI repository\r\nrmdir /s /q \"%SysPath%\\wbem\\repository\\\" %nul%\r\nif exist \"%SysPath%\\wbem\\repository\\\" (\r\ncall :dk_color %Red% \"[Failed]\"\r\n) else (\r\necho [Successful]\r\n)\r\n\r\necho:\r\necho Enabling Winmgmt service\r\nsc config Winmgmt start= auto %nul%\r\nif %errorlevel% EQU 0 (\r\necho [Successful]\r\n) else (\r\ncall :dk_color %Red% \"[Failed]\"\r\n)\r\n\r\ncall :checkwmi\r\nif not defined error (\r\necho:\r\necho Checking WMI\r\ncall :dk_color %Green% \"[Working]\"\r\ngoto :at_back\r\n)\r\n\r\necho:\r\necho Registering .dll's and Compiling .mof's, .mfl's\r\ncall :registerobj %nul%\r\n\r\necho:\r\necho Checking WMI\r\ncall :checkwmi\r\nif defined error (\r\ncall :dk_color %Red% \"[Not Responding]\"\r\necho:\r\necho Run [Dism RestoreHealth] and [SFC Scannow] options and make sure there are no errors.\r\n) else (\r\ncall :dk_color %Green% \"[Working]\"\r\n)\r\n\r\ngoto :at_back\r\n\r\n:registerobj\r\n\r\n::  https://eskonr.com/2012/01/how-to-fix-wmi-issues-automatically/\r\n\r\n%psc% Stop-Service Winmgmt -force %nul%\r\ncd /d %SysPath%\\wbem\\\r\nregsvr32 /s %SysPath%\\scecli.dll\r\nregsvr32 /s %SysPath%\\userenv.dll\r\nmofcomp cimwin32.mof\r\nmofcomp cimwin32.mfl\r\nmofcomp rsop.mof\r\nmofcomp rsop.mfl\r\nfor /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s\r\nfor /f %%s in ('dir /b *.mof') do mofcomp %%s\r\nfor /f %%s in ('dir /b *.mfl') do mofcomp %%s\r\n\r\nwinmgmt /salvagerepository\r\nwinmgmt /resetrepository\r\nexit /b\r\n\r\n:checkwmi\r\n\r\n::  https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants\r\n\r\nset error=\r\n%psc% \"Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName\" %nul2% | find /i \"computersystem\" %nul1%\r\nif %errorlevel% NEQ 0 (set error=1& exit /b)\r\nwinmgmt /verifyrepository %nul%\r\nif %errorlevel% NEQ 0 (set error=1& exit /b)\r\n\r\n%psc% \"try { $null=([WMISEARCHER]'SELECT * FROM SoftwareLicensingService').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\ncmd /c exit /b %errorlevel%\r\necho \"0x%=ExitCode%\" | findstr /i \"0x800410 0x800440 0x80131501\" %nul1%\r\nif %errorlevel% EQU 0 set error=1\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:at_back\r\n\r\necho:\r\necho %line%\r\necho:\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\ngoto :at_menu\r\n\r\n::========================================================================================================================================\r\n\r\n:compresslog\r\n\r\n::  https://stackoverflow.com/a/46268232\r\n\r\nset \"ddf=\"%SystemRoot%\\Temp\\%Random%%Random%%Random%%Random%\"\"\r\n%nul% del /q /f %ddf%\r\necho/.New Cabinet>%ddf%\r\necho/.set Cabinet=ON>>%ddf%\r\necho/.set CabinetFileCountThreshold=0;>>%ddf%\r\necho/.set Compress=ON>>%ddf%\r\necho/.set CompressionType=LZX>>%ddf%\r\necho/.set CompressionLevel=7;>>%ddf%\r\necho/.set CompressionMemory=21;>>%ddf%\r\necho/.set FolderFileCountThreshold=0;>>%ddf%\r\necho/.set FolderSizeThreshold=0;>>%ddf%\r\necho/.set GenerateInf=OFF>>%ddf%\r\necho/.set InfFileName=nul>>%ddf%\r\necho/.set MaxCabinetSize=0;>>%ddf%\r\necho/.set MaxDiskFileCount=0;>>%ddf%\r\necho/.set MaxDiskSize=0;>>%ddf%\r\necho/.set MaxErrors=1;>>%ddf%\r\necho/.set RptFileName=nul>>%ddf%\r\necho/.set UniqueFiles=ON>>%ddf%\r\nfor /f \"tokens=* delims=\" %%D in ('dir /a:-D/b/s \"%SystemRoot%\\logs\\%1\"') do (\r\n echo/\"%%~fD\"  /inf=no;>>%ddf%\r\n)\r\nmakecab /F %ddf% /D DiskDirectory1=\"\" /D CabinetNameTemplate=\"!desktop!\\%2_%_time%.cab\"\r\ndel /q /f %ddf%\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:checkperms\r\n\r\n::  This code checks if SPP has permission access to tokens folder and required registry keys. Incorrect permissions are often set by gaming spoofers.\r\n\r\nset permerror=\r\nif not exist \"%tokenstore%\\\" set \"permerror=Error Found In Token Folder\"\r\n\r\nif defined ps32onArm exit /b\r\n\r\nfor %%# in (\r\n\"%tokenstore%+FullControl\"\r\n\"HKLM:\\SYSTEM\\WPA+QueryValues, EnumerateSubKeys, WriteKey\"\r\n\"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform+SetValue\"\r\n) do for /f \"tokens=1,2 delims=+\" %%A in (%%#) do if not defined permerror (\r\n%psc% \"$acl = (Get-Acl '%%A' | fl | Out-String); if (-not ($acl -match 'NT SERVICE\\\\sppsvc Allow  %%B') -or ($acl -match 'NT SERVICE\\\\sppsvc Deny')) {Exit 2}\" %nul%\r\nif !errorlevel!==2 (\r\nif \"%%A\"==\"%tokenstore%\" (\r\nset \"permerror=Error Found In Token Folder\"\r\n) else (\r\nset \"permerror=Error Found In SPP Registries\"\r\n)\r\n)\r\n)\r\n\r\nREM  https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application\r\n\r\nif not defined permerror (\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% && (\r\nset \"pol=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\"\r\nreg query \"!pol!\" %nul% || reg add \"!pol!\" %nul%\r\n%psc% \"$netServ = (New-Object Security.Principal.SecurityIdentifier('S-1-5-20')).Translate([Security.Principal.NTAccount]).Value; $aclString = Get-Acl 'Registry::!pol!' | Format-List | Out-String; if (-not ($aclString.Contains($netServ + ' Allow  FullControl') -or $aclString.Contains('NT SERVICE\\sppsvc Allow  FullControl')) -or ($aclString.Contains('Deny'))) {Exit 3}\" %nul%\r\nif !errorlevel!==3 set \"permerror=Error Found In S-1-5-20 SPP\"\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix SPP related registry and folder permissions\r\n\r\n:fixsppperms:\r\n# Fix perms for Token Folder\r\n\r\nif ($env:permerror -eq 'Error Found In Token Folder') {\r\n    New-Item -Path $env:tokenstore -ItemType Directory -Force\r\n    $sddl = 'O:BAG:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;GR;;;BU)(A;;FR;;;BU)(A;OICI;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)'\r\n    $AclObject = New-Object System.Security.AccessControl.DirectorySecurity\r\n    $AclObject.SetSecurityDescriptorSddlForm($sddl)\r\n    Set-Acl -Path $env:tokenstore -AclObject $AclObject\r\n    exit\r\n}\r\n\r\n# Fix perms for SPP registries\r\n\r\nif ($env:permerror -eq 'Error Found In SPP Registries') {\r\n    $acl = Get-Acl 'HKLM:\\SYSTEM\\WPA'\r\n    $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\\sppsvc', 'QueryValues, EnumerateSubKeys, WriteKey', 'ContainerInherit, ObjectInherit', 'None', 'Allow')\r\n    $acl.ResetAccessRule($rule)\r\n    $acl.SetAccessRule($rule)\r\n    Set-Acl -Path 'HKLM:\\SYSTEM\\WPA' -AclObject $acl\r\n\t\r\n    $acl = Get-Acl 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform'\r\n    $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\\sppsvc', 'SetValue', 'ContainerInherit, ObjectInherit', 'None', 'Allow')\r\n    $acl.ResetAccessRule($rule)\r\n    $acl.SetAccessRule($rule)\r\n    Set-Acl -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform' -AclObject $acl\r\n    exit\r\n}\r\n\r\n# Fix perms for SPP in HKU\\S-1-5-20\r\n# https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application\r\n\r\nif ($env:permerror -ne 'Error Found In S-1-5-20 SPP') {\r\n    exit\r\n}\r\nif (-not (Test-Path 'Registry::HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform')) {\r\n    exit\r\n}\r\n\r\n# https://stackoverflow.com/a/35843420\r\n\r\nfunction Take-Permissions {\r\n    param($rootKey, $key, [System.Security.Principal.SecurityIdentifier]$sid = 'S-1-5-32-545', $recurse = $true)\r\n    \r\n    switch -regex ($rootKey) {\r\n        'HKCU|HKEY_CURRENT_USER' { $rootKey = 'CurrentUser' }\r\n        'HKLM|HKEY_LOCAL_MACHINE' { $rootKey = 'LocalMachine' }\r\n        'HKCR|HKEY_CLASSES_ROOT' { $rootKey = 'ClassesRoot' }\r\n        'HKCC|HKEY_CURRENT_CONFIG' { $rootKey = 'CurrentConfig' }\r\n        'HKU|HKEY_USERS' { $rootKey = 'Users' }\r\n    }\r\n\r\n    ### Step 1 - escalate current process's privilege\r\n    # get SeTakeOwnership, SeBackup and SeRestore privileges before executes next lines, script needs Admin privilege\r\n    $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)\r\n    $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)\r\n    $TypeBuilder = $ModuleBuilder.DefineType(0)\r\n    $TypeBuilder.DefinePInvokeMethod('RtlAdjustPrivilege', 'ntdll.dll', 'Public, Static', 1, [int], @([int], [bool], [bool], [bool].MakeByRefType()), 1, 3) | Out-Null\r\n    9, 17, 18 | ForEach-Object { $TypeBuilder.CreateType()::RtlAdjustPrivilege($_, $true, $false, [ref]$false) | Out-Null }\r\n\r\n    function Take-KeyPermissions {\r\n        param($rootKey, $key, $sid, $recurse, $recurseLevel = 0)\r\n\r\n        ### Step 2 - get ownerships of key - it works only for current key\r\n        $regKey = [Microsoft.Win32.Registry]::$rootKey.OpenSubKey($key, 'ReadWriteSubTree', 'TakeOwnership')\r\n        $acl = New-Object System.Security.AccessControl.RegistrySecurity\r\n        $acl.SetOwner($sid)\r\n        $regKey.SetAccessControl($acl)\r\n\r\n        ### Step 3 - enable inheritance of permissions (not ownership) for current key from parent\r\n        $acl.SetAccessRuleProtection($false, $false)\r\n        $regKey.SetAccessControl($acl)\r\n\r\n        ### Step 4 - only for top-level key, change permissions for current key and propagate it for subkeys\r\n        # to enable propagations for subkeys, it needs to execute Steps 2-3 for each subkey (Step 5)\r\n        if ($recurseLevel -eq 0) {\r\n            $regKey = $regKey.OpenSubKey('', 'ReadWriteSubTree', 'ChangePermissions')\r\n            $rule = New-Object System.Security.AccessControl.RegistryAccessRule($sid, 'FullControl', 'ContainerInherit', 'None', 'Allow')\r\n            $acl.ResetAccessRule($rule)\r\n            $regKey.SetAccessControl($acl)\r\n        }\r\n\r\n        ### Step 5 - recursively repeat steps 2-5 for subkeys\r\n        if ($recurse) {\r\n            foreach ($subKey in $regKey.OpenSubKey('').GetSubKeyNames()) {\r\n                Take-KeyPermissions $rootKey ($key + '\\' + $subKey) $sid $recurse ($recurseLevel + 1)\r\n            }\r\n        }\r\n    }\r\n\r\n    Take-KeyPermissions $rootKey $key $sid $recurse\r\n}\r\n\r\nTake-Permissions \"Users\" \"S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" \"S-1-5-20\"\r\n:fixsppperms:\r\n\r\n::========================================================================================================================================\r\n\r\n:scandat\r\n\r\nset token=\r\nfor %%# in (\r\n%SysPath%\\spp\\store_test\\2.0\\\r\n%SysPath%\\spp\\store\\\r\n%SysPath%\\spp\\store\\2.0\\\r\n%Systemdrive%\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareProtectionPlatform\\\r\n%Systemdrive%\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareLicensing\\\r\n) do (\r\n\r\nif %1==check (\r\nif exist %%#tokens.dat set token=%%#tokens.dat\r\n)\r\n\r\nif %1==delete (\r\nif exist %%# (\r\n%nul% dir /a-d /s \"%%#*.dat\" && (\r\nattrib -r -s -h \"%%#*.dat\" /S\r\ndel /S /F /Q \"%%#*.dat\"\r\n)\r\n)\r\n)\r\n)\r\nexit /b\r\n\r\n:scandatospp\r\n\r\nset token=\r\nfor %%# in (\r\n%ProgramData%\\Microsoft\\OfficeSoftwareProtectionPlatform\\\r\n) do (\r\n\r\nif %1==check (\r\nif exist %%#tokens.dat set token=%%#tokens.dat\r\n)\r\n\r\nif %1==delete (\r\nif exist %%# (\r\n%nul% dir /a-d /s \"%%#*.dat\" && (\r\nattrib -r -s -h \"%%#*.dat\" /S\r\ndel /S /F /Q \"%%#*.dat\"\r\n)\r\n)\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:regownstart\r\n\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':regown\\:.*';. ([scriptblock]::Create($f[1]));\"\r\nexit /b\r\n\r\n::  Below code takes ownership of a volatile registry key and deletes it\r\n::  HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState\r\n\r\n:regown:\r\n$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)\r\n$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)\r\n$TypeBuilder = $ModuleBuilder.DefineType(0)\r\n\r\n$TypeBuilder.DefinePInvokeMethod('RtlAdjustPrivilege', 'ntdll.dll', 'Public, Static', 1, [int], @([int], [bool], [bool], [bool].MakeByRefType()), 1, 3) | Out-Null\r\n$TypeBuilder.CreateType()::RtlAdjustPrivilege(9, $true, $false, [ref]$false) | Out-Null\r\n\r\n$SID = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544')\r\n$IDN = ($SID.Translate([System.Security.Principal.NTAccount])).Value\r\n$Admin = New-Object System.Security.Principal.NTAccount($IDN)\r\n\r\n$path = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState'\r\n$key = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64').OpenSubKey($path, 'ReadWriteSubTree', 'takeownership')\r\n\r\n$acl = $key.GetAccessControl()\r\n$acl.SetOwner($Admin)\r\n$key.SetAccessControl($acl)\r\n\r\n$rule = New-Object System.Security.AccessControl.RegistryAccessRule($Admin,\"FullControl\",\"Allow\")\r\n$acl.SetAccessRule($rule)\r\n$key.SetAccessControl($acl)\r\n:regown:\r\n\r\n::========================================================================================================================================\r\n\r\n::  This code runs to undo below registry key KMS38 protection\r\n::  HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\n::  This option is not used in KMS38 anymore, it's here only to remove previous versions protection.\r\n\r\n:regdel:\r\nparam (\r\n    [switch]$protect\r\n)\r\n\r\n$SID = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544')\r\n$Admin = ($SID.Translate([System.Security.Principal.NTAccount])).Value\r\n\r\nif($protect) {\r\n$ruleArgs = @(\"$Admin\", \"Delete, SetValue\", \"ContainerInherit\", \"None\", \"Deny\")\r\n} else {\r\n$ruleArgs = @(\"$Admin\", \"FullControl\", \"Allow\")\r\n}\r\n\r\n$path = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\55c92734-d682-4d71-983e-d6ec3f16059f'\r\n$key = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64').OpenSubKey($path, 'ReadWriteSubTree', 'ChangePermissions')\r\n$acl = $key.GetAccessControl()\r\n\r\n$rule = [System.Security.AccessControl.RegistryAccessRule]::new.Invoke($ruleArgs)\r\n$acl.ResetAccessRule($rule)\r\n$key.SetAccessControl($acl)\r\n:regdel:\r\n\r\n:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n\r\n:change_winedition\r\n\r\n::  To stage current edition while changing edition with CBS Upgrade Method, change 0 to 1 in below line\r\nset _stg=0\r\n\r\nset \"line=echo ___________________________________________________________________________________________\"\r\n\r\ncls\r\nif not defined terminal mode 98, 30\r\ntitle  Change Windows Edition %masver%\r\n\r\nif %winbuild% LSS 7600 (\r\n%eline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho This option is supported only for Windows 7/8/8.1/10/11 and their Server equivalents.\r\ngoto dk_done\r\n)\r\n\r\necho:\r\necho Initializing...\r\necho:\r\n\r\nfor %%# in (\r\nsppsvc.exe\r\ndism.exe\r\n) do (\r\nif not exist %SysPath%\\%%# (\r\n%eline%\r\necho [%SysPath%\\%%#] file is missing, aborting...\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options.\"\r\ncall :dk_color %Blue% \"After that, restart system and try activation again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If it still shows the same error, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_reflection\r\ncall :dk_ckeckwmic\r\ncall :dk_sppissue\r\n\r\nfor /f \"tokens=6-7 delims=[]. \" %%i in ('ver') do if not \"%%j\"==\"\" (\r\nset fullbuild=%%i.%%j\r\n) else (\r\nfor /f \"tokens=3\" %%G in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR\" %nul6%') do if not errorlevel 1 set /a \"UBR=%%G\"\r\nfor /f \"skip=2 tokens=3,4 delims=. \" %%G in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildLabEx') do (\r\nif defined UBR (set \"fullbuild=%%G.!UBR!\") else (set \"fullbuild=%%G.%%H\")\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Activation IDs\r\n\r\ncall :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\nif not defined allapps (\r\n%eline%\r\necho Failed to find activation IDs. Aborting...\r\ncall :dk_color %Blue% \"To fix this issue, activate Windows from the main menu.\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Windows Edition and branch\r\n\r\nset osedition=\r\nset dismnotworking=\r\n\r\nfor /f \"tokens=3 delims=: \" %%a in ('DISM /English /Online /Get-CurrentEdition %nul6% ^| find /i \"Current Edition :\"') do set \"osedition=%%a\"\r\nif not defined osedition set dismnotworking=1\r\n\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\nif not defined osedition %chkedi% do if not errorlevel 1 (call set \"osedition=%%a\")\r\n\r\nif not defined osedition (\r\n%eline%\r\necho Failed to detect OS edition, aborting...\r\ncall :dk_color %Blue% \"To fix this issue, activate Windows from the main menu.\"\r\ngoto dk_done\r\n)\r\n\r\nfor /f \"skip=2 tokens=3\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul6%') do set \"regedition=%%a\"\r\nif /i not \"%osedition%\"==\"%regedition%\" (\r\nset \"showeditionerror=call :dk_color %_Yellow% \"[%osedition%] [Reg-%regedition%].\"\"\r\n)\r\n\r\nset branch=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildBranch %nul6%') do set \"branch=%%b\"\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get target editions list\r\n\r\nset _target=\r\nset _dtarget=\r\nset _ptarget=\r\nset _ntarget=\r\nset _wtarget=\r\n\r\nif %winbuild% GEQ 10240 for /f \"tokens=4\" %%a in ('dism /online /english /Get-TargetEditions ^| findstr /i /c:\"Target Edition : \"') do (if defined _dtarget (set \"_dtarget= !_dtarget! %%a \") else (set \"_dtarget= %%a \"))\r\nif %winbuild% LSS 10240 for /f \"tokens=4\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':cbsxml\\:.*';. ([scriptblock]::Create($f[1])) -GetTargetEditions;\" ^| findstr /i /c:\"Target Edition : \"') do (if defined _ptarget (set \"_ptarget= !_ptarget! %%a \") else (set \"_ptarget= %%a \"))\r\n\r\nif %winbuild% GEQ 10240 if not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" (\r\nif %winbuild% GEQ 17063 call :ced_edilist\r\nif /i \"%osedition:~0,4%\"==\"Core\" set _pro=Professional\r\nif /i \"%osedition%\"==\"CoreN\" set _pro=ProfessionalN\r\nset \"_dtarget= %_dtarget% !_wtarget! !_pro! \"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nfor %%# in (CloudEdition CloudEditionN ServerRdsh) do if /i %osedition%==%%# (\r\ncls\r\necho:\r\ncall :dk_color %Red% \"==== Note ====\"\r\necho:\r\necho [EditionID:%osedition% ^| %fullbuild%]\r\necho:\r\necho Changing this edition may not remove \"%osedition%\"-specific features.\r\necho:\r\ncall :dk_color %_Yellow% \"Press [7] to continue anyway...\"\r\nchoice /c 7 /n\r\ncls\r\n)\r\n\r\nfor %%# in ( %_dtarget% %_ptarget% ) do if /i not \"%%#\"==\"%osedition%\" (\r\necho \"!_target!\" | find /i \" %%# \" %nul1% || set \"_target= !_target! %%# \"\r\n)\r\n\r\nif defined _target (\r\nfor %%# in (%_target%) do (\r\necho %%# | findstr /i \"CountrySpecific CloudEdition\" %nul% || (set \"_ntarget=!_ntarget! %%#\")\r\n)\r\n)\r\n\r\nif not defined _ntarget (\r\n%line%\r\necho:\r\nif defined dismnotworking call :dk_color %Red% \"DISM.exe is not working.\"\r\ncall :dk_color %Gray% \"Target editions not found.\"\r\necho Current Edition [%osedition% ^| %winbuild%] can not be changed to any other Edition.\r\n%line%\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:cedmenu2\r\n\r\ncls\r\nif not defined terminal mode 98, 30\r\nset inpt=\r\nset counter=0\r\nset verified=0\r\nset targetedition=\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"You can change the edition [%osedition%] [%fullbuild%] to one of the following.\"\r\n%showeditionerror%\r\nif defined dismnotworking (\r\ncall :dk_color %_Yellow% \"Note - DISM.exe is not working.\"\r\nif /i \"%osedition:~0,4%\"==\"Core\" call :dk_color %_Yellow% \"     - You will see more edition options to choose once its changed to Pro.\"\r\n)\r\n%line%\r\necho:\r\n\r\nfor %%A in (%_ntarget%) do (\r\nset /a counter+=1\r\nif /i %%A==IoTEnterprise (\r\necho [!counter!]  %%A [GAC, not LTSC]\r\n) else (\r\necho [!counter!]  %%A\r\n)\r\nset targetedition!counter!=%%A\r\n)\r\n\r\n%line%\r\necho:\r\necho [0]  %_exitmsg%\r\necho:\r\ncall :dk_color %_Green% \"Enter an option number using your keyboard and press Enter to confirm:\"\r\nset /p inpt=\r\nif \"%inpt%\"==\"\" goto cedmenu2\r\nif \"%inpt%\"==\"0\" exit /b\r\nfor /l %%i in (1,1,%counter%) do (if \"%inpt%\"==\"%%i\" set verified=1)\r\nset targetedition=!targetedition%inpt%!\r\nif %verified%==0 goto cedmenu2\r\n\r\n::========================================================================================================================================\r\n\r\nif %winbuild% LSS 10240 goto :cbsmethod\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" goto :ced_change_server\r\n\r\ncls\r\nif not defined terminal mode con cols=105 lines=32\r\n\r\nif /i \"%targetedition%\"==\"ServerRdsh\" (\r\necho:\r\ncall :dk_color %Red% \"==== Note ====\"\r\necho:\r\necho Once the edition is changed to \"%targetedition%\", \r\necho the system may not be able to properly change edition later.\r\necho:\r\necho [1] Continue Anyway\r\necho [0] Go Back\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 goto cedmenu2\r\nif !errorlevel!==1 rem\r\n)\r\n\r\ncls\r\nset key=\r\nset _chan=\r\nset _dismapi=0\r\n\r\n::  Check if DISM API or slmgr.vbs is required for edition upgrade\r\n\r\nif not exist \"%SysPath%\\spp\\tokens\\skus\\%targetedition%\\%targetedition%*.xrm-ms\" (\r\necho %_wtarget% | find /i \" %targetedition% \" || (\r\nset _dismapi=1\r\n)\r\n)\r\n\r\nset \"keyflow=Retail OEM:NONSLP OEM:DM Volume:MAK Volume:GVLK PGS:TB Retail:TB:Eval\"\r\n\r\ncall :ced_targetSKU %targetedition%\r\nif defined targetSKU call :ced_windowskey\r\nif defined key if defined pkeychannel set _chan=%pkeychannel%\r\nif not defined key call :changeeditiondata\r\nif not defined key if %_dismapi%==1 if /i \"%targetedition%\"==\"Professional\" (\r\nset key=VK7JG-NPHTM-C97JM-9MPGT-3V66T\r\nset _chan=Retail\r\n)\r\n\r\nif not defined key (\r\n%eline%\r\necho [%targetedition% ^| %winbuild%]\r\necho Failed to get product key from pkeyhelper.dll.\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Changing from Core to Non-Core & Changing editions in Windows build older than 17134 requires \"changepk /productkey\" or DISM Api method and restart\r\n::  In other cases, editions can be changed instantly with \"slmgr /ipk\"\r\n\r\nif %_dismapi%==1 (\r\nif not defined terminal mode con cols=105 lines=40\r\ncall :ced_rebootflag\r\nif defined rebootreq goto dk_done\r\n)\r\n\r\ncls\r\n%line%\r\necho:\r\n%showeditionerror%\r\nif defined dismnotworking call :dk_color %_Yellow% \"DISM.exe is not working.\"\r\necho Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...\r\necho:\r\n\r\nif %_dismapi%==1 (\r\ncall :dk_color %Green% \"Notes -\"\r\necho:\r\necho  - Save your work before continuing, the system will auto-restart.\r\necho:\r\necho  - You will need to activate with HWID option once the edition is changed.\r\n%line%\r\necho:\r\nchoice /C:21 /N /M \"[1] Continue [2] %_exitmsg% : \"\r\nif !errorlevel!==1 exit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_dismapi%==0 (\r\necho Installing %_chan% key [%key%]\r\necho:\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey=\"%key%\" %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset keyerror=!errorlevel!\r\ncmd /c exit /b !keyerror!\r\nif !keyerror! NEQ 0 set \"keyerror=[0x!=ExitCode!]\"\r\n\r\nif !keyerror! EQU 0 (\r\ncall :dk_refresh\r\ncall :dk_color %Green% \"[Successful]\"\r\necho:\r\ncall :dk_color %Gray% \"Reboot is required to fully change the edition.\"\r\n) else (\r\ncall :dk_color %Red% \"[Unsuccessful] [Error Code: !keyerror!]\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n)\r\n\r\nif %_dismapi%==1 (\r\necho:\r\necho Applying the DISM API method with %_chan% key %key%. Please wait...\r\necho:\r\n\r\ncall :ced_prep\r\nif defined preperror goto dk_done\r\n\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':dismapi\\:.*';. ([scriptblock]::Create($f[1])) %targetedition% %key%\"\r\ncall :ced_postprep\r\n)\r\n%line%\r\n\r\ngoto dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:cbsmethod\r\n\r\ncls\r\nif not defined terminal (\r\nmode con cols=105 lines=32\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\n\r\ncall :ced_rebootflag\r\nif defined rebootreq goto dk_done\r\n\r\necho:\r\n%showeditionerror%\r\nif defined dismnotworking call :dk_color %_Yellow% \"Note - DISM.exe is not working.\"\r\necho Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...\r\necho:\r\ncall :dk_color %Blue% \"Important - Save your work before continuing, the system will auto-restart.\"\r\necho:\r\nchoice /C:01 /N /M \"[1] Continue [0] %_exitmsg% : \"\r\nif %errorlevel%==1 exit /b\r\n\r\necho:\r\necho Initializing...\r\necho:\r\n\r\ncall :ced_prep\r\nif defined preperror goto dk_done\r\n\r\nif %_stg%==0 (set stage=) else (set stage=-StageCurrent)\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':cbsxml\\:.*';. ([scriptblock]::Create($f[1])) -SetEdition %targetedition% %stage%\"\r\ncall :ced_postprep\r\n%line%\r\n\r\ngoto dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ced_change_server\r\n\r\ncls\r\nif not defined terminal (\r\nmode con cols=105 lines=32\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\n\r\nset key=\r\nset _chan=\r\nset \"keyflow=Volume:GVLK Retail Volume:MAK OEM:NONSLP OEM:DM PGS:TB Retail:TB:Eval\"\r\n\r\ncall :ced_targetSKU %targetedition%\r\nif defined targetSKU call :ced_windowskey\r\nif defined key if defined pkeychannel set _chan=%pkeychannel%\r\nif not defined key call :changeeditiondata\r\n\r\nif not defined key (\r\n%eline%\r\necho [%targetedition% ^| %winbuild%]\r\necho Failed to get product key from pkeyhelper.dll.\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\ncall :ced_rebootflag\r\nif defined rebootreq goto dk_done\r\n\r\ncls\r\necho:\r\n%showeditionerror%\r\nif defined dismnotworking call :dk_color %_Yellow% \"Note - DISM.exe is not working.\"\r\necho Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...\r\necho:\r\n\r\ncall :ced_prep\r\nif defined preperror goto dk_done\r\n\r\necho Applying the command with %_chan% key...\r\necho DISM /online /Set-Edition:%targetedition% /ProductKey:%key% /AcceptEula\r\nDISM /online /Set-Edition:%targetedition% /ProductKey:%key% /AcceptEula\r\n\r\ncall :ced_postprep\r\n%line%\r\n\r\ngoto dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ced_prep\r\n\r\nset _time=\r\nset preperror=\r\n\r\nfor /f %%a in ('%psc% \"(Get-Date).ToString('yyyyMMdd-HHmmssfff')\"') do set _time=%%a\r\n\r\n%psc% Stop-Service TrustedInstaller -force %nul%\r\n\r\nsc query TrustedInstaller | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Failed to stop the TrustedInstaller service.\r\necho Reboot your machine using the restart option and try again.\r\nset preperror=1\r\nexit /b\r\n)\r\n\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\backup_cbs_%_time%.log\" %nul%\r\ncopy /y /b \"%SystemRoot%\\logs\\DISM\\dism.log\" \"%SystemRoot%\\logs\\DISM\\backup_dism_%_time%.log\" %nul%\r\n\r\ndel /f /q \"%SystemRoot%\\logs\\cbs\\cbs.log\" %nul%\r\ndel /f /q \"%SystemRoot%\\logs\\DISM\\dism.log\" %nul%\r\n\r\n:: Initiate this to appear in fresh logs\r\n\r\ndism /online /english /Get-CurrentEdition %nul%\r\ndism /online /english /Get-TargetEditions %nul%\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ced_postprep\r\n\r\ntimeout /t 5 %nul1%\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\cbs_%_time%.log\" %nul%\r\ncopy /y /b \"%SystemRoot%\\logs\\DISM\\dism.log\" \"%SystemRoot%\\logs\\DISM\\dism_%_time%.log\" %nul%\r\n\r\nif not exist \"!desktop!\\ChangeEdition_Logs\\\" md \"!desktop!\\ChangeEdition_Logs\\\" %nul%\r\ncall :compresslog cbs\\cbs_%_time%.log ChangeEdition_Logs\\CBS %nul%\r\ncall :compresslog DISM\\dism_%_time%.log ChangeEdition_Logs\\DISM %nul%\r\n\r\necho:\r\nif %winbuild% GEQ 9200 %psc% \"if ((Get-WindowsOptionalFeature -Online -FeatureName NetFx3).State -eq 'Enabled') {Write-Host 'Checking .NET Framework 3.5 Status - Enabled'}\"\r\necho Log files are copied to the ChangeEdition_Logs folder on your desktop.\r\necho:\r\ncall :dk_color %Blue% \"In case there are errors, you should restart the system before trying again.\"\r\necho:\r\nset fixes=%fixes% %mas%change_edition_issues\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%change_edition_issues\"\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get Edition list\r\n\r\n:ced_edilist\r\n\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do call set \"_wtarget= !_wtarget! %%a \"\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check pending reboot flags\r\n\r\n:ced_rebootflag\r\n\r\nset rebootreq=\r\nreg query \"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending\" %nul% && set rebootreq=1\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired\" %nul% && set rebootreq=1\r\n\r\nif defined rebootreq (\r\n%eline%\r\necho Pending reboot flags found.\r\necho:\r\necho Make sure Windows is fully updated, restart the system and try again.\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ced_windowskey\r\n\r\nfor %%# in (pkeyhelper.dll) do @if \"%%~$PATH:#\"==\"\" exit /b\r\nfor %%# in (%keyflow%) do (\r\ncall :k_pkey %targetSKU% '%%#'\r\nif defined pkey call :k_pkeychannel !pkey!\r\nif /i \"!pkeychannel!\"==\"%%#\" (\r\nset key=!pkey!\r\nexit /b\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ced_targetSKU\r\n\r\nset k=%1\r\nset targetSKU=\r\nfor %%# in (pkeyhelper.dll) do @if \"%%~$PATH:#\"==\"\" exit /b\r\n\r\ncall :dk_reflection\r\n\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionIdFromName', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionIdFromName('%k%', [ref]$out); $out\r\n\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (set targetSKU=%%a)\r\nif \"%targetSKU%\"==\"0\" set targetSKU=\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  https://github.com/asdcorp/Set-WindowsCbsEdition\r\n\r\n:cbsxml:[\r\nparam (\r\n    [Parameter()]\r\n    [String]$SetEdition,\r\n\r\n    [Parameter()]\r\n    [Switch]$GetTargetEditions,\r\n\r\n    [Parameter()]\r\n    [Switch]$StageCurrent\r\n)\r\n\r\nfunction Get-AssemblyIdentity {\r\n    param (\r\n        [String]$PackageName\r\n    )\r\n\r\n    $PackageName = [String]$PackageName\r\n    $packageData = ($PackageName -split '~')\r\n\r\n    if($packageData[3] -eq '') {\r\n        $packageData[3] = 'neutral'\r\n    }\r\n\r\n    return \"<assemblyIdentity name=`\"$($packageData[0])`\" version=`\"$($packageData[4])`\" processorArchitecture=`\"$($packageData[2])`\" publicKeyToken=`\"$($packageData[1])`\" language=`\"$($packageData[3])`\" />\"\r\n}\r\n\r\nfunction Get-SxsName {\r\n    param (\r\n        [String]$PackageName\r\n    )\r\n\r\n    $name = ($PackageName -replace '[^A-z0-9\\-\\._]', '')\r\n\r\n    if($name.Length -gt 40) {\r\n        $name = ($name[0..18] -join '') + '\\.\\.' + ($name[-19..-1] -join '')\r\n    }\r\n\r\n    return $name.ToLower()\r\n}\r\n\r\nfunction Find-EditionXmlInSxs {\r\n    param (\r\n        [String]$Edition\r\n    )\r\n\r\n    $candidates = @($Edition, 'Client', 'Server')\r\n    $winSxs = $Env:SystemRoot + '\\WinSxS'\r\n    $allInSxs = Get-ChildItem -Path $winSxs | select Name\r\n\r\n    foreach($candidate in $candidates) {\r\n        $name = Get-SxsName -PackageName \"Microsoft-Windows-Editions-$candidate\"\r\n        $packages = $allInSxs | where name -Match ('^.*_'+$name+'_31bf3856ad364e35')\r\n\r\n        if($packages.Length -eq 0) {\r\n            continue\r\n        }\r\n\r\n        $package = $packages[-1].Name\r\n        $testPath = $winSxs + \"\\$package\\\" + $Edition + 'Edition.xml'\r\n\r\n        if(Test-Path -Path $testPath -PathType Leaf) {\r\n            return $testPath\r\n        }\r\n    }\r\n\r\n    return $null\r\n}\r\n\r\nfunction Find-EditionXml {\r\n    param (\r\n        [String]$Edition\r\n    )\r\n\r\n    $servicingEditions = $Env:SystemRoot + '\\servicing\\Editions'\r\n    $editionXml = $Edition + 'Edition.xml'\r\n\r\n    $editionXmlInServicing = $servicingEditions + '\\' + $editionXml\r\n\r\n    if(Test-Path -Path $editionXmlInServicing -PathType Leaf) {\r\n        return $editionXmlInServicing\r\n    }\r\n\r\n    return Find-EditionXmlInSxs -Edition $Edition\r\n}\r\n\r\nfunction Write-UpgradeCandidates {\r\n    param (\r\n        [HashTable]$InstallCandidates\r\n    )\r\n\r\n    $editionCount = 0\r\n    Write-Host 'Editions that can be upgraded to:'\r\n    foreach($candidate in $InstallCandidates.Keys) {\r\n        Write-Host \"Target Edition : $candidate\"\r\n        $editionCount++\r\n    }\r\n\r\n    if($editionCount -eq 0) {\r\n        Write-Host '(no editions are available)'\r\n    }\r\n}\r\n\r\nfunction Write-UpgradeXml {\r\n    param (\r\n        [Array]$RemovalCandidates,\r\n        [Array]$InstallCandidates,\r\n        [Boolean]$Stage\r\n    )\r\n\r\n    $removeAction = 'remove'\r\n    if($Stage) {\r\n        $removeAction = 'stage'\r\n    }\r\n\r\n    Write-Output '<?xml version=\"1.0\"?>'\r\n    Write-Output '<unattend xmlns=\"urn:schemas-microsoft-com:unattend\">'\r\n    Write-Output '<servicing>'\r\n\r\n    foreach($package in $InstallCandidates) {\r\n        Write-Output '<package action=\"install\">'\r\n        Write-Output (Get-AssemblyIdentity -PackageName $package)\r\n        Write-Output '</package>'\r\n    }\r\n\r\n    foreach($package in $RemovalCandidates) {\r\n        Write-Output \"<package action=`\"$removeAction`\">\"\r\n        Write-Output (Get-AssemblyIdentity -PackageName $package)\r\n        Write-Output '</package>'\r\n    }\r\n\r\n    Write-Output '</servicing>'\r\n    Write-Output '</unattend>'\r\n}\r\n\r\nfunction Write-Usage {\r\n    Get-Help $script:MyInvocation.MyCommand.Path -detailed\r\n}\r\n\r\n$version = '1.0'\r\n$getTargetsParam = $GetTargetEditions.IsPresent\r\n$stageCurrentParam = $StageCurrent.IsPresent\r\n\r\nif($SetEdition -eq '' -and ($false -eq $getTargetsParam)) {\r\n    Write-Usage\r\n    Exit 1\r\n}\r\n\r\n$removalCandidates = @();\r\n$installCandidates = @{};\r\n\r\n$packages = Get-ChildItem -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\Packages' | select Name | where { $_.name -match '^.*\\\\Microsoft-Windows-.*Edition~' }\r\nforeach($package in $packages) {\r\n    $state = (Get-ItemProperty -Path \"Registry::$($package.Name)\").CurrentState\r\n    $packageName = ($package.Name -split '\\\\')[-1]\r\n    $packageEdition = (($packageName -split 'Edition~')[0] -split 'Microsoft-Windows-')[-1]\r\n\r\n    if($state -eq 0x40) {\r\n        if($null -eq $installCandidates[$packageEdition]) {\r\n            $installCandidates[$packageEdition] = @()\r\n        }\r\n\r\n        if($false -eq ($installCandidates[$packageEdition] -contains $packageName)) {\r\n            $installCandidates[$packageEdition] = $installCandidates[$packageEdition] + @($packageName)\r\n        }\r\n    }\r\n\r\n    if((($state -eq 0x50) -or ($state -eq 0x70)) -and ($false -eq ($removalCandidates -contains $packageName))) {\r\n        $removalCandidates = $removalCandidates + @($packageName)\r\n    }\r\n}\r\n\r\nif($getTargetsParam) {\r\n    Write-UpgradeCandidates -InstallCandidates $installCandidates\r\n    Exit\r\n}\r\n\r\nif($false -eq ($installCandidates.Keys -contains $SetEdition)) {\r\n    Write-Error \"The system cannot be upgraded to `\"$SetEdition`\"\"\r\n    Exit 1\r\n}\r\n\r\n$xmlPath = $Env:SystemRoot + '\\Temp' + '\\CbsUpgrade.xml'\r\n\r\nWrite-UpgradeXml -RemovalCandidates $removalCandidates `\r\n    -InstallCandidates $installCandidates[$SetEdition] `\r\n    -Stage $stageCurrentParam >$xmlPath\r\n\r\n$editionXml = Find-EditionXml -Edition $SetEdition\r\nif($null -eq $editionXml) {\r\n    Write-Warning 'Unable to find edition specific settings XML. Proceeding without it...'\r\n}\r\n\r\nWrite-Host 'Starting the upgrade process. This may take a while...'\r\n\r\nDISM.EXE /English /NoRestart /Online /Apply-Unattend:$xmlPath\r\n$dismError = $LASTEXITCODE\r\n\r\nRemove-Item -Path $xmlPath -Force\r\n\r\nif(($dismError -ne 0) -and ($dismError -ne 3010)) {\r\n    Write-Error 'Failed to upgrade to the target edition'\r\n    Exit $dismError\r\n}\r\n\r\nif($null -ne $editionXml) {\r\n    $destination = $Env:SystemRoot + '\\' + $SetEdition + '.xml'\r\n    Copy-Item -Path $editionXml -Destination $destination\r\n\r\n    DISM.EXE /English /NoRestart /Online /Apply-Unattend:$editionXml\r\n    $dismError = $LASTEXITCODE\r\n\r\n    if(($dismError -ne 0) -and ($dismError -ne 3010)) {\r\n        Write-Error 'Failed to apply edition specific settings'\r\n        Exit $dismError\r\n    }\r\n}\r\n\r\nRestart-Computer\r\n:cbsxml:]\r\n\r\n::========================================================================================================================================\r\n\r\n::  Change edition using DISM API\r\n::  Thanks to Alex (aka may, ave9858)\r\n\r\n:dismapi:[\r\nparam (\r\n    [Parameter()]\r\n    [String]$TargetEdition,\r\n\r\n    [Parameter()]\r\n    [String]$Key\r\n)\r\n\r\n$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)\r\n$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)\r\n$TB = $ModuleBuilder.DefineType(0)\r\n\r\n[void]$TB.DefinePInvokeMethod('DismInitialize', 'DismApi.dll', 22, 1, [int], @([int], [IntPtr], [IntPtr]), 1, 3)\r\n[void]$TB.DefinePInvokeMethod('DismOpenSession', 'DismApi.dll', 22, 1, [int], @([String], [IntPtr], [IntPtr], [UInt32].MakeByRefType()), 1, 3)\r\n[void]$TB.DefinePInvokeMethod('_DismSetEdition', 'DismApi.dll', 22, 1, [int], @([UInt32], [String], [String], [IntPtr], [IntPtr], [IntPtr]), 1, 3)\r\n$Dism = $TB.CreateType()\r\n\r\n[void]$Dism::DismInitialize(2, 0, 0)\r\n$Session = 0\r\n[void]$Dism::DismOpenSession('DISM_{53BFAE52-B167-4E2F-A258-0A37B57FF845}', 0, 0, [ref]$Session)\r\nif (!$Dism::_DismSetEdition($Session, \"$TargetEdition\", \"$Key\", 0, 0, 0)) {\r\n    Restart-Computer\r\n}\r\n:dismapi:]\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Generic Retail/OEM/MAK/GVLK Key\r\n::  2nd column = Key Type\r\n::  3rd column = WMI Edition ID\r\n::  4th column = Version name incase same Edition ID is used in different OS versions with different key\r\n::  Separator  = _\r\n\r\n::  For Windows 10/11 editions, HWID key is listed where ever possible, in Server versions, KMS key is listed where ever possible.\r\n::  For Windows, generic keys are mentioned till 22000 and for Server, generic keys are mentioned till 17763, later ones are extracted from the pkeyhelper.dll\r\n\r\n:changeeditiondata\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" (\r\nif %winbuild% GTR 17763 exit /b\r\n) else (\r\nif %winbuild% GEQ 22000 exit /b\r\n)\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*CorEdition~*.mum\" (set Cor=Cor) else (set Cor=)\r\n\r\nset w=\r\nfor %%# in (\r\nXGVPP-NMH47-7TTHJ-W3FW7-8HV%w%2C__OEM:NONSLP_Enterprise\r\nD6RD9-D4N8T-RT9QX-YW6YT-FCW%w%WJ______Retail_Starter\r\n3V6Q6-NQXCX-V8YXR-9QCYV-QPF%w%CT__Volume:MAK_EnterpriseN\r\n3NFXW-2T27M-2BDW6-4GHRV-68X%w%RX______Retail_StarterN\r\nVK7JG-NPHTM-C97JM-9MPGT-3V6%w%6T______Retail_Professional\r\n2B87N-8KFHP-DKV6R-Y2C8J-PKC%w%KT______Retail_ProfessionalN\r\n4CPRK-NM3K3-X6XXQ-RXX86-WXC%w%HW______Retail_CoreN\r\nN2434-X9D7W-8PF6X-8DV9T-8TY%w%MD______Retail_CoreCountrySpecific\r\nBT79Q-G7N6G-PGBYW-4YWX6-6F4%w%BT______Retail_CoreSingleLanguage\r\nYTMG3-N6DKC-DKB77-7M9GH-8HV%w%X7______Retail_Core\r\nXKCNC-J26Q9-KFHD2-FKTHY-KD7%w%2Y__OEM:NONSLP_PPIPro\r\nYNMGQ-8RYV3-4PGQ3-C8XTP-7CF%w%BY______Retail_Education\r\n84NGF-MHBT6-FXBX8-QWJK7-DRR%w%8H______Retail_EducationN\r\nKCNVH-YKWX8-GJJB9-H9FDT-6F7%w%W2__Volume:MAK_EnterpriseS_VB\r\n43TBQ-NH92J-XKTM7-KT3KK-P39%w%PB__OEM:NONSLP_EnterpriseS_RS5\r\nNK96Y-D9CD8-W44CQ-R8YTK-DYJ%w%WX__OEM:NONSLP_EnterpriseS_RS1\r\nFWN7H-PF93Q-4GGP8-M8RF3-MDW%w%WW__OEM:NONSLP_EnterpriseS_TH\r\nRQFNW-9TPM3-JQ73T-QV4VQ-DV9%w%PT__Volume:MAK_EnterpriseSN_VB\r\nM33WV-NHY3C-R7FPM-BQGPT-239%w%PG__Volume:MAK_EnterpriseSN_RS5\r\n2DBW3-N2PJG-MVHW3-G7TDK-9HK%w%R4__Volume:MAK_EnterpriseSN_RS1\r\nNTX6B-BRYC2-K6786-F6MVQ-M7V%w%2X__Volume:MAK_EnterpriseSN_TH\r\nG3KNM-CHG6T-R36X3-9QDG6-8M8%w%K9______Retail_ProfessionalSingleLanguage\r\nHNGCC-Y38KG-QVK8D-WMWRK-X86%w%VK______Retail_ProfessionalCountrySpecific\r\nDXG7C-N36C4-C4HTG-X4T3X-2YV%w%77______Retail_ProfessionalWorkstation\r\nWYPNQ-8C467-V2W6J-TX4WX-WT2%w%RQ______Retail_ProfessionalWorkstationN\r\n8PTT6-RNW4C-6V7J2-C2D3X-MHB%w%PB______Retail_ProfessionalEducation\r\nGJTYN-HDMQY-FRR76-HVGC7-QPF%w%8P______Retail_ProfessionalEducationN\r\nC4NTJ-CX6Q2-VXDMR-XVKGM-F9D%w%JC__Volume:MAK_EnterpriseG\r\n46PN6-R9BK9-CVHKB-HWQ9V-MBJ%w%Y8__Volume:MAK_EnterpriseGN\r\nNJCF7-PW8QT-3324D-688JX-2YV%w%66______Retail_ServerRdsh\r\nXQQYW-NFFMW-XJPBH-K8732-CKF%w%FD______OEM:DM_IoTEnterprise\r\nQPM6N-7J2WJ-P88HH-P3YRH-YY7%w%4H__OEM:NONSLP_IoTEnterpriseS\r\nK9VKN-3BGWV-Y624W-MCRMQ-BHD%w%CD______Retail_CloudEditionN\r\nKY7PN-VR6RX-83W6Y-6DDYQ-T6R%w%4W______Retail_CloudEdition\r\nV3WVW-N2PV2-CGWC3-34QGF-VMJ%w%2C______Retail_Cloud\r\nNH9J3-68WK7-6FB93-4K3DF-DJ4%w%F6______Retail_CloudN\r\n2HN6V-HGTM8-6C97C-RK67V-JQP%w%FD______Retail_CloudE\r\nWC2BQ-8NRM3-FDDYY-2BFGV-KHK%w%QY_Volume:GVLK_ServerStandard%Cor%_RS1\r\nCB7KF-BWN84-R7R2Y-793K2-8XD%w%DG_Volume:GVLK_ServerDatacenter%Cor%_RS1\r\nJCKRF-N37P4-C2D82-9YXRT-4M6%w%3B_Volume:GVLK_ServerSolution_RS1\r\nQN4C6-GBJD2-FB422-GHWJK-GJG%w%2R_Volume:GVLK_ServerCloudStorage_RS1\r\nVP34G-4NPPG-79JTQ-864T4-R3M%w%QX_Volume:GVLK_ServerAzureCor_RS1\r\n9JQNQ-V8HQ6-PKB8H-GGHRY-R62%w%H6______Retail_ServerAzureNano_RS1\r\nVN8D3-PR82H-DB6BJ-J9P4M-92F%w%6J______Retail_ServerStorageStandard_RS1\r\n48TQX-NVK3R-D8QR3-GTHHM-8FH%w%XC______Retail_ServerStorageWorkgroup_RS1\r\n2HXDN-KRXHB-GPYC7-YCKFJ-7FV%w%DG_Volume:GVLK_ServerDatacenterACor_RS3\r\nPTXN8-JFHJM-4WC78-MPCBR-9W4%w%KR_Volume:GVLK_ServerStandardACor_RS3\r\n) do (\r\nfor /f \"tokens=1-4 delims=_\" %%A in (\"%%#\") do if /i %targetedition%==%%C (\r\n\r\nif not defined key (\r\nset 4th=%%D\r\nif not defined 4th (\r\nset \"key=%%A\" & set \"_chan=%%B\"\r\n) else (\r\necho \"%branch%\" | find /i \"%%D\" %nul1% && (set \"key=%%A\" & set \"_chan=%%B\")\r\n)\r\n)\r\n)\r\n)\r\nexit /b\r\n\r\n:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n\r\n:change_offedition\r\n\r\nset \"line=echo ___________________________________________________________________________________________\"\r\n\r\ncls\r\nif not defined terminal mode 98, 30\r\ntitle  Change Office Edition %masver%\r\n\r\nif %winbuild% LSS 7600 (\r\n%eline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho This option is supported only for Windows 7/8/8.1/10/11 and their Server equivalents.\r\ngoto dk_done\r\n)\r\n\r\necho:\r\necho Initializing...\r\necho:\r\n\r\n::========================================================================================================================================\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_reflection\r\ncall :dk_ckeckwmic\r\ncall :dk_sppissue\r\n\r\nfor /f \"tokens=6-7 delims=[]. \" %%i in ('ver') do if not \"%%j\"==\"\" (\r\nset fullbuild=%%i.%%j\r\n) else (\r\nfor /f \"tokens=3\" %%G in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR\" %nul6%') do if not errorlevel 1 set /a \"UBR=%%G\"\r\nfor /f \"skip=2 tokens=3,4 delims=. \" %%G in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildLabEx') do (\r\nif defined UBR (set \"fullbuild=%%G.!UBR!\") else (set \"fullbuild=%%G.%%H\")\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Windows Edition\r\n::  This is just to ensure that SPP/WMI are functional\r\n\r\ncls\r\nset osedition=0\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do if not errorlevel 1 (call set \"osedition=%%a\")\r\n\r\nif %osedition%==0 (\r\n%eline%\r\necho Failed to detect OS Edition. Aborting...\r\ncall :dk_color %Blue% \"To fix this issue, activate Windows from the main menu.\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check installed Office 16.0 C2R\r\n\r\nset o16c2r=\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" (set o16c2r=1&set o16c2r_reg=%_86%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" (set o16c2r=1&set o16c2r_reg=%_68%\\ClickToRun)\r\n\r\nif not defined o16c2r_reg (\r\n%eline%\r\necho Office C2R 2016 or later is not installed, which is required for this script.\r\necho Download and install Office from below URL and try again.\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto dk_done\r\n)\r\n\r\ncall :ch_getinfo\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check minimum required details\r\n\r\nif %verchk% LSS 9029 (\r\n%eline%\r\necho Installed Office version is %_version%.\r\necho Minimum required version is 16.0.9029.2167\r\necho Aborting...\r\ncall :dk_color %Blue% \"Download and install latest Office from below URL and try again.\"\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto dk_done\r\n)\r\n\r\nfor %%A in (\r\n_oArch\r\n_updch\r\n_lang\r\n_clversion\r\n_version\r\n_AudienceData\r\n_oIds\r\n_c2rXml\r\n_c2rExe\r\n_c2rCexe\r\n_masterxml\r\n) do (\r\nif not defined %%A (\r\n%eline%\r\necho Failed to find %%A. Aborting...\r\ncall :dk_color %Blue% \"Download and install Office from below URL and try again.\"\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 10240 if defined ltscfound (\r\n%eline%\r\necho Installed Office appears to be from the Volume channel %ltsc19%%ltsc21%%ltsc24%,\r\necho which is not officially supported on your Windows build version %winbuild%.\r\necho Aborting...\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\nset unsupbuild=\r\nif %winbuild% LSS 10240 if %winbuild% GEQ 9200 if %verchk% GTR 16026 set unsupbuild=1\r\nif %winbuild% LSS 9200 if %verchk% GTR 12527 set unsupbuild=1\r\n\r\nif defined unsupbuild (\r\n%eline%\r\necho Unsupported Office %verchk% is installed on your Windows build version %winbuild%.\r\necho Aborting...\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:oemenu\r\n\r\ncls\r\nset fixes=\r\nif not defined terminal mode 76, 25\r\ntitle  Change Office Edition %masver%\r\necho:\r\necho:\r\necho:\r\necho:\r\necho         ____________________________________________________________\r\necho:\r\necho                 [1] Change all editions\r\necho                 [2] Add edition\r\necho                 [3] Remove edition\r\necho:\r\necho                 [4] Add/Remove apps\r\necho                 ____________________________________________\r\necho:\r\necho                 [5] Change Office Update Channel\r\necho                 [0] %_exitmsg%\r\necho         ____________________________________________________________\r\necho: \r\ncall :dk_color2 %_White% \"           \" %_Green% \"Choose a menu option using your keyboard [1,2,3,4,5,0]\"\r\nchoice /C:123450 /N\r\nset _el=!errorlevel!\r\nif !_el!==6  exit /b\r\nif !_el!==5  goto :oe_changeupdchnl\r\nif !_el!==4  goto :oe_editedition\r\nif !_el!==3  goto :oe_removeedition\r\nif !_el!==2  set change=0& goto :oe_edition\r\nif !_el!==1  set change=1& goto :oe_edition\r\ngoto :oemenu\r\n\r\n::========================================================================================================================================\r\n\r\n:oe_edition\r\n\r\ncls\r\ncall :oe_chkinternet\r\nif not defined _int (\r\ngoto :oe_goback\r\n)\r\n\r\ncls\r\nif not defined terminal mode 76, 25\r\nif %change%==1 (\r\ntitle  Change all editions %masver%\r\n) else (\r\ntitle  Add edition %masver%\r\n)\r\n\r\necho:\r\necho:\r\necho:\r\necho:\r\necho                 O365/Mondo editions have the latest features.     \r\necho         ____________________________________________________________\r\necho:\r\necho                 [1] Office Suites     - Retail\r\necho                 [2] Office Suites     - Volume\r\necho                 [3] Office SingleApps - Retail\r\necho                 [4] Office SingleApps - Volume\r\necho                 ____________________________________________\r\necho:\r\necho                 [0] Go Back\r\necho         ____________________________________________________________\r\necho: \r\ncall :dk_color2 %_White% \"            \" %_Green% \"Choose a menu option using your keyboard [1,2,3,4,0]\"\r\nchoice /C:12340 /N\r\nset _el=!errorlevel!\r\nif !_el!==5  goto :oemenu\r\nif !_el!==4  set list=SingleApps_Volume&goto :oe_editionchangepre\r\nif !_el!==3  set list=SingleApps_Retail&goto :oe_editionchangepre\r\nif !_el!==2  set list=Suites_Volume&goto :oe_editionchangepre\r\nif !_el!==1  set list=Suites_Retail&goto :oe_editionchangepre\r\ngoto :oe_edition\r\n\r\n::========================================================================================================================================\r\n\r\n:oe_editionchangepre\r\n\r\ncls\r\nset editedition=\r\ncall :ch_getinfo\r\ncall :oe_tempcleanup\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getlist\\:.*';. ([scriptblock]::Create($f[1]))\"\r\n\r\n:oe_editionchange\r\n\r\ncls\r\nif not defined terminal (\r\nmode 98, 45\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=44;$B.Height=100;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\n\r\nif not exist %SystemRoot%\\Temp\\%list%.txt (\r\n%eline%\r\necho Failed to generate available editions list.\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto :oe_goback\r\n)\r\n\r\nset inpt=\r\nset counter=0\r\nset verified=0\r\nset _notfound=\r\nset targetedition=\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"Installed Office editions: %_oIds%\"\r\ncall :dk_color %Gray% \"You can select one of the following Office Editions.\"\r\nif %winbuild% LSS 10240 (\r\necho Unsupported products such as 2019/2021/2024 are excluded from this list.\r\n) else (\r\nfor %%# in (2019 2021 2024) do (\r\nfind /i \"%%#\" \"%SystemRoot%\\Temp\\%list%.txt\" %nul1% || (\r\nif defined _notfound (set _notfound=%%#, !_notfound!) else (set _notfound=%%#)\r\n)\r\n)\r\nif defined _notfound call :dk_color %Gray% \"Office !_notfound! is not in this list because old version [%_version%] of Office is installed.\"\r\n)\r\n%line%\r\necho:\r\n\r\nfor /f \"usebackq delims=\" %%A in (%SystemRoot%\\Temp\\%list%.txt) do (\r\nset /a counter+=1\r\nif !counter! LSS 10 (\r\necho [!counter!]  %%A\r\n) else (\r\necho [!counter!] %%A\r\n)\r\nset targetedition!counter!=%%A\r\n)\r\n\r\n%line%\r\necho:\r\necho [0]  Go Back\r\necho:\r\ncall :dk_color %_Green% \"Enter an option number using your keyboard and press Enter to confirm:\"\r\nset /p inpt=\r\nif \"%inpt%\"==\"\" goto :oe_editionchange\r\nif \"%inpt%\"==\"0\" (call :oe_tempcleanup & goto :oe_edition)\r\nfor /l %%i in (1,1,%counter%) do (if \"%inpt%\"==\"%%i\" set verified=1)\r\nset targetedition=!targetedition%inpt%!\r\nif %verified%==0 goto :oe_editionchange\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set app exclusions\r\n\r\n:oe_excludeappspre\r\n\r\ncls\r\nset suites=\r\necho %list% | find /i \"Suites\" %nul1% && (\r\nset suites=1\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getappnames\\:.*';. ([scriptblock]::Create($f[1]))\"\r\nif not exist %SystemRoot%\\Temp\\getAppIds.txt (\r\n%eline%\r\necho Failed to generate available apps list.\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto :oe_goback\r\n)\r\n)\r\n\r\nfor %%# in (\r\nAccess\r\nExcel\r\nLync\r\nOneNote\r\nOutlook\r\nPowerPoint\r\nProject\r\nPublisher\r\nVisio\r\nWord\r\n) do (\r\nif defined suites (\r\nfind /i \"%%#\" \"%SystemRoot%\\Temp\\getAppIds.txt\" %nul1% && (set %%#_st=On) || (set %%#_st=)\r\n) else (\r\nset %%#_st=\r\n)\r\n)\r\n\r\nif defined Lync_st set Lync_st=Off\r\nset OneDrive_st=Off\r\nif defined suites (set Teams_st=Off) else (set Teams_st=)\r\n\r\n:oe_excludeapps\r\n\r\ncls\r\nif not defined terminal mode 98, 32\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"Target edition: %targetedition%\"\r\ncall :dk_color %Gray% \"To exclude the apps listed below from installation, toggle them from On to Off.\"\r\nif defined editedition call :dk_color %Gray% \"Note: The On/Off status below does not reflect the current status of the installed apps.\"\r\n%line%\r\nif defined suites echo:\r\nif defined Access_st     echo [A] Access           : %Access_st%\r\nif defined Excel_st      echo [E] Excel            : %Excel_st%\r\nif defined OneNote_st    echo [N] OneNote          : %OneNote_st%\r\nif defined Outlook_st    echo [O] Outlook          : %Outlook_st%\r\nif defined PowerPoint_st echo [P] PowerPoint       : %PowerPoint_st%\r\nif defined Project_st    echo [J] Project          : %Project_st%\r\nif defined Publisher_st  echo [R] Publisher        : %Publisher_st%\r\nif defined Visio_st      echo [V] Visio            : %Visio_st%\r\nif defined Word_st       echo [W] Word             : %Word_st%\r\necho:\r\nif defined Lync_st       echo [L] SkypeForBusiness : %Lync_st%\r\nif defined OneDrive_st   echo [D] OneDrive         : %OneDrive_st%\r\nif defined Teams_st      echo [T] Teams            : %Teams_st%\r\n%line%\r\necho:\r\necho [1] Continue\r\necho [0] Go Back\r\n%line%\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard:\"\r\nchoice /C:AENOPJRVWLDT10 /N\r\nset _el=!errorlevel!\r\nif !_el!==14 goto :oemenu\r\nif !_el!==13 call :excludelist & goto :oe_editionchangefinal\r\nif !_el!==12 if defined Teams_st      (if \"%Teams_st%\"==\"Off\"      (set Teams_st=ON)      else (set Teams_st=Off))\r\nif !_el!==11 if defined OneDrive_st   (if \"%OneDrive_st%\"==\"Off\"   (set OneDrive_st=ON)   else (set OneDrive_st=Off))\r\nif !_el!==10 if defined Lync_st       (if \"%Lync_st%\"==\"Off\"       (set Lync_st=ON)       else (set Lync_st=Off))\r\nif !_el!==9  if defined Word_st       (if \"%Word_st%\"==\"Off\"       (set Word_st=ON)       else (set Word_st=Off))\r\nif !_el!==8  if defined Visio_st      (if \"%Visio_st%\"==\"Off\"      (set Visio_st=ON)      else (set Visio_st=Off))\r\nif !_el!==7  if defined Publisher_st  (if \"%Publisher_st%\"==\"Off\"  (set Publisher_st=ON)  else (set Publisher_st=Off))\r\nif !_el!==6  if defined Project_st    (if \"%Project_st%\"==\"Off\"    (set Project_st=ON)    else (set Project_st=Off))\r\nif !_el!==5  if defined PowerPoint_st (if \"%PowerPoint_st%\"==\"Off\" (set PowerPoint_st=ON) else (set PowerPoint_st=Off))\r\nif !_el!==4  if defined Outlook_st    (if \"%Outlook_st%\"==\"Off\"    (set Outlook_st=ON)    else (set Outlook_st=Off))\r\nif !_el!==3  if defined OneNote_st    (if \"%OneNote_st%\"==\"Off\"    (set OneNote_st=ON)    else (set OneNote_st=Off))\r\nif !_el!==2  if defined Excel_st      (if \"%Excel_st%\"==\"Off\"      (set Excel_st=ON)      else (set Excel_st=Off))\r\nif !_el!==1  if defined Access_st     (if \"%Access_st%\"==\"Off\"     (set Access_st=ON)     else (set Access_st=Off))\r\ngoto :oe_excludeapps\r\n\r\n:excludelist\r\n\r\nset excludelist=\r\nfor %%# in (\r\naccess\r\nexcel\r\nonenote\r\noutlook\r\npowerpoint\r\nproject\r\npublisher\r\nvisio\r\nword\r\nlync\r\nonedrive\r\nteams\r\n) do (\r\nif /i \"!%%#_st!\"==\"Off\" if defined excludelist (set excludelist=!excludelist!,%%#) else (set excludelist=,%%#)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Final command to change/add edition\r\n\r\n:oe_editionchangefinal\r\n\r\ncls\r\nif not defined terminal mode 105, 32\r\n\r\n::  Check for Project and Visio with unsupported language\r\n\r\nset projvis=\r\nset langmatched=\r\necho: %Project_st% %Visio_st% | find /i \"ON\" %nul% && set projvis=1\r\necho: %targetedition% | findstr /i \"Project Visio\" %nul% && set projvis=1\r\n\r\nif defined projvis (\r\nfor %%# in (\r\nar-sa\r\ncs-cz\r\nda-dk\r\nde-de\r\nel-gr\r\nen-us\r\nes-es\r\nfi-fi\r\nfr-fr\r\nhe-il\r\nhu-hu\r\nit-it\r\nja-jp\r\nko-kr\r\nnb-no\r\nnl-nl\r\npl-pl\r\npt-br\r\npt-pt\r\nro-ro\r\nru-ru\r\nsk-sk\r\nsl-si\r\nsv-se\r\ntr-tr\r\nuk-ua\r\nzh-cn\r\nzh-tw\r\n) do (\r\nif /i \"%_lang%\"==\"%%#\" set langmatched=1\r\n)\r\nif not defined langmatched (\r\n%eline%\r\necho %_lang% language is not available for Project/Visio apps.\r\ncall :dk_color %Blue% \"Install Office in the supported language for Project/Visio from the below URL.\"\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto :oe_goback\r\n)\r\n)\r\n\r\n::  Thanks to @abbodi1406 for first discovering OfficeClickToRun.exe uses\r\n::  Thanks to @may for the suggestion to use it to change edition with CDN as a source\r\n::  OfficeClickToRun.exe with productstoadd method is used here to add editions\r\n::  It uses delta updates, meaning that since it's using same installed build, it will consume very less Internet\r\n\r\ncall :oe_getlangs\r\n\r\nset \"c2rcommand=\"%_c2rExe%\" platform=%_oArch% culture=%_lang% productstoadd=%targetedition%.16_%_allLangs% cdnbaseurl.16=http://officecdn.microsoft.com/pr/%_updch% baseurl.16=http://officecdn.microsoft.com/pr/%_updch% version.16=%_version% mediatype.16=CDN sourcetype.16=CDN deliverymechanism=%_updch% %targetedition%.excludedapps.16=groove%excludelist% flt.useteamsaddon=disabled flt.usebingaddononinstall=disabled flt.usebingaddononupdate=disabled\"\r\n\r\nif %change%==1 (\r\nset \"c2rcommand=!c2rcommand! productstoremove=AllProducts\"\r\n)\r\n\r\necho:\r\necho Running the below command, please wait...\r\necho:\r\necho %c2rcommand%\r\n%c2rcommand%\r\nset errorcode=%errorlevel%\r\ntimeout /t 10 %nul%\r\n\r\necho:\r\nset suggestchannel=\r\n\r\nif %errorcode% EQU 0 (\r\nif %change%==1 (\r\necho %targetedition% | find /i \"2019Volume\" %nul% && (\r\nif not defined ltsc19 set suggestchannel=Production::LTSC\r\nif /i not %_AudienceData%==Production::LTSC set suggestchannel=Production::LTSC\r\nif /i not %_updch%==F2E724C1-748F-4B47-8FB8-8E0D210E9208 set suggestchannel=Production::LTSC\r\n)\r\n\r\necho %targetedition% | find /i \"2021Volume\" %nul% && (\r\nif not defined ltsc21 set suggestchannel=Production::LTSC2021\r\nif /i not %_AudienceData%==Production::LTSC2021 set suggestchannel=Production::LTSC2021\r\nif /i not %_updch%==5030841D-C919-4594-8D2D-84AE4F96E58E set suggestchannel=Production::LTSC2021\r\n)\r\n\r\necho %targetedition% | find /i \"2024Volume\" %nul% && (\r\nif not defined ltsc24 set suggestchannel=Production::LTSC2024\r\nif /i not %_AudienceData%==Production::LTSC2024 set suggestchannel=Production::LTSC2024\r\nif /i not %_updch%==7983BAC0-E531-40CF-BE00-FD24FE66619C set suggestchannel=Production::LTSC2024\r\n)\r\n\r\necho %targetedition% | findstr /R \"20.*Volume\" %nul% || (\r\nif defined ltscfound set suggestchannel=Production::CC\r\necho %_AudienceData% | find /i \"LTSC\" %nul% && set suggestchannel=Production::CC\r\n)\r\n\r\nif defined suggestchannel (\r\ncall :dk_color %Gray% \"Mismatch found in update channel and installed product.\"\r\ncall :dk_color %Blue% \"It is recommended to change the update channel to [!suggestchannel!] from the previous menu.\"\r\n)\r\necho:\r\n)\r\ncall :dk_color %Gray% \"To activate Office, run the activation option from the main menu.\"\r\n) else (\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\ncall :oe_tempcleanup\r\ngoto :oe_goback\r\n\r\n::========================================================================================================================================\r\n\r\n::  Edit Office edition\r\n\r\n:oe_editedition\r\n\r\ncls\r\ntitle  Add/Remove Apps %masver%\r\n\r\ncall :oe_chkinternet\r\nif not defined _int (\r\ngoto :oe_goback\r\n)\r\n\r\nset change=0\r\nset editedition=1\r\ncall :ch_getinfo\r\ncls\r\n\r\nif not defined terminal (\r\nmode 98, 35\r\n)\r\n\r\nset inpt=\r\nset counter=0\r\nset verified=0\r\nset targetedition=\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"You can edit [add/remove apps] one of the following Office editions.\"\r\n%line%\r\necho:\r\n\r\nfor %%A in (%_oIds%) do (\r\nset /a counter+=1\r\necho [!counter!] %%A\r\nset targetedition!counter!=%%A\r\n)\r\n\r\n%line%\r\necho:\r\necho [0]  Go Back\r\necho:\r\ncall :dk_color %_Green% \"Enter an option number using your keyboard and press Enter to confirm:\"\r\nset /p inpt=\r\nif \"%inpt%\"==\"\" goto :oe_editedition\r\nif \"%inpt%\"==\"0\" goto :oemenu\r\nfor /l %%i in (1,1,%counter%) do (if \"%inpt%\"==\"%%i\" set verified=1)\r\nset targetedition=!targetedition%inpt%!\r\nif %verified%==0 goto :oe_editedition\r\n\r\n::===============\r\n\r\ncls\r\nif not defined terminal mode 98, 32\r\n\r\necho %targetedition% | findstr /i \"Access Excel OneNote Outlook PowerPoint Project Publisher Skype Visio Word\" %nul% && (set list=SingleApps) || (set list=Suites)\r\ngoto :oe_excludeappspre\r\n\r\n::========================================================================================================================================\r\n\r\n::  Remove Office editions\r\n\r\n:oe_removeedition\r\n\r\ntitle  Remove Office editions %masver%\r\n\r\ncall :ch_getinfo\r\n\r\ncls\r\nif not defined terminal (\r\nmode 98, 35\r\n)\r\n\r\nset counter=0\r\nfor %%A in (%_oIds%) do (set /a counter+=1)\r\n\r\nif !counter! LEQ 1 (\r\necho:\r\necho Only \"%_oIds%\" product is installed.\r\necho This option is available only when multiple products are installed.\r\ngoto :oe_goback\r\n)\r\n\r\n::===============\r\n\r\nset inpt=\r\nset counter=0\r\nset verified=0\r\nset targetedition=\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"You can uninstall one of the following Office editions.\"\r\n%line%\r\necho:\r\n\r\nfor %%A in (%_oIds%) do (\r\nset /a counter+=1\r\necho [!counter!] %%A\r\nset targetedition!counter!=%%A\r\n)\r\n\r\n%line%\r\necho:\r\necho [0]  Go Back\r\necho:\r\ncall :dk_color %_Green% \"Enter an option number using your keyboard and press Enter to confirm:\"\r\nset /p inpt=\r\nif \"%inpt%\"==\"\" goto :oe_removeedition\r\nif \"%inpt%\"==\"0\" goto :oemenu\r\nfor /l %%i in (1,1,%counter%) do (if \"%inpt%\"==\"%%i\" set verified=1)\r\nset targetedition=!targetedition%inpt%!\r\nif %verified%==0 goto :oe_removeedition\r\n\r\n::===============\r\n\r\ncls\r\nif not defined terminal mode 105, 32\r\n\r\ncall :oe_getlangs %targetedition%\r\nset \"c2rcommand=\"%_c2rExe%\" platform=%_oArch% productstoremove=%targetedition%.16_%_allLangs%\"\r\n\r\necho:\r\necho Running the below command, please wait...\r\necho:\r\necho %c2rcommand%\r\n%c2rcommand%\r\n\r\nif %errorlevel% NEQ 0 (\r\necho:\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\ngoto :oe_goback\r\n\r\n::========================================================================================================================================\r\n\r\n::  Change Office update channel\r\n\r\n:oe_changeupdchnl\r\n\r\ntitle  Change Office update channel %masver%\r\ncall :ch_getinfo\r\n\r\ncls\r\nif not defined terminal (\r\nmode 98, 33\r\n)\r\n\r\ncall :oe_chkinternet\r\nif not defined _int (\r\ngoto :oe_goback\r\n)\r\n\r\nif %winbuild% LSS 10240 (\r\necho %_oIds% | findstr \"2019 2021 2024\" %nul% && (\r\n%eline%\r\necho Installed Office editions: %_oIds%\r\necho Unsupported Office edition is installed on your Windows build version %winbuild%.\r\ngoto :oe_goback\r\n)\r\nif defined ltscfound (\r\n%eline%\r\necho Installed Office update channel: %ltsc19%%ltsc21%%ltsc24%\r\necho Unsupported Office update channel is installed on your Windows build version %winbuild%.\r\ngoto :oe_goback\r\n)\r\n)\r\n\r\n::===============\r\n\r\nset inpt=\r\nset counter=0\r\nset verified=0\r\nset targetFFN=\r\nset bypassFFN=\r\nset targetchannel=\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"Installed update channel: %_AudienceData%, %_version%, Client: %_clversion%\"\r\ncall :dk_color %Gray% \"Installed Office editions: %_oIds%\"\r\n%line%\r\necho:\r\n\r\nfor %%# in (\r\n\"5440fd1f-7ecb-4221-8110-145efaa6372f_Beta    / Insider Fast    -   Insiders::DevMain  -\"\r\n\"64256afe-f5d9-4f86-8936-8840a6a4f5be_Current / Monthly Preview -   Insiders::CC       -\"\r\n\"492350f6-3a01-4f97-b9c0-c7c6ddf67d60_Current / Monthly         - Production::CC       -\"\r\n\"55336b82-a18d-4dd6-b5f6-9e5095c314a6_Monthly Enterprise        - Production::MEC      -\"\r\n\"7ffbc6bf-bc32-4f92-8982-f9dd17fd3114_Semi Annual Enterprise    - Production::DC       -\"\r\n\"ea4a4090-de26-49d7-93c1-91bff9e53fc3_DevMain Channel           -    Dogfood::DevMain  -\"\r\n\"b61285dd-d9f7-41f2-9757-8f61cba4e9c8_Microsoft Elite           -  Microsoft::DevMain  -\"\r\n\"f2e724c1-748f-4b47-8fb8-8e0d210e9208_Perpetual2019 VL          - Production::LTSC     -\"\r\n\"1d2d2ea6-1680-4c56-ac58-a441c8c24ff9_Microsoft2019 VL          -  Microsoft::LTSC     -\"\r\n\"5030841d-c919-4594-8d2d-84ae4f96e58e_Perpetual2021 VL          - Production::LTSC2021 -\"\r\n\"86752282-5841-4120-ac80-db03ae6b5fdb_Microsoft2021 VL          -  Microsoft::LTSC2021 -\"\r\n\"7983bac0-e531-40cf-be00-fd24fe66619c_Perpetual2024 VL          - Production::LTSC2024 -\"\r\n\"c02d8fe6-5242-4da8-972f-82ee55e00671_Microsoft2024 VL          -  Microsoft::LTSC2024 -\"\r\n) do (\r\nfor /f \"tokens=1-2 delims=_\" %%A in (\"%%~#\") do (\r\nset bypass=\r\nset supported=\r\nif %winbuild% LSS 10240 (echo %%B | findstr /i \"LTSC DevMain\" %nul% || set supported=1) else (set supported=1)\r\nif %winbuild% GEQ 10240 (\r\nif defined ltsc19 echo %%B | find /i \"2019 VL\" %nul% || set bypass=1\r\nif defined ltsc21 echo %%B | find /i \"2021 VL\" %nul% || set bypass=1\r\nif defined ltsc24 echo %%B | find /i \"2024 VL\" %nul% || set bypass=1\r\nif not defined ltscfound echo %%B | find /i \"LTSC\" %nul% && set bypass=1\r\n)\r\nif defined supported (\r\nset /a counter+=1\r\nif !counter! LSS 10 (\r\nif defined bypass (echo [!counter!]  %%B  Unofficial change method will be used) else (echo [!counter!]  %%B)\r\n) else (\r\nif defined bypass (echo [!counter!] %%B  Unofficial change method will be used) else (echo [!counter!] %%B)\r\n)\r\nset targetFFN!counter!=%%A\r\nset targetchannel!counter!=%%B\r\nif defined bypass set bypassFFN=!bypassFFN!%%A\r\n)\r\n)\r\n)\r\n\r\n%line%\r\necho:\r\necho [R]  Learn about update channels\r\necho [0]  Go back\r\necho:\r\ncall :dk_color %_Green% \"Enter an option number using your keyboard and press Enter to confirm:\"\r\nset /p inpt=\r\nif \"%inpt%\"==\"\" goto :oe_changeupdchnl\r\nif \"%inpt%\"==\"0\" goto :oemenu\r\nif /i \"%inpt%\"==\"R\" start https://learn.microsoft.com/en-us/microsoft-365-apps/updates/overview-update-channels & goto :oe_changeupdchnl\r\nfor /l %%i in (1,1,%counter%) do (if \"%inpt%\"==\"%%i\" set verified=1)\r\nset targetFFN=!targetFFN%inpt%!\r\nset targetchannel=!targetchannel%inpt%!\r\nif %verified%==0 goto :oe_changeupdchnl\r\n\r\n::=======================\r\n\r\ncls\r\nif not defined terminal mode 105, 32\r\n\r\n::  Get build number for the target FFN, using build number with OfficeC2RClient.exe command to trigger updates provides accurate results\r\n\r\nset build=\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getbuild\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (set build=%%a)\r\necho \"%build%\" | find /i \"16.\" %nul% || set build=\r\n\r\necho:\r\nfor /f \"tokens=1 delims=-\" %%A in (\"%targetchannel%\") do (echo Target update channel: %%A)\r\necho Target build number: %build%\r\necho: %bypassFFN% | find /i \"%targetFFN%\" %nul% && goto :oe_changeunoff\r\n\r\ncall :oe_cleanupreg\r\n\r\nif not defined build (\r\nif %winbuild% GEQ 9200 call :dk_color %Gray% \"Failed to detect build number for the target FFN.\"\r\nset \"updcommand=\"%_c2rCexe%\" /update user\"\r\n) else (\r\nset \"updcommand=\"%_c2rCexe%\" /update user updatetoversion=%build%\"\r\n)\r\necho Running the below command to trigger updates...\r\necho:\r\necho %updcommand%\r\n%updcommand%\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\ngoto :oe_goback\r\n\r\n::=======================\r\n\r\n::  Unofficial method to change channel\r\n\r\n:oe_changeunoff\r\n\r\nset abortchange=\r\necho %targetchannel% | find /i \"2019 VL\" %nul% && (for %%A in (%_oIds%) do (echo %%A | find /i \"2019Volume\" %nul% || set abortchange=1))\r\necho %targetchannel% | find /i \"2021 VL\" %nul% && (for %%A in (%_oIds%) do (echo %%A | find /i \"2021Volume\" %nul% || set abortchange=1))\r\necho %targetchannel% | find /i \"2024 VL\" %nul% && (for %%A in (%_oIds%) do (echo %%A | find /i \"2024Volume\" %nul% || set abortchange=1))\r\n\r\nif defined abortchange (\r\n%eline%\r\necho Mismatch found in installed Office products and target update channel. Aborting...\r\necho Non-perpetual Office products are not suppported with Perpetual VL update channels.\r\ngoto :oe_goback\r\n)\r\n\r\nif not defined build (\r\n%eline%\r\ncall :dk_color %Red% \"Failed to detect build number for the target FFN.\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto :oe_goback\r\n)\r\n\r\nset buildchk=0\r\nfor /f \"tokens=3 delims=.\" %%a in (\"%build%\") do set \"buildchk=%%a\"\r\n\r\ncall :oe_getlangs %_firstoId%\r\n\r\necho %targetchannel% | find /i \"2019 VL\" %nul% && (\r\nfor %%A in (en-gb es-mx fr-ca) do (\r\necho %_allLangs% | find /i \"%%A\" %nul% && (\r\n%eline%\r\necho [%%A] language is not supported on the Office 2019 Perpetual VL update channel. Aborting...\r\ngoto :oe_goback\r\n)\r\n)\r\n)\r\n\r\nset \"c2rcommand=\"%_c2rExe%\" platform=%_oArch% culture=%_lang% productstoadd=%_firstoId%.16_%_allLangs% cdnbaseurl.16=http://officecdn.microsoft.com/pr/%targetFFN% baseurl.16=http://officecdn.microsoft.com/pr/%targetFFN% version.16=%build% mediatype.16=CDN sourcetype.16=CDN deliverymechanism=%targetFFN% %_firstoId%.excludedapps.16=%_firstoIdExcludelist% flt.useteamsaddon=disabled flt.usebingaddononinstall=disabled flt.usebingaddononupdate=disabled\"\r\nset \"c2rclientupdate=!c2rcommand! scenario=CLIENTUPDATE\"\r\n\r\nif %clverchk% LSS %buildchk% (\r\necho:\r\ncall :dk_color %Blue% \"Do not terminate the operation before it completes...\"\r\necho:\r\necho Updating Office C2R client with the command below, please wait...\r\necho:\r\necho %c2rclientupdate%\r\n%c2rclientupdate%\r\nfor /l %%i in (1,1,30) do (if !clverchk! LSS %buildchk% (call :ch_getinfo&timeout /t 10 %nul%))\r\n)\r\n\r\nif %clverchk% LSS %buildchk% (\r\necho:\r\ncall :dk_color %Red% \"Failed to update Office C2R client. Aborting...\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto :oe_goback\r\n)\r\n\r\ncall :oe_cleanupreg\r\n\r\necho Running the below command to change update channel, please wait...\r\necho:\r\necho %c2rcommand%\r\n%c2rcommand%\r\nset errorcode=%errorlevel%\r\ntimeout /t 10 %nul%\r\n\r\necho:\r\nif %errorcode% EQU 0 (\r\ncall :dk_color %Gray% \"Now run the Office activation option from the main menu.\"\r\n) else (\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:oe_goback\r\n\r\ncall :oe_tempcleanup\r\n\r\necho:\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 goto :oemenu\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to go back...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to go back...\"\r\npause %nul1%\r\n)\r\ngoto :oemenu\r\n\r\n::========================================================================================================================================\r\n\r\n:oe_cleanupreg\r\n\r\n::  Cleanup Office update related registries, thanks to @abbodi1406\r\n::  https://techcommunity.microsoft.com/t5/office-365-blog/how-to-manage-office-365-proplus-channels-for-it-pros/ba-p/795813\r\n::  https://learn.microsoft.com/en-us/microsoft-365-apps/updates/change-update-channels#considerations-when-changing-channels\r\n\r\necho:\r\necho Cleaning Office update registry keys...\r\necho Adding new update channel to registry keys...\r\necho:\r\n\r\n%nul% reg add %o16c2r_reg%\\Configuration /v CDNBaseUrl /t REG_SZ /d \"https://officecdn.microsoft.com/pr/%targetFFN%\" /f\r\n%nul% reg add %o16c2r_reg%\\Configuration /v UpdateChannel /t REG_SZ /d \"https://officecdn.microsoft.com/pr/%targetFFN%\" /f\r\n%nul% reg add %o16c2r_reg%\\Configuration /v UpdateChannelChanged /t REG_SZ /d \"True\" /f\r\n%nul% reg delete %o16c2r_reg%\\Configuration /v UnmanagedUpdateURL /f\r\n%nul% reg delete %o16c2r_reg%\\Configuration /v UpdateUrl /f\r\n%nul% reg delete %o16c2r_reg%\\Configuration /v UpdatePath /f\r\n%nul% reg delete %o16c2r_reg%\\Configuration /v UpdateToVersion /f\r\n%nul% reg delete %o16c2r_reg%\\Updates /v UpdateToVersion /f\r\n%nul% reg delete HKLM\\SOFTWARE\\Policies\\Microsoft\\office\\16.0\\common\\officeupdate /f\r\n%nul% reg delete HKLM\\SOFTWARE\\Policies\\Microsoft\\office\\16.0\\common\\officeupdate /f /reg:32\r\n%nul% reg delete HKCU\\SOFTWARE\\Policies\\Microsoft\\office\\16.0\\common\\officeupdate /f\r\n%nul% reg delete HKLM\\SOFTWARE\\Policies\\Microsoft\\cloud\\office\\16.0\\Common\\officeupdate /f\r\n%nul% reg delete HKLM\\SOFTWARE\\Policies\\Microsoft\\cloud\\office\\16.0\\Common\\officeupdate /f /reg:32\r\n%nul% reg delete HKCU\\Software\\Policies\\Microsoft\\cloud\\office\\16.0\\Common\\officeupdate /f\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oe_tempcleanup\r\n\r\ndel /f /q %SystemRoot%\\Temp\\SingleApps_Volume.txt %nul%\r\ndel /f /q %SystemRoot%\\Temp\\SingleApps_Retail.txt %nul%\r\ndel /f /q %SystemRoot%\\Temp\\Suites_Volume.txt %nul%\r\ndel /f /q %SystemRoot%\\Temp\\Suites_Retail.txt %nul%\r\ndel /f /q %SystemRoot%\\Temp\\getAppIds.txt %nul%\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fetch required info\r\n\r\n:ch_getinfo\r\n\r\nset _oRoot=\r\nset _oArch=\r\nset _updch=\r\nset _oIds=\r\nset _firstoId=\r\nset _lang=\r\nset _cfolder=\r\nset _version=\r\nset _clversion=\r\nset _AudienceData=\r\nset _actconfig=\r\nset _c2rXml=\r\nset _c2rExe=\r\nset _c2rCexe=\r\nset _masterxml=\r\nset ltsc19=\r\nset ltsc21=\r\nset ltsc24=\r\nset ltscfound=\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ClientFolder\" %nul6%') do (set \"_cfolder=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v AudienceId\" %nul6%') do (set \"_updch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ClientCulture\" %nul6%') do (set \"_lang=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ClientVersionToReport\" %nul6%') do (set \"_clversion=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v AudienceData\" %nul6%') do (set \"_AudienceData=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\ProductReleaseIDs /v ActiveConfiguration\" %nul6%') do (set \"_actconfig=%%b\")\r\n\r\necho \"%o16c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=9) || (set _tok=8)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query \"%o16c2r_reg%\\ProductReleaseIDs\\%_actconfig%\" /f \".16\" /k %nul6% ^| findstr /i \"Retail Volume\"') do (\r\nif defined _oIds (set \"_oIds=!_oIds! %%a\") else (set \"_oIds=%%a\")\r\n)\r\nset _oIds=%_oIds:.16=%\r\nfor /f \"tokens=1\" %%A in (\"%_oIds%\") do set _firstoId=%%A\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v %_firstoId%.ExcludedApps\" %nul6%') do (set \"_firstoIdExcludelist=%%b\")\r\n\r\nset verchk=0\r\nset clverchk=0\r\nfor /f \"tokens=3 delims=.\" %%a in (\"%_version%\") do set \"verchk=%%a\"\r\nfor /f \"tokens=3 delims=.\" %%a in (\"%_clversion%\") do set \"clverchk=%%a\"\r\n\r\nif exist \"%_oRoot%\\Licenses16\\c2rpridslicensefiles_auto.xml\" set \"_c2rXml=%_oRoot%\\Licenses16\\c2rpridslicensefiles_auto.xml\"\r\n\r\nif exist \"%ProgramData%\\Microsoft\\ClickToRun\\ProductReleases\\%_actconfig%\\x-none.16\\MasterDescriptor.x-none.xml\" (\r\nset \"_masterxml=%ProgramData%\\Microsoft\\ClickToRun\\ProductReleases\\%_actconfig%\\x-none.16\\MasterDescriptor.x-none.xml\"\r\n)\r\n\r\nif exist \"%_cfolder%\\OfficeClickToRun.exe\" (\r\nset \"_c2rExe=%_cfolder%\\OfficeClickToRun.exe\"\r\n)\r\n\r\nif exist \"%_cfolder%\\OfficeC2RClient.exe\" (\r\nset \"_c2rCexe=%_cfolder%\\OfficeC2RClient.exe\"\r\n)\r\n\r\n::  Check LTSC version files\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\ProductReleaseIDs\\%_actconfig%\" /s %nul6%') do (\r\necho \"%%b\" %nul2% | findstr \"16.0.103 16.0.104 16.0.105\" %nul% && set ltsc19=LTSC\r\necho \"%%b\" %nul2% | findstr \"16.0.14332\" %nul% && set ltsc21=LTSC2021\r\necho \"%%b\" %nul2% | findstr \"16.0.17932\" %nul% && set ltsc24=LTSC2024\r\n)\r\n\r\nif not \"%ltsc19%%ltsc21%%ltsc24%\"==\"\" set ltscfound=1\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check all the installed languages\r\n\r\n:oe_getlangs\r\n\r\nif \"%1\"==\"\" (\r\nset langreg=culture\r\n) else (\r\nset langreg=%1.16\r\n)\r\n\r\nset _allLangs=\r\necho \"%o16c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=10) || (set _tok=9)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query \"%o16c2r_reg%\\ProductReleaseIDs\\%_actconfig%\\%langreg%\" /f \"-\" /k ^| findstr /i \"%langreg%\\\\.*-.*\"') do (\r\nif defined _allLangs (set \"_allLangs=!_allLangs!_%%a\") else (set \"_allLangs=%%a\")\r\n)\r\n\r\nset _allLangs=%_allLangs:.16=%\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Internet connection\r\n\r\n:oe_chkinternet\r\n\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif !errorlevel!==0 (set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%eline%\r\ncall :dk_color %Red% \"Internet is not connected.\"\r\ncall :dk_color %Blue% \"Internet is required for this operation.\"\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get available build number for a FFN\r\n\r\n:getbuild:\r\n$Tls12 = [Enum]::ToObject([System.Net.SecurityProtocolType], 3072)\r\n[System.Net.ServicePointManager]::SecurityProtocol = $Tls12\r\n\r\n$FFN = $env:targetFFN\r\n$windowsBuild = [System.Environment]::OSVersion.Version.Build\r\n\r\n$baseUrl = \"https://mrodevicemgr.officeapps.live.com/mrodevicemgrsvc/api/v2/C2RReleaseData?audienceFFN=$FFN\"\r\n$url = if ($windowsBuild -lt 9200) { \"$baseUrl&osver=Client|6.1\" } elseif ($windowsBuild -lt 10240) { \"$baseUrl&osver=Client|6.3\" } else { $baseUrl }\r\n\r\n$response = if ($windowsBuild -ge 9200) { irm -Uri $url -Method Get } else { (New-Object System.Net.WebClient).DownloadString($url) }\r\n\r\nif ($windowsBuild -lt 9200) {\r\n    if ($response -match '\"AvailableBuild\"\\s*:\\s*\"([^\"]+)\"') { Write-Host $matches[1] }\r\n} else {\r\n    Write-Host $response.AvailableBuild\r\n}\r\n:getbuild:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get available edition list from c2rpridslicensefiles_auto.xml\r\n::  and filter the list using MasterDescriptor.x-none.xml\r\n::  and exclude unsupported products on Windows 7/8/8.1\r\n\r\n:getlist:\r\n$xmlPath1 = $env:_c2rXml\r\n$xmlPath2 = $env:_masterxml\r\n$outputDir = $env:SystemRoot + \"\\Temp\\\"\r\n$buildNumber = [System.Environment]::OSVersion.Version.Build\r\n$excludedKeywords = @(\"2019\", \"2021\", \"2024\")\r\n$productReleaseIds = @()\r\n\r\nif (Test-Path $xmlPath1) {\r\n    $xml1 = New-Object -TypeName System.Xml.XmlDocument\r\n    $xml1.Load($xmlPath1)\r\n    foreach ($node in $xml1.SelectNodes(\"//ProductReleaseId\")) {\r\n        $id = $node.GetAttribute(\"id\")\r\n        $exclude = $false\r\n        if ($buildNumber -lt 10240) {\r\n            foreach ($keyword in $excludedKeywords) {\r\n                if ($id -match $keyword) { $exclude = $true; break }\r\n            }\r\n        }\r\n        if ($id -ne \"CommonLicenseFiles\" -and -not $exclude) { $productReleaseIds += $id }\r\n    }\r\n}\r\n\r\n$categories = @{\r\n    \"Suites_Retail\" = @(); \"Suites_Volume\" = @()\r\n    \"SingleApps_Retail\" = @(); \"SingleApps_Volume\" = @()\r\n}\r\n\r\nforeach ($id in $productReleaseIds) {\r\n    $category = if ($id -match \"Retail\") { \"Retail\" } else { \"Volume\" }\r\n    $categories[\"SingleApps_$category\"] += $id\r\n}\r\n\r\nif (Test-Path $xmlPath2) {\r\n    $xml2 = New-Object -TypeName System.Xml.XmlDocument\r\n    $xml2.Load($xmlPath2)\r\n    foreach ($sku in $xml2.SelectNodes(\"//SKU\")) {\r\n        $skuId = $sku.GetAttribute(\"ID\")\r\n        if ($productReleaseIds -contains $skuId) {\r\n            $appIds = $sku.SelectNodes(\"Apps/App\") | ForEach-Object { $_.GetAttribute(\"id\") }\r\n            if ($appIds -contains \"Excel\" -and $appIds -contains \"Word\") {\r\n                $category = if ($skuId -match \"Retail\") { \"Retail\" } else { \"Volume\" }\r\n                $categories[\"Suites_$category\"] += $skuId\r\n                $categories[\"SingleApps_$category\"] = $categories[\"SingleApps_$category\"] | Where-Object { $_ -ne $skuId }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\nforeach ($section in $categories.Keys) {\r\n    $filePath = Join-Path -Path $outputDir -ChildPath \"$section.txt\"\r\n    $ids = $categories[$section]\r\n    if ($ids.Count -gt 0) { $ids | Out-File -FilePath $filePath -Encoding ASCII }\r\n}\r\n:getlist:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get App list for a specific product ID using MasterDescriptor.x-none.xml\r\n\r\n:getappnames:\r\n$xmlPath = $env:_masterxml\r\n$targetSkuId = $env:targetedition\r\n$outputDir = $env:SystemRoot + \"\\Temp\\\"\r\n$outputFile = Join-Path -Path $outputDir -ChildPath \"getAppIds.txt\"\r\n$excludeIds = @(\"shared\", \"PowerPivot\", \"PowerView\", \"MondoOnly\", \"OSM\", \"OSMUX\", \"Groove\", \"DCF\")\r\n\r\n$xml = New-Object -TypeName System.Xml.XmlDocument\r\n$xml.Load($xmlPath)\r\n\r\n$appIdsList = @()\r\n$skuNodes = $xml.SelectNodes(\"//SKU[@ID='$targetSkuId']\")\r\n\r\nforeach ($skuNode in $skuNodes) {\r\n    foreach ($app in $skuNode.SelectNodes(\"Apps/App\")) {\r\n        $appId = $app.GetAttribute(\"id\")\r\n        if ($excludeIds -notcontains $appId) {\r\n            $appIdsList += $appId\r\n        }\r\n    }\r\n}\r\n\r\nif ($appIdsList.Count -gt 0) {\r\n    $appIdsList | Out-File -FilePath $outputFile -Encoding ASCII\r\n}\r\n:getappnames:\r\n\r\n::========================================================================================================================================\r\n::\r\n:: Leave empty line below\r\n"
  },
  {
    "path": "MAS/Separate-Files-Version/Activators/HWID_Activation.cmd",
    "content": "@set masver=3.10\r\n@echo off\r\n\r\n\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\n\r\n::  To activate, run the script with \"/HWID\" parameter or change 0 to 1 in below line\r\nset _act=0\r\n\r\n::  To disable changing edition if current edition doesn't support HWID activation, change the value to 1 from 0 or run the script with \"/HWID-NoEditionChange\" parameter\r\nset _NoEditionChange=0\r\n\r\n::  To run the script in debug mode, change 0 to \"/HWID\" in below line\r\nset \"_debug=0\"\r\n\r\n::  If value is changed in above lines or parameter is used then script will run in unattended mode\r\n\r\n\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\nset re1=\r\nset re2=\r\nset \"_cmdf=%~f0\"\r\nfor %%# in (%*) do (\r\nif /i \"%%#\"==\"re1\" set re1=1\r\nif /i \"%%#\"==\"re2\" set re2=1\r\nif /i \"%%#\"==\"-qedit\" (set re1=1&set re2=1)\r\n)\r\n\r\n:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows\r\n:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\Sysnative\\cmd.exe if not defined re1 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\Sysnative\\cmd.exe /c \"\"!_cmdf!\" %* re1\"\r\nexit /b\r\n)\r\n\r\n:: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\SysArm32\\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\SysArm32\\cmd.exe /c \"\"!_cmdf!\" %* re2\"\r\nexit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Debug code\r\n\r\nif \"%_debug%\" EQU \"0\" (\r\nset \"nul1=1>nul\"\r\nset \"nul2=2>nul\"\r\nset \"nul6=2^>nul\"\r\nset \"nul=>nul 2>&1\"\r\ngoto :_debug\r\n)\r\n\r\nset \"nul1=\"\r\nset \"nul2=\"\r\nset \"nul6=\"\r\nset \"nul=\"\r\n\r\n@echo on\r\n@prompt $G\r\n@call :_debug \"%_debug%\" >\"%~dp0_tmp.log\" 2>&1\r\n@cmd /u /c type \"%~dp0_tmp.log\">\"%~dp0_Debug.log\"\r\n@del \"%~dp0_tmp.log\"\r\n@echo off\r\n@exit /b\r\n\r\n:_debug\r\n\r\n::========================================================================================================================================\r\n\r\nset \"blank=\"\r\nset \"mas=ht%blank%tps%blank%://m%blank%ass%blank%grave.dev/\"\r\nset \"github=ht%blank%tps%blank%://github.com/m%blank%assgra%blank%vel/Micro%blank%soft-Acti%blank%vation-Scripts\"\r\nset \"selfgit=ht%blank%tps%blank%://git.acti%blank%vated.win/Micr%blank%osoft-Act%blank%ivation-Scripts\"\r\n\r\n::  Check if Null service is working, it's important for the batch script\r\n\r\nsc query Null | find /i \"RUNNING\"\r\nif %errorlevel% NEQ 0 (\r\necho:\r\necho Null service is not running, script may crash...\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%fix_service\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20\r\n)\r\ncls\r\n\r\n::  Check LF line ending\r\n\r\npushd \"%~dp0\"\r\n>nul findstr /v \"$\" \"%~nx0\" && (\r\necho:\r\necho Error - Script either has LF line ending issue or an empty line at the end of the script is missing.\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20 >nul\r\npopd\r\nexit /b\r\n)\r\npopd\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\ntitle  HWID Activation %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args set _args=%_args:re1=%\r\nif defined _args set _args=%_args:re2=%\r\nif defined _args (\r\nfor %%A in (%_args%) do (\r\nif /i \"%%A\"==\"/HWID\"                  set _act=1\r\nif /i \"%%A\"==\"/HWID-NoEditionChange\"  set _NoEditionChange=1\r\nif /i \"%%A\"==\"-el\"                    set _elev=1\r\n)\r\n)\r\n\r\nfor %%A in (%_act% %_NoEditionChange%) do (if \"%%A\"==\"1\" set _unattended=1)\r\n\r\n::========================================================================================================================================\r\n\r\ncall :dk_setvar\r\n\r\nif %winbuild% EQU 1 (\r\n%eline%\r\necho Failed to detect Windows build number.\r\necho:\r\nsetlocal EnableDelayedExpansion\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\nif exist \"%Systemdrive%\\Users\\WDAGUtilityAccount\" (\r\nsc query gcs | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Windows Sandbox detected; activation is not supported.\r\necho The script cannot run due to missing licensing components. Aborting...\r\necho:\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 10240 (\r\n%eline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho HWID Activation is only supported on Windows 10/11.\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu.\"\r\ngoto dk_done\r\n)\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" (\r\n%eline%\r\necho HWID Activation is not supported on Windows Server.\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu.\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix special character limitations in path name\r\n\r\nset \"_work=%~dp0\"\r\nif \"%_work:~-1%\"==\"\\\" set \"_work=%_work:~0,-1%\"\r\n\r\nset \"_batf=%~f0\"\r\nset \"_batp=%_batf:'=''%\"\r\n\r\nset _PSarg=\"\"\"%~f0\"\"\" -el %_args%\r\nset _PSarg=%_PSarg:'=''%\r\n\r\nset \"_ttemp=%userprofile%\\AppData\\Local\\Temp\"\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\necho \"!_batf!\" | find /i \"!_ttemp!\" %nul1% && (\r\nif /i not \"!_work!\"==\"!_ttemp!\" (\r\n%eline%\r\necho The script was launched from the temp folder.\r\necho You are most likely running the script directly from the archive file.\r\necho:\r\necho Extract the archive file and launch the script from the extracted folder.\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Elevate script as admin and pass arguments and preventing loop\r\n\r\n%nul1% fltmc || (\r\nif not defined _elev %psc% \"start cmd.exe -arg '/c \\\"!_PSarg!\\\"' -verb runas\" && exit /b\r\n%eline%\r\necho This script needs admin rights.\r\necho Right click on this script and select 'Run as administrator'.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check PowerShell\r\n\r\n::pstst $ExecutionContext.SessionState.LanguageMode :pstst\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"if ($PSVersionTable.PSEdition -ne 'Core') {$f=[System.IO.File]::ReadAllText('!_batp!') -split ':pstst';. ([scriptblock]::Create($f[1]))}\" %nul6%') do (set tstresult=%%a)\r\n\r\nif /i not \"%tstresult%\"==\"FullLanguage\" (\r\n%eline%\r\nfor /f \"delims=\" %%a in ('%psc% \"$ExecutionContext.SessionState.LanguageMode\" %nul6%') do (set tstresult2=%%a)\r\necho Test 1 - %tstresult%\r\necho Test 2 - !tstresult2!\r\necho:\r\n\r\nREM check LanguageMode\r\n\r\necho: !tstresult2! | findstr /i \"ConstrainedLanguage RestrictedLanguage NoLanguage\" %nul1% && (\r\necho FullLanguage mode not found in PowerShell. Aborting...\r\necho If you have applied restrictions on Powershell then undo those changes.\r\nset fixes=%fixes% %mas%fix_powershell\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_powershell\"\r\ngoto dk_done\r\n)\r\n\r\nREM check Powershell core version\r\n\r\ncmd /c \"%psc% \"$PSVersionTable.PSEdition\"\" | find /i \"Core\" %nul1% && (\r\necho Windows Powershell is needed for MAS but it seems to be replaced with Powershell core. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n\r\nREM check for Mal-ware that may cause issues with Powershell\r\n\r\nfor /r \"%ProgramFiles%\\\" %%f in (secureboot.exe) do if exist \"%%f\" (\r\necho \"%%f\"\r\necho Mal%blank%ware found, PowerShell is not working properly.\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\ngoto dk_done\r\n)\r\n\r\nREM check if .NET is working properly\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\ncmd /c \"%psc% \"\"try {[System.AppDomain]::CurrentDomain.GetAssemblies(); [System.Math]::Sqrt(144)} catch {Exit 3}\"\"\" %nul%\r\nif !errorlevel!==3 (\r\necho Windows Powershell failed to load .NET command. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nREM check antivirus and other errors\r\n\r\necho PowerShell is not working properly. Aborting...\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\necho:\r\necho Your antivirus software might be blocking the script.\r\necho:\r\nsc query sense | find /i \"RUNNING\" %nul% && (\r\necho Installed Antivirus - Microsoft Defender for Endpoint\r\n)\r\ncmd /c \"%psc% \"\"$av = Get-WmiObject -Namespace root\\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { $n += $i.displayName }; if ($n) { Write-Host ('Installed Antivirus - ' + ($n -join ', '))}\"\"\"\r\n)\r\n\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Disable QuickEdit and launch from conhost.exe to avoid Terminal app\r\n\r\nif %winbuild% GEQ 17763 (\r\nset terminal=1\r\n) else (\r\nset terminal=\r\n)\r\n\r\n::  Check if script is running in Terminal app\r\n\r\nif defined terminal (\r\nset lines=0\r\nfor /f \"skip=3 tokens=* delims=\" %%A in ('mode con') do if \"!lines!\"==\"0\" (\r\nfor %%B in (%%A) do set lines=%%B\r\n)\r\nif !lines! GEQ 100 set terminal=\r\n)\r\n\r\nif %_unattended%==1 goto :skipQE\r\nfor %%# in (%_args%) do (if /i \"%%#\"==\"-qedit\" goto :skipQE)\r\n\r\n::  Relaunch to disable QuickEdit in the current session and use conhost.exe instead of the Terminal app\r\n::  This code disables QuickEdit for the current cmd.exe session without making permanent registry changes\r\n::  It is included because clicking on the script window can pause execution, causing confusion that the script has stopped due to an error\r\n\r\nset resetQE=1\r\nreg query HKCU\\Console /v QuickEdit %nul2% | find /i \"0x0\" %nul1% && set resetQE=0\r\nreg add HKCU\\Console /v QuickEdit /t REG_DWORD /d 0 /f %nul1%\r\n\r\nif defined terminal (\r\nstart conhost.exe \"!_batf!\" %_args% -qedit\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n) else if %resetQE% EQU 1 (\r\nstart cmd.exe /c \"\"!_batf!\" %_args% -qedit\"\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n)\r\n\r\n:skipQE\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check for updates\r\n\r\nset -=\r\nset old=\r\nset pingp=\r\nset upver=%masver:.=%\r\n\r\nfor %%A in (\r\nactiv%-%ated.win\r\nmass%-%grave.dev\r\n) do if not defined pingp (\r\nfor /f \"delims=[] tokens=2\" %%B in ('ping -n 1 %%A') do (\r\nif not \"%%B\"==\"\" (set old=1& set pingp=1)\r\nfor /f \"delims=[] tokens=2\" %%C in ('ping -n 1 updatecheck%upver%.%%A') do (\r\nif not \"%%C\"==\"\" set old=\r\n)\r\n)\r\n)\r\n\r\nif defined old (\r\necho ________________________________________________\r\n%eline%\r\necho Your version of MAS [%masver%] is outdated.\r\necho ________________________________________________\r\necho:\r\nif not %_unattended%==1 (\r\necho [1] Get Latest MAS\r\necho [0] Continue Anyway\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 rem\r\nif !errorlevel!==1 (start %selfgit% & start %github% & start %mas% & exit /b)\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\nif not defined terminal (\r\nmode 110, 34\r\nif exist \"%SysPath%\\spp\\store_test\\\" mode 134, 34\r\n)\r\ntitle  HWID Activation %masver%\r\n\r\necho:\r\necho Initializing...\r\ncall :dk_chkmal\r\n\r\nfor %%# in (\r\nsppsvc.exe\r\nClipUp.exe\r\n) do (\r\nif not exist %SysPath%\\%%# (\r\n%eline%\r\necho [%SysPath%\\%%#] file is missing, aborting...\r\necho:\r\nif not defined results (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options.\"\r\ncall :dk_color %Blue% \"After that, restart system and try activation again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If it still shows the same error, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_ckeckwmic\r\ncall :dk_checksku\r\ncall :dk_product\r\ncall :dk_sppissue\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check if system is permanently activated or not\r\n\r\ncall :dk_checkperm\r\nif defined _perm (\r\ncls\r\necho ___________________________________________________________________________________________\r\necho:\r\ncall :dk_color2 %_White% \"     \" %Green% \"%winos% is already permanently activated.\"\r\necho ___________________________________________________________________________________________\r\nif %_unattended%==1 goto dk_done\r\necho:\r\nchoice /C:10 /N /M \">    [1] Activate Anyway [0] %_exitmsg% : \"\r\nif errorlevel 2 exit /b\r\n)\r\ncls\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Evaluation version\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Eval\" %nul1% && (\r\n%eline%\r\necho [%winos% ^| %winbuild%]\r\necho:\r\necho Evaluation editions cannot be activated outside of their evaluation period.\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu to reset evaluation period.\"\r\nset fixes=%fixes% %mas%evaluation_editions\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%evaluation_editions\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset error=\r\n\r\ncls\r\necho:\r\ncall :dk_showosinfo\r\n\r\n::  Check Internet connection\r\n\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)\r\n)\r\n\r\nif defined _int (\r\necho Checking Internet Connection            [Connected%ping_f%]\r\n) else (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Internet Connection            [Not Connected]\"\r\ncall :dk_color %Blue% \"Internet is required for HWID activation.\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\necho Initiating Diagnostic Tests...\r\n\r\nset \"_serv=ClipSVC wlidsvc sppsvc KeyIso LicenseManager Winmgmt\"\r\n\r\n::  Client License Service (ClipSVC)\r\n::  Microsoft Account Sign-in Assistant\r\n::  Software Protection\r\n::  CNG Key Isolation\r\n::  Windows License Manager Service\r\n::  Windows Management Instrumentation\r\n\r\ncall :dk_errorcheck\r\n\r\n::========================================================================================================================================\r\n\r\n::  Detect Key\r\n\r\nset key=\r\nset altkey=\r\nset changekey=\r\nset altapplist=\r\nset altedition=\r\nset notworking=\r\n\r\ncall :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\nif defined allapps call :hwiddata key\r\nif not defined key (\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getactivationid\\:.*';. ([scriptblock]::Create($f[1]))\"') do (set altapplist=%%a)\r\nif defined altapplist call :hwiddata key\r\n)\r\n\r\nif defined notworking call :hwidfallback\r\nif not defined key call :hwidfallback\r\n\r\nif defined altkey (set key=%altkey%&set changekey=1&set notworking=)\r\n\r\nif defined notworking if defined notfoundaltactID (\r\ncall :dk_color %Red% \"Checking Alternate Edition For HWID     [%altedition% Activation ID Not Found]\"\r\n)\r\n\r\nif not defined key (\r\n%eline%\r\necho [%winos% ^| %winbuild% ^| SKU:%osSKU%]\r\nif not defined skunotfound (\r\necho This product does not support HWID activation.\r\necho Make sure you are using the latest version of the script.\r\necho If you are, then try TSforge activation option from the main menu.\r\nset fixes=%fixes% %mas%\r\necho %mas%\r\n) else (\r\necho Required license files not found in %SysPath%\\spp\\tokens\\skus\\\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\necho:\r\ngoto dk_done\r\n)\r\n\r\nif defined notworking set error=1\r\n\r\n::========================================================================================================================================\r\n\r\n::  Install key\r\n\r\necho:\r\nif defined changekey (\r\ncall :dk_color %Blue% \"[%altedition%] edition product key will be used to enable HWID activation.\"\r\necho:\r\n)\r\n\r\nif defined winsub (\r\ncall :dk_color %Blue% \"Windows Subscription [SKU ID-%slcSKU%] detected. Script will activate base edition [SKU ID-%regSKU%].\"\r\necho:\r\n)\r\n\r\nset generickey=1\r\ncall :dk_inskey \"[%key%]\"\r\n\r\n::========================================================================================================================================\r\n\r\n::  Change Windows region to USA to avoid activation issues as Windows store license is not available in many countries \r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKCU\\Control Panel\\International\\Geo\" /v Name %nul6%') do set \"name=%%b\"\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKCU\\Control Panel\\International\\Geo\" /v Nation %nul6%') do set \"nation=%%b\"\r\n\r\n::  Skip changing region in top countries\r\n\r\nset regionchange=1\r\nfor %%# in (US CN IN BR DE JP GB FR MX ID IT PK TR KR CA ES AU NG VN PL PH NL EG AR TH CO SA TW MY CL) do if /i \"%name%\"==\"%%#\" set regionchange=\r\n\r\nif defined regionchange (\r\n%psc% \"Set-WinHomeLocation -GeoId 244\" %nul%\r\nif !errorlevel! EQU 0 (\r\necho Changing Windows Region To USA          [Successful] [Script will change it back]\r\n) else (\r\ncall :dk_color %Red% \"Changing Windows Region To USA          [Failed]\"\r\n)\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\n::  Generate GenuineTicket.xml and apply\r\n::  In some cases clipup -v -o method fails and in some cases service restart method fails as well\r\n::  To maximize success rate and get better error details, script will install tickets two times (service restart + clipup -v -o)\r\n\r\nset \"tdir=%ProgramData%\\Microsoft\\Windows\\ClipSVC\\GenuineTicket\"\r\nif not exist \"%tdir%\\\" md \"%tdir%\\\" %nul%\r\n\r\nif exist \"%tdir%\\Genuine*\" del /f /q \"%tdir%\\Genuine*\" %nul%\r\nif exist \"%tdir%\\*.xml\" del /f /q \"%tdir%\\*.xml\" %nul%\r\nif exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\Install\\Migration\\*\" del /f /q \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\Install\\Migration\\*\" %nul%\r\n\r\ncall :hwiddata ticket\r\n\r\ncopy /y /b \"%tdir%\\GenuineTicket\" \"%tdir%\\GenuineTicket.xml\" %nul%\r\n\r\nif not exist \"%tdir%\\GenuineTicket.xml\" (\r\ncall :dk_color %Red% \"Generating GenuineTicket.xml            [Failed, aborting...]\"\r\necho [%encoded%]\r\nif exist \"%tdir%\\Genuine*\" del /f /q \"%tdir%\\Genuine*\" %nul%\r\ngoto :dl_final\r\n) else (\r\necho Generating GenuineTicket.xml            [Successful]\r\n)\r\n\r\nset \"_xmlexist=if exist \"%tdir%\\GenuineTicket.xml\"\"\r\n\r\n%_xmlexist% (\r\n%psc% \"Start-Job { Restart-Service ClipSVC } | Wait-Job -Timeout 20 | Out-Null\"\r\n%_xmlexist% timeout /t 2 %nul%\r\n%_xmlexist% timeout /t 2 %nul%\r\n\r\n%_xmlexist% (\r\nset error=1\r\nif exist \"%tdir%\\*.xml\" del /f /q \"%tdir%\\*.xml\" %nul%\r\ncall :dk_color %Gray% \"Installing GenuineTicket.xml            [Failed with ClipSVC service restart, wait...]\"\r\n)\r\n)\r\n\r\ncopy /y /b \"%tdir%\\GenuineTicket\" \"%tdir%\\GenuineTicket.xml\" %nul%\r\nclipup -v -o\r\n\r\nset rebuildinfo=\r\n\r\nif not exist %ProgramData%\\Microsoft\\Windows\\ClipSVC\\tokens.dat (\r\nset error=1\r\nset rebuildinfo=1\r\ncall :dk_color %Red% \"Checking ClipSVC tokens.dat             [Not Found]\"\r\n)\r\n\r\n%_xmlexist% (\r\nset error=1\r\nset rebuildinfo=1\r\ncall :dk_color %Red% \"Installing GenuineTicket.xml            [Failed With clipup -v -o]\"\r\n)\r\n\r\nif exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\Install\\Migration\\*.xml\" (\r\nset error=1\r\nset rebuildinfo=1\r\ncall :dk_color %Red% \"Checking Ticket Migration               [Failed]\"\r\n)\r\n\r\nif not defined altapplist if not defined showfix if defined rebuildinfo (\r\nset showfix=1\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\n\r\nif exist \"%tdir%\\Genuine*\" del /f /q \"%tdir%\\Genuine*\" %nul%\r\n\r\n::==========================================================================================================================================\r\n\r\ncall :dk_product\r\n\r\necho:\r\necho Activating...\r\n\r\ncall :dk_act\r\ncall :dk_checkperm\r\nif defined _perm (\r\necho:\r\ncall :dk_color %Green% \"%winos% is permanently activated with a digital license.\"\r\ngoto :dl_final\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\n::  Clear store ID related registry to fix activation if Internet is connected\r\n\r\nset \"_ident=HKU\\S-1-5-19\\SOFTWARE\\Microsoft\\IdentityCRL\"\r\n\r\nif %keyerror% EQU 0 if defined _int (\r\nreg delete \"%_ident%\" /f %nul%\r\nfor %%# in (wlidsvc LicenseManager sppsvc) do (%psc% \"Start-Job { Restart-Service %%# } | Wait-Job -Timeout 20 | Out-Null\")\r\ncall :dk_refresh\r\ncall :dk_act\r\ncall :dk_checkperm\r\n\r\nreg query \"%_ident%\" %nul% || (\r\nset error=1\r\necho:\r\ncall :dk_color %Red% \"Generating New IdentityCRL Registry     [Failed] [%_ident%]\"\r\n)\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\n::  Extended licensing servers tests incase error not found and activation failed\r\n\r\nif %keyerror% EQU 0 if not defined _perm if defined _int (\r\nipconfig /flushdns %nul%\r\nset \"tls=[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;\"\r\n\r\nfor %%# in (\r\nlicensing.mp.microsoft.com/v7.0/licenses/content\r\nlogin.live.com/ppsecure/deviceaddcredential.srf\r\npurchase.mp.microsoft.com/v7.0/users/me/orders\r\n) do if not defined resfail (\r\n%psc% \"try { !tls! irm https://%%# -Method POST } catch { if ($_.Exception.Response -eq $null) { Write-Host \"\"\"\"[%%#] $($_.Exception.Message)\"\"\"\" -ForegroundColor Red -BackgroundColor Black; exit 3 } }\"\r\nif !errorlevel!==3 set resfail=1\r\n)\r\n)\r\n\r\nif defined resfail (\r\nset error=1\r\nfor %%# in (\r\nlive.com\r\nmicrosoft.com\r\nlogin.live.com\r\npurchase.mp.microsoft.com\r\nlicensing.mp.microsoft.com\r\n) do (\r\nfindstr /i \"%%#\" \"%SysPath%\\drivers\\etc\\hosts\" %nul1% && set \"hosfail= [%%# Blocked in Hosts]\"\r\n)\r\ncall :dk_color %Red% \"Checking Licensing Servers              [Failed to Connect]!hosfail!\"\r\nset fixes=%fixes% %mas%licensing-servers-issue\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%licensing-servers-issue\"\r\necho:\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\n::  Windows update and store block check\r\n\r\nif %keyerror% EQU 0 if not defined _perm if defined _int (\r\n\r\nreg query \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\" /v DisableWindowsUpdateAccess %nul2% | find /i \"0x1\" %nul% && set wublock=1\r\nreg query \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\" /v DoNotConnectToWindowsUpdateInternetLocations %nul2% | find /i \"0x1\" %nul% && set wublock=1\r\nif defined wublock (\r\ncall :dk_color %Red% \"Checking Update Blocker In Registry     [Found]\"\r\ncall :dk_color %Blue% \"HWID activation needs working Windows updates, if you have used any tool to block updates, undo it.\"\r\necho:\r\n)\r\n\r\nreg query \"HKLM\\SOFTWARE\\Policies\\Microsoft\\WindowsStore\" /v DisableStoreApps %nul2% | find /i \"0x1\" %nul% && (\r\nset storeblock=1\r\ncall :dk_color %Red% \"Checking Store Blocker In Registry      [Found]\"\r\ncall :dk_color %Blue% \"If you have used any tool to block Store, undo it.\"\r\necho:\r\n)\r\n\r\nset wcount=0\r\nfor %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type ServiceSidType RequiredPrivileges FailureActions) do (\r\nreg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\wuauserv /v %%G %nul% || (set wucorrupt=1&set /a wcount+=1)\r\n)\r\n\r\nfor %%G in (Parameters Security) do (\r\nreg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\wuauserv\\%%G %nul% || (set wucorrupt=1&set /a wcount+=1)\r\n)\r\n\r\nif defined wucorrupt (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Windows Update Registry        [Corruption Found]\"\r\nif !wcount! GTR 2 (\r\ncall :dk_color %Red% \"Windows seems to be infected with Mal%w%ware.\"\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\necho:\r\n) else (\r\ncall :dk_color %Blue% \"HWID activation needs working Windows updates, if you have used any tool to block updates, undo it.\"\r\necho:\r\n)\r\n) else (\r\n%psc% \"Start-Job { Start-Service wuauserv } | Wait-Job -Timeout 20 | Out-Null\"\r\nsc query wuauserv | find /i \"RUNNING\" %nul% || (\r\nset error=1\r\nset wuerror=1\r\nsc start wuauserv %nul%\r\ncall :dk_color %Red% \"Starting Windows Update Service         [Failed] [!errorlevel!]\"\r\ncall :dk_color %Blue% \"HWID activation needs working Windows updates, if you have used any tool to block updates, undo it.\"\r\necho:\r\n)\r\n)\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\n::  Check Internet related error codes\r\n\r\nif %keyerror% EQU 0 if not defined _perm if defined _int (\r\nif not defined wucorrupt if not defined wublock if not defined wuerror if not defined storeblock if not defined resfail (\r\necho \"%error_code%\" | findstr /i \"0x80072e 0x80072f 0x800704cf 0x87e10bcf 0x800705b4\" %nul% && (\r\ncall :dk_color %Red% \"Checking Internet Issues                [Found] %error_code%\"\r\nset fixes=%fixes% %mas%licensing-servers-issue\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%licensing-servers-issue\"\r\necho:\r\n)\r\n)\r\n)\r\n\r\n::==========================================================================================================================================\r\n\r\necho:\r\nif defined _perm (\r\ncall :dk_color %Green% \"%winos% is permanently activated with a digital license.\"\r\n) else (\r\ncall :dk_color %Red% \"Activation Failed %error_code%\"\r\nif defined notworking (\r\ncall :dk_color %Blue% \"At the time of writing, HWID Activation is not supported for this product.\"\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu instead.\"\r\n) else (\r\nif not defined error call :dk_color %Blue% \"%_fixmsg%\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:dl_final\r\n\r\necho:\r\n\r\nif defined regionchange (\r\n%psc% \"Set-WinHomeLocation -GeoId %nation%\" %nul%\r\nif !errorlevel! EQU 0 (\r\necho Restoring Windows Region                [Successful]\r\n) else (\r\ncall :dk_color %Red% \"Restoring Windows Region                [Failed] [%name% - %nation%]\"\r\n)\r\n)\r\n\r\nREM if %osSKU%==175 call :dk_color %Red% \"%winos% does not support activation on non-azure platforms.\"\r\n\r\n::  Trigger reevaluation of SPP's Scheduled Tasks\r\n\r\nif defined _perm (\r\ncall :dk_reeval %nul%\r\n)\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set variables\r\n\r\n:dk_setvar\r\n\r\nset ps=%SysPath%\\WindowsPowerShell\\v1.0\\powershell.exe\r\nset psc=%ps% -nop -c\r\nset winbuild=1\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset _NCS=1\r\nif %winbuild% LSS 10586 set _NCS=0\r\nif %winbuild% GEQ 10586 reg query \"HKCU\\Console\" /v ForceV2 %nul2% | find /i \"0x0\" %nul1% && (set _NCS=0)\r\n\r\necho \"%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%\" | find /i \"ARM64\" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)\r\n\r\nif %_NCS% EQU 1 (\r\nfor /F %%a in ('echo prompt $E ^| cmd') do set \"esc=%%a\"\r\nset     \"Red=\"41;97m\"\"\r\nset    \"Gray=\"100;97m\"\"\r\nset   \"Green=\"42;97m\"\"\r\nset    \"Blue=\"44;97m\"\"\r\nset   \"White=\"107;91m\"\"\r\nset    \"_Red=\"40;91m\"\"\r\nset  \"_White=\"40;37m\"\"\r\nset  \"_Green=\"40;92m\"\"\r\nset \"_Yellow=\"40;93m\"\"\r\n) else (\r\nset     \"Red=\"Red\" \"white\"\"\r\nset    \"Gray=\"Darkgray\" \"white\"\"\r\nset   \"Green=\"DarkGreen\" \"white\"\"\r\nset    \"Blue=\"Blue\" \"white\"\"\r\nset   \"White=\"White\" \"Red\"\"\r\nset    \"_Red=\"Black\" \"Red\"\"\r\nset  \"_White=\"Black\" \"Gray\"\"\r\nset  \"_Green=\"Black\" \"Green\"\"\r\nset \"_Yellow=\"Black\" \"Yellow\"\"\r\n)\r\n\r\nset \"nceline=echo: &echo ==== ERROR ==== &echo:\"\r\nset \"eline=echo: &call :dk_color %Red% \"==== ERROR ====\" &echo:\"\r\nif %~z0 GEQ 200000 (\r\nset \"_exitmsg=Go back\"\r\nset \"_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option.\"\r\n) else (\r\nset \"_exitmsg=Exit\"\r\nset \"_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option.\"\r\n)\r\nexit /b\r\n\r\n::  Show OS info\r\n\r\n:dk_showosinfo\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\" /v PROCESSOR_ARCHITECTURE') do set osarch=%%b\r\n\r\nfor /f \"tokens=6-7 delims=[]. \" %%i in ('ver') do if not \"%%j\"==\"\" (\r\nset fullbuild=%%i.%%j\r\n) else (\r\nfor /f \"tokens=3\" %%G in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR\" %nul6%') do if not errorlevel 1 set /a \"UBR=%%G\"\r\nfor /f \"skip=2 tokens=3,4 delims=. \" %%G in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildLabEx') do (\r\nif defined UBR (set \"fullbuild=%%G.!UBR!\") else (set \"fullbuild=%%G.%%H\")\r\n)\r\n)\r\n\r\necho Checking OS Info                        [%winos% ^| %fullbuild% ^| %osarch%]\r\nexit /b\r\n\r\n::  Check SKU value\r\n\r\n:dk_checksku\r\n\r\ncall :dk_reflection\r\n\r\nset osSKU=\r\nset slcSKU=\r\nset wmiSKU=\r\nset regSKU=\r\nset winsub=\r\n\r\nif %winbuild% GEQ 14393 (set info=Kernel-BrandingInfo) else (set info=Kernel-ProductInfo)\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3);\r\nset d1=%d1% $Sku = 0; [void]$TypeBuilder.CreateType()::SLGetWindowsInformationDWORD('%info%', [ref]$Sku); $Sku\r\nfor /f \"delims=\" %%s in ('\"%psc% %d1%\"') do if not errorlevel 1 (set slcSKU=%%s)\r\nset slcSKU=%slcSKU: =%\r\nif \"%slcSKU%\"==\"0\" set slcSKU=\r\nfor /f \"tokens=* delims=0123456789\" %%a in (\"%slcSKU%\") do (if not \"[%%a]\"==\"[]\" set slcSKU=)\r\n\r\nfor /f \"tokens=3 delims=.\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions\" /v OSProductPfn %nul6%') do set \"regSKU=%%a\"\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%a in ('\"wmic Path Win32_OperatingSystem Get OperatingSystemSKU /format:LIST\" %nul6%') do if not errorlevel 1 set \"wmiSKU=%%a\"\r\nif %_wmic% EQU 0 for /f \"tokens=1\" %%a in ('%psc% \"([WMI]'Win32_OperatingSystem=@').OperatingSystemSKU\" %nul6%') do if not errorlevel 1 set \"wmiSKU=%%a\"\r\n\r\nif %winbuild% GEQ 15063 %psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':winsubstatus\\:.*';. ([scriptblock]::Create($f[1]))\" %nul2% | find /i \"Subscription_is_activated\" %nul% && (\r\nif defined regSKU if defined slcSKU if not \"%regSKU%\"==\"%slcSKU%\" (\r\nset winsub=1\r\nset osSKU=%regSKU%\r\n)\r\n)\r\n\r\nif not defined osSKU set osSKU=%slcSKU%\r\nif not defined osSKU set osSKU=%wmiSKU%\r\nif not defined osSKU set osSKU=%regSKU%\r\nexit /b\r\n\r\n::  Get Windows Subscription status\r\n\r\n:winsubstatus:\r\n$DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(6, 1).DefineDynamicModule(4).DefineType(2)\r\n[void]$DM.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n$m = [System.Runtime.InteropServices.Marshal]\r\n$p = $m::AllocHGlobal(12)\r\n$r = $DM.CreateType()::ClipGetSubscriptionStatus([ref]$p)\r\nif ($r -eq 0) {\r\n  $enabled = $m::ReadInt32($p)\r\n  if ($enabled -ge 1) {\r\n    $state = $m::ReadInt32($p, 8)\r\n    if ($state -eq 1) {\r\n        \"Subscription_is_activated.\"\r\n    }\r\n  }\r\n}\r\n:winsubstatus:\r\n\r\n::  Get Windows permanent activation status\r\n\r\n:dk_checkperm\r\n\r\nif %_wmic% EQU 1 wmic path %spp% where (LicenseStatus='1' and GracePeriodRemaining='0' and PartialProductKey is not NULL AND LicenseDependsOn is NULL) get Name /value %nul2% | findstr /i \"Windows\" %nul1% && set _perm=1||set _perm=\r\nif %_wmic% EQU 0 %psc% \"(([WMISEARCHER]'SELECT Name FROM %spp% WHERE LicenseStatus=1 AND GracePeriodRemaining=0 AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Name | %% {echo ('Name='+$_)}\" %nul2% | findstr /i \"Windows\" %nul1% && set _perm=1||set _perm=\r\nexit /b\r\n\r\n::  Refresh license status\r\n\r\n:dk_refresh\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call RefreshLicenseStatus %nul%\r\nif %_wmic% EQU 0 %psc% \"$null=(([WMICLASS]'%sps%').GetInstances()).RefreshLicenseStatus()\" %nul%\r\nexit /b\r\n\r\n::  Install Key\r\n\r\n:dk_inskey\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey=\"%key%\" %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset keyerror=%errorlevel%\r\ncmd /c exit /b %keyerror%\r\nif %keyerror% NEQ 0 set \"keyerror=[0x%=ExitCode%]\"\r\n\r\nif defined generickey (set \"keyecho=Installing Generic Product Key         \") else (set \"keyecho=Installing Product Key                 \")\r\nif %keyerror% EQU 0 (\r\nif %sps%==SoftwareLicensingService call :dk_refresh\r\necho %keyecho% %~1 [Successful]\r\n) else (\r\ncall :dk_color %Red% \"%keyecho% %~1 [Failed] %keyerror%\"\r\nif not defined showfix (\r\nif defined altapplist call :dk_color %Red% \"Activation ID not found for this key.\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\nset showfix=1\r\n)\r\nset error=1\r\n)\r\n\r\nset generickey=\r\nexit /b\r\n\r\n::  Activation command\r\n\r\n:dk_act\r\n\r\nset error_code=\r\nif %_wmic% EQU 1 wmic path %spp% where \"ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL\" call Activate %nul%\r\nif %_wmic% EQU 0 %psc% \"try {$null=(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Activate(); exit 0} catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset error_code=%errorlevel%\r\ncmd /c exit /b %error_code%\r\nif %error_code% NEQ 0 (set \"error_code=[Error Code: 0x%=ExitCode%]\") else (set error_code=)\r\nexit /b\r\n\r\n::  Get all products Activation IDs\r\n\r\n:dk_actids\r\n\r\nset allapps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1') get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1''').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined allapps (call set \"allapps=!allapps! %%a\") else (call set \"allapps=%%a\"))\r\nexit /b\r\n\r\n::  Get installed products Activation IDs\r\n\r\n:dk_actid\r\n\r\nset apps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1' and PartialProductKey is not null) get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1'' AND PartialProductKey IS NOT NULL').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined apps (call set \"apps=!apps! %%a\") else (call set \"apps=%%a\"))\r\nexit /b\r\n\r\n::  Trigger reevaluation, it helps in updating SPP tasks\r\n\r\n:dk_reeval\r\n\r\nif %winbuild% LSS 7600 exit /b\r\n\r\n::  This key is left by the system in rearm process and sppsvc sometimes fails to delete it, it causes issues in working of the Scheduled Tasks of SPP\r\n\r\nset \"ruleskey=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\PersistedSystemState\"\r\nreg delete \"%ruleskey%\" /v \"State\" /f %nul%\r\nreg delete \"%ruleskey%\" /v \"SuppressRulesEngine\" /f %nul%\r\n\r\nset r1=$TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);\r\nset r2=%r1% [void]$TB.DefinePInvokeMethod('SLpTriggerServiceWorker', 'sppc.dll', 22, 1, [Int32], @([UInt32], [IntPtr], [String], [UInt32]), 1, 3);\r\nset d1=%r2% [void]$TB.CreateType()::SLpTriggerServiceWorker(0, 0, 'reeval', 0)\r\n%psc% \"Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null; %d1%\"\r\nexit /b\r\n\r\n::  Get Activation IDs from licensing files if not found through WMI\r\n\r\n:getactivationid:\r\n$folderPath = \"$env:SysPath\\spp\\tokens\\skus\"\r\n$files = Get-ChildItem -Path $folderPath -Recurse -Filter \"*.xrm-ms\"\r\n$guids = @()\r\nforeach ($file in $files) {\r\n    $content = Get-Content -Path $file.FullName -Raw\r\n    $matches = [regex]::Matches($content, 'name=\"productSkuId\">\\{([0-9a-fA-F\\-]+)\\}')\r\n    foreach ($match in $matches) {\r\n        $guids += $match.Groups[1].Value\r\n    }\r\n}\r\n$guids = $guids | Select-Object -Unique\r\n$guidsString = $guids -join \" \"\r\n$guidsString\r\n:getactivationid:\r\n\r\n::  Install License files using Powershell/WMI instead of slmgr.vbs\r\n\r\n:xrm:\r\nfunction InstallLicenseFile($Lsc) {\r\n    try {\r\n        $null = $sls.InstallLicense([IO.File]::ReadAllText($Lsc))\r\n    } catch {\r\n        $host.SetShouldExit($_.Exception.HResult)\r\n    }\r\n}\r\nfunction InstallLicenseArr($Str) {\r\n    $a = $Str -split ';'\r\n    ForEach ($x in $a) {InstallLicenseFile \"$x\"}\r\n}\r\nfunction InstallLicenseDir($Loc) {\r\n\tGet-ChildItem $Loc -Recurse -Filter *.xrm-ms | ForEach-Object {InstallLicenseFile $_.FullName}\r\n}\r\nfunction ReinstallLicenses() {\r\n\t$Paths = @(\"$env:SysPath\\oem\", \"$env:SysPath\\licensing\", \"$env:SysPath\\spp\\tokens\")\r\n\tforeach ($Path in $Paths) {\r\n    if (Test-Path $Path) { InstallLicenseDir \"$Path\" }\r\n\t}\r\n}\r\n:xrm:\r\n\r\n::  Check wmic.exe\r\n\r\n:dk_ckeckwmic\r\n\r\nif %winbuild% LSS 9200 (set _wmic=1&exit /b)\r\nset _wmic=0\r\nfor %%# in (wmic.exe) do @if not \"%%~$PATH:#\"==\"\" (\r\ncmd /c \"wmic path Win32_ComputerSystem get CreationClassName /value\" %nul2% | find /i \"computersystem\" %nul1% && set _wmic=1\r\n)\r\nexit /b\r\n\r\n::  Show info for potential script stuck scenario\r\n\r\n:dk_sppissue\r\n\r\nsc start %_slser% %nul%\r\nset spperror=%errorlevel%\r\n\r\nif %spperror% NEQ 1056 if %spperror% NEQ 0 (\r\n%eline%\r\necho sc start %_slser% [Error Code: %spperror%]\r\nif %spperror% EQU 1053 (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\ncall :dk_color %Blue% \"If it still does not work, go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\n)\r\n)\r\n\r\necho:\r\n%psc% \"$job = Start-Job { (Get-WmiObject -Query 'SELECT * FROM %sps%').Version }; if (-not (Wait-Job $job -Timeout 30)) {write-host '%_slser% is not working correctly. Check this webpage for help - %mas%troubleshoot'}\"\r\nexit /b\r\n\r\n::  Get Product name (WMI/REG methods are not reliable in all conditions, hence winbrand.dll method is used)\r\n\r\n:dk_product\r\n\r\nset d1=%ref% $meth = $TypeBuilder.DefinePInvokeMethod('BrandingFormatString', 'winbrand.dll', 'Public, Static', 1, [String], @([String]), 1, 3);\r\nset d1=%d1% $meth.SetImplementationFlags(128); $TypeBuilder.CreateType()::BrandingFormatString('%%WINDOWS_LONG%%') -replace [string][char]0xa9, '' -replace [string][char]0xae, '' -replace [string][char]0x2122, ''\r\n\r\nset winos=\r\nfor /f \"delims=\" %%s in ('\"%psc% %d1%\"') do if not errorlevel 1 (set winos=%%s)\r\necho \"%winos%\" | find /i \"Windows\" %nul1% || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v ProductName %nul6%') do set \"winos=%%b\"\r\nif %winbuild% GEQ 22000 (\r\nset winos=!winos:Windows 10=Windows 11!\r\n)\r\n)\r\n\r\nif not defined winsub exit /b\r\n\r\n::  Check base edition product name if Windows subscription license is found\r\n\r\nfor %%# in (pkeyhelper.dll) do @if \"%%~$PATH:#\"==\"\" exit /b\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionNameFromId', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [IntPtr].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionNameFromId(%regSKU%, [ref]$out);$s=[Runtime.InteropServices.Marshal]::PtrToStringUni($out); $s\r\n\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (\r\nif %winbuild% GEQ 22000 (\r\nset winos=Windows 11 %%a\r\n) else (\r\nset winos=Windows 10 %%a\r\n)\r\n)\r\nexit /b\r\n\r\n::  Common lines used in PowerShell reflection code\r\n\r\n:dk_reflection\r\n\r\nset ref=$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1);\r\nset ref=%ref% $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False);\r\nset ref=%ref% $TypeBuilder = $ModuleBuilder.DefineType(0);\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_chkmal\r\n\r\n::  Many users unknowingly download mal-ware by using activators found through Google search.\r\n::  This code aims to notify users that their system has been affected by mal-ware.\r\n\r\nset w=\r\nset results=\r\nif exist \"%ProgramFiles%\\KM%w%Spico\" set pupfound= KM%w%Spico \r\nif not defined pupfound (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\" /f Path /s | find /i \"AutoPico\" %nul% && set pupfound= KM%w%Spico \r\n)\r\n\r\nset hcount=0\r\nfor %%# in (avira.com kaspersky.com virustotal.com mcafee.com) do (\r\nfind /i \"%%#\" %SysPath%\\drivers\\etc\\hosts %nul% && set /a hcount+=1)\r\nif %hcount%==4 set \"results=[Antivirus URLs are blocked in hosts]\"\r\n\r\nsc start %_slser% %nul%\r\necho \"%errorlevel%\" | findstr \"577 225\" %nul% && (\r\nset \"results=%results%[Likely File Infector]\"\r\n) || (\r\nif not exist %SysPath%\\%_slexe% if not exist %SysPath%\\alg.exe (set \"results=%results%[Likely File Infector]\")\r\n)\r\n\r\nif not \"%results%%pupfound%\"==\"\" (\r\nif defined pupfound call :dk_color %Gray% \"Checking PUP Activators                 [Found%pupfound%]\"\r\nif defined results call :dk_color %Red% \"Checking Probable Mal%w%ware Infection...\"\r\nif defined results (call :dk_color %Red% \"%results%\"&set showfix=1)\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\necho:\r\n)\r\n\r\n::  Remove the scheduled task of R@1n-KMS (old version) that runs the activation command every minute, as it leads to high CPU usage.\r\n\r\nif exist %SysPath%\\Tasks\\R@1n-KMS (\r\nfor /f %%A in ('dir /b /a:-d %SysPath%\\Tasks\\R@1n-KMS %nul6%') do (schtasks /delete /tn \\R@1n-KMS\\%%A /f %nul%)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_errorcheck\r\n\r\nset showfix=\r\ncall :dk_chkmal\r\n\r\n::==============================\r\n\r\n::  Check Sandboxing\r\n\r\nsc query Null %nul% || (\r\ncall :dk_color %Red% \"Checking Sandboxing                     [Found, script may not work properly]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"If you are using any third-party antivirus, check if it is blocking the script.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WinPE mode\r\n\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinPE\" /v InstRoot %nul% && (\r\n\r\ncall :dk_color %Red% \"Checking WinPE                          [Found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"WinPE mode found. Reboot the system and run in normal mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Safe mode\r\n\r\nif defined safeboot_option (\r\ncall :dk_color %Red% \"Checking Boot Mode                      [%safeboot_option%]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Safe mode found. Reboot the system and run in normal mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check ImageState\r\n::  https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-setup-states\r\n\r\nfor /f \"skip=2 tokens=2*\" %%A in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State\" /v ImageState') do (set imagestate=%%B)\r\n\r\nif /i not \"%imagestate%\"==\"IMAGE_STATE_COMPLETE\" (\r\ncall :dk_color %Gray% \"Checking Windows Setup State            [%imagestate%]\"\r\necho \"%imagestate%\" | find /i \"RESEAL\" %nul% && (\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"You need to run it in normal mode in case you are running it in Audit Mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\necho \"%imagestate%\" | find /i \"UNDEPLOYABLE\" %nul% && (\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If the activation fails, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check corrupt services\r\n\r\nset serv_cor=\r\nfor %%# in (%_serv%) do (\r\nset _regcorr=\r\nset _corrupt=\r\nsc start %%# %nul%\r\nif !errorlevel! EQU 1060 set _corrupt=1\r\nsc query %%# %nul% || set _corrupt=1\r\nfor %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type) do if not defined _regcorr (\r\nreg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%# /v %%G %nul% || (set _corrupt=1&set _regcorr=-RegistryError)\r\n)\r\n\r\nif defined _corrupt (if defined serv_cor (set \"serv_cor=!serv_cor! %%#!_regcorr!\") else (set \"serv_cor=%%#!_regcorr!\"))\r\n)\r\n\r\nif defined serv_cor (\r\ncall :dk_color %Red% \"Checking Corrupt Services               [%serv_cor%]\"\r\n\r\nif not defined showfix (\r\necho:\r\nif /i \"%serv_cor%\"==\"sppsvc-RegistryError\" (\r\nset fixes=%fixes% %mas%fix_service\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_service\"\r\n) else (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\necho:\r\n)\r\n\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check disabled services\r\n\r\nset serv_ste=\r\nfor %%# in (%_serv%) do (\r\nsc start %%# %nul%\r\nif !errorlevel! EQU 1058 (if defined serv_ste (set \"serv_ste=!serv_ste! %%#\") else (set \"serv_ste=%%#\"))\r\n)\r\n\r\n::  Change disabled services startup type to default\r\n\r\nset serv_csts=\r\nset serv_cste=\r\n\r\nif defined serv_ste (\r\nfor %%# in (%serv_ste%) do (\r\nif /i %%#==ClipSVC          (reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%#\" /v \"Start\" /t REG_DWORD /d \"3\" /f %nul% & sc config %%# start= demand %nul%)\r\nif /i %%#==wlidsvc          sc config %%# start= demand %nul%\r\nif /i %%#==sppsvc           (reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%#\" /v \"Start\" /t REG_DWORD /d \"2\" /f %nul% & sc config %%# start= delayed-auto %nul%)\r\nif /i %%#==SLsvc            sc config %%# start= auto %nul%\r\nif /i %%#==KeyIso           sc config %%# start= demand %nul%\r\nif /i %%#==LicenseManager   sc config %%# start= demand %nul%\r\nif /i %%#==Winmgmt          sc config %%# start= auto %nul%\r\nif !errorlevel!==0 (\r\nif defined serv_csts (set \"serv_csts=!serv_csts! %%#\") else (set \"serv_csts=%%#\")\r\n) else (\r\nif defined serv_cste (set \"serv_cste=!serv_cste! %%#\") else (set \"serv_cste=%%#\")\r\n)\r\n)\r\n)\r\n\r\nif defined serv_csts call :dk_color %Gray% \"Enabling Disabled Services              [Successful] [%serv_csts%]\"\r\n\r\nif defined serv_cste (\r\ncall :dk_color %Red% \"Enabling Disabled Services              [Failed] [%serv_cste%]\"\r\n\r\nif not defined showfix (\r\necho:\r\necho %serv_cste% | findstr /i \"ClipSVC sppsvc\" %nul% && (\r\necho A registry fix has been applied to enable the disabled service.\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\n) || (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\necho:\r\n)\r\n\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check if the services are able to run or not\r\n::  Workarounds are added to get correct status and error code because sc query doesn't output correct results in some conditions\r\n\r\nset serv_e=\r\nfor %%# in (%_serv%) do (\r\nset errorcode=\r\nset checkerror=\r\n\r\nsc query %%# | find /i \"RUNNING\" %nul% || (\r\n%psc% \"Start-Job { Start-Service %%# } | Wait-Job -Timeout 20 | Out-Null\"\r\nset errorcode=!errorlevel!\r\nsc query %%# | find /i \"RUNNING\" %nul% || set checkerror=1\r\n)\r\n\r\nsc start %%# %nul%\r\nif !errorlevel! NEQ 1056 if !errorlevel! NEQ 0 (set errorcode=!errorlevel!&set checkerror=1)\r\nif defined checkerror if defined serv_e (set \"serv_e=!serv_e!, %%#-!errorcode!\") else (set \"serv_e=%%#-!errorcode!\")\r\n)\r\n\r\nif defined serv_e (\r\ncall :dk_color %Red% \"Starting Services                       [Failed] [%serv_e%]\"\r\n\r\nif not defined showfix (\r\nset listwospp=%_serv:sppsvc=%\r\necho %serv_e% | findstr /i \"!listwospp!\" %nul% && (\r\nset showfix=1\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and run the script again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If service error is still not fixed, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\n)\r\nset error=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WMI\r\n\r\nset wmifailed=\r\nif %_wmic% EQU 1 wmic path Win32_ComputerSystem get CreationClassName /value %nul2% | find /i \"computersystem\" %nul1%\r\nif %_wmic% EQU 0 %psc% \"Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName\" %nul2% | find /i \"computersystem\" %nul1%\r\n\r\nif %errorlevel% NEQ 0 set wmifailed=1\r\n\r\nif %_wmic% EQU 1 wmic path %sps% get Version %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=([WMISEARCHER]'SELECT * FROM %sps%').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset error_code=%errorlevel%\r\ncmd /c exit /b %error_code%\r\nif %error_code% NEQ 0 set \"error_code=0x%=ExitCode%\"\r\n\r\necho \"%error_code%\" | findstr /i \"0x800410 0x800440 0x80131501\" %nul1% && set wmifailed=1& ::  https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants\r\n\r\nif defined wmifailed (\r\ncall :dk_color %Red% \"Checking WMI                            [Not Working]\"\r\n\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WMI option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SPP Registry Key\r\n\r\nif %winbuild% GEQ 7600 reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Plugins\\Objects\\msft:rm/algorithm/hwid/4.0\" /f ba02fed39662 /d %nul% || (\r\ncall :dk_color %Red% \"Checking SPP Registry Key               [Incorrect ModuleId Found] [Most likely caused by gaming spoofers]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%issues_due_to_gaming_spoofers\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%issues_due_to_gaming_spoofers\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check TokenStore registry key\r\n\r\nset tokenstore=\r\nif %winbuild% GEQ 7600 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v TokenStore %nul6%') do call set \"tokenstore=%%b\"\r\nif %winbuild% LSS 9200 set \"tokenstore=%Systemdrive%\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareProtectionPlatform\"\r\n\r\nif %winbuild% GEQ 9200 if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store\" if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store\\2.0\" if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store_test\\2.0\" (\r\ncall :dk_color %Red% \"Checking TokenStore Registry Key        [Correct Path Not Found] [!tokenstore!]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset toerr=1\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This code creates token folder only if it's missing and sets default permission for it\r\n\r\nif %winbuild% GEQ 7600 if not defined toerr if not exist \"%tokenstore%\\\" (\r\n\r\nmkdir \"%tokenstore%\" %nul%\r\n\r\nif %winbuild% LSS 9200 set \"d=$sddl = 'O:NSG:NSD:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;NS)';\"\r\nif %winbuild% GEQ 9200 set \"d=$sddl = 'O:BAG:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;GR;;;BU)(A;;FR;;;BU)(A;OICI;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)';\"\r\nset \"d=!d! $AclObject = New-Object System.Security.AccessControl.DirectorySecurity;\"\r\nset \"d=!d! $AclObject.SetSecurityDescriptorSddlForm($sddl);\"\r\nset \"d=!d! Set-Acl -Path %tokenstore% -AclObject $AclObject;\"\r\n%psc% \"!d!\" %nul%\r\n\r\nif exist \"%tokenstore%\\\" (\r\ncall :dk_color %Gray% \"Checking SPP Token Folder               [Not Found, Created Now] [%tokenstore%\\]\"\r\n) else (\r\ncall :dk_color %Red% \"Checking SPP Token Folder               [Not Found, Failed to Create] [%tokenstore%\\]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This code checks if SPP has permission access to tokens folder and required registry keys. It's often caused by gaming spoofers.\r\n\r\nset permerror=\r\nif %winbuild% GEQ 9200 if not defined toerr if not defined ps32onArm if exist \"%tokenstore%\\\" (\r\nfor %%# in (\r\n\"%tokenstore%+FullControl\"\r\n\"HKLM:\\SYSTEM\\WPA+QueryValues, EnumerateSubKeys, WriteKey\"\r\n\"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform+SetValue\"\r\n) do for /f \"tokens=1,2 delims=+\" %%A in (%%#) do if not defined permerror (\r\n%psc% \"$acl = (Get-Acl '%%A' | fl | Out-String); if (-not ($acl -match 'NT SERVICE\\\\sppsvc Allow  %%B') -or ($acl -match 'NT SERVICE\\\\sppsvc Deny')) {Exit 2}\" %nul%\r\nif !errorlevel!==2 (\r\nif \"%%A\"==\"%tokenstore%\" (\r\nset \"permerror=Error Found In Token Folder\"\r\n) else (\r\nset \"permerror=Error Found In SPP Registries\"\r\n)\r\n)\r\n)\r\n\r\nREM  https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application\r\n\r\nif not defined permerror (\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% && (\r\nset \"pol=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\"\r\nreg query \"!pol!\" %nul% || reg add \"!pol!\" %nul%\r\n%psc% \"$netServ = (New-Object Security.Principal.SecurityIdentifier('S-1-5-20')).Translate([Security.Principal.NTAccount]).Value; $aclString = Get-Acl 'Registry::!pol!' | Format-List | Out-String; if (-not ($aclString.Contains($netServ + ' Allow  FullControl') -or $aclString.Contains('NT SERVICE\\sppsvc Allow  FullControl')) -or ($aclString.Contains('Deny'))) {Exit 3}\" %nul%\r\nif !errorlevel!==3 set \"permerror=Error Found In S-1-5-20 SPP\"\r\n)\r\n)\r\n\r\nif defined permerror (\r\ncall :dk_color %Red% \"Checking SPP Permissions                [!permerror!]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WPA Registry Errors\r\n\r\nset chkalp=\r\nset wpainfo=NotFound\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wpatest\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (set wpainfo=%%a)\r\nfor /f \"delims=0123456789\" %%i in (\"%wpainfo%\") do set chkalp=%%i\r\n\r\nif defined chkalp (\r\ncall :dk_color %Red% \"Checking WPA Registry Errors            [%wpainfo%]\"\r\nif not defined showfix (\r\necho \"%wpainfo%\" | find /i \"Error Found\" %nul% && (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\necho:\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\nset wpainfo=a\r\n)\r\n\r\nif not defined chkalp (\r\nif %wpainfo% GEQ 5000 (\r\ncall :dk_color %Gray% \"Checking WPA Registry Count             [%wpainfo%]\"\r\ncall :dk_color %Blue% \"A large number of WPA registries have been found, which may cause high CPU usage.\"\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\necho:\r\n) else (\r\necho Checking WPA Registry Count             [%wpainfo%]\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Rearm\r\n\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\PersistedTSReArmed\" %nul% && (\r\ncall :dk_color %Red% \"Checking Rearm                          [System is Rearmed]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState\" %nul% && (\r\ncall :dk_color %Red% \"Checking ClipSVC PersistedSystemState   [Found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SoftwareLicensingService\r\n\r\nif %error_code% NEQ 0 (\r\ncall :dk_color %Red% \"Checking SoftwareLicensingService       [Not Working] [%error_code%]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Activation IDs\r\n\r\ncall :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nif not defined apps (\r\n%psc% \"if (-not $env:_vis) {Start-Job { Stop-Service %_slser% -force } | Wait-Job -Timeout 20 | Out-Null}; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif not defined _vis if !errorlevel! NEQ 0 set rlicfailed=1\r\ncall :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f\r\n)\r\n\r\nif not defined apps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nif not defined apps if defined allapps if not defined notwinact (\r\ncall :dk_color %Gray% \"Checking Activation IDs                 [Key Not Installed or Act ID Not Found]\"\r\n)\r\n\r\nif not defined apps if not defined allapps (\r\ncall :dk_color %Red% \"Checking Activation IDs                 [Not found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\nif not defined showfix if defined rlicfailed (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\n\r\nif %winbuild% GEQ 7600 if exist \"%tokenstore%\\\" if not exist \"%tokenstore%\\tokens.dat\" (\r\ncall :dk_color %Red% \"Checking SPP tokens.dat                 [Not Found] [%tokenstore%\\]\"\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Eval Windows\r\n\r\nif not defined notwinact if exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Eval\" %nul1% || (\r\ncall :dk_color %Red% \"Checking Eval Packages                  [License swapping found. Non-Eval licenses are installed in Eval Windows]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"License swapping is not the right way to upgrade to the full version. Learn the correct method at the link below.\"\r\nset fixes=%fixes% %mas%evaluation_editions\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%evaluation_editions\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check HKU\\S-1-5-20\\Software registry, in some systems it's missing and that causes Windows activation problems\r\n\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% || (\r\ncall :dk_color %Red% \"Checking HKU\\S-1-5-20 Registry          [Not Found]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check license and package files for the current edition\r\n\r\nset osedition=0\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do if not errorlevel 1 (call set \"osedition=%%a\")\r\n\r\nif %osedition%==0 for /f \"skip=2 tokens=3\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul6%') do set \"osedition=%%a\"\r\n\r\n::  Workaround for an issue in builds between 1607 and 1709 where ProfessionalEducation is shown as Professional\r\n\r\nif not %osedition%==0 (\r\nif \"%osSKU%\"==\"164\" set osedition=ProfessionalEducation\r\nif \"%osSKU%\"==\"165\" set osedition=ProfessionalEducationN\r\n)\r\n\r\nif not defined notwinact (\r\nif %osedition%==0 (\r\ncall :dk_color %Red% \"Checking Edition Name                   [Not Found In Registry]\"\r\n) else (\r\nif not exist \"%SysPath%\\spp\\tokens\\skus\\%osedition%\\%osedition%*.xrm-ms\" if not exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-%osedition%\\*-%osedition%-*.xrm-ms\" if not exist \"%SysPath%\\licensing\\skus\\Security-Licensing-SLC-Component-SKU-%osedition%\\*-%osedition%-*.xrm-ms\" (\r\nset skunotfound=1\r\ncall :dk_color %Red% \"Checking License Files                  [Not Found] [%osedition%]\"\r\n)\r\nif not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*-%osedition%-*.mum\" (\r\nif not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-%osedition%Edition*.mum\" (\r\ncall :dk_color %Red% \"Checking Package Files                  [Not Found] [%osedition%]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SKU value to find if there is any difference\r\n\r\nif not defined notwinact (\r\nif %winbuild% GEQ 10240 (\r\n%nul% set /a \"sum=%slcSKU%+%regSKU%+%wmiSKU%\"\r\nset /a \"sum/=3\"\r\nif not \"!sum!\"==\"%slcSKU%\" (\r\ncall :dk_color %Gray% \"Checking SLC/WMI/REG SKU                [Difference Found - SLC:%slcSKU% WMI:%wmiSKU% Reg:%regSKU%]\"\r\n)\r\n) else (\r\n%nul% set /a \"sum=%slcSKU%+%wmiSKU%\"\r\nset /a \"sum/=2\"\r\nif not \"!sum!\"==\"%slcSKU%\" (\r\ncall :dk_color %Gray% \"Checking SLC/WMI SKU                    [Difference Found - SLC:%slcSKU% WMI:%wmiSKU%]\"\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This \"WLMS\" service was included in previous Eval editions (which were activable) to automatically shut down the system every hour after the evaluation period expired and prevent SPPSVC from stopping.\r\n\r\nsc query wlms %nul%\r\n\r\nif %errorlevel% NEQ 1060 (\r\necho Checking Eval WLMS Service              [Found]\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SPP interference in IFEO\r\n\r\nfor %%# in (SppEx%w%tComObj.exe SLsvc.exe sppsvc.exe sppsvc.exe\\PerfOptions) do (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" %nul% && (if defined _sppint (set \"_sppint=!_sppint!, %%#\") else (set \"_sppint=%%#\"))\r\n)\r\nif defined _sppint (\r\necho %_sppint% | find /i \"PerfOptions\" %nul% && (\r\ncall :dk_color %Red% \"Checking SPP Interference In IFEO       [%_sppint% - System might deactivate later]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\nset showfix=1\r\n) || (\r\necho Checking SPP In IFEO                    [%_sppint%]\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check and fix SkipRearm registry value\r\n\r\nif %winbuild% GEQ 7600 for /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"SkipRearm\" %nul6%') do if /i %%b NEQ 0x0 (\r\nreg add \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"SkipRearm\" /t REG_DWORD /d \"0\" /f %nul%\r\ncall :dk_color %Gray% \"Checking SkipRearm                      [Default 0 Value Not Found. Changing To 0]\"\r\n%psc% \"Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null\"\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SvcRestartTask status, this task helps in making sure system remains activated\r\n\r\nif %winbuild% GEQ 9200 if not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\n%psc% \"Get-WmiObject -Query 'SELECT Description FROM SoftwareLicensingProduct WHERE PartialProductKey IS NOT NULL AND LicenseDependsOn IS NULL' | Select-Object -Property Description\" %nul2% | findstr /i \"KMS_\" %nul1% || (\r\nfor /f \"delims=\" %%a in ('%psc% \"$s=New-Object -ComObject 'Schedule.Service'; $s.Connect(); $state=$s.GetFolder('\\Microsoft\\Windows\\SoftwareProtectionPlatform').GetTask('SvcRestartTask').State; @{0='Unknown';1='Disabled';2='Queued';3='Ready';4='Running'}[$state]\" %nul6%') do (set taskinfo=%%a)\r\n\r\necho !taskinfo! | find /i \"Ready\" %nul% || (\r\nreg delete \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"actionlist\" /f %nul%\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\Microsoft\\Windows\\SoftwareProtectionPlatform\\SvcRestartTask\" %nul% || set taskinfo=Removed\r\nif \"!taskinfo!\"==\"\" set \"taskinfo=Not Found\"\r\n\r\ncall :dk_color %Gray% \"Checking SvcRestartTask Status          [!taskinfo!. System might deactivate later.]\"\r\nif not defined showfix (\r\necho \"!taskinfo!\" | findstr /i \"Removed Not Found\" %nul1% && (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n) || (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and run the script again.\"\r\n)\r\necho:\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\nexit /b\r\n\r\n::  This code checks for invalid registry keys in HKLM\\SYSTEM\\WPA. This issue may appear even on healthy systems\r\n\r\n:wpatest:\r\n$wpaKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME).OpenSubKey(\"SYSTEM\\\\WPA\")\r\n$count = 0\r\nforeach ($subkeyName in $wpaKey.GetSubKeyNames()) {\r\n    if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n        $count++\r\n    }\r\n}\r\n$osVersion = [System.Environment]::OSVersion.Version\r\n$minBuildNumber = 14393\r\nif ($osVersion.Build -ge $minBuildNumber) {\r\n    $subkeyHashTable = @{}\r\n    foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {\r\n        if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n            $keyNumber = $subkeyName -replace '.*-', ''\r\n            $subkeyHashTable[$keyNumber] = $true\r\n        }\r\n    }\r\n    for ($i=1; $i -le $count; $i++) {\r\n        if (-not $subkeyHashTable.ContainsKey(\"$i\")) {\r\n            Write-Output \"Total Keys $count. Error Found - $i key does not exist.\"\r\n\t\t\t$wpaKey.Close()\r\n\t\t\texit\r\n        }\r\n    }\r\n}\r\n$wpaKey.GetSubKeyNames() | ForEach-Object {\r\n    if ($_ -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n        if ($PSVersionTable.PSVersion.Major -lt 3) {\r\n            cmd /c \"reg query \"HKLM\\SYSTEM\\WPA\\$_\" /ve /t REG_BINARY >nul 2>&1\"\r\n\t\t\tif ($LASTEXITCODE -ne 0) {\r\n            Write-Host \"Total Keys $count. Error Found - Binary Data is corrupt.\"\r\n\t\t\t$wpaKey.Close()\r\n\t\t\texit\r\n\t\t\t}\r\n        } else {\r\n            $subkey = $wpaKey.OpenSubKey($_)\r\n            $p = $subkey.GetValueNames()\r\n            if (($p | Where-Object { $subkey.GetValueKind($_) -eq [Microsoft.Win32.RegistryValueKind]::Binary }).Count -eq 0) {\r\n                Write-Host \"Total Keys $count. Error Found - Binary Data is corrupt.\"\r\n\t\t\t\t$wpaKey.Close()\r\n\t\t\t\texit\r\n            }\r\n        }\r\n    }\r\n}\r\n$count\r\n$wpaKey.Close()\r\n:wpatest:\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_color\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3'\r\n) else if not exist %ps% (\r\necho %~3\r\n)\r\nexit /b\r\n\r\n:dk_color2\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[%~3%~4%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'\r\n) else if not exist %ps% (\r\necho %~3 %~6\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_done\r\n\r\necho:\r\nif %_unattended%==1 timeout /t 2 & exit /b\r\n\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 exit /b\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = Generic Retail/OEM/MAK Key\r\n::  3rd column = SKU ID\r\n::  4th column = Key part number\r\n::  5th column = 1 = activation is not working (at the time of writing this), 0 = activation is working\r\n::  6th column = Key Type\r\n::  7th column = WMI Edition ID (For reference only)\r\n::  8th column = Version name incase same Edition ID is used in different OS versions with different key\r\n::  Separator  = _\r\n\r\n\r\n:hwiddata\r\n\r\nset f=\r\nfor %%# in (\r\n8b351c9c-f398-4515-9900-09df49427262_XGVPP-NMH47-7TTHJ-W3FW7-8H%f%V2C___4_X19-99683_0_OEM:NONSLP_Enterprise\r\nc83cef07-6b72-4bbc-a28f-a00386872839_3V6Q6-NQXCX-V8YXR-9QCYV-QP%f%FCT__27_X19-98746_0_Volume:MAK_EnterpriseN\r\n4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T__48_X19-98841_0_____Retail_Professional\r\n9fbaf5d6-4d83-4422-870d-fdda6e5858aa_2B87N-8KFHP-DKV6R-Y2C8J-PK%f%CKT__49_X19-98859_0_____Retail_ProfessionalN\r\nf742e4ff-909d-4fe9-aacb-3231d24a0c58_4CPRK-NM3K3-X6XXQ-RXX86-WX%f%CHW__98_X19-98877_0_____Retail_CoreN\r\n1d1bac85-7365-4fea-949a-96978ec91ae0_N2434-X9D7W-8PF6X-8DV9T-8T%f%YMD__99_X19-99652_0_____Retail_CoreCountrySpecific\r\n3ae2cc14-ab2d-41f4-972f-5e20142771dc_BT79Q-G7N6G-PGBYW-4YWX6-6F%f%4BT_100_X19-99661_0_____Retail_CoreSingleLanguage\r\n2b1f36bb-c1cd-4306-bf5c-a0367c2d97d8_YTMG3-N6DKC-DKB77-7M9GH-8H%f%VX7_101_X19-98868_0_____Retail_Core\r\n2a6137f3-75c0-4f26-8e3e-d83d802865a4_XKCNC-J26Q9-KFHD2-FKTHY-KD%f%72Y_119_X19-99606_0_OEM:NONSLP_PPIPro\r\ne558417a-5123-4f6f-91e7-385c1c7ca9d4_YNMGQ-8RYV3-4PGQ3-C8XTP-7C%f%FBY_121_X19-98886_0_____Retail_Education\r\nc5198a66-e435-4432-89cf-ec777c9d0352_84NGF-MHBT6-FXBX8-QWJK7-DR%f%R8H_122_X19-98892_0_____Retail_EducationN\r\nf6e29426-a256-4316-88bf-cc5b0f95ec0c_PJB47-8PN2T-MCGDY-JTY3D-CB%f%CPV_125_X23-50331_1_Volume:MAK_EnterpriseS_Ge\r\ncce9d2de-98ee-4ce2-8113-222620c64a27_KCNVH-YKWX8-GJJB9-H9FDT-6F%f%7W2_125_X22-66075_1_Volume:MAK_EnterpriseS_VB\r\nd06934ee-5448-4fd1-964a-cd077618aa06_43TBQ-NH92J-XKTM7-KT3KK-P3%f%9PB_125_X21-83233_0_OEM:NONSLP_EnterpriseS_RS5\r\n706e0cfd-23f4-43bb-a9af-1a492b9f1302_NK96Y-D9CD8-W44CQ-R8YTK-DY%f%JWX_125_X21-05035_0_OEM:NONSLP_EnterpriseS_RS1\r\nfaa57748-75c8-40a2-b851-71ce92aa8b45_FWN7H-PF93Q-4GGP8-M8RF3-MD%f%WWW_125_X19-99617_0_OEM:NONSLP_EnterpriseS_TH\r\n3d1022d8-969f-4222-b54b-327f5a5af4c9_2DBW3-N2PJG-MVHW3-G7TDK-9H%f%KR4_126_X21-04921_0_Volume:MAK_EnterpriseSN_RS1\r\n60c243e1-f90b-4a1b-ba89-387294948fb6_NTX6B-BRYC2-K6786-F6MVQ-M7%f%V2X_126_X19-98770_0_Volume:MAK_EnterpriseSN_TH\r\n01eb852c-424d-4060-94b8-c10d799d7364_3XP6D-CRND4-DRYM2-GM84D-4G%f%G8Y_139_X23-37869_1_____Retail_ProfessionalCountrySpecific_Zn\r\neb6d346f-1c60-4643-b960-40ec31596c45_DXG7C-N36C4-C4HTG-X4T3X-2Y%f%V77_161_X21-43626_0_____Retail_ProfessionalWorkstation\r\n89e87510-ba92-45f6-8329-3afa905e3e83_WYPNQ-8C467-V2W6J-TX4WX-WT%f%2RQ_162_X21-43644_0_____Retail_ProfessionalWorkstationN\r\n62f0c100-9c53-4e02-b886-a3528ddfe7f6_8PTT6-RNW4C-6V7J2-C2D3X-MH%f%BPB_164_X21-04955_0_____Retail_ProfessionalEducation\r\n13a38698-4a49-4b9e-8e83-98fe51110953_GJTYN-HDMQY-FRR76-HVGC7-QP%f%F8P_165_X21-04956_0_____Retail_ProfessionalEducationN\r\ndf96023b-dcd9-4be2-afa0-c6c871159ebe_NJCF7-PW8QT-3324D-688JX-2Y%f%V66_175_X21-41295_0_____Retail_ServerRdsh\r\nd4ef7282-3d2c-4cf0-9976-8854e64a8d1e_V3WVW-N2PV2-CGWC3-34QGF-VM%f%J2C_178_X21-32983_0_____Retail_Cloud\r\naf5c9381-9240-417d-8d35-eb40cd03e484_NH9J3-68WK7-6FB93-4K3DF-DJ%f%4F6_179_X21-32987_0_____Retail_CloudN\r\n8ab9bdd1-1f67-4997-82d9-8878520837d9_XQQYW-NFFMW-XJPBH-K8732-CK%f%FFD_188_X21-99378_0_____OEM:DM_IoTEnterprise\r\ned655016-a9e8-4434-95d9-4345352c2552_QPM6N-7J2WJ-P88HH-P3YRH-YY%f%74H_191_X21-99682_0_OEM:NONSLP_IoTEnterpriseS_VB\r\n6c4de1b8-24bb-4c17-9a77-7b939414c298_CGK42-GYN6Y-VD22B-BX98W-J8%f%JXD_191_X23-12617_0_OEM:NONSLP_IoTEnterpriseS_Ge\r\nd4bdc678-0a4b-4a32-a5b3-aaa24c3b0f24_K9VKN-3BGWV-Y624W-MCRMQ-BH%f%DCD_202_X22-53884_0_____Retail_CloudEditionN\r\n92fb8726-92a8-4ffc-94ce-f82e07444653_KY7PN-VR6RX-83W6Y-6DDYQ-T6%f%R4W_203_X22-53847_0_____Retail_CloudEdition\r\n5a85300a-bfce-474f-ac07-a30983e3fb90_N979K-XWD77-YW3GB-HBGH6-D3%f%2MH_205_X23-15042_0_____OEM:DM_IoTEnterpriseSK\r\n80083eae-7031-4394-9e88-4901973d56fe_P8Q7T-WNK7X-PMFXY-VXHBG-RR%f%K69_206_X23-62084_0_____OEM:DM_IoTEnterpriseK\r\n1bc2140b-285b-4351-b99c-26a126104b29_TMP2N-KGFHJ-PWM6F-68KCQ-3P%f%JBP_210_X23-60513_0_____Retail_WNC\r\n) do (\r\nfor /f \"tokens=1-9 delims=_\" %%A in (\"%%#\") do (\r\n\r\nREM Detect key\r\n\r\nif %1==key if %osSKU%==%%C if not defined key (\r\necho \"!allapps! !altapplist!\" | find /i \"%%A\" %nul1% && (\r\nif %%E==1 set notworking=1\r\nset key=%%B\r\n)\r\n)\r\n\r\nREM Generate ticket\r\n\r\nif %1==ticket if \"%key%\"==\"%%B\" (\r\nset \"SessionIdStr=OSMajorVersion=5;OSMinorVersion=1;OSPlatformId=2;PP=0;Pfn=Microsoft.Windows.%%C.%%D_8wekyb3d8bbwe;PKeyIID=465145217131314304264339481117862266242033457260311819664735280;\"\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':sign\\:.*';. ([scriptblock]::Create($f[1]))\"\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:sign:\r\n$ErrorActionPreference = \"Stop\"\r\n\r\nfunction SignProperties {\r\n    param (\r\n        $Properties,\r\n        $rsa\r\n    )\r\n\r\n    $sha256 = [Security.Cryptography.SHA256]::Create()\r\n    $bytes = [Text.Encoding]::UTF8.GetBytes($Properties)\r\n    $hash = $sha256.ComputeHash($bytes)\r\n\r\n    $signature = $rsa.SignHash($hash, [Security.Cryptography.HashAlgorithmName]::SHA256, [Security.Cryptography.RSASignaturePadding]::Pkcs1)\r\n    return [Convert]::ToBase64String($signature)\r\n\r\n}\r\n\r\n[byte[]] $key = 0x07,0x02,0x00,0x00,0x00,0xA4,0x00,0x00,0x52,0x53,0x41,0x32,0x00,0x04,0x00,0x00,\r\n                0x01,0x00,0x01,0x00,0x29,0x87,0xBA,0x3F,0x52,0x90,0x57,0xD8,0x12,0x26,0x6B,0x38,\r\n                0xB2,0x3B,0xF9,0x67,0x08,0x4F,0xDD,0x8B,0xF5,0xE3,0x11,0xB8,0x61,0x3A,0x33,0x42,\r\n                0x51,0x65,0x05,0x86,0x1E,0x00,0x41,0xDE,0xC5,0xDD,0x44,0x60,0x56,0x3D,0x14,0x39,\r\n                0xB7,0x43,0x65,0xE9,0xF7,0x2B,0xA5,0xF0,0xA3,0x65,0x68,0xE9,0xE4,0x8B,0x5C,0x03,\r\n                0x2D,0x36,0xFE,0x28,0x4C,0xD1,0x3C,0x3D,0xC1,0x90,0x75,0xF9,0x6E,0x02,0xE0,0x58,\r\n                0x97,0x6A,0xCA,0x80,0x02,0x42,0x3F,0x6C,0x15,0x85,0x4D,0x83,0x23,0x6A,0x95,0x9E,\r\n                0x38,0x52,0x59,0x38,0x6A,0x99,0xF0,0xB5,0xCD,0x53,0x7E,0x08,0x7C,0xB5,0x51,0xD3,\r\n                0x8F,0xA3,0x0D,0xA0,0xFA,0x8D,0x87,0x3C,0xFC,0x59,0x21,0xD8,0x2E,0xD9,0x97,0x8B,\r\n                0x40,0x60,0xB1,0xD7,0x2B,0x0A,0x6E,0x60,0xB5,0x50,0xCC,0x3C,0xB1,0x57,0xE4,0xB7,\r\n                0xDC,0x5A,0x4D,0xE1,0x5C,0xE0,0x94,0x4C,0x5E,0x28,0xFF,0xFA,0x80,0x6A,0x13,0x53,\r\n                0x52,0xDB,0xF3,0x04,0x92,0x43,0x38,0xB9,0x1B,0xD9,0x85,0x54,0x7B,0x14,0xC7,0x89,\r\n                0x16,0x8A,0x4B,0x82,0xA1,0x08,0x02,0x99,0x23,0x48,0xDD,0x75,0x9C,0xC8,0xC1,0xCE,\r\n                0xB0,0xD7,0x1B,0xD8,0xFB,0x2D,0xA7,0x2E,0x47,0xA7,0x18,0x4B,0xF6,0x29,0x69,0x44,\r\n                0x30,0x33,0xBA,0xA7,0x1F,0xCE,0x96,0x9E,0x40,0xE1,0x43,0xF0,0xE0,0x0D,0x0A,0x32,\r\n                0xB4,0xEE,0xA1,0xC3,0x5E,0x9B,0xC7,0x7F,0xF5,0x9D,0xD8,0xF2,0x0F,0xD9,0x8F,0xAD,\r\n                0x75,0x0A,0x00,0xD5,0x25,0x43,0xF7,0xAE,0x51,0x7F,0xB7,0xDE,0xB7,0xAD,0xFB,0xCE,\r\n                0x83,0xE1,0x81,0xFF,0xDD,0xA2,0x77,0xFE,0xEB,0x27,0x1F,0x10,0xFA,0x82,0x37,0xF4,\r\n                0x7E,0xCC,0xE2,0xA1,0x58,0xC8,0xAF,0x1D,0x1A,0x81,0x31,0x6E,0xF4,0x8B,0x63,0x34,\r\n                0xF3,0x05,0x0F,0xE1,0xCC,0x15,0xDC,0xA4,0x28,0x7A,0x9E,0xEB,0x62,0xD8,0xD8,0x8C,\r\n                0x85,0xD7,0x07,0x87,0x90,0x2F,0xF7,0x1C,0x56,0x85,0x2F,0xEF,0x32,0x37,0x07,0xAB,\r\n                0xB0,0xE6,0xB5,0x02,0x19,0x35,0xAF,0xDB,0xD4,0xA2,0x9C,0x36,0x80,0xC6,0xDC,0x82,\r\n                0x08,0xE0,0xC0,0x5F,0x3C,0x59,0xAA,0x4E,0x26,0x03,0x29,0xB3,0x62,0x58,0x41,0x59,\r\n                0x3A,0x37,0x43,0x35,0xE3,0x9F,0x34,0xE2,0xA1,0x04,0x97,0x12,0x9D,0x8C,0xAD,0xF7,\r\n                0xFB,0x8C,0xA1,0xA2,0xE9,0xE4,0xEF,0xD9,0xC5,0xE5,0xDF,0x0E,0xBF,0x4A,0xE0,0x7A,\r\n                0x1E,0x10,0x50,0x58,0x63,0x51,0xE1,0xD4,0xFE,0x57,0xB0,0x9E,0xD7,0xDA,0x8C,0xED,\r\n                0x7D,0x82,0xAC,0x2F,0x25,0x58,0x0A,0x58,0xE6,0xA4,0xF4,0x57,0x4B,0xA4,0x1B,0x65,\r\n                0xB9,0x4A,0x87,0x46,0xEB,0x8C,0x0F,0x9A,0x48,0x90,0xF9,0x9F,0x76,0x69,0x03,0x72,\r\n                0x77,0xEC,0xC1,0x42,0x4C,0x87,0xDB,0x0B,0x3C,0xD4,0x74,0xEF,0xE5,0x34,0xE0,0x32,\r\n                0x45,0xB0,0xF8,0xAB,0xD5,0x26,0x21,0xD7,0xD2,0x98,0x54,0x8F,0x64,0x88,0x20,0x2B,\r\n                0x14,0xE3,0x82,0xD5,0x2A,0x4B,0x8F,0x4E,0x35,0x20,0x82,0x7E,0x1B,0xFE,0xFA,0x2C,\r\n                0x79,0x6C,0x6E,0x66,0x94,0xBB,0x0A,0xEB,0xBA,0xD9,0x70,0x61,0xE9,0x47,0xB5,0x82,\r\n                0xFC,0x18,0x3C,0x66,0x3A,0x09,0x2E,0x1F,0x61,0x74,0xCA,0xCB,0xF6,0x7A,0x52,0x37,\r\n                0x1D,0xAC,0x8D,0x63,0x69,0x84,0x8E,0xC7,0x70,0x59,0xDD,0x2D,0x91,0x1E,0xF7,0xB1,\r\n                0x56,0xED,0x7A,0x06,0x9D,0x5B,0x33,0x15,0xDD,0x31,0xD0,0xE6,0x16,0x07,0x9B,0xA5,\r\n                0x94,0x06,0x7D,0xC1,0xE9,0xD6,0xC8,0xAF,0xB4,0x1E,0x2D,0x88,0x06,0xA7,0x63,0xB8,\r\n                0xCF,0xC8,0xA2,0x6E,0x84,0xB3,0x8D,0xE5,0x47,0xE6,0x13,0x63,0x8E,0xD1,0x7F,0xD4,\r\n                0x81,0x44,0x38,0xBF\r\n\r\n$rsa = New-Object Security.Cryptography.RSACryptoServiceProvider\r\n$rsa.ImportCspBlob($key)\r\n$SessionId = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($env:SessionIdStr + [char]0))\r\n$PropertiesStr = \"OA3xOriginalProductId=;OA3xOriginalProductKey=;SessionId=$SessionId;TimeStampClient=2022-10-11T12:00:00Z\"\r\n$SignatureStr = SignProperties $PropertiesStr $rsa\r\n\r\n$xml = @\"\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?><genuineAuthorization xmlns=\"http://www.microsoft.com/DRM/SL/GenuineAuthorization/1.0\"><version>1.0</version><genuineProperties origin=\"sppclient\"><properties>$PropertiesStr</properties><signatures><signature name=\"clientLockboxKey\" method=\"rsa-sha256\">$SignatureStr</signature></signatures></genuineProperties></genuineAuthorization>\r\n\"@\r\n[System.IO.File]::WriteAllText(\"$env:ProgramData\\Microsoft\\Windows\\ClipSVC\\GenuineTicket\\GenuineTicket\", ($xml -join \"\"), [System.Text.Encoding]::ASCII)\r\n:sign:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Below code is used to get alternate edition name and key if current edition doesn't support HWID activation\r\n\r\n::  1st column = Current SKU ID\r\n::  2nd column = Current Edition Name\r\n::  3rd column = Current Edition Activation ID\r\n::  4th column = Alternate Edition Activation ID\r\n::  5th column = Alternate Edition HWID Key\r\n::  6th column = Alternate Edition Name\r\n::  Separator  = _\r\n\r\n\r\n:hwidfallback\r\n\r\nset notfoundaltactID=\r\nif %_NoEditionChange%==1 exit /b\r\n\r\nfor %%# in (\r\n125_EnterpriseS-2021_______________cce9d2de-98ee-4ce2-8113-222620c64a27_ed655016-a9e8-4434-95d9-4345352c2552_QPM6N-7J2WJ-P88HH-P3YRH-YY%f%74H_IoTEnterpriseS-2021\r\n125_EnterpriseS-2024_______________f6e29426-a256-4316-88bf-cc5b0f95ec0c_6c4de1b8-24bb-4c17-9a77-7b939414c298_CGK42-GYN6Y-VD22B-BX98W-J8%f%JXD_IoTEnterpriseS-2024\r\n138_ProfessionalSingleLanguage_____a48938aa-62fa-4966-9d44-9f04da3f72f2_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional\r\n139_ProfessionalCountrySpecific____f7af7d09-40e4-419c-a49b-eae366689ebd_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional\r\n139_ProfessionalCountrySpecific-Zn_01eb852c-424d-4060-94b8-c10d799d7364_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional\r\n) do (\r\nfor /f \"tokens=1-6 delims=_\" %%A in (\"%%#\") do if %osSKU%==%%A (\r\necho \"!allapps! !altapplist!\" | find /i \"%%C\" %nul1% && (\r\necho \"!allapps!\" | find /i \"%%D\" %nul1% && (\r\nset altkey=%%E\r\nset altedition=%%F\r\n) || (\r\nset altedition=%%F\r\nset notfoundaltactID=1\r\n)\r\n)\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n:: Leave empty line below\r\n"
  },
  {
    "path": "MAS/Separate-Files-Version/Activators/Ohook_Activation_AIO.cmd",
    "content": "@set masver=3.10\r\n@echo off\r\n\r\n\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\n\r\n::  To activate Office with Ohook activation, run the script with \"/Ohook\" parameter or change 0 to 1 in below line\r\nset _act=0\r\n\r\n::  To remove Ohook activation, run the script with /Ohook-Uninstall parameter or change 0 to 1 in below line\r\nset _rem=0\r\n\r\n::  To run the script in debug mode, change 0 to \"/Ohook\" in below line\r\nset \"_debug=0\"\r\n\r\n::  If value is changed in above lines or parameter is used then script will run in unattended mode\r\n\r\n\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\nset re1=\r\nset re2=\r\nset \"_cmdf=%~f0\"\r\nfor %%# in (%*) do (\r\nif /i \"%%#\"==\"re1\" set re1=1\r\nif /i \"%%#\"==\"re2\" set re2=1\r\nif /i \"%%#\"==\"-qedit\" (set re1=1&set re2=1)\r\n)\r\n\r\n:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows\r\n:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\Sysnative\\cmd.exe if not defined re1 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\Sysnative\\cmd.exe /c \"\"!_cmdf!\" %* re1\"\r\nexit /b\r\n)\r\n\r\n:: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\SysArm32\\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\SysArm32\\cmd.exe /c \"\"!_cmdf!\" %* re2\"\r\nexit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Debug code\r\n\r\nif \"%_debug%\" EQU \"0\" (\r\nset \"nul1=1>nul\"\r\nset \"nul2=2>nul\"\r\nset \"nul6=2^>nul\"\r\nset \"nul=>nul 2>&1\"\r\ngoto :_debug\r\n)\r\n\r\nset \"nul1=\"\r\nset \"nul2=\"\r\nset \"nul6=\"\r\nset \"nul=\"\r\n\r\n@echo on\r\n@prompt $G\r\n@call :_debug \"%_debug%\" >\"%~dp0_tmp.log\" 2>&1\r\n@cmd /u /c type \"%~dp0_tmp.log\">\"%~dp0_Debug.log\"\r\n@del \"%~dp0_tmp.log\"\r\n@echo off\r\n@exit /b\r\n\r\n:_debug\r\n\r\n::========================================================================================================================================\r\n\r\nset \"blank=\"\r\nset \"mas=ht%blank%tps%blank%://m%blank%ass%blank%grave.dev/\"\r\nset \"github=ht%blank%tps%blank%://github.com/m%blank%assgra%blank%vel/Micro%blank%soft-Acti%blank%vation-Scripts\"\r\nset \"selfgit=ht%blank%tps%blank%://git.acti%blank%vated.win/Micr%blank%osoft-Act%blank%ivation-Scripts\"\r\n\r\n::  Check if Null service is working, it's important for the batch script\r\n\r\nsc query Null | find /i \"RUNNING\"\r\nif %errorlevel% NEQ 0 (\r\necho:\r\necho Null service is not running, script may crash...\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%fix_service\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20\r\n)\r\ncls\r\n\r\n::  Check LF line ending\r\n\r\npushd \"%~dp0\"\r\n>nul findstr /v \"$\" \"%~nx0\" && (\r\necho:\r\necho Error - Script either has LF line ending issue or an empty line at the end of the script is missing.\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20 >nul\r\npopd\r\nexit /b\r\n)\r\npopd\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\ntitle  Ohook Activation %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args set _args=%_args:re1=%\r\nif defined _args set _args=%_args:re2=%\r\nif defined _args (\r\nfor %%A in (%_args%) do (\r\nif /i \"%%A\"==\"/Ohook\"                  set _act=1\r\nif /i \"%%A\"==\"/Ohook-Uninstall\"        set _rem=1\r\nif /i \"%%A\"==\"-el\"                     set _elev=1\r\n)\r\n)\r\n\r\nfor %%A in (%_act% %_rem%) do (if \"%%A\"==\"1\" set _unattended=1)\r\n\r\n::========================================================================================================================================\r\n\r\ncall :dk_setvar\r\n\r\nif %winbuild% EQU 1 (\r\n%eline%\r\necho Failed to detect Windows build number.\r\necho:\r\nsetlocal EnableDelayedExpansion\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\nif exist \"%Systemdrive%\\Users\\WDAGUtilityAccount\" (\r\nsc query gcs | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Windows Sandbox detected; activation is not supported.\r\necho The script cannot run due to missing licensing components. Aborting...\r\necho:\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 6001 (\r\n%nceline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho MAS only supports Windows Vista/7/8/8.1/10/11 and their Server equivalents.\r\nif %winbuild% EQU 6000 (\r\necho:\r\necho Windows Vista RTM is not supported because Powershell cannot be installed.\r\necho Upgrade to Windows Vista SP1 or SP2.\r\n)\r\ngoto dk_done\r\n)\r\n\r\nif %winbuild% LSS 7600 if not exist \"%SysPath%\\WindowsPowerShell\\v1.0\\Modules\" (\r\n%nceline%\r\nif not exist %ps% (\r\necho PowerShell is not installed in your system.\r\n)\r\necho Install PowerShell 2.0 using the following URL.\r\necho:\r\necho https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\nif %_unattended%==0 start https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix special character limitations in path name\r\n\r\nset \"_work=%~dp0\"\r\nif \"%_work:~-1%\"==\"\\\" set \"_work=%_work:~0,-1%\"\r\n\r\nset \"_batf=%~f0\"\r\nset \"_batp=%_batf:'=''%\"\r\n\r\nset _PSarg=\"\"\"%~f0\"\"\" -el %_args%\r\nset _PSarg=%_PSarg:'=''%\r\n\r\nset \"_ttemp=%userprofile%\\AppData\\Local\\Temp\"\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\necho \"!_batf!\" | find /i \"!_ttemp!\" %nul1% && (\r\nif /i not \"!_work!\"==\"!_ttemp!\" (\r\n%eline%\r\necho The script was launched from the temp folder.\r\necho You are most likely running the script directly from the archive file.\r\necho:\r\necho Extract the archive file and launch the script from the extracted folder.\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Elevate script as admin and pass arguments and preventing loop\r\n\r\n%nul1% fltmc || (\r\nif not defined _elev %psc% \"start cmd.exe -arg '/c \\\"!_PSarg!\\\"' -verb runas\" && exit /b\r\n%eline%\r\necho This script needs admin rights.\r\necho Right click on this script and select 'Run as administrator'.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check PowerShell\r\n\r\n::pstst $ExecutionContext.SessionState.LanguageMode :pstst\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"if ($PSVersionTable.PSEdition -ne 'Core') {$f=[System.IO.File]::ReadAllText('!_batp!') -split ':pstst';. ([scriptblock]::Create($f[1]))}\" %nul6%') do (set tstresult=%%a)\r\n\r\nif /i not \"%tstresult%\"==\"FullLanguage\" (\r\n%eline%\r\nfor /f \"delims=\" %%a in ('%psc% \"$ExecutionContext.SessionState.LanguageMode\" %nul6%') do (set tstresult2=%%a)\r\necho Test 1 - %tstresult%\r\necho Test 2 - !tstresult2!\r\necho:\r\n\r\nREM check LanguageMode\r\n\r\necho: !tstresult2! | findstr /i \"ConstrainedLanguage RestrictedLanguage NoLanguage\" %nul1% && (\r\necho FullLanguage mode not found in PowerShell. Aborting...\r\necho If you have applied restrictions on Powershell then undo those changes.\r\nset fixes=%fixes% %mas%fix_powershell\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_powershell\"\r\ngoto dk_done\r\n)\r\n\r\nREM check Powershell core version\r\n\r\ncmd /c \"%psc% \"$PSVersionTable.PSEdition\"\" | find /i \"Core\" %nul1% && (\r\necho Windows Powershell is needed for MAS but it seems to be replaced with Powershell core. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n\r\nREM check for Mal-ware that may cause issues with Powershell\r\n\r\nfor /r \"%ProgramFiles%\\\" %%f in (secureboot.exe) do if exist \"%%f\" (\r\necho \"%%f\"\r\necho Mal%blank%ware found, PowerShell is not working properly.\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\ngoto dk_done\r\n)\r\n\r\nREM check if .NET is working properly\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\ncmd /c \"%psc% \"\"try {[System.AppDomain]::CurrentDomain.GetAssemblies(); [System.Math]::Sqrt(144)} catch {Exit 3}\"\"\" %nul%\r\nif !errorlevel!==3 (\r\necho Windows Powershell failed to load .NET command. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nREM check antivirus and other errors\r\n\r\necho PowerShell is not working properly. Aborting...\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\necho:\r\necho Your antivirus software might be blocking the script.\r\necho:\r\nsc query sense | find /i \"RUNNING\" %nul% && (\r\necho Installed Antivirus - Microsoft Defender for Endpoint\r\n)\r\ncmd /c \"%psc% \"\"$av = Get-WmiObject -Namespace root\\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { $n += $i.displayName }; if ($n) { Write-Host ('Installed Antivirus - ' + ($n -join ', '))}\"\"\"\r\n)\r\n\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Disable QuickEdit and launch from conhost.exe to avoid Terminal app\r\n\r\nif %winbuild% GEQ 17763 (\r\nset terminal=1\r\n) else (\r\nset terminal=\r\n)\r\n\r\n::  Check if script is running in Terminal app\r\n\r\nif defined terminal (\r\nset lines=0\r\nfor /f \"skip=3 tokens=* delims=\" %%A in ('mode con') do if \"!lines!\"==\"0\" (\r\nfor %%B in (%%A) do set lines=%%B\r\n)\r\nif !lines! GEQ 100 set terminal=\r\n)\r\n\r\nif %_unattended%==1 goto :skipQE\r\nfor %%# in (%_args%) do (if /i \"%%#\"==\"-qedit\" goto :skipQE)\r\n\r\n::  Relaunch to disable QuickEdit in the current session and use conhost.exe instead of the Terminal app\r\n::  This code disables QuickEdit for the current cmd.exe session without making permanent registry changes\r\n::  It is included because clicking on the script window can pause execution, causing confusion that the script has stopped due to an error\r\n\r\nset resetQE=1\r\nreg query HKCU\\Console /v QuickEdit %nul2% | find /i \"0x0\" %nul1% && set resetQE=0\r\nreg add HKCU\\Console /v QuickEdit /t REG_DWORD /d 0 /f %nul1%\r\n\r\nif defined terminal (\r\nstart conhost.exe \"!_batf!\" %_args% -qedit\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n) else if %resetQE% EQU 1 (\r\nstart cmd.exe /c \"\"!_batf!\" %_args% -qedit\"\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n)\r\n\r\n:skipQE\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check for updates\r\n\r\nset -=\r\nset old=\r\nset pingp=\r\nset upver=%masver:.=%\r\n\r\nfor %%A in (\r\nactiv%-%ated.win\r\nmass%-%grave.dev\r\n) do if not defined pingp (\r\nfor /f \"delims=[] tokens=2\" %%B in ('ping -n 1 %%A') do (\r\nif not \"%%B\"==\"\" (set old=1& set pingp=1)\r\nfor /f \"delims=[] tokens=2\" %%C in ('ping -n 1 updatecheck%upver%.%%A') do (\r\nif not \"%%C\"==\"\" set old=\r\n)\r\n)\r\n)\r\n\r\nif defined old (\r\necho ________________________________________________\r\n%eline%\r\necho Your version of MAS [%masver%] is outdated.\r\necho ________________________________________________\r\necho:\r\nif not %_unattended%==1 (\r\necho [1] Get Latest MAS\r\necho [0] Continue Anyway\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 rem\r\nif !errorlevel!==1 (start %selfgit% & start %github% & start %mas% & exit /b)\r\n)\r\n)\r\ncls\r\n\r\n::========================================================================================================================================\r\n\r\nif %_rem%==1 goto :oh_uninstall\r\n\r\n:oh_menu\r\n\r\nif %_unattended%==0 (\r\ncls\r\nif not defined terminal mode 76, 25\r\ntitle  Ohook Activation %masver%\r\ncall :oh_checkapps\r\necho:\r\necho:\r\necho:\r\necho:\r\nif defined checknames (call :dk_color %_Yellow% \"                Close [!checknames!] before proceeding...\")\r\necho         ____________________________________________________________\r\necho:\r\necho                 [1] Install Ohook Office Activation\r\necho:\r\necho                 [2] Uninstall Ohook\r\necho                 ____________________________________________\r\necho:\r\necho                 [3] Download Office\r\necho:\r\necho                 [0] %_exitmsg%\r\necho         ____________________________________________________________\r\necho: \r\ncall :dk_color2 %_White% \"             \" %_Green% \"Choose a menu option using your keyboard [1,2,3,0]\"\r\nchoice /C:1230 /N\r\nset _el=!errorlevel!\r\nif !_el!==4  exit /b\r\nif !_el!==3  start %mas%genuine-installation-media &goto :oh_menu\r\nif !_el!==2  goto :oh_uninstall\r\nif !_el!==1  goto :oh_menu2\r\ngoto :oh_menu\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_menu2\r\n\r\ncls\r\nif not defined terminal (\r\nmode 140, 32\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=32;$B.Height=300;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\ntitle  Ohook Activation %masver%\r\n\r\necho:\r\necho Initializing...\r\ncall :dk_chkmal\r\n\r\nif not exist %SysPath%\\%_slexe% (\r\n%eline%\r\necho [%SysPath%\\%_slexe%] file is missing, aborting...\r\necho:\r\nif not defined results (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options.\"\r\ncall :dk_color %Blue% \"After that, restart system and try activation again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If it still shows the same error, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_reflection\r\ncall :dk_ckeckwmic\r\ncall :dk_product\r\ncall :dk_sppissue\r\n\r\n::========================================================================================================================================\r\n\r\nset error=\r\n\r\ncls\r\necho:\r\ncall :dk_showosinfo\r\n\r\n::========================================================================================================================================\r\n\r\necho Initiating Diagnostic Tests...\r\n\r\nset \"_serv=%_slser% Winmgmt\"\r\n\r\n::  Software Protection\r\n::  Windows Management Instrumentation\r\n\r\nset notwinact=1\r\nset ohookact=1\r\ncall :dk_errorcheck\r\n\r\ncall :oh_setspp\r\n\r\n::  Check unsupported office versions\r\n\r\nset o14c2r=\r\nset o16uwp=\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n%nul% reg query %_68%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n%nul% reg query %_86%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n\r\nif %winbuild% GEQ 10240 (\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty InstallLocation)\" %nul6%') do (if exist \"%%a\\Integration\\Integrator.exe\" set o16uwp=Office UWP )\r\n)\r\n\r\nif not \"%o14c2r%%o16uwp%\"==\"\" (\r\necho:\r\ncall :dk_color %Red% \"Checking Unsupported Office Install     [ %o14c2r%%o16uwp%]\"\r\nif not \"%o16uwp%\"==\"\" call :dk_color %Blue% \"Use TSforge option to activate it.\"\r\n)\r\n\r\nif %winbuild% GEQ 10240 %psc% \"Get-AppxPackage -name \"Microsoft.MicrosoftOfficeHub\"\" | find /i \"Office\" %nul1% && (\r\nset ohub=1\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check supported office versions\r\n\r\ncall :oh_getpath\r\n\r\nsc query ClickToRunSvc %nul%\r\nset error1=%errorlevel%\r\n\r\nif defined o16c2r if %error1% EQU 1060 (\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 16.0 files found]\"\r\nset o16c2r=\r\nset error=1\r\n)\r\n\r\nsc query OfficeSvc %nul%\r\nset error2=%errorlevel%\r\n\r\nif defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 15.0 files found]\"\r\nset o15c2r=\r\nset error=1\r\n)\r\n\r\nif \"%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%\"==\"\" (\r\nset error=1\r\necho:\r\nif not \"%o14c2r%%o16uwp%\"==\"\" (\r\ncall :dk_color %Red% \"Checking Supported Office Install       [Not Found]\"\r\n) else (\r\ncall :dk_color %Red% \"Checking Installed Office               [Not Found]\"\r\n)\r\n\r\nif defined ohub (\r\necho:\r\necho You only have the Office Dashboard app installed; you need to install the full version of Office.\r\n)\r\ncall :dk_color %Blue% \"Download and install Office from the URL below, then try again.\"\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto dk_done\r\n)\r\n\r\nset multioffice=\r\nif not \"%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%\"==\"1\" set multioffice=1\r\nif not \"%o14c2r%%o16uwp%\"==\"\" set multioffice=1\r\n\r\nif defined multioffice (\r\ncall :dk_color %Gray% \"Checking Multiple Office Install        [Found, its recommended to install only one version]\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Windows Server\r\n\r\nset winserver=\r\nreg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions\" /v ProductType %nul2% | find /i \"WinNT\" %nul1% || set winserver=1\r\nif not defined winserver (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Server\" %nul1% && set winserver=1\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:: Check Smart App Control\r\n\r\nset \"sacstate=\"\r\nif %winbuild% GEQ 22621 (\r\nfor /f \"tokens=3\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\CI\\Policy\" /v VerifiedAndReputablePolicyState %nul6%') do set \"sacstate=%%a\"\r\n)\r\nif defined sacstate (\r\nif \"%sacstate%\"==\"0x1\" (\r\ncall :dk_color %Gray% \"Checking Smart App Control State        [Enabled]\"\r\ncall :dk_color %Blue% \"Smart App Control may prevent you from opening Office after Ohook activation.\"\r\ncall :dk_color %Blue% \"You will need to disable it from the Windows Defender settings if it does.\"\r\n) else if \"%sacstate%\"==\"0x2\" (\r\ncall :dk_color %Gray% \"Checking Smart App Control State        [Evaluation]\"\r\ncall :dk_color %Blue% \"Smart App Control may prevent you from opening Office in the future if it enables itself after the evaluation period.\"\r\ncall :dk_color %Blue% \"It is recommended that you disable it from the Windows Defender settings.\"\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Process Office 15.0 C2R\r\n\r\nif not defined o15c2r goto :starto16c2r\r\n\r\ncall :oh_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=15\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o15c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o15c2r_reg%\\Configuration\")\r\nif not defined _oArch   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nif not defined _version for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v version\" %nul6%') do (set \"_version=%%b\")\r\nif not defined _prids   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v ProductReleaseId\" %nul6%') do (set \"_prids=%o15c2r_reg%\\propertyBag /v ProductReleaseId\" & set \"_config=%o15c2r_reg%\\propertyBag\")\r\n\r\necho \"%o15c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=10) || (set _tok=9)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query %o15c2r_reg%\\ProductReleaseIDs\\Active %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\nif /i \"%_oArch%\"==\"x64\" (set \"_hookPath=%_oRoot%\\vfs\\System\"    & set \"_hook=sppc64.dll\")\r\nif /i \"%_oArch%\"==\"x86\" (set \"_hookPath=%_oRoot%\\vfs\\SystemX86\" & set \"_hook=sppc32.dll\")\r\n\r\ncall :oh_ppcpath\r\n\r\necho:\r\necho Activating Office...                    [C2R ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :starto16c2r\r\n)\r\n\r\nif defined noOsppc (\r\ncall :dk_color %Red% \"Checking OSPPC.DLL                      [Not found. Aborting activation...]\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\nset error=1\r\ngoto :starto16c2r\r\n)\r\n\r\ncall :oh_expiredpreview 2013\r\ncall :oh_fixprids\r\ncall :oh_process\r\nif defined isOspp (\r\ncall :oh_hookinstall_ospp\r\n) else (\r\ncall :oh_hookinstall\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:starto16c2r\r\n\r\n::  Process Office 16.0 C2R\r\n\r\nif not defined o16c2r goto :startmsi\r\n\r\ncall :oh_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=16\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v AudienceData\" %nul6%') do (set \"_AudienceData=^| %%b \")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o16c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o16c2r_reg%\\Configuration\")\r\n\r\necho \"%o16c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=9) || (set _tok=8)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query \"%o16c2r_reg%\\ProductReleaseIDs\" /s /f \".16\" /k %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\nset _oIds=%_oIds:.16=%\r\nset _o16c2rIds=%_oIds%\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses16\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\nif /i \"%_oArch%\"==\"x64\" (set \"_hookPath=%_oRoot%\\vfs\\System\"    & set \"_hook=sppc64.dll\")\r\nif /i \"%_oArch%\"==\"x86\" (set \"_hookPath=%_oRoot%\\vfs\\SystemX86\" & set \"_hook=sppc32.dll\")\r\n\r\ncall :oh_ppcpath\r\n\r\necho:\r\necho Activating Office...                    [C2R ^| %_version% %_AudienceData%^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :startmsi\r\n)\r\n\r\nif defined noOsppc (\r\ncall :dk_color %Red% \"Checking OSPPC.DLL                      [Not found. Aborting activation...]\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\nset error=1\r\ngoto :startmsi\r\n)\r\n\r\ncall :oh_expiredpreview 2016 2019 2021 2024\r\ncall :oh_fixprids\r\ncall :oh_process\r\nif defined isOspp (\r\ncall :oh_hookinstall_ospp\r\n) else (\r\ncall :oh_hookinstall\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Old version of Office with subscription license key may show a banner to sign in to fix license issue.\r\n::  Although script applies a Resiliency registry entry to fix that but it doesn't work on old office versions.\r\n::  Below code checks that condition and informs the user to update the Office.\r\n\r\nif defined _sublic (\r\nif not exist \"%_oLPath%\\Word2021VL_KMS_Client_AE*.xrm-ms\" (\r\ncall :dk_color %Gray% \"Checking Old Office With Sub License    [Found. Update Office, otherwise, it may show a licensing issue-related banner.]\"\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  mass{}grave{dot}dev/office-license-is-not-genuine\r\n::  Add registry keys for volume products so that 'non-genuine' banner won't appear \r\n::  Script already is using MAK instead of GVLK so it won't appear anyway, but registry keys are added incase Office installs default GVLK grace key for volume products\r\n\r\nset \"kmskey=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\0ff1ce15-a989-479d-af46-f275c6370663\"\r\necho \"%_oIds%\" | find /i \"Volume\" %nul1% && (\r\nif %winbuild% GEQ 9200 (\r\nif not \"%osarch%\"==\"x86\" (\r\nreg delete \"%kmskey%\" /f /reg:32 %nul%\r\nreg add \"%kmskey%\" /f /v KeyManagementServiceName /t REG_SZ /d \"10.0.0.10\" /reg:32 %nul%\r\n)\r\nreg delete \"%kmskey%\" /f %nul%\r\nreg add \"%kmskey%\" /f /v KeyManagementServiceName /t REG_SZ /d \"10.0.0.10\" %nul%\r\necho Adding a Registry to Prevent Banner     [Successful]\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:startmsi\r\n\r\nif defined o14msi call :oh_setspp 14\r\nif defined o14msi call :oh_processmsi 14 %o14msi_reg%\r\ncall :oh_setspp\r\nif defined o15msi call :oh_processmsi 15 %o15msi_reg%\r\nif defined o16msi call :oh_processmsi 16 %o16msi_reg%\r\n\r\n::========================================================================================================================================\r\n\r\ncall :oh_clearblock\r\ncall :oh_uninstkey\r\ncall :oh_licrefresh\r\n\r\n::========================================================================================================================================\r\n\r\necho:\r\nif not defined error (\r\ncall :dk_color %Green% \"Office is permanently activated.\"\r\nif defined ohub call :dk_color %Gray% \"Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app.\"\r\necho Help: %mas%troubleshoot\r\n) else (\r\ncall :dk_color %Red% \"Some errors were detected.\"\r\nif not defined ierror if not defined showfix call :dk_color %Blue% \"%_fixmsg%\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_uninstall\r\n\r\ncls\r\nif not defined terminal mode 145, 32\r\ntitle  Uninstall Ohook Activation %masver%\r\n\r\nset _present=\r\nset _unerror=\r\ncall :oh_reset\r\ncall :oh_getpath\r\n\r\necho:\r\necho Uninstalling Ohook activation...\r\necho:\r\n\r\nif defined o16c2r_reg (for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg% /v InstallPath\" %nul6%') do (set \"_16CHook=%%b\\root\\vfs\"))\r\nif defined o15c2r_reg (for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg% /v InstallPath\" %nul6%') do (set \"_15CHook=%%b\\root\\vfs\"))\r\nif defined o16msi_reg (for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16msi_reg%\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_16MHook=%%b\"))\r\nif defined o15msi_reg (for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15msi_reg%\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_15MHook=%%b\"))\r\nif defined o14msi_reg (for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o14msi_reg%\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_14MHook=%%b\"))\r\n\r\nif defined _16CHook (if exist \"%_16CHook%\\System\\sppc*dll\"    (set _present=1& del /s /f /q \"%_16CHook%\\System\\sppc*dll\"    & if exist \"%_16CHook%\\System\\sppc*dll\"    set _unerror=1))\r\nif defined _16CHook (if exist \"%_16CHook%\\SystemX86\\sppc*dll\" (set _present=1& del /s /f /q \"%_16CHook%\\SystemX86\\sppc*dll\" & if exist \"%_16CHook%\\SystemX86\\sppc*dll\" set _unerror=1))\r\nif defined _15CHook (if exist \"%_15CHook%\\System\\sppc*dll\"    (set _present=1& del /s /f /q \"%_15CHook%\\System\\sppc*dll\"    & if exist \"%_15CHook%\\System\\sppc*dll\"    set _unerror=1))\r\nif defined _15CHook (if exist \"%_15CHook%\\SystemX86\\sppc*dll\" (set _present=1& del /s /f /q \"%_15CHook%\\SystemX86\\sppc*dll\" & if exist \"%_15CHook%\\SystemX86\\sppc*dll\" set _unerror=1))\r\nif defined _16MHook (if exist \"%_16MHook%sppc*dll\"            (set _present=1& del /s /f /q \"%_16MHook%sppc*dll\"            & if exist \"%_16MHook%sppc*dll\"            set _unerror=1))\r\nif defined _15MHook (if exist \"%_15MHook%sppc*dll\"            (set _present=1& del /s /f /q \"%_15MHook%sppc*dll\"            & if exist \"%_15MHook%sppc*dll\"            set _unerror=1))\r\nif defined _14MHook (if exist \"%_14MHook%sppc*dll\"            (set _present=1& del /s /f /q \"%_14MHook%sppc*dll\"            & if exist \"%_14MHook%sppc*dll\"            set _unerror=1))\r\n\r\nfor %%# in (14 15 16) do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft Office\\Office%%#\\sppc*dll\" (set _present=1& del /s /f /q \"%%~A\\Microsoft Office\\Office%%#\\sppc*dll\" & if exist \"%%~A\\Microsoft Office\\Office%%#\\sppc*dll\" set _unerror=1)\r\n)\r\n)\r\n\r\nfor %%# in (System SystemX86) do (\r\nfor %%G in (\"Office 15\" \"Office\") do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft %%~G\\root\\vfs\\%%#\\sppc*dll\" (set _present=1& del /s /f /q \"%%~A\\Microsoft %%~G\\root\\vfs\\%%#\\sppc*dll\" & if exist \"%%~A\\Microsoft %%~G\\root\\vfs\\%%#\\sppc*dll\" set _unerror=1)\r\n)\r\n)\r\n)\r\n\r\n::==================================\r\n\r\nfor %%# in (OSPPC.DLL sppcs.dll) do (\r\nfor %%A in (\"%CommonProgramFiles%\" \"%CommonProgramW6432%\" \"%CommonProgramFiles(x86)%\") do (\r\nfor %%G in (\"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\%%#\") do (\r\nset size=0\r\nset size=%%~zG\r\nif !size! GEQ 1 if !size! LSS 100000 (\r\nset _present=1\r\ndel /f /q \"%%~G\"\r\nif exist \"%%~G\" (move /y \"%%~G\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%)\r\nif exist \"%%~G\" (set _unerror=1) else (echo Deleted file - %%~G)\r\n)\r\nif /i sppcs.dll==%%# if !size! GEQ 100000 (\r\nmove /y \"%%~G\" \"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\OSPPC.DLL\" %nul%\r\nif exist \"%%~G\" (move /y \"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\OSPPC.DLL\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%)\r\nmove /y \"%%~G\" \"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\OSPPC.DLL\" %nul%\r\nif exist \"%%~G\" (set _unerror=1&echo Failed to rename sppcs.dll back to \"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\OSPPC.DLL\") else (echo Renamed sppcs.dll back to \"%%~A\\Microsoft Shared\\OfficeSoftwareProtectionPlatform\\OSPPC.DLL\")\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==================================\r\n\r\nreg query HKCU\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency %nul% && (\r\necho:\r\necho Deleting - Registry keys for skipping license check\r\n\r\nreg load HKU\\DEF_TEMP %SystemDrive%\\Users\\Default\\NTUSER.DAT %nul%\r\nreg query HKU\\DEF_TEMP\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency %nul% && reg delete HKU\\DEF_TEMP\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /f\r\nreg unload HKU\\DEF_TEMP %nul%\r\n\r\nset _sidlist=\r\nfor /f \"tokens=* delims=\" %%a in ('%psc% \"$p = 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty \"\"\"\"$p\\$($_.PSChildName)\"\"\"\").ProfileImagePath; if ($pi -like '*\\Users\\*' -and (Test-Path \"\"\"\"$pi\\NTUSER.DAT\"\"\"\") -and -not ($_.PSChildName -match '\\.bak$')) { Split-Path $_.PSPath -Leaf } }\" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))\r\n\r\nif not defined _sidlist (\r\nfor /f \"delims=\" %%a in ('%psc% \"$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid\" %nul6%') do (set _sidlist=%%a)\r\n)\r\n\r\nfor %%# in (!_sidlist!) do (\r\n\r\nreg query HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency %nul% && reg delete HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /f\r\n\r\nreg query HKU\\%%#\\Software %nul% || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nreg load HKU\\%%# \"%%b\\NTUSER.DAT\" %nul%\r\nreg query HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency %nul% && reg delete HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /f\r\nreg unload HKU\\%%# %nul%\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==================================\r\n\r\nset \"kmskey=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\0ff1ce15-a989-479d-af46-f275c6370663\"\r\nreg query \"%kmskey%\" %nul% && (\r\necho:\r\necho Deleting - Registry keys for preventing non-genuine banner\r\nreg delete \"%kmskey%\" /f\r\n)\r\n\r\nreg query \"%kmskey%\" /reg:32 %nul% && (\r\nreg delete \"%kmskey%\" /f /reg:32\r\n)\r\n\r\necho __________________________________________________________________________________________\r\necho:\r\n\r\nif not defined _present (\r\necho Ohook activation is not installed.\r\n) else (\r\nif defined _unerror (\r\ncall :dk_color %Red% \"Failed to uninstall Ohook activation.\"\r\ncall :oh_checkapps\r\nif defined checknames (\r\ncall :dk_color %Blue% \"Close [!checknames!] and try again.\"\r\ncall :dk_color %Blue% \"If it is still not fixed, reboot your machine using the restart option and try again.\"\r\n) else (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\n)\r\n) else (\r\ncall :dk_color %Green% \"Successfully uninstalled Ohook activation.\"\r\n)\r\n)\r\necho __________________________________________________________________________________________\r\n\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_reset\r\n\r\nset key=\r\nset _oRoot=\r\nset _oArch=\r\nset _oIds=\r\nset _oLPath=\r\nset _hookPath=\r\nset _hook=\r\nset _sppcPath=\r\nset _osppPath=\r\nset _actid=\r\nset _prod=\r\nset _lic=\r\nset _arr=\r\nset _prids=\r\nset _config=\r\nset _version=\r\nset _License=\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_getpath\r\n\r\nset o16c2r=\r\nset o15c2r=\r\nset o16msi=\r\nset o15msi=\r\nset o14msi=\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set o16c2r=1&set o16c2r_reg=%_86%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set o16c2r=1&set o16c2r_reg=%_68%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set o15c2r=1&set o15c2r_reg=%_86%\\15.0\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set o15c2r=1&set o15c2r_reg=%_68%\\15.0\\ClickToRun)\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o16msi=1&set o16msi_reg=%_86%\\16.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o16msi=1&set o16msi_reg=%_68%\\16.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o15msi=1&set o15msi_reg=%_86%\\15.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o15msi=1&set o15msi_reg=%_68%\\15.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=1&set o14msi_reg=%_86%\\14.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=1&set o14msi_reg=%_68%\\14.0)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_expiredpreview\r\n\r\necho %_oIds% | find /i \"Volume\" %nul% || exit /b\r\n\r\nfor %%# in (%*) do (\r\nif %%#==2013 set _offver=\r\nif %%#==2016 set _offver=\r\nif %%#==2019 set _offver=2019\r\nif %%#==2021 set _offver=2021\r\nif %%#==2024 set _offver=2024\r\nif exist \"!_oLPath!\\ProPlus!_offver!PreviewVL_*.xrm-ms\" if not exist \"!_oLPath!\\ProPlus!_offver!VL_*.xrm-ms\" (\r\nset error=1\r\nset showfix=1\r\ncall :dk_color %Red% \"Checking Expired Preview Products       [Office %%# Preview Found]\"\r\ncall :dk_color %Blue% \"Please run the Office updates first, and then attempt to activate it again.\"\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_ppcpath\r\n\r\nif not defined isOspp (\r\nif not \"%osarch%\"==\"x86\" (\r\nif /i \"%_oArch%\"==\"x64\" set \"_sppcPath=%SystemRoot%\\System32\\sppc.dll\"\r\nif /i \"%_oArch%\"==\"x86\" set \"_sppcPath=%SystemRoot%\\SysWOW64\\sppc.dll\"\r\n) else (\r\nset \"_sppcPath=%SystemRoot%\\System32\\sppc.dll\"\r\n)\r\n)\r\n\r\nset noOsppc=\r\nset _hook68=\r\nset _hook86=\r\nset _osppPath68=\r\nset _osppPath86=\r\n\r\nif defined isOspp (\r\nif not \"%osarch%\"==\"x86\" (\r\nif /i \"%_oArch%\"==\"x64\" (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform /v Path\" %nul6%') do (set \"_osppPath68=%%b\")\r\nif not exist \"!_osppPath68!OSPPC.DLL\" set noOsppc=1\r\n)\r\nif /i \"%_oArch%\"==\"x86\" (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform /v Path\" %nul6%') do (set \"_osppPath68=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\OfficeSoftwareProtectionPlatform /v Path\" %nul6%') do (set \"_osppPath86=%%b\")\r\nif not exist \"!_osppPath68!OSPPC.DLL\" set noOsppc=1\r\nif not exist \"!_osppPath86!OSPPC.DLL\" set noOsppc=1\r\n)\r\n) else (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform /v Path\" %nul6%') do (set \"_osppPath86=%%b\")\r\nif not exist \"!_osppPath86!OSPPC.DLL\" set noOsppc=1\r\n)\r\nif \"!_osppPath68:~-1!\"==\"\\\" set \"_osppPath68=!_osppPath68:~0,-1!\"\r\nif \"!_osppPath86:~-1!\"==\"\\\" set \"_osppPath86=!_osppPath86:~0,-1!\"\r\n)\r\n\r\nif defined _osppPath68 set _hook68=sppc64.dll\r\nif defined _osppPath86 set _hook86=sppc32.dll\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Some Office Retail to Volume converter tools may edit the ProductReleaseIds to add VL products. This code restores it because it may affect features.\r\n\r\n:oh_fixprids\r\n\r\nif not defined _prids (\r\ncall :dk_color %Gray% \"Checking ProductReleaseIds In Registry  [Not Found]\"\r\nexit /b\r\n)\r\n\r\nset _pridsR=\r\nset _pridsE=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_prids%\" %nul6%') do (set \"_pridsR=%%b\")\r\n\r\nset _pridsR=%_pridsR:,= %\r\nfor %%# in (%_pridsR%) do (echo %%# | findstr /I \"%_oIds%\" %nul1% || set _pridsE=1)\r\nfor %%# in (%_oIds%) do (echo %%# | findstr /I \"%_pridsR%\" %nul1% || set _pridsE=1)\r\n\r\nif not defined _pridsE exit /b\r\nreg add %_prids% /t REG_SZ /d \"\" /f %nul1%\r\n\r\nfor %%# in (%_oIds%) do (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query %_prids%') do if not \"%%b\"==\"\" (\r\nreg add %_prids% /t REG_SZ /d \"%%b,%%#\" /f %nul1%\r\n) else (\r\nreg add %_prids% /t REG_SZ /d \"%%#\" /f %nul1%\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_installlic\r\n\r\nif not defined _oLPath exit /b\r\n\r\nif defined _oIntegrator (\r\nif %oVer%==16 (\r\n\"!_oIntegrator!\" /I /License PRIDName=%_License%.16 PidKey=%key% %nul%\r\n) else (\r\n\"!_oIntegrator!\" /I /License PRIDName=%_License% PidKey=%key% %nul%\r\n)\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% && exit /b\r\n)\r\n\r\n::  Fallback to manual method to install licenses incase integrator.exe is not working\r\n\r\nset _License=%_License:XVolume=XC2RVL_%\r\n\r\nset _License=%_License:O365EduCloudRetail=O365EduCloudEDUR_%\r\n\r\nset _License=%_License:ProjectProRetail=ProjectProO365R_%\r\nset _License=%_License:ProjectStdRetail=ProjectStdO365R_%\r\nset _License=%_License:VisioProRetail=VisioProO365R_%\r\nset _License=%_License:VisioStdRetail=VisioStdO365R_%\r\n\r\nif defined _preview set _License=%_License:Volume=PreviewVL_%\r\n\r\nset _License=%_License:Retail=R_%\r\nset _License=%_License:Volume=VL_%\r\n\r\nfor %%# in (\"!_oLPath!\\client-issuance-*.xrm-ms\") do (\r\nif defined _arr (set \"_arr=!_arr!;\"!_oLPath!\\%%~nx#\"\") else (set \"_arr=\"!_oLPath!\\%%~nx#\"\")\r\n)\r\n\r\nfor %%# in (\"!_oLPath!\\%_License%*.xrm-ms\") do (\r\nif defined _arr (set \"_arr=!_arr!;\"!_oLPath!\\%%~nx#\"\") else (set \"_arr=\"!_oLPath!\\%%~nx#\"\")\r\n)\r\n\r\n%psc% \"$sls = Get-WmiObject %sps%; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); InstallLicenseArr '!_arr!'; InstallLicenseFile '\"!_oLPath!\\pkeyconfig-office.xrm-ms\"'\" %nul%\r\n\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% || (\r\nset error=1\r\ncall :dk_color %Red% \"Installing Missing License Files        [Office %oVer%.0 %_prod%] [Failed]\"\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_hookinstall\r\n\r\nset ierror=\r\nset hasherror=\r\n\r\nif %_hook%==sppc32.dll set offset=2564\r\nif %_hook%==sppc64.dll set offset=3076\r\n\r\n::======================================\r\n\r\n::  Remove previous Install\r\n\r\nfor %%# in (sppcs.dll sppc.dll) do (\r\ndel /f /q \"%_hookPath%\\%%#\" %nul%\r\nif exist \"%_hookPath%\\%%#\" (move /y \"%_hookPath%\\%%#\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%)\r\nif exist \"%_hookPath%\\%%#\" (set \"ierror=Remove Previous Ohook Install [%%#]\")\r\n)\r\n\r\nif defined ierror goto :oh_hookinstall_error\r\n\r\n::======================================\r\n\r\nmklink \"%_hookPath%\\sppcs.dll\" \"%_sppcPath%\" %nul%\r\nif not exist \"%_hookPath%\\sppcs.dll\" (\r\nset ierror=mklink sppcs.dll\r\ngoto :oh_hookinstall_error\r\n)\r\n\r\nset exhook=\r\nif exist \"!_work!\\BIN\\%_hook%\" set exhook=1\r\n\r\nif not exist \"%_hookPath%\\sppc.dll\" (\r\nif defined exhook (\r\npushd \"!_work!\\BIN\\\"\r\ncopy /y /b \"%_hook%\" \"%_hookPath%\\sppc.dll\" %nul%\r\npopd\r\n) else (\r\ncall :oh_extractdll \"%_hookPath%\\sppc.dll\" \"%offset%\"\r\n)\r\n)\r\nif not exist \"%_hookPath%\\sppc.dll\" (\r\nset ierror=Copy\r\ngoto :oh_hookinstall_error\r\n)\r\n\r\necho:\r\necho Symlinking System's sppc.dll            [\"%_hookPath%\\sppcs.dll\"] [Successful]\r\nif defined exhook (\r\necho Copying Custom %_hook% to            [\"%_hookPath%\\sppc.dll\"] [Successful]\r\n) else (\r\necho Extracting Custom %_hook% to         [\"%_hookPath%\\sppc.dll\"] [Successful]\r\n)\r\n\r\ngoto :oh_hookinstall_error\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_hookinstall_ospp\r\n\r\nset ierror=\r\nset hasherror=\r\n\r\nif defined _hook86 set offset86=2564\r\nif defined _hook68 set offset68=3076\r\n\r\n::======================================\r\n\r\n::  Remove previous Install\r\n\r\nfor %%# in (OSPPC.DLL sppcs.dll) do (\r\nfor %%A in (\"%_osppPath68%\\%%#\" \"%_osppPath86%\\%%#\") do (\r\nset size=0\r\nset size=%%~zA\r\nif !size! GEQ 1 if !size! LSS 100000 (\r\ndel /f /q \"%%~A\" %nul%\r\nif exist \"%%~A\" (move /y \"%%~A\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%)\r\nif exist \"%%~A\" (set \"ierror=Remove Previous Ohook Install [%%#]\")\r\n)\r\n)\r\n)\r\n\r\nif defined ierror goto :oh_hookinstall_error\r\n\r\nfor %%A in (\"%_osppPath68%\" \"%_osppPath86%\") do (\r\nif exist \"%%~A\\sppcs.dll\" (move /y \"%%~A\\sppcs.dll\" \"%%~A\\OSPPC.DLL\" %nul%)\r\nif exist \"%%~A\\sppcs.dll\" (\r\nmove /y \"%%~A\\OSPPC.DLL\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%\r\nmove /y \"%%~A\\sppcs.dll\" \"%%~A\\OSPPC.DLL\" %nul%\r\n)\r\nif exist \"%%~A\\sppcs.dll\" (set \"ierror=Move sppcs.dll back to OSPPC.DLL\")\r\n)\r\n\r\ndel /f /q \"%_hookPath%\\sppcs.dll\" %nul%\r\nif exist \"%_hookPath%\\sppcs.dll\" (move /y \"%_hookPath%\\sppcs.dll\" \"!_ttemp!\\needsToBeDeleted%random%\" %nul%)\r\nif exist \"%_hookPath%\\sppcs.dll\" (set \"ierror=Remove Previous Ohook mklink sppcs.dll\")\r\n\r\nif defined ierror goto :oh_hookinstall_error\r\n\r\n::======================================\r\n\r\nif defined _osppPath68 (move /y \"%_osppPath68%\\OSPPC.DLL\" \"%_osppPath68%\\sppcs.dll\" %nul% & if not exist \"%_osppPath68%\\sppcs.dll\" set ierror=1)\r\nif defined _osppPath86 (move /y \"%_osppPath86%\\OSPPC.DLL\" \"%_osppPath86%\\sppcs.dll\" %nul% & if not exist \"%_osppPath86%\\sppcs.dll\" set ierror=1)\r\n\r\nif defined ierror (\r\nset \"ierror=Rename OSPPC.DLL\"\r\ngoto :oh_hookinstall_error\r\n)\r\n\r\nif defined _osppPath68 if defined _osppPath86     (mklink \"%_hookPath%\\sppcs.dll\" \"%_osppPath86%\\sppcs.dll\" %nul%)\r\nif defined _osppPath68 if not defined _osppPath86 (mklink \"%_hookPath%\\sppcs.dll\" \"%_osppPath68%\\sppcs.dll\" %nul%)\r\nif defined _osppPath86 if not defined _osppPath68 (mklink \"%_hookPath%\\sppcs.dll\" \"%_osppPath86%\\sppcs.dll\" %nul%)\r\n\r\nif not exist \"%_hookPath%\\sppcs.dll\" (\r\nset ierror=mklink sppcs.dll\r\ngoto :oh_hookinstall_error\r\n)\r\n\r\nset exhook=\r\nif exist \"!_work!\\BIN\\%_hook68%\" if exist \"!_work!\\BIN\\%_hook86%\"  set exhook=1\r\n\r\nif defined exhook (\r\npushd \"!_work!\\BIN\\\"\r\nif defined _osppPath68 (copy /y /b \"%_hook68%\" \"%_osppPath68%\\OSPPC.DLL\" %nul%)\r\nif defined _osppPath86 (copy /y /b \"%_hook86%\" \"%_osppPath86%\\OSPPC.DLL\" %nul%)\r\npopd\r\n) else (\r\nif defined _osppPath68 (set _hook=%_hook68%&call :oh_extractdll \"%_osppPath68%\\OSPPC.DLL\" \"%offset68%\")\r\nif defined _osppPath86 (set _hook=%_hook86%&call :oh_extractdll \"%_osppPath86%\\OSPPC.DLL\" \"%offset86%\")\r\n)\r\n\r\nif defined _osppPath68 (if not exist \"%_osppPath68%\\OSPPC.DLL\" set ierror=1)\r\nif defined _osppPath86 (if not exist \"%_osppPath86%\\OSPPC.DLL\" set ierror=1)\r\n\r\nif defined ierror (\r\nset ierror=Copy\r\ngoto :oh_hookinstall_error\r\n)\r\n\r\necho:\r\nif defined _osppPath68 (echo Renaming OSPPC.DLL to sppcs.dll         [\"%_osppPath68%\\sppcs.dll\"])\r\nif defined _osppPath86 (echo Renaming OSPPC.DLL to sppcs.dll         [\"%_osppPath86%\\sppcs.dll\"])\r\nif defined exhook (\r\nif defined _osppPath68 (echo Copying Custom %_hook68% to            [\"%_osppPath68%\\OSPPC.DLL\"])\r\nif defined _osppPath86 (echo Copying Custom %_hook86% to            [\"%_osppPath86%\\OSPPC.DLL\"])\r\n) else (\r\nif defined _osppPath68 (echo Extracting Custom %_hook68% to         [\"%_osppPath68%\\OSPPC.DLL\"])\r\nif defined _osppPath86 (echo Extracting Custom %_hook86% to         [\"%_osppPath86%\\OSPPC.DLL\"])\r\n)\r\n\r\necho Symlinking Renamed sppcs.dll            [\"%_hookPath%\\sppcs.dll\"]\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_hookinstall_error\r\n\r\nif defined ierror (\r\nset error=1\r\ncall :dk_color %Red% \"Installing Ohook                        [Failed to %ierror%]\"\r\necho:\r\ncall :oh_checkapps\r\nif defined checknames (\r\ncall :dk_color %Blue% \"Close [!checknames!] and try again.\"\r\ncall :dk_color %Blue% \"If it is still not fixed, reboot your machine using the restart option and try again.\"\r\n) else (\r\nif /i not \"%ierror%\"==\"Copy\" call :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\nif /i \"%ierror%\"==\"Copy\" call :dk_color %Blue% \"If you are using any third-party antivirus, check if it is blocking the script.\"\r\n)\r\necho:\r\n)\r\n\r\nif not defined exhook if not defined ierror (\r\nif defined hasherror (\r\nset error=1\r\nset ierror=1\r\ncall :dk_color %Red% \"Modifying Hash of Custom sppcs.dll      [Failed]\"\r\n) else (\r\necho Modifying Hash of Custom sppcs.dll      [Successful]\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_setspp\r\n\r\nset isOspp=\r\nif %winbuild% GEQ 9200 (\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n) else (\r\nset isOspp=1\r\nset spp=OfficeSoftwareProtectionProduct\r\nset sps=OfficeSoftwareProtectionService\r\n)\r\nif \"%1\"==\"14\" (\r\nset isOspp=1\r\nset spp=OfficeSoftwareProtectionProduct\r\nset sps=OfficeSoftwareProtectionService\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_process\r\n\r\nfor %%# in (%_oIds%) do (\r\n\r\nset key=\r\nset _actid=\r\nset _lic=\r\nset _preview=\r\nset _License=%%#\r\n\r\necho %%# | find /i \"2024\" %nul% && (\r\nif exist \"!_oLPath!\\ProPlus2024PreviewVL_*.xrm-ms\" if not exist \"!_oLPath!\\ProPlus2024VL_*.xrm-ms\" set _preview=-Preview\r\n)\r\nset _prod=%%#!_preview!\r\n\r\ncall :ohookdata getinfo !_prod!\r\n\r\nif not \"!key!\"==\"\" (\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% || call :oh_installlic\r\nif not %oVer%==14 set generickey=1\r\ncall :dk_inskey \"[!key!] [!_prod!] [!_lic!]\"\r\n) else (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Product In Script              [Office %oVer%.0 !_prod! key not found in script]\"\r\ncall :dk_color %Blue% \"Make sure you are using the latest version of MAS.\"\r\nset fixes=%fixes% %mas%\r\ncall :dk_color %_Yellow% \"%mas%\"\r\n)\r\n)\r\n\r\n::  Add SharedComputerLicensing registry key if Retail Office C2R is installed on Windows Server\r\n::  https://learn.microsoft.com/en-us/office/troubleshoot/office-suite-issues/click-to-run-office-on-terminal-server\r\n\r\nif defined winserver if defined _config if exist \"%_oLPath%\\Word2019VL_KMS_Client_AE*.xrm-ms\" (\r\necho %_oIds% | find /i \"Retail\" %nul1% && (\r\nset scaIsNeeded=1\r\nreg add %_config% /v SharedComputerLicensing /t REG_SZ /d \"1\" /f %nul1%\r\necho Adding SharedComputerLicensing Reg      [Successful] [Needed on Server With Retail Office]\"\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_processmsi\r\n\r\n::  Process Office MSI Version\r\n\r\ncall :oh_reset\r\nif \"%1\"==\"14\" (\r\ncall :dk_actids 59a52881-a989-479d-af46-f275c6370663\r\n) else (\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n)\r\n\r\nset oVer=%1\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_oRoot=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\ProductVersion /v LastProduct\" %nul6%') do (set \"_version=%%b\")\r\nif \"%_oRoot:~-1%\"==\"\\\" set \"_oRoot=%_oRoot:~0,-1%\"\r\n\r\necho \"%2\" | find /i \"Wow6432Node\" %nul1% && set _oArch=x86\r\nif not \"%osarch%\"==\"x86\" if not defined _oArch set _oArch=x64\r\nif \"%osarch%\"==\"x86\" set _oArch=x86\r\n\r\nif /i \"%_oArch%\"==\"x64\" (set \"_hookPath=%_oRoot%\" & set \"_hook=sppc64.dll\")\r\nif /i \"%_oArch%\"==\"x86\" (set \"_hookPath=%_oRoot%\" & set \"_hook=sppc32.dll\")\r\n\r\ncall :oh_ppcpath\r\n\r\ncall :msiofficedata %2\r\n\r\necho:\r\necho Activating Office...                    [MSI ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found, aborting activation...]\"\r\nexit /b\r\n)\r\n\r\nif defined noOsppc (\r\ncall :dk_color %Red% \"Checking OSPPC.DLL                      [Not found. Aborting activation...]\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\nset error=1\r\nexit /b\r\n)\r\n\r\nif %oVer%==14 if defined SingleImage (\r\necho Checking Installed Products             [SingleImage product found, Professional Retail key will be used for activation]\r\n)\r\n\r\ncall :oh_process\r\nif defined isOspp (\r\ncall :oh_hookinstall_ospp\r\n) else (\r\ncall :oh_hookinstall\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_clearblock\r\n\r\n::  Find remnants of Office vNext/shared/device license block and remove it because it stops other licenses from appearing\r\n::  https://learn.microsoft.com/en-us/office/troubleshoot/activation/reset-office-365-proplus-activation-state\r\n\r\nset _sidlist=\r\nfor /f \"tokens=* delims=\" %%a in ('%psc% \"$p = 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty \"\"\"\"$p\\$($_.PSChildName)\"\"\"\").ProfileImagePath; if ($pi -like '*\\Users\\*' -and (Test-Path \"\"\"\"$pi\\NTUSER.DAT\"\"\"\") -and -not ($_.PSChildName -match '\\.bak$')) { Split-Path $_.PSPath -Leaf } }\" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))\r\n\r\nif not defined _sidlist (\r\nfor /f \"delims=\" %%a in ('%psc% \"$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid\" %nul6%') do (set _sidlist=%%a)\r\n)\r\n\r\n::==========================\r\n\r\n::  Load the unloaded useraccounts registry\r\n\r\nset loadedsids=\r\nset alrloadedsids=\r\n\r\nfor %%# in (%_sidlist%) do (\r\nreg query HKU\\%%#\\Software %nul% && (\r\ncall set \"alrloadedsids=%%alrloadedsids%% %%#\"\r\n) || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nreg load HKU\\%%# \"%%b\\NTUSER.DAT\" %nul%\r\nreg query HKU\\%%#\\Software %nul% && (\r\ncall set \"loadedsids=%%loadedsids%% %%#\"\r\n) || (\r\nreg unload HKU\\%%# %nul%\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==========================\r\n\r\nset \"_sidlist=%loadedsids% %alrloadedsids%\"\r\n\r\nset /a counter=0\r\nfor %%# in (%_sidlist%) do set /a counter+=1\r\n\r\nif %counter% EQU 0 (\r\nset error=1\r\ncall :dk_color %Red% \"Checking User Accounts SID              [Not Found]\"\r\nexit /b\r\n)\r\n\r\nif %counter% GTR 10 (\r\ncall :dk_color %Gray% \"Checking Total User Accounts            [%counter%]\"\r\n)\r\n\r\n::==========================\r\n\r\n::  Clear the vNext/shared/device license blocks which may prevent ohook activation\r\n\r\nset vnextexist=\r\nrmdir /s /q \"%ProgramData%\\Microsoft\\Office\\Licenses\\\" %nul%\r\n\r\nfor %%x in (15 16) do (\r\nfor %%# in (%_sidlist%) do (\r\nreg query HKU\\%%#\\Software\\Microsoft\\Office\\%%x.0\\Common\\Licensing /s %nul2% | findstr /i \"CIDToLicenseIdsMapping LicenseIdToEmailMapping @\" %nul% && set vnextexist=1\r\nreg delete HKU\\%%#\\Software\\Microsoft\\Office\\%%x.0\\Common\\Licensing /f %nul%\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nrmdir /s /q \"%%b\\AppData\\Local\\Microsoft\\Office\\Licenses\\\" %nul%\r\nrmdir /s /q \"%%b\\AppData\\Local\\Microsoft\\Office\\%%x.0\\Licensing\\\" %nul%\r\n)\r\n)\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f /reg:32 %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f /reg:32 %nul%\r\n)\r\n\r\n::  Clear vNext in UWP Office\r\n\r\nif defined o16uwpapplist (\r\nfor %%# in (%_sidlist%) do (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nrmdir /s /q \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\LocalCache\\Local\\Microsoft\\Office\\Licenses\\\" %nul%\r\nif exist \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\SystemAppData\\Helium\\User.dat\" (\r\nset defname=DEFTEMP-%%#\r\nreg load HKU\\!defname! \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\SystemAppData\\Helium\\User.dat\" %nul%\r\nreg query HKU\\!defname!\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing /s %nul2% | findstr /i \"CIDToLicenseIdsMapping LicenseIdToEmailMapping @\" %nul% && set vnextexist=1\r\nreg delete HKU\\!defname!\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing /f %nul%\r\nreg unload HKU\\!defname! %nul%\r\n)\r\n)\r\n)\r\n)\r\n\r\nif defined vnextexist (\r\necho:\r\ncall :dk_color %Gray% \"The logged-in Office account has a subscription license.\"\r\ncall :dk_color %Blue% \"If the subscription is active, it overrides other activation methods.\"\r\ncall :dk_color %Blue% \"If it is expiring soon, rerun the activation script after it expires.\"\r\ncall :dk_color2 %Blue% \"If it has already expired and activation fails, get help here - \" %_Yellow% \" %mas%troubleshoot\"\r\necho:\r\n)\r\n\r\n::  Clear SharedComputerLicensing for office\r\n::  https://learn.microsoft.com/en-us/deployoffice/overview-shared-computer-activation\r\n\r\nif not defined scaIsNeeded (\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration /v SharedComputerLicensing /f %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration /v SharedComputerLicensing /f /reg:32 %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\15.0\\ClickToRun\\Configuration /v SharedComputerLicensing /f %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\15.0\\ClickToRun\\Configuration /v SharedComputerLicensing /f /reg:32 %nul%\r\n)\r\n\r\n::  Clear device-based-licensing\r\n::  https://learn.microsoft.com/en-us/deployoffice/device-based-licensing\r\n\r\nfor /f %%# in ('reg query \"%o16c2r_reg%\\Configuration\" /f *.DeviceBasedLicensing %nul6% ^| findstr REG_') do reg delete \"%o16c2r_reg%\\Configuration\" /v %%# /f %nul%\r\n\r\n::  Remove OEM registry key\r\n::  https://support.microsoft.com/en-us/office/office-repeatedly-prompts-you-to-activate-on-a-new-pc-a9a6b05f-f6ce-4d1f-8d49-eb5007b64ba1\r\n\r\nfor %%# in (15 16) do (\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%#.0\\Common\\OEM\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%#.0\\Common\\OEM\" /f /reg:32 %nul%\r\n)\r\n\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\\0ff1ce15-a989-479d-af46-f275c6370663\" /f %nul%\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\OfficeSoftwareProtectionPlatform\\Policies\\0ff1ce15-a989-479d-af46-f275c6370663\" /f %nul%\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\OfficeSoftwareProtectionPlatform\\Policies\\59a52881-a989-479d-af46-f275c6370663\" /f %nul%\r\n\r\necho Clearing Office License Blocks          [Successfully cleared from all %counter% user accounts]\r\n\r\n::==========================\r\n\r\n::  Some retail products attempt to validate the license and may show a banner \"There was a problem checking this device's license status.\"\r\n::  Resiliency registry entry can skip this check\r\n\r\nset defname=DEFTEMP-%random%\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\" /v Default\" %nul6%') do call set \"defdat=%%b\"\r\n\r\nif defined o16c2r if defined ohookact (\r\nif exist \"%defdat%\\NTUSER.DAT\" (\r\nreg load HKU\\%defname% \"%defdat%\\NTUSER.DAT\" %nul%\r\nreg query HKU\\%defname%\\Software %nul% && (\r\nreg add HKU\\%defname%\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /v \"TimeOfLastHeartbeatFailure\" /t REG_SZ /d \"2040-01-01T00:00:00Z\" /f %nul%\r\n)\r\nreg unload HKU\\%defname% %nul%\r\n)\r\n\r\nfor %%# in (%_sidlist%) do (\r\nreg delete HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /f %nul%\r\nreg add HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /v \"TimeOfLastHeartbeatFailure\" /t REG_SZ /d \"2040-01-01T00:00:00Z\" /f %nul%\r\n)\r\necho Adding Registry to Skip License Check   [Successfully added to all %counter% ^& future new user accounts]\r\n)\r\n\r\n::==========================\r\n\r\n::  Unload the loaded useraccounts registry\r\n\r\nfor %%# in (%loadedsids%) do (\r\nreg unload HKU\\%%# %nul%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Uninstall other / grace Keys\r\n\r\n:oh_uninstkey\r\n\r\nset upk_result=0\r\ncall :dk_actid 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nif \"%_actprojvis%\"==\"1\" (\r\nfor /f \"delims=\" %%a in ('%psc% \"Get-WmiObject -Query 'SELECT ID, Description, LicenseFamily FROM %spp% WHERE ApplicationID=''0ff1ce15-a989-479d-af46-f275c6370663'' AND PartialProductKey IS NOT NULL' | Where-Object { $_.LicenseFamily -notmatch 'Project' -and $_.LicenseFamily -notmatch 'Visio' } | Select-Object -ExpandProperty ID\" %nul6%') do call set \"_allactid=%%a !_allactid!\"\r\nfor /f \"delims=\" %%a in ('%psc% \"Get-WmiObject -Query 'SELECT ID, Description, LicenseFamily FROM %spp% WHERE ApplicationID=''0ff1ce15-a989-479d-af46-f275c6370663'' AND PartialProductKey IS NOT NULL' | Where-Object { '!_allactid!' -contains $_.ID -and ($_.LicenseFamily -match 'Project' -or $_.LicenseFamily -match 'Visio') } | Select-Object -ExpandProperty ID\" %nul6%') do call set \"_allactid=%%a !_allactid!\"\r\n)\r\n\r\nfor %%# in (%apps%) do (\r\necho \"%_allactid%\" | find /i \"%%#\" %nul1% || (\r\n\r\nif %_wmic% EQU 1 wmic path %spp% where ID='%%#' call UninstallProductKey %nul%\r\nif %_wmic% EQU 0 %psc% \"$null=([WMI]'%spp%=''%%#''').UninstallProductKey()\" %nul%\r\n\r\nif !errorlevel!==0 (\r\nset upk_result=1\r\n) else (\r\nset error=1\r\nset upk_result=2\r\n)\r\n)\r\n)\r\n\r\nif defined ohookact if not %upk_result%==0 echo:\r\nif %upk_result%==1 echo Uninstalling Other/Grace Keys           [Successful]\r\nif %upk_result%==2 (\r\ncall :dk_color %Red% \"Uninstalling Other/Grace Keys           [Failed]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\nset showfix=1\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Refresh Windows Insider Preview Licenses\r\n::  It required in Insider versions otherwise office may not activate\r\n\r\n:oh_licrefresh\r\n\r\nif exist \"%SysPath%\\spp\\store_test\\2.0\\tokens.dat\" (\r\n%psc% \"Stop-Service sppsvc -force; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif !errorlevel! NEQ 0 %psc% \"$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check running office apps and notify user\r\n\r\n:oh_checkapps\r\n\r\nset checkapps=\r\nset checknames=\r\nfor /f \"tokens=1\" %%i in ('tasklist ^| findstr /I \".exe\" %nul6%') do (set \"checkapps=!checkapps! -%%i-\")\r\n\r\nfor %%# in (\r\nAccess_msaccess.exe\r\nExcel_excel.exe\r\nGroove_groove.exe\r\nLync_lync.exe\r\nOneNote_onenote.exe\r\nOutlook_outlook.exe\r\nPowerPoint_powerpnt.exe\r\nProject_winproj.exe\r\nPublisher_mspub.exe\r\nVisio_visio.exe\r\nWord_winword.exe\r\nLime_lime.exe\r\n) do (\r\nfor /f \"tokens=1-2 delims=_\" %%A in (\"%%#\") do (\r\necho !checkapps! | find /i \"-%%B-\" %nul1% && (if defined checknames (set \"checknames=!checknames! %%A\") else (set \"checknames=%%A\"))\r\n)\r\n)\r\nexit /b\r\n\r\n::  Set variables\r\n\r\n:dk_setvar\r\n\r\nset ps=%SysPath%\\WindowsPowerShell\\v1.0\\powershell.exe\r\nset psc=%ps% -nop -c\r\nset winbuild=1\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset _NCS=1\r\nif %winbuild% LSS 10586 set _NCS=0\r\nif %winbuild% GEQ 10586 reg query \"HKCU\\Console\" /v ForceV2 %nul2% | find /i \"0x0\" %nul1% && (set _NCS=0)\r\n\r\necho \"%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%\" | find /i \"ARM64\" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)\r\n\r\nif %_NCS% EQU 1 (\r\nfor /F %%a in ('echo prompt $E ^| cmd') do set \"esc=%%a\"\r\nset     \"Red=\"41;97m\"\"\r\nset    \"Gray=\"100;97m\"\"\r\nset   \"Green=\"42;97m\"\"\r\nset    \"Blue=\"44;97m\"\"\r\nset   \"White=\"107;91m\"\"\r\nset    \"_Red=\"40;91m\"\"\r\nset  \"_White=\"40;37m\"\"\r\nset  \"_Green=\"40;92m\"\"\r\nset \"_Yellow=\"40;93m\"\"\r\n) else (\r\nset     \"Red=\"Red\" \"white\"\"\r\nset    \"Gray=\"Darkgray\" \"white\"\"\r\nset   \"Green=\"DarkGreen\" \"white\"\"\r\nset    \"Blue=\"Blue\" \"white\"\"\r\nset   \"White=\"White\" \"Red\"\"\r\nset    \"_Red=\"Black\" \"Red\"\"\r\nset  \"_White=\"Black\" \"Gray\"\"\r\nset  \"_Green=\"Black\" \"Green\"\"\r\nset \"_Yellow=\"Black\" \"Yellow\"\"\r\n)\r\n\r\nset \"nceline=echo: &echo ==== ERROR ==== &echo:\"\r\nset \"eline=echo: &call :dk_color %Red% \"==== ERROR ====\" &echo:\"\r\nif %~z0 GEQ 200000 (\r\nset \"_exitmsg=Go back\"\r\nset \"_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option.\"\r\n) else (\r\nset \"_exitmsg=Exit\"\r\nset \"_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option.\"\r\n)\r\nexit /b\r\n\r\n::  Show OS info\r\n\r\n:dk_showosinfo\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\" /v PROCESSOR_ARCHITECTURE') do set osarch=%%b\r\n\r\nfor /f \"tokens=6-7 delims=[]. \" %%i in ('ver') do if not \"%%j\"==\"\" (\r\nset fullbuild=%%i.%%j\r\n) else (\r\nfor /f \"tokens=3\" %%G in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR\" %nul6%') do if not errorlevel 1 set /a \"UBR=%%G\"\r\nfor /f \"skip=2 tokens=3,4 delims=. \" %%G in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildLabEx') do (\r\nif defined UBR (set \"fullbuild=%%G.!UBR!\") else (set \"fullbuild=%%G.%%H\")\r\n)\r\n)\r\n\r\necho Checking OS Info                        [%winos% ^| %fullbuild% ^| %osarch%]\r\nexit /b\r\n\r\n::  Refresh license status\r\n\r\n:dk_refresh\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call RefreshLicenseStatus %nul%\r\nif %_wmic% EQU 0 %psc% \"$null=(([WMICLASS]'%sps%').GetInstances()).RefreshLicenseStatus()\" %nul%\r\nexit /b\r\n\r\n::  Install Key\r\n\r\n:dk_inskey\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey=\"%key%\" %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset keyerror=%errorlevel%\r\ncmd /c exit /b %keyerror%\r\nif %keyerror% NEQ 0 set \"keyerror=[0x%=ExitCode%]\"\r\n\r\nif defined generickey (set \"keyecho=Installing Generic Product Key         \") else (set \"keyecho=Installing Product Key                 \")\r\nif %keyerror% EQU 0 (\r\nif %sps%==SoftwareLicensingService call :dk_refresh\r\necho %keyecho% %~1 [Successful]\r\n) else (\r\ncall :dk_color %Red% \"%keyecho% %~1 [Failed] %keyerror%\"\r\nif not defined showfix (\r\nif defined altapplist call :dk_color %Red% \"Activation ID not found for this key.\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\nset showfix=1\r\n)\r\nset error=1\r\n)\r\n\r\nset generickey=\r\nexit /b\r\n\r\n::  Get all products Activation IDs\r\n\r\n:dk_actids\r\n\r\nset allapps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1') get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1''').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined allapps (call set \"allapps=!allapps! %%a\") else (call set \"allapps=%%a\"))\r\n\r\n::  Check potential script crash issue when user manually installs way too many licenses for Office (length limit in variable)\r\n\r\nif defined allapps if %1==0ff1ce15-a989-479d-af46-f275c6370663 (\r\nset len=0\r\necho:!allapps!> \"!_ttemp!\\chklen\"\r\nfor %%A in (\"!_ttemp!\\chklen\") do (set len=%%~zA)\r\ndel \"!_ttemp!\\chklen\" %nul%\r\n\r\nif !len! GTR 6000 (\r\n%eline%\r\necho Too many licenses are installed, the script may crash.\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ntimeout /t 30\r\n)\r\n)\r\nexit /b\r\n\r\n::  Get installed products Activation IDs\r\n\r\n:dk_actid\r\n\r\nset apps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1' and PartialProductKey is not null) get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1'' AND PartialProductKey IS NOT NULL').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined apps (call set \"apps=!apps! %%a\") else (call set \"apps=%%a\"))\r\nexit /b\r\n\r\n::  Install License files using Powershell/WMI instead of slmgr.vbs\r\n\r\n:xrm:\r\nfunction InstallLicenseFile($Lsc) {\r\n    try {\r\n        $null = $sls.InstallLicense([IO.File]::ReadAllText($Lsc))\r\n    } catch {\r\n        $host.SetShouldExit($_.Exception.HResult)\r\n    }\r\n}\r\nfunction InstallLicenseArr($Str) {\r\n    $a = $Str -split ';'\r\n    ForEach ($x in $a) {InstallLicenseFile \"$x\"}\r\n}\r\nfunction InstallLicenseDir($Loc) {\r\n\tGet-ChildItem $Loc -Recurse -Filter *.xrm-ms | ForEach-Object {InstallLicenseFile $_.FullName}\r\n}\r\nfunction ReinstallLicenses() {\r\n    $Oem = \"$env:SysPath\\oem\"\r\n    $Spp = \"$env:SysPath\\spp\\tokens\"\r\n    InstallLicenseDir \"$Spp\"\r\n    If (Test-Path $Oem) {InstallLicenseDir \"$Oem\"}\r\n}\r\n:xrm:\r\n\r\n::  Check wmic.exe\r\n\r\n:dk_ckeckwmic\r\n\r\nif %winbuild% LSS 9200 (set _wmic=1&exit /b)\r\nset _wmic=0\r\nfor %%# in (wmic.exe) do @if not \"%%~$PATH:#\"==\"\" (\r\ncmd /c \"wmic path Win32_ComputerSystem get CreationClassName /value\" %nul2% | find /i \"computersystem\" %nul1% && set _wmic=1\r\n)\r\nexit /b\r\n\r\n::  Show info for potential script stuck scenario\r\n\r\n:dk_sppissue\r\n\r\nsc start %_slser% %nul%\r\nset spperror=%errorlevel%\r\n\r\nif %spperror% NEQ 1056 if %spperror% NEQ 0 (\r\n%eline%\r\necho sc start %_slser% [Error Code: %spperror%]\r\nif %spperror% EQU 1053 (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\ncall :dk_color %Blue% \"If it still does not work, go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\n)\r\n)\r\n\r\necho:\r\n%psc% \"$job = Start-Job { (Get-WmiObject -Query 'SELECT * FROM %sps%').Version }; if (-not (Wait-Job $job -Timeout 30)) {write-host '%_slser% is not working correctly. Check this webpage for help - %mas%troubleshoot'}\"\r\nexit /b\r\n\r\n::  Get Product name (WMI/REG methods are not reliable in all conditions, hence winbrand.dll method is used)\r\n\r\n:dk_product\r\n\r\nset d1=%ref% $meth = $TypeBuilder.DefinePInvokeMethod('BrandingFormatString', 'winbrand.dll', 'Public, Static', 1, [String], @([String]), 1, 3);\r\nset d1=%d1% $meth.SetImplementationFlags(128); $TypeBuilder.CreateType()::BrandingFormatString('%%WINDOWS_LONG%%') -replace [string][char]0xa9, '' -replace [string][char]0xae, '' -replace [string][char]0x2122, ''\r\n\r\nset winos=\r\nfor /f \"delims=\" %%s in ('\"%psc% %d1%\"') do if not errorlevel 1 (set winos=%%s)\r\necho \"%winos%\" | find /i \"Windows\" %nul1% || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v ProductName %nul6%') do set \"winos=%%b\"\r\nif %winbuild% GEQ 22000 (\r\nset winos=!winos:Windows 10=Windows 11!\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::  Common lines used in PowerShell reflection code\r\n\r\n:dk_reflection\r\n\r\nset ref=$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1);\r\nset ref=%ref% $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False);\r\nset ref=%ref% $TypeBuilder = $ModuleBuilder.DefineType(0);\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_chkmal\r\n\r\n::  Many users unknowingly download mal-ware by using activators found through Google search.\r\n::  This code aims to notify users that their system has been affected by mal-ware.\r\n\r\nset w=\r\nset results=\r\nif exist \"%ProgramFiles%\\KM%w%Spico\" set pupfound= KM%w%Spico \r\nif not defined pupfound (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\" /f Path /s | find /i \"AutoPico\" %nul% && set pupfound= KM%w%Spico \r\n)\r\n\r\nset hcount=0\r\nfor %%# in (avira.com kaspersky.com virustotal.com mcafee.com) do (\r\nfind /i \"%%#\" %SysPath%\\drivers\\etc\\hosts %nul% && set /a hcount+=1)\r\nif %hcount%==4 set \"results=[Antivirus URLs are blocked in hosts]\"\r\n\r\nsc start %_slser% %nul%\r\necho \"%errorlevel%\" | findstr \"577 225\" %nul% && (\r\nset \"results=%results%[Likely File Infector]\"\r\n) || (\r\nif not exist %SysPath%\\%_slexe% if not exist %SysPath%\\alg.exe (set \"results=%results%[Likely File Infector]\")\r\n)\r\n\r\nif not \"%results%%pupfound%\"==\"\" (\r\nif defined pupfound call :dk_color %Gray% \"Checking PUP Activators                 [Found%pupfound%]\"\r\nif defined results call :dk_color %Red% \"Checking Probable Mal%w%ware Infection...\"\r\nif defined results (call :dk_color %Red% \"%results%\"&set showfix=1)\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\necho:\r\n)\r\n\r\n::  Remove the scheduled task of R@1n-KMS (old version) that runs the activation command every minute, as it leads to high CPU usage.\r\n\r\nif exist %SysPath%\\Tasks\\R@1n-KMS (\r\nfor /f %%A in ('dir /b /a:-d %SysPath%\\Tasks\\R@1n-KMS %nul6%') do (schtasks /delete /tn \\R@1n-KMS\\%%A /f %nul%)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_errorcheck\r\n\r\nset showfix=\r\ncall :dk_chkmal\r\n\r\n::==============================\r\n\r\n::  Check Sandboxing\r\n\r\nsc query Null %nul% || (\r\ncall :dk_color %Red% \"Checking Sandboxing                     [Found, script may not work properly]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"If you are using any third-party antivirus, check if it is blocking the script.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WinPE mode\r\n\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinPE\" /v InstRoot %nul% && (\r\n\r\ncall :dk_color %Red% \"Checking WinPE                          [Found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"WinPE mode found. Reboot the system and run in normal mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Safe mode\r\n\r\nif defined safeboot_option (\r\ncall :dk_color %Red% \"Checking Boot Mode                      [%safeboot_option%]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Safe mode found. Reboot the system and run in normal mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check ImageState\r\n::  https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-setup-states\r\n\r\nfor /f \"skip=2 tokens=2*\" %%A in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State\" /v ImageState') do (set imagestate=%%B)\r\n\r\nif /i not \"%imagestate%\"==\"IMAGE_STATE_COMPLETE\" (\r\ncall :dk_color %Gray% \"Checking Windows Setup State            [%imagestate%]\"\r\necho \"%imagestate%\" | find /i \"RESEAL\" %nul% && (\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"You need to run it in normal mode in case you are running it in Audit Mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\necho \"%imagestate%\" | find /i \"UNDEPLOYABLE\" %nul% && (\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If the activation fails, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check corrupt services\r\n\r\nset serv_cor=\r\nfor %%# in (%_serv%) do (\r\nset _regcorr=\r\nset _corrupt=\r\nsc start %%# %nul%\r\nif !errorlevel! EQU 1060 set _corrupt=1\r\nsc query %%# %nul% || set _corrupt=1\r\nfor %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type) do if not defined _regcorr (\r\nreg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%# /v %%G %nul% || (set _corrupt=1&set _regcorr=-RegistryError)\r\n)\r\n\r\nif defined _corrupt (if defined serv_cor (set \"serv_cor=!serv_cor! %%#!_regcorr!\") else (set \"serv_cor=%%#!_regcorr!\"))\r\n)\r\n\r\nif defined serv_cor (\r\ncall :dk_color %Red% \"Checking Corrupt Services               [%serv_cor%]\"\r\n\r\nif not defined showfix (\r\necho:\r\nif /i \"%serv_cor%\"==\"sppsvc-RegistryError\" (\r\nset fixes=%fixes% %mas%fix_service\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_service\"\r\n) else (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\necho:\r\n)\r\n\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check disabled services\r\n\r\nset serv_ste=\r\nfor %%# in (%_serv%) do (\r\nsc start %%# %nul%\r\nif !errorlevel! EQU 1058 (if defined serv_ste (set \"serv_ste=!serv_ste! %%#\") else (set \"serv_ste=%%#\"))\r\n)\r\n\r\n::  Change disabled services startup type to default\r\n\r\nset serv_csts=\r\nset serv_cste=\r\n\r\nif defined serv_ste (\r\nfor %%# in (%serv_ste%) do (\r\nif /i %%#==ClipSVC          (reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%#\" /v \"Start\" /t REG_DWORD /d \"3\" /f %nul% & sc config %%# start= demand %nul%)\r\nif /i %%#==wlidsvc          sc config %%# start= demand %nul%\r\nif /i %%#==sppsvc           (reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%#\" /v \"Start\" /t REG_DWORD /d \"2\" /f %nul% & sc config %%# start= delayed-auto %nul%)\r\nif /i %%#==SLsvc            sc config %%# start= auto %nul%\r\nif /i %%#==KeyIso           sc config %%# start= demand %nul%\r\nif /i %%#==LicenseManager   sc config %%# start= demand %nul%\r\nif /i %%#==Winmgmt          sc config %%# start= auto %nul%\r\nif !errorlevel!==0 (\r\nif defined serv_csts (set \"serv_csts=!serv_csts! %%#\") else (set \"serv_csts=%%#\")\r\n) else (\r\nif defined serv_cste (set \"serv_cste=!serv_cste! %%#\") else (set \"serv_cste=%%#\")\r\n)\r\n)\r\n)\r\n\r\nif defined serv_csts call :dk_color %Gray% \"Enabling Disabled Services              [Successful] [%serv_csts%]\"\r\n\r\nif defined serv_cste (\r\ncall :dk_color %Red% \"Enabling Disabled Services              [Failed] [%serv_cste%]\"\r\n\r\nif not defined showfix (\r\necho:\r\necho %serv_cste% | findstr /i \"ClipSVC sppsvc\" %nul% && (\r\necho A registry fix has been applied to enable the disabled service.\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\n) || (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\necho:\r\n)\r\n\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check if the services are able to run or not\r\n::  Workarounds are added to get correct status and error code because sc query doesn't output correct results in some conditions\r\n\r\nset serv_e=\r\nfor %%# in (%_serv%) do (\r\nset errorcode=\r\nset checkerror=\r\n\r\nsc query %%# | find /i \"RUNNING\" %nul% || (\r\n%psc% \"Start-Job { Start-Service %%# } | Wait-Job -Timeout 20 | Out-Null\"\r\nset errorcode=!errorlevel!\r\nsc query %%# | find /i \"RUNNING\" %nul% || set checkerror=1\r\n)\r\n\r\nsc start %%# %nul%\r\nif !errorlevel! NEQ 1056 if !errorlevel! NEQ 0 (set errorcode=!errorlevel!&set checkerror=1)\r\nif defined checkerror if defined serv_e (set \"serv_e=!serv_e!, %%#-!errorcode!\") else (set \"serv_e=%%#-!errorcode!\")\r\n)\r\n\r\nif defined serv_e (\r\ncall :dk_color %Red% \"Starting Services                       [Failed] [%serv_e%]\"\r\n\r\nif not defined showfix (\r\nset listwospp=%_serv:sppsvc=%\r\necho %serv_e% | findstr /i \"!listwospp!\" %nul% && (\r\nset showfix=1\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and run the script again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If service error is still not fixed, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\n)\r\nset error=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WMI\r\n\r\nset wmifailed=\r\nif %_wmic% EQU 1 wmic path Win32_ComputerSystem get CreationClassName /value %nul2% | find /i \"computersystem\" %nul1%\r\nif %_wmic% EQU 0 %psc% \"Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName\" %nul2% | find /i \"computersystem\" %nul1%\r\n\r\nif %errorlevel% NEQ 0 set wmifailed=1\r\n\r\nif %_wmic% EQU 1 wmic path %sps% get Version %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=([WMISEARCHER]'SELECT * FROM %sps%').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset error_code=%errorlevel%\r\ncmd /c exit /b %error_code%\r\nif %error_code% NEQ 0 set \"error_code=0x%=ExitCode%\"\r\n\r\necho \"%error_code%\" | findstr /i \"0x800410 0x800440 0x80131501\" %nul1% && set wmifailed=1& ::  https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants\r\n\r\nif defined wmifailed (\r\ncall :dk_color %Red% \"Checking WMI                            [Not Working]\"\r\n\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WMI option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SPP Registry Key\r\n\r\nif %winbuild% GEQ 7600 reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Plugins\\Objects\\msft:rm/algorithm/hwid/4.0\" /f ba02fed39662 /d %nul% || (\r\ncall :dk_color %Red% \"Checking SPP Registry Key               [Incorrect ModuleId Found] [Most likely caused by gaming spoofers]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%issues_due_to_gaming_spoofers\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%issues_due_to_gaming_spoofers\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check TokenStore registry key\r\n\r\nset tokenstore=\r\nif %winbuild% GEQ 7600 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v TokenStore %nul6%') do call set \"tokenstore=%%b\"\r\nif %winbuild% LSS 9200 set \"tokenstore=%Systemdrive%\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareProtectionPlatform\"\r\n\r\nif %winbuild% GEQ 9200 if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store\" if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store\\2.0\" if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store_test\\2.0\" (\r\ncall :dk_color %Red% \"Checking TokenStore Registry Key        [Correct Path Not Found] [!tokenstore!]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset toerr=1\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This code creates token folder only if it's missing and sets default permission for it\r\n\r\nif %winbuild% GEQ 7600 if not defined toerr if not exist \"%tokenstore%\\\" (\r\n\r\nmkdir \"%tokenstore%\" %nul%\r\n\r\nif %winbuild% LSS 9200 set \"d=$sddl = 'O:NSG:NSD:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;NS)';\"\r\nif %winbuild% GEQ 9200 set \"d=$sddl = 'O:BAG:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;GR;;;BU)(A;;FR;;;BU)(A;OICI;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)';\"\r\nset \"d=!d! $AclObject = New-Object System.Security.AccessControl.DirectorySecurity;\"\r\nset \"d=!d! $AclObject.SetSecurityDescriptorSddlForm($sddl);\"\r\nset \"d=!d! Set-Acl -Path %tokenstore% -AclObject $AclObject;\"\r\n%psc% \"!d!\" %nul%\r\n\r\nif exist \"%tokenstore%\\\" (\r\ncall :dk_color %Gray% \"Checking SPP Token Folder               [Not Found, Created Now] [%tokenstore%\\]\"\r\n) else (\r\ncall :dk_color %Red% \"Checking SPP Token Folder               [Not Found, Failed to Create] [%tokenstore%\\]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This code checks if SPP has permission access to tokens folder and required registry keys. It's often caused by gaming spoofers.\r\n\r\nset permerror=\r\nif %winbuild% GEQ 9200 if not defined toerr if not defined ps32onArm if exist \"%tokenstore%\\\" (\r\nfor %%# in (\r\n\"%tokenstore%+FullControl\"\r\n\"HKLM:\\SYSTEM\\WPA+QueryValues, EnumerateSubKeys, WriteKey\"\r\n\"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform+SetValue\"\r\n) do for /f \"tokens=1,2 delims=+\" %%A in (%%#) do if not defined permerror (\r\n%psc% \"$acl = (Get-Acl '%%A' | fl | Out-String); if (-not ($acl -match 'NT SERVICE\\\\sppsvc Allow  %%B') -or ($acl -match 'NT SERVICE\\\\sppsvc Deny')) {Exit 2}\" %nul%\r\nif !errorlevel!==2 (\r\nif \"%%A\"==\"%tokenstore%\" (\r\nset \"permerror=Error Found In Token Folder\"\r\n) else (\r\nset \"permerror=Error Found In SPP Registries\"\r\n)\r\n)\r\n)\r\n\r\nREM  https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application\r\n\r\nif not defined permerror (\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% && (\r\nset \"pol=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\"\r\nreg query \"!pol!\" %nul% || reg add \"!pol!\" %nul%\r\n%psc% \"$netServ = (New-Object Security.Principal.SecurityIdentifier('S-1-5-20')).Translate([Security.Principal.NTAccount]).Value; $aclString = Get-Acl 'Registry::!pol!' | Format-List | Out-String; if (-not ($aclString.Contains($netServ + ' Allow  FullControl') -or $aclString.Contains('NT SERVICE\\sppsvc Allow  FullControl')) -or ($aclString.Contains('Deny'))) {Exit 3}\" %nul%\r\nif !errorlevel!==3 set \"permerror=Error Found In S-1-5-20 SPP\"\r\n)\r\n)\r\n\r\nif defined permerror (\r\ncall :dk_color %Red% \"Checking SPP Permissions                [!permerror!]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WPA Registry Errors\r\n\r\nset chkalp=\r\nset wpainfo=NotFound\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wpatest\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (set wpainfo=%%a)\r\nfor /f \"delims=0123456789\" %%i in (\"%wpainfo%\") do set chkalp=%%i\r\n\r\nif defined chkalp (\r\ncall :dk_color %Red% \"Checking WPA Registry Errors            [%wpainfo%]\"\r\nif not defined showfix (\r\necho \"%wpainfo%\" | find /i \"Error Found\" %nul% && (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\necho:\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\nset wpainfo=a\r\n)\r\n\r\nif not defined chkalp (\r\nif %wpainfo% GEQ 5000 (\r\ncall :dk_color %Gray% \"Checking WPA Registry Count             [%wpainfo%]\"\r\ncall :dk_color %Blue% \"A large number of WPA registries have been found, which may cause high CPU usage.\"\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\necho:\r\n) else (\r\necho Checking WPA Registry Count             [%wpainfo%]\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Rearm\r\n\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\PersistedTSReArmed\" %nul% && (\r\ncall :dk_color %Red% \"Checking Rearm                          [System is Rearmed]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState\" %nul% && (\r\ncall :dk_color %Red% \"Checking ClipSVC PersistedSystemState   [Found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SoftwareLicensingService\r\n\r\nif %error_code% NEQ 0 (\r\ncall :dk_color %Red% \"Checking SoftwareLicensingService       [Not Working] [%error_code%]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Activation IDs\r\n\r\ncall :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nif not defined apps (\r\n%psc% \"if (-not $env:_vis) {Start-Job { Stop-Service %_slser% -force } | Wait-Job -Timeout 20 | Out-Null}; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif not defined _vis if !errorlevel! NEQ 0 set rlicfailed=1\r\ncall :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f\r\n)\r\n\r\nif not defined apps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nif not defined apps if defined allapps if not defined notwinact (\r\ncall :dk_color %Gray% \"Checking Activation IDs                 [Key Not Installed or Act ID Not Found]\"\r\n)\r\n\r\nif not defined apps if not defined allapps (\r\ncall :dk_color %Red% \"Checking Activation IDs                 [Not found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\nif not defined showfix if defined rlicfailed (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\n\r\nif %winbuild% GEQ 7600 if exist \"%tokenstore%\\\" if not exist \"%tokenstore%\\tokens.dat\" (\r\ncall :dk_color %Red% \"Checking SPP tokens.dat                 [Not Found] [%tokenstore%\\]\"\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Eval Windows\r\n\r\nif not defined notwinact if exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Eval\" %nul1% || (\r\ncall :dk_color %Red% \"Checking Eval Packages                  [License swapping found. Non-Eval licenses are installed in Eval Windows]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"License swapping is not the right way to upgrade to the full version. Learn the correct method at the link below.\"\r\nset fixes=%fixes% %mas%evaluation_editions\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%evaluation_editions\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check HKU\\S-1-5-20\\Software registry, in some systems it's missing and that causes Windows activation problems\r\n\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% || (\r\ncall :dk_color %Red% \"Checking HKU\\S-1-5-20 Registry          [Not Found]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check license and package files for the current edition\r\n\r\nset osedition=0\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do if not errorlevel 1 (call set \"osedition=%%a\")\r\n\r\nif %osedition%==0 for /f \"skip=2 tokens=3\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul6%') do set \"osedition=%%a\"\r\n\r\n::  Workaround for an issue in builds between 1607 and 1709 where ProfessionalEducation is shown as Professional\r\n\r\nif not %osedition%==0 (\r\nif \"%osSKU%\"==\"164\" set osedition=ProfessionalEducation\r\nif \"%osSKU%\"==\"165\" set osedition=ProfessionalEducationN\r\n)\r\n\r\nif not defined notwinact (\r\nif %osedition%==0 (\r\ncall :dk_color %Red% \"Checking Edition Name                   [Not Found In Registry]\"\r\n) else (\r\nif not exist \"%SysPath%\\spp\\tokens\\skus\\%osedition%\\%osedition%*.xrm-ms\" if not exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-%osedition%\\*-%osedition%-*.xrm-ms\" if not exist \"%SysPath%\\licensing\\skus\\Security-Licensing-SLC-Component-SKU-%osedition%\\*-%osedition%-*.xrm-ms\" (\r\nset skunotfound=1\r\ncall :dk_color %Red% \"Checking License Files                  [Not Found] [%osedition%]\"\r\n)\r\nif not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*-%osedition%-*.mum\" (\r\nif not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-%osedition%Edition*.mum\" (\r\ncall :dk_color %Red% \"Checking Package Files                  [Not Found] [%osedition%]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SKU value to find if there is any difference\r\n\r\nif not defined notwinact (\r\nif %winbuild% GEQ 10240 (\r\n%nul% set /a \"sum=%slcSKU%+%regSKU%+%wmiSKU%\"\r\nset /a \"sum/=3\"\r\nif not \"!sum!\"==\"%slcSKU%\" (\r\ncall :dk_color %Gray% \"Checking SLC/WMI/REG SKU                [Difference Found - SLC:%slcSKU% WMI:%wmiSKU% Reg:%regSKU%]\"\r\n)\r\n) else (\r\n%nul% set /a \"sum=%slcSKU%+%wmiSKU%\"\r\nset /a \"sum/=2\"\r\nif not \"!sum!\"==\"%slcSKU%\" (\r\ncall :dk_color %Gray% \"Checking SLC/WMI SKU                    [Difference Found - SLC:%slcSKU% WMI:%wmiSKU%]\"\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This \"WLMS\" service was included in previous Eval editions (which were activable) to automatically shut down the system every hour after the evaluation period expired and prevent SPPSVC from stopping.\r\n\r\nsc query wlms %nul%\r\n\r\nif %errorlevel% NEQ 1060 (\r\necho Checking Eval WLMS Service              [Found]\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SPP interference in IFEO\r\n\r\nfor %%# in (SppEx%w%tComObj.exe SLsvc.exe sppsvc.exe sppsvc.exe\\PerfOptions) do (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" %nul% && (if defined _sppint (set \"_sppint=!_sppint!, %%#\") else (set \"_sppint=%%#\"))\r\n)\r\nif defined _sppint (\r\necho %_sppint% | find /i \"PerfOptions\" %nul% && (\r\ncall :dk_color %Red% \"Checking SPP Interference In IFEO       [%_sppint% - System might deactivate later]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\nset showfix=1\r\n) || (\r\necho Checking SPP In IFEO                    [%_sppint%]\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check and fix SkipRearm registry value\r\n\r\nif %winbuild% GEQ 7600 for /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"SkipRearm\" %nul6%') do if /i %%b NEQ 0x0 (\r\nreg add \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"SkipRearm\" /t REG_DWORD /d \"0\" /f %nul%\r\ncall :dk_color %Gray% \"Checking SkipRearm                      [Default 0 Value Not Found. Changing To 0]\"\r\n%psc% \"Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null\"\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SvcRestartTask status, this task helps in making sure system remains activated\r\n\r\nif %winbuild% GEQ 9200 if not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\n%psc% \"Get-WmiObject -Query 'SELECT Description FROM SoftwareLicensingProduct WHERE PartialProductKey IS NOT NULL AND LicenseDependsOn IS NULL' | Select-Object -Property Description\" %nul2% | findstr /i \"KMS_\" %nul1% || (\r\nfor /f \"delims=\" %%a in ('%psc% \"$s=New-Object -ComObject 'Schedule.Service'; $s.Connect(); $state=$s.GetFolder('\\Microsoft\\Windows\\SoftwareProtectionPlatform').GetTask('SvcRestartTask').State; @{0='Unknown';1='Disabled';2='Queued';3='Ready';4='Running'}[$state]\" %nul6%') do (set taskinfo=%%a)\r\n\r\necho !taskinfo! | find /i \"Ready\" %nul% || (\r\nreg delete \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"actionlist\" /f %nul%\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\Microsoft\\Windows\\SoftwareProtectionPlatform\\SvcRestartTask\" %nul% || set taskinfo=Removed\r\nif \"!taskinfo!\"==\"\" set \"taskinfo=Not Found\"\r\n\r\ncall :dk_color %Gray% \"Checking SvcRestartTask Status          [!taskinfo!. System might deactivate later.]\"\r\nif not defined showfix (\r\necho \"!taskinfo!\" | findstr /i \"Removed Not Found\" %nul1% && (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n) || (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and run the script again.\"\r\n)\r\necho:\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\nexit /b\r\n\r\n::  This code checks for invalid registry keys in HKLM\\SYSTEM\\WPA. This issue may appear even on healthy systems\r\n\r\n:wpatest:\r\n$wpaKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME).OpenSubKey(\"SYSTEM\\\\WPA\")\r\n$count = 0\r\nforeach ($subkeyName in $wpaKey.GetSubKeyNames()) {\r\n    if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n        $count++\r\n    }\r\n}\r\n$osVersion = [System.Environment]::OSVersion.Version\r\n$minBuildNumber = 14393\r\nif ($osVersion.Build -ge $minBuildNumber) {\r\n    $subkeyHashTable = @{}\r\n    foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {\r\n        if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n            $keyNumber = $subkeyName -replace '.*-', ''\r\n            $subkeyHashTable[$keyNumber] = $true\r\n        }\r\n    }\r\n    for ($i=1; $i -le $count; $i++) {\r\n        if (-not $subkeyHashTable.ContainsKey(\"$i\")) {\r\n            Write-Output \"Total Keys $count. Error Found - $i key does not exist.\"\r\n\t\t\t$wpaKey.Close()\r\n\t\t\texit\r\n        }\r\n    }\r\n}\r\n$wpaKey.GetSubKeyNames() | ForEach-Object {\r\n    if ($_ -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n        if ($PSVersionTable.PSVersion.Major -lt 3) {\r\n            cmd /c \"reg query \"HKLM\\SYSTEM\\WPA\\$_\" /ve /t REG_BINARY >nul 2>&1\"\r\n\t\t\tif ($LASTEXITCODE -ne 0) {\r\n            Write-Host \"Total Keys $count. Error Found - Binary Data is corrupt.\"\r\n\t\t\t$wpaKey.Close()\r\n\t\t\texit\r\n\t\t\t}\r\n        } else {\r\n            $subkey = $wpaKey.OpenSubKey($_)\r\n            $p = $subkey.GetValueNames()\r\n            if (($p | Where-Object { $subkey.GetValueKind($_) -eq [Microsoft.Win32.RegistryValueKind]::Binary }).Count -eq 0) {\r\n                Write-Host \"Total Keys $count. Error Found - Binary Data is corrupt.\"\r\n\t\t\t\t$wpaKey.Close()\r\n\t\t\t\texit\r\n            }\r\n        }\r\n    }\r\n}\r\n$count\r\n$wpaKey.Close()\r\n:wpatest:\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_color\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3'\r\n) else if not exist %ps% (\r\necho %~3\r\n)\r\nexit /b\r\n\r\n:dk_color2\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[%~3%~4%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'\r\n) else if not exist %ps% (\r\necho %~3 %~6\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_done\r\n\r\necho:\r\nif %_unattended%==1 timeout /t 2 & exit /b\r\n\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 exit /b\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Office version number\r\n::  2nd column = Activation ID\r\n::  3rd column = For Office 2013 and later, the generated keys are listed. For Office 2010, the blocked keys sourced from the Internet are listed.\r\n::               For Office 2013 and later, key preference is given in this order, Retail:TB:Sub > Retail > OEM:NONSLP > Volume:MAK > Volume:GVLK\r\n::               For Office 2010, key preference is given in this order, Retail > Volume:MAK\r\n::  4th column = Last part of license description\r\n::  5th column = Edition\r\n::  6th column = Other Edition IDs if they are part of the same primary product (For reference only)\r\n::  Separator  = \"_\"\r\n\r\n::===============\r\n\r\n:: We couldn't find any keys (blocked/generic doesn't matter) for these Office 2010 products. If you have them, please share with us.\r\n\r\n14_4eaff0d0-c6cb-4187-94f3-c7656d49a0aa_Retail________ExcelR_[HSExcelR]\r\n14_7004b7f0-6407-4f45-8eac-966e5f868bde_Retail________GrooveR\r\n14_133c8359-4e93-4241-8118-30bb18737ea0_Retail________PowerPointR_[HSPowerPointR]\r\n14_db3bbc9c-ce52-41d1-a46f-1a1d68059119_Retail________WordR_[HSWordR]\r\n14_dbe3aee0-5183-4ff7-8142-66050173cb01_Retail________SmallBusBasicsR_[SmallBusBasicsMSDNR]\r\n\r\n:: These installers are not publicly available, so it doesn't matter if we don't have their keys.\r\n\r\n14_19316117-30a8-4773-8fd9-7f7231f4e060_SubPrepid_____HomeBusinessSubR\r\n14_4d06f72e-fd50-4bc2-a24b-d448d7f17ef2_SubPrepid_____ProjectProSubR\r\n14_e98ef0c0-71c4-42ce-8305-287d8721e26c_SubPrepid_____ProPlusSubR\r\n14_14f5946a-debc-4716-babc-7e2c240fec08_Retail________MondoR\r\n14_533b656a-4425-480b-8e30-1a2358898350_MAK___________MondoVL\r\n\r\n:ohookdata\r\n\r\nset f=\r\nfor %%# in (\r\n:: Office 2010\r\n14_4d463c2c-0505-4626-8cdb-a4da82e2d8ed_7KTYC-XR43P-C3MRW-BJKFD-XB%f%YPG_Retail________AccessR\r\n14_745fb377-0a59-4ca9-b9a9-c359557a2c4e_7XHPQ-BQMYG-YBP49-CY8B2-T8%f%CGQ_ByPass________AccessRuntimeR\r\n14_95ab3ec8-4106-4f9d-b632-03c019d1d23f_89RTQ-MT4GK-6CPTX-WWP7C-J9%f%KXR_MAK___________AccessVL\r\n14_71dc86ff-f056-40d0-8ffb-9592705c9b76_39TRR-C2F37-9WYJ2-MJQXH-B9%f%38K_MAK___________ExcelVL\r\n14_fdad0dfa-417d-4b4f-93e4-64ea8867b7fd_RCGT3-FPQDV-H49CD-PPDBF-TH%f%47G_MAK___________GrooveVL\r\n14_7b7d1f17-fdcb-4820-9789-9bec6e377821_3YR9B-D9W79-BY66R-R8XYP-QY%f%YYY_Retail________HomeBusinessR_[HomeBusinessDemoR]\r\n14_09e2d37e-474b-4121-8626-58ad9be5776f_3X43R-HHHXX-FRHRW-2M2WJ-8V%f%PHD_Retail________HomeStudentR_[HomeStudentDemoR]\r\n14_ef1da464-01c8-43a6-91af-e4e5713744f9_XDGJY-KFHW9-JWX9X-YM4GW-GC%f%8WR_Retail________InfoPathR\r\n14_85e22450-b741-430c-a172-a37962c938af_6GKT2-KMJPK-4RRBF-8VQKB-JB%f%6G6_MAK___________InfoPathVL\r\n14_3f7aa693-9a7e-44fc-9309-bb3d8e604925_2TG3P-9DB76-4YT99-8RXGD-CW%f%XBP_Retail________OneNoteR_[HSOneNoteR]\r\n14_6860b31f-6a67-48b8-84b9-e312b3485c4b_CV64P-F4VRH-BJ33D-PH6MR-X6%f%9RY_MAK___________OneNoteVL\r\n14_fbf4ac36-31c8-4340-8666-79873129cf40_9D8FR-7GYBW-4YG8M-V36JK-VD%f%7CM_Retail________OutlookR\r\n14_a9aeabd8-63b8-4079-a28e-f531807fd6b8_J8C9M-YXMH2-9CX44-2C3YG-V7%f%692_MAK___________OutlookVL\r\n14_acb51361-c0db-4895-9497-1831c41f31a6_GMBWM-WVX26-7WHV4-DB43D-WV%f%DY2_Retail________PersonalR_[PersonalDemoR,PersonalPrepaidR]\r\n14_38252940-718c-4aa6-81a4-135398e53851_HPBQP-RJHDR-Q3472-PT9Q6-PB%f%B72_MAK___________PowerPointVL\r\n14_8b559c37-0117-413e-921b-b853aeb6e210_367X9-9HP9R-TKHY6-DH4QH-K9%f%PY7_Retail________ProfessionalR_[ProfessionalAcadR,ProfessionalDemoR,OEM-SingleImage]\r\n14_725714d7-d58f-4d12-9fa8-35873c6f7215_6JD4G-KRW3J-48MGV-DM6FC-T9%f%WKR_Retail________ProjectProR_[ProjectProMSDNR]\r\n14_1cf57a59-c532-4e56-9a7d-ffa2fe94b474_3XDTH-MMGJ6-F9MKX-THP8D-G9%f%BP7_MAK___________ProjectProVL\r\n14_688f6589-2bd9-424e-a152-b13f36aa6de1_2W96V-RTQ9R-2BPVT-PT8H9-MV%f%68T_Retail________ProjectStdR\r\n14_11b39439-6b93-4642-9570-f2eb81be2238_4DTT4-D4MKX-23KFH-JKR6T-YK%f%G2J_MAK___________ProjectStdVL\r\n14_71af7e84-93e6-4363-9b69-699e04e74071_2J9H6-H4D3G-PCXD2-96XVM-TR%f%R73_Retail________ProPlusR_[ProPlusAcadR,ProPlusMSDNR,Sub4R]\r\n14_fdf3ecb9-b56f-43b2-a9b8-1b48b6bae1a7_6CD6C-9R8PB-T2D9Y-8RKKX-W7%f%DFK_MAK___________ProPlusVL_[ProPlusAcadVL]\r\n14_98677603-a668-4fa4-9980-3f1f05f78f69_CTRJP-P72VV-JBF8Y-4W6WW-HX%f%HVG_Retail________PublisherR\r\n14_3d014759-b128-4466-9018-e80f6320d9d0_32YG9-3VX77-YXJVV-PRVFW-TT%f%8BV_MAK___________PublisherVL\r\n14_8090771e-d41a-4482-929e-de87f1f47e46_7VKXH-9BWCG-RPTBB-JBRV3-GR%f%HYC_MAK___________SmallBusBasicsVL\r\n14_b78df69e-0966-40b1-ae85-30a5134dedd0_H48K6-FB4Y6-P83GH-9J7XG-HD%f%KKX_ByPass________SPDR\r\n14_b6d2565c-341d-4768-ad7d-addbe00bb5ce_W3BTX-H6BW7-Q6DFW-BXFFY-8R%f%VJP_Retail________StandardR_[StandardMSDNR][KeyisforMSDNR]\r\n14_1f76e346-e0be-49bc-9954-70ec53a4fcfe_2XTQP-GDR7C-GTXPC-6W6PV-4R%f%XGC_MAK___________StandardVL_[StandardAcadVL]\r\n14_2745e581-565a-4670-ae90-6bf7c57ffe43_VXHHB-W7HBD-7M342-RJ7P8-CH%f%BD6_ByPass________StarterR\r\n14_66cad568-c2dc-459d-93ec-2f3cb967ee34_2RDPT-WPYQM-C2WXF-BTPDW-2J%f%2HM_Retail________VisioSIR_Prem[Pro,Std]\r\n14_36756cb8-8e69-4d11-9522-68899507cd6a_7PKFT-X2MKQ-GT6X2-8CB2W-CH%f%C9K_MAK___________VisioSIVL_Prem[Pro,Std]\r\n14_98d4050e-9c98-49bf-9be1-85e12eb3ab13_6J3XK-DFKGK-X373V-QJHYM-V3%f%FC2_MAK___________WordVL\r\n:: Office 2013\r\n15_ab4d047b-97cf-4126-a69f-34df08e2f254_B7RFY-7NXPK-Q4342-Y9X2H-3J%f%X4X_Retail________AccessRetail\r\n15_259de5be-492b-44b3-9d78-9645f848f7b0_X3XNB-HJB7K-66THH-8DWQ3-XH%f%GJP_Bypass________AccessRuntimeRetail\r\n15_4374022d-56b8-48c1-9bb7-d8f2fc726343_9MF9G-CN32B-HV7XT-9XJ8T-9K%f%VF4_MAK___________AccessVolume\r\n15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_NT889-MBH4X-8MD4H-X8R2D-WQ%f%HF8_Retail________ExcelRetail\r\n15_ac1ae7fd-b949-4e04-a330-849bc40638cf_Y3N36-YCHDK-XYWBG-KYQVV-BD%f%TJ2_MAK___________ExcelVolume\r\n15_cfaf5356-49e3-48a8-ab3c-e729ab791250_BMK4W-6N88B-BP9QR-PHFCK-MG%f%7GF_Retail________GrooveRetail\r\n15_4825ac28-ce41-45a7-9e6e-1fed74057601_RN84D-7HCWY-FTCBK-JMXWM-HT%f%7GJ_MAK___________GrooveVolume\r\n15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_2WQNF-GBK4B-XVG6F-BBMX7-M4%f%F2Y_OEM-Perp______HomeBusinessPipcRetail\r\n15_a2b90e7a-a797-4713-af90-f0becf52a1dd_YWD4R-CNKVT-VG8VJ-9333B-RC%f%W9F_Subscription__HomeBusinessRetail\r\n15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_B92QY-NKYFQ-6KTKH-VWW2Q-3P%f%B3B_OEM-ARM_______HomeStudentARMRetail\r\n15_ebef9f05-5273-404a-9253-c5e252f50555_QPG96-CNT7M-KH36K-KY4HQ-M7%f%TBR_OEM-ARM_______HomeStudentPlusARMRetail\r\n15_f2de350d-3028-410a-bfae-283e00b44d0e_6WW3N-BDGM9-PCCHD-9QPP9-P3%f%4QG_Subscription__HomeStudentRetail\r\n15_44984381-406e-4a35-b1c3-e54f499556e2_RV7NQ-HY3WW-7CKWH-QTVMW-29%f%VHC_Retail________InfoPathRetail\r\n15_9e016989-4007-42a6-8051-64eb97110cf2_C4TGN-QQW6Y-FYKXC-6WJW7-X7%f%3VG_MAK___________InfoPathVolume\r\n15_9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY_PrepidBypass__LyncAcademicRetail\r\n15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_N42BF-CBY9F-W2C7R-X397X-DY%f%FQW_PrepidBypass__LyncEntryRetail\r\n15_fada6658-bfc6-4c4e-825a-59a89822cda8_89P23-2NK2R-JXM2M-3Q8R8-BW%f%M3Y_Retail________LyncRetail\r\n15_e1264e10-afaf-4439-a98b-256df8bb156f_3WKCD-RN489-4M7XJ-GJ2GQ-YB%f%FQ6_MAK___________LyncVolume\r\n15_69ec9152-153b-471a-bf35-77ec88683eae_VNWHF-FKFBW-Q2RGD-HYHWF-R3%f%HH2_Subscription__MondoRetail\r\n15_f33485a0-310b-4b72-9a0e-b1d605510dbd_2YNYQ-FQMVG-CB8KW-6XKYD-M7%f%RRJ_MAK___________MondoVolume\r\n15_3391e125-f6e4-4b1e-899c-a25e6092d40d_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%FF4_Bypass________OneNoteFreeRetail\r\n15_8b524bcc-67ea-4876-a509-45e46f6347e8_3KXXQ-PVN2C-8P7YY-HCV88-GV%f%GQ6_Retail________OneNoteRetail\r\n15_b067e965-7521-455b-b9f7-c740204578a2_JDMWF-NJC7B-HRCHY-WFT8G-BP%f%XD9_MAK___________OneNoteVolume\r\n15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_9N4RQ-CF8R2-HBVCB-J3C9V-94%f%P4D_Retail________OutlookRetail\r\n15_8d577c50-ae5e-47fd-a240-24986f73d503_HNG29-GGWRG-RFC8C-JTFP4-2J%f%9FH_MAK___________OutlookVolume\r\n15_5aab8561-1686-43f7-9ff5-2c861da58d17_9CYB3-NFMRW-YFDG6-XC7TF-BY%f%36J_OEM-Perp______PersonalPipcRetail\r\n15_17e9df2d-ed91-4382-904b-4fed6a12caf0_2NCQJ-MFRMH-TXV83-J7V4C-RV%f%RWC_Retail________PersonalRetail\r\n15_31743b82-bfbc-44b6-aa12-85d42e644d5b_HVMN2-KPHQH-DVQMK-7B3CM-FG%f%BFC_Retail________PowerPointRetail\r\n15_e40dcb44-1d5c-4085-8e8f-943f33c4f004_47DKN-HPJP7-RF9M3-VCYT2-TM%f%Q4G_MAK___________PowerPointVolume\r\n15_064383fa-1538-491c-859b-0ecab169a0ab_N3QMM-GKDT3-JQGX6-7X3MQ-4G%f%BG3_Retail________ProPlusRetail\r\n15_2b88c4f2-ea8f-43cd-805e-4d41346e18a7_QKHNX-M9GGH-T3QMW-YPK4Q-QR%f%P9V_MAK___________ProPlusVolume\r\n15_4e26cac1-e15a-4467-9069-cb47b67fe191_CF9DD-6CNW2-BJWJQ-CVCFX-Y7%f%TXD_OEM-Perp______ProfessionalPipcRetail\r\n15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_MBQBN-CQPT6-PXRMC-TYJFR-3C%f%8MY_Retail________ProfessionalRetail\r\n15_2f72340c-b555-418d-8b46-355944fe66b8_WPY8N-PDPY4-FC7TF-KMP7P-KW%f%YFY_Subscription__ProjectProRetail\r\n15_ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32_WFCT2-NBFQ7-JD7VV-MFJX6-6F%f%2CM_MAK___________ProjectProVolume\r\n15_58d95b09-6af6-453d-a976-8ef0ae0316b1_NTHQT-VKK6W-BRB87-HV346-Y9%f%6W8_Subscription__ProjectStdRetail\r\n15_2b9e4a37-6230-4b42-bee2-e25ce86c8c7a_3CNQX-T34TY-99RH4-C4YD2-KW%f%YGV_MAK___________ProjectStdVolume\r\n15_c3a0814a-70a4-471f-af37-2313a6331111_TWNCJ-YR84W-X7PPF-6DPRP-D6%f%7VC_Retail________PublisherRetail\r\n15_38ea49f6-ad1d-43f1-9888-99a35d7c9409_DJPHV-NCJV6-GWPT6-K26JX-C7%f%GX6_MAK___________PublisherVolume\r\n15_ba3e3833-6a7e-445a-89d0-7802a9a68588_3NY6J-WHT3F-47BDV-JHF36-23%f%43W_PrepidBypass__SPDRetail\r\n15_32255c0a-16b4-4ce2-b388-8a4267e219eb_V6VWN-KC2HR-YYDD6-9V7HQ-7T%f%7VP_Retail________StandardRetail\r\n15_a24cca51-3d54-4c41-8a76-4031f5338cb2_9TN6B-PCYH4-MCVDQ-KT83C-TM%f%Q7T_MAK___________StandardVolume\r\n15_a56a3b37-3a35-4bbb-a036-eee5f1898eee_NVK2G-2MY4G-7JX2P-7D6F2-VF%f%QBR_Subscription__VisioProRetail\r\n15_3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d_YN7CF-XRH6R-CGKRY-GKPV3-BG%f%7WF_MAK___________VisioProVolume\r\n15_980f9e3e-f5a8-41c8-8596-61404addf677_NCRB7-VP48F-43FYY-62P3R-36%f%7WK_Subscription__VisioStdRetail\r\n15_44a1f6ff-0876-4edb-9169-dbb43101ee89_RX63Y-4NFK2-XTYC8-C6B3W-YP%f%XPJ_MAK___________VisioStdVolume\r\n15_191509f2-6977-456f-ab30-cf0492b1e93a_NB77V-RPFQ6-PMMKQ-T87DV-M4%f%D84_Retail________WordRetail\r\n15_9cedef15-be37-4ff0-a08a-13a045540641_RPHPB-Y7NC4-3VYFM-DW7VD-G8%f%YJ8_MAK___________WordVolume\r\n:: Office 365 - 15.0 version\r\n15_742178ed-6b28-42dd-b3d7-b7c0ea78741b_Y9NF9-M2QWD-FF6RJ-QJW36-RR%f%F2T_SubTest_______O365BusinessRetail\r\n15_a96f8dae-da54-4fad-bdc6-108da592707a_3NMDC-G7C3W-68RGP-CB4MH-4C%f%XCH_SubTest1______O365HomePremRetail\r\n15_e3dacc06-3bc2-4e13-8e59-8e05f3232325_H8DN8-Y2YP3-CR9JT-DHDR9-C7%f%GP3_Subscription2_O365ProPlusRetail\r\n15_0bc1dae4-6158-4a1c-a893-807665b934b2_2QCNB-RMDKJ-GC8PB-7QGQV-7Q%f%TQJ_Subscription2_O365SmallBusPremRetail\r\n:: Office 365 - 16.0 version\r\n16_dabaa1f2-109b-496d-bf49-1536cc862900_3HYJN-9KG99-F8VG9-V3DT8-JF%f%MHV_Subscription__O365AppsBasicRetail\r\n16_742178ed-6b28-42dd-b3d7-b7c0ea78741b_Y9NF9-M2QWD-FF6RJ-QJW36-RR%f%F2T_SubTest_______O365BusinessRetail\r\n16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_W62NQ-267QR-RTF74-PF2MH-JQ%f%MTH_Subscription__O365EduCloudRetail\r\n16_a96f8dae-da54-4fad-bdc6-108da592707a_3NMDC-G7C3W-68RGP-CB4MH-4C%f%XCH_SubTest1______O365HomePremRetail\r\n16_e3dacc06-3bc2-4e13-8e59-8e05f3232325_H8DN8-Y2YP3-CR9JT-DHDR9-C7%f%GP3_Subscription2_O365ProPlusRetail\r\n16_0bc1dae4-6158-4a1c-a893-807665b934b2_2QCNB-RMDKJ-GC8PB-7QGQV-7Q%f%TQJ_Subscription2_O365SmallBusPremRetail\r\n:: Office 2016\r\n16_bfa358b0-98f1-4125-842e-585fa13032e6_WHK4N-YQGHB-XWXCC-G3HYC-6J%f%F94_Retail________AccessRetail\r\n16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_RNB7V-P48F4-3FYY6-2P3R3-63%f%BQV_PrepidBypass__AccessRuntimeRetail\r\n16_3b2fa33f-cd5a-43a5-bd95-f49f3f546b0b_JJ2Y4-N8KM3-Y8KY3-Y22FR-R3%f%KVK_MAK___________AccessVolume\r\n16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_RKJBN-VWTM2-BDKXX-RKQFD-JT%f%YQ2_Retail________ExcelRetail\r\n16_685062a7-6024-42e7-8c5f-6bb9e63e697f_FVGNR-X82B2-6PRJM-YT4W7-8H%f%V36_MAK___________ExcelVolume\r\n16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_2WQNF-GBK4B-XVG6F-BBMX7-M4%f%F2Y_OEM-Perp______HomeBusinessPipcRetail\r\n16_86834d00-7896-4a38-8fae-32f20b86fa2b_HM6FM-NVF78-KV9PM-F36B8-D9%f%MXD_Retail________HomeBusinessRetail\r\n16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_PBQPJ-NC22K-69MXD-KWMRF-WF%f%G77_OEM-ARM_______HomeStudentARMRetail\r\n16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_6F2NY-7RTX4-MD9KM-TJ43H-94%f%TBT_OEM-ARM_______HomeStudentPlusARMRetail\r\n16_c28acdb8-d8b3-4199-baa4-024d09e97c99_PNPRV-F2627-Q8JVC-3DGR9-WT%f%YRK_Retail________HomeStudentRetail\r\n16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_YWD4R-CNKVT-VG8VJ-9333B-RC%f%3B8_Retail________HomeStudentVNextRetail\r\n16_69ec9152-153b-471a-bf35-77ec88683eae_VNWHF-FKFBW-Q2RGD-HYHWF-R3%f%HH2_Subscription__MondoRetail\r\n16_2cd0ea7e-749f-4288-a05e-567c573b2a6c_FMTQQ-84NR8-2744R-MXF4P-PG%f%YR3_MAK___________MondoVolume\r\n16_436366de-5579-4f24-96db-3893e4400030_XYNTG-R96FY-369HX-YFPHY-F9%f%CPM_Bypass________OneNoteFreeRetail\r\n16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_FXF6F-CNC26-W643C-K6KB7-6X%f%XW3_Retail________OneNoteRetail\r\n16_23b672da-a456-4860-a8f3-e062a501d7e8_9TYVN-D76HK-BVMWT-Y7G88-9T%f%PPV_MAK___________OneNoteVolume\r\n16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_7N4KG-P2QDH-86V9C-DJFVF-36%f%9W9_Retail________OutlookRetail\r\n16_50059979-ac6f-4458-9e79-710bcb41721a_7QPNR-3HFDG-YP6T9-JQCKQ-KK%f%XXC_MAK___________OutlookVolume\r\n16_5aab8561-1686-43f7-9ff5-2c861da58d17_9CYB3-NFMRW-YFDG6-XC7TF-BY%f%36J_OEM-Perp______PersonalPipcRetail\r\n16_a9f645a1-0d6a-4978-926a-abcb363b72a6_FT7VF-XBN92-HPDJV-RHMBY-6V%f%KBF_Retail________PersonalRetail\r\n16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_N7GCB-WQT7K-QRHWG-TTPYD-7T%f%9XF_Retail________PowerPointRetail\r\n16_9b4060c9-a7f5-4a66-b732-faf248b7240f_X3RT9-NDG64-VMK2M-KQ6XY-DP%f%FGV_MAK___________PowerPointVolume\r\n16_de52bd50-9564-4adc-8fcb-a345c17f84f9_GM43N-F742Q-6JDDK-M622J-J8%f%GDV_Retail________ProPlusRetail\r\n16_c47456e3-265d-47b6-8ca0-c30abbd0ca36_FNVK8-8DVCJ-F7X3J-KGVQB-RC%f%2QY_MAK___________ProPlusVolume\r\n16_4e26cac1-e15a-4467-9069-cb47b67fe191_CF9DD-6CNW2-BJWJQ-CVCFX-Y7%f%TXD_OEM-Perp______ProfessionalPipcRetail\r\n16_d64edc00-7453-4301-8428-197343fafb16_NXFTK-YD9Y7-X9MMJ-9BWM6-J2%f%QVH_Retail________ProfessionalRetail\r\n16_2f72340c-b555-418d-8b46-355944fe66b8_WPY8N-PDPY4-FC7TF-KMP7P-KW%f%YFY_Subscription__ProjectProRetail\r\n16_82f502b5-b0b0-4349-bd2c-c560df85b248_PKC3N-8F99H-28MVY-J4RYY-CW%f%GDH_MAK___________ProjectProVolume\r\n16_16728639-a9ab-4994-b6d8-f81051e69833_JBNPH-YF2F7-Q9Y29-86CTG-C9%f%YGV_MAKC2R________ProjectProXVolume\r\n16_58d95b09-6af6-453d-a976-8ef0ae0316b1_NTHQT-VKK6W-BRB87-HV346-Y9%f%6W8_Subscription__ProjectStdRetail\r\n16_82e6b314-2a62-4e51-9220-61358dd230e6_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%G93_MAK___________ProjectStdVolume\r\n16_431058f0-c059-44c5-b9e7-ed2dd46b6789_N3W2Q-69MBT-27RD9-BH8V3-JT%f%2C8_MAKC2R________ProjectStdXVolume\r\n16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_WKWND-X6G9G-CDMTV-CPGYJ-6M%f%VBF_Retail________PublisherRetail\r\n16_fcc1757b-5d5f-486a-87cf-c4d6dedb6032_9QVN2-PXXRX-8V4W8-Q7926-TJ%f%GD8_MAK___________PublisherVolume\r\n16_9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY_PrepidBypass__SkypeServiceBypassRetail\r\n16_971cd368-f2e1-49c1-aedd-330909ce18b6_4N4D8-3J7Y3-YYW7C-73HD2-V8%f%RHY_PrepidBypass__SkypeforBusinessEntryRetail\r\n16_418d2b9f-b491-4d7f-84f1-49e27cc66597_PBJ79-77NY4-VRGFG-Y8WYC-CK%f%CRC_Retail________SkypeforBusinessRetail\r\n16_03ca3b9a-0869-4749-8988-3cbc9d9f51bb_DMTCJ-KNRKR-JV8TQ-V2CR2-VF%f%TFH_MAK___________SkypeforBusinessVolume\r\n16_4a31c291-3a12-4c64-b8ab-cd79212be45e_2FPWN-4H6CM-KD8QQ-8HCHC-P9%f%XYW_Retail________StandardRetail\r\n16_0ed94aac-2234-4309-ba29-74bdbb887083_WHGMQ-JNMGT-MDQVF-WDR69-KQ%f%BWC_MAK___________StandardVolume\r\n16_a56a3b37-3a35-4bbb-a036-eee5f1898eee_NVK2G-2MY4G-7JX2P-7D6F2-VF%f%QBR_Subscription__VisioProRetail\r\n16_295b2c03-4b1c-4221-b292-1411f468bd02_NRKT9-C8GP2-XDYXQ-YW72K-MG%f%92B_MAK___________VisioProVolume\r\n16_0594dc12-8444-4912-936a-747ca742dbdb_G98Q2-B6N77-CFH9J-K824G-XQ%f%CC4_MAKC2R________VisioProXVolume\r\n16_980f9e3e-f5a8-41c8-8596-61404addf677_NCRB7-VP48F-43FYY-62P3R-36%f%7WK_Subscription__VisioStdRetail\r\n16_44151c2d-c398-471f-946f-7660542e3369_XNCJB-YY883-JRW64-DPXMX-JX%f%CR6_MAK___________VisioStdVolume\r\n16_1d1c6879-39a3-47a5-9a6d-aceefa6a289d_B2HTN-JPH8C-J6Y6V-HCHKB-43%f%MGT_MAKC2R________VisioStdXVolume\r\n16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_P8K82-NQ7GG-JKY8T-6VHVY-88%f%GGD_Retail________WordRetail\r\n16_c3000759-551f-4f4a-bcac-a4b42cbf1de2_YHMWC-YN6V9-WJPXD-3WQKP-TM%f%VCV_MAK___________WordVolume\r\n:: Office 2019\r\n16_518687bd-dc55-45b9-8fa6-f918e1082e83_WRYJ6-G3NP7-7VH94-8X7KP-JB%f%7HC_Retail________Access2019Retail\r\n16_385b91d6-9c2c-4a2e-86b5-f44d44a48c5f_6FWHX-NKYXK-BW34Q-7XC9F-Q9%f%PX7_MAK-AE________Access2019Volume\r\n16_22e6b96c-1011-4cd5-8b35-3c8fb6366b86_FGQNJ-JWJCG-7Q8MG-RMRGJ-9T%f%QVF_PrepidBypass__AccessRuntime2019Retail\r\n16_c201c2b7-02a1-41a8-b496-37c72910cd4a_KBPNW-64CMM-8KWCB-23F44-8B%f%7HM_Retail________Excel2019Retail\r\n16_05cb4e1d-cc81-45d5-a769-f34b09b9b391_8NT4X-GQMCK-62X4P-TW6QP-YK%f%PYF_MAK-AE________Excel2019Volume\r\n16_7fe09eef-5eed-4733-9a60-d7019df11cac_QBN2Y-9B284-9KW78-K48PB-R6%f%2YT_Retail________HomeBusiness2019Retail\r\n16_6303d14a-afad-431f-8434-81052a65f575_DJTNY-4HDWM-TDWB2-8PWC2-W2%f%RRT_OEM-ARM_______HomeStudentARM2019Retail\r\n16_215c841d-ffc1-4f03-bd11-5b27b6ab64cc_NM8WT-CFHB2-QBGXK-J8W6J-GV%f%K8F_OEM-ARM_______HomeStudentPlusARM2019Retail\r\n16_4539aa2c-5c31-4d47-9139-543a868e5741_XNWPM-32XQC-Y7QJC-QGGBV-YY%f%7JK_Retail________HomeStudent2019Retail\r\n16_20e359d5-927f-47c0-8a27-38adbdd27124_WR43D-NMWQQ-HCQR2-VKXDR-37%f%B7H_Retail________Outlook2019Retail\r\n16_92a99ed8-2923-4cb7-a4c5-31da6b0b8cf3_RN3QB-GT6D7-YB3VH-F3RPB-3G%f%QYB_MAK-AE________Outlook2019Volume\r\n16_2747b731-0f1f-413e-a92d-386ec1277dd8_NMBY8-V3CV7-BX6K6-2922Y-43%f%M7T_Retail________Personal2019Retail\r\n16_7e63cc20-ba37-42a1-822d-d5f29f33a108_HN27K-JHJ8R-7T7KK-WJYC3-FM%f%7MM_Retail________PowerPoint2019Retail\r\n16_13c2d7bf-f10d-42eb-9e93-abf846785434_29GNM-VM33V-WR23K-HG2DT-KT%f%QYR_MAK-AE________PowerPoint2019Volume\r\n16_a3072b8f-adcc-4e75-8d62-fdeb9bdfae57_BN4XJ-R9DYY-96W48-YK8DM-MY%f%7PY_Retail________ProPlus2019Retail\r\n16_6755c7a7-4dfe-46f5-bce8-427be8e9dc62_T8YBN-4YV3X-KK24Q-QXBD7-T3%f%C63_MAK-AE________ProPlus2019Volume\r\n16_1717c1e0-47d3-4899-a6d3-1022db7415e0_9NXDK-MRY98-2VJV8-GF73J-TQ%f%9FK_Retail________Professional2019Retail\r\n16_0d270ef7-5aaf-4370-a372-bc806b96adb7_JDTNC-PP77T-T9H2W-G4J2J-VH%f%8JK_Retail________ProjectPro2019Retail\r\n16_d4ebadd6-401b-40d5-adf4-a5d4accd72d1_TBXBD-FNWKJ-WRHBD-KBPHH-XD%f%9F2_MAK-AE________ProjectPro2019Volume\r\n16_bb7ffe5f-daf9-4b79-b107-453e1c8427b5_R3JNT-8PBDP-MTWCK-VD2V8-HM%f%KF9_Retail________ProjectStd2019Retail\r\n16_fdaa3c03-dc27-4a8d-8cbf-c3d843a28ddc_RBRFX-MQNDJ-4XFHF-7QVDR-JH%f%XGC_MAK-AE________ProjectStd2019Volume\r\n16_f053a7c7-f342-4ab8-9526-a1d6e5105823_4QC36-NW3YH-D2Y9D-RJPC7-VV%f%B9D_Retail________Publisher2019Retail\r\n16_40055495-be00-444e-99cc-07446729b53e_K8F2D-NBM32-BF26V-YCKFJ-29%f%Y9W_MAK-AE________Publisher2019Volume\r\n16_b639e55c-8f3e-47fe-9761-26c6a786ad6b_JBDKF-6NCD6-49K3G-2TV79-BK%f%P73_Retail________SkypeforBusiness2019Retail\r\n16_15a430d4-5e3f-4e6d-8a0a-14bf3caee4c7_9MNQ7-YPQ3B-6WJXM-G83T3-CB%f%BDK_MAK-AE________SkypeforBusiness2019Volume\r\n16_f88cfdec-94ce-4463-a969-037be92bc0e7_N9722-BV9H6-WTJTT-FPB93-97%f%8MK_PrepidBypass__SkypeforBusinessEntry2019Retail\r\n16_fdfa34dd-a472-4b85-bee6-cf07bf0aaa1c_NDGVM-MD27H-2XHVC-KDDX2-YK%f%P74_Retail________Standard2019Retail\r\n16_beb5065c-1872-409e-94e2-403bcfb6a878_NT3V6-XMBK7-Q66MF-VMKR4-FC%f%33M_MAK-AE________Standard2019Volume\r\n16_a6f69d68-5590-4e02-80b9-e7233dff204e_2NWVW-QGF4T-9CPMB-WYDQ9-7X%f%P79_Retail________VisioPro2019Retail\r\n16_f41abf81-f409-4b0d-889d-92b3e3d7d005_33YF4-GNCQ3-J6GDM-J67P3-FM%f%7QP_MAK-AE________VisioPro2019Volume\r\n16_4a582021-18c2-489f-9b3d-5186de48f1cd_263WK-3N797-7R437-28BKG-3V%f%8M8_Retail________VisioStd2019Retail\r\n16_933ed0e3-747d-48b0-9c2c-7ceb4c7e473d_BGNHX-QTPRJ-F9C9G-R8QQG-8T%f%27F_MAK-AE________VisioStd2019Volume\r\n16_72cee1c2-3376-4377-9f25-4024b6baadf8_JXR8H-NJ3MK-X66W8-78CWD-QR%f%VR2_Retail________Word2019Retail\r\n16_fe5fe9d5-3b06-4015-aa35-b146f85c4709_9F36R-PNVHH-3DXGQ-7CD2H-R9%f%D3V_MAK-AE________Word2019Volume\r\n:: Office 2021\r\n16_f634398e-af69-48c9-b256-477bea3078b5_P286B-N3XYP-36QRQ-29CMP-RV%f%X9M_Retail________Access2021Retail\r\n16_ae17db74-16b0-430b-912f-4fe456e271db_JBH3N-P97FP-FRTJD-MGK2C-VF%f%WG6_MAK-AE________Access2021Volume\r\n16_844c36cb-851c-49e7-9079-12e62a049e2a_MNX9D-PB834-VCGY2-K2RW2-2D%f%P3D_Bypass________AccessRuntime2021Retail\r\n16_fb099c19-d48b-4a2f-a160-4383011060aa_V6QFB-7N7G9-PF7W9-M8FQM-MY%f%8G9_Retail________Excel2021Retail\r\n16_9da1ecdb-3a62-4273-a234-bf6d43dc0778_WNYR4-KMR9H-KVC8W-7HJ8B-K7%f%9DQ_MAK-AE________Excel2021Volume\r\n16_38b92b63-1dff-4be7-8483-2a839441a2bc_JM99N-4MMD8-DQCGJ-VMYFY-R6%f%3YK_Subscription__HomeBusiness2021Retail\r\n16_2f258377-738f-48dd-9397-287e43079958_N3CWD-38XVH-KRX2Y-YRP74-6R%f%BB2_Subscription__HomeStudent2021Retail\r\n16_279706f4-3a4b-4877-949b-f8c299cf0cc5_NB2TQ-3Y79C-77C6M-QMY7H-7Q%f%Y8P_Retail________OneNote2021Retail\r\n16_0c7af60d-0664-49fc-9b01-41b2dea81380_THNKC-KFR6C-Y86Q9-W8CB3-GF%f%7PD_MAK-AE________OneNote2021Volume\r\n16_778ccb9a-2f6a-44e5-853c-eb22b7609643_CNM3W-V94GB-QJQHH-BDQ3J-33%f%Y8H_Bypass________OneNoteFree2021Retail\r\n16_ecea2cfa-d406-4a7f-be0d-c6163250d126_4NCWR-9V92Y-34VB2-RPTHR-YT%f%GR7_Retail________Outlook2021Retail\r\n16_45bf67f9-0fc8-4335-8b09-9226cef8a576_JQ9MJ-QYN6B-67PX9-GYFVY-QJ%f%6TB_MAK-AE________Outlook2021Volume\r\n16_8f89391e-eedb-429d-af90-9d36fbf94de6_RRRYB-DN749-GCPW4-9H6VK-HC%f%HPT_Retail________Personal2021Retail\r\n16_c9bf5e86-f5e3-4ac6-8d52-e114a604d7bf_3KXXQ-PVN2C-8P7YY-HCV88-GV%f%M96_Retail1_______PowerPoint2021Retail\r\n16_716f2434-41b6-4969-ab73-e61e593a3875_39G2N-3BD9C-C4XCM-BD4QG-FV%f%YDY_MAK-AE________PowerPoint2021Volume\r\n16_c2f04adf-a5de-45c5-99a5-f5fddbda74a8_8WXTP-MN628-KY44G-VJWCK-C7%f%PCF_Retail________ProPlus2021Retail\r\n16_3f180b30-9b05-4fe2-aa8d-0c1c4790f811_RNHJY-DTFXW-HW9F8-4982D-MD%f%2CW_MAK-AE1_______ProPlus2021Volume\r\n16_96097a68-b5c5-4b19-8600-2e8d6841a0db_JRJNJ-33M7C-R73X3-P9XF7-R9%f%F6M_MAK-AE________ProPlusSPLA2021Volume\r\n16_711e48a6-1a79-4b00-af10-73f4ca3aaac4_DJPHV-NCJV6-GWPT6-K26JX-C7%f%PBG_Retail________Professional2021Retail\r\n16_3747d1d5-55a8-4bc3-b53d-19fff1913195_QKHNX-M9GGH-T3QMW-YPK4Q-QR%f%WMV_Retail________ProjectPro2021Retail\r\n16_17739068-86c4-4924-8633-1e529abc7efc_HVC34-CVNPG-RVCMT-X2JRF-CR%f%7RK_MAK-AE1_______ProjectPro2021Volume\r\n16_4ea64dca-227c-436b-813f-b6624be2d54c_2B96V-X9NJY-WFBRC-Q8MP2-7C%f%HRR_Retail________ProjectStd2021Retail\r\n16_84313d1e-47c8-4e27-8ced-0476b7ee46c4_3CNQX-T34TY-99RH4-C4YD2-KW%f%6WH_MAK-AE________ProjectStd2021Volume\r\n16_b769b746-53b1-4d89-8a68-41944dafe797_CDNFG-77T8D-VKQJX-B7KT3-KK%f%28V_Retail1_______Publisher2021Retail\r\n16_a0234cfe-99bd-4586-a812-4f296323c760_2KXJH-3NHTW-RDBPX-QFRXJ-MT%f%GXF_MAK-AE________Publisher2021Volume\r\n16_c3fb48b2-1fd4-4dc8-af39-819edf194288_DVBXN-HFT43-CVPRQ-J89TF-VM%f%MHG_Retail________SkypeforBusiness2021Retail\r\n16_6029109c-ceb8-4ee5-b324-f8eb2981e99a_R3FCY-NHGC7-CBPVP-8Q934-YT%f%GXG_MAK-AE________SkypeforBusiness2021Volume\r\n16_9e7e7b8e-a0e7-467b-9749-d0de82fb7297_HXNXB-J4JGM-TCF44-2X2CV-FJ%f%VVH_Retail________Standard2021Retail\r\n16_223a60d8-9002-4a55-abac-593f5b66ca45_2CJN4-C9XK2-HFPQ6-YH498-82%f%TXH_MAK-AE________Standard2021Volume\r\n16_b99ba8c4-e257-4b70-a31a-8bd308ce7073_BQWDW-NJ9YF-P7Y79-H6DCT-MK%f%Q9C_MAK-AE________StandardSPLA2021Volume\r\n16_814014d3-c30b-4f63-a493-3708e0dc0ba8_T6P26-NJVBR-76BK8-WBCDY-TX%f%3BC_Retail________VisioPro2021Retail\r\n16_c590605a-a08a-4cc7-8dc2-f1ffb3d06949_JNKBX-MH9P4-K8YYV-8CG2Y-VQ%f%2C8_MAK-AE________VisioPro2021Volume\r\n16_16d43989-a5ef-47e2-9ff1-272784caee24_89NYY-KB93R-7X22F-93QDF-DJ%f%6YM_Retail________VisioStd2021Retail\r\n16_d55f90ee-4ba2-4d02-b216-1300ee50e2af_BW43B-4PNFP-V637F-23TR2-J4%f%7TX_MAK-AE________VisioStd2021Volume\r\n16_fb33d997-4aa3-494e-8b58-03e9ab0f181d_VNCC4-CJQVK-BKX34-77Y8H-CY%f%XMR_Retail________Word2021Retail\r\n16_0c728382-95fb-4a55-8f12-62e605f91727_BJG97-NW3GM-8QQQ7-FH76G-68%f%6XM_MAK-AE________Word2021Volume\r\n:: Office 2024\r\n16_8fdb1f1e-663f-4f2e-8fdb-7c35aee7d5ea_GNXWX-DF797-B2JT3-82W27-KH%f%PXT_MAK-AE________ProPlus2024Volume-Preview\r\n16_33b11b14-91fd-4f7b-b704-e64a055cf601_X86XX-N3QMW-B4WGQ-QCB69-V2%f%6KW_MAK-AE________ProjectPro2024Volume-Preview\r\n16_eb074198-7384-4bdd-8e6c-c3342dac8435_DW99Y-H7NT6-6B29D-8JQ8F-R3%f%QT7_MAK-AE________VisioPro2024Volume-Preview\r\n16_e563d108-7b0e-418a-8390-20e1d133d6bb_P6NMW-JMTRC-R6MQ6-HH3F2-BT%f%HKB_Retail________Access2024Retail\r\n16_f748e2f7-5951-4bc2-8a06-5a1fbe42f5f4_CXNJT-98HPP-92HX7-MX6GY-2P%f%VFR_MAK-AE________Access2024Volume\r\n16_f3a5e86a-e4f8-4d88-8220-1440c3bbcefa_82CNJ-W82TW-BY23W-BVJ6W-W4%f%8GP_Retail________Excel2024Retail\r\n16_523fbbab-c290-460d-a6c9-48e49709cb8e_7Y287-9N2KC-8MRR3-BKY82-2D%f%QRV_MAK-AE________Excel2024Volume\r\n16_885f83e0-5e18-4199-b8be-56697d0debfb_N69X7-73KPT-899FD-P8HQ4-QG%f%TP4_Retail________Home2024Retail\r\n16_acd4eccb-ff89-4e6a-9350-d2d56276ec69_PRKQM-YNPQR-77QT6-328D7-BD%f%223_Retail________HomeBusiness2024Retail\r\n16_6f5fd645-7119-44a4-91b4-eccfeeb738bf_2CFK4-N44KG-7XG89-CWDG6-P7%f%P27_Retail________Outlook2024Retail\r\n16_9a1e1bac-2d8b-4890-832f-0a68b27c16e0_NQPXP-WVB87-H3MMB-FYBW2-9Q%f%FPB_MAK-AE________Outlook2024Volume\r\n16_da9a57ae-81a8-4cb3-b764-5840e6b5d0bf_CT2KT-GTNWH-9HFGW-J2PWJ-XW%f%7KJ_Retail________PowerPoint2024Retail\r\n16_eca0d8a6-e21b-4622-9a87-a7103ff14012_RRXFN-JJ26R-RVWD2-V7WMP-27%f%PWQ_MAK-AE________PowerPoint2024Volume\r\n16_295dcc21-151a-4b4d-8f50-2b627ea197f6_GNJ6P-Y4RBM-C32WW-2VJKJ-MT%f%HKK_Retail________ProjectPro2024Retail\r\n16_2141d341-41aa-4e45-9ca1-201e117d6495_WNFMR-HK4R7-7FJVM-VQ3JC-76%f%HF6_MAK-AE1_______ProjectPro2024Volume\r\n16_ead42f74-817d-45b4-af6b-3beeb36ba650_C2PNM-2GQFC-CY3XR-WXCP4-GX%f%3XM_Retail________ProjectStd2024Retail\r\n16_4b6d9b9b-c16e-429d-babe-8bb84c3c27d6_F2VNW-MW8TT-K622Q-4D96H-PW%f%J8X_MAK-AE________ProjectStd2024Volume\r\n16_db249714-bb54-4422-8c78-2cc8d4c4a19f_VWCNX-7FKBD-FHJYG-XBR4B-88%f%KC6_Retail________ProPlus2024Retail\r\n16_d77244dc-2b82-4f0a-b8ae-1fca00b7f3e2_4YV2J-VNG7W-YGTP3-443TK-TF%f%8CP_MAK-AE1_______ProPlus2024Volume\r\n16_3046a03e-2277-4a51-8ccd-a6609eae8c19_XKRBW-KN2FF-G8CKY-HXVG6-FV%f%Y2V_MAK-AE________SkypeforBusiness2024Volume\r\n16_44a07f51-8263-4b2f-b2a5-70340055c646_GVG6N-6WCHH-K2MVP-RQ78V-3J%f%7GJ_MAK-AE1_______Standard2024Volume\r\n16_282d8f34-1111-4a6f-80fe-c17f70dec567_HGRBX-N68QF-6DY8J-CGX4W-XW%f%7KP_Retail________VisioPro2024Retail\r\n16_4c2f32bf-9d0b-4d8c-8ab1-b4c6a0b9992d_GBNHB-B2G3Q-G42YB-3MFC2-7C%f%JCX_MAK-AE________VisioPro2024Volume\r\n16_8504167d-887a-41ae-bd1d-f849d834352d_VBXPJ-38NR3-C4DKF-C8RT7-RG%f%HKQ_Retail________VisioStd2024Retail\r\n16_0978336b-5611-497c-9414-96effaff4938_YNFTY-63K7P-FKHXK-28YYT-D3%f%2XB_MAK-AE________VisioStd2024Volume\r\n16_f6b24e61-6aa7-4fd2-ab9b-4046cee4230a_XN33R-RP676-GMY2F-T3MH7-GC%f%VKR_Retail________Word2024Retail\r\n16_06142aa2-e935-49ca-af5d-08069a3d84f3_WD8CQ-6KNQM-8W2CX-2RT63-KK%f%3TP_MAK-AE________Word2024Volume\r\n) do (\r\nfor /f \"tokens=1-5 delims=_\" %%A in (\"%%#\") do (\r\n\r\nif %1==getinfo if not defined key (\r\nif %oVer%==%%A if /i \"%2\"==\"%%E\" (\r\nset key=%%C\r\nset _actid=%%B\r\nset _allactid=!_allactid! %%B\r\nset _lic=%%D\r\nif %oVer%==16 (echo \"%%D\" | find /i \"Subscription\" %nul% && set _sublic=1)\r\n)\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Office version number\r\n::  2nd column = Activation ID\r\n::  3rd column = Product ID from branding.xml\r\n::  4th column = Edition\r\n::  5th column = Other Edition IDs if they are part of the same primary product (For reference only)\r\n::  Separator  = \"_\"\r\n\r\n:msiofficedata\r\n\r\nfor %%# in (\r\n14_4d463c2c-0505-4626-8cdb-a4da82e2d8ed_0015_AccessR\r\n14_745fb377-0a59-4ca9-b9a9-c359557a2c4e_001C_AccessRuntimeR\r\n14_95ab3ec8-4106-4f9d-b632-03c019d1d23f_0015_AccessVL\r\n14_4eaff0d0-c6cb-4187-94f3-c7656d49a0aa_0016_ExcelR_[HSExcelR]\r\n14_71dc86ff-f056-40d0-8ffb-9592705c9b76_0016_ExcelVL\r\n14_7004b7f0-6407-4f45-8eac-966e5f868bde_00BA_GrooveR\r\n14_fdad0dfa-417d-4b4f-93e4-64ea8867b7fd_00BA_GrooveVL\r\n14_7b7d1f17-fdcb-4820-9789-9bec6e377821_0013_HomeBusinessR_[HomeBusinessDemoR]\r\n14_19316117-30a8-4773-8fd9-7f7231f4e060_011E_HomeBusinessSubR\r\n14_09e2d37e-474b-4121-8626-58ad9be5776f_002F_HomeStudentR_[HomeStudentDemoR]\r\n14_ef1da464-01c8-43a6-91af-e4e5713744f9_0044_InfoPathR\r\n14_85e22450-b741-430c-a172-a37962c938af_0044_InfoPathVL\r\n14_14f5946a-debc-4716-babc-7e2c240fec08_000F_MondoR\r\n14_533b656a-4425-480b-8e30-1a2358898350_000F_MondoVL\r\n14_c1ceda8b-c578-4d5d-a4aa-23626be4e234_003D_ProfessionalR_[OEM-SingleImage]Exception\r\n14_3f7aa693-9a7e-44fc-9309-bb3d8e604925_00A1_OneNoteR_[HSOneNoteR]\r\n14_6860b31f-6a67-48b8-84b9-e312b3485c4b_00A1_OneNoteVL\r\n14_fbf4ac36-31c8-4340-8666-79873129cf40_001A_OutlookR\r\n14_a9aeabd8-63b8-4079-a28e-f531807fd6b8_001A_OutlookVL\r\n14_acb51361-c0db-4895-9497-1831c41f31a6_0033_PersonalR_[PersonalDemoR,PersonalPrepaidR]\r\n14_133c8359-4e93-4241-8118-30bb18737ea0_0018_PowerPointR_[HSPowerPointR]\r\n14_38252940-718c-4aa6-81a4-135398e53851_0018_PowerPointVL\r\n14_8b559c37-0117-413e-921b-b853aeb6e210_0014_ProfessionalR_[ProfessionalAcadR,ProfessionalDemoR]\r\n14_725714d7-d58f-4d12-9fa8-35873c6f7215_003B_ProjectProR_[ProjectProMSDNR]\r\n14_4d06f72e-fd50-4bc2-a24b-d448d7f17ef2_011F_ProjectProSubR\r\n14_1cf57a59-c532-4e56-9a7d-ffa2fe94b474_003B_ProjectProVL\r\n14_688f6589-2bd9-424e-a152-b13f36aa6de1_003A_ProjectStdR\r\n14_11b39439-6b93-4642-9570-f2eb81be2238_003A_ProjectStdVL\r\n14_71af7e84-93e6-4363-9b69-699e04e74071_0011_ProPlusR_[ProPlusAcadR,ProPlusMSDNR,Sub4R]\r\n14_e98ef0c0-71c4-42ce-8305-287d8721e26c_011D_ProPlusSubR\r\n14_fdf3ecb9-b56f-43b2-a9b8-1b48b6bae1a7_0011_ProPlusVL_[ProPlusAcadVL]\r\n14_98677603-a668-4fa4-9980-3f1f05f78f69_0019_PublisherR\r\n14_3d014759-b128-4466-9018-e80f6320d9d0_0019_PublisherVL\r\n14_dbe3aee0-5183-4ff7-8142-66050173cb01_008B_SmallBusBasicsR_[SmallBusBasicsMSDNR]\r\n14_8090771e-d41a-4482-929e-de87f1f47e46_008B_SmallBusBasicsVL\r\n14_b78df69e-0966-40b1-ae85-30a5134dedd0_0017_SPDR\r\n14_d3422cfb-8d8b-4ead-99f9-eab0ccd990d7_0012_StandardR\r\n14_1f76e346-e0be-49bc-9954-70ec53a4fcfe_0012_StandardVL_[StandardAcadVL]\r\n14_2745e581-565a-4670-ae90-6bf7c57ffe43_0066_StarterR\r\n14_66cad568-c2dc-459d-93ec-2f3cb967ee34_0057_VisioSIR_Prem[Pro,Std]Exception\r\n14_36756cb8-8e69-4d11-9522-68899507cd6a_0057_VisioSIVL_Prem[Pro,Std]Exception\r\n14_db3bbc9c-ce52-41d1-a46f-1a1d68059119_001B_WordR_[HSWordR]\r\n14_98d4050e-9c98-49bf-9be1-85e12eb3ab13_001B_WordVL\r\n:: Office 2013\r\n15_ab4d047b-97cf-4126-a69f-34df08e2f254_0015_AccessRetail\r\n15_259de5be-492b-44b3-9d78-9645f848f7b0_001C_AccessRuntimeRetail\r\n15_4374022d-56b8-48c1-9bb7-d8f2fc726343_0015_AccessVolume\r\n15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_0016_ExcelRetail\r\n15_ac1ae7fd-b949-4e04-a330-849bc40638cf_0016_ExcelVolume\r\n15_cfaf5356-49e3-48a8-ab3c-e729ab791250_00BA_GrooveRetail\r\n15_4825ac28-ce41-45a7-9e6e-1fed74057601_00BA_GrooveVolume\r\n15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_00E7_HomeBusinessPipcRetail\r\n15_cd256150-a898-441f-aac0-9f8f33390e45_0013_HomeBusinessRetail\r\n15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_00CE_HomeStudentARMRetail\r\n15_ebef9f05-5273-404a-9253-c5e252f50555_00DA_HomeStudentPlusARMRetail\r\n15_98685d21-78bd-4c62-bc4f-653344a63035_002F_HomeStudentRetail\r\n15_44984381-406e-4a35-b1c3-e54f499556e2_0044_InfoPathRetail\r\n15_9e016989-4007-42a6-8051-64eb97110cf2_0044_InfoPathVolume\r\n15_9103f3ce-1084-447a-827e-d6097f68c895_00EA_LyncAcademicRetail\r\n15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_012D_LyncEntryRetail\r\n15_fada6658-bfc6-4c4e-825a-59a89822cda8_012C_LyncRetail\r\n15_e1264e10-afaf-4439-a98b-256df8bb156f_012C_LyncVolume\r\n15_3169c8df-f659-4f95-9cc6-3115e6596e83_000F_MondoRetail\r\n15_f33485a0-310b-4b72-9a0e-b1d605510dbd_000F_MondoVolume\r\n15_3391e125-f6e4-4b1e-899c-a25e6092d40d_00A1_OneNoteFreeRetail\r\n15_8b524bcc-67ea-4876-a509-45e46f6347e8_00A1_OneNoteRetail\r\n15_b067e965-7521-455b-b9f7-c740204578a2_00A1_OneNoteVolume\r\n15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_001A_OutlookRetail\r\n15_8d577c50-ae5e-47fd-a240-24986f73d503_001A_OutlookVolume\r\n15_5aab8561-1686-43f7-9ff5-2c861da58d17_00E6_PersonalPipcRetail\r\n15_17e9df2d-ed91-4382-904b-4fed6a12caf0_0033_PersonalRetail\r\n15_31743b82-bfbc-44b6-aa12-85d42e644d5b_0018_PowerPointRetail\r\n15_e40dcb44-1d5c-4085-8e8f-943f33c4f004_0018_PowerPointVolume\r\n15_4e26cac1-e15a-4467-9069-cb47b67fe191_00E8_ProfessionalPipcRetail\r\n15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_0014_ProfessionalRetail\r\n15_f2435de4-5fc0-4e5b-ac97-34f515ec5ee7_003B_ProjectProRetail\r\n15_ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32_003B_ProjectProVolume\r\n15_5517e6a2-739b-4822-946f-7f0f1c5934b1_003A_ProjectStdRetail\r\n15_2b9e4a37-6230-4b42-bee2-e25ce86c8c7a_003A_ProjectStdVolume\r\n15_064383fa-1538-491c-859b-0ecab169a0ab_0011_ProPlusRetail\r\n15_2b88c4f2-ea8f-43cd-805e-4d41346e18a7_0011_ProPlusVolume\r\n15_c3a0814a-70a4-471f-af37-2313a6331111_0019_PublisherRetail\r\n15_38ea49f6-ad1d-43f1-9888-99a35d7c9409_0019_PublisherVolume\r\n15_ba3e3833-6a7e-445a-89d0-7802a9a68588_0017_SPDRetail\r\n15_32255c0a-16b4-4ce2-b388-8a4267e219eb_0012_StandardRetail\r\n15_a24cca51-3d54-4c41-8a76-4031f5338cb2_0012_StandardVolume\r\n15_15d12ad4-622d-4257-976c-5eb3282fb93d_0051_VisioProRetail\r\n15_3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d_0051_VisioProVolume\r\n15_dae597ce-5823-4c77-9580-7268b93a4b23_0053_VisioStdRetail\r\n15_44a1f6ff-0876-4edb-9169-dbb43101ee89_0053_VisioStdVolume\r\n15_191509f2-6977-456f-ab30-cf0492b1e93a_001B_WordRetail\r\n15_9cedef15-be37-4ff0-a08a-13a045540641_001B_WordVolume\r\n:: Office 365 - 15.0 version\r\n15_befee371-a2f5-4648-85db-a2c55fdf324c_00E9_O365BusinessRetail\r\n15_537ea5b5-7d50-4876-bd38-a53a77caca32_00D6_O365HomePremRetail\r\n15_149dbce7-a48e-44db-8364-a53386cd4580_00D4_O365ProPlusRetail\r\n15_bacd4614-5bef-4a5e-bafc-de4c788037a2_00D5_O365SmallBusPremRetail\r\n:: Office 365 - 16.0 version\r\n16_6337137e-7c07-4197-8986-bece6a76fc33_00E9_O365BusinessRetail\r\n16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_00D6_O365EduCloudRetail\r\n16_537ea5b5-7d50-4876-bd38-a53a77caca32_00D6_O365HomePremRetail\r\n16_149dbce7-a48e-44db-8364-a53386cd4580_00D4_O365ProPlusRetail\r\n16_bacd4614-5bef-4a5e-bafc-de4c788037a2_00D5_O365SmallBusPremRetail\r\n:: Office 2016\r\n16_bfa358b0-98f1-4125-842e-585fa13032e6_0015_AccessRetail\r\n16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_001C_AccessRuntimeRetail\r\n16_3b2fa33f-cd5a-43a5-bd95-f49f3f546b0b_0015_AccessVolume\r\n16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_0016_ExcelRetail\r\n16_685062a7-6024-42e7-8c5f-6bb9e63e697f_0016_ExcelVolume\r\n16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_00E7_HomeBusinessPipcRetail\r\n16_86834d00-7896-4a38-8fae-32f20b86fa2b_0013_HomeBusinessRetail\r\n16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_00CE_HomeStudentARMRetail\r\n16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_00DA_HomeStudentPlusARMRetail\r\n16_c28acdb8-d8b3-4199-baa4-024d09e97c99_002F_HomeStudentRetail\r\n16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_002F_HomeStudentVNextRetail\r\n16_b21367df-9545-4f02-9f24-240691da0e58_000F_MondoRetail\r\n16_2cd0ea7e-749f-4288-a05e-567c573b2a6c_000F_MondoVolume\r\n16_436366de-5579-4f24-96db-3893e4400030_00A3_OneNoteFreeRetail\r\n16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_00A1_OneNoteRetail\r\n16_23b672da-a456-4860-a8f3-e062a501d7e8_00A1_OneNoteVolume\r\n16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_001A_OutlookRetail\r\n16_50059979-ac6f-4458-9e79-710bcb41721a_001A_OutlookVolume\r\n16_5aab8561-1686-43f7-9ff5-2c861da58d17_00E6_PersonalPipcRetail\r\n16_a9f645a1-0d6a-4978-926a-abcb363b72a6_0033_PersonalRetail\r\n16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_0018_PowerPointRetail\r\n16_9b4060c9-a7f5-4a66-b732-faf248b7240f_0018_PowerPointVolume\r\n16_4e26cac1-e15a-4467-9069-cb47b67fe191_00E8_ProfessionalPipcRetail\r\n16_d64edc00-7453-4301-8428-197343fafb16_0014_ProfessionalRetail\r\n16_0f42f316-00b1-48c5-ada4-2f52b5720ad0_003B_ProjectProRetail\r\n16_82f502b5-b0b0-4349-bd2c-c560df85b248_003B_ProjectProVolume\r\n16_16728639-a9ab-4994-b6d8-f81051e69833_003B_ProjectProXVolume\r\n16_e9f0b3fc-962f-4944-ad06-05c10b6bcd5e_003A_ProjectStdRetail\r\n16_82e6b314-2a62-4e51-9220-61358dd230e6_003A_ProjectStdVolume\r\n16_431058f0-c059-44c5-b9e7-ed2dd46b6789_003A_ProjectStdXVolume\r\n16_de52bd50-9564-4adc-8fcb-a345c17f84f9_0011_ProPlusRetail\r\n16_c47456e3-265d-47b6-8ca0-c30abbd0ca36_0011_ProPlusVolume\r\n16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_0019_PublisherRetail\r\n16_fcc1757b-5d5f-486a-87cf-c4d6dedb6032_0019_PublisherVolume\r\n16_971cd368-f2e1-49c1-aedd-330909ce18b6_012D_SkypeforBusinessEntryRetail\r\n16_418d2b9f-b491-4d7f-84f1-49e27cc66597_012C_SkypeforBusinessRetail\r\n16_03ca3b9a-0869-4749-8988-3cbc9d9f51bb_012C_SkypeforBusinessVolume\r\n16_9103f3ce-1084-447a-827e-d6097f68c895_012C_SkypeServiceBypassRetail\r\n16_4a31c291-3a12-4c64-b8ab-cd79212be45e_0012_StandardRetail\r\n16_0ed94aac-2234-4309-ba29-74bdbb887083_0012_StandardVolume\r\n16_2dfe2075-2d04-4e43-816a-eb60bbb77574_0051_VisioProRetail\r\n16_295b2c03-4b1c-4221-b292-1411f468bd02_0051_VisioProVolume\r\n16_0594dc12-8444-4912-936a-747ca742dbdb_0051_VisioProXVolume\r\n16_c76dbcbc-d71b-4f45-b5b3-b7494cb4e23e_0053_VisioStdRetail\r\n16_44151c2d-c398-471f-946f-7660542e3369_0053_VisioStdVolume\r\n16_1d1c6879-39a3-47a5-9a6d-aceefa6a289d_0053_VisioStdXVolume\r\n16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_001B_WordRetail\r\n16_c3000759-551f-4f4a-bcac-a4b42cbf1de2_001B_WordVolume\r\n) do (\r\nfor /f \"tokens=1-5 delims=_\" %%A in (\"%%#\") do (\r\n\r\nif \"%oVer%\"==\"%%A\" (\r\nreg query \"%1\\Registration\\{%%B}\" /v ProductCode %nul2% | find /i \"-%%C-\" %nul% && (\r\nreg query \"%1\\Common\\InstalledPackages\" %nul2% | find /i \"-%%C-\" %nul% && (\r\nif defined _oIds (set _oIds=!_oIds! %%D) else (set _oIds=%%D)\r\nif /i 003D==%%C set SingleImage=1\r\n)\r\n)\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  This code is used to modify the timestamp value of sppc dll file in order to change checksums\r\n::  It's done to lower the potential false positive detection by antivirus's. On each install, it will install a unique sppc dll file\r\n\r\n:oh_extractdll\r\n\r\nset b=\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':%_hook%\\:.*';$encoded = ($f[1]) -replace '-', 'A' -replace '_', 'a';$bytes = [Con%b%vert]::FromBas%b%e64String($encoded); $PePath='%1'; $offset='%2'; $m=[System.IO.File]::ReadAllText('!_batp!') -split ':hexedit\\:.*';. ([scriptblock]::Create($m[1]))\" %nul2% | find /i \"Error found\" %nul1% && set hasherror=1\r\nexit /b\r\n\r\n:hexedit:\r\n# Use a MemoryStream to perform operations on the bytes\r\n$MemoryStream = New-Object System.IO.MemoryStream\r\n$Writer = New-Object System.IO.BinaryWriter($MemoryStream)\r\n$Writer.Write($bytes)\r\n\r\n# Define dynamic assembly, module, and type\r\n$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)\r\n$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)\r\n$TypeBuilder = $ModuleBuilder.DefineType(0)\r\n\r\n# Define P/Invoke method\r\n[void]$TypeBuilder.DefinePInvokeMethod('MapFileAndCheckSum', 'imagehlp.dll', 'Public, Static', [Reflection.CallingConventions]::Standard, [int], @([string], [int].MakeByRefType(), [int].MakeByRefType()), [Runtime.InteropServices.CallingConvention]::Winapi, [Runtime.InteropServices.CharSet]::Auto)\r\n\r\n# Create the type\r\n$Imagehlp = $TypeBuilder.CreateType()\r\n\r\n# Offset information\r\n$timestampOffset = 136\r\n$exportTimestampOffset = $offset\r\n$checkSumOffset = 216\r\n\r\n# Calculate timestamp\r\n$currentTimestamp = [DateTime]::UtcNow\r\n$unixTimestamp = [int]($currentTimestamp - (Get-Date -Year 1970 -Month 1 -Day 1 -Hour 0 -Minute 0 -Second 0)).TotalSeconds\r\n\r\n# Change timestamps\r\n$Writer.BaseStream.Position = $timestampOffset\r\n$Writer.Write($unixTimestamp)\r\n\r\n$Writer.BaseStream.Position = $exportTimestampOffset\r\n$Writer.Write($unixTimestamp)\r\n\r\n$Writer.Flush()\r\n\r\n# Write the current state of the MemoryStream to a temporary file\r\n$tempFilePath = \"$env:windir\\Temp\\$([System.IO.Path]::GetRandomFileName())\"\r\n[System.IO.File]::WriteAllBytes($tempFilePath, $MemoryStream.ToArray())\r\n\r\n# Update hash using the temporary file\r\n[int]$HeaderSum = 0\r\n[int]$CheckSum = 0\r\n[void]$Imagehlp::MapFileAndCheckSum($tempFilePath, [ref]$HeaderSum, [ref]$CheckSum)\r\n\r\n# If the checksums don't match, update the checksum in the MemoryStream\r\nif ($HeaderSum -ne $CheckSum) {\r\n    $Writer.BaseStream.Position = $checkSumOffset\r\n    $Writer.Write($CheckSum)\r\n    $Writer.Flush()\r\n} else {\r\n    Write-host Error found\r\n}\r\n\r\n# Delete the temporary file\r\nRemove-Item -Path $tempFilePath -Force\r\n\r\n# Get the modified bytes\r\n$modifiedBytes = $MemoryStream.ToArray()\r\n\r\n# Write the modified bytes to the final file\r\n[System.IO.File]::WriteAllBytes($PePath, $modifiedBytes)\r\n\r\n[void]$Imagehlp::MapFileAndCheckSum($PePath, [ref]$HeaderSum, [ref]$CheckSum)\r\nif ($HeaderSum -ne $CheckSum) {\r\n    Write-host Error found\r\n}\r\n\r\n$MemoryStream.Close()\r\n:hexedit:\r\n\r\n::========================================================================================================================================\r\n::\r\n::  This below blocks of text is encoded in base64 format\r\n::  The blocks in labels \"sppc32.dll\" and \"sppc64.dll\" contains below files\r\n::\r\n::  09865ea5993215965e8f27a74b8a41d15fd0f60f5f404cb7a8b3c7757acdab02 *sppc32.dll\r\n::  393a1fa26deb3663854e41f2b687c188a9eacd87b23f17ea09422c4715cb5a9f *sppc64.dll\r\n::\r\n::  The files are encoded in base64 to make AIO version.\r\n::\r\n::  mass{}grave{dot}dev/ohook\r\n::  Here you can find the files source code and info on how to rebuild the identical sppc.dll files\r\n::\r\n::  stackoverflow.com/a/35335273\r\n::  Here you can check how to extract sppc.dll files from base64\r\n::\r\n::  For any further question, feel free to contact us on mass{}grave{dot}dev/contactus\r\n::\r\n::========================================================================================================================================\r\n::\r\n::  If you want to use a different sppc.dll or without base64 format, then create a folder named \"BIN\" where this script is located and \r\n::  place these two files in that \"BIN\" folder. sppc32.dll, sppc64.dll\r\n::  Script will auto pick that instead of using the below from base64 section. You can also delete the below code in that case.\r\n::\r\n::========================================================================================================================================\r\n::\r\n::  Replace \"-\" with \"A\" and \"_\" with \"a\" before base64 conversion\r\n::  It was changed to prevent antiviruses from detecting and flagging base64 encoding\r\n\r\n:sppc32.dll:\r\nTVqQ--M----E----//8--Lg---------Q-----------------------------------------------g-----4fug4-t-nNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4g_W4gRE9TIG1vZGUuDQ0KJ---------BQRQ--T-EH-MDc0GQ----------O--\r\nDiML-QIo--I----e--------RxE----Q----------C-_g-Q-----g--B-----E----G----------CQ----B---+dY---I-Q-E--C---B------E---E--------B------Q---jR----Bg---Y-Q---H---HgD-------------------------I---BQ---------\r\n----------------------------------------------------------BsY---H------------------------------------C50ZXh0----c-E----Q-----g----Q------------------C---G-ucmRhdGE--Bg-----I-----I----G----------------\r\n--B---B-LmVoX2ZyYW2------D-----C----C-------------------Q---QC5lZGF0YQ--jR----B-----Eg----o------------------E---E-u_WRhdGE--BgB----Y-----I----c------------------B---D-LnJzcmM---B4-w---H-----E----Hg--\r\n----------------Q---wC5yZWxvYw--F-----C------g---CI------------------E---EI-----------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n---------------------------------------------------------------------------------------------------------------------------------------------------------------------FWJ5VZTjUXwg+wwx0Xw-----IlEJBSNRfSJ\r\nRCQQi0UMx0QkD-----CJRCQEi0UIx0QkC--ggGqJBCTHRfQ-----6-oB--CLNXhggGqD7BiFwInDi0Xwd-qJBCQx2//WUesyi1X0x0QkB-oggGqJBCSJVCQI/xW-YIBqg+wMhcCLRfCJBCR0Cv/WuwE---BS6wP/1lCNZfiJ2FteXcNVieVXVlOD7DyLRRiLdRyJRCQQ\r\ni0UUiXQkFIlEJ-yLRRCJRCQIi0UMiUQkBItFCIkEJOiE----McmD7BiJx4X-dVyLRRg5CHZV_9koiwYB2IN4E-B0RYlEJ-SLRQiJTeSJBCTo+/7//4tN5IX-dSwDHsdDE-E---DHQxQ-----x0MY-----MdDH-----DHQy------x0Mk-----EHrpI1l9In4W15fXcIY\r\n-LgB----wgw-kP8lcGC-_pCQ/yVsYIBqkJD/////-----P////8-----------------------------------------------------------------------------------------------------------------------------------------------------\r\n------------------------------------------------TgBh-G0-ZQ---Ec-cgBh-GM-ZQ------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n-----------------------------------------------------------------------------------------------------------------------------------U----------F6Ug-Bf-gBGwwEBIgB---k----H----ODf//+d-----EEOCIUCQg0FSIYD\r\ngwQCj8NBxkHFD-QEK----EQ---BV4P//qg----BBDgiF-kINBU_H-4YEgwUCm8NBxkHHQcUMB-QQ----c----NPg//8I------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n------------------D-3NBk-----MZC---B----Qw---EM----oQ---NEE--EBC--DPQg--70I---VD---pQw--XUM--KFD--DpQw--F0Q--DVE--BnR---nUQ--ONE---tRQ--YUU--J9F--DTRQ--DUY--DtG--BxRg--r0Y--M9G--D7Rg--nR---FFH--BvRw--\r\nn0c--NNH---RS---TUg--G9I--ClS---zUg---VJ--BBSQ--bUk--KdJ--C7SQ--+0k--DlK--BPSg--dUo--J1K--DTSg--B0s--D1L--BpSw--pUs--ONL---NT---OUw--IlM--DRT---EU0--FlN--CjTQ--8U0--BtO--BHTg--h04--LtO--DnTg--K08--FtP\r\n--C1Tw--608--CdQ--BdU---4kI--P1C---_Qw--RkM--IJD--DIQw---0Q--ClE--BRR---hUQ--MNE---LRQ--SkU--INF--C8RQ--80U--CdG--BZRg--k0Y--MJG--DoRg--GUc--DFH--BjRw--ikc--LxH--D1Rw--Mkg--GFI--CNS---vEg--OxI---mSQ--\r\nWkk--I1J--C0SQ--3kk--B1K--BHSg--ZUo--IxK--C7Sg--8Eo--CVL--BWSw--iks--MdL--D7Sw--Jkw--GRM--CwT---9Ew--DhN--CBTQ--zU0---lO---0Tg--_k4--KRO--DUTg--DE8--EZP--CLTw--008---xQ--BFU---eF-------Q-C--M-B--F--Y-\r\nBw-I--k-Cg-L--w-DQ-O--8-E--R-BI-Ew-U-BU-Fg-X-Bg-GQ-_-Bs-H--d-B4-Hw-g-CE-Ig-j-CQ-JQ-m-Cc-K--p-Co-Kw-s-C0-Lg-v-D--MQ-y-DM-N--1-DY-Nw-4-Dk-Og-7-Dw-PQ-+-D8-Q-BB-EI-c3BwYy5kbGw-U1BQQ1MuU0xDYWxsU2VydmVy-FNM\r\nQ2FsbFNlcnZlcgBTUFBDUy5TTENsb3Nl-FNMQ2xvc2U-U1BQQ1MuU0xDb25zdW1lUmln_HQ-U0xDb25zdW1lUmln_HQ-U1BQQ1MuU0xEZXBvc2l0TWlncmF0_W9uQmxvYgBTTERlcG9z_XRN_WdyYXRpb25CbG9i-FNQUENTLlNMRGVwb3NpdE9mZmxpbmVDb25m_XJt\r\nYXRpb25JZ-BTTERlcG9z_XRPZmZs_W5lQ29uZmlybWF0_W9uSWQ-U1BQQ1MuU0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklkRXg-U0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklkRXg-U1BQQ1MuU0xEZXBvc2l0U3RvcmVUb2tlbgBTTERlcG9z_XRTdG9y\r\nZVRv_2Vu-FNQUENTLlNMRmlyZUV2ZW50-FNMRmlyZUV2ZW50-FNQUENTLlNMR2F0_GVyTWlncmF0_W9uQmxvYgBTTEdhdGhlck1pZ3JhdGlvbkJsb2I-U1BQQ1MuU0xHYXRoZXJN_WdyYXRpb25CbG9iRXg-U0xHYXRoZXJN_WdyYXRpb25CbG9iRXg-U1BQQ1MuU0xH\r\nZW5lcmF0ZU9mZmxpbmVJbnN0YWxsYXRpb25JZ-BTTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklk-FNQUENTLlNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWRFe-BTTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklkRXg-U1BQQ1MuU0xHZXRBY3Rp\r\ndmVM_WNlbnNlSW5mbwBTTEdldEFjdGl2ZUxpY2Vuc2VJbmZv-FNQUENTLlNMR2V0QXBwbGljYXRpb25JbmZvcm1hdGlvbgBTTEdldEFwcGxpY2F0_W9uSW5mb3JtYXRpb24-U1BQQ1MuU0xHZXRBcHBs_WNhdGlvblBvbGljeQBTTEdldEFwcGxpY2F0_W9uUG9s_WN5\r\n-FNQUENTLlNMR2V0QXV0_GVudGljYXRpb25SZXN1bHQ-U0xHZXRBdXRoZW50_WNhdGlvblJlc3Vsd-BTUFBDUy5TTEdldEVuY3J5cHRlZFBJREV4-FNMR2V0RW5jcnlwdGVkUElERXg-U1BQQ1MuU0xHZXRHZW51_W5lSW5mb3JtYXRpb24-U0xHZXRHZW51_W5lSW5m\r\nb3JtYXRpb24-U1BQQ1MuU0xHZXRJbnN0YWxsZWRQcm9kdWN0S2V5SWRz-FNMR2V0SW5zdGFsbGVkUHJvZHVjdEtleUlkcwBTUFBDUy5TTEdldExpY2Vuc2U-U0xHZXRM_WNlbnNl-FNQUENTLlNMR2V0TGljZW5zZUZpbGVJZ-BTTEdldExpY2Vuc2VG_WxlSWQ-U1BQ\r\nQ1MuU0xHZXRM_WNlbnNlSW5mb3JtYXRpb24-U0xHZXRM_WNlbnNlSW5mb3JtYXRpb24-U0xHZXRM_WNlbnNpbmdTdGF0dXNJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFBLZXlJZ-BTTEdldFBLZXlJZ-BTUFBDUy5TTEdldFBLZXlJbmZvcm1hdGlvbgBTTEdldFBLZXlJ\r\nbmZvcm1hdGlvbgBTUFBDUy5TTEdldFBvbGljeUluZm9ybWF0_W9u-FNMR2V0UG9s_WN5SW5mb3JtYXRpb24-U1BQQ1MuU0xHZXRQb2xpY3lJbmZvcm1hdGlvbkRXT1JE-FNMR2V0UG9s_WN5SW5mb3JtYXRpb25EV09SR-BTUFBDUy5TTEdldFByb2R1Y3RT_3VJbmZv\r\ncm1hdGlvbgBTTEdldFByb2R1Y3RT_3VJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFNMSURM_XN0-FNMR2V0U0xJRExpc3Q-U1BQQ1MuU0xHZXRTZXJ2_WNlSW5mb3JtYXRpb24-U0xHZXRTZXJ2_WNlSW5mb3JtYXRpb24-U1BQQ1MuU0xJbnN0YWxsTGljZW5zZQBTTElu\r\nc3RhbGxM_WNlbnNl-FNQUENTLlNMSW5zdGFsbFByb29mT2ZQdXJj_GFzZQBTTEluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U1BQQ1MuU0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNlRXg-U0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNlRXg-U1BQQ1MuU0xJc0dlbnVpbmVMb2Nh\r\nbEV4-FNMSXNHZW51_W5lTG9jYWxFe-BTUFBDUy5TTExvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNMTG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U1BQQ1MuU0xPcGVu-FNMT3BlbgBTUFBDUy5TTFBlcnNpc3RBcHBs_WNhdGlvblBvbGlj_WVz-FNMUGVyc2lzdEFwcGxp\r\nY2F0_W9uUG9s_WNpZXM-U1BQQ1MuU0xQZXJz_XN0UlRTUGF5bG9hZE92ZXJy_WRl-FNMUGVyc2lzdFJUU1BheWxvYWRPdmVycmlkZQBTUFBDUy5TTFJlQXJt-FNMUmVBcm0-U1BQQ1MuU0xSZWdpc3RlckV2ZW50-FNMUmVn_XN0ZXJFdmVud-BTUFBDUy5TTFJlZ2lz\r\ndGVyUGx1Z2lu-FNMUmVn_XN0ZXJQbHVn_W4-U1BQQ1MuU0xTZXRBdXRoZW50_WNhdGlvbkRhdGE-U0xTZXRBdXRoZW50_WNhdGlvbkRhdGE-U1BQQ1MuU0xTZXRDdXJyZW50UHJvZHVjdEtleQBTTFNldEN1cnJlbnRQcm9kdWN0S2V5-FNQUENTLlNMU2V0R2VudWlu\r\nZUluZm9ybWF0_W9u-FNMU2V0R2VudWluZUluZm9ybWF0_W9u-FNQUENTLlNMVW5pbnN0YWxsTGljZW5zZQBTTFVu_W5zdGFsbExpY2Vuc2U-U1BQQ1MuU0xVbmluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U0xVbmluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U1BQQ1MuU0xV\r\nbmxvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNMVW5sb2FkQXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5TTFVucmVn_XN0ZXJFdmVud-BTTFVucmVn_XN0ZXJFdmVud-BTUFBDUy5TTFVucmVn_XN0ZXJQbHVn_W4-U0xVbnJlZ2lzdGVyUGx1Z2lu-FNQUENTLlNMcEF1\r\ndGhlbnRpY2F0ZUdlbnVpbmVU_WNrZXRSZXNwb25zZQBTTHBBdXRoZW50_WNhdGVHZW51_W5lVGlj_2V0UmVzcG9uc2U-U1BQQ1MuU0xwQmVn_W5HZW51_W5lVGlj_2V0VHJhbnNhY3Rpb24-U0xwQmVn_W5HZW51_W5lVGlj_2V0VHJhbnNhY3Rpb24-U1BQQ1MuU0xw\r\nQ2xlYXJBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTTHBDbGVhckFjdGl2YXRpb25JblByb2dyZXNz-FNQUENTLlNMcERlcG9z_XREb3dubGV2ZWxHZW51_W5lVGlj_2V0-FNMcERlcG9z_XREb3dubGV2ZWxHZW51_W5lVGlj_2V0-FNQUENTLlNMcERlcG9z_XRUb2tlbkFj\r\ndGl2YXRpb25SZXNwb25zZQBTTHBEZXBvc2l0VG9rZW5BY3RpdmF0_W9uUmVzcG9uc2U-U1BQQ1MuU0xwR2VuZXJhdGVUb2tlbkFjdGl2YXRpb25D_GFsbGVuZ2U-U0xwR2VuZXJhdGVUb2tlbkFjdGl2YXRpb25D_GFsbGVuZ2U-U1BQQ1MuU0xwR2V0R2VudWluZUJs\r\nb2I-U0xwR2V0R2VudWluZUJsb2I-U1BQQ1MuU0xwR2V0R2VudWluZUxvY2Fs-FNMcEdldEdlbnVpbmVMb2Nhb-BTUFBDUy5TTHBHZXRM_WNlbnNlQWNxdWlz_XRpb25JbmZv-FNMcEdldExpY2Vuc2VBY3F1_XNpdGlvbkluZm8-U1BQQ1MuU0xwR2V0TVNQ_WRJbmZv\r\ncm1hdGlvbgBTTHBHZXRNU1BpZEluZm9ybWF0_W9u-FNQUENTLlNMcEdldE1hY2hpbmVVR1VJR-BTTHBHZXRNYWNo_W5lVUdVSUQ-U1BQQ1MuU0xwR2V0VG9rZW5BY3RpdmF0_W9uR3JhbnRJbmZv-FNMcEdldFRv_2VuQWN0_XZhdGlvbkdyYW50SW5mbwBTUFBDUy5T\r\nTHBJQUFjdGl2YXRlUHJvZHVjd-BTTHBJQUFjdGl2YXRlUHJvZHVjd-BTUFBDUy5TTHBJc0N1cnJlbnRJbnN0YWxsZWRQcm9kdWN0S2V5RGVmYXVsdEtleQBTTHBJc0N1cnJlbnRJbnN0YWxsZWRQcm9kdWN0S2V5RGVmYXVsdEtleQBTUFBDUy5TTHBQcm9jZXNzVk1Q\r\n_XBlTWVzc2FnZQBTTHBQcm9jZXNzVk1Q_XBlTWVzc2FnZQBTUFBDUy5TTHBTZXRBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTTHBTZXRBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTUFBDUy5TTHBUcmlnZ2VyU2VydmljZVdvcmtlcgBTTHBUcmlnZ2VyU2VydmljZVdvcmtlcgBT\r\nUFBDUy5TTHBWTEFjdGl2YXRlUHJvZHVjd-BTTHBWTEFjdGl2YXRlUHJvZHVjd-------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n-------------------------------------------------------------------------------------------------------------------------------------------------------------FBg-------------Ohg--BsY---XG--------------\r\n+G---Hhg--BkY--------------MYQ--gG------------------------------iG---Kpg--------yG--------DUY--------Ihg--CqY--------Mhg--------1G---------C-FNMR2V0TGljZW5z_W5nU3RhdHVzSW5mb3JtYXRpb24--QBTTEdldFByb2R1\r\nY3RT_3VJbmZvcm1hdGlvbg--3QNMb2NhbEZyZWU-RwFTdHJTdHJOSVc--G----Bg--BzcHBjcy5kbGw----UY---S0VSTkVMMzIuZGxs-----Chg--BTSExXQVBJLmRsb-----------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n-----------------------------------------------------------B-B-----Y--C--------------------B--E----w--C--------------------B--kE--BI----WH---BwD-------------BwDN----FY-UwBf-FY-RQBS-FM-SQBP-E4-XwBJ-E4-\r\nRgBP------C9BO/+---B--U---------BQ--------------------Q-B--C--------------------f-I---E-UwB0-HI-_QBu-Gc-RgBp-Gw-ZQBJ-G4-ZgBv----W-I---E-M--0-D--OQ-w-DQ-RQ-0----eg-t--E-QwBv-G0-c-Bh-G4-eQBO-GE-bQBl----\r\n--BB-G4-bwBt-GE-b-Bv-HU-cw-g-FM-bwBm-HQ-dwBh-HI-ZQ-g-EQ-ZQB0-GU-cgBp-G8-cgBh-HQ-_QBv-G4-I-BD-G8-cgBw-G8-cgBh-HQ-_QBv-G4------D4-Cw-B-EY-_QBs-GU-R-Bl-HM-YwBy-Gk-c-B0-Gk-bwBu------Bv-Gg-bwBv-Gs-I-BT-F--\r\nU-BD-------w--g--QBG-Gk-b-Bl-FY-ZQBy-HM-_QBv-G4------D--Lg-1-C4-M--u-D-----q--U--QBJ-G4-d-Bl-HI-bgBh-Gw-TgBh-G0-ZQ---HM-c-Bw-GM------Iw-N--B-Ew-ZQBn-GE-b-BD-G8-c-B5-HI-_QBn-Gg-d----Kk-I--y-D--Mg-0-C--\r\nQQBu-G8-bQBh-Gw-bwB1-HM-I-BT-G8-ZgB0-Hc-YQBy-GU-I-BE-GU-d-Bl-HI-_QBv-HI-YQB0-Gk-bwBu-C--QwBv-HI-c-Bv-HI-YQB0-Gk-bwBu----Og-J--E-TwBy-Gk-ZwBp-G4-YQBs-EY-_QBs-GU-bgBh-G0-ZQ---HM-c-Bw-GM-LgBk-Gw-b-------\r\nL--G--E-U-By-G8-Z-B1-GM-d-BO-GE-bQBl------Bv-Gg-bwBv-Gs----0--g--QBQ-HI-bwBk-HU-YwB0-FY-ZQBy-HM-_QBv-G4----w-C4-NQ-u-D--Lg-w----R-----E-VgBh-HI-RgBp-Gw-ZQBJ-G4-ZgBv-------k--Q---BU-HI-YQBu-HM-b-Bh-HQ-\r\n_QBv-G4-------kE5-Q-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n-------Q---U----MzBIMGkwdjBSMVox------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n----------------------------------------------------------------------------------------\r\n:sppc32.dll:\r\n\r\n:========================================================================================================================================\r\n\r\n::  Replace \"-\" with \"A\" and \"_\" with \"a\" before base64 conversion\r\n::  It was changed to prevent antiviruses from detecting and flagging base64 encoding\r\n\r\n:sppc64.dll:\r\nTVqQ--M----E----//8--Lg---------Q-----------------------------------------------g-----4fug4-t-nNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4g_W4gRE9TIG1vZGUuDQ0KJ---------BQRQ--ZIYH-MDc0GQ----------P--\r\nLiIL-gIo--I----e--------ExE----Q-----JIx-g-----Q-----g--B----------G----------CQ----B---LeY---I-Y-E--C---------Q-----------Q--------E--------------Q-----F---I0Q----c---U-E---C---B4-w---D---CQ---------\r\n--------------------------------------------------------------------------------iH---Dg------------------------------------udGV4d----H-B----E-----I----E-------------------g--BgLnJkYXRh---g-----C-----C\r\n----Bg------------------Q---QC5wZGF0YQ--J------w-----g----g------------------E---E-ueGRhdGE--CQ-----Q-----I----K------------------B---B-LmVkYXRh--CNE----F-----S----D-------------------Q---QC5pZGF0YQ--\r\nU-E---Bw-----g---B4------------------E---M-ucnNyYw---HgD----g-----Q----g------------------B---D---------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n---------------------------------------------------------------------------------------------------------------------------------------------------------------------EFUU0iD7EhFMclMjQXvDw--SI1EJDjHRCQ0\r\n-----EiJRCQoSI1EJDRIiUQkIEjHRCQ4-----OgF-Q--SItMJDhIix1ZY---hcBBicR0B//TRTHk6yhEi0QkNEiNF_kP--D/FUlg--BIi0wkOEiFwHQK/9NBv-E---Dr-v/TRIngSIPESFtBXMNBVUFUVVdWU0iD7Dgx9kyLrCSQ----SIusJJg---BMiWwkIEiJz0iJ\r\nbCQo6J----BBicSFwHVEQTl1-HY+SGveKEiLVQBI-dqDeh--dChIifnoIv///4X-dRxI-10-SMdDE-E---BIx0MY-----EjHQy------SP/G67xEieBIg8Q4W15fXUFcQV3Du-E---DDkJCQkJCQkP8lel8--JCQDx+E------D/JXpf--CQk-8fh-------/yVKXw--\r\nkJD/JTpf--CQkP//////////----------D//////////w----------------------------------------------------------------------------------------------------------------------------------------------------------\r\n------------------------------------------------TgBh-G0-ZQ---Ec-cgBh-GM-ZQ------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n------------------------------------------------------------------------------------------------------------------------------------E---iB----B---CIE---ExE---x----TEQ--GRE--CB-------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------EH-w-HggMw-s----EMBw-MYggwB2-Gc-VQBM-C0----Q----------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n-----------------------------------------------------------------------------------------------------MDc0GQ-----xlI---E---BD----Qw---ChQ---0UQ--QFI--M9S--DvUg--BVM--ClT--BdUw--oVM--OlT---XV---NVQ--GdU\r\n--CdV---41Q--C1V--BhVQ--n1U--NNV---NVg--O1Y--HFW--CvVg--z1Y--PtW--CIE---UVc--G9X--CfVw--01c--BFY--BNW---b1g--KVY--DNW---BVk--EFZ--BtWQ--p1k--LtZ--D7WQ--OVo--E9_--B1Wg--nVo--NN_---HWw--PVs--Glb--ClWw--\r\n41s---1c---5X---iVw--NFc---RXQ--WV0--KNd--DxXQ--G14--Ede--CHXg--u14--Ode---rXw--W18--LVf--DrXw--J2---F1g--DiUg--/VI--BpT--BGUw--glM--MhT---DV---KVQ--FFU--CFV---w1Q---tV--BKVQ--g1U--LxV--DzVQ--J1Y--FlW\r\n--CTVg--wlY--OhW---ZVw--MVc--GNX--CKVw--vFc--PVX---yW---YVg--I1Y--C8W---7Fg--CZZ--B_WQ--jVk--LRZ--DeWQ--HVo--Ed_--BlWg--jFo--Lt_--DwWg--JVs--FZb--CKWw--x1s--Ptb---mX---ZFw--LBc--D0X---OF0--IFd--DNXQ--\r\nCV4--DRe--BqXg--pF4--NRe---MXw--Rl8--Itf--DTXw--DG---EVg--B4Y------B--I--w-E--U-Bg-H--g-CQ-K--s-D--N--4-Dw-Q-BE-Eg-T-BQ-FQ-W-Bc-G--Z-Bo-Gw-c-B0-Hg-f-C--IQ-i-CM-J--l-CY-Jw-o-Ck-Kg-r-Cw-LQ-u-C8-M--x-DI-\r\nMw-0-DU-Ng-3-Dg-OQ-6-Ds-P--9-D4-PwB--EE-QgBzcHBjLmRsb-BTUFBDUy5TTENhbGxTZXJ2ZXI-U0xDYWxsU2VydmVy-FNQUENTLlNMQ2xvc2U-U0xDbG9zZQBTUFBDUy5TTENvbnN1bWVS_Wdod-BTTENvbnN1bWVS_Wdod-BTUFBDUy5TTERlcG9z_XRN_Wdy\r\nYXRpb25CbG9i-FNMRGVwb3NpdE1pZ3JhdGlvbkJsb2I-U1BQQ1MuU0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklk-FNMRGVwb3NpdE9mZmxpbmVDb25m_XJtYXRpb25JZ-BTUFBDUy5TTERlcG9z_XRPZmZs_W5lQ29uZmlybWF0_W9uSWRFe-BTTERlcG9z_XRP\r\nZmZs_W5lQ29uZmlybWF0_W9uSWRFe-BTUFBDUy5TTERlcG9z_XRTdG9yZVRv_2Vu-FNMRGVwb3NpdFN0b3JlVG9rZW4-U1BQQ1MuU0xG_XJlRXZlbnQ-U0xG_XJlRXZlbnQ-U1BQQ1MuU0xHYXRoZXJN_WdyYXRpb25CbG9i-FNMR2F0_GVyTWlncmF0_W9uQmxvYgBT\r\nUFBDUy5TTEdhdGhlck1pZ3JhdGlvbkJsb2JFe-BTTEdhdGhlck1pZ3JhdGlvbkJsb2JFe-BTUFBDUy5TTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklk-FNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWQ-U1BQQ1MuU0xHZW5lcmF0ZU9mZmxpbmVJbnN0\r\nYWxsYXRpb25JZEV4-FNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWRFe-BTUFBDUy5TTEdldEFjdGl2ZUxpY2Vuc2VJbmZv-FNMR2V0QWN0_XZlTGljZW5zZUluZm8-U1BQQ1MuU0xHZXRBcHBs_WNhdGlvbkluZm9ybWF0_W9u-FNMR2V0QXBwbGljYXRpb25J\r\nbmZvcm1hdGlvbgBTUFBDUy5TTEdldEFwcGxpY2F0_W9uUG9s_WN5-FNMR2V0QXBwbGljYXRpb25Qb2xpY3k-U1BQQ1MuU0xHZXRBdXRoZW50_WNhdGlvblJlc3Vsd-BTTEdldEF1dGhlbnRpY2F0_W9uUmVzdWx0-FNQUENTLlNMR2V0RW5jcnlwdGVkUElERXg-U0xH\r\nZXRFbmNyeXB0ZWRQSURFe-BTUFBDUy5TTEdldEdlbnVpbmVJbmZvcm1hdGlvbgBTTEdldEdlbnVpbmVJbmZvcm1hdGlvbgBTUFBDUy5TTEdldEluc3RhbGxlZFByb2R1Y3RLZXlJZHM-U0xHZXRJbnN0YWxsZWRQcm9kdWN0S2V5SWRz-FNQUENTLlNMR2V0TGljZW5z\r\nZQBTTEdldExpY2Vuc2U-U1BQQ1MuU0xHZXRM_WNlbnNlRmlsZUlk-FNMR2V0TGljZW5zZUZpbGVJZ-BTUFBDUy5TTEdldExpY2Vuc2VJbmZvcm1hdGlvbgBTTEdldExpY2Vuc2VJbmZvcm1hdGlvbgBTTEdldExpY2Vuc2luZ1N0YXR1c0luZm9ybWF0_W9u-FNQUENT\r\nLlNMR2V0UEtleUlk-FNMR2V0UEtleUlk-FNQUENTLlNMR2V0UEtleUluZm9ybWF0_W9u-FNMR2V0UEtleUluZm9ybWF0_W9u-FNQUENTLlNMR2V0UG9s_WN5SW5mb3JtYXRpb24-U0xHZXRQb2xpY3lJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFBvbGljeUluZm9ybWF0\r\n_W9uRFdPUkQ-U0xHZXRQb2xpY3lJbmZvcm1hdGlvbkRXT1JE-FNQUENTLlNMR2V0UHJvZHVjdFNrdUluZm9ybWF0_W9u-FNMR2V0UHJvZHVjdFNrdUluZm9ybWF0_W9u-FNQUENTLlNMR2V0U0xJRExpc3Q-U0xHZXRTTElETGlzd-BTUFBDUy5TTEdldFNlcnZpY2VJ\r\nbmZvcm1hdGlvbgBTTEdldFNlcnZpY2VJbmZvcm1hdGlvbgBTUFBDUy5TTEluc3RhbGxM_WNlbnNl-FNMSW5zdGFsbExpY2Vuc2U-U1BQQ1MuU0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNl-FNMSW5zdGFsbFByb29mT2ZQdXJj_GFzZQBTUFBDUy5TTEluc3RhbGxQcm9v\r\nZk9mUHVyY2hhc2VFe-BTTEluc3RhbGxQcm9vZk9mUHVyY2hhc2VFe-BTUFBDUy5TTElzR2VudWluZUxvY2FsRXg-U0xJc0dlbnVpbmVMb2NhbEV4-FNQUENTLlNMTG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xMb2FkQXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5T\r\nTE9wZW4-U0xPcGVu-FNQUENTLlNMUGVyc2lzdEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xQZXJz_XN0QXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5TTFBlcnNpc3RSVFNQYXlsb2FkT3ZlcnJpZGU-U0xQZXJz_XN0UlRTUGF5bG9hZE92ZXJy_WRl-FNQUENTLlNMUmVB\r\ncm0-U0xSZUFybQBTUFBDUy5TTFJlZ2lzdGVyRXZlbnQ-U0xSZWdpc3RlckV2ZW50-FNQUENTLlNMUmVn_XN0ZXJQbHVn_W4-U0xSZWdpc3RlclBsdWdpbgBTUFBDUy5TTFNldEF1dGhlbnRpY2F0_W9uRGF0YQBTTFNldEF1dGhlbnRpY2F0_W9uRGF0YQBTUFBDUy5T\r\nTFNldEN1cnJlbnRQcm9kdWN0S2V5-FNMU2V0Q3VycmVudFByb2R1Y3RLZXk-U1BQQ1MuU0xTZXRHZW51_W5lSW5mb3JtYXRpb24-U0xTZXRHZW51_W5lSW5mb3JtYXRpb24-U1BQQ1MuU0xVbmluc3RhbGxM_WNlbnNl-FNMVW5pbnN0YWxsTGljZW5zZQBTUFBDUy5T\r\nTFVu_W5zdGFsbFByb29mT2ZQdXJj_GFzZQBTTFVu_W5zdGFsbFByb29mT2ZQdXJj_GFzZQBTUFBDUy5TTFVubG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xVbmxvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNQUENTLlNMVW5yZWdpc3RlckV2ZW50-FNMVW5yZWdpc3Rl\r\nckV2ZW50-FNQUENTLlNMVW5yZWdpc3RlclBsdWdpbgBTTFVucmVn_XN0ZXJQbHVn_W4-U1BQQ1MuU0xwQXV0_GVudGljYXRlR2VudWluZVRpY2tldFJlc3BvbnNl-FNMcEF1dGhlbnRpY2F0ZUdlbnVpbmVU_WNrZXRSZXNwb25zZQBTUFBDUy5TTHBCZWdpbkdlbnVp\r\nbmVU_WNrZXRUcmFuc2FjdGlvbgBTTHBCZWdpbkdlbnVpbmVU_WNrZXRUcmFuc2FjdGlvbgBTUFBDUy5TTHBDbGVhckFjdGl2YXRpb25JblByb2dyZXNz-FNMcENsZWFyQWN0_XZhdGlvbkluUHJvZ3Jlc3M-U1BQQ1MuU0xwRGVwb3NpdERvd25sZXZlbEdlbnVpbmVU\r\n_WNrZXQ-U0xwRGVwb3NpdERvd25sZXZlbEdlbnVpbmVU_WNrZXQ-U1BQQ1MuU0xwRGVwb3NpdFRv_2VuQWN0_XZhdGlvblJlc3BvbnNl-FNMcERlcG9z_XRUb2tlbkFjdGl2YXRpb25SZXNwb25zZQBTUFBDUy5TTHBHZW5lcmF0ZVRv_2VuQWN0_XZhdGlvbkNoYWxs\r\nZW5nZQBTTHBHZW5lcmF0ZVRv_2VuQWN0_XZhdGlvbkNoYWxsZW5nZQBTUFBDUy5TTHBHZXRHZW51_W5lQmxvYgBTTHBHZXRHZW51_W5lQmxvYgBTUFBDUy5TTHBHZXRHZW51_W5lTG9jYWw-U0xwR2V0R2VudWluZUxvY2Fs-FNQUENTLlNMcEdldExpY2Vuc2VBY3F1\r\n_XNpdGlvbkluZm8-U0xwR2V0TGljZW5zZUFjcXVpc2l0_W9uSW5mbwBTUFBDUy5TTHBHZXRNU1BpZEluZm9ybWF0_W9u-FNMcEdldE1TUGlkSW5mb3JtYXRpb24-U1BQQ1MuU0xwR2V0TWFj_GluZVVHVUlE-FNMcEdldE1hY2hpbmVVR1VJR-BTUFBDUy5TTHBHZXRU\r\nb2tlbkFjdGl2YXRpb25HcmFudEluZm8-U0xwR2V0VG9rZW5BY3RpdmF0_W9uR3JhbnRJbmZv-FNQUENTLlNMcElBQWN0_XZhdGVQcm9kdWN0-FNMcElBQWN0_XZhdGVQcm9kdWN0-FNQUENTLlNMcElzQ3VycmVudEluc3RhbGxlZFByb2R1Y3RLZXlEZWZhdWx0S2V5\r\n-FNMcElzQ3VycmVudEluc3RhbGxlZFByb2R1Y3RLZXlEZWZhdWx0S2V5-FNQUENTLlNMcFByb2Nlc3NWTVBpcGVNZXNzYWdl-FNMcFByb2Nlc3NWTVBpcGVNZXNzYWdl-FNQUENTLlNMcFNldEFjdGl2YXRpb25JblByb2dyZXNz-FNMcFNldEFjdGl2YXRpb25JblBy\r\nb2dyZXNz-FNQUENTLlNMcFRy_WdnZXJTZXJ2_WNlV29y_2Vy-FNMcFRy_WdnZXJTZXJ2_WNlV29y_2Vy-FNQUENTLlNMcFZMQWN0_XZhdGVQcm9kdWN0-FNMcFZMQWN0_XZhdGVQcm9kdWN0--------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n----------------------------------------UH--------------IHE--Ihw--Boc--------------wcQ--oH---Hhw-------------ERx--Cwc-----------------------------D-c--------OJw--------------------cQ------------------\r\nDHE------------------MBw--------4n--------------------Bx-------------------McQ-------------------gBTTEdldExpY2Vuc2luZ1N0YXR1c0luZm9ybWF0_W9u--E-U0xHZXRQcm9kdWN0U2t1SW5mb3JtYXRpb24--OgDTG9jYWxGcmVl-FEB\r\nU3RyU3RyTklX--Bw----c---c3BwY3MuZGxs----FH---EtFUk5FTDMyLmRsb------oc---U0hMV0FQSS5kbGw-----------------------------------------------------------------------------------------------------------------\r\n----------------------------------------------------------------------------------------------------------------------------------------------E-E----Bg--I--------------------E--Q---D---I--------------\r\n------E-CQQ--Eg---BYg---H-M-------------H-M0----VgBT-F8-VgBF-FI-UwBJ-E8-TgBf-Ek-TgBG-E8------L0E7/4---E-BQ---------F--------------------B--E--I-------------------B8-g---QBT-HQ-cgBp-G4-ZwBG-Gk-b-Bl-Ek-\r\nbgBm-G8---BY-g---Q-w-DQ-M--5-D--N-BF-DQ---B6-C0--QBD-G8-bQBw-GE-bgB5-E4-YQBt-GU------EE-bgBv-G0-YQBs-G8-dQBz-C--UwBv-GY-d-B3-GE-cgBl-C--R-Bl-HQ-ZQBy-Gk-bwBy-GE-d-Bp-G8-bg-g-EM-bwBy-H--bwBy-GE-d-Bp-G8-\r\nbg------Pg-L--E-RgBp-Gw-ZQBE-GU-cwBj-HI-_QBw-HQ-_QBv-G4------G8-_-Bv-G8-_w-g-FM-U-BQ-EM------D--C--B-EY-_QBs-GU-VgBl-HI-cwBp-G8-bg------M--u-DU-Lg-w-C4-M----Co-BQ-B-Ek-bgB0-GU-cgBu-GE-b-BO-GE-bQBl----\r\ncwBw-H--Yw------j--0--E-T-Bl-Gc-YQBs-EM-bwBw-Hk-cgBp-Gc-_-B0----qQ-g-DI-M--y-DQ-I-BB-G4-bwBt-GE-b-Bv-HU-cw-g-FM-bwBm-HQ-dwBh-HI-ZQ-g-EQ-ZQB0-GU-cgBp-G8-cgBh-HQ-_QBv-G4-I-BD-G8-cgBw-G8-cgBh-HQ-_QBv-G4-\r\n---6--k--QBP-HI-_QBn-Gk-bgBh-Gw-RgBp-Gw-ZQBu-GE-bQBl----cwBw-H--Yw-u-GQ-b-Bs-------s--Y--QBQ-HI-bwBk-HU-YwB0-E4-YQBt-GU------G8-_-Bv-G8-_w---DQ-C--B-F--cgBv-GQ-dQBj-HQ-VgBl-HI-cwBp-G8-bg---D--Lg-1-C4-\r\nM--u-D----BE-----QBW-GE-cgBG-Gk-b-Bl-Ek-bgBm-G8------CQ-B----FQ-cgBh-G4-cwBs-GE-d-Bp-G8-bg------CQTkB---------------------------------------------------------------------------------------------------\r\n----------------------------------------------------------------------------------------\r\n:sppc64.dll:\r\n\r\n::========================================================================================================================================\r\n:: Leave empty line below\r\n"
  },
  {
    "path": "MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd",
    "content": "@set masver=3.10\r\n@echo off\r\n\r\n\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\n\r\n::  To activate Windows with K-M-S activation, run the script with \"/K-Windows\" parameter or change 0 to 1 in below line\r\nset _actwin=0\r\n\r\n::  To activate all Office apps (including Project/Visio) with K-M-S activation, run the script with \"/K-Office\" parameter or change 0 to 1 in below line\r\nset _actoff=0\r\n\r\n::  To activate only Project/Visio with K-M-S activation, run the script with \"/K-ProjectVisio\" parameter or change 0 to 1 in below line\r\nset _actprojvis=0\r\n\r\n::  To activate all Windows/Office with K-M-S activation, run the script with \"/K-WindowsOffice\" parameter or change 0 to 1 in below line\r\nset _actwinoff=0\r\n\r\n::  To disable changing Windows/Office edition if current edition doesn't support K-M-S activation, run the script with \"/K-NoEditionChange\" parameter or change 0 to 1 in below line\r\nset _NoEditionChange=0\r\n\r\n::  To NOT auto-install renewal task with activation, run the script with \"/K-NoRenewalTask\" parameter or change 0 to 1 in below line\r\nset _norentsk=0\r\n\r\n::  To uninstall K-M-S, run the script with \"/K-Uninstall\" parameter or change 0 to 1 in below line. It'll take preference over any other parameter.\r\nset _uni=0\r\n\r\n::  Advanced options:\r\n::  Don't use renewal task option if you are going to use a specific server name instead of public servers used in the script\r\n\r\n::  To specify a server address for activation, run the script with \"/K-Server-YOURKMSSERVERNAME\" parameter or add it in below line after = sign\r\nset _server=\r\n\r\n::  To specify a port for activation, run the script with \"/K-Port-YOURPORTNAME\" parameter or add it in below line after = sign\r\nset _port=\r\n\r\n::  Debug Mode:\r\n::  To run the script in debug mode, change 0 to any parameter above that you want to run, in below line\r\nset \"_debug=0\"\r\n\r\n::  Script will run in unattended mode if parameters are used OR value is changed in above lines FOR activation or uninstall.\r\n\r\n\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\nset re1=\r\nset re2=\r\nset \"_cmdf=%~f0\"\r\nfor %%# in (%*) do (\r\nif /i \"%%#\"==\"re1\" set re1=1\r\nif /i \"%%#\"==\"re2\" set re2=1\r\nif /i \"%%#\"==\"-qedit\" (set re1=1&set re2=1)\r\n)\r\n\r\n:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows\r\n:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\Sysnative\\cmd.exe if not defined re1 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\Sysnative\\cmd.exe /c \"\"!_cmdf!\" %* re1\"\r\nexit /b\r\n)\r\n\r\n:: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\SysArm32\\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\SysArm32\\cmd.exe /c \"\"!_cmdf!\" %* re2\"\r\nexit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Debug code\r\n\r\nif \"%_debug%\" EQU \"0\" (\r\nset \"nul1=1>nul\"\r\nset \"nul2=2>nul\"\r\nset \"nul6=2^>nul\"\r\nset \"nul=>nul 2>&1\"\r\ngoto :_debug\r\n)\r\n\r\nset \"nul1=\"\r\nset \"nul2=\"\r\nset \"nul6=\"\r\nset \"nul=\"\r\n\r\n@echo on\r\n@prompt $G\r\n@call :_debug \"%_debug%\" >\"%~dp0_tmp.log\" 2>&1\r\n@cmd /u /c type \"%~dp0_tmp.log\">\"%~dp0_Debug.log\"\r\n@del \"%~dp0_tmp.log\"\r\n@echo off\r\n@exit /b\r\n\r\n:_debug\r\n\r\n::========================================================================================================================================\r\n\r\nset \"blank=\"\r\nset \"mas=ht%blank%tps%blank%://m%blank%ass%blank%grave.dev/\"\r\nset \"github=ht%blank%tps%blank%://github.com/m%blank%assgra%blank%vel/Micro%blank%soft-Acti%blank%vation-Scripts\"\r\nset \"selfgit=ht%blank%tps%blank%://git.acti%blank%vated.win/Micr%blank%osoft-Act%blank%ivation-Scripts\"\r\n\r\n::  Check if Null service is working, it's important for the batch script\r\n\r\nsc query Null | find /i \"RUNNING\"\r\nif %errorlevel% NEQ 0 (\r\necho:\r\necho Null service is not running, script may crash...\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%fix_service\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20\r\n)\r\ncls\r\n\r\n::  Check LF line ending\r\n\r\npushd \"%~dp0\"\r\n>nul findstr /v \"$\" \"%~nx0\" && (\r\necho:\r\necho Error - Script either has LF line ending issue or an empty line at the end of the script is missing.\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20 >nul\r\npopd\r\nexit /b\r\n)\r\npopd\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\nset KS=K%blank%MS\r\ntitle  Online %KS% Activation %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args set _args=%_args:re1=%\r\nif defined _args set _args=%_args:re2=%\r\nif defined _args for %%A in (%_args%) do (\r\nif /i \"%%A\"==\"-el\"                        (set _elev=1)\r\nif /i \"%%A\"==\"/K-Windows\"                 (set _actwin=1)\r\nif /i \"%%A\"==\"/K-Office\"                  (set _actoff=1)\r\nif /i \"%%A\"==\"/K-ProjectVisio\"            (set _actprojvis=1)\r\nif /i \"%%A\"==\"/K-WindowsOffice\"           (set _actwinoff=1)\r\nif /i \"%%A\"==\"/K-NoEditionChange\"         (set _NoEditionChange=1)\r\nif /i \"%%A\"==\"/K-NoRenewalTask\"           (set _norentsk=1)\r\nif /i \"%%A\"==\"/K-Uninstall\"               (set _uni=1)\r\necho \"%%A\" | find /i \"/K-Port-\"   >nul && (set \"_port=%%A\"   & call set \"_port=%%_port:~8%%\")\r\necho \"%%A\" | find /i \"/K-Server-\" >nul && (set \"_server=%%A\" & call set \"_server=%%_server:~10%%\")\r\n)\r\n\r\nfor %%A in (%_actwin% %_actoff% %_actprojvis% %_actwinoff% %_uni%) do (if \"%%A\"==\"1\" set _unattended=1)\r\n\r\n::========================================================================================================================================\r\n\r\ncall :dk_setvar\r\n\r\nif %winbuild% EQU 1 (\r\n%eline%\r\necho Failed to detect Windows build number.\r\necho:\r\nsetlocal EnableDelayedExpansion\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\nif exist \"%Systemdrive%\\Users\\WDAGUtilityAccount\" (\r\nsc query gcs | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Windows Sandbox detected; activation is not supported.\r\necho The script cannot run due to missing licensing components. Aborting...\r\necho:\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 6001 (\r\n%nceline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho MAS only supports Windows Vista/7/8/8.1/10/11 and their Server equivalents.\r\nif %winbuild% EQU 6000 (\r\necho:\r\necho Windows Vista RTM is not supported because Powershell cannot be installed.\r\necho Upgrade to Windows Vista SP1 or SP2.\r\n)\r\ngoto dk_done\r\n)\r\n\r\nif %winbuild% LSS 7600 if not exist \"%SysPath%\\WindowsPowerShell\\v1.0\\Modules\" (\r\n%nceline%\r\nif not exist %ps% (\r\necho PowerShell is not installed in your system.\r\n)\r\necho Install PowerShell 2.0 using the following URL.\r\necho:\r\necho https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\nif %_unattended%==0 start https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix special character limitations in path name\r\n\r\nset \"_work=%~dp0\"\r\nif \"%_work:~-1%\"==\"\\\" set \"_work=%_work:~0,-1%\"\r\n\r\nset \"_batf=%~f0\"\r\nset \"_batp=%_batf:'=''%\"\r\n\r\nset _PSarg=\"\"\"%~f0\"\"\" -el %_args%\r\nset _PSarg=%_PSarg:'=''%\r\n\r\nset \"_ttemp=%userprofile%\\AppData\\Local\\Temp\"\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\necho \"!_batf!\" | find /i \"!_ttemp!\" %nul1% && (\r\nif /i not \"!_work!\"==\"!_ttemp!\" (\r\n%eline%\r\necho The script was launched from the temp folder.\r\necho You are most likely running the script directly from the archive file.\r\necho:\r\necho Extract the archive file and launch the script from the extracted folder.\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Elevate script as admin and pass arguments and preventing loop\r\n\r\n%nul1% fltmc || (\r\nif not defined _elev %psc% \"start cmd.exe -arg '/c \\\"!_PSarg!\\\"' -verb runas\" && exit /b\r\n%eline%\r\necho This script needs admin rights.\r\necho Right click on this script and select 'Run as administrator'.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check PowerShell\r\n\r\n::pstst $ExecutionContext.SessionState.LanguageMode :pstst\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"if ($PSVersionTable.PSEdition -ne 'Core') {$f=[System.IO.File]::ReadAllText('!_batp!') -split ':pstst';. ([scriptblock]::Create($f[1]))}\" %nul6%') do (set tstresult=%%a)\r\n\r\nif /i not \"%tstresult%\"==\"FullLanguage\" (\r\n%eline%\r\nfor /f \"delims=\" %%a in ('%psc% \"$ExecutionContext.SessionState.LanguageMode\" %nul6%') do (set tstresult2=%%a)\r\necho Test 1 - %tstresult%\r\necho Test 2 - !tstresult2!\r\necho:\r\n\r\nREM check LanguageMode\r\n\r\necho: !tstresult2! | findstr /i \"ConstrainedLanguage RestrictedLanguage NoLanguage\" %nul1% && (\r\necho FullLanguage mode not found in PowerShell. Aborting...\r\necho If you have applied restrictions on Powershell then undo those changes.\r\nset fixes=%fixes% %mas%fix_powershell\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_powershell\"\r\ngoto dk_done\r\n)\r\n\r\nREM check Powershell core version\r\n\r\ncmd /c \"%psc% \"$PSVersionTable.PSEdition\"\" | find /i \"Core\" %nul1% && (\r\necho Windows Powershell is needed for MAS but it seems to be replaced with Powershell core. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n\r\nREM check for Mal-ware that may cause issues with Powershell\r\n\r\nfor /r \"%ProgramFiles%\\\" %%f in (secureboot.exe) do if exist \"%%f\" (\r\necho \"%%f\"\r\necho Mal%blank%ware found, PowerShell is not working properly.\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\ngoto dk_done\r\n)\r\n\r\nREM check if .NET is working properly\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\ncmd /c \"%psc% \"\"try {[System.AppDomain]::CurrentDomain.GetAssemblies(); [System.Math]::Sqrt(144)} catch {Exit 3}\"\"\" %nul%\r\nif !errorlevel!==3 (\r\necho Windows Powershell failed to load .NET command. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nREM check antivirus and other errors\r\n\r\necho PowerShell is not working properly. Aborting...\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\necho:\r\necho Your antivirus software might be blocking the script.\r\necho:\r\nsc query sense | find /i \"RUNNING\" %nul% && (\r\necho Installed Antivirus - Microsoft Defender for Endpoint\r\n)\r\ncmd /c \"%psc% \"\"$av = Get-WmiObject -Namespace root\\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { $n += $i.displayName }; if ($n) { Write-Host ('Installed Antivirus - ' + ($n -join ', '))}\"\"\"\r\n)\r\n\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Disable QuickEdit and launch from conhost.exe to avoid Terminal app\r\n\r\nif %winbuild% GEQ 17763 (\r\nset terminal=1\r\n) else (\r\nset terminal=\r\n)\r\n\r\n::  Check if script is running in Terminal app\r\n\r\nif defined terminal (\r\nset lines=0\r\nfor /f \"skip=3 tokens=* delims=\" %%A in ('mode con') do if \"!lines!\"==\"0\" (\r\nfor %%B in (%%A) do set lines=%%B\r\n)\r\nif !lines! GEQ 100 set terminal=\r\n)\r\n\r\nif %_unattended%==1 goto :skipQE\r\nfor %%# in (%_args%) do (if /i \"%%#\"==\"-qedit\" goto :skipQE)\r\n\r\n::  Relaunch to disable QuickEdit in the current session and use conhost.exe instead of the Terminal app\r\n::  This code disables QuickEdit for the current cmd.exe session without making permanent registry changes\r\n::  It is included because clicking on the script window can pause execution, causing confusion that the script has stopped due to an error\r\n\r\nset resetQE=1\r\nreg query HKCU\\Console /v QuickEdit %nul2% | find /i \"0x0\" %nul1% && set resetQE=0\r\nreg add HKCU\\Console /v QuickEdit /t REG_DWORD /d 0 /f %nul1%\r\n\r\nif defined terminal (\r\nstart conhost.exe \"!_batf!\" %_args% -qedit\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n) else if %resetQE% EQU 1 (\r\nstart cmd.exe /c \"\"!_batf!\" %_args% -qedit\"\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n)\r\n\r\n:skipQE\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check for updates\r\n\r\nset -=\r\nset old=\r\nset pingp=\r\nset upver=%masver:.=%\r\n\r\nfor %%A in (\r\nactiv%-%ated.win\r\nmass%-%grave.dev\r\n) do if not defined pingp (\r\nfor /f \"delims=[] tokens=2\" %%B in ('ping -n 1 %%A') do (\r\nif not \"%%B\"==\"\" (set old=1& set pingp=1)\r\nfor /f \"delims=[] tokens=2\" %%C in ('ping -n 1 updatecheck%upver%.%%A') do (\r\nif not \"%%C\"==\"\" set old=\r\n)\r\n)\r\n)\r\n\r\nif defined old (\r\necho ________________________________________________\r\n%eline%\r\necho Your version of MAS [%masver%] is outdated.\r\necho ________________________________________________\r\necho:\r\nif not %_unattended%==1 (\r\necho [1] Get Latest MAS\r\necho [0] Continue Anyway\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 rem\r\nif !errorlevel!==1 (start %selfgit% & start %github% & start %mas% & exit /b)\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_uni%==1 goto :ks_uninstall\r\n\r\n:ks_menu\r\n\r\nif defined _server set _norentsk=1\r\nif not defined _server set _port=\r\n\r\nif %_unattended%==0 (\r\ncls\r\nif not defined terminal mode 76, 30\r\ntitle  Online %KS% Activation %masver%\r\n\r\necho:\r\necho:\r\necho:\r\necho:\r\nif exist \"%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd\" (\r\nfind /i \"Ver:2.7\" \"%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd\" %nul% || (\r\ncall :dk_color %_Yellow% \"              Old renewal task found, run activation to update it.\"\r\n)\r\n)\r\necho        ______________________________________________________________\r\necho: \r\necho               [1] Activate - Windows\r\necho               [2] Activate - Office [All]\r\necho               [3] Activate - Office [Project/Visio]\r\necho               [4] Activate - All\r\necho               _______________________________________________  \r\necho: \r\nif %_norentsk%==0 (\r\necho               [5] Renewal Task With Activation       [Yes]\r\n) else (\r\ncall :dk_color2 %_White% \"              [5] Renewal Task With Activation        \" %_Yellow% \"[No]\"\r\n)\r\nif %_NoEditionChange%==0 (\r\necho               [6] Change Edition If Needed           [Yes]\r\n) else (\r\ncall :dk_color2 %_White% \"              [6] Change Edition If Needed            \" %_Yellow% \"[No]\"\r\n)\r\necho               [7] Uninstall Online %KS%\r\necho               _______________________________________________       \r\necho:\r\nif defined _server (\r\necho               [8] Set %KS% Server/Port [%_server%] [%_port%]\r\n) else (\r\necho               [8] Set %KS% Server/Port\r\n)\r\necho               [9] Download Office\r\necho               [0] %_exitmsg%\r\necho        ______________________________________________________________\r\necho:\r\ncall :dk_color2 %_White% \"       \" %_Green% \"Choose a menu option using your keyboard [1,2,3,4,5,6,7,8,9,0]\"\r\nchoice /C:1234567890 /N\r\nset _el=!errorlevel!\r\n\r\nif !_el!==10 exit /b\r\nif !_el!==9 start %mas%genuine-installation-media & goto :ks_menu\r\nif !_el!==8 goto :ks_ip\r\nif !_el!==7 cls & call :ks_uninstall & cls & goto :ks_menu\r\nif !_el!==6 (if %_NoEditionChange%==0 (set _NoEditionChange=1) else (set _NoEditionChange=0)) & goto :ks_menu\r\nif !_el!==5 (if %_norentsk%==0 (set _norentsk=1) else (set _norentsk=0)) & goto :ks_menu\r\nif !_el!==4 cls & setlocal & set \"_actwin=1\" & set \"_actoff=1\" & set \"_actprojvis=0\" & call :ks_start & endlocal & cls & goto :ks_menu\r\nif !_el!==3 cls & setlocal & set \"_actwin=0\" & set \"_actoff=0\" & set \"_actprojvis=1\" & call :ks_start & endlocal & cls & goto :ks_menu\r\nif !_el!==2 cls & setlocal & set \"_actwin=0\" & set \"_actoff=1\" & set \"_actprojvis=0\" & call :ks_start & endlocal & cls & goto :ks_menu\r\nif !_el!==1 cls & setlocal & set \"_actwin=1\" & set \"_actoff=0\" & set \"_actprojvis=0\" & call :ks_start & endlocal & cls & goto :ks_menu\r\ngoto :ks_menu\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_start\r\n\r\ncls\r\nif not defined terminal (\r\nmode 115, 32\r\nif exist \"%SysPath%\\spp\\store_test\\\" mode 135, 32\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=32;$B.Height=300;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\ntitle  Online %KS% Activation %masver%\r\n\r\necho:\r\necho Initializing...\r\ncall :dk_chkmal\r\n\r\nif not exist %SysPath%\\%_slexe% (\r\n%eline%\r\necho [%SysPath%\\%_slexe%] file is missing, aborting...\r\necho:\r\nif not defined results (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options.\"\r\ncall :dk_color %Blue% \"After that, restart system and try activation again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If it still shows the same error, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_actprojvis%==1 (set \"_actoff=1\")\r\nif %_actwinoff%==1 (set \"_actwin=1\" & set \"_actoff=1\")\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_ckeckwmic\r\ncall :dk_checksku\r\ncall :dk_product\r\ncall :dk_sppissue\r\n\r\n::========================================================================================================================================\r\n\r\nset error=\r\n\r\ncls\r\necho:\r\ncall :dk_showosinfo\r\n\r\n::  Check Internet connection\r\n\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)\r\n)\r\n\r\nif defined _int (\r\necho Checking Internet Connection            [Connected%ping_f%]\r\n) else (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Internet Connection            [Not Connected]\"\r\ncall :dk_color %Blue% \"Internet is required for Online %KS% Activation.\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\necho Initiating Diagnostic Tests...\r\n\r\nset \"_serv=%_slser% Winmgmt\"\r\n\r\n::  Software Protection\r\n::  Windows Management Instrumentation\r\n\r\nif %_actwin%==0 set notwinact=1\r\ncall :dk_errorcheck\r\n\r\n::========================================================================================================================================\r\n\r\ncall :_taskclear-cache\r\ncall :_tasksetserv\r\n\r\nif not %_actwin%==1 goto :ks_office\r\n\r\n::  Process Windows\r\n::  Check if system is permanently activated or not\r\n\r\necho:\r\necho Processing Windows...\r\ncall :dk_checkperm\r\nif defined _perm (\r\ncall :dk_color %Gray% \"Checking OS Activation                  [Windows is already permanently activated]\"\r\ngoto :ks_office\r\n)\r\n\r\n::  Check Evaluation version\r\n\r\nset _eval=\r\nset _evalserv=\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" set _eval=1\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*EvalEdition~*.mum\" set _evalserv=1\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*EvalCorEdition~*.mum\" set _eval=1 & set _evalserv=1\r\n\r\nif defined _eval (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Eval\" %nul1% && (\r\ncall :dk_color %Red% \"Checking Evaluation Edition             [Evaluation editions cannot be activated outside of evaluation period.]\"\r\n\r\nif defined _evalserv (\r\ncall :dk_color %Blue% \"Go back to main menu and use [Change Edition] option.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu to reset evaluation period.\"\r\nset fixes=%fixes% %mas%evaluation_editions\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%evaluation_editions\"\r\n)\r\n\r\ngoto :ks_office\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check if GVLK is already installed or not\r\n\r\ncall :k_channel\r\n\r\n::  Detect Key\r\n\r\nset key=\r\nset pkey=\r\nset altkey=\r\nset changekey=\r\nset altedition=\r\n\r\ncall :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\nif defined allapps call :ksdata winkey\r\nif not defined key call :k_gvlk %nul%\r\nif defined allapps if not defined key call :kmsfallback\r\n\r\nif defined altkey (set key=%altkey%&set changekey=1)\r\n\r\nset /a UBR=0\r\nif %osSKU%==191 if defined altkey if defined altedition (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR %nul6%') do if not errorlevel 1 set /a UBR=%%b\r\nif %winbuild% LSS 22598 if !UBR! LSS 2788 (\r\ncall :dk_color %Blue% \"Windows must be updated to build 19044.2788 or higher for IotEnterpriseS %KS% activation.\"\r\n)\r\n)\r\n\r\nif not defined key if defined notfoundaltactID (\r\ncall :dk_color %Red% \"Checking Alternate Edition For %KS%      [%altedition% Activation ID Not Found]\"\r\n)\r\n\r\nif not defined key if not defined _gvlk (\r\necho [%winos% ^| %winbuild% ^| SKU:%osSKU%]\r\n\r\nif %winbuild% GEQ 9200 if exist \"%SysPath%\\spp\\tokens\\skus\\%osedition%\\*GVLK*.xrm-ms\" set sppks=1\r\nif %winbuild% LSS 9200 if exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-%osedition%\\*VLKMS*.xrm-ms\" set sppks=1\r\nif %winbuild% LSS 9200 if exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-%osedition%\\*VL-BYPASS*.xrm-ms\" set sppks=1\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\licensing\\skus\\Security-Licensing-SLC-Component-SKU-%osedition%\\*KMS*.xrm-ms\" set sppks=1\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\licensing\\skus\\Security-Licensing-SLC-Component-SKU-%osedition%\\*VL-BYPASS*.xrm-ms\" set sppks=1\r\n\r\nif defined skunotfound (\r\ncall :dk_color %Red% \"Required license files not found.\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\nif defined sppks (\r\ncall :dk_color %Red% \"%KS% activation is supported but failed to find the %KS% key.\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\nif not defined skunotfound if not defined sppks (\r\ncall :dk_color %Red% \"This product does not support %KS% activation.\"\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu.\"\r\n)\r\necho:\r\ngoto :ks_office\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Install key\r\n\r\nif defined changekey (\r\ncall :dk_color %Blue% \"[%altedition%] edition product key will be used to enable %KS% activation.\"\r\necho:\r\n)\r\n\r\nif defined winsub (\r\ncall :dk_color %Blue% \"Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%].\"\r\necho:\r\n)\r\n\r\nset _partial=\r\nif not defined key (\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%# in ('wmic path %spp% where \"ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' and PartialProductKey<>null AND LicenseDependsOn is NULL\" Get PartialProductKey /value %nul6%') do set \"_partial=%%#\"\r\nif %_wmic% EQU 0 for /f \"tokens=2 delims==\" %%# in ('%psc% \"(([WMISEARCHER]'SELECT PartialProductKey FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).PartialProductKey | %% {echo ('PartialProductKey='+$_)}\" %nul6%') do set \"_partial=%%#\"\r\ncall echo Checking Installed Product Key          [Partial Key - %%_partial%%] [Volume:GVLK]\r\n)\r\n\r\nif defined key (\r\nset generickey=1\r\ncall :dk_inskey \"[%key%]\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_office\r\n\r\nif not %_actoff%==1 goto :ks_activate\r\n\r\ncall :oh_setspp\r\n\r\n::  Check ohook install\r\n\r\nset ohook=\r\nfor %%# in (15 16) do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft Office\\Office%%#\\sppc*dll\" set ohook=1\r\n)\r\n)\r\n\r\nfor %%# in (System SystemX86) do (\r\nfor %%G in (\"Office 15\" \"Office\") do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft %%~G\\root\\vfs\\%%#\\sppc*dll\" set ohook=1\r\n)\r\n)\r\n)\r\n\r\nif defined ohook (\r\necho:\r\ncall :dk_color %Gray% \"Checking Ohook                          [Ohook activation is already installed for Office]\"\r\n)\r\n\r\n::  Check unsupported office versions\r\n\r\nset o14c2r=\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n%nul% reg query %_68%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n%nul% reg query %_86%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n\r\nif not \"%o14c2r%\"==\"\" (\r\necho:\r\ncall :dk_color %Red% \"Checking Unsupported Office Install     [ %o14c2r%]\"\r\n)\r\n\r\nif %winbuild% GEQ 10240 %psc% \"Get-AppxPackage -name \"Microsoft.MicrosoftOfficeHub\"\" | find /i \"Office\" %nul1% && (\r\nset ohub=1\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check supported office versions\r\n\r\ncall :oh_getpath\r\n\r\nset o16uwp=\r\nset o16uwp_path=\r\n\r\nif %winbuild% GEQ 10240 (\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty InstallLocation)\" %nul6%') do (if exist \"%%a\\Integration\\Integrator.exe\" (set o16uwp=1&set \"o16uwp_path=%%a\"))\r\n)\r\n\r\nsc query ClickToRunSvc %nul%\r\nset error1=%errorlevel%\r\n\r\nif defined o16c2r if %error1% EQU 1060 (\r\necho:\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 16.0 files found]\"\r\nset o16c2r=\r\nset error=1\r\n)\r\n\r\nsc query OfficeSvc %nul%\r\nset error2=%errorlevel%\r\n\r\nif defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (\r\necho:\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 15.0 files found]\"\r\nset o15c2r=\r\nset error=1\r\n)\r\n\r\nif \"%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%\"==\"\" (\r\nset error=1\r\necho:\r\nif not \"%o14c2r%\"==\"\" (\r\ncall :dk_color %Red% \"Checking Supported Office Install       [Not Found]\"\r\n) else (\r\ncall :dk_color %Red% \"Checking Installed Office               [Not Found]\"\r\n)\r\n\r\nif defined ohub (\r\necho:\r\necho You only have the Office Dashboard app installed; you need to install the full version of Office.\r\n)\r\ncall :dk_color %Blue% \"Download and install Office from the URL below, then try again.\"\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto :ks_activate\r\n)\r\n\r\nset multioffice=\r\nif not \"%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%\"==\"1\" set multioffice=1\r\nif not \"%o14c2r%\"==\"\" set multioffice=1\r\n\r\nif defined multioffice (\r\necho:\r\ncall :dk_color %Gray% \"Checking Multiple Office Install        [Found. Recommended to install one version only]\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Process Office UWP\r\n\r\nif not defined o16uwp goto :ks_starto15c2r\r\n\r\ncall :ks_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=16\r\nset \"_oLPath=%o16uwp_path%\\Licenses16\"\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty Dependencies) | Select-Object PackageFullName\" %nul6%') do (set \"o16uwpapplist=!o16uwpapplist! %%a\")\r\n\r\necho \"%o16uwpapplist%\" | findstr /i \"Access Excel OneNote Outlook PowerPoint Publisher SkypeForBusiness Word\" %nul% && set \"_oIds=O365HomePremRetail\"\r\n\r\nfor %%# in (Project Visio) do (\r\necho \"%o16uwpapplist%\" | findstr /i \"%%#\" %nul% && (\r\nset _lat=\r\nif exist \"%_oLPath%\\%%#Pro2024VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2024Retail \" & set _lat=1\r\nif not defined _lat if exist \"%_oLPath%\\%%#Pro2021VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2021Retail \" & set _lat=1\r\nif not defined _lat if exist \"%_oLPath%\\%%#Pro2019VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2019Retail \" & set _lat=1\r\nif not defined _lat set \"_oIds= !_oIds! %%#ProRetail \"\r\n)\r\n)\r\n\r\nset uwpinfo=%o16uwp_path:C:\\Program Files\\WindowsApps\\Microsoft.Office.Desktop_=%\r\n\r\necho:\r\necho Processing Office...                    [UWP ^| %uwpinfo%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ks_starto15c2r\r\n)\r\n\r\ncall :ks_process\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_starto15c2r\r\n\r\n::  Process Office 15.0 C2R\r\n\r\nif not defined o15c2r goto :ks_starto16c2r\r\n\r\ncall :ks_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=15\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o15c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o15c2r_reg%\\Configuration\")\r\nif not defined _oArch   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nif not defined _version for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v version\" %nul6%') do (set \"_version=%%b\")\r\nif not defined _prids   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v ProductReleaseId\" %nul6%') do (set \"_prids=%o15c2r_reg%\\propertyBag /v ProductReleaseId\" & set \"_config=%o15c2r_reg%\\propertyBag\")\r\n\r\necho \"%o15c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=10) || (set _tok=9)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query %o15c2r_reg%\\ProductReleaseIDs\\Active %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\necho:\r\necho Processing Office...                    [C2R ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ks_starto16c2r\r\n)\r\n\r\ncall :oh_expiredpreview 2013\r\nif \"%_actprojvis%\"==\"0\" call :oh_fixprids\r\ncall :ks_process\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_starto16c2r\r\n\r\n::  Process Office 16.0 C2R\r\n\r\nif not defined o16c2r goto :ks_startmsi\r\n\r\ncall :ks_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=16\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v AudienceData\" %nul6%') do (set \"_AudienceData=^| %%b \")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o16c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o16c2r_reg%\\Configuration\")\r\n\r\necho \"%o16c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=9) || (set _tok=8)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query \"%o16c2r_reg%\\ProductReleaseIDs\" /s /f \".16\" /k %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\nset _oIds=%_oIds:.16=%\r\nset _o16c2rIds=%_oIds%\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses16\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\necho:\r\necho Processing Office...                    [C2R ^| %_version% %_AudienceData%^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ks_startmsi\r\n)\r\n\r\ncall :oh_expiredpreview 2016 2019 2021 2024\r\nif \"%_actprojvis%\"==\"0\" call :oh_fixprids\r\ncall :ks_process\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_startmsi\r\n\r\nif defined o14msi call :oh_setspp 14\r\nif defined o14msi call :ks_processmsi 14 %o14msi_reg%\r\ncall :oh_setspp\r\nif defined o15msi call :ks_processmsi 15 %o15msi_reg%\r\nif defined o16msi call :ks_processmsi 16 %o16msi_reg%\r\n\r\n::========================================================================================================================================\r\n\r\necho:\r\ncall :oh_clearblock\r\nif \"%o16msi%%o15msi%\"==\"\" if not \"%o16uwp%%o16c2r%%o15c2r%\"==\"\" if \"%keyerror%\"==\"0\" if %_NoEditionChange%==0 call :oh_uninstkey\r\ncall :oh_licrefresh\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_activate\r\n\r\n::  Opt out of sending KMSclient activation data to Microsoft\r\n::  https://learn.microsoft.com/en-us/windows/privacy/manage-connections-from-windows-operating-system-components-to-microsoft-services#19-software-protection-platform\r\n\r\nif %winbuild% GEQ 9600 (\r\nreg add \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows NT\\CurrentVersion\\Software Protection Platform\" /v NoGenTicket /t REG_DWORD /d 1 /f %nul%\r\nif %winbuild% EQU 14393 reg add \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows NT\\CurrentVersion\\Software Protection Platform\" /v NoAcquireGT /t REG_DWORD /d 1 /f %nul%\r\necho Turn off %KS% AVS Validation             [Successful]\r\n)\r\n\r\nset \"slp=SoftwareLicensingProduct\"\r\nset \"ospp=OfficeSoftwareProtectionProduct\"\r\n\r\necho:\r\necho Activating Volume Products...\r\nif %_actwin%==1 call :_taskgetids sppwid %slp% windows\r\nif %_actoff%==1 call :_taskgetids sppoid %slp% office\r\nif %_actoff%==1 call :_taskgetids osppid %ospp% office\r\n\r\nif not defined sppwid if not defined sppoid if not defined osppid (\r\nif not defined keyerror (\r\necho No installed Volume Windows / Office products found.\r\n) else (\r\ncall :dk_color %Red% \"Failed to get installed Volume Windows / Office products.\"\r\n)\r\ncall :_taskgetserv\r\ncall :_taskregserv\r\n)\r\n\r\ncall :_taskact\r\nif not defined showfix if defined _tserror (call :dk_color %Blue% \"%_fixmsg%\" & set showfix=1)\r\n\r\n::  Don't create renewal task if Windows/Office volume IDs are not found, even if script is set to create it by default\r\n::  Don't create renewal task if only Windows volume ID is found and OEM BIOS error is present on Windows 7, even if script is set to create it by default\r\n\r\nset _deltask=\r\nif not %_norentsk%==0 set _deltask=1\r\nif not defined _deltask (\r\nif %_actwin%==0 call :_taskgetids sppwid %slp% windows\r\nif %_actoff%==0 call :_taskgetids sppoid %slp% office\r\nif %_actoff%==0 call :_taskgetids osppid %ospp% office\r\n)\r\n\r\nif not defined sppwid if not defined sppoid if not defined osppid (set _deltask=1)\r\nif defined oemerr if not defined sppoid if not defined osppid (set _deltask=1)\r\n\r\nif not defined _deltask (\r\ncall :ks_renewal\r\n) else (\r\nif exist \"%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd\" call :dk_color %Gray% \"Deleting activation renewal task...\"\r\ncall :dk_color %Gray% \"Skipping creation of activation renewal task...\"\r\ncall :ks_clearstuff %nul%\r\nif not defined _server (\r\nif %winbuild% GEQ 9200 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" set \"_C16R=1\"\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun /v InstallPath /reg:32\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" set \"_C16R=1\"\r\nif defined _C16R (\r\nREM  mass{}grave{dot}dev/office-license-is-not-genuine\r\nset _server=10.0.0.10\r\ncall :_taskregserv\r\necho Keeping the non-existent IP address 10.0.0.10 as %KS% Server.\r\n)\r\n)\r\nif not defined _C16R (\r\ncall :_taskclear-cache\r\necho Cleared %KS% Server from the registry.\r\n)\r\n)\r\n)\r\n\r\n::  https://learn.microsoft.com/en-us/azure/virtual-desktop/windows-10-multisession-faq\r\n\r\nif %_actwin%==1 for %%# in (407) do if %osSKU%==%%# (\r\ncall :dk_color %Red% \"%winos% does not support activation on non-azure platforms.\"\r\n)\r\n\r\nif %_actoff%==1 if defined sppoid if not defined _tserror if %_NoEditionChange%==0 if defined ohub (\r\necho:\r\ncall :dk_color %Gray% \"Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app.\"\r\n)\r\n\r\n::  Trigger reevaluation of SPP's Scheduled Tasks\r\n\r\ncall :dk_reeval %nul%\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_ip\r\n\r\ncls\r\nset _server=\r\necho:\r\necho Enter / Paste the %KS% Server address, or just press Enter to return:\r\necho:\r\nset /p _server=\r\nif not defined _server goto :ks_menu\r\nset \"_server=%_server: =%\"\r\n\r\necho:\r\necho Enter / Paste the %KS% Port address, or just press Enter to use default:\r\necho:\r\nset /p _port=\r\nif not defined _port goto :ks_menu\r\nset \"_port=%_port: =%\"\r\n\r\ngoto :ks_menu\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_reset\r\n\r\nset key=\r\nset _oRoot=\r\nset _oArch=\r\nset _oIds=\r\nset _oLPath=\r\nset _actid=\r\nset _prod=\r\nset _lic=\r\nset _arr=\r\nset _prids=\r\nset _config=\r\nset _version=\r\nset _License=\r\nset _oMSI=\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_getpath\r\n\r\nset o16c2r=\r\nset o15c2r=\r\nset o16msi=\r\nset o15msi=\r\nset o14msi=\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set o16c2r=1&set o16c2r_reg=%_86%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set o16c2r=1&set o16c2r_reg=%_68%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set o15c2r=1&set o15c2r_reg=%_86%\\15.0\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set o15c2r=1&set o15c2r_reg=%_68%\\15.0\\ClickToRun)\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o16msi=1&set o16msi_reg=%_86%\\16.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o16msi=1&set o16msi_reg=%_68%\\16.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o15msi=1&set o15msi_reg=%_86%\\15.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o15msi=1&set o15msi_reg=%_68%\\15.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=1&set o14msi_reg=%_86%\\14.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=1&set o14msi_reg=%_68%\\14.0)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_expiredpreview\r\n\r\necho %_oIds% | find /i \"Volume\" %nul% || exit /b\r\n\r\nfor %%# in (%*) do (\r\nif %%#==2013 set _offver=\r\nif %%#==2016 set _offver=\r\nif %%#==2019 set _offver=2019\r\nif %%#==2021 set _offver=2021\r\nif %%#==2024 set _offver=2024\r\nif exist \"!_oLPath!\\ProPlus!_offver!PreviewVL_*.xrm-ms\" if not exist \"!_oLPath!\\ProPlus!_offver!VL_*.xrm-ms\" (\r\nset error=1\r\nset showfix=1\r\ncall :dk_color %Red% \"Checking Expired Preview Products       [Office %%# Preview Found]\"\r\ncall :dk_color %Blue% \"Please run the Office updates first, and then attempt to activate it again.\"\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Some Office Retail to Volume converter tools may edit the ProductReleaseIds to add VL products. This code restores it because it may affect features.\r\n\r\n:oh_fixprids\r\n\r\nif not defined _prids (\r\ncall :dk_color %Gray% \"Checking ProductReleaseIds In Registry  [Not Found]\"\r\nexit /b\r\n)\r\n\r\nset _pridsR=\r\nset _pridsE=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_prids%\" %nul6%') do (set \"_pridsR=%%b\")\r\n\r\nset _pridsR=%_pridsR:,= %\r\nfor %%# in (%_pridsR%) do (echo %%# | findstr /I \"%_oIds%\" %nul1% || set _pridsE=1)\r\nfor %%# in (%_oIds%) do (echo %%# | findstr /I \"%_pridsR%\" %nul1% || set _pridsE=1)\r\n\r\nif not defined _pridsE exit /b\r\nreg add %_prids% /t REG_SZ /d \"\" /f %nul1%\r\n\r\nfor %%# in (%_oIds%) do (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query %_prids%') do if not \"%%b\"==\"\" (\r\nreg add %_prids% /t REG_SZ /d \"%%b,%%#\" /f %nul1%\r\n) else (\r\nreg add %_prids% /t REG_SZ /d \"%%#\" /f %nul1%\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  After retail to volume conversion, new product ID needs .OSPPReady key in registry, otherwise product info may not fully reflect \r\n\r\n:ks_osppready\r\n\r\nif not defined _config exit /b\r\n\r\necho: %_config% | find /i \"propertyBag\" %nul1% && (\r\nset \"_osppt=REG_DWORD\"\r\nset \"_osppready=%o15c2r_reg%\"\r\n) || (\r\nset \"_osppt=REG_SZ\"\r\nset \"_osppready=%_config%\"\r\n)\r\n\r\nreg add %_osppready% /f /v %_altoffid%.OSPPReady /t %_osppt% /d 1 %nul1%\r\n\r\n::  Office builds before 16.0.10730.20102 need the Installed license product ID in ProductReleaseIds, otherwise product info may not fully reflect \r\n\r\nif exist \"%_oLPath%\\Word2019VL_KMS_Client_AE*.xrm-ms\" exit /b\r\n\r\nreg query %_prids% | findstr /I \"%_altoffid%\" %nul1%\r\nif %errorlevel% NEQ 0 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query %_prids%') do reg add %_prids% /t REG_SZ /d \"%%b,%_altoffid%\" /f %nul1%\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_setspp\r\n\r\nset isOspp=\r\nif %winbuild% GEQ 9200 (\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n) else (\r\nset isOspp=1\r\nset spp=OfficeSoftwareProtectionProduct\r\nset sps=OfficeSoftwareProtectionService\r\n)\r\nif \"%1\"==\"14\" (\r\nset isOspp=1\r\nset spp=OfficeSoftwareProtectionProduct\r\nset sps=OfficeSoftwareProtectionService\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_process\r\n\r\nfor %%# in (%_oIds%) do (\r\n\r\nset skipprocess=\r\nif %_NoEditionChange%==1 if not defined _oMSI (\r\nset foundprod=\r\ncall :ksdata chkprod %%#\r\nif not defined foundprod (\r\nset skipprocess=1\r\ncall :dk_color %Gray% \"Skipping Because NoEditionChange Mode   [%%#]\"\r\n)\r\n)\r\n\r\n\r\nif \"%_actprojvis%\"==\"1\" if not defined skipprocess (\r\necho %%# | findstr /i \"Project Visio\" %nul% || (\r\nset skipprocess=1\r\ncall :dk_color %Gray% \"Skipping Because Project/Visio Mode     [%%#]\"\r\n)\r\n)\r\n\r\nif \"%_actprojvis%\"==\"0\" if not defined skipprocess echo %_oIds% | findstr /i \"O365\" %nul% && (\r\necho %%# | findstr /i \"Project Visio\" %nul% && (\r\nset skipprocess=1\r\necho Skipping Because Mondo Is Available     [%%#]\r\n)\r\n)\r\n\r\nif not defined skipprocess (\r\nset key=\r\nset _actid=\r\nset _preview=\r\nset _License=%%#\r\nset _altoffid=\r\n\r\necho %%# | find /i \"2024\" %nul% && (\r\nif exist \"!_oLPath!\\ProPlus2024PreviewVL_*.xrm-ms\" if not exist \"!_oLPath!\\ProPlus2024VL_*.xrm-ms\" set _preview=-Preview\r\n)\r\nset _prod=%%#!_preview!\r\n\r\ncall :ksdata getinfo !_prod!\r\n\r\nif defined _altoffid (\r\nset _License=!_altoffid!\r\necho Converting Retail To Volume             [!_prod! To !_altoffid!]\r\necho %%# | find /i \"O365\" %nul% && (\r\nif \"%oVer%\"==\"15\" (call :dk_color %Gray% \"Mondo 2013 is equivalent to O365 [15.0 version] in terms of the latest features.\")\r\nif \"%oVer%\"==\"16\" (call :dk_color %Gray% \"Mondo 2016 is equivalent to O365 in terms of the latest features.\")\r\n)\r\nset _prod=!_altoffid!\r\ncall :ks_osppready\r\n)\r\n\r\nif not \"!key!\"==\"\" (\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% || call :oh_installlic\r\nset generickey=1\r\ncall :dk_inskey \"[!key!] [!_prod!]\"\r\n) else (\r\nif not defined _oMSI (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Product In Script              [Office %oVer%.0 !_prod! not found in script]\"\r\ncall :dk_color %Blue% \"Make sure you are using Latest MAS script.\"\r\n) else (\r\ncall :dk_color %Red% \"Checking Product In Script              [!_prod! MSI Retail is not supported]\"\r\ncall :dk_color %Blue% \"Use Ohook option to activate it. To activate with %KS%, you need to install Volume version of Office.\"\r\n)\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\n)\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_processmsi\r\n\r\n::  Process Office MSI Version\r\n\r\ncall :ks_reset\r\nset _oMSI=1\r\n\r\nif \"%1\"==\"14\" (\r\ncall :dk_actids 59a52881-a989-479d-af46-f275c6370663\r\n) else (\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n)\r\n\r\nset oVer=%1\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_oRoot=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\ProductVersion /v LastProduct\" %nul6%') do (set \"_version=%%b\")\r\nif \"%_oRoot:~-1%\"==\"\\\" set \"_oRoot=%_oRoot:~0,-1%\"\r\n\r\necho \"%2\" | find /i \"Wow6432Node\" %nul1% && set _oArch=x86\r\nif not \"%osarch%\"==\"x86\" if not defined _oArch set _oArch=x64\r\nif \"%osarch%\"==\"x86\" set _oArch=x86\r\n\r\ncall :msiofficedata %2\r\n\r\necho:\r\necho Processing Office...                    [MSI ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nexit /b\r\n)\r\n\r\ncall :ks_process\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_installlic\r\n\r\nif not defined _oLPath exit /b\r\n\r\nif defined _oIntegrator (\r\nif %oVer%==16 (\r\n\"!_oIntegrator!\" /I /License PRIDName=%_License%.16 PidKey=%key% %nul%\r\n) else (\r\n\"!_oIntegrator!\" /I /License PRIDName=%_License% PidKey=%key% %nul%\r\n)\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% && exit /b\r\n)\r\n\r\n::  Fallback to manual method to install licenses incase integrator.exe is not working\r\n\r\nset _License=%_License:XVolume=XC2RVL_%\r\n\r\nset _License=%_License:O365EduCloudRetail=O365EduCloudEDUR_%\r\n\r\nset _License=%_License:ProjectProRetail=ProjectProO365R_%\r\nset _License=%_License:ProjectStdRetail=ProjectStdO365R_%\r\nset _License=%_License:VisioProRetail=VisioProO365R_%\r\nset _License=%_License:VisioStdRetail=VisioStdO365R_%\r\n\r\nif defined _preview set _License=%_License:Volume=PreviewVL_%\r\n\r\nset _License=%_License:Retail=R_%\r\nset _License=%_License:Volume=VL_%\r\n\r\nfor %%# in (\"!_oLPath!\\client-issuance-*.xrm-ms\") do (\r\nif defined _arr (set \"_arr=!_arr!;\"!_oLPath!\\%%~nx#\"\") else (set \"_arr=\"!_oLPath!\\%%~nx#\"\")\r\n)\r\n\r\nfor %%# in (\"!_oLPath!\\%_License%*.xrm-ms\") do (\r\nif defined _arr (set \"_arr=!_arr!;\"!_oLPath!\\%%~nx#\"\") else (set \"_arr=\"!_oLPath!\\%%~nx#\"\")\r\n)\r\n\r\n%psc% \"$sls = Get-WmiObject %sps%; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); InstallLicenseArr '!_arr!'; InstallLicenseFile '\"!_oLPath!\\pkeyconfig-office.xrm-ms\"'\" %nul%\r\n\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% || (\r\nset error=1\r\ncall :dk_color %Red% \"Installing Missing License Files        [Office %oVer%.0 %_prod%] [Failed]\"\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_clearblock\r\n\r\n::  Find remnants of Office vNext/shared/device license block and remove it because it stops other licenses from appearing\r\n::  https://learn.microsoft.com/en-us/office/troubleshoot/activation/reset-office-365-proplus-activation-state\r\n\r\nset _sidlist=\r\nfor /f \"tokens=* delims=\" %%a in ('%psc% \"$p = 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty \"\"\"\"$p\\$($_.PSChildName)\"\"\"\").ProfileImagePath; if ($pi -like '*\\Users\\*' -and (Test-Path \"\"\"\"$pi\\NTUSER.DAT\"\"\"\") -and -not ($_.PSChildName -match '\\.bak$')) { Split-Path $_.PSPath -Leaf } }\" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))\r\n\r\nif not defined _sidlist (\r\nfor /f \"delims=\" %%a in ('%psc% \"$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid\" %nul6%') do (set _sidlist=%%a)\r\n)\r\n\r\n::==========================\r\n\r\n::  Load the unloaded useraccounts registry\r\n\r\nset loadedsids=\r\nset alrloadedsids=\r\n\r\nfor %%# in (%_sidlist%) do (\r\nreg query HKU\\%%#\\Software %nul% && (\r\ncall set \"alrloadedsids=%%alrloadedsids%% %%#\"\r\n) || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nreg load HKU\\%%# \"%%b\\NTUSER.DAT\" %nul%\r\nreg query HKU\\%%#\\Software %nul% && (\r\ncall set \"loadedsids=%%loadedsids%% %%#\"\r\n) || (\r\nreg unload HKU\\%%# %nul%\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==========================\r\n\r\nset \"_sidlist=%loadedsids% %alrloadedsids%\"\r\n\r\nset /a counter=0\r\nfor %%# in (%_sidlist%) do set /a counter+=1\r\n\r\nif %counter% EQU 0 (\r\nset error=1\r\ncall :dk_color %Red% \"Checking User Accounts SID              [Not Found]\"\r\nexit /b\r\n)\r\n\r\nif %counter% GTR 10 (\r\ncall :dk_color %Gray% \"Checking Total User Accounts            [%counter%]\"\r\n)\r\n\r\n::==========================\r\n\r\n::  Clear the vNext/shared/device license blocks which may prevent ohook activation\r\n\r\nset vnextexist=\r\nrmdir /s /q \"%ProgramData%\\Microsoft\\Office\\Licenses\\\" %nul%\r\n\r\nfor %%x in (15 16) do (\r\nfor %%# in (%_sidlist%) do (\r\nreg query HKU\\%%#\\Software\\Microsoft\\Office\\%%x.0\\Common\\Licensing /s %nul2% | findstr /i \"CIDToLicenseIdsMapping LicenseIdToEmailMapping @\" %nul% && set vnextexist=1\r\nreg delete HKU\\%%#\\Software\\Microsoft\\Office\\%%x.0\\Common\\Licensing /f %nul%\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nrmdir /s /q \"%%b\\AppData\\Local\\Microsoft\\Office\\Licenses\\\" %nul%\r\nrmdir /s /q \"%%b\\AppData\\Local\\Microsoft\\Office\\%%x.0\\Licensing\\\" %nul%\r\n)\r\n)\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f /reg:32 %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f /reg:32 %nul%\r\n)\r\n\r\n::  Clear vNext in UWP Office\r\n\r\nif defined o16uwpapplist (\r\nfor %%# in (%_sidlist%) do (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nrmdir /s /q \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\LocalCache\\Local\\Microsoft\\Office\\Licenses\\\" %nul%\r\nif exist \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\SystemAppData\\Helium\\User.dat\" (\r\nset defname=DEFTEMP-%%#\r\nreg load HKU\\!defname! \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\SystemAppData\\Helium\\User.dat\" %nul%\r\nreg query HKU\\!defname!\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing /s %nul2% | findstr /i \"CIDToLicenseIdsMapping LicenseIdToEmailMapping @\" %nul% && set vnextexist=1\r\nreg delete HKU\\!defname!\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing /f %nul%\r\nreg unload HKU\\!defname! %nul%\r\n)\r\n)\r\n)\r\n)\r\n\r\nif defined vnextexist (\r\necho:\r\ncall :dk_color %Gray% \"The logged-in Office account has a subscription license.\"\r\ncall :dk_color %Blue% \"If the subscription is active, it overrides other activation methods.\"\r\ncall :dk_color %Blue% \"If it is expiring soon, rerun the activation script after it expires.\"\r\ncall :dk_color2 %Blue% \"If it has already expired and activation fails, get help here - \" %_Yellow% \" %mas%troubleshoot\"\r\necho:\r\n)\r\n\r\n::  Clear SharedComputerLicensing for office\r\n::  https://learn.microsoft.com/en-us/deployoffice/overview-shared-computer-activation\r\n\r\nif not defined scaIsNeeded (\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration /v SharedComputerLicensing /f %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration /v SharedComputerLicensing /f /reg:32 %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\15.0\\ClickToRun\\Configuration /v SharedComputerLicensing /f %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\15.0\\ClickToRun\\Configuration /v SharedComputerLicensing /f /reg:32 %nul%\r\n)\r\n\r\n::  Clear device-based-licensing\r\n::  https://learn.microsoft.com/en-us/deployoffice/device-based-licensing\r\n\r\nfor /f %%# in ('reg query \"%o16c2r_reg%\\Configuration\" /f *.DeviceBasedLicensing %nul6% ^| findstr REG_') do reg delete \"%o16c2r_reg%\\Configuration\" /v %%# /f %nul%\r\n\r\n::  Remove OEM registry key\r\n::  https://support.microsoft.com/en-us/office/office-repeatedly-prompts-you-to-activate-on-a-new-pc-a9a6b05f-f6ce-4d1f-8d49-eb5007b64ba1\r\n\r\nfor %%# in (15 16) do (\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%#.0\\Common\\OEM\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%#.0\\Common\\OEM\" /f /reg:32 %nul%\r\n)\r\n\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\\0ff1ce15-a989-479d-af46-f275c6370663\" /f %nul%\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\OfficeSoftwareProtectionPlatform\\Policies\\0ff1ce15-a989-479d-af46-f275c6370663\" /f %nul%\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\OfficeSoftwareProtectionPlatform\\Policies\\59a52881-a989-479d-af46-f275c6370663\" /f %nul%\r\n\r\necho Clearing Office License Blocks          [Successfully cleared from all %counter% user accounts]\r\n\r\n::==========================\r\n\r\n::  Some retail products attempt to validate the license and may show a banner \"There was a problem checking this device's license status.\"\r\n::  Resiliency registry entry can skip this check\r\n\r\nset defname=DEFTEMP-%random%\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\" /v Default\" %nul6%') do call set \"defdat=%%b\"\r\n\r\nif defined o16c2r if defined ohookact (\r\nif exist \"%defdat%\\NTUSER.DAT\" (\r\nreg load HKU\\%defname% \"%defdat%\\NTUSER.DAT\" %nul%\r\nreg query HKU\\%defname%\\Software %nul% && (\r\nreg add HKU\\%defname%\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /v \"TimeOfLastHeartbeatFailure\" /t REG_SZ /d \"2040-01-01T00:00:00Z\" /f %nul%\r\n)\r\nreg unload HKU\\%defname% %nul%\r\n)\r\n\r\nfor %%# in (%_sidlist%) do (\r\nreg delete HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /f %nul%\r\nreg add HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /v \"TimeOfLastHeartbeatFailure\" /t REG_SZ /d \"2040-01-01T00:00:00Z\" /f %nul%\r\n)\r\necho Adding Registry to Skip License Check   [Successfully added to all %counter% ^& future new user accounts]\r\n)\r\n\r\n::==========================\r\n\r\n::  Unload the loaded useraccounts registry\r\n\r\nfor %%# in (%loadedsids%) do (\r\nreg unload HKU\\%%# %nul%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Uninstall other / grace Keys\r\n\r\n:oh_uninstkey\r\n\r\nset upk_result=0\r\ncall :dk_actid 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nif \"%_actprojvis%\"==\"1\" (\r\nfor /f \"delims=\" %%a in ('%psc% \"Get-WmiObject -Query 'SELECT ID, Description, LicenseFamily FROM %spp% WHERE ApplicationID=''0ff1ce15-a989-479d-af46-f275c6370663'' AND PartialProductKey IS NOT NULL' | Where-Object { $_.LicenseFamily -notmatch 'Project' -and $_.LicenseFamily -notmatch 'Visio' } | Select-Object -ExpandProperty ID\" %nul6%') do call set \"_allactid=%%a !_allactid!\"\r\nfor /f \"delims=\" %%a in ('%psc% \"Get-WmiObject -Query 'SELECT ID, Description, LicenseFamily FROM %spp% WHERE ApplicationID=''0ff1ce15-a989-479d-af46-f275c6370663'' AND PartialProductKey IS NOT NULL' | Where-Object { '!_allactid!' -contains $_.ID -and ($_.LicenseFamily -match 'Project' -or $_.LicenseFamily -match 'Visio') } | Select-Object -ExpandProperty ID\" %nul6%') do call set \"_allactid=%%a !_allactid!\"\r\n)\r\n\r\nfor %%# in (%apps%) do (\r\necho \"%_allactid%\" | find /i \"%%#\" %nul1% || (\r\n\r\nif %_wmic% EQU 1 wmic path %spp% where ID='%%#' call UninstallProductKey %nul%\r\nif %_wmic% EQU 0 %psc% \"$null=([WMI]'%spp%=''%%#''').UninstallProductKey()\" %nul%\r\n\r\nif !errorlevel!==0 (\r\nset upk_result=1\r\n) else (\r\nset error=1\r\nset upk_result=2\r\n)\r\n)\r\n)\r\n\r\nif defined ohookact if not %upk_result%==0 echo:\r\nif %upk_result%==1 echo Uninstalling Other/Grace Keys           [Successful]\r\nif %upk_result%==2 (\r\ncall :dk_color %Red% \"Uninstalling Other/Grace Keys           [Failed]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\nset showfix=1\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Refresh Windows Insider Preview Licenses\r\n::  It required in Insider versions otherwise office may not activate\r\n\r\n:oh_licrefresh\r\n\r\nif exist \"%SysPath%\\spp\\store_test\\2.0\\tokens.dat\" (\r\n%psc% \"Stop-Service sppsvc -force; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif !errorlevel! NEQ 0 %psc% \"$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_uninstall\r\n\r\ncls\r\nif not defined terminal mode 91, 30\r\ntitle  Online %KS% Complete Uninstall %masver%\r\n\r\nset \"uline=__________________________________________________________________________________________\"\r\n\r\nset \"_C16R=\"\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun /v InstallPath\" 2^>nul') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" set \"_C16R=1\"\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun /v InstallPath /reg:32\" 2^>nul') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" set \"_C16R=1\"\r\nif %winbuild% GEQ 9200 if defined _C16R (\r\necho:\r\ncall :dk_color %Gray% \"Notice-\"\r\necho:\r\necho To make sure Office programs do not show a non-genuine banner,\r\necho please run the activation option once, and don't uninstall afterward.\r\necho %uline%\r\n)\r\n\r\necho:\r\nset error_=\r\ncall :_taskclear-cache\r\ncall :ks_clearstuff\r\n\r\n:: check KMS38 lock\r\n\r\n%nul% reg query \"HKLM\\%SPPk%\\%_wApp%\" && (\r\nset error_=9\r\necho Failed to completely clear %KS% Cache.\r\nreg query \"HKLM\\%SPPk%\\%_wApp%\" /s %nul2% | findstr /i \"127.0.0.2\" %nul1% && echo KMS38 activation is locked.\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n) || (\r\necho Cleared %KS% Cache successfully.\r\n)\r\n\r\nif defined error_ (\r\nif \"%error_%\"==\"1\" (\r\necho %uline%\r\n%eline%\r\necho Try Again / Restart the System\r\necho %uline%\r\n)\r\n) else (\r\necho %uline%\r\necho:\r\ncall :dk_color %Green% \"Online %KS% has been successfully uninstalled.\"\r\necho:\r\ncall :dk_color %Gray% \"If you want to reset the activation status,\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\necho %uline%\r\n)\r\n\r\ngoto :dk_done\r\n\r\n:ks_clearstuff\r\n\r\nset \"key=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\"\r\n\r\nreg query \"%key%\" /f Path /s | find /i \"\\Activation-Renewal\" %nul1% && (\r\necho Deleting [Task] Activation-Renewal\r\nschtasks /delete /tn Activation-Renewal /f %nul%\r\n)\r\n\r\nreg query \"%key%\" /f Path /s | find /i \"\\Activation-Run_Once\" %nul1% && (\r\necho Deleting [Task] Activation-Run_Once\r\nschtasks /delete /tn Activation-Run_Once /f %nul%\r\n)\r\n\r\nIf exist \"%ProgramFiles%\\Activation-Renewal\\\" (\r\necho Deleting [Folder] %ProgramFiles%\\Activation-Renewal\\\r\nrmdir /s /q \"%ProgramFiles%\\Activation-Renewal\\\" %nul%\r\n)\r\n\r\n::  Stuff from old MAS versions\r\n\r\nschtasks /delete /tn Online_%KS%_Activation_Script-Renewal /f %nul%\r\nschtasks /delete /tn Online_%KS%_Activation_Script-Run_Once /f %nul%\r\ndel /f /q \"%ProgramData%\\Online_%KS%_Activation.cmd\" %nul%\r\nrmdir /s /q \"%ProgramData%\\Activation-Renewal\\\" %nul%\r\nrmdir /s /q \"%ProgramData%\\Online_%KS%_Activation\\\" %nul%\r\nrmdir /s /q \"%windir%\\Online_%KS%_Activation_Script\\\" %nul%\r\nreg delete \"HKCR\\DesktopBackground\\shell\\Activate Windows - Office\" /f %nul%\r\n\r\n::  Check if all is removed\r\n\r\nreg query \"%key%\" /f Path /s | find /i \"\\Activation-Renewal\" %nul1% && (set error_=1)\r\nreg query \"%key%\" /f Path /s | find /i \"\\Activation-Run_Once\" %nul1% && (set error_=1)\r\nreg query \"%key%\" /f Path /s | find /i \"\\Online_%KS%_Activation_Script\" %nul1% && (set error_=1)\r\nIf exist \"%windir%\\Online_%KS%_Activation_Script\\\" (set error_=1)\r\nreg query \"HKCR\\DesktopBackground\\shell\\Activate Windows - Office\" %nul% && (set error_=1)\r\nif exist \"%ProgramData%\\Online_%KS%_Activation.cmd\" (set error_=1)\r\nif exist \"%ProgramData%\\Online_%KS%_Activation\\\" (set error_=1)\r\nif exist \"%ProgramData%\\Activation-Renewal\\\" (set error_=1)\r\nif exist \"%ProgramFiles%\\Activation-Renewal\\\" (set error_=1)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_extracttask:\r\n@echo off\r\n\r\n::   Renew K-M-S activation with Online servers via scheduled task\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\nif not \"%~1\"==\"Task\" (\r\necho:\r\necho ====== Error ======\r\necho:\r\necho This file is supposed to be run only by the scheduled task.\r\necho:\r\necho Press any key to exit\r\npause >nul\r\nexit /b\r\n)\r\n\r\n::  Set Environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\n>nul fltmc || exit /b\r\n\r\n::========================================================================================================================================\r\n\r\nset _tserror=\r\nset winbuild=1\r\nset \"nul=>nul 2>&1\"\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\nset psc=powershell.exe -nop -c\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset run_once=\r\nset t_name=Renewal Task\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\" /f Path /s | find /i \"\\Activation-Run_Once\" >nul && (\r\nset run_once=1\r\nset t_name=Run Once Task\r\n)\r\n\r\nset _wmic=0\r\nfor %%# in (wmic.exe) do @if not \"%%~$PATH:#\"==\"\" (\r\ncmd /c \"wmic path Win32_ComputerSystem get CreationClassName /value\" 2>nul | find /i \"computersystem\" 1>nul && set _wmic=1\r\n)\r\nif %winbuild% LSS 9200 set _wmic=1\r\n\r\nsetlocal EnableDelayedExpansion\r\nif exist \"%ProgramFiles%\\Activation-Renewal\\\" call :_taskstart>>\"%ProgramFiles%\\Activation-Renewal\\Logs.txt\"\r\nexit\r\n\r\n::========================================================================================================================================\r\n\r\n:_taskstart\r\n\r\necho:\r\necho %date%, %time%\r\n\r\nset /a loop=1\r\nset /a max_loop=4\r\n\r\ncall :_tasksetserv\r\n\r\n:_intrepeat\r\n\r\n::  Check Internet connection. Works even if ICMP echo is disabled.\r\n\r\nfor %%a in (%srvlist%) do (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (\r\nif not \"%%#\"==\"\" goto _taskIntConnected\r\n)\r\n)\r\n\r\nnslookup dns.msftncsi.com 2>nul | find \"131.107.255.255\" 1>nul\r\nif \"%errorlevel%\"==\"0\" goto _taskIntConnected\r\n\r\nif %loop%==%max_loop% (\r\nset _tserror=1\r\ngoto _taskend\r\n)\r\n\r\necho:\r\necho Error: Internet is not connected\r\necho Waiting 30 seconds\r\n\r\ntimeout /t 30 >nul\r\nset /a loop=%loop%+1\r\ngoto _intrepeat\r\n\r\n:_taskIntConnected\r\n\r\n::========================================================================================================================================\r\n\r\ncall :_taskclear-cache\r\n\r\n::  Check WMI and sppsvc Errors\r\n\r\nset applist=\r\nnet start %_slser% /y %nul%\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %slp% where (ApplicationID='%_wApp%') get ID /VALUE\" 2^>nul')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %slp% WHERE ApplicationID=''%_wApp%''').Get()).ID ^| %% {echo ('ID='+$_)}\" 2^>nul')\"\r\n%chkapp% do (if defined applist (call set \"applist=!applist! %%a\") else (call set \"applist=%%a\"))\r\n\r\nif not defined applist (\r\nset _tserror=1\r\nif %_wmic% EQU 1 wmic path Win32_ComputerSystem get CreationClassName /value 2>nul | find /i \"computersystem\" 1>nul\r\nif %_wmic% EQU 0 %psc% \"Get-CIMInstance -Class Win32_ComputerSystem | Select-Object -Property CreationClassName\" 2>nul | find /i \"computersystem\" 1>nul\r\nif !errorlevel! NEQ 0 (set e_wmispp=WMI, SPP) else (set e_wmispp=SPP)\r\necho:\r\necho Error: Not Respoding- !e_wmispp!\r\necho:\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check installed volume products activation ID's\r\n\r\ncall :_taskgetids sppwid %slp% windows\r\ncall :_taskgetids sppoid %slp% office\r\ncall :_taskgetids osppid %ospp% office\r\n\r\n::========================================================================================================================================\r\n\r\necho:\r\necho Renewing K-M-S activation for all installed Volume products\r\n\r\nif not defined sppwid if not defined sppoid if not defined osppid (\r\necho:\r\necho No installed Volume Windows / Office product found\r\necho:\r\necho Renewing K-M-S server\r\ncall :_taskgetserv\r\ncall :_taskregserv\r\ngoto :_skipact\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\ncall :_taskact\r\n\r\n:_skipact\r\n\r\n::========================================================================================================================================\r\n\r\nif defined run_once (\r\necho:\r\necho Deleting Scheduled Task Activation-Run_Once\r\nschtasks /delete /tn Activation-Run_Once /f %nul%\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:_taskend\r\n\r\necho:\r\necho Exiting\r\necho ______________________________________________________________________\r\n\r\nif defined _tserror (exit /b 123456789) else (exit /b 0)\r\n\r\n::========================================================================================================================================\r\n\r\n:_act\r\n\r\nset prodname=\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%# in ('\"wmic path !_path! where ID='!_actid!' get LicenseFamily /VALUE\" 2^>nul') do (call set \"prodname=%%#\")\r\nif %_wmic% EQU 0 for /f \"tokens=2 delims==\" %%# in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM !_path! WHERE ID=''!_actid!''').Get()).LicenseFamily | %% {echo ('LicenseFamily='+$_)}\" 2^>nul') do (call set \"prodname=%%#\")\r\nfor /f \"tokens=1 delims=-_\" %%a in (\"%prodname%\") do set \"prodname=%%a\"\r\n\r\nset _taskskip=\r\nif \"%_actprojvis%\"==\"1\" (\r\necho: %prodname% | find /i \"Office\" %nul% && (\r\necho: %prodname% | findstr /i \"Project Visio\" %nul% || (set _taskskip=1& exit /b)\r\n)\r\n)\r\n\r\nif defined t_name Activating: %prodname%\r\n\r\nset errorcode=12345\r\nset /a act_attempt=0\r\n\r\n:_act2\r\n\r\nif %act_attempt% GTR 4 exit /b\r\n\r\nif not \"%act_ok%\"==\"1\" (\r\nif not defined _server call :_taskgetserv\r\ncall :_taskregserv\r\n)\r\n\r\nif not !server_num! GTR %max_servers% (\r\n\r\nif \"%1\"==\"act_win\" if %_kms38% EQU 1 (\r\nset act_ok=1\r\nexit /b\r\n)\r\n\r\nif %_wmic% EQU 1 wmic path !_path! where ID='!_actid!' call Activate %nul%\r\nif %_wmic% EQU 0 %psc% \"try {$null=(([WMISEARCHER]'SELECT ID FROM !_path! where ID=''!_actid!''').Get()).Activate(); exit 0} catch { exit $_.Exception.InnerException.HResult }\"\r\n\r\ncall set errorcode=!errorlevel!\r\n\r\nif !errorcode! EQU 0 (\r\nset act_ok=1\r\nexit /b\r\n)\r\nif \"%1\"==\"act_win\" if !errorcode! EQU -1073418187 if %winbuild% LSS 9200 (\r\nset act_ok=1\r\nexit /b\r\n)\r\n\r\nset act_ok=0\r\nset /a act_attempt+=1\r\nif not defined _server goto _act2\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_actinfo\r\n\r\nif \"%1\"==\"act_win\" if not defined t_name (set prodname=%winos%)\r\n\r\nif \"%1\"==\"act_win\" if %_kms38% EQU 1 (\r\nif defined t_name (\r\necho %prodname% is already activated with KMS38.\r\n) else (\r\ncall :dk_color %Green% \"%prodname% is already activated with KMS38.\"\r\n)\r\nexit /b\r\n)\r\n\r\nif %errorcode% EQU 12345 (\r\nif defined t_name (\r\necho %prodname% activation failed due to restricted or no Internet.\r\n) else (\r\ncall :dk_color %Red% \"%prodname% activation failed due to restricted or no Internet.\"\r\n)\r\nset showfix=1\r\nset _tserror=1\r\nexit /b\r\n)\r\n\r\nif %errorcode% EQU -1073418187 if \"%1\"==\"act_win\" if %winbuild% LSS 9200 (\r\nif defined t_name (\r\necho %prodname% cannot be KMS-activated on this computer due to unqualified OEM BIOS [0xC004F035].\r\n) else (\r\ncall :dk_color %Red% \"%prodname% cannot be KMS-activated on this computer due to unqualified OEM BIOS [0xC004F035].\"\r\ncall :dk_color %Blue% \"Use TSforge activation option from the main menu.\"\r\n)\r\nset oemerr=1\r\nset showfix=1\r\nexit /b\r\n)\r\n\r\nif %errorcode% EQU -1073418124 (\r\nif defined t_name (\r\necho %prodname% activation failed due to Internet issue [0xC004F074].\r\n) else (\r\ncall :dk_color %Red% \"%prodname% activation failed due to Internet issue [0xC004F074].\"\r\nif not defined _tserror (\r\ncall :dk_color %Blue% \"Make sure that system files are not blocked by firewall.\"\r\ncall :dk_color %Blue% \"If the issue persists, try another Internet connection or VPN such as https://1.1.1.1\"\r\n)\r\n)\r\nset showfix=1\r\nset _tserror=1\r\nexit /b\r\n)\r\n\r\n\r\nset gpr=0\r\nset gpr2=0\r\ncall :_taskgetgrace\r\nset /a \"gpr2=(%gpr%+1440-1)/1440\"\r\n\r\nif %errorcode% EQU 0 if %gpr% EQU 0 (\r\nif defined t_name (\r\necho %prodname% activation succeeded, but Remaining Period failed to increase.\r\n) else (\r\ncall :dk_color %Red% \"%prodname% activation succeeded, but Remaining Period failed to increase.\"\r\n)\r\nset _tserror=1\r\nexit /b\r\n)\r\n\r\nset _actpass=1\r\nif %gpr% EQU 43200  if \"%1\"==\"act_win\" if %winbuild% GEQ 9200 set _actpass=0\r\nif %gpr% EQU 64800  set _actpass=0\r\nif %gpr% GTR 259200 if \"%1\"==\"act_win\" call :_taskchkEnterpriseG _actpass\r\nif %gpr% EQU 259200 set _actpass=0\r\n\r\nif %errorcode% EQU 0 if %_actpass% EQU 0 (\r\nif defined t_name (\r\necho %prodname% is successfully activated for %gpr2% days.\r\n) else (\r\ncall :dk_color %Green% \"%prodname% is successfully activated for %gpr2% days.\"\r\n)\r\nexit /b\r\n)\r\n\r\ncmd /c exit /b %errorcode%\r\nif defined t_name (\r\necho %prodname% has failed to activate [0x!=ExitCode!]. Remaining Period: %gpr2% days [%gpr% minutes].\r\n) else (\r\ncall :dk_color %Red% \"%prodname% has failed to activate [0x!=ExitCode!]. Remaining Period: %gpr2% days [%gpr% minutes].\"\r\n)\r\nset _tserror=1\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_taskact\r\n\r\n:: Check KMS38 activation\r\n\r\nset gpr=0\r\nset _kms38=0\r\nif defined sppwid if %winbuild% GEQ 14393 (\r\nset _path=%slp%\r\nset _actid=%sppwid%\r\ncall :_taskgetgrace\r\n)\r\n\r\nif %gpr% NEQ 0 if %gpr% GTR 259200 (\r\nset _kms38=1\r\ncall :_taskchkEnterpriseG _kms38\r\n)\r\n\r\n:: Set specific K-M-S host to Local Host so that global K-M-S IP can not replace KMS38 activation but can be used with Office and other Windows Editions.\r\n\r\nif %_kms38% EQU 1 (\r\n%nul% reg add \"HKLM\\%SPPk%\\%_wApp%\\%sppwid%\" /f /v KeyManagementServiceName /t REG_SZ /d \"127.0.0.2\"\r\n%nul% reg add \"HKLM\\%SPPk%\\%_wApp%\\%sppwid%\" /f /v KeyManagementServicePort /t REG_SZ /d \"1688\"\r\n)\r\n\r\necho:\r\nif defined sppwid (\r\nset _path=%slp%\r\nset _actid=%sppwid%\r\ncall :_act act_win\r\ncall :_actinfo act_win\r\n) else (\r\nif defined t_name echo Checking: Volume version of Windows is not installed\r\n)\r\n\r\nif defined sppoid (\r\nset _path=%slp%\r\nfor %%# in (%sppoid%) do (\r\nset _actid=%%#\r\ncall :_act\r\nif not defined _taskskip call :_actinfo\r\n)\r\n)\r\n\r\nif defined osppid (\r\nset _path=%ospp%\r\nfor %%# in (%osppid%) do (\r\nset _actid=%%#\r\ncall :_act\r\nif not defined _taskskip call :_actinfo\r\n)\r\n)\r\n\r\nif not defined sppoid if not defined osppid if defined t_name (\r\necho:\r\necho Checking: Volume version of Office is not installed\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_taskgetids\r\n\r\nset %1=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %2 where (Name like '%%%3%%' and Description like '%%KMSCLIENT%%' and PartialProductKey is not NULL AND LicenseDependsOn is NULL) get ID /VALUE\" 2^>nul')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %2 WHERE Name like ''%%%3%%'' and Description like ''%%KMSCLIENT%%'' and PartialProductKey is not NULL AND LicenseDependsOn is NULL').Get()).ID ^| %% {echo ('ID='+$_)}\" 2^>nul')\"\r\n%chkapp% do (if defined %1 (call set \"%1=!%1! %%a\") else (call set \"%1=%%a\"))\r\nexit /b\r\n\r\n:_taskgetgrace\r\n\r\nset gpr=0\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%# in ('\"wmic path !_path! where ID='!_actid!' get GracePeriodRemaining /VALUE\" 2^>nul') do call set \"gpr=%%#\"\r\nif %_wmic% EQU 0 for /f \"tokens=2 delims==\" %%# in ('%psc% \"(([WMISEARCHER]'SELECT GracePeriodRemaining FROM !_path! where ID=''!_actid!''').Get()).GracePeriodRemaining | %% {echo ('GracePeriodRemaining='+$_)}\" 2^>nul') do call set \"gpr=%%#\"\r\nexit /b\r\n\r\n:_taskchkEnterpriseG\r\n\r\nfor %%# in (e0b2d383-d112-413f-8a80-97f373a5820c e38454fb-41a4-4f59-a5dc-25080e354730) do (if %sppwid%==%%# set %1=0)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Clean existing K-M-S cache from the registry\r\n\r\n:_taskclear-cache\r\n\r\nset w=\r\nfor %%# in (SppE%w%xtComObj.exe sppsvc.exe SLsvc.exe) do (\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" /f %nul%\r\n)\r\n\r\nset \"OPPk=SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform\"\r\n\r\nif %winbuild% LSS 7600 (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\" %nul% && (\r\nset \"SPPk=SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\"\r\n)\r\n)\r\nif not defined SPPk (\r\nset \"SPPk=SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\"\r\n)\r\n\r\nset \"slp=SoftwareLicensingProduct\"\r\nset \"ospp=OfficeSoftwareProtectionProduct\"\r\n\r\nset \"_wApp=55c92734-d682-4d71-983e-d6ec3f16059f\"\r\nset \"_oApp=0ff1ce15-a989-479d-af46-f275c6370663\"\r\nset \"_oA14=59a52881-a989-479d-af46-f275c6370663\"\r\n\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName /reg:32\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort /reg:32\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v DisableDnsPublishing\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v DisableKeyManagementServiceHostCaching\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_wApp%\" /f\r\nif %winbuild% GEQ 9200 (\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_oApp%\" /f\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_oApp%\" /f /reg:32\r\n)\r\nif %winbuild% GEQ 9600 (\r\n%nul% reg delete \"HKU\\S-1-5-20\\%SPPk%\\%_wApp%\" /f\r\n%nul% reg delete \"HKU\\S-1-5-20\\%SPPk%\\%_oApp%\" /f\r\n)\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v KeyManagementServiceName\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v KeyManagementServicePort\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v DisableDnsPublishing\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v DisableKeyManagementServiceHostCaching\r\n%nul% reg delete \"HKLM\\%OPPk%\\%_oA14%\" /f\r\n%nul% reg delete \"HKLM\\%OPPk%\\%_oApp%\" /f\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_taskregserv\r\n\r\nif defined _server (set KMS_IP=%_server%)\r\nif not defined _port set _port=1688\r\n\r\n%nul% reg add \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName /t REG_SZ /d \"%KMS_IP%\"\r\n%nul% reg add \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName /t REG_SZ /d \"%KMS_IP%\" /reg:32\r\n%nul% reg add \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort /t REG_SZ /d \"%_port%\"\r\n%nul% reg add \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort /t REG_SZ /d \"%_port%\" /reg:32\r\n\r\n%nul% reg add \"HKLM\\%OPPk%\" /f /v KeyManagementServiceName /t REG_SZ /d \"%KMS_IP%\"\r\n%nul% reg add \"HKLM\\%OPPk%\" /f /v KeyManagementServicePort /t REG_SZ /d \"%_port%\"\r\n\r\nif %winbuild% GEQ 9200 (\r\n%nul% reg add \"HKLM\\%SPPk%\\%_oApp%\" /f /v KeyManagementServiceName /t REG_SZ /d \"%KMS_IP%\"\r\n%nul% reg add \"HKLM\\%SPPk%\\%_oApp%\" /f /v KeyManagementServiceName /t REG_SZ /d \"%KMS_IP%\" /reg:32\r\n%nul% reg add \"HKLM\\%SPPk%\\%_oApp%\" /f /v KeyManagementServicePort /t REG_SZ /d \"%_port%\"\r\n%nul% reg add \"HKLM\\%SPPk%\\%_oApp%\" /f /v KeyManagementServicePort /t REG_SZ /d \"%_port%\" /reg:32\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:_tasksetserv\r\n\r\n::  Multi K-M-S servers integration and servers randomization\r\n\r\nset srvlist=\r\nset -=\r\n\r\nset \"srvlist=kms.03%-%k.org kms-default.cangs%-%hui.net kms.six%-%yin.com kms.moe%-%club.org kms.cgt%-%soft.com\"\r\nset \"srvlist=%srvlist% kms.id%-%ina.cn kms.moe%-%yuuko.com xinch%-%eng213618.cn kms.lol%-%i.best kms.mc%-%06.net\"\r\nset \"srvlist=%srvlist% kms.0%-%t.net.cn win.k%-%ms.pub kms.wx%-%lost.com kms.moe%-%yuuko.top kms.gh%-%xi.com\"\r\n\r\nset n=1\r\nfor %%a in (%srvlist%) do (set %%a=&set server!n!=%%a&set /a n+=1)\r\nset max_servers=15\r\nset /a server_num=0\r\nexit /b\r\n\r\n:_taskgetserv\r\n\r\nif %server_num% geq %max_servers% (set /a server_num+=1&set KMS_IP=222.184.9.98&exit /b)\r\nset /a rand=%Random%%%(15+1-1)+1\r\nif defined !server%rand%! goto :_taskgetserv\r\nset KMS_IP=!server%rand%!\r\nset !server%rand%!=1\r\n\r\n::  Get IPv4 address of K-M-S server to use for the activation, works even if ICMP echo is disabled.\r\n::  Microsoft and Antivirus's may flag the issue if public K-M-S server host name is directly used for the activation.\r\n\r\nset /a server_num+=1\r\n(for /f \"delims=[] tokens=2\" %%a in ('ping -4 -n 1 %KMS_IP% 2^>nul') do set \"KMS_IP=%%a\"\r\nif \"%KMS_IP%\"==\"!KMS_IP!\" for /f \"delims=[] tokens=2\" %%# in ('pathping -4 -h 1 -n -p 1 -q 1 -w 1 %KMS_IP% 2^>nul') do set \"KMS_IP=%%#\"\r\nif not \"%KMS_IP%\"==\"!KMS_IP!\" exit /b\r\ngoto :_taskgetserv\r\n)\r\n::Ver:2.7\r\n:_extracttask:\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_renewal\r\n\r\nset error_=\r\nset \"_dest=%ProgramFiles%\\Activation-Renewal\"\r\nset \"key=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\"\r\n\r\ncall :ks_clearstuff %nul%\r\n\r\nif defined error_ (\r\nset error=1\r\ncall :dk_color %Red% \"Failed to remove previous Renewal Task. Restart system / Try again.\"\r\nexit /b\r\n)\r\n\r\nif not exist \"%_dest%\\\" md \"%_dest%\\\" %nul%\r\nfor /f %%G in ('%psc% \"[Guid]::NewGuid().Guid\"') do set \"randguid=%%G\"\r\nset \"_temp=%SystemRoot%\\Temp\\%Random%%randguid%\"\r\n\r\nset nil=\r\nif %winbuild% LSS 7600 (set _vista=_vista)\r\nif exist \"%_temp%\\.*\" rmdir /s /q \"%_temp%\\\" %nul%\r\nmd \"%_temp%\\\" %nul%\r\ncall :ks_RenExport renewal%_vista% \"%_temp%\\Renewal.xml\" Unicode\r\nif not defined _int (call :ks_RenExport run_once%_vista% \"%_temp%\\Run_Once.xml\" Unicode)\r\ns%nil%cht%nil%asks /cre%nil%ate /tn \"Activation-Renewal\" /ru \"SYS%nil%TEM\" /xml \"%_temp%\\Renewal.xml\" %nul%\r\nif not defined _int (s%nil%cht%nil%asks /cre%nil%ate /tn \"Activation-Run_Once\" /ru \"SYS%nil%TEM\" /xml \"%_temp%\\Run_Once.xml\" %nul%)\r\nif exist \"%_temp%\\.*\" rmdir /s /q \"%_temp%\\\" %nul%\r\n\r\ncall :ks_createInfo.txt\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split \\\":_extracttask\\:.*`r`n\\\"; [io.file]::WriteAllText('%_dest%\\Activation_task.cmd', '@::%randguid%' + [Environment]::NewLine + $f[1].Trim(), [System.Text.Encoding]::ASCII)\"\r\n\r\n::========================================================================================================================================\r\n\r\nreg query \"%key%\" /f Path /s | find /i \"\\Activation-Renewal\" >nul || (set error_=1)\r\nif not defined _int reg query \"%key%\" /f Path /s | find /i \"\\Activation-Run_Once\" >nul || (set error_=1)\r\n\r\nIf not exist \"%_dest%\\Activation_task.cmd\" (set error_=1)\r\nIf not exist \"%_dest%\\Info.txt\" (set error_=1)\r\n\r\nif defined error_ (\r\nschtasks /delete /tn Activation-Renewal /f %nul%\r\nschtasks /delete /tn Activation-Run_Once /f %nul%\r\nrmdir /s /q \"%_dest%\\\" %nul%\r\nset error=1\r\ncall :dk_color %Red% \"Failed to install Renewal Task. Restart system / Try again.\"\r\nexit /b\r\n)\r\n\r\nif \"%keyerror%\"==\"0\" if not defined _tserror (\r\ncall :dk_color %Green% \"Renewal Task for lifetime activation is successfully installed in %_dest%\"\r\nexit /b\r\n)\r\necho Renewal Task for lifetime activation is successfully installed in %_dest%\r\nexit /b\r\n\r\n::  Extract the text from batch script without character and file encoding issue\r\n\r\n:ks_RenExport\r\n\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split \\\":%~1\\:.*`r`n\\\"; [io.file]::WriteAllText('%~2',$f[1].Trim(),[System.Text.Encoding]::%~3);\"\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ks_createInfo.txt\r\n\r\n(\r\necho   The use of this script is to renew your Windows/Office license using online K-M-S.\r\necho:\r\necho   If renewal/activation Scheduled tasks were created then following would exist,\r\necho:\r\necho   - Scheduled tasks\r\necho     Activation-Renewal    [Renewal / Weekly]\r\necho     Activation-Run_Once   [Activation Task - deletes itself once activated]\r\necho     The scheduled tasks runs only if the system is connected to the Internet.\r\necho:\r\necho   - Files\r\necho     C:\\Program Files\\Activation-Renewal\\Activation_task.cmd\r\necho     C:\\Program Files\\Activation-Renewal\\Info.txt\r\necho     C:\\Program Files\\Activation-Renewal\\Logs.txt\r\necho ______________________________________________________________________________________________\r\necho:\r\necho   This Script is a part of MAS project.\r\necho:   \r\necho   Homepage: mass%w%grave%w%.dev\r\n)>\"%_dest%\\Info.txt\"\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:renewal:\r\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<Task version=\"1.3\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\r\n  <RegistrationInfo>\r\n    <Source>Microsoft Corporation</Source>\r\n    <Date>1999-01-01T12:00:00.34375</Date>\r\n    <Author>WindowsAddict</Author>\r\n    <Version>1.0</Version>\r\n    <Description>Online K-M-S Activation-Renewal - Weekly Task</Description>\r\n    <URI>\\Activation-Renewal</URI>\r\n    <SecurityDescriptor>D:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FRFX;;;LS)(A;;FRFW;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)(A;;FR;;;S-1-5-4)</SecurityDescriptor>\r\n  </RegistrationInfo>\r\n  <Triggers>\r\n    <CalendarTrigger>\r\n      <StartBoundary>1999-01-01T12:00:00</StartBoundary>\r\n      <Enabled>true</Enabled>\r\n      <ScheduleByWeek>\r\n        <DaysOfWeek>\r\n          <Sunday />\r\n        </DaysOfWeek>\r\n        <WeeksInterval>1</WeeksInterval>\r\n      </ScheduleByWeek>\r\n    </CalendarTrigger>\r\n  </Triggers>\r\n  <Principals>\r\n    <Principal id=\"LocalSystem\">\r\n      <UserId>S-1-5-18</UserId>\r\n      <RunLevel>HighestAvailable</RunLevel>\r\n    </Principal>\r\n  </Principals>\r\n  <Settings>\r\n    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\r\n    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\r\n    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>\r\n    <AllowHardTerminate>true</AllowHardTerminate>\r\n    <StartWhenAvailable>true</StartWhenAvailable>\r\n    <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>\r\n    <IdleSettings>\r\n      <StopOnIdleEnd>false</StopOnIdleEnd>\r\n      <RestartOnIdle>false</RestartOnIdle>\r\n    </IdleSettings>\r\n    <AllowStartOnDemand>true</AllowStartOnDemand>\r\n    <Enabled>true</Enabled>\r\n    <Hidden>true</Hidden>\r\n    <RunOnlyIfIdle>false</RunOnlyIfIdle>\r\n    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>\r\n    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>\r\n    <WakeToRun>false</WakeToRun>\r\n    <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>\r\n    <Priority>7</Priority>\r\n    <RestartOnFailure>\r\n      <Interval>PT2M</Interval>\r\n      <Count>3</Count>\r\n    </RestartOnFailure>\r\n  </Settings>\r\n  <Actions Context=\"LocalSystem\">\r\n    <Exec>\r\n      <Command>%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd</Command>\r\n    <Arguments>Task</Arguments>\r\n    </Exec>\r\n  </Actions>\r\n</Task>\r\n:renewal:\r\n\r\n:run_once:\r\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<Task version=\"1.3\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\r\n  <RegistrationInfo>\r\n    <Source>Microsoft Corporation</Source>\r\n    <Date>1999-01-01T12:00:00.34375</Date>\r\n    <Author>WindowsAddict</Author>\r\n    <Version>1.0</Version>\r\n    <Description>Online K-M-S Activation Run Once - Run and Delete itself on first Internet Contact</Description>\r\n    <URI>\\Activation-Run_Once</URI>\r\n    <SecurityDescriptor>D:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FRFX;;;LS)(A;;FRFW;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)(A;;FR;;;S-1-5-4)</SecurityDescriptor>\r\n  </RegistrationInfo>\r\n  <Triggers>\r\n    <LogonTrigger>\r\n      <Enabled>true</Enabled>\r\n    </LogonTrigger>\r\n  </Triggers>\r\n  <Principals>\r\n    <Principal id=\"LocalSystem\">\r\n      <UserId>S-1-5-18</UserId>\r\n      <RunLevel>HighestAvailable</RunLevel>\r\n    </Principal>\r\n  </Principals>\r\n  <Settings>\r\n    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\r\n    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\r\n    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>\r\n    <AllowHardTerminate>true</AllowHardTerminate>\r\n    <StartWhenAvailable>true</StartWhenAvailable>\r\n    <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>\r\n    <IdleSettings>\r\n      <StopOnIdleEnd>false</StopOnIdleEnd>\r\n      <RestartOnIdle>false</RestartOnIdle>\r\n    </IdleSettings>\r\n    <AllowStartOnDemand>true</AllowStartOnDemand>\r\n    <Enabled>true</Enabled>\r\n    <Hidden>true</Hidden>\r\n    <RunOnlyIfIdle>false</RunOnlyIfIdle>\r\n    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>\r\n    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>\r\n    <WakeToRun>false</WakeToRun>\r\n    <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>\r\n    <Priority>7</Priority>\r\n    <RestartOnFailure>\r\n      <Interval>PT2M</Interval>\r\n      <Count>3</Count>\r\n    </RestartOnFailure>\r\n  </Settings>\r\n  <Actions Context=\"LocalSystem\">\r\n    <Exec>\r\n      <Command>%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd</Command>\r\n    <Arguments>Task</Arguments>\r\n    </Exec>\r\n  </Actions>\r\n</Task>\r\n:run_once:\r\n\r\n:renewal_vista:\r\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<Task version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\r\n  <RegistrationInfo>\r\n    <Date>1999-01-01T12:00:00.34375</Date>\r\n    <Author>WindowsAddict</Author>\r\n    <Description>Online K-M-S Activation-Renewal - Weekly Task</Description>\r\n  </RegistrationInfo>\r\n  <Triggers>\r\n    <CalendarTrigger>\r\n      <StartBoundary>1999-01-01T12:00:00.34375</StartBoundary>\r\n      <Enabled>true</Enabled>\r\n      <ScheduleByWeek>\r\n        <DaysOfWeek>\r\n          <Sunday />\r\n        </DaysOfWeek>\r\n        <WeeksInterval>1</WeeksInterval>\r\n      </ScheduleByWeek>\r\n    </CalendarTrigger>\r\n  </Triggers>\r\n  <Principals>\r\n    <Principal id=\"Author\">\r\n      <UserId>S-1-5-18</UserId>\r\n      <RunLevel>HighestAvailable</RunLevel>\r\n    </Principal>\r\n  </Principals>\r\n  <Settings>\r\n    <IdleSettings>\r\n      <Duration>PT10M</Duration>\r\n      <WaitTimeout>PT1H</WaitTimeout>\r\n      <StopOnIdleEnd>true</StopOnIdleEnd>\r\n      <RestartOnIdle>false</RestartOnIdle>\r\n    </IdleSettings>\r\n    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\r\n    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\r\n    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>\r\n    <AllowHardTerminate>true</AllowHardTerminate>\r\n    <StartWhenAvailable>true</StartWhenAvailable>\r\n    <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>\r\n    <NetworkSettings />\r\n    <AllowStartOnDemand>true</AllowStartOnDemand>\r\n    <Enabled>true</Enabled>\r\n    <Hidden>false</Hidden>\r\n    <RunOnlyIfIdle>false</RunOnlyIfIdle>\r\n    <WakeToRun>false</WakeToRun>\r\n    <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>\r\n    <Priority>7</Priority>\r\n    <RestartOnFailure>\r\n      <Interval>PT5M</Interval>\r\n      <Count>3</Count>\r\n    </RestartOnFailure>\r\n  </Settings>\r\n  <Actions Context=\"Author\">\r\n    <Exec>\r\n      <Command>%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd</Command>\r\n      <Arguments>Task</Arguments>\r\n    </Exec>\r\n  </Actions>\r\n</Task>\r\n:renewal_vista:\r\n\r\n:run_once_vista:\r\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<Task version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\r\n  <RegistrationInfo>\r\n    <Date>1999-01-01T12:00:00.34375</Date>\r\n    <Author>WindowsAddict</Author>\r\n    <Description>Online K-M-S Activation Run Once - Run and Delete itself on first Internet Contact</Description>\r\n  </RegistrationInfo>\r\n  <Triggers>\r\n    <LogonTrigger>\r\n      <Enabled>true</Enabled>\r\n    </LogonTrigger>\r\n  </Triggers>\r\n  <Principals>\r\n    <Principal id=\"Author\">\r\n      <UserId>S-1-5-18</UserId>\r\n      <RunLevel>HighestAvailable</RunLevel>\r\n    </Principal>\r\n  </Principals>\r\n  <Settings>\r\n    <IdleSettings>\r\n      <Duration>PT10M</Duration>\r\n      <WaitTimeout>PT1H</WaitTimeout>\r\n      <StopOnIdleEnd>true</StopOnIdleEnd>\r\n      <RestartOnIdle>false</RestartOnIdle>\r\n    </IdleSettings>\r\n    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\r\n    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\r\n    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>\r\n    <AllowHardTerminate>true</AllowHardTerminate>\r\n    <StartWhenAvailable>true</StartWhenAvailable>\r\n    <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>\r\n    <NetworkSettings />\r\n    <AllowStartOnDemand>true</AllowStartOnDemand>\r\n    <Enabled>true</Enabled>\r\n    <Hidden>false</Hidden>\r\n    <RunOnlyIfIdle>false</RunOnlyIfIdle>\r\n    <WakeToRun>false</WakeToRun>\r\n    <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>\r\n    <Priority>7</Priority>\r\n    <RestartOnFailure>\r\n      <Interval>PT5M</Interval>\r\n      <Count>3</Count>\r\n    </RestartOnFailure>\r\n  </Settings>\r\n  <Actions Context=\"Author\">\r\n    <Exec>\r\n      <Command>%ProgramFiles%\\Activation-Renewal\\Activation_task.cmd</Command>\r\n      <Arguments>Task</Arguments>\r\n    </Exec>\r\n  </Actions>\r\n</Task>\r\n:run_once_vista:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set variables\r\n\r\n:dk_setvar\r\n\r\nset ps=%SysPath%\\WindowsPowerShell\\v1.0\\powershell.exe\r\nset psc=%ps% -nop -c\r\nset winbuild=1\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset _NCS=1\r\nif %winbuild% LSS 10586 set _NCS=0\r\nif %winbuild% GEQ 10586 reg query \"HKCU\\Console\" /v ForceV2 %nul2% | find /i \"0x0\" %nul1% && (set _NCS=0)\r\n\r\necho \"%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%\" | find /i \"ARM64\" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)\r\n\r\nif %_NCS% EQU 1 (\r\nfor /F %%a in ('echo prompt $E ^| cmd') do set \"esc=%%a\"\r\nset     \"Red=\"41;97m\"\"\r\nset    \"Gray=\"100;97m\"\"\r\nset   \"Green=\"42;97m\"\"\r\nset    \"Blue=\"44;97m\"\"\r\nset   \"White=\"107;91m\"\"\r\nset    \"_Red=\"40;91m\"\"\r\nset  \"_White=\"40;37m\"\"\r\nset  \"_Green=\"40;92m\"\"\r\nset \"_Yellow=\"40;93m\"\"\r\n) else (\r\nset     \"Red=\"Red\" \"white\"\"\r\nset    \"Gray=\"Darkgray\" \"white\"\"\r\nset   \"Green=\"DarkGreen\" \"white\"\"\r\nset    \"Blue=\"Blue\" \"white\"\"\r\nset   \"White=\"White\" \"Red\"\"\r\nset    \"_Red=\"Black\" \"Red\"\"\r\nset  \"_White=\"Black\" \"Gray\"\"\r\nset  \"_Green=\"Black\" \"Green\"\"\r\nset \"_Yellow=\"Black\" \"Yellow\"\"\r\n)\r\n\r\nset \"nceline=echo: &echo ==== ERROR ==== &echo:\"\r\nset \"eline=echo: &call :dk_color %Red% \"==== ERROR ====\" &echo:\"\r\nif %~z0 GEQ 200000 (\r\nset \"_exitmsg=Go back\"\r\nset \"_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option.\"\r\n) else (\r\nset \"_exitmsg=Exit\"\r\nset \"_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option.\"\r\n)\r\nexit /b\r\n\r\n::  Show OS info\r\n\r\n:dk_showosinfo\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\" /v PROCESSOR_ARCHITECTURE') do set osarch=%%b\r\n\r\nfor /f \"tokens=6-7 delims=[]. \" %%i in ('ver') do if not \"%%j\"==\"\" (\r\nset fullbuild=%%i.%%j\r\n) else (\r\nfor /f \"tokens=3\" %%G in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR\" %nul6%') do if not errorlevel 1 set /a \"UBR=%%G\"\r\nfor /f \"skip=2 tokens=3,4 delims=. \" %%G in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildLabEx') do (\r\nif defined UBR (set \"fullbuild=%%G.!UBR!\") else (set \"fullbuild=%%G.%%H\")\r\n)\r\n)\r\n\r\necho Checking OS Info                        [%winos% ^| %fullbuild% ^| %osarch%]\r\nexit /b\r\n\r\n::  Check SKU value\r\n\r\n:dk_checksku\r\n\r\ncall :dk_reflection\r\n\r\nset osSKU=\r\nset slcSKU=\r\nset wmiSKU=\r\nset regSKU=\r\nset winsub=\r\n\r\nif %winbuild% GEQ 14393 (set info=Kernel-BrandingInfo) else (set info=Kernel-ProductInfo)\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3);\r\nset d1=%d1% $Sku = 0; [void]$TypeBuilder.CreateType()::SLGetWindowsInformationDWORD('%info%', [ref]$Sku); $Sku\r\nfor /f \"delims=\" %%s in ('\"%psc% %d1%\"') do if not errorlevel 1 (set slcSKU=%%s)\r\nset slcSKU=%slcSKU: =%\r\nif \"%slcSKU%\"==\"0\" set slcSKU=\r\nfor /f \"tokens=* delims=0123456789\" %%a in (\"%slcSKU%\") do (if not \"[%%a]\"==\"[]\" set slcSKU=)\r\n\r\nfor /f \"tokens=3 delims=.\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions\" /v OSProductPfn %nul6%') do set \"regSKU=%%a\"\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%a in ('\"wmic Path Win32_OperatingSystem Get OperatingSystemSKU /format:LIST\" %nul6%') do if not errorlevel 1 set \"wmiSKU=%%a\"\r\nif %_wmic% EQU 0 for /f \"tokens=1\" %%a in ('%psc% \"([WMI]'Win32_OperatingSystem=@').OperatingSystemSKU\" %nul6%') do if not errorlevel 1 set \"wmiSKU=%%a\"\r\n\r\nif %winbuild% GEQ 15063 %psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':winsubstatus\\:.*';. ([scriptblock]::Create($f[1]))\" %nul2% | find /i \"Subscription_is_activated\" %nul% && (\r\nif defined regSKU if defined slcSKU if not \"%regSKU%\"==\"%slcSKU%\" (\r\nset winsub=1\r\nset osSKU=%regSKU%\r\n)\r\n)\r\n\r\nif not defined osSKU set osSKU=%slcSKU%\r\nif not defined osSKU set osSKU=%wmiSKU%\r\nif not defined osSKU set osSKU=%regSKU%\r\nexit /b\r\n\r\n::  Get Windows Subscription status\r\n\r\n:winsubstatus:\r\n$DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(6, 1).DefineDynamicModule(4).DefineType(2)\r\n[void]$DM.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n$m = [System.Runtime.InteropServices.Marshal]\r\n$p = $m::AllocHGlobal(12)\r\n$r = $DM.CreateType()::ClipGetSubscriptionStatus([ref]$p)\r\nif ($r -eq 0) {\r\n  $enabled = $m::ReadInt32($p)\r\n  if ($enabled -ge 1) {\r\n    $state = $m::ReadInt32($p, 8)\r\n    if ($state -eq 1) {\r\n        \"Subscription_is_activated.\"\r\n    }\r\n  }\r\n}\r\n:winsubstatus:\r\n\r\n::  Get Windows permanent activation status\r\n\r\n:dk_checkperm\r\n\r\nif %_wmic% EQU 1 wmic path %spp% where (LicenseStatus='1' and GracePeriodRemaining='0' and PartialProductKey is not NULL AND LicenseDependsOn is NULL) get Name /value %nul2% | findstr /i \"Windows\" %nul1% && set _perm=1||set _perm=\r\nif %_wmic% EQU 0 %psc% \"(([WMISEARCHER]'SELECT Name FROM %spp% WHERE LicenseStatus=1 AND GracePeriodRemaining=0 AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Name | %% {echo ('Name='+$_)}\" %nul2% | findstr /i \"Windows\" %nul1% && set _perm=1||set _perm=\r\nexit /b\r\n\r\n::  Refresh license status\r\n\r\n:dk_refresh\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call RefreshLicenseStatus %nul%\r\nif %_wmic% EQU 0 %psc% \"$null=(([WMICLASS]'%sps%').GetInstances()).RefreshLicenseStatus()\" %nul%\r\nexit /b\r\n\r\n::  Install Key\r\n\r\n:dk_inskey\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey=\"%key%\" %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset keyerror=%errorlevel%\r\ncmd /c exit /b %keyerror%\r\nif %keyerror% NEQ 0 set \"keyerror=[0x%=ExitCode%]\"\r\n\r\nif defined generickey (set \"keyecho=Installing Generic Product Key         \") else (set \"keyecho=Installing Product Key                 \")\r\nif %keyerror% EQU 0 (\r\nif %sps%==SoftwareLicensingService call :dk_refresh\r\necho %keyecho% %~1 [Successful]\r\n) else (\r\ncall :dk_color %Red% \"%keyecho% %~1 [Failed] %keyerror%\"\r\nif not defined showfix (\r\nif defined altapplist call :dk_color %Red% \"Activation ID not found for this key.\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\nset showfix=1\r\n)\r\nset error=1\r\n)\r\n\r\nset generickey=\r\nexit /b\r\n\r\n::  Get Windows installed key channel\r\n\r\n:k_channel\r\n\r\nset _gvlk=\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%# in ('wmic path %spp% where \"ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' and PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL and Description like '%%KMSCLIENT%%'\" Get Name /value %nul6%') do (echo %%# findstr /i \"Windows\" %nul1% && set _gvlk=1)\r\nif %_wmic% EQU 0 for /f \"tokens=2 delims==\" %%# in ('%psc% \"(([WMISEARCHER]'SELECT Name FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL and Description like ''%%KMSCLIENT%%''').Get()).Name | %% {echo ('Name='+$_)}\" %nul6%') do (echo %%# findstr /i \"Windows\" %nul1% && set _gvlk=1)\r\nexit /b\r\n\r\n::  Get all products Activation IDs\r\n\r\n:dk_actids\r\n\r\nset allapps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1') get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1''').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined allapps (call set \"allapps=!allapps! %%a\") else (call set \"allapps=%%a\"))\r\n\r\n::  Check potential script crash issue when user manually installs way too many licenses for Office (length limit in variable)\r\n\r\nif defined allapps if %1==0ff1ce15-a989-479d-af46-f275c6370663 (\r\nset len=0\r\necho:!allapps!> \"!_ttemp!\\chklen\"\r\nfor %%A in (\"!_ttemp!\\chklen\") do (set len=%%~zA)\r\ndel \"!_ttemp!\\chklen\" %nul%\r\n\r\nif !len! GTR 6000 (\r\n%eline%\r\necho Too many licenses are installed, the script may crash.\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ntimeout /t 30\r\n)\r\n)\r\nexit /b\r\n\r\n::  Get installed products Activation IDs\r\n\r\n:dk_actid\r\n\r\nset apps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1' and PartialProductKey is not null) get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1'' AND PartialProductKey IS NOT NULL').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined apps (call set \"apps=!apps! %%a\") else (call set \"apps=%%a\"))\r\nexit /b\r\n\r\n::  Trigger reevaluation, it helps in updating SPP tasks\r\n\r\n:dk_reeval\r\n\r\nif %winbuild% LSS 7600 exit /b\r\n\r\n::  This key is left by the system in rearm process and sppsvc sometimes fails to delete it, it causes issues in working of the Scheduled Tasks of SPP\r\n\r\nset \"ruleskey=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\PersistedSystemState\"\r\nreg delete \"%ruleskey%\" /v \"State\" /f %nul%\r\nreg delete \"%ruleskey%\" /v \"SuppressRulesEngine\" /f %nul%\r\n\r\nset r1=$TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);\r\nset r2=%r1% [void]$TB.DefinePInvokeMethod('SLpTriggerServiceWorker', 'sppc.dll', 22, 1, [Int32], @([UInt32], [IntPtr], [String], [UInt32]), 1, 3);\r\nset d1=%r2% [void]$TB.CreateType()::SLpTriggerServiceWorker(0, 0, 'reeval', 0)\r\n%psc% \"Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null; %d1%\"\r\nexit /b\r\n\r\n::  Install License files using Powershell/WMI instead of slmgr.vbs\r\n\r\n:xrm:\r\nfunction InstallLicenseFile($Lsc) {\r\n    try {\r\n        $null = $sls.InstallLicense([IO.File]::ReadAllText($Lsc))\r\n    } catch {\r\n        $host.SetShouldExit($_.Exception.HResult)\r\n    }\r\n}\r\nfunction InstallLicenseArr($Str) {\r\n    $a = $Str -split ';'\r\n    ForEach ($x in $a) {InstallLicenseFile \"$x\"}\r\n}\r\nfunction InstallLicenseDir($Loc) {\r\n\tGet-ChildItem $Loc -Recurse -Filter *.xrm-ms | ForEach-Object {InstallLicenseFile $_.FullName}\r\n}\r\nfunction ReinstallLicenses() {\r\n\t$Paths = @(\"$env:SysPath\\oem\", \"$env:SysPath\\licensing\", \"$env:SysPath\\spp\\tokens\")\r\n\tforeach ($Path in $Paths) {\r\n    if (Test-Path $Path) { InstallLicenseDir \"$Path\" }\r\n\t}\r\n}\r\n:xrm:\r\n\r\n::  Check wmic.exe\r\n\r\n:dk_ckeckwmic\r\n\r\nif %winbuild% LSS 9200 (set _wmic=1&exit /b)\r\nset _wmic=0\r\nfor %%# in (wmic.exe) do @if not \"%%~$PATH:#\"==\"\" (\r\ncmd /c \"wmic path Win32_ComputerSystem get CreationClassName /value\" %nul2% | find /i \"computersystem\" %nul1% && set _wmic=1\r\n)\r\nexit /b\r\n\r\n::  Show info for potential script stuck scenario\r\n\r\n:dk_sppissue\r\n\r\nsc start %_slser% %nul%\r\nset spperror=%errorlevel%\r\n\r\nif %spperror% NEQ 1056 if %spperror% NEQ 0 (\r\n%eline%\r\necho sc start %_slser% [Error Code: %spperror%]\r\nif %spperror% EQU 1053 (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\ncall :dk_color %Blue% \"If it still does not work, go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\n)\r\n)\r\n\r\necho:\r\n%psc% \"$job = Start-Job { (Get-WmiObject -Query 'SELECT * FROM %sps%').Version }; if (-not (Wait-Job $job -Timeout 30)) {write-host '%_slser% is not working correctly. Check this webpage for help - %mas%troubleshoot'}\"\r\nexit /b\r\n\r\n::  Get Product name (WMI/REG methods are not reliable in all conditions, hence winbrand.dll method is used)\r\n\r\n:dk_product\r\n\r\nset d1=%ref% $meth = $TypeBuilder.DefinePInvokeMethod('BrandingFormatString', 'winbrand.dll', 'Public, Static', 1, [String], @([String]), 1, 3);\r\nset d1=%d1% $meth.SetImplementationFlags(128); $TypeBuilder.CreateType()::BrandingFormatString('%%WINDOWS_LONG%%') -replace [string][char]0xa9, '' -replace [string][char]0xae, '' -replace [string][char]0x2122, ''\r\n\r\nset winos=\r\nfor /f \"delims=\" %%s in ('\"%psc% %d1%\"') do if not errorlevel 1 (set winos=%%s)\r\necho \"%winos%\" | find /i \"Windows\" %nul1% || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v ProductName %nul6%') do set \"winos=%%b\"\r\nif %winbuild% GEQ 22000 (\r\nset winos=!winos:Windows 10=Windows 11!\r\n)\r\n)\r\n\r\nif not defined winsub exit /b\r\n\r\n::  Check base edition product name if Windows subscription license is found\r\n\r\nfor %%# in (pkeyhelper.dll) do @if \"%%~$PATH:#\"==\"\" exit /b\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionNameFromId', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [IntPtr].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionNameFromId(%regSKU%, [ref]$out);$s=[Runtime.InteropServices.Marshal]::PtrToStringUni($out); $s\r\n\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (\r\nif %winbuild% GEQ 22000 (\r\nset winos=Windows 11 %%a\r\n) else (\r\nset winos=Windows 10 %%a\r\n)\r\n)\r\nexit /b\r\n\r\n::  Common lines used in PowerShell reflection code\r\n\r\n:dk_reflection\r\n\r\nset ref=$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1);\r\nset ref=%ref% $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False);\r\nset ref=%ref% $TypeBuilder = $ModuleBuilder.DefineType(0);\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get Product Key from pkeyhelper.dll for future new editions\r\n::  It works on Windows 10 1803 (17134) and later builds.\r\n\r\n:k_pkey\r\n\r\ncall :dk_reflection\r\n\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SkuGetProductKeyForEdition', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [String], [String].MakeByRefType(), [String].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = ''; [void]$TypeBuilder.CreateType()::SkuGetProductKeyForEdition(%1, %2, [ref]$out, [ref]$null); $out\r\n\r\nset pkey=\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (set pkey=%%a)\r\nexit /b\r\n\r\n::  Get channel name for the key which was extracted from pkeyhelper.dll\r\n\r\n:k_pkeychannel\r\n\r\nset k=%1\r\nset m=[Runtime.InteropServices.Marshal]\r\nset p=%SysPath%\\spp\\tokens\\pkeyconfig\\pkeyconfig.xrm-ms\r\n\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('PidGenX', 'pidgenx.dll', 'Public, Static', 1, [int], @([String], [String], [String], [int], [IntPtr], [IntPtr], [IntPtr]), 1, 3);\r\nset d1=%d1% $r = [byte[]]::new(0x04F8); $r[0] = 0xF8; $r[1] = 0x04; $f = %m%::AllocHGlobal(0x04F8); %m%::Copy($r, 0, $f, 0x04F8);\r\nset d1=%d1% [void]$TypeBuilder.CreateType()::PidGenX('%k%', '%p%', '00000', 0, 0, 0, $f); %m%::Copy($f, $r, 0, 0x04F8); %m%::FreeHGlobal($f); [Text.Encoding]::Unicode.GetString($r, 1016, 128)\r\n\r\nset pkeychannel=\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (set pkeychannel=%%a)\r\nexit /b\r\n\r\n:k_gvlk\r\n\r\nfor %%# in (pkeyhelper.dll) do @if \"%%~$PATH:#\"==\"\" exit /b\r\nfor %%# in (Volume:GVLK) do (\r\ncall :k_pkey %osSKU% '%%#'\r\nif defined pkey call :k_pkeychannel !pkey!\r\nif /i \"!pkeychannel!\"==\"%%#\" (\r\nset key=!pkey!\r\nexit /b\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_chkmal\r\n\r\n::  Many users unknowingly download mal-ware by using activators found through Google search.\r\n::  This code aims to notify users that their system has been affected by mal-ware.\r\n\r\nset w=\r\nset results=\r\nif exist \"%ProgramFiles%\\KM%w%Spico\" set pupfound= KM%w%Spico \r\nif not defined pupfound (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\" /f Path /s | find /i \"AutoPico\" %nul% && set pupfound= KM%w%Spico \r\n)\r\n\r\nset hcount=0\r\nfor %%# in (avira.com kaspersky.com virustotal.com mcafee.com) do (\r\nfind /i \"%%#\" %SysPath%\\drivers\\etc\\hosts %nul% && set /a hcount+=1)\r\nif %hcount%==4 set \"results=[Antivirus URLs are blocked in hosts]\"\r\n\r\nsc start %_slser% %nul%\r\necho \"%errorlevel%\" | findstr \"577 225\" %nul% && (\r\nset \"results=%results%[Likely File Infector]\"\r\n) || (\r\nif not exist %SysPath%\\%_slexe% if not exist %SysPath%\\alg.exe (set \"results=%results%[Likely File Infector]\")\r\n)\r\n\r\nif not \"%results%%pupfound%\"==\"\" (\r\nif defined pupfound call :dk_color %Gray% \"Checking PUP Activators                 [Found%pupfound%]\"\r\nif defined results call :dk_color %Red% \"Checking Probable Mal%w%ware Infection...\"\r\nif defined results (call :dk_color %Red% \"%results%\"&set showfix=1)\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\necho:\r\n)\r\n\r\n::  Remove the scheduled task of R@1n-KMS (old version) that runs the activation command every minute, as it leads to high CPU usage.\r\n\r\nif exist %SysPath%\\Tasks\\R@1n-KMS (\r\nfor /f %%A in ('dir /b /a:-d %SysPath%\\Tasks\\R@1n-KMS %nul6%') do (schtasks /delete /tn \\R@1n-KMS\\%%A /f %nul%)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_errorcheck\r\n\r\nset showfix=\r\ncall :dk_chkmal\r\n\r\n::==============================\r\n\r\n::  Check Sandboxing\r\n\r\nsc query Null %nul% || (\r\ncall :dk_color %Red% \"Checking Sandboxing                     [Found, script may not work properly]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"If you are using any third-party antivirus, check if it is blocking the script.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WinPE mode\r\n\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinPE\" /v InstRoot %nul% && (\r\n\r\ncall :dk_color %Red% \"Checking WinPE                          [Found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"WinPE mode found. Reboot the system and run in normal mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Safe mode\r\n\r\nif defined safeboot_option (\r\ncall :dk_color %Red% \"Checking Boot Mode                      [%safeboot_option%]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Safe mode found. Reboot the system and run in normal mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check ImageState\r\n::  https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-setup-states\r\n\r\nfor /f \"skip=2 tokens=2*\" %%A in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State\" /v ImageState') do (set imagestate=%%B)\r\n\r\nif /i not \"%imagestate%\"==\"IMAGE_STATE_COMPLETE\" (\r\ncall :dk_color %Gray% \"Checking Windows Setup State            [%imagestate%]\"\r\necho \"%imagestate%\" | find /i \"RESEAL\" %nul% && (\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"You need to run it in normal mode in case you are running it in Audit Mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\necho \"%imagestate%\" | find /i \"UNDEPLOYABLE\" %nul% && (\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If the activation fails, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check corrupt services\r\n\r\nset serv_cor=\r\nfor %%# in (%_serv%) do (\r\nset _regcorr=\r\nset _corrupt=\r\nsc start %%# %nul%\r\nif !errorlevel! EQU 1060 set _corrupt=1\r\nsc query %%# %nul% || set _corrupt=1\r\nfor %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type) do if not defined _regcorr (\r\nreg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%# /v %%G %nul% || (set _corrupt=1&set _regcorr=-RegistryError)\r\n)\r\n\r\nif defined _corrupt (if defined serv_cor (set \"serv_cor=!serv_cor! %%#!_regcorr!\") else (set \"serv_cor=%%#!_regcorr!\"))\r\n)\r\n\r\nif defined serv_cor (\r\ncall :dk_color %Red% \"Checking Corrupt Services               [%serv_cor%]\"\r\n\r\nif not defined showfix (\r\necho:\r\nif /i \"%serv_cor%\"==\"sppsvc-RegistryError\" (\r\nset fixes=%fixes% %mas%fix_service\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_service\"\r\n) else (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\necho:\r\n)\r\n\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check disabled services\r\n\r\nset serv_ste=\r\nfor %%# in (%_serv%) do (\r\nsc start %%# %nul%\r\nif !errorlevel! EQU 1058 (if defined serv_ste (set \"serv_ste=!serv_ste! %%#\") else (set \"serv_ste=%%#\"))\r\n)\r\n\r\n::  Change disabled services startup type to default\r\n\r\nset serv_csts=\r\nset serv_cste=\r\n\r\nif defined serv_ste (\r\nfor %%# in (%serv_ste%) do (\r\nif /i %%#==ClipSVC          (reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%#\" /v \"Start\" /t REG_DWORD /d \"3\" /f %nul% & sc config %%# start= demand %nul%)\r\nif /i %%#==wlidsvc          sc config %%# start= demand %nul%\r\nif /i %%#==sppsvc           (reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%#\" /v \"Start\" /t REG_DWORD /d \"2\" /f %nul% & sc config %%# start= delayed-auto %nul%)\r\nif /i %%#==SLsvc            sc config %%# start= auto %nul%\r\nif /i %%#==KeyIso           sc config %%# start= demand %nul%\r\nif /i %%#==LicenseManager   sc config %%# start= demand %nul%\r\nif /i %%#==Winmgmt          sc config %%# start= auto %nul%\r\nif !errorlevel!==0 (\r\nif defined serv_csts (set \"serv_csts=!serv_csts! %%#\") else (set \"serv_csts=%%#\")\r\n) else (\r\nif defined serv_cste (set \"serv_cste=!serv_cste! %%#\") else (set \"serv_cste=%%#\")\r\n)\r\n)\r\n)\r\n\r\nif defined serv_csts call :dk_color %Gray% \"Enabling Disabled Services              [Successful] [%serv_csts%]\"\r\n\r\nif defined serv_cste (\r\ncall :dk_color %Red% \"Enabling Disabled Services              [Failed] [%serv_cste%]\"\r\n\r\nif not defined showfix (\r\necho:\r\necho %serv_cste% | findstr /i \"ClipSVC sppsvc\" %nul% && (\r\necho A registry fix has been applied to enable the disabled service.\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\n) || (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\necho:\r\n)\r\n\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check if the services are able to run or not\r\n::  Workarounds are added to get correct status and error code because sc query doesn't output correct results in some conditions\r\n\r\nset serv_e=\r\nfor %%# in (%_serv%) do (\r\nset errorcode=\r\nset checkerror=\r\n\r\nsc query %%# | find /i \"RUNNING\" %nul% || (\r\n%psc% \"Start-Job { Start-Service %%# } | Wait-Job -Timeout 20 | Out-Null\"\r\nset errorcode=!errorlevel!\r\nsc query %%# | find /i \"RUNNING\" %nul% || set checkerror=1\r\n)\r\n\r\nsc start %%# %nul%\r\nif !errorlevel! NEQ 1056 if !errorlevel! NEQ 0 (set errorcode=!errorlevel!&set checkerror=1)\r\nif defined checkerror if defined serv_e (set \"serv_e=!serv_e!, %%#-!errorcode!\") else (set \"serv_e=%%#-!errorcode!\")\r\n)\r\n\r\nif defined serv_e (\r\ncall :dk_color %Red% \"Starting Services                       [Failed] [%serv_e%]\"\r\n\r\nif not defined showfix (\r\nset listwospp=%_serv:sppsvc=%\r\necho %serv_e% | findstr /i \"!listwospp!\" %nul% && (\r\nset showfix=1\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and run the script again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If service error is still not fixed, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\n)\r\nset error=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WMI\r\n\r\nset wmifailed=\r\nif %_wmic% EQU 1 wmic path Win32_ComputerSystem get CreationClassName /value %nul2% | find /i \"computersystem\" %nul1%\r\nif %_wmic% EQU 0 %psc% \"Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName\" %nul2% | find /i \"computersystem\" %nul1%\r\n\r\nif %errorlevel% NEQ 0 set wmifailed=1\r\n\r\nif %_wmic% EQU 1 wmic path %sps% get Version %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=([WMISEARCHER]'SELECT * FROM %sps%').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset error_code=%errorlevel%\r\ncmd /c exit /b %error_code%\r\nif %error_code% NEQ 0 set \"error_code=0x%=ExitCode%\"\r\n\r\necho \"%error_code%\" | findstr /i \"0x800410 0x800440 0x80131501\" %nul1% && set wmifailed=1& ::  https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants\r\n\r\nif defined wmifailed (\r\ncall :dk_color %Red% \"Checking WMI                            [Not Working]\"\r\n\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WMI option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SPP Registry Key\r\n\r\nif %winbuild% GEQ 7600 reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Plugins\\Objects\\msft:rm/algorithm/hwid/4.0\" /f ba02fed39662 /d %nul% || (\r\ncall :dk_color %Red% \"Checking SPP Registry Key               [Incorrect ModuleId Found] [Most likely caused by gaming spoofers]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%issues_due_to_gaming_spoofers\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%issues_due_to_gaming_spoofers\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check TokenStore registry key\r\n\r\nset tokenstore=\r\nif %winbuild% GEQ 7600 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v TokenStore %nul6%') do call set \"tokenstore=%%b\"\r\nif %winbuild% LSS 9200 set \"tokenstore=%Systemdrive%\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareProtectionPlatform\"\r\n\r\nif %winbuild% GEQ 9200 if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store\" if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store\\2.0\" if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store_test\\2.0\" (\r\ncall :dk_color %Red% \"Checking TokenStore Registry Key        [Correct Path Not Found] [!tokenstore!]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset toerr=1\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This code creates token folder only if it's missing and sets default permission for it\r\n\r\nif %winbuild% GEQ 7600 if not defined toerr if not exist \"%tokenstore%\\\" (\r\n\r\nmkdir \"%tokenstore%\" %nul%\r\n\r\nif %winbuild% LSS 9200 set \"d=$sddl = 'O:NSG:NSD:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;NS)';\"\r\nif %winbuild% GEQ 9200 set \"d=$sddl = 'O:BAG:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;GR;;;BU)(A;;FR;;;BU)(A;OICI;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)';\"\r\nset \"d=!d! $AclObject = New-Object System.Security.AccessControl.DirectorySecurity;\"\r\nset \"d=!d! $AclObject.SetSecurityDescriptorSddlForm($sddl);\"\r\nset \"d=!d! Set-Acl -Path %tokenstore% -AclObject $AclObject;\"\r\n%psc% \"!d!\" %nul%\r\n\r\nif exist \"%tokenstore%\\\" (\r\ncall :dk_color %Gray% \"Checking SPP Token Folder               [Not Found, Created Now] [%tokenstore%\\]\"\r\n) else (\r\ncall :dk_color %Red% \"Checking SPP Token Folder               [Not Found, Failed to Create] [%tokenstore%\\]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This code checks if SPP has permission access to tokens folder and required registry keys. It's often caused by gaming spoofers.\r\n\r\nset permerror=\r\nif %winbuild% GEQ 9200 if not defined toerr if not defined ps32onArm if exist \"%tokenstore%\\\" (\r\nfor %%# in (\r\n\"%tokenstore%+FullControl\"\r\n\"HKLM:\\SYSTEM\\WPA+QueryValues, EnumerateSubKeys, WriteKey\"\r\n\"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform+SetValue\"\r\n) do for /f \"tokens=1,2 delims=+\" %%A in (%%#) do if not defined permerror (\r\n%psc% \"$acl = (Get-Acl '%%A' | fl | Out-String); if (-not ($acl -match 'NT SERVICE\\\\sppsvc Allow  %%B') -or ($acl -match 'NT SERVICE\\\\sppsvc Deny')) {Exit 2}\" %nul%\r\nif !errorlevel!==2 (\r\nif \"%%A\"==\"%tokenstore%\" (\r\nset \"permerror=Error Found In Token Folder\"\r\n) else (\r\nset \"permerror=Error Found In SPP Registries\"\r\n)\r\n)\r\n)\r\n\r\nREM  https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application\r\n\r\nif not defined permerror (\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% && (\r\nset \"pol=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\"\r\nreg query \"!pol!\" %nul% || reg add \"!pol!\" %nul%\r\n%psc% \"$netServ = (New-Object Security.Principal.SecurityIdentifier('S-1-5-20')).Translate([Security.Principal.NTAccount]).Value; $aclString = Get-Acl 'Registry::!pol!' | Format-List | Out-String; if (-not ($aclString.Contains($netServ + ' Allow  FullControl') -or $aclString.Contains('NT SERVICE\\sppsvc Allow  FullControl')) -or ($aclString.Contains('Deny'))) {Exit 3}\" %nul%\r\nif !errorlevel!==3 set \"permerror=Error Found In S-1-5-20 SPP\"\r\n)\r\n)\r\n\r\nif defined permerror (\r\ncall :dk_color %Red% \"Checking SPP Permissions                [!permerror!]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WPA Registry Errors\r\n\r\nset chkalp=\r\nset wpainfo=NotFound\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wpatest\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (set wpainfo=%%a)\r\nfor /f \"delims=0123456789\" %%i in (\"%wpainfo%\") do set chkalp=%%i\r\n\r\nif defined chkalp (\r\ncall :dk_color %Red% \"Checking WPA Registry Errors            [%wpainfo%]\"\r\nif not defined showfix (\r\necho \"%wpainfo%\" | find /i \"Error Found\" %nul% && (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\necho:\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\nset wpainfo=a\r\n)\r\n\r\nif not defined chkalp (\r\nif %wpainfo% GEQ 5000 (\r\ncall :dk_color %Gray% \"Checking WPA Registry Count             [%wpainfo%]\"\r\ncall :dk_color %Blue% \"A large number of WPA registries have been found, which may cause high CPU usage.\"\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\necho:\r\n) else (\r\necho Checking WPA Registry Count             [%wpainfo%]\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Rearm\r\n\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\PersistedTSReArmed\" %nul% && (\r\ncall :dk_color %Red% \"Checking Rearm                          [System is Rearmed]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState\" %nul% && (\r\ncall :dk_color %Red% \"Checking ClipSVC PersistedSystemState   [Found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SoftwareLicensingService\r\n\r\nif %error_code% NEQ 0 (\r\ncall :dk_color %Red% \"Checking SoftwareLicensingService       [Not Working] [%error_code%]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Activation IDs\r\n\r\ncall :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nif not defined apps (\r\n%psc% \"if (-not $env:_vis) {Start-Job { Stop-Service %_slser% -force } | Wait-Job -Timeout 20 | Out-Null}; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif not defined _vis if !errorlevel! NEQ 0 set rlicfailed=1\r\ncall :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f\r\n)\r\n\r\nif not defined apps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nif not defined apps if defined allapps if not defined notwinact (\r\ncall :dk_color %Gray% \"Checking Activation IDs                 [Key Not Installed or Act ID Not Found]\"\r\n)\r\n\r\nif not defined apps if not defined allapps (\r\ncall :dk_color %Red% \"Checking Activation IDs                 [Not found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\nif not defined showfix if defined rlicfailed (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\n\r\nif %winbuild% GEQ 7600 if exist \"%tokenstore%\\\" if not exist \"%tokenstore%\\tokens.dat\" (\r\ncall :dk_color %Red% \"Checking SPP tokens.dat                 [Not Found] [%tokenstore%\\]\"\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Eval Windows\r\n\r\nif not defined notwinact if exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Eval\" %nul1% || (\r\ncall :dk_color %Red% \"Checking Eval Packages                  [License swapping found. Non-Eval licenses are installed in Eval Windows]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"License swapping is not the right way to upgrade to the full version. Learn the correct method at the link below.\"\r\nset fixes=%fixes% %mas%evaluation_editions\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%evaluation_editions\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check HKU\\S-1-5-20\\Software registry, in some systems it's missing and that causes Windows activation problems\r\n\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% || (\r\ncall :dk_color %Red% \"Checking HKU\\S-1-5-20 Registry          [Not Found]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check license and package files for the current edition\r\n\r\nset osedition=0\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do if not errorlevel 1 (call set \"osedition=%%a\")\r\n\r\nif %osedition%==0 for /f \"skip=2 tokens=3\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul6%') do set \"osedition=%%a\"\r\n\r\n::  Workaround for an issue in builds between 1607 and 1709 where ProfessionalEducation is shown as Professional\r\n\r\nif not %osedition%==0 (\r\nif \"%osSKU%\"==\"164\" set osedition=ProfessionalEducation\r\nif \"%osSKU%\"==\"165\" set osedition=ProfessionalEducationN\r\n)\r\n\r\nif not defined notwinact (\r\nif %osedition%==0 (\r\ncall :dk_color %Red% \"Checking Edition Name                   [Not Found In Registry]\"\r\n) else (\r\nif not exist \"%SysPath%\\spp\\tokens\\skus\\%osedition%\\%osedition%*.xrm-ms\" if not exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-%osedition%\\*-%osedition%-*.xrm-ms\" if not exist \"%SysPath%\\licensing\\skus\\Security-Licensing-SLC-Component-SKU-%osedition%\\*-%osedition%-*.xrm-ms\" (\r\nset skunotfound=1\r\ncall :dk_color %Red% \"Checking License Files                  [Not Found] [%osedition%]\"\r\n)\r\nif not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*-%osedition%-*.mum\" (\r\nif not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-%osedition%Edition*.mum\" (\r\ncall :dk_color %Red% \"Checking Package Files                  [Not Found] [%osedition%]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SKU value to find if there is any difference\r\n\r\nif not defined notwinact (\r\nif %winbuild% GEQ 10240 (\r\n%nul% set /a \"sum=%slcSKU%+%regSKU%+%wmiSKU%\"\r\nset /a \"sum/=3\"\r\nif not \"!sum!\"==\"%slcSKU%\" (\r\ncall :dk_color %Gray% \"Checking SLC/WMI/REG SKU                [Difference Found - SLC:%slcSKU% WMI:%wmiSKU% Reg:%regSKU%]\"\r\n)\r\n) else (\r\n%nul% set /a \"sum=%slcSKU%+%wmiSKU%\"\r\nset /a \"sum/=2\"\r\nif not \"!sum!\"==\"%slcSKU%\" (\r\ncall :dk_color %Gray% \"Checking SLC/WMI SKU                    [Difference Found - SLC:%slcSKU% WMI:%wmiSKU%]\"\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This \"WLMS\" service was included in previous Eval editions (which were activable) to automatically shut down the system every hour after the evaluation period expired and prevent SPPSVC from stopping.\r\n\r\nsc query wlms %nul%\r\n\r\nif %errorlevel% NEQ 1060 (\r\necho Checking Eval WLMS Service              [Found]\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SPP interference in IFEO\r\n\r\nfor %%# in (SppEx%w%tComObj.exe SLsvc.exe sppsvc.exe sppsvc.exe\\PerfOptions) do (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" %nul% && (if defined _sppint (set \"_sppint=!_sppint!, %%#\") else (set \"_sppint=%%#\"))\r\n)\r\nif defined _sppint (\r\necho %_sppint% | find /i \"PerfOptions\" %nul% && (\r\ncall :dk_color %Red% \"Checking SPP Interference In IFEO       [%_sppint% - System might deactivate later]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\nset showfix=1\r\n) || (\r\necho Checking SPP In IFEO                    [%_sppint%]\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check and fix SkipRearm registry value\r\n\r\nif %winbuild% GEQ 7600 for /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"SkipRearm\" %nul6%') do if /i %%b NEQ 0x0 (\r\nreg add \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"SkipRearm\" /t REG_DWORD /d \"0\" /f %nul%\r\ncall :dk_color %Gray% \"Checking SkipRearm                      [Default 0 Value Not Found. Changing To 0]\"\r\n%psc% \"Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null\"\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SvcRestartTask status, this task helps in making sure system remains activated\r\n\r\nif %winbuild% GEQ 9200 if not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\n%psc% \"Get-WmiObject -Query 'SELECT Description FROM SoftwareLicensingProduct WHERE PartialProductKey IS NOT NULL AND LicenseDependsOn IS NULL' | Select-Object -Property Description\" %nul2% | findstr /i \"KMS_\" %nul1% || (\r\nfor /f \"delims=\" %%a in ('%psc% \"$s=New-Object -ComObject 'Schedule.Service'; $s.Connect(); $state=$s.GetFolder('\\Microsoft\\Windows\\SoftwareProtectionPlatform').GetTask('SvcRestartTask').State; @{0='Unknown';1='Disabled';2='Queued';3='Ready';4='Running'}[$state]\" %nul6%') do (set taskinfo=%%a)\r\n\r\necho !taskinfo! | find /i \"Ready\" %nul% || (\r\nreg delete \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"actionlist\" /f %nul%\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\Microsoft\\Windows\\SoftwareProtectionPlatform\\SvcRestartTask\" %nul% || set taskinfo=Removed\r\nif \"!taskinfo!\"==\"\" set \"taskinfo=Not Found\"\r\n\r\ncall :dk_color %Gray% \"Checking SvcRestartTask Status          [!taskinfo!. System might deactivate later.]\"\r\nif not defined showfix (\r\necho \"!taskinfo!\" | findstr /i \"Removed Not Found\" %nul1% && (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n) || (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and run the script again.\"\r\n)\r\necho:\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\nexit /b\r\n\r\n::  This code checks for invalid registry keys in HKLM\\SYSTEM\\WPA. This issue may appear even on healthy systems\r\n\r\n:wpatest:\r\n$wpaKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME).OpenSubKey(\"SYSTEM\\\\WPA\")\r\n$count = 0\r\nforeach ($subkeyName in $wpaKey.GetSubKeyNames()) {\r\n    if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n        $count++\r\n    }\r\n}\r\n$osVersion = [System.Environment]::OSVersion.Version\r\n$minBuildNumber = 14393\r\nif ($osVersion.Build -ge $minBuildNumber) {\r\n    $subkeyHashTable = @{}\r\n    foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {\r\n        if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n            $keyNumber = $subkeyName -replace '.*-', ''\r\n            $subkeyHashTable[$keyNumber] = $true\r\n        }\r\n    }\r\n    for ($i=1; $i -le $count; $i++) {\r\n        if (-not $subkeyHashTable.ContainsKey(\"$i\")) {\r\n            Write-Output \"Total Keys $count. Error Found - $i key does not exist.\"\r\n\t\t\t$wpaKey.Close()\r\n\t\t\texit\r\n        }\r\n    }\r\n}\r\n$wpaKey.GetSubKeyNames() | ForEach-Object {\r\n    if ($_ -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n        if ($PSVersionTable.PSVersion.Major -lt 3) {\r\n            cmd /c \"reg query \"HKLM\\SYSTEM\\WPA\\$_\" /ve /t REG_BINARY >nul 2>&1\"\r\n\t\t\tif ($LASTEXITCODE -ne 0) {\r\n            Write-Host \"Total Keys $count. Error Found - Binary Data is corrupt.\"\r\n\t\t\t$wpaKey.Close()\r\n\t\t\texit\r\n\t\t\t}\r\n        } else {\r\n            $subkey = $wpaKey.OpenSubKey($_)\r\n            $p = $subkey.GetValueNames()\r\n            if (($p | Where-Object { $subkey.GetValueKind($_) -eq [Microsoft.Win32.RegistryValueKind]::Binary }).Count -eq 0) {\r\n                Write-Host \"Total Keys $count. Error Found - Binary Data is corrupt.\"\r\n\t\t\t\t$wpaKey.Close()\r\n\t\t\t\texit\r\n            }\r\n        }\r\n    }\r\n}\r\n$count\r\n$wpaKey.Close()\r\n:wpatest:\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_color\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3'\r\n) else if not exist %ps% (\r\necho %~3\r\n)\r\nexit /b\r\n\r\n:dk_color2\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[%~3%~4%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'\r\n) else if not exist %ps% (\r\necho %~3 %~6\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_done\r\n\r\necho:\r\nif %_unattended%==1 timeout /t 2 & exit /b\r\n\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 exit /b\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Office version number\r\n::  2nd column = Activation ID\r\n::  3rd column = Product ID from branding.xml\r\n::  4th column = Edition\r\n::  5th column = Other Edition IDs if they are part of the same primary product (For reference only)\r\n::  Separator  = \"_\"\r\n\r\n:msiofficedata\r\n\r\nfor %%# in (\r\n14_4d463c2c-0505-4626-8cdb-a4da82e2d8ed_0015_AccessR\r\n14_745fb377-0a59-4ca9-b9a9-c359557a2c4e_001C_AccessRuntimeR\r\n14_95ab3ec8-4106-4f9d-b632-03c019d1d23f_0015_AccessVL\r\n14_4eaff0d0-c6cb-4187-94f3-c7656d49a0aa_0016_ExcelR_[HSExcelR]\r\n14_71dc86ff-f056-40d0-8ffb-9592705c9b76_0016_ExcelVL\r\n14_7004b7f0-6407-4f45-8eac-966e5f868bde_00BA_GrooveR\r\n14_fdad0dfa-417d-4b4f-93e4-64ea8867b7fd_00BA_GrooveVL\r\n14_7b7d1f17-fdcb-4820-9789-9bec6e377821_0013_HomeBusinessR_[HomeBusinessDemoR]\r\n14_19316117-30a8-4773-8fd9-7f7231f4e060_011E_HomeBusinessSubR\r\n14_09e2d37e-474b-4121-8626-58ad9be5776f_002F_HomeStudentR_[HomeStudentDemoR]\r\n14_ef1da464-01c8-43a6-91af-e4e5713744f9_0044_InfoPathR\r\n14_85e22450-b741-430c-a172-a37962c938af_0044_InfoPathVL\r\n14_14f5946a-debc-4716-babc-7e2c240fec08_000F_MondoR\r\n14_533b656a-4425-480b-8e30-1a2358898350_000F_MondoVL\r\n14_c1ceda8b-c578-4d5d-a4aa-23626be4e234_003D_ProfessionalR_[OEM-SingleImage]Exception\r\n14_3f7aa693-9a7e-44fc-9309-bb3d8e604925_00A1_OneNoteR_[HSOneNoteR]\r\n14_6860b31f-6a67-48b8-84b9-e312b3485c4b_00A1_OneNoteVL\r\n14_fbf4ac36-31c8-4340-8666-79873129cf40_001A_OutlookR\r\n14_a9aeabd8-63b8-4079-a28e-f531807fd6b8_001A_OutlookVL\r\n14_acb51361-c0db-4895-9497-1831c41f31a6_0033_PersonalR_[PersonalDemoR,PersonalPrepaidR]\r\n14_133c8359-4e93-4241-8118-30bb18737ea0_0018_PowerPointR_[HSPowerPointR]\r\n14_38252940-718c-4aa6-81a4-135398e53851_0018_PowerPointVL\r\n14_8b559c37-0117-413e-921b-b853aeb6e210_0014_ProfessionalR_[ProfessionalAcadR,ProfessionalDemoR]\r\n14_725714d7-d58f-4d12-9fa8-35873c6f7215_003B_ProjectProR_[ProjectProMSDNR]\r\n14_4d06f72e-fd50-4bc2-a24b-d448d7f17ef2_011F_ProjectProSubR\r\n14_1cf57a59-c532-4e56-9a7d-ffa2fe94b474_003B_ProjectProVL\r\n14_688f6589-2bd9-424e-a152-b13f36aa6de1_003A_ProjectStdR\r\n14_11b39439-6b93-4642-9570-f2eb81be2238_003A_ProjectStdVL\r\n14_71af7e84-93e6-4363-9b69-699e04e74071_0011_ProPlusR_[ProPlusAcadR,ProPlusMSDNR,Sub4R]\r\n14_e98ef0c0-71c4-42ce-8305-287d8721e26c_011D_ProPlusSubR\r\n14_fdf3ecb9-b56f-43b2-a9b8-1b48b6bae1a7_0011_ProPlusVL_[ProPlusAcadVL]\r\n14_98677603-a668-4fa4-9980-3f1f05f78f69_0019_PublisherR\r\n14_3d014759-b128-4466-9018-e80f6320d9d0_0019_PublisherVL\r\n14_dbe3aee0-5183-4ff7-8142-66050173cb01_008B_SmallBusBasicsR_[SmallBusBasicsMSDNR]\r\n14_8090771e-d41a-4482-929e-de87f1f47e46_008B_SmallBusBasicsVL\r\n14_b78df69e-0966-40b1-ae85-30a5134dedd0_0017_SPDR\r\n14_d3422cfb-8d8b-4ead-99f9-eab0ccd990d7_0012_StandardR\r\n14_1f76e346-e0be-49bc-9954-70ec53a4fcfe_0012_StandardVL_[StandardAcadVL]\r\n14_2745e581-565a-4670-ae90-6bf7c57ffe43_0066_StarterR\r\n14_66cad568-c2dc-459d-93ec-2f3cb967ee34_0057_VisioSIR_Prem[Pro,Std]Exception\r\n14_36756cb8-8e69-4d11-9522-68899507cd6a_0057_VisioSIVL_Prem[Pro,Std]Exception\r\n14_db3bbc9c-ce52-41d1-a46f-1a1d68059119_001B_WordR_[HSWordR]\r\n14_98d4050e-9c98-49bf-9be1-85e12eb3ab13_001B_WordVL\r\n:: Office 2013\r\n15_ab4d047b-97cf-4126-a69f-34df08e2f254_0015_AccessRetail\r\n15_259de5be-492b-44b3-9d78-9645f848f7b0_001C_AccessRuntimeRetail\r\n15_4374022d-56b8-48c1-9bb7-d8f2fc726343_0015_AccessVolume\r\n15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_0016_ExcelRetail\r\n15_ac1ae7fd-b949-4e04-a330-849bc40638cf_0016_ExcelVolume\r\n15_cfaf5356-49e3-48a8-ab3c-e729ab791250_00BA_GrooveRetail\r\n15_4825ac28-ce41-45a7-9e6e-1fed74057601_00BA_GrooveVolume\r\n15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_00E7_HomeBusinessPipcRetail\r\n15_cd256150-a898-441f-aac0-9f8f33390e45_0013_HomeBusinessRetail\r\n15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_00CE_HomeStudentARMRetail\r\n15_ebef9f05-5273-404a-9253-c5e252f50555_00DA_HomeStudentPlusARMRetail\r\n15_98685d21-78bd-4c62-bc4f-653344a63035_002F_HomeStudentRetail\r\n15_44984381-406e-4a35-b1c3-e54f499556e2_0044_InfoPathRetail\r\n15_9e016989-4007-42a6-8051-64eb97110cf2_0044_InfoPathVolume\r\n15_9103f3ce-1084-447a-827e-d6097f68c895_00EA_LyncAcademicRetail\r\n15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_012D_LyncEntryRetail\r\n15_fada6658-bfc6-4c4e-825a-59a89822cda8_012C_LyncRetail\r\n15_e1264e10-afaf-4439-a98b-256df8bb156f_012C_LyncVolume\r\n15_3169c8df-f659-4f95-9cc6-3115e6596e83_000F_MondoRetail\r\n15_f33485a0-310b-4b72-9a0e-b1d605510dbd_000F_MondoVolume\r\n15_3391e125-f6e4-4b1e-899c-a25e6092d40d_00A1_OneNoteFreeRetail\r\n15_8b524bcc-67ea-4876-a509-45e46f6347e8_00A1_OneNoteRetail\r\n15_b067e965-7521-455b-b9f7-c740204578a2_00A1_OneNoteVolume\r\n15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_001A_OutlookRetail\r\n15_8d577c50-ae5e-47fd-a240-24986f73d503_001A_OutlookVolume\r\n15_5aab8561-1686-43f7-9ff5-2c861da58d17_00E6_PersonalPipcRetail\r\n15_17e9df2d-ed91-4382-904b-4fed6a12caf0_0033_PersonalRetail\r\n15_31743b82-bfbc-44b6-aa12-85d42e644d5b_0018_PowerPointRetail\r\n15_e40dcb44-1d5c-4085-8e8f-943f33c4f004_0018_PowerPointVolume\r\n15_4e26cac1-e15a-4467-9069-cb47b67fe191_00E8_ProfessionalPipcRetail\r\n15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_0014_ProfessionalRetail\r\n15_f2435de4-5fc0-4e5b-ac97-34f515ec5ee7_003B_ProjectProRetail\r\n15_ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32_003B_ProjectProVolume\r\n15_5517e6a2-739b-4822-946f-7f0f1c5934b1_003A_ProjectStdRetail\r\n15_2b9e4a37-6230-4b42-bee2-e25ce86c8c7a_003A_ProjectStdVolume\r\n15_064383fa-1538-491c-859b-0ecab169a0ab_0011_ProPlusRetail\r\n15_2b88c4f2-ea8f-43cd-805e-4d41346e18a7_0011_ProPlusVolume\r\n15_c3a0814a-70a4-471f-af37-2313a6331111_0019_PublisherRetail\r\n15_38ea49f6-ad1d-43f1-9888-99a35d7c9409_0019_PublisherVolume\r\n15_ba3e3833-6a7e-445a-89d0-7802a9a68588_0017_SPDRetail\r\n15_32255c0a-16b4-4ce2-b388-8a4267e219eb_0012_StandardRetail\r\n15_a24cca51-3d54-4c41-8a76-4031f5338cb2_0012_StandardVolume\r\n15_15d12ad4-622d-4257-976c-5eb3282fb93d_0051_VisioProRetail\r\n15_3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d_0051_VisioProVolume\r\n15_dae597ce-5823-4c77-9580-7268b93a4b23_0053_VisioStdRetail\r\n15_44a1f6ff-0876-4edb-9169-dbb43101ee89_0053_VisioStdVolume\r\n15_191509f2-6977-456f-ab30-cf0492b1e93a_001B_WordRetail\r\n15_9cedef15-be37-4ff0-a08a-13a045540641_001B_WordVolume\r\n:: Office 365 - 15.0 version\r\n15_befee371-a2f5-4648-85db-a2c55fdf324c_00E9_O365BusinessRetail\r\n15_537ea5b5-7d50-4876-bd38-a53a77caca32_00D6_O365HomePremRetail\r\n15_149dbce7-a48e-44db-8364-a53386cd4580_00D4_O365ProPlusRetail\r\n15_bacd4614-5bef-4a5e-bafc-de4c788037a2_00D5_O365SmallBusPremRetail\r\n:: Office 365 - 16.0 version\r\n16_6337137e-7c07-4197-8986-bece6a76fc33_00E9_O365BusinessRetail\r\n16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_00D6_O365EduCloudRetail\r\n16_537ea5b5-7d50-4876-bd38-a53a77caca32_00D6_O365HomePremRetail\r\n16_149dbce7-a48e-44db-8364-a53386cd4580_00D4_O365ProPlusRetail\r\n16_bacd4614-5bef-4a5e-bafc-de4c788037a2_00D5_O365SmallBusPremRetail\r\n:: Office 2016\r\n16_bfa358b0-98f1-4125-842e-585fa13032e6_0015_AccessRetail\r\n16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_001C_AccessRuntimeRetail\r\n16_3b2fa33f-cd5a-43a5-bd95-f49f3f546b0b_0015_AccessVolume\r\n16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_0016_ExcelRetail\r\n16_685062a7-6024-42e7-8c5f-6bb9e63e697f_0016_ExcelVolume\r\n16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_00E7_HomeBusinessPipcRetail\r\n16_86834d00-7896-4a38-8fae-32f20b86fa2b_0013_HomeBusinessRetail\r\n16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_00CE_HomeStudentARMRetail\r\n16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_00DA_HomeStudentPlusARMRetail\r\n16_c28acdb8-d8b3-4199-baa4-024d09e97c99_002F_HomeStudentRetail\r\n16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_002F_HomeStudentVNextRetail\r\n16_b21367df-9545-4f02-9f24-240691da0e58_000F_MondoRetail\r\n16_2cd0ea7e-749f-4288-a05e-567c573b2a6c_000F_MondoVolume\r\n16_436366de-5579-4f24-96db-3893e4400030_00A3_OneNoteFreeRetail\r\n16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_00A1_OneNoteRetail\r\n16_23b672da-a456-4860-a8f3-e062a501d7e8_00A1_OneNoteVolume\r\n16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_001A_OutlookRetail\r\n16_50059979-ac6f-4458-9e79-710bcb41721a_001A_OutlookVolume\r\n16_5aab8561-1686-43f7-9ff5-2c861da58d17_00E6_PersonalPipcRetail\r\n16_a9f645a1-0d6a-4978-926a-abcb363b72a6_0033_PersonalRetail\r\n16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_0018_PowerPointRetail\r\n16_9b4060c9-a7f5-4a66-b732-faf248b7240f_0018_PowerPointVolume\r\n16_4e26cac1-e15a-4467-9069-cb47b67fe191_00E8_ProfessionalPipcRetail\r\n16_d64edc00-7453-4301-8428-197343fafb16_0014_ProfessionalRetail\r\n16_0f42f316-00b1-48c5-ada4-2f52b5720ad0_003B_ProjectProRetail\r\n16_82f502b5-b0b0-4349-bd2c-c560df85b248_003B_ProjectProVolume\r\n16_16728639-a9ab-4994-b6d8-f81051e69833_003B_ProjectProXVolume\r\n16_e9f0b3fc-962f-4944-ad06-05c10b6bcd5e_003A_ProjectStdRetail\r\n16_82e6b314-2a62-4e51-9220-61358dd230e6_003A_ProjectStdVolume\r\n16_431058f0-c059-44c5-b9e7-ed2dd46b6789_003A_ProjectStdXVolume\r\n16_de52bd50-9564-4adc-8fcb-a345c17f84f9_0011_ProPlusRetail\r\n16_c47456e3-265d-47b6-8ca0-c30abbd0ca36_0011_ProPlusVolume\r\n16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_0019_PublisherRetail\r\n16_fcc1757b-5d5f-486a-87cf-c4d6dedb6032_0019_PublisherVolume\r\n16_971cd368-f2e1-49c1-aedd-330909ce18b6_012D_SkypeforBusinessEntryRetail\r\n16_418d2b9f-b491-4d7f-84f1-49e27cc66597_012C_SkypeforBusinessRetail\r\n16_03ca3b9a-0869-4749-8988-3cbc9d9f51bb_012C_SkypeforBusinessVolume\r\n16_9103f3ce-1084-447a-827e-d6097f68c895_012C_SkypeServiceBypassRetail\r\n16_4a31c291-3a12-4c64-b8ab-cd79212be45e_0012_StandardRetail\r\n16_0ed94aac-2234-4309-ba29-74bdbb887083_0012_StandardVolume\r\n16_2dfe2075-2d04-4e43-816a-eb60bbb77574_0051_VisioProRetail\r\n16_295b2c03-4b1c-4221-b292-1411f468bd02_0051_VisioProVolume\r\n16_0594dc12-8444-4912-936a-747ca742dbdb_0051_VisioProXVolume\r\n16_c76dbcbc-d71b-4f45-b5b3-b7494cb4e23e_0053_VisioStdRetail\r\n16_44151c2d-c398-471f-946f-7660542e3369_0053_VisioStdVolume\r\n16_1d1c6879-39a3-47a5-9a6d-aceefa6a289d_0053_VisioStdXVolume\r\n16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_001B_WordRetail\r\n16_c3000759-551f-4f4a-bcac-a4b42cbf1de2_001B_WordVolume\r\n) do (\r\nfor /f \"tokens=1-5 delims=_\" %%A in (\"%%#\") do (\r\n\r\nif \"%oVer%\"==\"%%A\" (\r\nreg query \"%1\\Registration\\{%%B}\" /v ProductCode %nul2% | find /i \"-%%C-\" %nul% && (\r\nreg query \"%1\\Common\\InstalledPackages\" %nul2% | find /i \"-%%C-\" %nul% && (\r\nif defined _oIds (set _oIds=!_oIds! %%D) else (set _oIds=%%D)\r\nif /i 003D==%%C set SingleImage=1\r\n)\r\n)\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = GVLK / Free Office products keys\r\n::  3rd column = In case of Windows, its SKU ID. In case of Office, its Office version\r\n::  4th column = Edition ID\r\n::  5th column = In case of Windows, its Build Branch name in case same Edition ID is used in different OS versions with different key (For reference only)\r\n::               In case of Office, its either a key type if its a free Office product or Retail product names that needs to be converted to the Edition ID mentioned in 4th column\r\n::               In Office 2010, one highest VL edition from each primary product ID is selected, that's why Visio Prem key is mentioned but not for Visio Pro, Std\r\n::  Separator  = \"_\"\r\n\r\n:ksdata\r\n\r\nset f=\r\nfor %%# in (\r\n:: Windows 10/11\r\n73111121-5638-40f6-bc11-f1d7b0d64300_NPPR9-FWDCX-D2C8J-H872K-2Y%f%T43___4_Enterprise\r\ne272e3e2-732f-4c65-a8f0-484747d0d947_DPH2V-TTNVB-4X9Q3-TJR4H-KH%f%JW4__27_EnterpriseN\r\n2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX__48_Professional\r\na80b5abf-76ad-428b-b05d-a47d2dffeebf_MH37W-N47XK-V7XM9-C7227-GC%f%QG9__49_ProfessionalN\r\n7b9e1751-a8da-4f75-9560-5fadfe3d8e38_3KHY7-WNT83-DGQKR-F7HPR-84%f%4BM__98_CoreN\r\na9107544-f4a0-4053-a96a-1479abdef912_PVMJN-6DFY6-9CCP6-7BKTT-D3%f%WVR__99_CoreCountrySpecific\r\ncd918a57-a41b-4c82-8dce-1a538e221a83_7HNRX-D7KGG-3K4RQ-4WPJ4-YT%f%DFH_100_CoreSingleLanguage\r\n58e97c99-f377-4ef1-81d5-4ad5522b5fd8_TX9XD-98N7V-6WMQ6-BX7FG-H8%f%Q99_101_Core\r\ne0c42288-980c-4788-a014-c080d2e1926e_NW6C2-QMPVW-D7KKK-3GKT6-VC%f%FB2_121_Education\r\n3c102355-d027-42c6-ad23-2e7ef8a02585_2WH4N-8QGBV-H22JP-CT43Q-MD%f%WWJ_122_EducationN\r\n32d2fab3-e4a8-42c2-923b-4bf4fd13e6ee_M7XTQ-FN8P6-TTKYV-9D4CC-J4%f%62D_125_EnterpriseS_RS5,VB,Ge\r\n2d5a5a60-3040-48bf-beb0-fcd770c20ce0_DCPHK-NFMTC-H88MJ-PFHPY-QJ%f%4BJ_125_EnterpriseS_RS1\r\n7b51a46c-0c04-4e8f-9af4-8496cca90d5e_WNMTR-4C88C-JK8YV-HQ7T2-76%f%DF9_125_EnterpriseS_TH1\r\n7103a333-b8c8-49cc-93ce-d37c09687f92_92NFX-8DJQP-P6BBQ-THF9C-7C%f%G2H_126_EnterpriseSN_RS5,VB,Ge\r\n9f776d83-7156-45b2-8a5c-359b9c9f22a3_QFFDN-GRT3P-VKWWX-X7T3R-8B%f%639_126_EnterpriseSN_RS1\r\n87b838b7-41b6-4590-8318-5797951d8529_2F77B-TNFGY-69QQF-B8YKP-D6%f%9TJ_126_EnterpriseSN_TH1\r\n82bbc092-bc50-4e16-8e18-b74fc486aec3_NRG8B-VKK3Q-CXVCJ-9G2XF-6Q%f%84J_161_ProfessionalWorkstation\r\n4b1571d3-bafb-4b40-8087-a961be2caf65_9FNHH-K3HBT-3W4TD-6383H-6X%f%YWF_162_ProfessionalWorkstationN\r\n3f1afc82-f8ac-4f6c-8005-1d233e606eee_6TP4R-GNPTD-KYYHQ-7B7DP-J4%f%47Y_164_ProfessionalEducation\r\n5300b18c-2e33-4dc2-8291-47ffcec746dd_YVWGF-BXNMC-HTQYQ-CPQ99-66%f%QFC_165_ProfessionalEducationN\r\ne0b2d383-d112-413f-8a80-97f373a5820c_YYVX9-NTFWV-6MDM3-9PT4T-4M%f%68B_171_EnterpriseG\r\ne38454fb-41a4-4f59-a5dc-25080e354730_44RPN-FTY23-9VTTB-MP9BX-T8%f%4FV_172_EnterpriseGN\r\nec868e65-fadf-4759-b23e-93fe37f2cc29_CPWHC-NT2C7-VYW78-DHDB2-PG%f%3GK_175_ServerRdsh_RS5\r\ne4db50ea-bda1-4566-b047-0ca50abc6f07_7NBT4-WGBQX-MP4H7-QXFF8-YP%f%3KX_175_ServerRdsh_RS3\r\n0df4f814-3f57-4b8b-9a9d-fddadcd69fac_NBTWJ-3DR69-3C4V8-C26MC-GQ%f%9M6_183_CloudE\r\n59eb965c-9150-42b7-a0ec-22151b9897c5_KBN8V-HFGQ4-MGXVD-347P6-PD%f%QGT_191_IoTEnterpriseS_VB,NI\r\nd30136fc-cb4b-416e-a23d-87207abc44a9_6XN7V-PCBDC-BDBRH-8DQY7-G6%f%R44_202_CloudEditionN\r\nca7df2e3-5ea0-47b8-9ac1-b1be4d8edd69_37D7F-N49CB-WQR8W-TBJ73-FM%f%8RX_203_CloudEdition\r\n:: Windows 2016/19/22/25 LTSC/SAC\r\n7dc26449-db21-4e09-ba37-28f2958506a6_TVRH6-WHNXV-R9WG3-9XRFY-MY%f%832___7_ServerStandard_Ge\r\n9bd77860-9b31-4b7b-96ad-2564017315bf_VDYBN-27WPP-V4HQT-9VMD4-VM%f%K7H___7_ServerStandard_FE\r\nde32eafd-aaee-4662-9444-c1befb41bde2_N69G4-B89J2-4G8F4-WWYCC-J4%f%64C___7_ServerStandard_RS5\r\n8c1c5410-9f39-4805-8c9d-63a07706358f_WC2BQ-8NRM3-FDDYY-2BFGV-KH%f%KQY___7_ServerStandard_RS1\r\nc052f164-cdf6-409a-a0cb-853ba0f0f55a_D764K-2NDRG-47T6Q-P8T8W-YP%f%6DF___8_ServerDatacenter_Ge\r\nef6cfc9f-8c5d-44ac-9aad-de6a2ea0ae03_WX4NM-KYWYW-QJJR4-XV3QB-6V%f%M33___8_ServerDatacenter_FE\r\n34e1ae55-27f8-4950-8877-7a03be5fb181_WMDGN-G9PQG-XVVXX-R3X43-63%f%DFG___8_ServerDatacenter_RS5\r\n21c56779-b449-4d20-adfc-eece0e1ad74b_CB7KF-BWN84-R7R2Y-793K2-8X%f%DDG___8_ServerDatacenter_RS1\r\n034d3cbb-5d4b-4245-b3f8-f84571314078_WVDHN-86M7X-466P6-VHXV7-YY%f%726__50_ServerSolution_RS5\r\n2b5a1b0f-a5ab-4c54-ac2f-a6d94824a283_JCKRF-N37P4-C2D82-9YXRT-4M%f%63B__50_ServerSolution_RS1\r\n7b4433f4-b1e7-4788-895a-c45378d38253_QN4C6-GBJD2-FB422-GHWJK-GJ%f%G2R_110_ServerCloudStorage\r\n8de8eb62-bbe0-40ac-ac17-f75595071ea3_GRFBW-QNDC4-6QBHG-CCK3B-2P%f%R88_120_ServerARM64_RS5\r\n43d9af6e-5e86-4be8-a797-d072a046896c_K9FYF-G6NCK-73M32-XMVPY-F9%f%DRR_120_ServerARM64_RS4\r\n39e69c41-42b4-4a0a-abad-8e3c10a797cc_QFND9-D3Y9C-J3KKY-6RPVP-2D%f%PYV_145_ServerDatacenterACor_FE\r\n90c362e5-0da1-4bfd-b53b-b87d309ade43_6NMRW-2C8FM-D24W7-TQWMY-CW%f%H2D_145_ServerDatacenterACor_RS5\r\ne49c08e7-da82-42f8-bde2-b570fbcae76c_2HXDN-KRXHB-GPYC7-YCKFJ-7F%f%VDG_145_ServerDatacenterACor_RS3\r\nf5e9429c-f50b-4b98-b15c-ef92eb5cff39_67KN8-4FYJW-2487Q-MQ2J7-4C%f%4RG_146_ServerStandardACor_FE\r\n73e3957c-fc0c-400d-9184-5f7b6f2eb409_N2KJX-J94YW-TQVFB-DG9YT-72%f%4CC_146_ServerStandardACor_RS5\r\n61c5ef22-f14f-4553-a824-c4b31e84b100_PTXN8-JFHJM-4WC78-MPCBR-9W%f%4KR_146_ServerStandardACor_RS3\r\n45b5aff2-60a0-42f2-bc4b-ec6e5f7b527e_FCNV3-279Q9-BQB46-FTKXX-9H%f%PRH_168_ServerAzureCor_Ge\r\n8c8f0ad3-9a43-4e05-b840-93b8d1475cbc_6N379-GGTMK-23C6M-XVVTC-CK%f%FRQ_168_ServerAzureCor_FE\r\na99cc1f0-7719-4306-9645-294102fbff95_FDNH6-VW9RW-BXPJ7-4XTYG-23%f%9TB_168_ServerAzureCor_RS5\r\n3dbf341b-5f6c-4fa7-b936-699dce9e263f_VP34G-4NPPG-79JTQ-864T4-R3%f%MQX_168_ServerAzureCor_RS1\r\nc2e946d1-cfa2-4523-8c87-30bc696ee584_XGN3F-F394H-FD2MY-PP6FD-8M%f%CRC_407_ServerTurbine_Ge\r\n19b5e0fb-4431-46bc-bac1-2f1873e4ae73_NTBV8-9K7Q8-V27C6-M2BTV-KH%f%MXV_407_ServerTurbine_RS5\r\n:: Windows 8.1\r\n81671aaf-79d1-4eb1-b004-8cbbe173afea_MHF9N-XY6XB-WVXMC-BTDCT-MK%f%KG7___4_Enterprise\r\n113e705c-fa49-48a4-beea-7dd879b46b14_TT4HM-HN7YT-62K67-RGRQJ-JF%f%FXW__27_EnterpriseN\r\nc06b6981-d7fd-4a35-b7b4-054742b7af67_GCRJD-8NW9H-F2CDX-CCM8D-9D%f%6T9__48_Professional\r\n7476d79f-8e48-49b4-ab63-4d0b813a16e4_HMCNV-VVBFX-7HMBH-CTY9B-B4%f%FXY__49_ProfessionalN\r\nf7e88590-dfc7-4c78-bccb-6f3865b99d1a_VHXM3-NR6FT-RY6RT-CK882-KW%f%2CJ__86_EmbeddedIndustryA\r\n0ab82d54-47f4-4acb-818c-cc5bf0ecb649_NMMPB-38DD4-R2823-62W8D-VX%f%KJB__89_EmbeddedIndustry\r\ncd4e2d9f-5059-4a50-a92d-05d5bb1267c7_FNFKF-PWTVT-9RC8H-32HB2-JB%f%34X__91_EmbeddedIndustryE\r\nffee456a-cd87-4390-8e07-16146c672fd0_XYTND-K6QKT-K2MRH-66RTM-43%f%JKP__97_CoreARM\r\n78558a64-dc19-43fe-a0d0-8075b2a370a3_7B9N3-D94CG-YTVHR-QBPX3-RJ%f%P64__98_CoreN\r\ndb78b74f-ef1c-4892-abfe-1e66b8231df6_NCTT7-2RGK8-WMHRF-RY7YQ-JT%f%XG3__99_CoreCountrySpecific\r\nc72c6a1d-f252-4e7e-bdd1-3fca342acb35_BB6NG-PQ82V-VRDPW-8XVD2-V8%f%P66_100_CoreSingleLanguage\r\nfe1c3238-432a-43a1-8e25-97e7d1ef10f3_M9Q9P-WNJJT-6PXPY-DWX8H-6X%f%WKK_101_Core\r\n096ce63d-4fac-48a9-82a9-61ae9e800e5f_789NJ-TQK6T-6XTH8-J39CJ-J8%f%D3P_103_ProfessionalWMC\r\ne9942b32-2e55-4197-b0bd-5ff58cba8860_3PY8R-QHNP9-W7XQD-G6DPH-3J%f%2C9_111_CoreConnected\r\nc6ddecd6-2354-4c19-909b-306a3058484e_Q6HTR-N24GM-PMJFP-69CD8-2G%f%XKR_113_CoreConnectedN\r\nb8f5e3a3-ed33-4608-81e1-37d6c9dcfd9c_KF37N-VDV38-GRRTV-XH8X6-6F%f%3BB_115_CoreConnectedSingleLanguage\r\nba998212-460a-44db-bfb5-71bf09d1c68b_R962J-37N87-9VVK2-WJ74P-XT%f%MHR_116_CoreConnectedCountrySpecific\r\ne58d87b5-8126-4580-80fb-861b22f79296_MX3RK-9HNGX-K3QKC-6PJ3F-W8%f%D7B_112_ProfessionalStudent\r\ncab491c7-a918-4f60-b502-dab75e334f40_TNFGH-2R6PB-8XM3K-QYHX2-J4%f%296_114_ProfessionalStudentN\r\n:: Windows Server 2012 R2\r\nb3ca044e-a358-4d68-9883-aaa2941aca99_D2N9P-3P6X9-2R39C-7RTCD-MD%f%VJX___7_ServerStandard\r\n00091344-1ea4-4f37-b789-01750ba6988c_W3GGN-FT8W3-Y4M27-J84CP-Q3%f%VJ9___8_ServerDatacenter\r\n21db6ba4-9a7b-4a14-9e29-64a60c59301d_KNC87-3J2TX-XB4WP-VCPJV-M4%f%FWM__50_ServerSolution\r\nb743a2be-68d4-4dd3-af32-92425b7bb623_3NPTF-33KPT-GGBPR-YX76B-39%f%KDD_110_ServerCloudStorage\r\n:: Windows 8\r\n458e1bec-837a-45f6-b9d5-925ed5d299de_32JNW-9KQ84-P47T8-D8GGY-CW%f%CK7___4_Enterprise\r\ne14997e7-800a-4cf7-ad10-de4b45b578db_JMNMF-RHW7P-DMY6X-RF3DR-X2%f%BQT__27_EnterpriseN\r\na98bcd6d-5343-4603-8afe-5908e4611112_NG4HW-VH26C-733KW-K6F98-J8%f%CK4__48_Professional\r\nebf245c1-29a8-4daf-9cb1-38dfc608a8c8_XCVCF-2NXM9-723PB-MHCB7-2R%f%YQQ__49_ProfessionalN\r\n10018baf-ce21-4060-80bd-47fe74ed4dab_RYXVT-BNQG7-VD29F-DBMRY-HT%f%73M__89_EmbeddedIndustry\r\n18db1848-12e0-4167-b9d7-da7fcda507db_NKB3R-R2F8T-3XCDP-7Q2KW-XW%f%YQ2__91_EmbeddedIndustryE\r\naf35d7b7-5035-4b63-8972-f0b747b9f4dc_DXHJF-N9KQX-MFPVR-GHGQK-Y7%f%RKV__97_CoreARM\r\n197390a0-65f6-4a95-bdc4-55d58a3b0253_8N2M2-HWPGY-7PGT9-HGDD8-GV%f%GGY__98_CoreN\r\n9d5584a2-2d85-419a-982c-a00888bb9ddf_4K36P-JN4VD-GDC6V-KDT89-DY%f%FKP__99_CoreCountrySpecific\r\n8860fcd4-a77b-4a20-9045-a150ff11d609_2WN2H-YGCQR-KFX6K-CD6TF-84%f%YXQ_100_CoreSingleLanguage\r\nc04ed6bf-55c8-4b47-9f8e-5a1f31ceee60_BN3D2-R7TKB-3YPBD-8DRP2-27%f%GG4_101_Core\r\na00018a3-f20f-4632-bf7c-8daa5351c914_GNBB8-YVD74-QJHX6-27H4K-8Q%f%HDG_103_ProfessionalWMC\r\n:: Windows Server 2012\r\nf0f5ec41-0d55-4732-af02-440a44a3cf0f_XC9B7-NBPP2-83J2H-RHMBY-92%f%BT4___7_ServerStandard\r\nd3643d60-0c42-412d-a7d6-52e6635327f6_48HP8-DN98B-MYWDG-T2DCC-8W%f%83P___8_ServerDatacenter\r\n8f365ba6-c1b9-4223-98fc-282a0756a3ed_HTDQM-NBMMG-KGYDT-2DTKT-J2%f%MPV__50_ServerSolution\r\n7d5486c7-e120-4771-b7f1-7b56c6d3170c_HM7DN-YVMH3-46JC3-XYTG7-CY%f%QJJ__76_ServerMultiPointStandard\r\n95fd1c83-7df5-494a-be8b-1300e1c9d1cd_XNH6W-2V9GX-RGJ4K-Y8X6F-QG%f%J2G__77_ServerMultiPointPremium\r\n:: Windows 7\r\nae2ee509-1b34-41c0-acb7-6d4650168915_33PXH-7Y6KF-2VJC9-XBBR8-HV%f%THH___4_Enterprise\r\n1cb6d605-11b3-4e14-bb30-da91c8e3983a_YDRBP-3D83W-TY26F-D46B2-XC%f%KRJ__27_EnterpriseN\r\nb92e9980-b9d5-4821-9c94-140f632f6312_FJ82H-XT6CR-J8D7P-XQJJ2-GP%f%DD4__48_Professional\r\n54a09a0d-d57b-4c10-8b69-a842d6590ad5_MRPKT-YTG23-K7D7T-X2JMM-QY%f%7MG__49_ProfessionalN\r\ndb537896-376f-48ae-a492-53d0547773d0_YBYF6-BHCR3-JPKRB-CDW7B-F9%f%BK4__65_Embedded_POSReady\r\naa6dd3aa-c2b4-40e2-a544-a6bbb3f5c395_73KQT-CD9G6-K7TQG-66MRP-CQ%f%22C__65_Embedded_ThinPC\r\n5a041529-fef8-4d07-b06f-b59b573b32d2_W82YF-2Q76Y-63HXB-FGJG9-GF%f%7QX__69_ProfessionalE\r\n46bbed08-9c7b-48fc-a614-95250573f4ea_C29WB-22CC8-VJ326-GHFJW-H9%f%DH4__70_EnterpriseE\r\n:: Windows Server 2008 R2\r\n68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC___7_ServerStandard\r\n7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648___8_ServerDatacenter\r\n620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y__10_ServerEnterprise\r\n7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648__12_ServerDatacenterCore\r\n68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC__13_ServerStandardCore\r\n620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y__14_ServerEnterpriseCore\r\n8a26851c-1c7e-48d3-a687-fbca9b9ac16b_GT63C-RJFQ3-4GMB6-BRFB9-CB%f%83V__15_ServerEnterpriseIA64\r\na78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4__17_ServerWeb\r\ncda18cf3-c196-46ad-b289-60c072869994_TT8MH-CG224-D3D7Q-498W2-9Q%f%CTX__18_ServerHPC\r\na78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4__29_ServerWebCore\r\nf772515c-0e87-48d5-a676-e6962c3e1195_736RG-XDKJK-V34PF-BHK87-J6%f%X3K__56_ServerEmbeddedSolution\r\n:: Windows Vista\r\ncfd8ff08-c0d7-452b-9f60-ef5c70c32094_VKK3X-68KWM-X2YGT-QR4M6-4B%f%WMV___4_Enterprise\r\n4f3d1606-3fea-4c01-be3c-8d671c401e3b_YFKBB-PQJJV-G996G-VWGXY-2V%f%3X8___6_Business\r\n2c682dc2-8b68-4f63-a165-ae291d4cf138_HMBQG-8H2RH-C77VX-27R82-VM%f%QBT__16_BusinessN\r\nd4f54950-26f2-4fb4-ba21-ffab16afcade_VTC42-BM838-43QHV-84HX6-XJ%f%XKV__27_EnterpriseN\r\n:: Windows Server 2008\r\nad2542d4-9154-4c6d-8a44-30f11ee96989_TM24T-X9RMF-VWXK6-X8JC9-BF%f%GM2___7_ServerStandard\r\n68b6e220-cf09-466b-92d3-45cd964b9509_7M67G-PC374-GR742-YH8V4-TC%f%BY3___8_ServerDatacenter\r\nc1af4d90-d1bc-44ca-85d4-003ba33db3b9_YQGMW-MPWTJ-34KDK-48M3W-X4%f%Q6V__10_ServerEnterprise\r\n01ef176b-3e0d-422a-b4f8-4ea880035e8f_4DWFP-JF3DJ-B7DTH-78FJB-PD%f%RHK__15_ServerEnterpriseIA64\r\nddfa9f7c-f09e-40b9-8c1a-be877a9a7f4b_WYR28-R7TFJ-3X2YQ-YCY4H-M2%f%49D__17_ServerWeb\r\n7afb1156-2c1d-40fc-b260-aab7442b62fe_RCTX3-KWVHP-BR6TB-RB6DM-6X%f%7HP__18_ServerComputeCluster\r\n2401e3d0-c50a-4b58-87b2-7e794b7d2607_W7VD6-7JFBR-RX26B-YKQ3Y-6F%f%FFJ__36_ServerStandardV\r\nfd09ef77-5647-4eff-809c-af2b64659a45_22XQ2-VRXRG-P8D42-K34TD-G3%f%QQC__37_ServerDatacenterV\r\n8198490a-add0-47b2-b3ba-316b12d647b4_39BXF-X8Q23-P2WWT-38T2F-G3%f%FPG__38_ServerEnterpriseV\r\n::=======================================================================================================================================\r\n:: Office 2010\r\n8ce7e872-188c-4b98-9d90-f8f90b7aad02_V7Y44-9T38C-R2VJK-666HK-T7%f%DDX__14_AccessVL\r\ncee5d470-6e3b-4fcc-8c2b-d17428568a9f_H62QG-HXVKF-PP4HP-66KMR-CW%f%9BM__14_ExcelVL\r\n8947d0b8-c33b-43e1-8c56-9b674c052832_QYYW6-QP4CB-MBV6G-HYMCJ-4T%f%3J4__14_GrooveVL\r\nca6b6639-4ad6-40ae-a575-14dee07f6430_K96W8-67RPQ-62T9Y-J8FQJ-BT%f%37T__14_InfoPathVL\r\n09ed9640-f020-400a-acd8-d7d867dfd9c2_YBJTT-JG6MD-V9Q7P-DBKXJ-38%f%W9R__14_MondoVL\r\nab586f5c-5256-4632-962f-fefd8b49e6f4_Q4Y4M-RHWJM-PY37F-MTKWH-D3%f%XHX__14_OneNoteVL\r\necb7c192-73ab-4ded-acf4-2399b095d0cc_7YDC2-CWM8M-RRTJC-8MDVC-X3%f%DWQ__14_OutlookVL\r\n45593b1d-dfb1-4e91-bbfb-2d5d0ce2227a_RC8FX-88JRY-3PF7C-X8P67-P4%f%VTT__14_PowerPointVL\r\ndf133ff7-bf14-4f95-afe3-7b48e7e331ef_YGX6F-PGV49-PGW3J-9BTGG-VH%f%KC6__14_ProjectProVL\r\n5dc7bf61-5ec9-4996-9ccb-df806a2d0efe_4HP3K-88W3F-W2K3D-6677X-F9%f%PGB__14_ProjectStdVL\r\n6f327760-8c5c-417c-9b61-836a98287e0c_VYBBJ-TRJPB-QFQRF-QFT4D-H3%f%GVB__14_ProPlusVL\r\nb50c4f75-599b-43e8-8dcd-1081a7967241_BFK7F-9MYHM-V68C7-DRQ66-83%f%YTP__14_PublisherVL\r\nea509e87-07a1-4a45-9edc-eba5a39f36af_D6QFG-VBYP2-XQHM7-J97RH-VV%f%RCK__14_SmallBusBasicsVL\r\n9da2a678-fb6b-4e67-ab84-60dd6a9c819a_V7QKV-4XVVR-XYV4D-F7DFM-8R%f%6BM__14_StandardVL\r\n92236105-bb67-494f-94c7-7f7a607929bd_D9DWC-HPYVV-JGF4P-BTWQB-WX%f%8BJ__14_VisioSIVL\r\n2d0882e7-a4e7-423b-8ccc-70d91e0158b1_HVHB3-C6FV7-KQX9W-YQG79-CR%f%Y7T__14_WordVL\r\n:: Office 2013\r\n6ee7622c-18d8-4005-9fb7-92db644a279b_NG2JY-H4JBT-HQXYP-78QH9-4J%f%M2D__15_AccessVolume_-AccessRetail-\r\n259de5be-492b-44b3-9d78-9645f848f7b0_X3XNB-HJB7K-66THH-8DWQ3-XH%f%GJP__15_AccessRuntimeRetail_[Bypass]\r\nf7461d52-7c2b-43b2-8744-ea958e0bd09a_VGPNG-Y7HQW-9RHP7-TKPV3-BG%f%7GB__15_ExcelVolume_-ExcelRetail-\r\nfb4875ec-0c6b-450f-b82b-ab57d8d1677f_H7R7V-WPNXQ-WCYYC-76BGV-VT%f%7GH__15_GrooveVolume_-GrooveRetail-\r\na30b8040-d68a-423f-b0b5-9ce292ea5a8f_DKT8B-N7VXH-D963P-Q4PHY-F8%f%894__15_InfoPathVolume_-InfoPathRetail-\r\n9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY__15_LyncAcademicRetail_[PrepidBypass]\r\nff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_N42BF-CBY9F-W2C7R-X397X-DY%f%FQW__15_LyncEntryRetail_[PrepidBypass]\r\n1b9f11e3-c85c-4e1b-bb29-879ad2c909e3_2MG3G-3BNTT-3MFW9-KDQW3-TC%f%K7R__15_LyncVolume_-LyncRetail-\r\n1dc00701-03af-4680-b2af-007ffc758a1f_CWH2Y-NPYJW-3C7HD-BJQWB-G2%f%8JJ__15_MondoRetail\r\ndc981c6b-fc8e-420f-aa43-f8f33e5c0923_42QTK-RN8M7-J3C4G-BBGYM-88%f%CYV__15_MondoVolume_-O365BusinessRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-\r\n3391e125-f6e4-4b1e-899c-a25e6092d40d_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%FF4__15_OneNoteFreeRetail_[Bypass]\r\nefe1f3e6-aea2-4144-a208-32aa872b6545_TGN6P-8MMBC-37P2F-XHXXK-P3%f%4VW__15_OneNoteVolume_-OneNoteRetail-\r\n771c3afa-50c5-443f-b151-ff2546d863a0_QPN8Q-BJBTJ-334K3-93TGY-2P%f%MBT__15_OutlookVolume_-OutlookRetail-\r\n8c762649-97d1-4953-ad27-b7e2c25b972e_4NT99-8RJFH-Q2VDH-KYG2C-4R%f%D4F__15_PowerPointVolume_-PowerPointRetail-\r\n4a5d124a-e620-44ba-b6ff-658961b33b9a_FN8TT-7WMH6-2D4X9-M337T-23%f%42K__15_ProjectProVolume_-ProjectProRetail-\r\n427a28d1-d17c-4abf-b717-32c780ba6f07_6NTH3-CW976-3G3Y2-JK3TX-8Q%f%HTT__15_ProjectStdVolume_-ProjectStdRetail-\r\nb322da9c-a2e2-4058-9e4e-f59a6970bd69_YC7DK-G2NP3-2QQC3-J6H88-GV%f%GXT__15_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-\r\n00c79ff1-6850-443d-bf61-71cde0de305f_PN2WF-29XG2-T9HJ7-JQPJR-FC%f%XK4__15_PublisherVolume_-PublisherRetail-\r\nba3e3833-6a7e-445a-89d0-7802a9a68588_3NY6J-WHT3F-47BDV-JHF36-23%f%43W__15_SPDRetail_[PrepidBypass]\r\nb13afb38-cd79-4ae5-9f7f-eed058d750ca_KBKQT-2NMXY-JJWGP-M62JB-92%f%CD4__15_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-PersonalPipcRetail-PersonalRetail-\r\ne13ac10e-75d0-4aff-a0cd-764982cf541c_C2FG9-N6J68-H8BTJ-BW3QX-RM%f%3B3__15_VisioProVolume_-VisioProRetail-\r\nac4efaf0-f81f-4f61-bdf7-ea32b02ab117_J484Y-4NKBF-W2HMG-DBMJC-PG%f%WR7__15_VisioStdVolume_-VisioStdRetail-\r\nd9f5b1c6-5386-495a-88f9-9ad6b41ac9b3_6Q7VD-NX8JD-WJ2VH-88V73-4G%f%BJ7__15_WordVolume_-WordRetail-\r\n:: Office 2016\r\n9d9faf9e-d345-4b49-afce-68cb0a539c7c_RNB7V-P48F4-3FYY6-2P3R3-63%f%BQV__16_AccessRuntimeRetail_[PrepidBypass]\r\n67c0fc0c-deba-401b-bf8b-9c8ad8395804_GNH9Y-D2J4T-FJHGG-QRVH7-QP%f%FDW__16_AccessVolume_-AccessRetail-\r\nc3e65d36-141f-4d2f-a303-a842ee756a29_9C2PK-NWTVB-JMPW8-BFT28-7F%f%TBF__16_ExcelVolume_-ExcelRetail-\r\ne914ea6e-a5fa-4439-a394-a9bb3293ca09_DMTCJ-KNRKX-26982-JYCKT-P7%f%KB6__16_MondoRetail\r\n9caabccb-61b1-4b4b-8bec-d10a3c3ac2ce_HFTND-W9MK4-8B7MJ-B6C4G-XQ%f%BR2__16_MondoVolume_-O365AppsBasicRetail-O365BusinessRetail-O365EduCloudRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-\r\n436366de-5579-4f24-96db-3893e4400030_XYNTG-R96FY-369HX-YFPHY-F9%f%CPM__16_OneNoteFreeRetail_[Bypass]\r\nd8cace59-33d2-4ac7-9b1b-9b72339c51c8_DR92N-9HTF2-97XKM-XW2WJ-XW%f%3J6__16_OneNoteVolume_-OneNoteRetail-OneNote2021Retail-\r\nec9d9265-9d1e-4ed0-838a-cdc20f2551a1_R69KK-NTPKF-7M3Q4-QYBHW-6M%f%T9B__16_OutlookVolume_-OutlookRetail-\r\nd70b1bba-b893-4544-96e2-b7a318091c33_J7MQP-HNJ4Y-WJ7YM-PFYGF-BY%f%6C6__16_PowerPointVolume_-PowerPointRetail-\r\n4f414197-0fc2-4c01-b68a-86cbb9ac254c_YG9NW-3K39V-2T3HJ-93F3Q-G8%f%3KT__16_ProjectProVolume_-ProjectProRetail-\r\n829b8110-0e6f-4349-bca4-42803577788d_WGT24-HCNMF-FQ7XH-6M8K7-DR%f%TW9__16_ProjectProXVolume\r\nda7ddabc-3fbe-4447-9e01-6ab7440b4cd4_GNFHQ-F6YQM-KQDGJ-327XX-KQ%f%BVC__16_ProjectStdVolume_-ProjectStdRetail-\r\ncbbaca45-556a-4416-ad03-bda598eaa7c8_D8NRQ-JTYM3-7J2DX-646CT-68%f%36M__16_ProjectStdXVolume\r\nd450596f-894d-49e0-966a-fd39ed4c4c64_XQNVK-8JYDB-WJ9W3-YJ8YR-WF%f%G99__16_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-\r\n041a06cb-c5b8-4772-809f-416d03d16654_F47MM-N3XJP-TQXJ9-BP99D-8K%f%837__16_PublisherVolume_-PublisherRetail-\r\n9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY__16_SkypeServiceBypassRetail_[PrepidBypass]\r\n971cd368-f2e1-49c1-aedd-330909ce18b6_4N4D8-3J7Y3-YYW7C-73HD2-V8%f%RHY__16_SkypeforBusinessEntryRetail_[PrepidBypass]\r\n83e04ee1-fa8d-436d-8994-d31a862cab77_869NQ-FJ69K-466HW-QYCP2-DD%f%BV6__16_SkypeforBusinessVolume_-SkypeforBusinessRetail-\r\ndedfa23d-6ed1-45a6-85dc-63cae0546de6_JNRGM-WHDWX-FJJG3-K47QV-DR%f%TFM__16_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-HomeStudentVNextRetail-PersonalPipcRetail-PersonalRetail-\r\n6bf301c1-b94a-43e9-ba31-d494598c47fb_PD3PC-RHNGV-FXJ29-8JK7D-RJ%f%RJK__16_VisioProVolume_-VisioProRetail-\r\nb234abe3-0857-4f9c-b05a-4dc314f85557_69WXN-MBYV6-22PQG-3WGHK-RM%f%6XC__16_VisioProXVolume\r\naa2a7821-1827-4c2c-8f1d-4513a34dda97_7WHWN-4T7MP-G96JF-G33KR-W8%f%GF4__16_VisioStdVolume_-VisioStdRetail-\r\n361fe620-64f4-41b5-ba77-84f8e079b1f7_NY48V-PPYYH-3F4PX-XJRKJ-W4%f%423__16_VisioStdXVolume\r\nbb11badf-d8aa-470e-9311-20eaf80fe5cc_WXY84-JN2Q9-RBCCQ-3Q3J3-3P%f%FJ6__16_WordVolume_-WordRetail-\r\n:: Office 2019\r\n22e6b96c-1011-4cd5-8b35-3c8fb6366b86_FGQNJ-JWJCG-7Q8MG-RMRGJ-9T%f%QVF__16_AccessRuntime2019Retail_[PrepidBypass]\r\n9e9bceeb-e736-4f26-88de-763f87dcc485_9N9PT-27V4Y-VJ2PD-YXFMF-YT%f%FQT__16_Access2019Volume_-Access2019Retail-\r\n237854e9-79fc-4497-a0c1-a70969691c6b_TMJWT-YYNMB-3BKTF-644FC-RV%f%XBD__16_Excel2019Volume_-Excel2019Retail-\r\nc8f8a301-19f5-4132-96ce-2de9d4adbd33_7HD7K-N4PVK-BHBCQ-YWQRW-XW%f%4VK__16_Outlook2019Volume_-Outlook2019Retail-\r\n3131fd61-5e4f-4308-8d6d-62be1987c92c_RRNCX-C64HY-W2MM7-MCH9G-TJ%f%HMQ__16_PowerPoint2019Volume_-PowerPoint2019Retail-\r\n2ca2bf3f-949e-446a-82c7-e25a15ec78c4_B4NPR-3FKK7-T2MBV-FRQ4W-PK%f%D2B__16_ProjectPro2019Volume_-ProjectPro2019Retail-\r\n1777f0e3-7392-4198-97ea-8ae4de6f6381_C4F7P-NCP8C-6CQPT-MQHV9-JX%f%D2M__16_ProjectStd2019Volume_-ProjectStd2019Retail-\r\n85dd8b5f-eaa4-4af3-a628-cce9e77c9a03_NMMKJ-6RK4F-KMJVX-8D9MJ-6M%f%WKP__16_ProPlus2019Volume_-ProPlus2019Retail-Professional2019Retail-\r\n9d3e4cca-e172-46f1-a2f4-1d2107051444_G2KWX-3NW6P-PY93R-JXK2T-C9%f%Y9V__16_Publisher2019Volume_-Publisher2019Retail-\r\n734c6c6e-b0ba-4298-a891-671772b2bd1b_NCJ33-JHBBY-HTK98-MYCV8-HM%f%KHJ__16_SkypeforBusiness2019Volume_-SkypeforBusiness2019Retail-\r\nf88cfdec-94ce-4463-a969-037be92bc0e7_N9722-BV9H6-WTJTT-FPB93-97%f%8MK__16_SkypeforBusinessEntry2019Retail_[PrepidBypass]\r\n6912a74b-a5fb-401a-bfdb-2e3ab46f4b02_6NWWJ-YQWMR-QKGCB-6TMB3-9D%f%9HK__16_Standard2019Volume_-Standard2019Retail-HomeBusiness2019Retail-HomeStudentARM2019Retail-HomeStudentPlusARM2019Retail-HomeStudent2019Retail-Personal2019Retail-\r\n5b5cf08f-b81a-431d-b080-3450d8620565_9BGNQ-K37YR-RQHF2-38RQ3-7V%f%CBB__16_VisioPro2019Volume_-VisioPro2019Retail-\r\ne06d7df3-aad0-419d-8dfb-0ac37e2bdf39_7TQNQ-K3YQQ-3PFH7-CCPPM-X4%f%VQ2__16_VisioStd2019Volume_-VisioStd2019Retail-\r\n059834fe-a8ea-4bff-b67b-4d006b5447d3_PBX3G-NWMT6-Q7XBW-PYJGG-WX%f%D33__16_Word2019Volume_-Word2019Retail-\r\n:: Office 2021\r\n:: OneNote2021Volume KMS license is not available\r\n844c36cb-851c-49e7-9079-12e62a049e2a_MNX9D-PB834-VCGY2-K2RW2-2D%f%P3D__16_AccessRuntime2021Retail_[Bypass]\r\n1fe429d8-3fa7-4a39-b6f0-03dded42fe14_WM8YG-YNGDD-4JHDC-PG3F4-FC%f%4T4__16_Access2021Volume_-Access2021Retail-\r\nea71effc-69f1-4925-9991-2f5e319bbc24_NWG3X-87C9K-TC7YY-BC2G7-G6%f%RVC__16_Excel2021Volume_-Excel2021Retail-\r\na5799e4c-f83c-4c6e-9516-dfe9b696150b_C9FM6-3N72F-HFJXB-TM3V9-T8%f%6R9__16_Outlook2021Volume_-Outlook2021Retail-\r\n778ccb9a-2f6a-44e5-853c-eb22b7609643_CNM3W-V94GB-QJQHH-BDQ3J-33%f%Y8H__16_OneNoteFree2021Retail_[Bypass]\r\n6e166cc3-495d-438a-89e7-d7c9e6fd4dea_TY7XF-NFRBR-KJ44C-G83KF-GX%f%27K__16_PowerPoint2021Volume_-PowerPoint2021Retail-\r\n76881159-155c-43e0-9db7-2d70a9a3a4ca_FTNWT-C6WBT-8HMGF-K9PRX-QV%f%9H8__16_ProjectPro2021Volume_-ProjectPro2021Retail-\r\n6dd72704-f752-4b71-94c7-11cec6bfc355_J2JDC-NJCYY-9RGQ4-YXWMH-T3%f%D4T__16_ProjectStd2021Volume_-ProjectStd2021Retail-\r\nfbdb3e18-a8ef-4fb3-9183-dffd60bd0984_FXYTK-NJJ8C-GB6DW-3DYQT-6F%f%7TH__16_ProPlus2021Volume_-ProPlus2021Retail-Professional2021Retail-\r\naa66521f-2370-4ad8-a2bb-c095e3e4338f_2MW9D-N4BXM-9VBPG-Q7W6M-KF%f%BGQ__16_Publisher2021Volume_-Publisher2021Retail-\r\n1f32a9af-1274-48bd-ba1e-1ab7508a23e8_HWCXN-K3WBT-WJBKY-R8BD9-XK%f%29P__16_SkypeforBusiness2021Volume_-SkypeforBusiness2021Retail-\r\n080a45c5-9f9f-49eb-b4b0-c3c610a5ebd3_KDX7X-BNVR8-TXXGX-4Q7Y8-78%f%VT3__16_Standard2021Volume_-Standard2021Retail-HomeBusiness2021Retail-HomeStudent2021Retail-Personal2021Retail-\r\nfb61ac9a-1688-45d2-8f6b-0674dbffa33c_KNH8D-FGHT4-T8RK3-CTDYJ-K2%f%HT4__16_VisioPro2021Volume_-VisioPro2021Retail-\r\n72fce797-1884-48dd-a860-b2f6a5efd3ca_MJVNY-BYWPY-CWV6J-2RKRT-4M%f%8QG__16_VisioStd2021Volume_-VisioStd2021Retail-\r\nabe28aea-625a-43b1-8e30-225eb8fbd9e5_TN8H9-M34D3-Y64V9-TR72V-X7%f%9KV__16_Word2021Volume_-Word2021Retail-\r\n:: Office 2024\r\nfceda083-1203-402a-8ec4-3d7ed9f3648c_2TDPW-NDQ7G-FMG99-DXQ7M-TX%f%3T2__16_ProPlus2024Volume-Preview\r\naaea0dc8-78e1-4343-9f25-b69b83dd1bce_D9GTG-NP7DV-T6JP3-B6B62-JB%f%89R__16_ProjectPro2024Volume-Preview\r\n4ab4d849-aabc-43fb-87ee-3aed02518891_YW66X-NH62M-G6YFP-B7KCT-WX%f%GKQ__16_VisioPro2024Volume-Preview\r\n72e9faa7-ead1-4f3d-9f6e-3abc090a81d7_82FTR-NCHR7-W3944-MGRHM-JM%f%CWD__16_Access2024Volume_-Access2024Retail-\r\ncbbba2c3-0ff5-4558-846a-043ef9d78559_F4DYN-89BP2-WQTWJ-GR8YC-CK%f%GJG__16_Excel2024Volume_-Excel2024Retail-\r\nbef3152a-8a04-40f2-a065-340c3f23516d_D2F8D-N3Q3B-J28PV-X27HD-RJ%f%WB9__16_Outlook2024Volume_-Outlook2024Retail-\r\nb63626a4-5f05-4ced-9639-31ba730a127e_CW94N-K6GJH-9CTXY-MG2VC-FY%f%CWP__16_PowerPoint2024Volume_-PowerPoint2024Retail-\r\nf510af75-8ab7-4426-a236-1bfb95c34ff8_FQQ23-N4YCY-73HQ3-FM9WC-76%f%HF4__16_ProjectPro2024Volume_-ProjectPro2024Retail-\r\n9f144f27-2ac5-40b9-899d-898c2b8b4f81_PD3TT-NTHQQ-VC7CY-MFXK3-G8%f%7F8__16_ProjectStd2024Volume_-ProjectStd2024Retail-\r\n8d368fc1-9470-4be2-8d66-90e836cbb051_XJ2XN-FW8RK-P4HMP-DKDBV-GC%f%VGB__16_ProPlus2024Volume_-ProPlus2024Retail-\r\n0002290a-2091-4324-9e53-3cfe28884cde_4NKHF-9HBQF-Q3B6C-7YV34-F6%f%4P3__16_SkypeforBusiness2024Volume\r\nbbac904f-6a7e-418a-bb4b-24c85da06187_V28N4-JG22K-W66P8-VTMGK-H6%f%HGR__16_Standard2024Volume_-Home2024Retail-HomeBusiness2024Retail-\r\nfa187091-8246-47b1-964f-80a0b1e5d69a_B7TN8-FJ8V3-7QYCP-HQPMV-YY%f%89G__16_VisioPro2024Volume_-VisioPro2024Retail-\r\n923fa470-aa71-4b8b-b35c-36b79bf9f44b_JMMVY-XFNQC-KK4HK-9H7R3-WQ%f%QTV__16_VisioStd2024Volume_-VisioStd2024Retail-\r\nd0eded01-0881-4b37-9738-190400095098_MQ84N-7VYDM-FXV7C-6K7CC-VF%f%W9J__16_Word2024Volume_-Word2024Retail-\r\n) do (\r\nfor /f \"tokens=1-5 delims=_\" %%A in (\"%%#\") do (\r\n\r\nif %1==winkey if %osSKU%==%%C if not defined key (\r\necho \"!allapps!\" | find /i \"%%A\" %nul1% && set key=%%B\r\n)\r\n\r\nif %1==chkprod if \"%oVer%\"==\"%%C\" if not defined foundprod (\r\necho \"%%D\" | findstr /I \"\\<%2.*\" %nul% && set foundprod=1\r\n)\r\n\r\nif %1==getinfo if not defined key if \"%oVer%\"==\"%%C\" (\r\nif /i \"%2\"==\"%%D\" (\r\nset key=%%B\r\nset _actid=%%A\r\nset _allactid=!_allactid! %%A\r\n) else if not defined _oMSI if %_NoEditionChange%==0 (\r\necho: %%E | find /i \"-%2-\" %nul% && (\r\nset key=%%B\r\nset _altoffid=%%D\r\nset _actid=%%A\r\nset _allactid=!_allactid! %%A\r\n)\r\n)\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Below code is used to get alternate edition name and key if current edition doesn't support K-M-S activation\r\n\r\n::  1st column = Current SKU ID\r\n::  2nd column = Current Edition Name\r\n::  3rd column = Current Edition Activation ID\r\n::  4th column = Alternate Edition Activation ID\r\n::  5th column = Alternate Edition GVLK\r\n::  6th column = Alternate Edition Name\r\n::  Separator  = _\r\n\r\n\r\n:kmsfallback\r\n\r\nset notfoundaltactID=\r\nif %_NoEditionChange%==1 exit /b\r\n\r\nfor %%# in (\r\n205_IoTEnterpriseSK________________d4f9b41f-205c-405e-8e08-3d16e88e02be_59eb965c-9150-42b7-a0ec-22151b9897c5_KBN8V-HFGQ4-MGXVD-347P6-PD%f%QGT_IoTEnterpriseS\r\n138_ProfessionalSingleLanguage_____a48938aa-62fa-4966-9d44-9f04da3f72f2_2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX_Professional\r\n139_ProfessionalCountrySpecific____f7af7d09-40e4-419c-a49b-eae366689ebd_2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX_Professional\r\n139_ProfessionalCountrySpecific-Zn_01eb852c-424d-4060-94b8-c10d799d7364_2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX_Professional\r\n) do (\r\nfor /f \"tokens=1-6 delims=_\" %%A in (\"%%#\") do if %osSKU%==%%A (\r\necho \"!allapps!\" | find /i \"%%C\" %nul1% && (\r\necho \"!allapps!\" | find /i \"%%D\" %nul1% && (\r\nset altkey=%%E\r\nset altedition=%%F\r\n) || (\r\nset altedition=%%F\r\nset notfoundaltactID=1\r\n)\r\n)\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n:: Leave empty line below\r\n"
  },
  {
    "path": "MAS/Separate-Files-Version/Activators/TSforge_Activation.cmd",
    "content": "@set masver=3.10\r\n@echo off\r\n\r\n\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\n\r\n::  To activate Windows, run the script with \"/Z-Windows\" parameter or change 0 to 1 in below line\r\nset _actwin=0\r\n\r\n::  To activate Windows ESU, run the script with \"/Z-ESU\" parameter or change 0 to 1 in below line\r\nset _actesu=0\r\n\r\n::  To activate all Office apps (including Project/Visio), run the script with \"/Z-Office\" parameter or change 0 to 1 in below line\r\nset _actoff=0\r\n\r\n::  To activate only Project/Visio, run the script with \"/Z-ProjectVisio\" parameter or change 0 to 1 in below line\r\nset _actprojvis=0\r\n\r\n::  To activate all Windows/ESU/Office, run the script with \"/Z-WindowsESUOffice\" parameter or change 0 to 1 in below line\r\nset _actwinesuoff=0\r\n\r\n::  Advanced options:\r\n::  To activate Windows K-M-S host (csvlk), run the script with \"/Z-WinHost\" parameter or change 0 to 1 in below line\r\nset _actwinhost=0\r\n\r\n::  To activate Office K-M-S host (csvlk), run the script with \"/Z-OffHost\" parameter or change 0 to 1 in below line\r\nset _actoffhost=0\r\n\r\n::  To activate Windows 8/8.1 APPX Sideloading (APPXLOB), run the script with \"/Z-APPX\" parameter or change 0 to 1 in below line\r\nset _actappx=0\r\n\r\n::  To activate certain activation IDs, change 0 to 1 in below line and set activation IDs in \"tsids\" variable, you can enter multiple by adding a space after each of them\r\n::  or run the script with \"/Z-ID-ActivationIdGoesHere\" parameter. If you want to add multiple through parameter, pass each of them in separate parameters\r\nset _actman=\r\nset tsids=\r\n\r\n::  To reset rearm counter, evaluation period and clear the tamper state, key lock, run the script with \"/Z-Reset\" parameter or change 0 to 1 in below line\r\nset _resall=0\r\n\r\n::  Choose activation method:\r\n::  In builds 26100 and later, the script will auto select StaticCID (requires internet). If no internet is detected, it will then auto select the KMS4k method. For builds lower than 26100, the script will auto select ZeroCID.\r\n::  To change the activation method, run the script with the parameters \"/Z-SCID\", \"/Z-ZCID\", or \"/Z-KMS4k\", or modify the option from Auto to SCID, ZCID, or KMS4k in the line below.\r\nset _actmethod=Auto\r\n\r\n::  Debug Mode:\r\n::  To run the script in debug mode, change 0 to any parameter above that you want to run, in below line\r\nset \"_debug=0\"\r\n\r\n::  Script will run in unattended mode if parameters are used OR value is changed in above lines.\r\n::  If multiple options are selected then script will only pick one from the advanced option.\r\n\r\n\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\nset re1=\r\nset re2=\r\nset \"_cmdf=%~f0\"\r\nfor %%# in (%*) do (\r\nif /i \"%%#\"==\"re1\" set re1=1\r\nif /i \"%%#\"==\"re2\" set re2=1\r\nif /i \"%%#\"==\"-qedit\" (set re1=1&set re2=1)\r\n)\r\n\r\n:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows\r\n:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\Sysnative\\cmd.exe if not defined re1 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\Sysnative\\cmd.exe /c \"\"!_cmdf!\" %* re1\"\r\nexit /b\r\n)\r\n\r\n:: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\SysArm32\\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\SysArm32\\cmd.exe /c \"\"!_cmdf!\" %* re2\"\r\nexit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Debug code\r\n\r\nif \"%_debug%\" EQU \"0\" (\r\nset \"nul1=1>nul\"\r\nset \"nul2=2>nul\"\r\nset \"nul6=2^>nul\"\r\nset \"nul=>nul 2>&1\"\r\ngoto :_debug\r\n)\r\n\r\nset \"nul1=\"\r\nset \"nul2=\"\r\nset \"nul6=\"\r\nset \"nul=\"\r\n\r\n@echo on\r\n@prompt $G\r\n@call :_debug \"%_debug%\" >\"%~dp0_tmp.log\" 2>&1\r\n@cmd /u /c type \"%~dp0_tmp.log\">\"%~dp0_Debug.log\"\r\n@del \"%~dp0_tmp.log\"\r\n@echo off\r\n@exit /b\r\n\r\n:_debug\r\n\r\n::========================================================================================================================================\r\n\r\nset \"blank=\"\r\nset \"mas=ht%blank%tps%blank%://m%blank%ass%blank%grave.dev/\"\r\nset \"github=ht%blank%tps%blank%://github.com/m%blank%assgra%blank%vel/Micro%blank%soft-Acti%blank%vation-Scripts\"\r\nset \"selfgit=ht%blank%tps%blank%://git.acti%blank%vated.win/Micr%blank%osoft-Act%blank%ivation-Scripts\"\r\n\r\n::  Check if Null service is working, it's important for the batch script\r\n\r\nsc query Null | find /i \"RUNNING\"\r\nif %errorlevel% NEQ 0 (\r\necho:\r\necho Null service is not running, script may crash...\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%fix_service\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20\r\n)\r\ncls\r\n\r\n::  Check LF line ending\r\n\r\npushd \"%~dp0\"\r\n>nul findstr /v \"$\" \"%~nx0\" && (\r\necho:\r\necho Error - Script either has LF line ending issue or an empty line at the end of the script is missing.\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20 >nul\r\npopd\r\nexit /b\r\n)\r\npopd\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\nset KS=K%blank%MS\r\ntitle  TSforge Activation %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args set _args=%_args:re1=%\r\nif defined _args set _args=%_args:re2=%\r\nif defined _args for %%A in (%_args%) do (\r\nif /i \"%%A\"==\"-el\"                     (set _elev=1)\r\nif /i \"%%A\"==\"/Z-Windows\"              (set _actwin=1)\r\nif /i \"%%A\"==\"/Z-ESU\"                  (set _actesu=1)\r\nif /i \"%%A\"==\"/Z-Office\"               (set _actoff=1)\r\nif /i \"%%A\"==\"/Z-ProjectVisio\"         (set _actprojvis=1)\r\nif /i \"%%A\"==\"/Z-WindowsESUOffice\"     (set _actwinesuoff=1)\r\nif /i \"%%A\"==\"/Z-WinHost\"              (set _actwinhost=1)\r\nif /i \"%%A\"==\"/Z-OffHost\"              (set _actoffhost=1)\r\nif /i \"%%A\"==\"/Z-APPX\"                 (set _actappx=1)\r\necho \"%%A\" | find /i \"/Z-ID-\"  >nul && (set _actman=1& set \"filtsids=%%A\" & call set \"filtsids=%%filtsids:~6%%\" & if defined filtsids call set tsids=%%filtsids%% %%tsids%%)\r\nif /i \"%%A\"==\"/Z-Reset\"                (set _resall=1)\r\nif /i \"%%A\"==\"/Z-SCID\"                 (set _actmethod=SCID)\r\nif /i \"%%A\"==\"/Z-ZCID\"                 (set _actmethod=ZCID)\r\nif /i \"%%A\"==\"/Z-KMS4k\"                (set _actmethod=KMS4k)\r\n)\r\n\r\nif not defined tsids set _actman=0\r\nfor %%A in (%_actwin% %_actesu% %_actoff% %_actprojvis% %_actwinesuoff% %_actwinhost% %_actoffhost% %_actappx% %_actman% %_resall%) do (if \"%%A\"==\"1\" set _unattended=1)\r\nif /i not %_actmethod%==Auto set _unattended=1\r\n\r\n::========================================================================================================================================\r\n\r\ncall :dk_setvar\r\n\r\nif %winbuild% EQU 1 (\r\n%eline%\r\necho Failed to detect Windows build number.\r\nsetlocal EnableDelayedExpansion\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\nif exist \"%Systemdrive%\\Users\\WDAGUtilityAccount\" (\r\nsc query gcs | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Windows Sandbox detected; activation is not supported.\r\necho The script cannot run due to missing licensing components. Aborting...\r\necho:\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 6001 (\r\n%nceline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho MAS only supports Windows Vista/7/8/8.1/10/11 and their Server equivalents.\r\nif %winbuild% EQU 6000 (\r\necho:\r\necho Windows Vista RTM is not supported because Powershell cannot be installed.\r\necho Upgrade to Windows Vista SP1 or SP2.\r\n)\r\ngoto dk_done\r\n)\r\n\r\nif %winbuild% LSS 7600 if not exist \"%SysPath%\\WindowsPowerShell\\v1.0\\Modules\" (\r\n%nceline%\r\nif not exist %ps% (\r\necho PowerShell is not installed in your system.\r\n)\r\necho Install PowerShell 2.0 using the following URL.\r\necho:\r\necho https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\nif %_unattended%==0 start https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\ngoto dk_done\r\n)\r\n\r\nif %winbuild% LSS 7600 (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5\" /v Install %nul2% | find /i \"0x1\" %nul1% || (\r\n%eline%\r\necho .NET 3.5 Framework is not installed in your system.\r\necho Install it using the following URL.\r\necho:\r\necho https://www.microsoft.com/en-us/download/details.aspx?id=25150\r\nif %_unattended%==0 start https://www.microsoft.com/en-us/download/details.aspx?id=25150\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix special character limitations in path name\r\n\r\nset \"_work=%~dp0\"\r\nif \"%_work:~-1%\"==\"\\\" set \"_work=%_work:~0,-1%\"\r\n\r\nset \"_batf=%~f0\"\r\nset \"_batp=%_batf:'=''%\"\r\n\r\nset _PSarg=\"\"\"%~f0\"\"\" -el %_args%\r\nset _PSarg=%_PSarg:'=''%\r\n\r\nset \"_ttemp=%userprofile%\\AppData\\Local\\Temp\"\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\necho \"!_batf!\" | find /i \"!_ttemp!\" %nul1% && (\r\nif /i not \"!_work!\"==\"!_ttemp!\" (\r\n%eline%\r\necho The script was launched from the temp folder.\r\necho You are most likely running the script directly from the archive file.\r\necho:\r\necho Extract the archive file and launch the script from the extracted folder.\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Elevate script as admin and pass arguments and preventing loop\r\n\r\n%nul1% fltmc || (\r\nif not defined _elev %psc% \"start cmd.exe -arg '/c \\\"!_PSarg!\\\"' -verb runas\" && exit /b\r\n%eline%\r\necho This script needs admin rights.\r\necho Right click on this script and select 'Run as administrator'.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check PowerShell\r\n\r\n::pstst $ExecutionContext.SessionState.LanguageMode :pstst\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"if ($PSVersionTable.PSEdition -ne 'Core') {$f=[System.IO.File]::ReadAllText('!_batp!') -split ':pstst';. ([scriptblock]::Create($f[1]))}\" %nul6%') do (set tstresult=%%a)\r\n\r\nif /i not \"%tstresult%\"==\"FullLanguage\" (\r\n%eline%\r\nfor /f \"delims=\" %%a in ('%psc% \"$ExecutionContext.SessionState.LanguageMode\" %nul6%') do (set tstresult2=%%a)\r\necho Test 1 - %tstresult%\r\necho Test 2 - !tstresult2!\r\necho:\r\n\r\nREM check LanguageMode\r\n\r\necho: !tstresult2! | findstr /i \"ConstrainedLanguage RestrictedLanguage NoLanguage\" %nul1% && (\r\necho FullLanguage mode not found in PowerShell. Aborting...\r\necho If you have applied restrictions on Powershell then undo those changes.\r\nset fixes=%fixes% %mas%fix_powershell\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_powershell\"\r\ngoto dk_done\r\n)\r\n\r\nREM check Powershell core version\r\n\r\ncmd /c \"%psc% \"$PSVersionTable.PSEdition\"\" | find /i \"Core\" %nul1% && (\r\necho Windows Powershell is needed for MAS but it seems to be replaced with Powershell core. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n\r\nREM check for Mal-ware that may cause issues with Powershell\r\n\r\nfor /r \"%ProgramFiles%\\\" %%f in (secureboot.exe) do if exist \"%%f\" (\r\necho \"%%f\"\r\necho Mal%blank%ware found, PowerShell is not working properly.\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\ngoto dk_done\r\n)\r\n\r\nREM check if .NET is working properly\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\ncmd /c \"%psc% \"\"try {[System.AppDomain]::CurrentDomain.GetAssemblies(); [System.Math]::Sqrt(144)} catch {Exit 3}\"\"\" %nul%\r\nif !errorlevel!==3 (\r\necho Windows Powershell failed to load .NET command. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nREM check antivirus and other errors\r\n\r\necho PowerShell is not working properly. Aborting...\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\necho:\r\necho Your antivirus software might be blocking the script.\r\necho:\r\nsc query sense | find /i \"RUNNING\" %nul% && (\r\necho Installed Antivirus - Microsoft Defender for Endpoint\r\n)\r\ncmd /c \"%psc% \"\"$av = Get-WmiObject -Namespace root\\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { $n += $i.displayName }; if ($n) { Write-Host ('Installed Antivirus - ' + ($n -join ', '))}\"\"\"\r\n)\r\n\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Disable QuickEdit and launch from conhost.exe to avoid Terminal app\r\n\r\nif %winbuild% GEQ 17763 (\r\nset terminal=1\r\n) else (\r\nset terminal=\r\n)\r\n\r\n::  Check if script is running in Terminal app\r\n\r\nif defined terminal (\r\nset lines=0\r\nfor /f \"skip=3 tokens=* delims=\" %%A in ('mode con') do if \"!lines!\"==\"0\" (\r\nfor %%B in (%%A) do set lines=%%B\r\n)\r\nif !lines! GEQ 100 set terminal=\r\n)\r\n\r\nif %_unattended%==1 goto :skipQE\r\nfor %%# in (%_args%) do (if /i \"%%#\"==\"-qedit\" goto :skipQE)\r\n\r\n::  Relaunch to disable QuickEdit in the current session and use conhost.exe instead of the Terminal app\r\n::  This code disables QuickEdit for the current cmd.exe session without making permanent registry changes\r\n::  It is included because clicking on the script window can pause execution, causing confusion that the script has stopped due to an error\r\n\r\nset resetQE=1\r\nreg query HKCU\\Console /v QuickEdit %nul2% | find /i \"0x0\" %nul1% && set resetQE=0\r\nreg add HKCU\\Console /v QuickEdit /t REG_DWORD /d 0 /f %nul1%\r\n\r\nif defined terminal (\r\nstart conhost.exe \"!_batf!\" %_args% -qedit\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n) else if %resetQE% EQU 1 (\r\nstart cmd.exe /c \"\"!_batf!\" %_args% -qedit\"\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n)\r\n\r\n:skipQE\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check for updates\r\n\r\nset -=\r\nset old=\r\nset pingp=\r\nset upver=%masver:.=%\r\n\r\nfor %%A in (\r\nactiv%-%ated.win\r\nmass%-%grave.dev\r\n) do if not defined pingp (\r\nfor /f \"delims=[] tokens=2\" %%B in ('ping -n 1 %%A') do (\r\nif not \"%%B\"==\"\" (set old=1& set pingp=1)\r\nfor /f \"delims=[] tokens=2\" %%C in ('ping -n 1 updatecheck%upver%.%%A') do (\r\nif not \"%%C\"==\"\" set old=\r\n)\r\n)\r\n)\r\n\r\nif defined old (\r\necho ________________________________________________\r\n%eline%\r\necho Your version of MAS [%masver%] is outdated.\r\necho ________________________________________________\r\necho:\r\nif not %_unattended%==1 (\r\necho [1] Get Latest MAS\r\necho [0] Continue Anyway\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 rem\r\nif !errorlevel!==1 (start %selfgit% & start %github% & start %mas% & exit /b)\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_menu\r\n\r\nif %_unattended%==0 (\r\ncls\r\nif not defined terminal mode 76, 33\r\ntitle  TSforge Activation %masver%\r\n\r\necho:\r\necho:\r\necho:\r\necho        ______________________________________________________________\r\necho: \r\necho               [1] Activate - Windows\r\necho               [2] Activate - ESU\r\necho               [3] Activate - Office [All]\r\necho               [4] Activate - Office [Project/Visio]\r\necho               [5] Activate - All\r\necho               _______________________________________________  \r\necho: \r\necho                   Advanced Options:\r\necho:\r\necho               [A] Activate - Windows %KS% Host\r\necho               [B] Activate - Office %KS% Host\r\necho               [C] Activate - Windows 8/8.1 APPX Sideloading\r\necho               [D] Activate - Manually Select Products\r\nif defined _vis (\r\necho               [E] Reset    - Rearm/Timers\r\n) else (\r\necho               [E] Reset    - Rearm/Timers/Tamper/Lock\r\n)\r\necho               [F] Change   - Activation Method [%_actmethod%]\r\necho               _______________________________________________       \r\necho:\r\necho               [6] Remove TSforge Activation\r\necho               [7] Download Office\r\necho               [0] %_exitmsg%\r\necho        ______________________________________________________________\r\necho:\r\ncall :dk_color2 %_White% \"            \" %_Green% \"Choose a menu option using your keyboard...\"\r\nchoice /C:12345ABCDEF670 /N\r\nset _el=!errorlevel!\r\n\r\nif !_el!==14 exit /b\r\nif !_el!==13 start %mas%genuine-installation-media & goto :ts_menu\r\nif !_el!==12 call :ts_remove & cls & goto :ts_menu\r\nif !_el!==11 goto :ts_changemethod\r\nif !_el!==10 cls & setlocal & set \"_resall=1\"       & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==9  cls & setlocal & set \"_actman=1\"       & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==8  cls & setlocal & set \"_actappx=1\"      & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==7  cls & setlocal & set \"_actoffhost=1\"   & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==6  cls & setlocal & set \"_actwinhost=1\"   & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==5  cls & setlocal & set \"_actwinesuoff=1\" & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==4  cls & setlocal & set \"_actprojvis=1\"   & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==3  cls & setlocal & set \"_actoff=1\"       & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==2  cls & setlocal & set \"_actesu=1\"       & call :ts_start & endlocal & cls & goto :ts_menu\r\nif !_el!==1  cls & setlocal & set \"_actwin=1\"       & call :ts_start & endlocal & cls & goto :ts_menu\r\ngoto :ts_menu\r\n)\r\n\r\ngoto :ts_start\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_changemethod\r\n\r\ncls\r\nif not defined terminal mode 76, 36\r\n\r\necho:\r\necho:\r\necho:\r\necho        ______________________________________________________________\r\necho: \r\ncall :dk_color2 %_White% \"             [1] \" %_Green% \"Auto\"\r\necho                  Builds ^>= 26100 - StaticCID (KMS4k if offline)\r\necho                  Builds ^<  26100 - ZeroCID\r\necho              __________________________________________________\r\necho: \r\necho              [2] StaticCID\r\necho                  Needs Internet\r\necho                  Not for Windows 7 or older\r\necho              __________________________________________________\r\necho:\r\necho              [3] ZeroCID\r\necho                  Works reliably on builds below 26100\r\necho                  Does not work on builds above 26100.4188\r\necho              __________________________________________________\r\necho:\r\necho              [4] KMS4k\r\necho                  Volume licenses only\r\necho                  Activates for 4000+ years\r\necho              __________________________________________________\r\necho:\r\necho              [5] Learn More\r\necho              [0] %_exitmsg%\r\necho        ______________________________________________________________\r\necho:\r\ncall :dk_color2 %_White% \"            \" %_Green% \"Choose a menu option using your keyboard...\"\r\nchoice /C:123450 /N\r\nset _el=!errorlevel!\r\n\r\nif !_el!==6 goto :ts_menu\r\nif !_el!==5  cls & start %mas%tsforge &goto :ts_menu\r\nif !_el!==4  cls & set \"_actmethod=KMS4k\" & goto :ts_menu\r\nif !_el!==3  cls & set \"_actmethod=ZCID\"  & goto :ts_menu\r\nif !_el!==2  cls & set \"_actmethod=SCID\"  & goto :ts_menu\r\nif !_el!==1  cls & set \"_actmethod=Auto\"  & goto :ts_menu\r\ngoto :ts_changemethod\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_start\r\n\r\ncls\r\n\r\nif %_actwinesuoff%==1 (set height=38) else (set height=32)\r\nif not defined terminal (\r\nmode 125, %height%\r\nif exist \"%SysPath%\\spp\\store_test\\\" mode 134, %height%\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=%height%;$B.Height=300;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\ntitle  TSforge Activation %masver%\r\n\r\necho:\r\necho Initializing...\r\ncall :dk_chkmal\r\n\r\nif not exist %SysPath%\\%_slexe% (\r\n%eline%\r\necho [%SysPath%\\%_slexe%] file is missing, aborting...\r\necho:\r\nif not defined results (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options.\"\r\ncall :dk_color %Blue% \"After that, restart system and try activation again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If it still shows the same error, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\ngoto dk_done\r\n)\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"[System.Environment]::Version.Major\" %nul6%') do if \"%%a\"==\"2\" (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5\" /v Install %nul2% | find /i \"0x1\" %nul1% || (\r\n%eline%\r\necho .NET 3.5 Framework is corrupt or missing. Aborting...\r\nif exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-Embedded\" (\r\necho Install .NET Framework 4.8 and Windows Management Framework 5.1\r\n)\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 9200 if exist \"%SysPath%\\wlms\\wlms.exe\" (\r\nsc query wlms | find /i \"RUNNING\" %nul% && (\r\nsc stop %_slser% %nul%\r\nif !errorlevel! EQU 1051 (\r\n%eline%\r\necho Evaluation WLMS service is running, %_slser% service can not be stopped. Aborting...\r\necho Install Non-Eval version for Windows build %winbuild%.\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_actwinesuoff%==1 (set \"_actwin=1\" & set \"_actesu=1\" & set \"_actoff=1\")\r\nif %_actprojvis%==1   (set \"_actoff=1\")\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_ckeckwmic\r\ncall :dk_checksku\r\ncall :dk_product\r\ncall :dk_sppissue\r\n\r\n::========================================================================================================================================\r\n\r\nset error=\r\n\r\ncls\r\necho:\r\ncall :dk_showosinfo\r\n\r\nif /i %_actmethod%==SCID set tsmethod=StaticCID\r\nif /i %_actmethod%==ZCID set tsmethod=ZeroCID\r\nif /i %_actmethod%==KMS4k set tsmethod=KMS4k\r\n\r\nif /i %_actmethod%==Auto (\r\nif %winbuild% GEQ 26100 (\r\nset tsmethod=StaticCID\r\n) else (\r\nset tsmethod=ZeroCID\r\n)\r\n)\r\n\r\nif %winbuild% LSS 9200 if /i %tsmethod%==StaticCID (\r\n%eline%\r\necho StaticCID method is supported only on Windows 8 and later.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Internet connection\r\n\r\nif /i %tsmethod%==StaticCID (\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)\r\n)\r\n\r\nif defined _int (\r\necho Checking Internet Connection            [Connected!ping_f!]\r\n) else (\r\nif /i %_actmethod%==Auto if not %_actman%==1 set tsmethod=KMS4k\r\nif /i !tsmethod!==KMS4k (\r\ncall :dk_color %Red% \"Checking Internet Connection            [Not Connected]\"\r\ncall :dk_color %Blue% \"Switching To KMS4k activation because Internet is needed for StaticCID method.\"\r\n) else (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Internet Connection            [Not Connected]\"\r\ncall :dk_color %Blue% \"Internet is required for TSforge StaticCID option.\"\r\n)\r\necho:\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\necho Initiating Diagnostic Tests...\r\n\r\nset \"_serv=%_slser% Winmgmt\"\r\n\r\n::  Software Protection\r\n::  Windows Management Instrumentation\r\n\r\ncall :dk_errorcheck\r\n\r\ncall :ts_getedition\r\nif not defined tsedition (\r\ncall :dk_color %Red% \"Checking Windows Edition ID             [Not found in installed licenses, aborting...]\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto :dk_done\r\n)\r\n\r\nif /i !tsmethod!==KMS4k (\r\ncall :_taskclear-cache\r\necho Clearing %KS% Cache                      [Successful]\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_resall%==1 goto :ts_resetall\r\nif %_actman%==1 goto :ts_actman\r\nif %_actappx%==1 goto :ts_appxlob\r\nif %_actwinhost%==1 goto :ts_whost\r\nif %_actoffhost%==1 goto :ts_ohost\r\nif not %_actwin%==1 goto :ts_esu\r\n\r\n::========================================================================================================================================\r\n\r\n::  Process Windows\r\n::  Check if system is permanently activated or not\r\n\r\necho:\r\necho Processing Windows...\r\n\r\necho %tsedition% | find /i \"Eval\" %nul1% && (\r\ngoto :ts_wineval\r\n)\r\n\r\nset /a UBR=0\r\nif %winbuild% EQU 26100 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR %nul6%') do if not errorlevel 1 set /a UBR=%%b\r\nif !UBR! LSS 4188 (set dontcheckact=1)\r\n)\r\n\r\nif not defined dontcheckact call :ts_checkwinperm\r\nif defined _perm (\r\ncall :dk_color %Gray% \"Checking OS Activation                  [Windows is already permanently activated]\"\r\ngoto :ts_esu\r\n)\r\n\r\nif %winbuild% LSS 9200 if /i %tsmethod%==KMS4k goto :ts_oldks\r\nif defined _vis goto :ts_winvista\r\n\r\nset tempid=\r\nif /i %tsmethod%==KMS4k (set keytype=ks) else (set keytype=zero)\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wintsid\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (\r\necho \"%%a\" | findstr /r \".*-.*-.*-.*-.*\" %nul1% && (set tsids=!tsids! %%a& set tempid=%%a)\r\n)\r\n\r\nif defined tempid (\r\necho Checking Activation ID                  [%tempid%] [%tsedition%]\r\n) else (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Not Found] [%tsedition%] [%osSKU%]\"\r\nset error=1\r\nif /i %tsmethod%==KMS4k (\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\n)\r\ngoto :ts_esu\r\n)\r\n\r\nif defined winsub (\r\ncall :dk_color %Blue% \"Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%].\"\r\necho:\r\n)\r\n\r\ngoto :ts_esu\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_oldks\r\n\r\n::  KMS keys for KMS4k method because TSforge cannot install KMS key on Windows Vista and 7\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = Generic key\r\n::  3rd column = Edition ID\r\n::  Separator  = _\r\n\r\nset f=\r\nset key=\r\nset tempid=\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nfor %%# in (\r\n:: Windows 7\r\nae2ee509-1b34-41c0-acb7-6d4650168915_33PXH-7Y6KF-2VJC9-XBBR8-HV%f%THH_Enterprise\r\n1cb6d605-11b3-4e14-bb30-da91c8e3983a_YDRBP-3D83W-TY26F-D46B2-XC%f%KRJ_EnterpriseN\r\nb92e9980-b9d5-4821-9c94-140f632f6312_FJ82H-XT6CR-J8D7P-XQJJ2-GP%f%DD4_Professional\r\n54a09a0d-d57b-4c10-8b69-a842d6590ad5_MRPKT-YTG23-K7D7T-X2JMM-QY%f%7MG_ProfessionalN\r\ndb537896-376f-48ae-a492-53d0547773d0_YBYF6-BHCR3-JPKRB-CDW7B-F9%f%BK4_Embedded_POSReady\r\naa6dd3aa-c2b4-40e2-a544-a6bbb3f5c395_73KQT-CD9G6-K7TQG-66MRP-CQ%f%22C_Embedded_ThinPC\r\n5a041529-fef8-4d07-b06f-b59b573b32d2_W82YF-2Q76Y-63HXB-FGJG9-GF%f%7QX_ProfessionalE\r\n46bbed08-9c7b-48fc-a614-95250573f4ea_C29WB-22CC8-VJ326-GHFJW-H9%f%DH4_EnterpriseE\r\n:: Windows Server 2008 R2\r\n68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC_ServerStandard\r\n7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648_ServerDatacenter\r\n620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y_ServerEnterprise\r\n7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648_ServerDatacenterCore\r\n68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC_ServerStandardCore\r\n620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y_ServerEnterpriseCore\r\n8a26851c-1c7e-48d3-a687-fbca9b9ac16b_GT63C-RJFQ3-4GMB6-BRFB9-CB%f%83V_ServerEnterpriseIA64\r\na78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4_ServerWeb\r\ncda18cf3-c196-46ad-b289-60c072869994_TT8MH-CG224-D3D7Q-498W2-9Q%f%CTX_ServerHPC\r\na78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4_ServerWebCore\r\nf772515c-0e87-48d5-a676-e6962c3e1195_736RG-XDKJK-V34PF-BHK87-J6%f%X3K_ServerEmbeddedSolution\r\n:: Windows Vista\r\ncfd8ff08-c0d7-452b-9f60-ef5c70c32094_VKK3X-68KWM-X2YGT-QR4M6-4B%f%WMV_Enterprise\r\n4f3d1606-3fea-4c01-be3c-8d671c401e3b_YFKBB-PQJJV-G996G-VWGXY-2V%f%3X8_Business\r\n2c682dc2-8b68-4f63-a165-ae291d4cf138_HMBQG-8H2RH-C77VX-27R82-VM%f%QBT_BusinessN\r\nd4f54950-26f2-4fb4-ba21-ffab16afcade_VTC42-BM838-43QHV-84HX6-XJ%f%XKV_EnterpriseN\r\n:: Windows Server 2008\r\nad2542d4-9154-4c6d-8a44-30f11ee96989_TM24T-X9RMF-VWXK6-X8JC9-BF%f%GM2_ServerStandard\r\n68b6e220-cf09-466b-92d3-45cd964b9509_7M67G-PC374-GR742-YH8V4-TC%f%BY3_ServerDatacenter\r\nc1af4d90-d1bc-44ca-85d4-003ba33db3b9_YQGMW-MPWTJ-34KDK-48M3W-X4%f%Q6V_ServerEnterprise\r\n01ef176b-3e0d-422a-b4f8-4ea880035e8f_4DWFP-JF3DJ-B7DTH-78FJB-PD%f%RHK_ServerEnterpriseIA64\r\nddfa9f7c-f09e-40b9-8c1a-be877a9a7f4b_WYR28-R7TFJ-3X2YQ-YCY4H-M2%f%49D_ServerWeb\r\n7afb1156-2c1d-40fc-b260-aab7442b62fe_RCTX3-KWVHP-BR6TB-RB6DM-6X%f%7HP_ServerComputeCluster\r\n2401e3d0-c50a-4b58-87b2-7e794b7d2607_W7VD6-7JFBR-RX26B-YKQ3Y-6F%f%FFJ_ServerStandardV\r\nfd09ef77-5647-4eff-809c-af2b64659a45_22XQ2-VRXRG-P8D42-K34TD-G3%f%QQC_ServerDatacenterV\r\n8198490a-add0-47b2-b3ba-316b12d647b4_39BXF-X8Q23-P2WWT-38T2F-G3%f%FPG_ServerEnterpriseV\r\n) do (\r\nfor /f \"tokens=1-3 delims=_\" %%A in (\"%%#\") do if %tsedition%==%%C if not defined key (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\nset key=%%B\r\nset tempid=%%A\r\n)\r\n)\r\n)\r\n\r\nif not defined key (\r\ncall :dk_color %Red% \"Checking Activation ID                  [%tsedition% SKU-%osSKU% %KS% key is not available]\"\r\ncall :dk_color %Blue% \"Use ZeroCID activation method from the previous menu.\"\r\ngoto :ts_esu\r\n)\r\n\r\necho Checking Activation ID                  [%tempid%] [%tsedition%]\r\n\r\nset oldks=1\r\nset generickey=1\r\ncall :dk_inskey \"[%key%]\"\r\nset tsids=%tsids% %tempid%\r\ngoto :ts_esu\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_winvista\r\n\r\n::  Process Windows Vista\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = Generic key\r\n::  3rd column = Key channel\r\n::  4th column = Edition ID\r\n::  Separator  = _\r\n\r\n::  Keys aren't available for these editions, but since these editions aren't publicly available, it doesn't matter\r\n::  a797d61e-1475-470b-86c8-f737a72c188d StarterN\r\n::  5e9f548a-c8a9-44e6-a6c2-3f8d0a7a99dd ServerComputeClusterV\r\n\r\nset f=\r\nset key=\r\nset tempid=\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nfor %%# in (\r\n::  WindowsVista\r\n9de9abe2-d01d-4538-af84-4498bdbc2ba3_4D2XH-PRBMM-8Q22B-K8BM3-MR%f%W4W_____Retail_Business\r\ndb442be4-81ed-4ab3-9d66-2417e8a5c81c_76884-QXFY2-6Q2WX-2QTQ8-QX%f%X44_____Retail_BusinessN\r\nb51791c2-b562-4b73-97b0-735a0e4429a6_YQPQV-RW8R3-XMPFG-RXG9R-JG%f%TVF_____Retail_Enterprise\r\n58c37517-42f8-4723-bb44-30b05791ff2a_Q7J9R-G63R4-BFMHF-FWM9R-RW%f%DMV_____Retail_EnterpriseN\r\n95c6e80a-0ff8-4bd0-95f2-c4a39b79d09e_RCG7P-TX42D-HM8FM-TCFCW-3V%f%4VD_____Retail_HomeBasic\r\nd0333dad-c14e-46f2-b62a-8b47a1b9768b_HY2VV-XC6FF-MD6WV-FPYBQ-GF%f%JBT_____Retail_HomeBasicN\r\n9e042223-03bf-49ae-808f-ff37f128d40d_X9HTF-MKJQQ-XK376-TJ7T4-76%f%PKF_____Retail_HomePremium\r\n92d8977c-d506-4e63-b500-6d39283b6cd5_KJ6TP-PF9W2-23T3Q-XTV7M-PX%f%DT2_____Retail_HomePremiumN\r\n89e51a3c-76c0-4beb-a650-53d34c8f8186_X9PYV-YBQRV-9BXWV-TQDMK-QD%f%WK4_____Retail_Starter\r\n30fab9cc-8614-4339-989f-7ce61fb7a5c4_VMCB9-FDRV6-6CDQM-RV23K-RP%f%8F7_____Retail_Ultimate\r\n1eefed20-8ac0-478c-8774-70cd44782ea1_CVX38-P27B4-2X8BT-RXD4J-V7%f%CKX_____Retail_UltimateN\r\n::  WindowsServer2008\r\nc9ad502b-ef48-41d1-a2a0-38a38e82fed0_24FV9-H7JW8-C8Q6X-BQKMK-K9%f%77J_____Retail_ServerComputeCluster\r\n866e924e-c2a3-4872-aca1-6b48c13962d5_6QBHY-DXTPJ-T9W3P-DTJXX-4V%f%QMB_____Retail_ServerDatacenter\r\nd020c729-07f0-4f8f-87ce-bf803275c786_83TWG-TD3TC-HRDP2-K93FJ-Y3%f%4YC_OEM:NONSLP_ServerDatacenterV\r\n32b40e5e-0c6d-4c6f-ab12-a031933fd2c6_MRB7H-QJRHG-FXTBR-B2Q2M-8W%f%MTJ_____Retail_ServerEnterprise\r\n256cc990-1692-4ea8-965c-2d423d5dd24e_H4VB6-QPRWH-VDCYM-996P8-MH%f%KFY_OEM:NONSLP_ServerEnterpriseIA64\r\n1ba5e036-e386-42c4-b7eb-16bdb4fa1945_H8H7M-HDPQT-PJHQF-M7B83-9C%f%VGV_____Retail_ServerEnterpriseV\r\n8df04457-07c8-4301-bce9-d61eb76cb2d6_RGBMC-PQBVF-94Q9K-HD63B-VY%f%6MP_____Retail_ServerHomePremium\r\n5bd23b19-aa71-4a5b-8b68-c8801c2baff6_6C8KR-MD3QK-9GWFW-44CY2-W9%f%CBM_____Retail_ServerHomeStandard\r\nb86c7736-91ff-4de9-bfa9-b32b8a09acac_7XRBY-6MP2K-VQPT8-F37JV-YY%f%Q83_____Retail_ServerMediumBusinessManagement\r\nd3f5642f-081d-40b2-a4b9-efd3054d4584_6PDTD-JK48J-662TF-8J2QV-R4%f%CRB_____Retail_ServerMediumBusinessMessaging\r\nc6936a36-69f3-4994-9857-3069c7b9ec7a_D694V-CMWKH-PY92X-PFQKQ-JC%f%B69_____Retail_ServerMediumBusinessSecurity\r\ncc4c2cf8-ef29-4d8e-b168-2b65a3db3309_MRDK3-YYQF3-88BQJ-D6FJG-69%f%YJY_____Retail_ServerSBSPremium\r\nb3827b27-bd38-4284-98af-e4f4d1c051a0_2KB23-GJRBD-W3T9C-6CH2W-39%f%B7V_____Retail_ServerSBSPrime\r\n5dad0eff-3f6f-4310-8844-422f9dc7c84b_H4XDD-B27GY-667P6-XWVV7-GY%f%G8J_____Retail_ServerSBSStandard\r\n603504f9-109f-49f0-9271-8c66f7878f58_8YVM4-YQBDH-7WDQM-R27WR-WV%f%CWG_____Retail_ServerStandard\r\n65ab7338-9ad0-43fe-af1b-190b577495e2_H9MW3-6V7GK-94P9G-7FTPJ-VK%f%CKF_____Retail_ServerStandardV\r\n2be204da-24a0-4943-b66c-81e8464acd7e_2264C-TD9T8-P8HPW-CC9GH-MH%f%M2V_____Retail_ServerStorageEnterprise\r\n60207eba-8b4a-486c-a013-023b4b742c2f_RCYMT-YX342-8T6YY-XYHYC-3D%f%D7X_____Retail_ServerStorageExpress\r\n368856e9-43f7-4601-8358-e561f36c7dd8_FKFT2-WXYY9-WBPY7-6YMY4-X4%f%8JF_____Retail_ServerStorageStandard\r\n4bf433fa-ab04-4c6c-b55b-00170e14b8cd_8X9J7-HCJ7J-3WDJT-QM7D8-46%f%4YH_____Retail_ServerStorageWorkgroup\r\na77a6806-f59e-4953-97d7-229317b8e6a6_BGT39-9FYH7-X2CYD-T628F-QP%f%QPW_____Retail_ServerWeb\r\nf92f836d-4d3e-4e90-a08f-2d612d65e716_HPH76-FHFPP-DRW9D-7W2V4-HW%f%GKT_____Retail_ServerWinSB\r\n3059a9fd-b068-4f0d-acaf-66324dca67ac_2V8G6-KRXYR-MMGXJ-6RWM3-GX%f%CCG_____Retail_ServerWinSBV\r\n) do (\r\nfor /f \"tokens=1-4 delims=_\" %%A in (\"%%#\") do if %tsedition%==%%D if not defined key (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\nset key=%%B\r\nset tempid=%%A\r\n)\r\n)\r\n)\r\n\r\nif not defined key (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Activation ID                  [%tsedition% SKU-%osSKU% not found in the system]\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ngoto :ts_esu\r\n)\r\n\r\necho Checking Activation ID                  [%tempid%] [%tsedition%]\r\n\r\nset generickey=1\r\ncall :dk_inskey \"[%key%]\"\r\nset tsids=%tsids% %tempid%\r\ngoto :ts_esu\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_wineval\r\n\r\ncall :dk_color %Gray% \"Checking OS Edition                     [%tsedition%] [Evaluation edition found]\"\r\ncall :dk_color %Blue% \"Evaluation editions cannot be activated outside of evaluation period.\"\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" (\r\ncall :dk_color %Blue% \"Script will reset evaluation period, but to permanently activate Windows,\"\r\ncall :dk_color %Blue% \"Go back to main menu and use [Change Edition] option and change to Non-eval edition.\"\r\n) else (\r\ncall :dk_color %Blue% \"Script will reset evaluation period, but to permanently activate Windows, install Non-eval edition.\"\r\ncall :dk_color %_Yellow% \"%mas%evaluation_editions\"\r\n)\r\n\r\n::  Check Internet connection\r\n\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)\r\n)\r\n\r\nif defined _int (\r\necho Checking Internet Connection            [Connected%ping_f%]\r\n) else (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Internet Connection            [Not Connected]\"\r\ncall :dk_color %Blue% \"Internet is required for Windows Evaluation activation.\"\r\n)\r\n\r\n::  List of products lacking activable evaluation keys and ISOs\r\n\r\n::  c4b908d2-c4b9-439d-8ff0-48b656a24da4_EmbeddedIndustryEEval_8.1\r\n::  9b74255b-afe1-4da7-a143-98d1874b2a6c_EnterpriseNEval_8\r\n::  7fd0a88b-fb89-415f-9b79-84adc6a7cd56_EnterpriseNEval_8.1\r\n::  994578eb-193c-4c99-bea0-2483274c9afd_EnterpriseSNEval_2015\r\n::  b9f3109c-bfa9-4f37-9824-6dba9ee62056_ServerStorageStandardEval_2012R2\r\n::  2d3b7269-65f4-467d-9d51-dbe0e5a4e668_ServerStorageWorkgroupEval_2012R2\r\n\r\n:: --------\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = Activable evaluation key\r\n::  3rd column = Edition ID\r\n::  4th column = Windows version (for reference only)\r\n::  5th column = NoAct = activation is not working\r\n::  Separator  = _\r\n\r\nset f=\r\nset key=\r\nset eval=\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nfor %%# in (\r\nd9eea459-1e6b-499d-8486-e68163f2a8be_N3QJR-YCWKK-RVJGK-GQFMX-T8%f%2BF_EmbeddedIndustryEval_8.1\r\nfbd4c5c6-adc6-4740-bc65-b2dc6dc249c1_MJ8TN-42JH8-886MT-8THCF-36%f%67B_EnterpriseEval_8_NoAct_          REM New time based activation not available\r\n0eebbb45-29d4-49cb-ba87-a23db0cce40a_76FKW-8NR3K-QDH4P-3C87F-JH%f%TTW_EnterpriseEval_8.1\r\n3f4c0546-36c6-46a8-a37f-be13cdd0cf25_7HBDQ-QNKVG-K4RBF-HMBY6-YG%f%9R6_EnterpriseEval_10\r\n1f8dbfe8-defa-4676-b5a6-f76949a01540_4N8VT-7Y686-43DGV-THTW9-M9%f%8W7_EnterpriseNEval_10\r\n57a4ebb6-8e0c-41f8-b79e-8872ddc971ef_W63GF-7N4D9-GQH3K-K4FP7-9B%f%T6C_EnterpriseSEval_2015\r\nb47dd250-fd6a-44c8-9217-03aca6e4812e_N4DMT-RJKDQ-XR6H7-3DKKP-3Y%f%JWT_EnterpriseSEval_2016\r\n267bf82d-08e8-4046-b061-9ef3f8ac2b5a_N7HMH-MK36Q-M4X93-76KQ2-6J%f%HWR_EnterpriseSEval_2019\r\naff25f1f-fb53-4e27-95ef-b8e5aca10ac6_9V4NK-624Y3-VK47R-Q27GP-27%f%PGF_EnterpriseSEval_2021\r\n399f0697-886b-4881-894c-4ff6c52e7d8f_CYPB3-XNV9V-QR4G4-Q3B8K-KQ%f%FGJ_EnterpriseSEval_2024\r\n6162e8c2-3c30-46e1-b964-0de603498e2d_R34N9-HJ6Q3-GBX4F-Q24KQ-49%f%DF7_EnterpriseSNEval_2016\r\naed14fc8-907d-44fb-a3a1-d5d8e638acb3_MHN9Q-RD9PW-BFHDQ-9FTWQ-WQ%f%PF8_EnterpriseSNEval_2019\r\n5dd0c869-eae9-40ce-af48-736692cd8e43_XCN62-29X92-C4T8X-WP82X-DY%f%MJ8_EnterpriseSNEval_2021\r\n522cc0dc-3c7b-4258-ae68-f297ca63b64e_Y8DJM-NPXF3-QG4MH-W7WJK-KQ%f%FGM_EnterpriseSNEval_2024\r\naa708397-8618-42de-b120-a44190ef456d_R63DV-9NPDX-QVWJF-HMR8V-M4%f%K7D_IoTEnterpriseSEval_2024\r\ncd25b1e8-5839-4a96-a769-b6abe3aa5dee_73BMN-332G9-DX6B8-FGDT3-GF%f%YT6_ServerDatacenterEval_2012\r\ne628c5e8-2300-4429-8b80-a8b21bd7ce0a_WPR94-KN3J7-MRB7X-JPJV8-RX%f%7J2_ServerDatacenterEval_2012R2\r\n01398239-85ff-487f-9e90-0e3cc5bcc92e_QVTQ9-GNRBH-JQ9G7-W7FBW-RX%f%9QR_ServerDatacenterEval_2016\r\n5ea4af9e-fd59-4691-b61c-1fc1ff3e309e_KNW3G-22YD2-7QKQJ-2RF2X-H6%f%F8M_ServerDatacenterEval_2019\r\n1d02774d-66ab-4c57-8b14-e254fdce09d4_PK7JN-24236-FH7JP-V792F-37%f%CYR_ServerDatacenterEval_2021\r\n96794a98-097f-42fe-8f28-2c38ea115229_M4RNW-CRTHF-TY7BG-DDHG6-J2%f%T92_ServerDatacenterEval_2025\r\n38d172c7-36b3-4e4b-b435-fd0b06b95c6e_RNFGD-WFFQR-XQ8BG-K7QQK-GJ%f%CP9_ServerStandardEval_2012\r\n4fc45a88-26b5-4cf9-9eef-769ee3f0a016_79M8M-N36BX-8YGJY-2G9KP-3Y%f%GPC_ServerStandardEval_2012R2\r\n9dfa8ec0-7665-4b9d-b2cb-bfc2dc37c9f4_9PBKX-4NHGT-QWV4C-4JD94-TV%f%KQ6_ServerStandardEval_2016\r\n7783a126-c108-4cf7-b59f-13c78c7a7337_J4WNC-H9BG3-6XRX4-3XD8K-Y7%f%XRX_ServerStandardEval_2019\r\nc1a197b6-ba5e-4394-b9bf-b659a6c1b873_7PBJM-MNVPD-MBQD7-TYTY4-W8%f%JDY_ServerStandardEval_2021\r\n753c53a2-4274-4339-8c2e-f66c0b9646c5_YPBVM-HFNWQ-CTF9M-FR4RR-7H%f%9YG_ServerStandardEval_2025\r\n0de5ff31-2d62-4912-b1a8-3ea01d2461fd_3CKBN-3GJ8X-7YT4X-D8DDC-D6%f%69B_ServerStorageStandardEval_2012\r\nfb08f53a-e597-40dc-9f08-8bbf99f19b92_NCJ6J-J23VR-DBYB3-QQBJF-W8%f%CP7_ServerStorageWorkgroupEval_2012\r\n) do (\r\nfor /f \"tokens=1-5 delims=_\" %%A in (\"%%#\") do if %tsedition%==%%C if not defined key (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\nset key=%%B\r\nset eval=1\r\nif /i \"%%E\"==\"NoAct\" set noact=1\r\necho Checking Activation ID                  [%%A] [%%C]\r\n)\r\n)\r\n)\r\n\r\nif not defined key (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Activation ID                  [%tsedition% not found in the script]\"\r\ncall :dk_color %Blue% \"Make sure you are using the updated version of the script.\"\r\ngoto :ts_esu\r\n)\r\n\r\nset resetstuff=1\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':tsforge\\:.*';. ([scriptblock]::Create($f[1]))\"\r\nset resetstuff=\r\nif !errorlevel!==3 (\r\nset error=1\r\ncall :dk_color %Red% \"Resetting Rearm / GracePeriod           [Failed]\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ngoto :ts_esu\r\n) else (\r\necho Resetting Rearm / GracePeriod           [Successful]\r\n)\r\n\r\nset generickey=1\r\ncall :dk_inskey \"[%key%]\"\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_esu\r\n\r\nif not %_actesu%==1 goto :ts_off\r\nif /i %tsmethod%==KMS4k (\r\ncall :dk_color %Red% \"Skipping Windows ESU                    [KMS4k method is not supported with Windows ESU]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\ngoto :ts_off\r\n)\r\n\r\n::  Process Windows ESU\r\n\r\necho:\r\necho Processing Windows ESU...\r\n\r\nset esuexist=\r\nset esuexistsup=\r\nset esueditionlist=\r\nset esuexistbutnosup=\r\n\r\nfor %%# in (EnterpriseS IoTEnterpriseS IoTEnterpriseSK) do (if /i %tsedition%==%%# set isltsc=1)\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" set isServer=1\r\n\r\nif /i %tsedition%==Embedded (\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\WinEmb-Branding-Embedded-ThinPC-Package*.mum\" set isThinpc=1\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\WinEmb-Branding-Embedded-POSReady7-Package*.mum\" set subEdition=[POS]\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\WinEmb-Branding-Embedded-Standard-Package*.mum\" set subEdition=[Standard]\r\n)\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nset w10EsuEditions=Education-EducationN-Enterprise-EnterpriseN-Professional-ProfessionalEducation-ProfessionalEducationN-ProfessionalN-ProfessionalWorkstation-ProfessionalWorkstationN\r\n\r\nset minbuild=0\r\nif /i %tsedition%==ServerRdsh set minbuild=5552\r\nfor %%# in (Core CoreN CoreCountrySpecific CoreSingleLanguage IoTEnterprise) do (if /i %tsedition%==%%# set minbuild=6156)\r\nif /i %tsedition%==PPIPro set minbuild=6388\r\n\r\nset /a UBR=0\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR %nul6%') do if not errorlevel 1 set /a UBR=%%b\r\nif %winbuild% EQU 19045 if %minbuild% GTR 0 if %UBR% GEQ %minbuild% (\r\nset w10EsuEditionsLaterAdded=%tsedition%-\r\n)\r\n\r\nif not defined isThinpc if not defined isltsc for %%# in (\r\nREM Windows7\r\n4220f546-f522-46df-8202-4d07afd26454_Client-ESU-Year3[1-3y]_-Enterprise-EnterpriseE-EnterpriseN-Professional-ProfessionalE-ProfessionalN-Ultimate-UltimateE-UltimateN-\r\n7e94be23-b161-4956-a682-146ab291774c_Client-ESU-Year6[4-6y]_-Enterprise-EnterpriseE-EnterpriseN-Professional-ProfessionalE-ProfessionalN-Ultimate-UltimateE-UltimateN-\r\nREM Windows7EmbeddedPOSReady7\r\n4f1f646c-1e66-4908-acc7-d1606229b29e_POS-ESU-Year3[1-3y]_-Embedded[POS]-\r\nREM Windows7EmbeddedStandard\r\n6aaf1c7d-527f-4ed5-b908-9fc039dfc654_WES-ESU-Year3[1-3y]_-Embedded[Standard]-\r\nREM WindowsServer2008/WindowsServer2008R2\r\n8e7bfb1e-acc1-4f56-abae-b80fce56cd4b_Server-ESU-PA[1-6y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-ServerEnterprise-ServerEnterpriseCore-ServerEnterpriseV-ServerEnterpriseVCore-\r\nREM Windows8.1\r\n4afc620f-12a4-48ad-8015-2aebfbd6e47c_Client-ESU-Year3[1-3y]_-Enterprise-EnterpriseN-Professional-ProfessionalN-\r\n11be7019-a309-4763-9a09-091d1722ffe3_Client-FES-ESU-Year3[1-3y]_-EmbeddedIndustry-EmbeddedIndustryE-\r\nREM WindowsServer2012/2012R2\r\n55b1dd2d-2209-4ea0-a805-06298bad25b3_Server-ESU-Year3[1-3y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-\r\nREM Windows10\r\nf520e45e-7413-4a34-a497-d2765967d094_Client-ESU-Year1_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%\r\n1043add5-23b1-4afb-9a0f-64343c8f3f8d_Client-ESU-Year2_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%\r\n83d49986-add3-41d7-ba33-87c7bfb5c0fb_Client-ESU-Year3_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%\r\n0b533b5e-08b6-44f9-b885-c2de291ba456_Client-ESU-Year6[4-6y]_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%\r\nREM WindowsServer2016\r\n91bcac0a-d7d3-4d2b-bd0c-72fed675f01b_Server-ESU-Year3[1-3y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-\r\n4cd0ab30-73a4-4dde-972c-512f05be31df_Server-ESU-Year6[4-6y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-\r\n) do (\r\nfor /f \"tokens=1-3 delims=_\" %%A in (\"%%#\") do (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\nset esuexist=1\r\necho \"%%C\" | find /i \"-%tsedition%%subEdition%-\" %nul1% && (\r\nset esuexistsup=1\r\nset esueditionlist=\r\nset esuexistbutnosup=\r\nset tsids=!tsids! %%A\r\necho Checking Activation ID                  [%%A] [%%B]\r\n) || (\r\nif not defined esueditionlist set esueditionlist=%%C\r\nset esuexistbutnosup=1\r\n)\r\n)\r\n)\r\n)\r\n\r\nif defined esuexistsup if defined _vis (\r\nset key=9FPV7-MWGT8-7XPDF-JC23W-WT7TW\r\nREM This is a non-generic blocked MAK key for Server-ESU-PA\r\ncall :dk_inskey \"[!key!]\"\r\ngoto :ts_off\r\n)\r\n\r\nif defined esuexistsup (\r\necho \"%tsids%\" | find /i \"4220f546-f522-46df-8202-4d07afd26454\" %nul1% && (\r\necho \"%tsids%\" | find /i \"7e94be23-b161-4956-a682-146ab291774c\" %nul1% || (\r\ncall :dk_color %Gray% \"To get Client-ESU-Year6[4-6y] license, install updates from the below URL.\"\r\ncall :dk_color %Blue% \"%mas%tsforge#windows-esu\"\r\n)\r\n)\r\ngoto :ts_off\r\n)\r\n\r\nif defined isltsc (\r\ncall :dk_color %Gray% \"Checking Activation ID                  [%tsedition% LTSC already has longer support, ESU is not applicable]\"\r\ngoto :ts_off\r\n)\r\n\r\nif defined esuexistbutnosup (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Currently installed ESU License is not supported for %tsedition%]\"\r\necho:\r\nif %winbuild% EQU 19045 if not defined w10EsuEditionsLaterAdded (\r\ncall :dk_color %Blue% \"To get latest version, go to Windows settings and run Windows Update. After that, try the script again.\"\r\ngoto :ts_off\r\n)\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Change Windows Edition option and change to any of the below listed editions.\"\r\necho [%esueditionlist%]\r\ngoto :ts_off\r\n)\r\n\r\nset esuavail=\r\nif defined _vis if defined isServer set esuavail=1\r\nif %winbuild% LEQ 7602 if not defined _vis if not defined isThinpc set esuavail=1\r\nif %winbuild% GTR 7602 if %winbuild% LEQ 14393 if defined isServer set esuavail=1\r\nif %winbuild% GEQ 10240 if %winbuild% LEQ 19045 if not defined isServer set esuavail=1\r\nif %winbuild% EQU 9600 set esuavail=1\r\n\r\nif defined esuavail (\r\ncall :dk_color %Red% \"Checking Activation ID                  [ESU license is not found, make sure Windows is fully updated]\"\r\nset fixes=%fixes% %mas%tsforge#windows-esu\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%tsforge#windows-esu\"\r\n) else (\r\ncall :dk_color %Gray% \"Checking Activation ID                  [ESU is not available for %winos%]\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_off\r\n\r\nif not %_actoff%==1 goto :ts_act\r\n\r\nif %winbuild% LSS 9200 (\r\necho:\r\ncall :dk_color %Gray% \"Checking Supported Office               [TSforge for Office is supported on Windows 8 and later versions]\"\r\ncall :dk_color %Blue% \"On Windows Vista / 7, use Ohook activation option for Office instead.\"\r\ngoto :ts_act\r\n)\r\n\r\n::  Check ohook install\r\n\r\nset ohook=\r\nfor %%# in (15 16) do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft Office\\Office%%#\\sppc*dll\" set ohook=1\r\n)\r\n)\r\n\r\nfor %%# in (System SystemX86) do (\r\nfor %%G in (\"Office 15\" \"Office\") do (\r\nfor %%A in (\"%ProgramFiles%\" \"%ProgramW6432%\" \"%ProgramFiles(x86)%\") do (\r\nif exist \"%%~A\\Microsoft %%~G\\root\\vfs\\%%#\\sppc*dll\" set ohook=1\r\n)\r\n)\r\n)\r\n\r\nif defined ohook (\r\necho:\r\ncall :dk_color %Gray% \"Checking Ohook                          [Ohook activation is already installed for Office]\"\r\n)\r\n\r\n::  Check unsupported office versions\r\n\r\nset o14msi=\r\nset o14c2r=\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=Office 2010 MSI )\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o14msi=Office 2010 MSI )\r\n%nul% reg query %_68%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n%nul% reg query %_86%\\14.0\\CVH /f Click2run /k         && set o14c2r=Office 2010 C2R \r\n\r\nif not \"%o14msi%%o14c2r%\"==\"\" (\r\necho:\r\ncall :dk_color %Red% \"Checking Unsupported Office Install     [ %o14msi%%o14c2r%]\"\r\nif defined o14msi call :dk_color %Blue% \"Use Ohook activation option for Office 2010.\"\r\n)\r\n\r\nif %winbuild% GEQ 10240 %psc% \"Get-AppxPackage -name \"Microsoft.MicrosoftOfficeHub\"\" | find /i \"Office\" %nul1% && (\r\nset ohub=1\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check supported office versions\r\n\r\ncall :ts_getpath\r\n\r\nset o16uwp=\r\nset o16uwp_path=\r\n\r\nif %winbuild% GEQ 10240 (\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty InstallLocation)\" %nul6%') do (if exist \"%%a\\Integration\\Integrator.exe\" (set o16uwp=1&set \"o16uwp_path=%%a\"))\r\n)\r\n\r\nsc query ClickToRunSvc %nul%\r\nset error1=%errorlevel%\r\n\r\nif defined o16c2r if %error1% EQU 1060 (\r\necho:\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 16.0 files found]\"\r\nset o16c2r=\r\nset error=1\r\n)\r\n\r\nsc query OfficeSvc %nul%\r\nset error2=%errorlevel%\r\n\r\nif defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (\r\necho:\r\ncall :dk_color %Red% \"Checking ClickToRun Service             [Not found, Office 15.0 files found]\"\r\nset o15c2r=\r\nset error=1\r\n)\r\n\r\nif \"%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%\"==\"\" (\r\nset error=1\r\nset showfix=1\r\necho:\r\nif not \"%o14msi%%o14c2r%\"==\"\" (\r\ncall :dk_color %Red% \"Checking Supported Office Install       [Not Found]\"\r\n) else (\r\nif %_actwin%==0 (\r\ncall :dk_color %Red% \"Checking Installed Office               [Not Found]\"\r\n) else (\r\ncall :dk_color %Gray% \"Checking Installed Office               [Not Found]\"\r\n)\r\n)\r\n\r\nif defined ohub (\r\necho:\r\necho You only have the Office Dashboard app installed; you need to install the full version of Office.\r\n)\r\ncall :dk_color %Blue% \"Download and install Office from the URL below, then try again.\"\r\nif %_actwin%==0 set fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto :ts_act\r\n)\r\n\r\nset multioffice=\r\nif not \"%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%\"==\"1\" set multioffice=1\r\nif not \"%o14c2r%%o14msi%\"==\"\" set multioffice=1\r\n\r\nif defined multioffice (\r\necho:\r\ncall :dk_color %Gray% \"Checking Multiple Office Install        [Found. Recommended to install one version only]\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Windows Server\r\n\r\nset winserver=\r\nreg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions\" /v ProductType %nul2% | find /i \"WinNT\" %nul1% || set winserver=1\r\nif not defined winserver (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Server\" %nul1% && set winserver=1\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Process Office UWP\r\n\r\nif not defined o16uwp goto :ts_starto15c2r\r\n\r\ncall :ts_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=16\r\nset \"_oLPath=%o16uwp_path%\\Licenses16\"\r\nset \"pkeypath=%o16uwp_path%\\Office16\\pkeyconfig-office.xrm-ms\"\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty Dependencies) | Select-Object PackageFullName\" %nul6%') do (set \"o16uwpapplist=!o16uwpapplist! %%a\")\r\n\r\necho \"%o16uwpapplist%\" | findstr /i \"Access Excel OneNote Outlook PowerPoint Publisher SkypeForBusiness Word\" %nul% && set \"_oIds=O365HomePremRetail\"\r\n\r\nfor %%# in (Project Visio) do (\r\necho \"%o16uwpapplist%\" | findstr /i \"%%#\" %nul% && (\r\nset _lat=\r\nif exist \"%_oLPath%\\%%#Pro2024VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2024Retail \" & set _lat=1\r\nif not defined _lat if exist \"%_oLPath%\\%%#Pro2021VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2021Retail \" & set _lat=1\r\nif not defined _lat if exist \"%_oLPath%\\%%#Pro2019VL*.xrm-ms\" set \"_oIds= !_oIds! %%#Pro2019Retail \" & set _lat=1\r\nif not defined _lat set \"_oIds= !_oIds! %%#ProRetail \"\r\n)\r\n)\r\n\r\nset uwpinfo=%o16uwp_path:C:\\Program Files\\WindowsApps\\Microsoft.Office.Desktop_=%\r\n\r\necho:\r\necho Processing Office...                    [UWP ^| %uwpinfo%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ts_starto15c2r\r\n)\r\n\r\ncall :ts_process\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_starto15c2r\r\n\r\n::  Process Office 15.0 C2R\r\n\r\nif not defined o15c2r goto :ts_starto16c2r\r\n\r\ncall :ts_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=15\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o15c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o15c2r_reg%\\Configuration\")\r\nif not defined _oArch   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nif not defined _version for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v version\" %nul6%') do (set \"_version=%%b\")\r\nif not defined _prids   for /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o15c2r_reg%\\propertyBag /v ProductReleaseId\" %nul6%') do (set \"_prids=%o15c2r_reg%\\propertyBag /v ProductReleaseId\" & set \"_config=%o15c2r_reg%\\propertyBag\")\r\n\r\necho \"%o15c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=10) || (set _tok=9)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query %o15c2r_reg%\\ProductReleaseIDs\\Active %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses\"\r\nset \"pkeypath=%_oRoot%\\Office15\\pkeyconfig-office.xrm-ms\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\necho:\r\necho Processing Office...                    [C2R ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ts_starto16c2r\r\n)\r\n\r\ncall :oh_expiredpreview 2013\r\nif \"%_actprojvis%\"==\"0\" call :oh_fixprids\r\ncall :ts_process\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_starto16c2r\r\n\r\n::  Process Office 16.0 C2R\r\n\r\nif not defined o16c2r goto :ts_startmsi\r\n\r\ncall :ts_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset oVer=16\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v AudienceData\" %nul6%') do (set \"_AudienceData=^| %%b \")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ProductReleaseIds\" %nul6%') do (set \"_prids=%o16c2r_reg%\\Configuration /v ProductReleaseIds\" & set \"_config=%o16c2r_reg%\\Configuration\")\r\n\r\necho \"%o16c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=9) || (set _tok=8)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query \"%o16c2r_reg%\\ProductReleaseIDs\" /s /f \".16\" /k %nul6% ^| findstr /i \"Retail Volume\"') do (\r\necho \"!_oIds!\" | find /i \" %%a \" %nul1% || (set \"_oIds= !_oIds! %%a \")\r\n)\r\nset _oIds=%_oIds:.16=%\r\nset _o16c2rIds=%_oIds%\r\n\r\nset \"_oLPath=%_oRoot%\\Licenses16\"\r\nset \"pkeypath=%_oRoot%\\Office16\\pkeyconfig-office.xrm-ms\"\r\nset \"_oIntegrator=%_oRoot%\\integration\\integrator.exe\"\r\n\r\necho:\r\necho Processing Office...                    [C2R ^| %_version% %_AudienceData%^| %_oArch%]\r\n\r\nif not defined _oIds (\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nset error=1\r\ngoto :ts_startmsi\r\n)\r\n\r\ncall :oh_expiredpreview 2016 2019 2021 2024\r\nif \"%_actprojvis%\"==\"0\" call :oh_fixprids\r\ncall :ts_process\r\n\r\n::========================================================================================================================================\r\n\r\n::  mass{}grave{dot}dev/office-license-is-not-genuine\r\n::  Add registry keys for volume products so that 'non-genuine' banner won't appear \r\n\r\nset \"kmskey=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\0ff1ce15-a989-479d-af46-f275c6370663\"\r\nif /i %tsmethod%==KMS4k (\r\nif %winbuild% GEQ 9200 (\r\nif not \"%osarch%\"==\"x86\" (\r\nreg delete \"%kmskey%\" /f /reg:32 %nul%\r\nreg add \"%kmskey%\" /f /v KeyManagementServiceName /t REG_SZ /d \"10.0.0.10\" /reg:32 %nul%\r\n)\r\nreg delete \"%kmskey%\" /f %nul%\r\nreg add \"%kmskey%\" /f /v KeyManagementServiceName /t REG_SZ /d \"10.0.0.10\" %nul%\r\necho Adding a Registry to Prevent Banner     [Successful]\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_startmsi\r\n\r\nif defined o15msi call :ts_processmsi 15 %o15msi_reg%\r\nif defined o16msi call :ts_processmsi 16 %o16msi_reg%\r\n\r\n::========================================================================================================================================\r\n\r\necho:\r\ncall :oh_clearblock\r\nif \"%o16msi%%o15msi%\"==\"\" if not \"%o16uwp%%o16c2r%%o15c2r%\"==\"\" call :oh_uninstkey\r\ncall :oh_licrefresh\r\n\r\ngoto :ts_act\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_whost\r\n\r\n::  Process Windows K-M-S host\r\n\r\necho:\r\necho Processing Windows %KS% Host...\r\n\r\nif /i %tsmethod%==KMS4k (\r\necho:\r\ncall :dk_color %Red% \"Skipping Windows %KS% Host               [KMS4k method is not supported with Windows %KS% Host]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\ngoto :ts_act\r\n)\r\n\r\necho:\r\nif %winbuild% GEQ 10586 (\r\ncall :dk_color %Gray% \"With %KS% Host license, system may randomly change Windows Edition later. It is a Windows issue and can be safely ignored.\"\r\n)\r\ncall :dk_color %Gray% \"%KS% Host [Not to be confused with %KS% Client] license causes the %_slser% service to run continuously.\"\r\ncall :dk_color %Blue% \"Only use this activation when necessary, you can revert to normal activation from the previous menu.\"\r\n\r\nif %_unattended%==0 (\r\necho:\r\nchoice /C:0F /N /M \"> [0] Go back  [F] Continue : \"\r\nif !errorlevel!==1 exit /b\r\necho:\r\n)\r\n\r\nset _arr=\r\nset tempid=\r\nset keytype=kmshost\r\n\r\nif defined _vis goto :ts_whost_vista\r\n\r\n::  Install current edition csvlk license so that correct edition can reflect for csvlk\r\n\r\nif %winbuild% GEQ 10586 (\r\nfor %%# in (\"%SysPath%\\spp\\tokens\\skus\\%tsedition%\\*CSVLK*.xrm-ms\") do (\r\nif defined _arr (set \"_arr=!_arr!;\"%SysPath%\\spp\\tokens\\skus\\%tsedition%\\%%~nx#\"\") else (set \"_arr=\"%SysPath%\\spp\\tokens\\skus\\%tsedition%\\%%~nx#\"\")\r\n)\r\nif defined _arr %psc% \"$sls = Get-WmiObject %sps%; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); InstallLicenseArr '!_arr!'\" %nul%\r\n)\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wintsid\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (\r\necho \"%%a\" | findstr /r \".*-.*-.*-.*-.*\" %nul1% && (set tsids=!tsids! %%a& set tempid=%%a)\r\n)\r\n\r\nif defined tempid (\r\necho Checking Activation ID                  [%tempid%] [%tsedition%]\r\n) else (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Not Found] [%tsedition%] [%osSKU%]\"\r\ncall :dk_color %Blue% \"%KS% Host license is not found on your system. It is available for the below editions.\"\r\ncall :dk_color %Blue% \"Professional, Education, ProfessionalWorkstation, Enterprise, EnterpriseS, and Server editions, etc.\"\r\ngoto :ts_act\r\n)\r\n\r\nif defined winsub (\r\necho:\r\ncall :dk_color %Blue% \"Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%].\"\r\n)\r\n\r\ngoto :ts_act\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_whost_vista\r\n\r\n::  Process Windows K-M-S host for Vista\r\n\r\n::  1st column = Activation ID\r\n::  2nd column = CSVLK key\r\n::  3rd column = Edition IDs\r\n::  Separator  = _\r\n\r\nset f=\r\nset key=\r\nset tempid=\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nfor %%# in (\r\n::  WindowsVista\r\n212a64dc-43b1-4d3d-a30c-2fc69d2095c6_TWVG3-9Q4P8-W9XJF-Y76FJ-DW%f%Q4R_-Business-BusinessN-Enterprise-EnterpriseN-\r\n::  WindowsServer2008\r\nc90d1b4e-8aa8-439e-8b9e-b6d6b6a6d975_BHC4Q-6D7B7-QMVH7-4MKQH-Y9%f%VK7_-ServerComputeCluster-ServerDatacenter-ServerDatacenterV-ServerEnterprise-ServerEnterpriseIA64-ServerEnterpriseV-ServerStandard-ServerStandardV-ServerWeb-\r\n56df4151-1f9f-41bf-acaa-2941c071872b_PVGKG-2R7XQ-7WTFD-FXTJR-DQ%f%BQ3_-ServerComputeCluster-ServerEnterprise-ServerEnterpriseV-ServerStandard-ServerStandardV-ServerWeb-\r\nc448fa06-49d1-44ec-82bb-0085545c3b51_KH4PC-KJFX6-XFVHQ-GDK2G-JC%f%JY9_-ServerComputeCluster-ServerWeb-\r\n) do (\r\nfor /f \"tokens=1-3 delims=_\" %%A in (\"%%#\") do if not defined key (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\necho \"%%C\" | find /i \"-%tsedition%-\" %nul1% && (\r\nset key=%%B\r\nset tempid=%%A\r\n)\r\n)\r\n)\r\n)\r\n\r\nif defined key (\r\necho Checking Activation ID                  [%tempid%] [%tsedition%]\r\n) else (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Not Found] [%tsedition%] [%osSKU%]\"\r\ncall :dk_color %Blue% \"%KS% Host license is not found on your system. It is available for the below editions.\"\r\ncall :dk_color %Blue% \"Business, BusinessN, Enterprise, EnterpriseN, and Server editions, etc.\"\r\ngoto :ts_act\r\n)\r\n\r\ncall :dk_inskey \"[%key%]\"\r\nset tsids=%tsids% %tempid%\r\ngoto :ts_act\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_ohost\r\n\r\n::  Process Office K-M-S host\r\n\r\necho:\r\necho Processing Office %KS% Host...\r\n\r\nif defined _vis (\r\necho:\r\ncall :dk_color %Blue% \"Windows Vista and Server 2008 do not support the installation of Office KMS Host.\"\r\ngoto :ts_act\r\n)\r\n\r\nif /i %tsmethod%==KMS4k (\r\necho:\r\ncall :dk_color %Red% \"Skipping Office %KS% Host                [KMS4k method is not supported with Office %KS% Host]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\ngoto :ts_act\r\n)\r\n\r\nset ohostexist=\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\nset ohostids=%allapps%\r\ncall :dk_actids 59a52881-a989-479d-af46-f275c6370663\r\nset ohostids=%ohostids% %allapps%\r\n\r\nfor %%# in (\r\nbfe7a195-4f8f-4f0b-a622-cf13c7d16864_KMSHost2010-ProPlusVL\r\nf3d89bbf-c0ec-47ce-a8fa-e5a5f97e447f_KMSHost2024Volume\r\n47f3b983-7c53-4d45-abc6-bcd91e2dd90a_KMSHost2021Volume\r\n70512334-47b4-44db-a233-be5ea33b914c_KMSHost2019Volume\r\n98ebfe73-2084-4c97-932c-c0cd1643bea7_KMSHost2016Volume\r\n2e28138a-847f-42bc-9752-61b03fff33cd_KMSHost2013Volume\r\n) do (\r\nfor /f \"tokens=1-2 delims=_\" %%A in (\"%%#\") do (\r\necho \"%ohostids%\" | find /i \"%%A\" %nul1% && (\r\nset ohostexist=1\r\nset tsids=!tsids! %%A\r\necho Checking Activation ID                  [%%A] [%%B]\r\n)\r\n)\r\n)\r\n\r\nif not defined ohostexist (\r\ncall :dk_color %Gray% \"Checking Activation ID                  [Not found for Office %KS% Host]\"\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%tsforge#office-kms-host\"\r\n)\r\n\r\necho:\r\ncall :dk_color %Gray% \"%KS% Host [Not to be confused with %KS% Client] license causes the sppsvc service to run continuously.\"\r\ncall :dk_color %Gray% \"Only use this activation when necessary.\"\r\n\r\ngoto :ts_act\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_appxlob\r\n\r\n::  Process Windows 8/8.1 APPX Sideloading\r\n\r\necho:\r\necho Processing Windows 8/8.1 APPX Sideloading...\r\n\r\nif %winbuild% LSS 9200 set noappx=1\r\nif %winbuild% GTR 9600 set noappx=1\r\n\r\necho:\r\nif defined noappx (\r\ncall :dk_color %Gray% \"Checking Activation ID                  [APPX Sideloading feature is available only on Windows 8/8.1]\"\r\ngoto :dk_done\r\n)\r\n\r\nif /i %tsmethod%==KMS4k (\r\necho:\r\ncall :dk_color %Red% \"Skipping Windows 8/8.1 APPX             [KMS4k method is not supported with Windows 8/8.1 APPX]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\ngoto :dk_done\r\n)\r\n\r\nset appxexist=\r\nif not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nfor %%# in (\r\nec67814b-30e6-4a50-bf7b-d55daf729d1e_APPXLOB-Client\r\n251ef9bf-2005-442f-94c4-86307de7bb32_APPXLOB-Embedded-Industry\r\n1e58c9d7-e3f1-4f69-9039-1f162463ac2c_APPXLOB-Embedded-Standard\r\n3502d53e-5d43-436a-84af-714e8d334f8d_APPXLOB-Server\r\n) do (\r\nfor /f \"tokens=1-2 delims=_\" %%A in (\"%%#\") do (\r\necho \"%allapps%\" | find /i \"%%A\" %nul1% && (\r\nset appxexist=1\r\nset tsids=!tsids! %%A\r\necho Checking Activation ID                  [%%A] [%%B]\r\n)\r\n)\r\n)\r\n\r\nif not defined appxexist (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Not found]\"\r\ncall :dk_color %Blue% \"APPX Sideloading feature is available only on Pro and higher level editions.\"\r\n)\r\n\r\ngoto :ts_act\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_resetall\r\n\r\necho:\r\nif defined _vis (\r\necho Processing Reset of Rearm / Timers...\r\n) else (\r\necho Processing Reset of Rearm / Timers / Tamper / Lock...\r\n)\r\necho:\r\n\r\nset resetstuff=1\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':tsforge\\:.*';. ([scriptblock]::Create($f[1]))\"\r\n\r\nif %errorlevel%==3 (\r\ncall :dk_color %Red% \"Reset Failed.\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n) else (\r\ncall :dk_color %Green% \"Reset process has been successfully done.\"\r\n)\r\n\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_actman\r\n\r\necho:\r\necho Processing Manual Activation...\r\necho:\r\n\r\nif /i %tsmethod%==KMS4k (\r\necho:\r\ncall :dk_color %Red% \"Skipping Manual Activation              [KMS4k method is not supported with it]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\ngoto :dk_done\r\n)\r\n\r\ncall :dk_color %Gray% \"This option is for advanced users, those who already know what they are doing.\"\r\ncall :dk_color %Blue% \"Some activation IDs may cause system crash [MUI mismatch], or irreversible changes [CloudEdition etc].\"\r\n\r\nif %_unattended%==1 (\r\necho:\r\nfor %%# in (%tsids%) do (echo Activation ID - %%#)\r\ngoto :ts_act\r\n)\r\n\r\ncall :dk_color %Blue% \"Although the script will try to remove those IDs from the list, it is not fully guaranteed.\"\r\necho:\r\nchoice /C:0F /N /M \"> [0] Go back  [F] Continue : \"\r\nif %errorlevel%==1 exit /b\r\n\r\necho:\r\necho Fetching Supported Activation IDs list. Please wait...\r\n\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':listactids\\:.*';. ([scriptblock]::Create($f[1]))\"\r\nif %errorlevel%==3 (\r\ncall :dk_color %Gray% \"No supported activation ID found, aborting...\"\r\ngoto :dk_done\r\n)\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"$ids = Get-WmiObject -Query 'SELECT ID FROM SoftwareLicensingProduct' | Select-Object -ExpandProperty ID; $ids\" %nul6%') do call set \"allactids= %%a !allactids! \"\r\n\r\nif defined _vis (\r\necho:\r\ncall :dk_color %Blue% \"On Windows Vista and Server 2008, you must manually install the key before activating it.\"\r\n)\r\necho:\r\ncall :dk_color %Gray% \"Enter / Paste the Activation ID shown in first column in the opened text file, or just press Enter to return:\"\r\necho Add space after each Activation ID if you are adding multiple:\r\necho:\r\nset /p tsids=\r\n\r\ndel /f /q \"%SystemRoot%\\Temp\\actids_159_*\" %nul%\r\nif not defined tsids goto :dk_done\r\n\r\nfor %%# in (%tsids%) do (\r\necho \"%allactids%\" | find /i \" %%# \" %nul1% || (\r\ncall :dk_color %Red% \"[%%#] Incorrect Activation ID entered, aborting...\"\r\ngoto :dk_done\r\n)\r\n)\r\n\r\ngoto :ts_act\r\n\r\n:listactids:\r\n$t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)\r\n$t.DefinePInvokeMethod('SLOpen', 'slc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n$t.DefinePInvokeMethod('SLClose', 'slc.dll', 22, 1, [IntPtr], @([IntPtr]), 1, 3).SetImplementationFlags(128)\r\n$t.DefinePInvokeMethod('SLGetProductSkuInformation', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n$t.DefinePInvokeMethod('SLGetLicense', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n$w = $t.CreateType()\r\n$m = [Runtime.InteropServices.Marshal]\r\n\r\nfunction slGetSkuInfo($SkuId) {\r\n    $c = 0; $b = 0\r\n    $r = $w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, \"msft:sl/EUL/PHONE/PUBLIC\", [ref]$null, [ref]$c, [ref]$b)\r\n    return ($r -eq 0)\r\n}\r\n\r\nfunction IsMuiNotLocked($SkuId) {\r\n    $r = $true; $c = 0; $b = 0\r\n\r\n    $LicId = [Guid]::Empty\r\n    [void]$w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, \"fileId\", [ref]$null, [ref]$c, [ref]$b)\r\n    $FileId = $m::PtrToStringUni($b)\r\n\r\n    $c = 0; $b = 0\r\n    [void]$w::SLGetLicense($hSLC, [ref][Guid]$FileId, [ref]$c, [ref]$b)\r\n    $blob = New-Object byte[] $c; $m::Copy($b, $blob, 0, $c)\r\n    $cont = [Text.Encoding]::UTF8.GetString($blob)\r\n    $xml = [xml]$cont.SubString($cont.IndexOf('<r'))\r\n\r\n    $xml.licenseGroup.license[0].grant | foreach {\r\n        $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Kernel-MUI-Language-Allowed' } | foreach {\r\n            if ($_.InnerText -ne 'EMPTY') { $r = $false }\r\n        }\r\n    }\r\n    return $r\r\n}\r\n\r\n$hSLC = 0; [void]$w::SLOpen([ref]$hSLC)\r\n$results = Get-WmiObject -Query \"SELECT ID, Name, Description FROM SoftwareLicensingProduct\"\r\n$maxNameWidth = 60\r\n\r\n$filteredResults = $results | Where-Object {\r\n    if ($env:tsedition -like \"*CountrySpecific*\") {\r\n        $true\r\n    }\r\n    else {\r\n        $_.Name -like \"*ESU*\" -or $_.Name -notlike \"*CountrySpecific*\"\r\n    }\r\n} | Where-Object {\r\n    if ($env:tsedition -like \"*CloudEdition*\") {\r\n        $true\r\n    }\r\n    else {\r\n        $_.Name -like \"*ESU*\" -or $_.Name -notlike \"*CloudEdition*\"\r\n    }\r\n} | Where-Object {\r\n    $_.Name -like \"*CountrySpecific*\" -or (IsMuiNotLocked $_.ID)\r\n} | Where-Object {\r\n    slGetSkuInfo $_.ID\r\n} | ForEach-Object {\r\n    \"$($_.ID)`t$($_.Name.PadRight($maxNameWidth))`t$($_.Description)\"\r\n}\r\n\r\n[void]$w::SLClose($hSLC)\r\nif (-not $filteredResults) {\r\n    Exit 3\r\n}\r\n\r\n$sortedResults = $filteredResults | Sort-Object { $_.Split(\"`t\")[1].Trim() }\r\n$output = $sortedResults -join \"`r`n\"\r\n$newGuid = [Guid]::NewGuid().Guid\r\n$filename = \"$env:SystemRoot\\Temp\\actids_159_$newGuid.txt\"\r\n$output | Set-Content -Path $filename -Encoding ASCII\r\nStart-Process notepad.exe $filename\r\n:listactids:\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_act\r\n\r\nif defined eval (\r\necho:\r\necho Activating...\r\necho:\r\ncall :dk_act\r\n\r\nset gpr=0\r\nset gprdays=0\r\nset actdone=\r\nfor /f \"delims=\" %%a in ('%psc% \"(Get-WmiObject -Query 'SELECT GracePeriodRemaining FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').GracePeriodRemaining\" %nul6%') do set \"gpr=%%a\"\r\nset /a \"gprdays=(!gpr!+1440-1)/1440\"\r\n\r\nif !gprdays! EQU 90 set actdone=1\r\nif !gprdays! EQU 180 set actdone=1\r\n\r\nif defined actdone (\r\ncall :dk_color %Green% \"[%winos%] has been reset and activated successfully for !gprdays! days.\"\r\n) else (\r\nset error=1\r\nset showfix=1\r\ncall :dk_color %Red% \"[%winos%] Activation Failed %error_code%. Remaining Period: !gprdays! days [!gpr! minutes].\"\r\nif not defined noact (\r\ncall :dk_color %Gray% \"To activate, check your internet connection and ensure the date and time are correct.\"\r\n) else (\r\ncall :dk_color %Blue% \"This Windows version is known to not activate due to MS Windows/Server issues.\"\r\n)\r\nif not defined showfix call :dk_color %Blue% \"%_fixmsg%\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n)\r\n\r\nif defined tsids (\r\necho:\r\nif not defined _vis if not defined oldks echo Installing Forged Product Key Data...\r\nif /i %tsmethod%==KMS4k (\r\necho Writing TrustedStore data...\r\n) else (\r\nif /i %tsmethod%==StaticCID (echo Depositing Static Confirmation ID...) else (echo Depositing Zero Confirmation ID...)\r\n)\r\necho:\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':tsforge\\:.*';. ([scriptblock]::Create($f[1])) %tsids%\"\r\nif !errorlevel!==3 (\r\nif %_actman%==0 (if not defined showfix call :dk_color %Blue% \"%_fixmsg%\")\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n) else (\r\nif /i %tsmethod%==KMS4k if %winbuild% GEQ 26100 (\r\necho:\r\ncall :dk_color %Gray% \"In Windows settings, you may see a renewal notification for activation that can be ignored.\"\r\nif /i %_actmethod%==Auto call :dk_color %Gray% \"To avoid this notification, run the script with an internet connection to use the StaticCID method.\"\r\n)\r\necho \"%tsids%\" | find /i \"7e94be23-b161-4956-a682-146ab291774c\" %nul1% && (\r\ncall :dk_color %Gray% \"Windows Update gets 1-3 years of ESU; 4-6 are unofficial but let you install Server 2008 R2 updates manually.\"\r\n)\r\necho \"%tsids%\" | findstr /i \"4afc620f-12a4-48ad-8015-2aebfbd6e47c 11be7019-a309-4763-9a09-091d1722ffe3\" %nul1% && (\r\ncall :dk_color %Gray% \"ESU is not officially supported on Windows 8.1, but updates can be installed manually until January 2024.\"\r\n)\r\necho \"%tsids%\" | findstr /i \"83d49986-add3-41d7-ba33-87c7bfb5c0fb 0b533b5e-08b6-44f9-b885-c2de291ba456\" %nul1% && (\r\ncall :dk_color %Gray% \"Windows Update gets 1-3 years of ESU; 4-6 are unofficial but may let you install LTSC updates manually.\"\r\nif exist %SysPath%\\ClipESUConsumer.exe (%SysPath%\\ClipESUConsumer.exe -evaluateEligibility)\r\nif exist %SysPath%\\ClipESU.exe (%SysPath%\\ClipESU.exe %nul%)\r\n)\r\n)\r\n\r\nif defined esuexistsup echo Help: %mas%tsforge#windows-esu\r\n\r\nif %_actwin%==1 for %%# in (407) do if %osSKU%==%%# (\r\ncall :dk_color %Red% \"%winos% does not support activation on non-azure platforms.\"\r\n)\r\n\r\nif %_actoff%==1 if not defined error if defined ohub (\r\necho:\r\ncall :dk_color %Gray% \"Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app.\"\r\n)\r\n\r\nREM Trigger reevaluation of SPP's Scheduled Tasks\r\ncall :dk_reeval %nul%\r\n)\r\n\r\nif not defined tsids if defined error if not defined showfix (\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_remove\r\n\r\ncls\r\nif not defined terminal (\r\nmode 100, 30\r\n)\r\ntitle  Remove TSforge Activation %masver%\r\n\r\necho:\r\necho TSforge activation doesn't modify any Windows components and doesn't install any new files.\r\necho:\r\necho Instead, it appends data to one of data files used by Software Protection Platform.\r\necho:\r\ncall :dk_color %Gray% \"If you want to reset the activation status,\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n\r\ngoto :dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_reset\r\n\r\nset key=\r\nset _oRoot=\r\nset _oArch=\r\nset _oIds=\r\nset _oLPath=\r\nset _actid=\r\nset _prod=\r\nset _lic=\r\nset _arr=\r\nset _prids=\r\nset _config=\r\nset _version=\r\nset _License=\r\nset _oMSI=\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_getpath\r\n\r\nset o16c2r=\r\nset o15c2r=\r\nset o16msi=\r\nset o15msi=\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set o16c2r=1&set o16c2r_reg=%_86%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set o16c2r=1&set o16c2r_reg=%_68%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set o15c2r=1&set o15c2r_reg=%_86%\\15.0\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set o15c2r=1&set o15c2r_reg=%_68%\\15.0\\ClickToRun)\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o16msi=1&set o16msi_reg=%_86%\\16.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o16msi=1&set o16msi_reg=%_68%\\16.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o15msi=1&set o15msi_reg=%_86%\\15.0)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set o15msi=1&set o15msi_reg=%_68%\\15.0)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_expiredpreview\r\n\r\necho %_oIds% | find /i \"Volume\" %nul% || exit /b\r\n\r\nfor %%# in (%*) do (\r\nif %%#==2013 set _offver=\r\nif %%#==2016 set _offver=\r\nif %%#==2019 set _offver=2019\r\nif %%#==2021 set _offver=2021\r\nif %%#==2024 set _offver=2024\r\nif exist \"!_oLPath!\\ProPlus!_offver!PreviewVL_*.xrm-ms\" if not exist \"!_oLPath!\\ProPlus!_offver!VL_*.xrm-ms\" (\r\nset error=1\r\nset showfix=1\r\ncall :dk_color %Red% \"Checking Expired Preview Products       [Office %%# Preview Found]\"\r\ncall :dk_color %Blue% \"Please run the Office updates first, and then attempt to activate it again.\"\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Some Office Retail to Volume converter tools may edit the ProductReleaseIds to add VL products. This code restores it because it may affect features.\r\n\r\n:oh_fixprids\r\n\r\nif not defined _prids (\r\ncall :dk_color %Gray% \"Checking ProductReleaseIds In Registry  [Not Found]\"\r\nexit /b\r\n)\r\n\r\nset _pridsR=\r\nset _pridsE=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_prids%\" %nul6%') do (set \"_pridsR=%%b\")\r\n\r\nset _pridsR=%_pridsR:,= %\r\nfor %%# in (%_pridsR%) do (echo %%# | findstr /I \"%_oIds%\" %nul1% || set _pridsE=1)\r\nfor %%# in (%_oIds%) do (echo %%# | findstr /I \"%_pridsR%\" %nul1% || set _pridsE=1)\r\n\r\nif not defined _pridsE exit /b\r\nreg add %_prids% /t REG_SZ /d \"\" /f %nul1%\r\n\r\nfor %%# in (%_oIds%) do (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query %_prids%') do if not \"%%b\"==\"\" (\r\nreg add %_prids% /t REG_SZ /d \"%%b,%%#\" /f %nul1%\r\n) else (\r\nreg add %_prids% /t REG_SZ /d \"%%#\" /f %nul1%\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  After retail to volume conversion, new product ID needs .OSPPReady key in registry, otherwise product info may not fully reflect \r\n\r\n:ks_osppready\r\n\r\nif not defined _config exit /b\r\n\r\necho: %_config% | find /i \"propertyBag\" %nul1% && (\r\nset \"_osppt=REG_DWORD\"\r\nset \"_osppready=%o15c2r_reg%\"\r\n) || (\r\nset \"_osppt=REG_SZ\"\r\nset \"_osppready=%_config%\"\r\n)\r\n\r\nreg add %_osppready% /f /v %_altoffid%.OSPPReady /t %_osppt% /d 1 %nul1%\r\n\r\n::  Office builds before 16.0.10730.20102 need the Installed license product ID in ProductReleaseIds, otherwise product info may not fully reflect \r\n\r\nif exist \"%_oLPath%\\Word2019VL_KMS_Client_AE*.xrm-ms\" exit /b\r\n\r\nreg query %_prids% | findstr /I \"%_altoffid%\" %nul1%\r\nif %errorlevel% NEQ 0 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query %_prids%') do reg add %_prids% /t REG_SZ /d \"%%b,%_altoffid%\" /f %nul1%\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_process\r\n\r\nif not exist \"%pkeypath%\" (\r\ncall :dk_color %Red% \"Checking pkeyconfig-office.xrm-ms       [Not found. Aborting activation...]\"\r\nset error=1\r\nexit /b\r\n)\r\n\r\nfor %%# in (%_oIds%) do (\r\nset _actid=\r\nset _preview=\r\nset _License=%%#\r\n\r\nset skipprocess=\r\n\r\nset foundprod=\r\ncall :tsksdata chkprod %%#\r\nif defined _oMSI if not defined foundprod if /i %tsmethod%==KMS4k (\r\nset skipprocess=1\r\ncall :dk_color %Red% \"Checking Product In Script              [%%# MSI Retail is not supported with KMS4k]\"\r\nif /i %_actmethod%==Auto (\r\ncall :dk_color %Blue% \"Connect to the Internet and try again. Script will use the StaticCID activation method.\"\r\n) else (\r\ncall :dk_color %Blue% \"Use non-KMS4K activation options from the previous menu.\"\r\n)\r\n)\r\n\r\nif \"%_actprojvis%\"==\"1\" (\r\necho %%# | findstr /i \"Project Visio\" %nul% || (\r\nset skipprocess=1\r\ncall :dk_color %Gray% \"Skipping Because Project/Visio Mode     [%%#]\"\r\n)\r\n)\r\n\r\nif \"%_actprojvis%\"==\"0\" if /i %tsmethod%==KMS4k echo %_oIds% | findstr /i \"O365\" %nul% && (\r\necho %%# | findstr /i \"Project Visio\" %nul% && (\r\nset skipprocess=1\r\necho Skipping Because Mondo Is Available     [%%#]\r\n)\r\n)\r\n\r\n\r\nif not defined skipprocess (\r\n\r\nif /i not %tsmethod%==KMS4k (\r\nset no365=\r\nif \"%oVer%\"==\"15\" (echo %%# | findstr /i \"O365HomePremRetail\" %nul% && set no365=1)\r\nif \"%oVer%\"==\"16\" (echo %%# | findstr /i \"O365\" %nul% && set no365=1)\r\n\r\nif defined no365 (\r\nset _License=MondoRetail\r\nset _altoffid=MondoRetail\r\ncall :ks_osppready\r\necho Converting Unsupported O365 Office      [%%# To MondoRetail]\r\nif \"%oVer%\"==\"15\" (call :dk_color %Gray% \"Mondo 2013 is equivalent to O365 [15.0 version] in terms of the latest features.\")\r\nif \"%oVer%\"==\"16\" (call :dk_color %Gray% \"Mondo 2016 is equivalent to O365 in terms of the latest features.\")\r\n)\r\n\r\nif not defined _oMSI (\r\necho %%# | findstr /i \"ARM\" %nul% && (\r\nset _License=MondoRetail\r\nset _altoffid=MondoRetail\r\ncall :ks_osppready\r\necho Converting Unsupported OEM-ARM Office   [%%# To MondoRetail]\r\n)\r\n)\r\n)\r\n\r\nif not defined _oMSI if /i %tsmethod%==KMS4k if not defined foundprod (\r\ncall :tsksdata getinfo %%#\r\nif defined _altoffid (\r\necho Converting Retail To Volume             [%%# To !_altoffid!]\r\n) else (\r\nset _License=MondoVolume\r\nset _altoffid=MondoVolume\r\necho Converting Retail To Volume             [%%# To !_altoffid!] [Using Mondo because %%# is not found in the script]\r\n)\r\necho %%# | find /i \"O365\" %nul% && (\r\nif \"%oVer%\"==\"15\" (call :dk_color %Gray% \"Mondo 2013 is equivalent to O365 [15.0 version] in terms of the latest features.\")\r\nif \"%oVer%\"==\"16\" (call :dk_color %Gray% \"Mondo 2016 is equivalent to O365 in terms of the latest features.\")\r\n)\r\ncall :ks_osppready\r\n)\r\n\r\nif /i %tsmethod%==KMS4k (\r\necho !_License! | find /i \"Retail\" %nul% && (set keytype=zero) || (set keytype=ks)\r\n) else (\r\nset keytype=zero\r\n)\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':offtsid\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (\r\necho \"%%a\" | findstr /r \".*-.*-.*-.*-.*\" %nul1% && (set tsids=!tsids! %%a& set _actid=%%a)\r\n)\r\nset \"_allactid=!tsids!\"\r\n\r\nif defined _actid (\r\necho Checking Activation ID                  [!_actid!] [!_License!]\r\n) else (\r\ncall :dk_color %Red% \"Checking Activation ID                  [Office %oVer%.0 !_License! not found]\"\r\nset error=1\r\nset showfix=1\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\necho %%# | find /i \"2024\" %nul% && (\r\nif exist \"!_oLPath!\\ProPlus2024PreviewVL_*.xrm-ms\" if not exist \"!_oLPath!\\ProPlus2024VL_*.xrm-ms\" set _preview=1\r\n)\r\n\r\nif defined _actid (\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% || call :oh_installlic\r\n)\r\n)\r\n)\r\n\r\n::  Add SharedComputerLicensing registry key if Retail Office C2R is installed on Windows Server\r\n::  https://learn.microsoft.com/en-us/office/troubleshoot/office-suite-issues/click-to-run-office-on-terminal-server\r\n\r\nif /i not %tsmethod%==KMS4k if defined winserver if defined _config if exist \"%_oLPath%\\Word2019VL_KMS_Client_AE*.xrm-ms\" (\r\necho %_oIds% | find /i \"Retail\" %nul1% && (\r\nset scaIsNeeded=1\r\nreg add %_config% /v SharedComputerLicensing /t REG_SZ /d \"1\" /f %nul1%\r\necho Adding SharedComputerLicensing Reg      [Successful] [Needed on Server With Retail Office]\"\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_processmsi\r\n\r\n::  Process Office MSI Version\r\n\r\ncall :ts_reset\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nset _oMSI=1\r\nset oVer=%1\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\InstallRoot /v Path\" %nul6%') do (set \"_oRoot=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %2\\Common\\ProductVersion /v LastProduct\" %nul6%') do (set \"_version=%%b\")\r\nif \"%_oRoot:~-1%\"==\"\\\" set \"_oRoot=%_oRoot:~0,-1%\"\r\n\r\necho \"%2\" | find /i \"Wow6432Node\" %nul1% && set _oArch=x86\r\nif not \"%osarch%\"==\"x86\" if not defined _oArch set _oArch=x64\r\nif \"%osarch%\"==\"x86\" set _oArch=x86\r\n\r\nset \"_common=%CommonProgramFiles%\"\r\nif defined PROCESSOR_ARCHITEW6432 set \"_common=%CommonProgramW6432%\"\r\nset \"_common2=%CommonProgramFiles(x86)%\"\r\n\r\nif exist \"%_common%\\Microsoft Shared\\OFFICE%oVer%\\Office Setup Controller\\pkeyconfig-office.xrm-ms\" (\r\nset \"pkeypath=%_common%\\Microsoft Shared\\OFFICE%oVer%\\Office Setup Controller\\pkeyconfig-office.xrm-ms\"\r\n) else if exist \"%_common2%\\Microsoft Shared\\OFFICE%oVer%\\Office Setup Controller\\pkeyconfig-office.xrm-ms\" (\r\nset \"pkeypath=%_common2%\\Microsoft Shared\\OFFICE%oVer%\\Office Setup Controller\\pkeyconfig-office.xrm-ms\"\r\n)\r\n\r\ncall :msiofficedata %2\r\n\r\necho:\r\necho Processing Office...                    [MSI ^| %_version% ^| %_oArch%]\r\n\r\nif not defined _oIds (\r\nset error=1\r\ncall :dk_color %Red% \"Checking Installed Products             [Product IDs not found. Aborting activation...]\"\r\nexit /b\r\n)\r\n\r\ncall :ts_process\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_installlic\r\n\r\nif not defined _oLPath exit /b\r\n\r\nif defined _oIntegrator (\r\nif %oVer%==16 (\r\n\"!_oIntegrator!\" /I /License PRIDName=%_License%.16 PidKey=%key% %nul%\r\n) else (\r\n\"!_oIntegrator!\" /I /License PRIDName=%_License% PidKey=%key% %nul%\r\n)\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% && exit /b\r\n)\r\n\r\n::  Fallback to manual method to install licenses incase integrator.exe is not working\r\n\r\nset _License=%_License:XVolume=XC2RVL_%\r\n\r\nset _License=%_License:O365EduCloudRetail=O365EduCloudEDUR_%\r\n\r\nset _License=%_License:ProjectProRetail=ProjectProO365R_%\r\nset _License=%_License:ProjectStdRetail=ProjectStdO365R_%\r\nset _License=%_License:VisioProRetail=VisioProO365R_%\r\nset _License=%_License:VisioStdRetail=VisioStdO365R_%\r\n\r\nif defined _preview set _License=%_License:Volume=PreviewVL_%\r\n\r\nset _License=%_License:Retail=R_%\r\nset _License=%_License:Volume=VL_%\r\n\r\nfor %%# in (\"!_oLPath!\\client-issuance-*.xrm-ms\") do (\r\nif defined _arr (set \"_arr=!_arr!;\"!_oLPath!\\%%~nx#\"\") else (set \"_arr=\"!_oLPath!\\%%~nx#\"\")\r\n)\r\n\r\nfor %%# in (\"!_oLPath!\\%_License%*.xrm-ms\") do (\r\nif defined _arr (set \"_arr=!_arr!;\"!_oLPath!\\%%~nx#\"\") else (set \"_arr=\"!_oLPath!\\%%~nx#\"\")\r\n)\r\n\r\n%psc% \"$sls = Get-WmiObject %sps%; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); InstallLicenseArr '!_arr!'; InstallLicenseFile '\"!_oLPath!\\pkeyconfig-office.xrm-ms\"'\" %nul%\r\n\r\ncall :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663\r\necho \"!allapps!\" | find /i \"!_actid!\" %nul1% || (\r\nset error=1\r\ncall :dk_color %Red% \"Installing Missing License Files        [Office %oVer%.0 %_prod%] [Failed]\"\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oh_clearblock\r\n\r\n::  Find remnants of Office vNext/shared/device license block and remove it because it stops other licenses from appearing\r\n::  https://learn.microsoft.com/en-us/office/troubleshoot/activation/reset-office-365-proplus-activation-state\r\n\r\nset _sidlist=\r\nfor /f \"tokens=* delims=\" %%a in ('%psc% \"$p = 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty \"\"\"\"$p\\$($_.PSChildName)\"\"\"\").ProfileImagePath; if ($pi -like '*\\Users\\*' -and (Test-Path \"\"\"\"$pi\\NTUSER.DAT\"\"\"\") -and -not ($_.PSChildName -match '\\.bak$')) { Split-Path $_.PSPath -Leaf } }\" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))\r\n\r\nif not defined _sidlist (\r\nfor /f \"delims=\" %%a in ('%psc% \"$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid\" %nul6%') do (set _sidlist=%%a)\r\n)\r\n\r\n::==========================\r\n\r\n::  Load the unloaded useraccounts registry\r\n\r\nset loadedsids=\r\nset alrloadedsids=\r\n\r\nfor %%# in (%_sidlist%) do (\r\nreg query HKU\\%%#\\Software %nul% && (\r\ncall set \"alrloadedsids=%%alrloadedsids%% %%#\"\r\n) || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nreg load HKU\\%%# \"%%b\\NTUSER.DAT\" %nul%\r\nreg query HKU\\%%#\\Software %nul% && (\r\ncall set \"loadedsids=%%loadedsids%% %%#\"\r\n) || (\r\nreg unload HKU\\%%# %nul%\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==========================\r\n\r\nset \"_sidlist=%loadedsids% %alrloadedsids%\"\r\n\r\nset /a counter=0\r\nfor %%# in (%_sidlist%) do set /a counter+=1\r\n\r\nif %counter% EQU 0 (\r\nset error=1\r\ncall :dk_color %Red% \"Checking User Accounts SID              [Not Found]\"\r\nexit /b\r\n)\r\n\r\nif %counter% GTR 10 (\r\ncall :dk_color %Gray% \"Checking Total User Accounts            [%counter%]\"\r\n)\r\n\r\n::==========================\r\n\r\n::  Clear the vNext/shared/device license blocks which may prevent ohook activation\r\n\r\nset vnextexist=\r\nrmdir /s /q \"%ProgramData%\\Microsoft\\Office\\Licenses\\\" %nul%\r\n\r\nfor %%x in (15 16) do (\r\nfor %%# in (%_sidlist%) do (\r\nreg query HKU\\%%#\\Software\\Microsoft\\Office\\%%x.0\\Common\\Licensing /s %nul2% | findstr /i \"CIDToLicenseIdsMapping LicenseIdToEmailMapping @\" %nul% && set vnextexist=1\r\nreg delete HKU\\%%#\\Software\\Microsoft\\Office\\%%x.0\\Common\\Licensing /f %nul%\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nrmdir /s /q \"%%b\\AppData\\Local\\Microsoft\\Office\\Licenses\\\" %nul%\r\nrmdir /s /q \"%%b\\AppData\\Local\\Microsoft\\Office\\%%x.0\\Licensing\\\" %nul%\r\n)\r\n)\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f /reg:32 %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Office\\%%x.0\\Common\\Licensing\" /f /reg:32 %nul%\r\n)\r\n\r\n::  Clear vNext in UWP Office\r\n\r\nif defined o16uwpapplist (\r\nfor %%# in (%_sidlist%) do (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%%#\" /v ProfileImagePath\" %nul6%') do (\r\nrmdir /s /q \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\LocalCache\\Local\\Microsoft\\Office\\Licenses\\\" %nul%\r\nif exist \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\SystemAppData\\Helium\\User.dat\" (\r\nset defname=DEFTEMP-%%#\r\nreg load HKU\\!defname! \"%%b\\AppData\\Local\\Packages\\Microsoft.Office.Desktop_8wekyb3d8bbwe\\SystemAppData\\Helium\\User.dat\" %nul%\r\nreg query HKU\\!defname!\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing /s %nul2% | findstr /i \"CIDToLicenseIdsMapping LicenseIdToEmailMapping @\" %nul% && set vnextexist=1\r\nreg delete HKU\\!defname!\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing /f %nul%\r\nreg unload HKU\\!defname! %nul%\r\n)\r\n)\r\n)\r\n)\r\n\r\nif defined vnextexist (\r\necho:\r\ncall :dk_color %Gray% \"The logged-in Office account has a subscription license.\"\r\ncall :dk_color %Blue% \"If the subscription is active, it overrides other activation methods.\"\r\ncall :dk_color %Blue% \"If it is expiring soon, rerun the activation script after it expires.\"\r\ncall :dk_color2 %Blue% \"If it has already expired and activation fails, get help here - \" %_Yellow% \" %mas%troubleshoot\"\r\necho:\r\n)\r\n\r\n::  Clear SharedComputerLicensing for office\r\n::  https://learn.microsoft.com/en-us/deployoffice/overview-shared-computer-activation\r\n\r\nif not defined scaIsNeeded (\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration /v SharedComputerLicensing /f %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration /v SharedComputerLicensing /f /reg:32 %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\15.0\\ClickToRun\\Configuration /v SharedComputerLicensing /f %nul%\r\nreg delete HKLM\\SOFTWARE\\Microsoft\\Office\\15.0\\ClickToRun\\Configuration /v SharedComputerLicensing /f /reg:32 %nul%\r\n)\r\n\r\n::  Clear device-based-licensing\r\n::  https://learn.microsoft.com/en-us/deployoffice/device-based-licensing\r\n\r\nfor /f %%# in ('reg query \"%o16c2r_reg%\\Configuration\" /f *.DeviceBasedLicensing %nul6% ^| findstr REG_') do reg delete \"%o16c2r_reg%\\Configuration\" /v %%# /f %nul%\r\n\r\n::  Remove OEM registry key\r\n::  https://support.microsoft.com/en-us/office/office-repeatedly-prompts-you-to-activate-on-a-new-pc-a9a6b05f-f6ce-4d1f-8d49-eb5007b64ba1\r\n\r\nfor %%# in (15 16) do (\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%#.0\\Common\\OEM\" /f %nul%\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Office\\%%#.0\\Common\\OEM\" /f /reg:32 %nul%\r\n)\r\n\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\\0ff1ce15-a989-479d-af46-f275c6370663\" /f %nul%\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\OfficeSoftwareProtectionPlatform\\Policies\\0ff1ce15-a989-479d-af46-f275c6370663\" /f %nul%\r\nreg delete \"HKU\\S-1-5-20\\Software\\Microsoft\\OfficeSoftwareProtectionPlatform\\Policies\\59a52881-a989-479d-af46-f275c6370663\" /f %nul%\r\n\r\necho Clearing Office License Blocks          [Successfully cleared from all %counter% user accounts]\r\n\r\n::==========================\r\n\r\n::  Some retail products attempt to validate the license and may show a banner \"There was a problem checking this device's license status.\"\r\n::  Resiliency registry entry can skip this check\r\n\r\nset defname=DEFTEMP-%random%\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\" /v Default\" %nul6%') do call set \"defdat=%%b\"\r\n\r\nif defined o16c2r if defined ohookact (\r\nif exist \"%defdat%\\NTUSER.DAT\" (\r\nreg load HKU\\%defname% \"%defdat%\\NTUSER.DAT\" %nul%\r\nreg query HKU\\%defname%\\Software %nul% && (\r\nreg add HKU\\%defname%\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /v \"TimeOfLastHeartbeatFailure\" /t REG_SZ /d \"2040-01-01T00:00:00Z\" /f %nul%\r\n)\r\nreg unload HKU\\%defname% %nul%\r\n)\r\n\r\nfor %%# in (%_sidlist%) do (\r\nreg delete HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /f %nul%\r\nreg add HKU\\%%#\\Software\\Microsoft\\Office\\16.0\\Common\\Licensing\\Resiliency /v \"TimeOfLastHeartbeatFailure\" /t REG_SZ /d \"2040-01-01T00:00:00Z\" /f %nul%\r\n)\r\necho Adding Registry to Skip License Check   [Successfully added to all %counter% ^& future new user accounts]\r\n)\r\n\r\n::==========================\r\n\r\n::  Unload the loaded useraccounts registry\r\n\r\nfor %%# in (%loadedsids%) do (\r\nreg unload HKU\\%%# %nul%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Uninstall other / grace Keys\r\n\r\n:oh_uninstkey\r\n\r\nset upk_result=0\r\ncall :dk_actid 0ff1ce15-a989-479d-af46-f275c6370663\r\n\r\nif \"%_actprojvis%\"==\"1\" (\r\nfor /f \"delims=\" %%a in ('%psc% \"Get-WmiObject -Query 'SELECT ID, Description, LicenseFamily FROM %spp% WHERE ApplicationID=''0ff1ce15-a989-479d-af46-f275c6370663'' AND PartialProductKey IS NOT NULL' | Where-Object { $_.LicenseFamily -notmatch 'Project' -and $_.LicenseFamily -notmatch 'Visio' } | Select-Object -ExpandProperty ID\" %nul6%') do call set \"_allactid=%%a !_allactid!\"\r\nfor /f \"delims=\" %%a in ('%psc% \"Get-WmiObject -Query 'SELECT ID, Description, LicenseFamily FROM %spp% WHERE ApplicationID=''0ff1ce15-a989-479d-af46-f275c6370663'' AND PartialProductKey IS NOT NULL' | Where-Object { '!_allactid!' -contains $_.ID -and ($_.LicenseFamily -match 'Project' -or $_.LicenseFamily -match 'Visio') } | Select-Object -ExpandProperty ID\" %nul6%') do call set \"_allactid=%%a !_allactid!\"\r\n)\r\n\r\nfor %%# in (%apps%) do (\r\necho \"%_allactid%\" | find /i \"%%#\" %nul1% || (\r\n\r\nif %_wmic% EQU 1 wmic path %spp% where ID='%%#' call UninstallProductKey %nul%\r\nif %_wmic% EQU 0 %psc% \"$null=([WMI]'%spp%=''%%#''').UninstallProductKey()\" %nul%\r\n\r\nif !errorlevel!==0 (\r\nset upk_result=1\r\n) else (\r\nset error=1\r\nset upk_result=2\r\n)\r\n)\r\n)\r\n\r\nif defined ohookact if not %upk_result%==0 echo:\r\nif %upk_result%==1 echo Uninstalling Other/Grace Keys           [Successful]\r\nif %upk_result%==2 (\r\ncall :dk_color %Red% \"Uninstalling Other/Grace Keys           [Failed]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\nset showfix=1\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Refresh Windows Insider Preview Licenses\r\n::  It required in Insider versions otherwise office may not activate\r\n\r\n:oh_licrefresh\r\n\r\nif exist \"%SysPath%\\spp\\store_test\\2.0\\tokens.dat\" (\r\n%psc% \"Stop-Service sppsvc -force; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif !errorlevel! NEQ 0 %psc% \"$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Clean existing K-M-S cache from the registry\r\n\r\n:_taskclear-cache\r\n\r\nset w=\r\nfor %%# in (SppE%w%xtComObj.exe sppsvc.exe SLsvc.exe) do (\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" /f %nul%\r\n)\r\n\r\nset \"OPPk=SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform\"\r\n\r\nif %winbuild% LSS 7600 (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\" %nul% && (\r\nset \"SPPk=SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\"\r\n)\r\n)\r\nif not defined SPPk (\r\nset \"SPPk=SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\"\r\n)\r\n\r\nset \"slp=SoftwareLicensingProduct\"\r\nset \"ospp=OfficeSoftwareProtectionProduct\"\r\n\r\nset \"_wApp=55c92734-d682-4d71-983e-d6ec3f16059f\"\r\nset \"_oApp=0ff1ce15-a989-479d-af46-f275c6370663\"\r\nset \"_oA14=59a52881-a989-479d-af46-f275c6370663\"\r\n\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName /reg:32\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort /reg:32\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v DisableDnsPublishing\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v DisableKeyManagementServiceHostCaching\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_wApp%\" /f\r\nif %winbuild% GEQ 9200 (\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_oApp%\" /f\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_oApp%\" /f /reg:32\r\n)\r\nif %winbuild% GEQ 9600 (\r\n%nul% reg delete \"HKU\\S-1-5-20\\%SPPk%\\%_wApp%\" /f\r\n%nul% reg delete \"HKU\\S-1-5-20\\%SPPk%\\%_oApp%\" /f\r\n)\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v KeyManagementServiceName\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v KeyManagementServicePort\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v DisableDnsPublishing\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v DisableKeyManagementServiceHostCaching\r\n%nul% reg delete \"HKLM\\%OPPk%\\%_oA14%\" /f\r\n%nul% reg delete \"HKLM\\%OPPk%\\%_oApp%\" /f\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set variables\r\n\r\n:dk_setvar\r\n\r\nset ps=%SysPath%\\WindowsPowerShell\\v1.0\\powershell.exe\r\nset psc=%ps% -nop -c\r\nset winbuild=1\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset _NCS=1\r\nif %winbuild% LSS 10586 set _NCS=0\r\nif %winbuild% GEQ 10586 reg query \"HKCU\\Console\" /v ForceV2 %nul2% | find /i \"0x0\" %nul1% && (set _NCS=0)\r\n\r\necho \"%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%\" | find /i \"ARM64\" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)\r\n\r\nif %_NCS% EQU 1 (\r\nfor /F %%a in ('echo prompt $E ^| cmd') do set \"esc=%%a\"\r\nset     \"Red=\"41;97m\"\"\r\nset    \"Gray=\"100;97m\"\"\r\nset   \"Green=\"42;97m\"\"\r\nset    \"Blue=\"44;97m\"\"\r\nset   \"White=\"107;91m\"\"\r\nset    \"_Red=\"40;91m\"\"\r\nset  \"_White=\"40;37m\"\"\r\nset  \"_Green=\"40;92m\"\"\r\nset \"_Yellow=\"40;93m\"\"\r\n) else (\r\nset     \"Red=\"Red\" \"white\"\"\r\nset    \"Gray=\"Darkgray\" \"white\"\"\r\nset   \"Green=\"DarkGreen\" \"white\"\"\r\nset    \"Blue=\"Blue\" \"white\"\"\r\nset   \"White=\"White\" \"Red\"\"\r\nset    \"_Red=\"Black\" \"Red\"\"\r\nset  \"_White=\"Black\" \"Gray\"\"\r\nset  \"_Green=\"Black\" \"Green\"\"\r\nset \"_Yellow=\"Black\" \"Yellow\"\"\r\n)\r\n\r\nset \"nceline=echo: &echo ==== ERROR ==== &echo:\"\r\nset \"eline=echo: &call :dk_color %Red% \"==== ERROR ====\" &echo:\"\r\nif %~z0 GEQ 200000 (\r\nset \"_exitmsg=Go back\"\r\nset \"_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option.\"\r\n) else (\r\nset \"_exitmsg=Exit\"\r\nset \"_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option.\"\r\n)\r\nexit /b\r\n\r\n::  Show OS info\r\n\r\n:dk_showosinfo\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\" /v PROCESSOR_ARCHITECTURE') do set osarch=%%b\r\n\r\nfor /f \"tokens=6-7 delims=[]. \" %%i in ('ver') do if not \"%%j\"==\"\" (\r\nset fullbuild=%%i.%%j\r\n) else (\r\nfor /f \"tokens=3\" %%G in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR\" %nul6%') do if not errorlevel 1 set /a \"UBR=%%G\"\r\nfor /f \"skip=2 tokens=3,4 delims=. \" %%G in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildLabEx') do (\r\nif defined UBR (set \"fullbuild=%%G.!UBR!\") else (set \"fullbuild=%%G.%%H\")\r\n)\r\n)\r\n\r\necho Checking OS Info                        [%winos% ^| %fullbuild% ^| %osarch%]\r\nexit /b\r\n\r\n::  Check SKU value\r\n\r\n:dk_checksku\r\n\r\ncall :dk_reflection\r\n\r\nset osSKU=\r\nset slcSKU=\r\nset wmiSKU=\r\nset regSKU=\r\nset winsub=\r\n\r\nif %winbuild% GEQ 14393 (set info=Kernel-BrandingInfo) else (set info=Kernel-ProductInfo)\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3);\r\nset d1=%d1% $Sku = 0; [void]$TypeBuilder.CreateType()::SLGetWindowsInformationDWORD('%info%', [ref]$Sku); $Sku\r\nfor /f \"delims=\" %%s in ('\"%psc% %d1%\"') do if not errorlevel 1 (set slcSKU=%%s)\r\nset slcSKU=%slcSKU: =%\r\nif \"%slcSKU%\"==\"0\" set slcSKU=\r\nfor /f \"tokens=* delims=0123456789\" %%a in (\"%slcSKU%\") do (if not \"[%%a]\"==\"[]\" set slcSKU=)\r\n\r\nfor /f \"tokens=3 delims=.\" %%a in ('reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions\" /v OSProductPfn %nul6%') do set \"regSKU=%%a\"\r\nif %_wmic% EQU 1 for /f \"tokens=2 delims==\" %%a in ('\"wmic Path Win32_OperatingSystem Get OperatingSystemSKU /format:LIST\" %nul6%') do if not errorlevel 1 set \"wmiSKU=%%a\"\r\nif %_wmic% EQU 0 for /f \"tokens=1\" %%a in ('%psc% \"([WMI]'Win32_OperatingSystem=@').OperatingSystemSKU\" %nul6%') do if not errorlevel 1 set \"wmiSKU=%%a\"\r\n\r\nif %winbuild% GEQ 15063 %psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':winsubstatus\\:.*';. ([scriptblock]::Create($f[1]))\" %nul2% | find /i \"Subscription_is_activated\" %nul% && (\r\nif defined regSKU if defined slcSKU if not \"%regSKU%\"==\"%slcSKU%\" (\r\nset winsub=1\r\nset osSKU=%regSKU%\r\n)\r\n)\r\n\r\nif not defined osSKU set osSKU=%slcSKU%\r\nif not defined osSKU set osSKU=%wmiSKU%\r\nif not defined osSKU set osSKU=%regSKU%\r\nexit /b\r\n\r\n::  Get Windows Subscription status\r\n\r\n:winsubstatus:\r\n$DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(6, 1).DefineDynamicModule(4).DefineType(2)\r\n[void]$DM.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n$m = [System.Runtime.InteropServices.Marshal]\r\n$p = $m::AllocHGlobal(12)\r\n$r = $DM.CreateType()::ClipGetSubscriptionStatus([ref]$p)\r\nif ($r -eq 0) {\r\n  $enabled = $m::ReadInt32($p)\r\n  if ($enabled -ge 1) {\r\n    $state = $m::ReadInt32($p, 8)\r\n    if ($state -eq 1) {\r\n        \"Subscription_is_activated.\"\r\n    }\r\n  }\r\n}\r\n:winsubstatus:\r\n\r\n::  Get Windows permanent activation status (not counting csvlk)\r\n\r\n:ts_checkwinperm\r\n\r\n%psc% \"Get-WmiObject -Query 'SELECT Name, Description FROM SoftwareLicensingProduct WHERE LicenseStatus=''1'' AND GracePeriodRemaining=''0'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn IS NULL' | Where-Object { $_.Description -notmatch 'KMS' } | Select-Object -Property Name\" %nul2% | findstr /i \"Windows\" %nul1% && set _perm=1||set _perm=\r\nexit /b\r\n\r\n::  Refresh license status\r\n\r\n:dk_refresh\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call RefreshLicenseStatus %nul%\r\nif %_wmic% EQU 0 %psc% \"$null=(([WMICLASS]'%sps%').GetInstances()).RefreshLicenseStatus()\" %nul%\r\nexit /b\r\n\r\n::  Install Key\r\n\r\n:dk_inskey\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey=\"%key%\" %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset keyerror=%errorlevel%\r\ncmd /c exit /b %keyerror%\r\nif %keyerror% NEQ 0 set \"keyerror=[0x%=ExitCode%]\"\r\n\r\nif defined generickey (set \"keyecho=Installing Generic Product Key         \") else (set \"keyecho=Installing Product Key                 \")\r\nif %keyerror% EQU 0 (\r\nif %sps%==SoftwareLicensingService call :dk_refresh\r\necho %keyecho% %~1 [Successful]\r\n) else (\r\ncall :dk_color %Red% \"%keyecho% %~1 [Failed] %keyerror%\"\r\nif not defined showfix (\r\nif defined altapplist call :dk_color %Red% \"Activation ID not found for this key.\"\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\nset showfix=1\r\n)\r\nset error=1\r\n)\r\n\r\nset generickey=\r\nexit /b\r\n\r\n::  Activation command\r\n\r\n:dk_act\r\n\r\nset error_code=\r\nif %_wmic% EQU 1 wmic path %spp% where \"ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL\" call Activate %nul%\r\nif %_wmic% EQU 0 %psc% \"try {$null=(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Activate(); exit 0} catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset error_code=%errorlevel%\r\ncmd /c exit /b %error_code%\r\nif %error_code% NEQ 0 (set \"error_code=[Error Code: 0x%=ExitCode%]\") else (set error_code=)\r\nexit /b\r\n\r\n::  Get all products Activation IDs\r\n\r\n:dk_actids\r\n\r\nset allapps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1') get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1''').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined allapps (call set \"allapps=!allapps! %%a\") else (call set \"allapps=%%a\"))\r\n\r\n::  Check potential script crash issue when user manually installs way too many licenses for Office (length limit in variable)\r\n\r\nif defined allapps if %1==0ff1ce15-a989-479d-af46-f275c6370663 (\r\nset len=0\r\necho:!allapps!> \"!_ttemp!\\chklen\"\r\nfor %%A in (\"!_ttemp!\\chklen\") do (set len=%%~zA)\r\ndel \"!_ttemp!\\chklen\" %nul%\r\n\r\nif !len! GTR 6000 (\r\n%eline%\r\necho Too many licenses are installed, the script may crash.\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ntimeout /t 30\r\n)\r\n)\r\nexit /b\r\n\r\n::  Get installed products Activation IDs\r\n\r\n:dk_actid\r\n\r\nset apps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1' and PartialProductKey is not null) get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1'' AND PartialProductKey IS NOT NULL').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined apps (call set \"apps=!apps! %%a\") else (call set \"apps=%%a\"))\r\nexit /b\r\n\r\n::  Trigger reevaluation, it helps in updating SPP tasks\r\n\r\n:dk_reeval\r\n\r\nif %winbuild% LSS 7600 exit /b\r\n\r\n::  This key is left by the system in rearm process and sppsvc sometimes fails to delete it, it causes issues in working of the Scheduled Tasks of SPP\r\n\r\nset \"ruleskey=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\PersistedSystemState\"\r\nreg delete \"%ruleskey%\" /v \"State\" /f %nul%\r\nreg delete \"%ruleskey%\" /v \"SuppressRulesEngine\" /f %nul%\r\n\r\nset r1=$TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);\r\nset r2=%r1% [void]$TB.DefinePInvokeMethod('SLpTriggerServiceWorker', 'sppc.dll', 22, 1, [Int32], @([UInt32], [IntPtr], [String], [UInt32]), 1, 3);\r\nset d1=%r2% [void]$TB.CreateType()::SLpTriggerServiceWorker(0, 0, 'reeval', 0)\r\n%psc% \"Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null; %d1%\"\r\nexit /b\r\n\r\n::  Install License files using Powershell/WMI instead of slmgr.vbs\r\n\r\n:xrm:\r\nfunction InstallLicenseFile($Lsc) {\r\n    try {\r\n        $null = $sls.InstallLicense([IO.File]::ReadAllText($Lsc))\r\n    } catch {\r\n        $host.SetShouldExit($_.Exception.HResult)\r\n    }\r\n}\r\nfunction InstallLicenseArr($Str) {\r\n    $a = $Str -split ';'\r\n    ForEach ($x in $a) {InstallLicenseFile \"$x\"}\r\n}\r\nfunction InstallLicenseDir($Loc) {\r\n\tGet-ChildItem $Loc -Recurse -Filter *.xrm-ms | ForEach-Object {InstallLicenseFile $_.FullName}\r\n}\r\nfunction ReinstallLicenses() {\r\n\t$Paths = @(\"$env:SysPath\\oem\", \"$env:SysPath\\licensing\", \"$env:SysPath\\spp\\tokens\")\r\n\tforeach ($Path in $Paths) {\r\n    if (Test-Path $Path) { InstallLicenseDir \"$Path\" }\r\n\t}\r\n}\r\n:xrm:\r\n\r\n::  Check wmic.exe\r\n\r\n:dk_ckeckwmic\r\n\r\nif %winbuild% LSS 9200 (set _wmic=1&exit /b)\r\nset _wmic=0\r\nfor %%# in (wmic.exe) do @if not \"%%~$PATH:#\"==\"\" (\r\ncmd /c \"wmic path Win32_ComputerSystem get CreationClassName /value\" %nul2% | find /i \"computersystem\" %nul1% && set _wmic=1\r\n)\r\nexit /b\r\n\r\n::  Show info for potential script stuck scenario\r\n\r\n:dk_sppissue\r\n\r\nsc start %_slser% %nul%\r\nset spperror=%errorlevel%\r\n\r\nif %spperror% NEQ 1056 if %spperror% NEQ 0 (\r\n%eline%\r\necho sc start %_slser% [Error Code: %spperror%]\r\nif %spperror% EQU 1053 (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\ncall :dk_color %Blue% \"If it still does not work, go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\n)\r\n)\r\n\r\necho:\r\n%psc% \"$job = Start-Job { (Get-WmiObject -Query 'SELECT * FROM %sps%').Version }; if (-not (Wait-Job $job -Timeout 30)) {write-host '%_slser% is not working correctly. Check this webpage for help - %mas%troubleshoot'}\"\r\nexit /b\r\n\r\n::  Get Product name (WMI/REG methods are not reliable in all conditions, hence winbrand.dll method is used)\r\n\r\n:dk_product\r\n\r\nset d1=%ref% $meth = $TypeBuilder.DefinePInvokeMethod('BrandingFormatString', 'winbrand.dll', 'Public, Static', 1, [String], @([String]), 1, 3);\r\nset d1=%d1% $meth.SetImplementationFlags(128); $TypeBuilder.CreateType()::BrandingFormatString('%%WINDOWS_LONG%%') -replace [string][char]0xa9, '' -replace [string][char]0xae, '' -replace [string][char]0x2122, ''\r\n\r\nset winos=\r\nfor /f \"delims=\" %%s in ('\"%psc% %d1%\"') do if not errorlevel 1 (set winos=%%s)\r\necho \"%winos%\" | find /i \"Windows\" %nul1% || (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v ProductName %nul6%') do set \"winos=%%b\"\r\nif %winbuild% GEQ 22000 (\r\nset winos=!winos:Windows 10=Windows 11!\r\n)\r\n)\r\n\r\nif not defined winsub exit /b\r\n\r\n::  Check base edition product name if Windows subscription license is found\r\n\r\nfor %%# in (pkeyhelper.dll) do @if \"%%~$PATH:#\"==\"\" exit /b\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionNameFromId', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [IntPtr].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionNameFromId(%regSKU%, [ref]$out);$s=[Runtime.InteropServices.Marshal]::PtrToStringUni($out); $s\r\n\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (\r\nif %winbuild% GEQ 22000 (\r\nset winos=Windows 11 %%a\r\n) else (\r\nset winos=Windows 10 %%a\r\n)\r\n)\r\nexit /b\r\n\r\n::  Common lines used in PowerShell reflection code\r\n\r\n:dk_reflection\r\n\r\nset ref=$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1);\r\nset ref=%ref% $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False);\r\nset ref=%ref% $TypeBuilder = $ModuleBuilder.DefineType(0);\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_chkmal\r\n\r\n::  Many users unknowingly download mal-ware by using activators found through Google search.\r\n::  This code aims to notify users that their system has been affected by mal-ware.\r\n\r\nset w=\r\nset results=\r\nif exist \"%ProgramFiles%\\KM%w%Spico\" set pupfound= KM%w%Spico \r\nif not defined pupfound (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\taskcache\\tasks\" /f Path /s | find /i \"AutoPico\" %nul% && set pupfound= KM%w%Spico \r\n)\r\n\r\nset hcount=0\r\nfor %%# in (avira.com kaspersky.com virustotal.com mcafee.com) do (\r\nfind /i \"%%#\" %SysPath%\\drivers\\etc\\hosts %nul% && set /a hcount+=1)\r\nif %hcount%==4 set \"results=[Antivirus URLs are blocked in hosts]\"\r\n\r\nsc start %_slser% %nul%\r\necho \"%errorlevel%\" | findstr \"577 225\" %nul% && (\r\nset \"results=%results%[Likely File Infector]\"\r\n) || (\r\nif not exist %SysPath%\\%_slexe% if not exist %SysPath%\\alg.exe (set \"results=%results%[Likely File Infector]\")\r\n)\r\n\r\nif not \"%results%%pupfound%\"==\"\" (\r\nif defined pupfound call :dk_color %Gray% \"Checking PUP Activators                 [Found%pupfound%]\"\r\nif defined results call :dk_color %Red% \"Checking Probable Mal%w%ware Infection...\"\r\nif defined results (call :dk_color %Red% \"%results%\"&set showfix=1)\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\necho:\r\n)\r\n\r\n::  Remove the scheduled task of R@1n-KMS (old version) that runs the activation command every minute, as it leads to high CPU usage.\r\n\r\nif exist %SysPath%\\Tasks\\R@1n-KMS (\r\nfor /f %%A in ('dir /b /a:-d %SysPath%\\Tasks\\R@1n-KMS %nul6%') do (schtasks /delete /tn \\R@1n-KMS\\%%A /f %nul%)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_errorcheck\r\n\r\nset showfix=\r\ncall :dk_chkmal\r\n\r\n::==============================\r\n\r\n::  Check Sandboxing\r\n\r\nsc query Null %nul% || (\r\ncall :dk_color %Red% \"Checking Sandboxing                     [Found, script may not work properly]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"If you are using any third-party antivirus, check if it is blocking the script.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WinPE mode\r\n\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinPE\" /v InstRoot %nul% && (\r\n\r\ncall :dk_color %Red% \"Checking WinPE                          [Found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"WinPE mode found. Reboot the system and run in normal mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Safe mode\r\n\r\nif defined safeboot_option (\r\ncall :dk_color %Red% \"Checking Boot Mode                      [%safeboot_option%]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Safe mode found. Reboot the system and run in normal mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check ImageState\r\n::  https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-setup-states\r\n\r\nfor /f \"skip=2 tokens=2*\" %%A in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State\" /v ImageState') do (set imagestate=%%B)\r\n\r\nif /i not \"%imagestate%\"==\"IMAGE_STATE_COMPLETE\" (\r\ncall :dk_color %Gray% \"Checking Windows Setup State            [%imagestate%]\"\r\necho \"%imagestate%\" | find /i \"RESEAL\" %nul% && (\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"You need to run it in normal mode in case you are running it in Audit Mode.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\necho \"%imagestate%\" | find /i \"UNDEPLOYABLE\" %nul% && (\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If the activation fails, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check corrupt services\r\n\r\nset serv_cor=\r\nfor %%# in (%_serv%) do (\r\nset _regcorr=\r\nset _corrupt=\r\nsc start %%# %nul%\r\nif !errorlevel! EQU 1060 set _corrupt=1\r\nsc query %%# %nul% || set _corrupt=1\r\nfor %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type) do if not defined _regcorr (\r\nreg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%# /v %%G %nul% || (set _corrupt=1&set _regcorr=-RegistryError)\r\n)\r\n\r\nif defined _corrupt (if defined serv_cor (set \"serv_cor=!serv_cor! %%#!_regcorr!\") else (set \"serv_cor=%%#!_regcorr!\"))\r\n)\r\n\r\nif defined serv_cor (\r\ncall :dk_color %Red% \"Checking Corrupt Services               [%serv_cor%]\"\r\n\r\nif not defined showfix (\r\necho:\r\nif /i \"%serv_cor%\"==\"sppsvc-RegistryError\" (\r\nset fixes=%fixes% %mas%fix_service\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_service\"\r\n) else (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\necho:\r\n)\r\n\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check disabled services\r\n\r\nset serv_ste=\r\nfor %%# in (%_serv%) do (\r\nsc start %%# %nul%\r\nif !errorlevel! EQU 1058 (if defined serv_ste (set \"serv_ste=!serv_ste! %%#\") else (set \"serv_ste=%%#\"))\r\n)\r\n\r\n::  Change disabled services startup type to default\r\n\r\nset serv_csts=\r\nset serv_cste=\r\n\r\nif defined serv_ste (\r\nfor %%# in (%serv_ste%) do (\r\nif /i %%#==ClipSVC          (reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%#\" /v \"Start\" /t REG_DWORD /d \"3\" /f %nul% & sc config %%# start= demand %nul%)\r\nif /i %%#==wlidsvc          sc config %%# start= demand %nul%\r\nif /i %%#==sppsvc           (reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\%%#\" /v \"Start\" /t REG_DWORD /d \"2\" /f %nul% & sc config %%# start= delayed-auto %nul%)\r\nif /i %%#==SLsvc            sc config %%# start= auto %nul%\r\nif /i %%#==KeyIso           sc config %%# start= demand %nul%\r\nif /i %%#==LicenseManager   sc config %%# start= demand %nul%\r\nif /i %%#==Winmgmt          sc config %%# start= auto %nul%\r\nif !errorlevel!==0 (\r\nif defined serv_csts (set \"serv_csts=!serv_csts! %%#\") else (set \"serv_csts=%%#\")\r\n) else (\r\nif defined serv_cste (set \"serv_cste=!serv_cste! %%#\") else (set \"serv_cste=%%#\")\r\n)\r\n)\r\n)\r\n\r\nif defined serv_csts call :dk_color %Gray% \"Enabling Disabled Services              [Successful] [%serv_csts%]\"\r\n\r\nif defined serv_cste (\r\ncall :dk_color %Red% \"Enabling Disabled Services              [Failed] [%serv_cste%]\"\r\n\r\nif not defined showfix (\r\necho:\r\necho %serv_cste% | findstr /i \"ClipSVC sppsvc\" %nul% && (\r\necho A registry fix has been applied to enable the disabled service.\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\n) || (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n)\r\necho:\r\n)\r\n\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check if the services are able to run or not\r\n::  Workarounds are added to get correct status and error code because sc query doesn't output correct results in some conditions\r\n\r\nset serv_e=\r\nfor %%# in (%_serv%) do (\r\nset errorcode=\r\nset checkerror=\r\n\r\nsc query %%# | find /i \"RUNNING\" %nul% || (\r\n%psc% \"Start-Job { Start-Service %%# } | Wait-Job -Timeout 20 | Out-Null\"\r\nset errorcode=!errorlevel!\r\nsc query %%# | find /i \"RUNNING\" %nul% || set checkerror=1\r\n)\r\n\r\nsc start %%# %nul%\r\nif !errorlevel! NEQ 1056 if !errorlevel! NEQ 0 (set errorcode=!errorlevel!&set checkerror=1)\r\nif defined checkerror if defined serv_e (set \"serv_e=!serv_e!, %%#-!errorcode!\") else (set \"serv_e=%%#-!errorcode!\")\r\n)\r\n\r\nif defined serv_e (\r\ncall :dk_color %Red% \"Starting Services                       [Failed] [%serv_e%]\"\r\n\r\nif not defined showfix (\r\nset listwospp=%_serv:sppsvc=%\r\necho %serv_e% | findstr /i \"!listwospp!\" %nul% && (\r\nset showfix=1\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and run the script again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If service error is still not fixed, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\n)\r\nset error=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WMI\r\n\r\nset wmifailed=\r\nif %_wmic% EQU 1 wmic path Win32_ComputerSystem get CreationClassName /value %nul2% | find /i \"computersystem\" %nul1%\r\nif %_wmic% EQU 0 %psc% \"Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName\" %nul2% | find /i \"computersystem\" %nul1%\r\n\r\nif %errorlevel% NEQ 0 set wmifailed=1\r\n\r\nif %_wmic% EQU 1 wmic path %sps% get Version %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=([WMISEARCHER]'SELECT * FROM %sps%').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset error_code=%errorlevel%\r\ncmd /c exit /b %error_code%\r\nif %error_code% NEQ 0 set \"error_code=0x%=ExitCode%\"\r\n\r\necho \"%error_code%\" | findstr /i \"0x800410 0x800440 0x80131501\" %nul1% && set wmifailed=1& ::  https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants\r\n\r\nif defined wmifailed (\r\ncall :dk_color %Red% \"Checking WMI                            [Not Working]\"\r\n\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WMI option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SPP Registry Key\r\n\r\nif %winbuild% GEQ 7600 reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Plugins\\Objects\\msft:rm/algorithm/hwid/4.0\" /f ba02fed39662 /d %nul% || (\r\ncall :dk_color %Red% \"Checking SPP Registry Key               [Incorrect ModuleId Found] [Most likely caused by gaming spoofers]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%issues_due_to_gaming_spoofers\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%issues_due_to_gaming_spoofers\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check TokenStore registry key\r\n\r\nset tokenstore=\r\nif %winbuild% GEQ 7600 (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v TokenStore %nul6%') do call set \"tokenstore=%%b\"\r\nif %winbuild% LSS 9200 set \"tokenstore=%Systemdrive%\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareProtectionPlatform\"\r\n\r\nif %winbuild% GEQ 9200 if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store\" if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store\\2.0\" if /i not \"!tokenstore!\"==\"%SysPath%\\spp\\store_test\\2.0\" (\r\ncall :dk_color %Red% \"Checking TokenStore Registry Key        [Correct Path Not Found] [!tokenstore!]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset toerr=1\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This code creates token folder only if it's missing and sets default permission for it\r\n\r\nif %winbuild% GEQ 7600 if not defined toerr if not exist \"%tokenstore%\\\" (\r\n\r\nmkdir \"%tokenstore%\" %nul%\r\n\r\nif %winbuild% LSS 9200 set \"d=$sddl = 'O:NSG:NSD:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;NS)';\"\r\nif %winbuild% GEQ 9200 set \"d=$sddl = 'O:BAG:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;GR;;;BU)(A;;FR;;;BU)(A;OICI;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)';\"\r\nset \"d=!d! $AclObject = New-Object System.Security.AccessControl.DirectorySecurity;\"\r\nset \"d=!d! $AclObject.SetSecurityDescriptorSddlForm($sddl);\"\r\nset \"d=!d! Set-Acl -Path %tokenstore% -AclObject $AclObject;\"\r\n%psc% \"!d!\" %nul%\r\n\r\nif exist \"%tokenstore%\\\" (\r\ncall :dk_color %Gray% \"Checking SPP Token Folder               [Not Found, Created Now] [%tokenstore%\\]\"\r\n) else (\r\ncall :dk_color %Red% \"Checking SPP Token Folder               [Not Found, Failed to Create] [%tokenstore%\\]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This code checks if SPP has permission access to tokens folder and required registry keys. It's often caused by gaming spoofers.\r\n\r\nset permerror=\r\nif %winbuild% GEQ 9200 if not defined toerr if not defined ps32onArm if exist \"%tokenstore%\\\" (\r\nfor %%# in (\r\n\"%tokenstore%+FullControl\"\r\n\"HKLM:\\SYSTEM\\WPA+QueryValues, EnumerateSubKeys, WriteKey\"\r\n\"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform+SetValue\"\r\n) do for /f \"tokens=1,2 delims=+\" %%A in (%%#) do if not defined permerror (\r\n%psc% \"$acl = (Get-Acl '%%A' | fl | Out-String); if (-not ($acl -match 'NT SERVICE\\\\sppsvc Allow  %%B') -or ($acl -match 'NT SERVICE\\\\sppsvc Deny')) {Exit 2}\" %nul%\r\nif !errorlevel!==2 (\r\nif \"%%A\"==\"%tokenstore%\" (\r\nset \"permerror=Error Found In Token Folder\"\r\n) else (\r\nset \"permerror=Error Found In SPP Registries\"\r\n)\r\n)\r\n)\r\n\r\nREM  https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application\r\n\r\nif not defined permerror (\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% && (\r\nset \"pol=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\"\r\nreg query \"!pol!\" %nul% || reg add \"!pol!\" %nul%\r\n%psc% \"$netServ = (New-Object Security.Principal.SecurityIdentifier('S-1-5-20')).Translate([Security.Principal.NTAccount]).Value; $aclString = Get-Acl 'Registry::!pol!' | Format-List | Out-String; if (-not ($aclString.Contains($netServ + ' Allow  FullControl') -or $aclString.Contains('NT SERVICE\\sppsvc Allow  FullControl')) -or ($aclString.Contains('Deny'))) {Exit 3}\" %nul%\r\nif !errorlevel!==3 set \"permerror=Error Found In S-1-5-20 SPP\"\r\n)\r\n)\r\n\r\nif defined permerror (\r\ncall :dk_color %Red% \"Checking SPP Permissions                [!permerror!]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check WPA Registry Errors\r\n\r\nset chkalp=\r\nset wpainfo=NotFound\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wpatest\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (set wpainfo=%%a)\r\nfor /f \"delims=0123456789\" %%i in (\"%wpainfo%\") do set chkalp=%%i\r\n\r\nif defined chkalp (\r\ncall :dk_color %Red% \"Checking WPA Registry Errors            [%wpainfo%]\"\r\nif not defined showfix (\r\necho \"%wpainfo%\" | find /i \"Error Found\" %nul% && (\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\necho:\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\nset wpainfo=a\r\n)\r\n\r\nif not defined chkalp (\r\nif %wpainfo% GEQ 5000 (\r\ncall :dk_color %Gray% \"Checking WPA Registry Count             [%wpainfo%]\"\r\ncall :dk_color %Blue% \"A large number of WPA registries have been found, which may cause high CPU usage.\"\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\necho:\r\n) else (\r\necho Checking WPA Registry Count             [%wpainfo%]\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Rearm\r\n\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\PersistedTSReArmed\" %nul% && (\r\ncall :dk_color %Red% \"Checking Rearm                          [System is Rearmed]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState\" %nul% && (\r\ncall :dk_color %Red% \"Checking ClipSVC PersistedSystemState   [Found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option to fix this error.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SoftwareLicensingService\r\n\r\nif %error_code% NEQ 0 (\r\ncall :dk_color %Red% \"Checking SoftwareLicensingService       [Not Working] [%error_code%]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Activation IDs\r\n\r\ncall :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nif not defined apps (\r\n%psc% \"if (-not $env:_vis) {Start-Job { Stop-Service %_slser% -force } | Wait-Job -Timeout 20 | Out-Null}; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif not defined _vis if !errorlevel! NEQ 0 set rlicfailed=1\r\ncall :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f\r\n)\r\n\r\nif not defined apps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\nif not defined apps if defined allapps if not defined notwinact (\r\ncall :dk_color %Gray% \"Checking Activation IDs                 [Key Not Installed or Act ID Not Found]\"\r\n)\r\n\r\nif not defined apps if not defined allapps (\r\ncall :dk_color %Red% \"Checking Activation IDs                 [Not found]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\nif not defined showfix if defined rlicfailed (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\ncall :dk_color %Blue% \"If activation still fails then run Fix WPA Registry option.\"\r\necho:\r\n)\r\n\r\nif %winbuild% GEQ 7600 if exist \"%tokenstore%\\\" if not exist \"%tokenstore%\\tokens.dat\" (\r\ncall :dk_color %Red% \"Checking SPP tokens.dat                 [Not Found] [%tokenstore%\\]\"\r\n)\r\n\r\n::==============================\r\n\r\n::  Check Eval Windows\r\n\r\nif not defined notwinact if exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul2% | find /i \"Eval\" %nul1% || (\r\ncall :dk_color %Red% \"Checking Eval Packages                  [License swapping found. Non-Eval licenses are installed in Eval Windows]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"License swapping is not the right way to upgrade to the full version. Learn the correct method at the link below.\"\r\nset fixes=%fixes% %mas%evaluation_editions\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%evaluation_editions\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check HKU\\S-1-5-20\\Software registry, in some systems it's missing and that causes Windows activation problems\r\n\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% || (\r\ncall :dk_color %Red% \"Checking HKU\\S-1-5-20 Registry          [Not Found]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n\r\n::==============================\r\n\r\n::  Check license and package files for the current edition\r\n\r\nset osedition=0\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do if not errorlevel 1 (call set \"osedition=%%a\")\r\n\r\nif %osedition%==0 for /f \"skip=2 tokens=3\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul6%') do set \"osedition=%%a\"\r\n\r\n::  Workaround for an issue in builds between 1607 and 1709 where ProfessionalEducation is shown as Professional\r\n\r\nif not %osedition%==0 (\r\nif \"%osSKU%\"==\"164\" set osedition=ProfessionalEducation\r\nif \"%osSKU%\"==\"165\" set osedition=ProfessionalEducationN\r\n)\r\n\r\nif not defined notwinact (\r\nif %osedition%==0 (\r\ncall :dk_color %Red% \"Checking Edition Name                   [Not Found In Registry]\"\r\n) else (\r\nif not exist \"%SysPath%\\spp\\tokens\\skus\\%osedition%\\%osedition%*.xrm-ms\" if not exist \"%SysPath%\\spp\\tokens\\skus\\Security-SPP-Component-SKU-%osedition%\\*-%osedition%-*.xrm-ms\" if not exist \"%SysPath%\\licensing\\skus\\Security-Licensing-SLC-Component-SKU-%osedition%\\*-%osedition%-*.xrm-ms\" (\r\nset skunotfound=1\r\ncall :dk_color %Red% \"Checking License Files                  [Not Found] [%osedition%]\"\r\n)\r\nif not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*-%osedition%-*.mum\" (\r\nif not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-%osedition%Edition*.mum\" (\r\ncall :dk_color %Red% \"Checking Package Files                  [Not Found] [%osedition%]\"\r\nif not defined showfix (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\necho:\r\n)\r\nset error=1\r\nset showfix=1\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SKU value to find if there is any difference\r\n\r\nif not defined notwinact (\r\nif %winbuild% GEQ 10240 (\r\n%nul% set /a \"sum=%slcSKU%+%regSKU%+%wmiSKU%\"\r\nset /a \"sum/=3\"\r\nif not \"!sum!\"==\"%slcSKU%\" (\r\ncall :dk_color %Gray% \"Checking SLC/WMI/REG SKU                [Difference Found - SLC:%slcSKU% WMI:%wmiSKU% Reg:%regSKU%]\"\r\n)\r\n) else (\r\n%nul% set /a \"sum=%slcSKU%+%wmiSKU%\"\r\nset /a \"sum/=2\"\r\nif not \"!sum!\"==\"%slcSKU%\" (\r\ncall :dk_color %Gray% \"Checking SLC/WMI SKU                    [Difference Found - SLC:%slcSKU% WMI:%wmiSKU%]\"\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  This \"WLMS\" service was included in previous Eval editions (which were activable) to automatically shut down the system every hour after the evaluation period expired and prevent SPPSVC from stopping.\r\n\r\nsc query wlms %nul%\r\n\r\nif %errorlevel% NEQ 1060 (\r\necho Checking Eval WLMS Service              [Found]\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SPP interference in IFEO\r\n\r\nfor %%# in (SppEx%w%tComObj.exe SLsvc.exe sppsvc.exe sppsvc.exe\\PerfOptions) do (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" %nul% && (if defined _sppint (set \"_sppint=!_sppint!, %%#\") else (set \"_sppint=%%#\"))\r\n)\r\nif defined _sppint (\r\necho %_sppint% | find /i \"PerfOptions\" %nul% && (\r\ncall :dk_color %Red% \"Checking SPP Interference In IFEO       [%_sppint% - System might deactivate later]\"\r\nif not defined showfix (\r\ncall :dk_color %Blue% \"%_fixmsg%\"\r\necho:\r\n)\r\nset showfix=1\r\n) || (\r\necho Checking SPP In IFEO                    [%_sppint%]\r\n)\r\n)\r\n\r\n::==============================\r\n\r\n::  Check and fix SkipRearm registry value\r\n\r\nif %winbuild% GEQ 7600 for /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"SkipRearm\" %nul6%') do if /i %%b NEQ 0x0 (\r\nreg add \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"SkipRearm\" /t REG_DWORD /d \"0\" /f %nul%\r\ncall :dk_color %Gray% \"Checking SkipRearm                      [Default 0 Value Not Found. Changing To 0]\"\r\n%psc% \"Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null\"\r\n)\r\n\r\n::==============================\r\n\r\n::  Check SvcRestartTask status, this task helps in making sure system remains activated\r\n\r\nif %winbuild% GEQ 9200 if not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-*EvalEdition~*.mum\" (\r\n%psc% \"Get-WmiObject -Query 'SELECT Description FROM SoftwareLicensingProduct WHERE PartialProductKey IS NOT NULL AND LicenseDependsOn IS NULL' | Select-Object -Property Description\" %nul2% | findstr /i \"KMS_\" %nul1% || (\r\nfor /f \"delims=\" %%a in ('%psc% \"$s=New-Object -ComObject 'Schedule.Service'; $s.Connect(); $state=$s.GetFolder('\\Microsoft\\Windows\\SoftwareProtectionPlatform').GetTask('SvcRestartTask').State; @{0='Unknown';1='Disabled';2='Queued';3='Ready';4='Running'}[$state]\" %nul6%') do (set taskinfo=%%a)\r\n\r\necho !taskinfo! | find /i \"Ready\" %nul% || (\r\nreg delete \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"actionlist\" /f %nul%\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\Microsoft\\Windows\\SoftwareProtectionPlatform\\SvcRestartTask\" %nul% || set taskinfo=Removed\r\nif \"!taskinfo!\"==\"\" set \"taskinfo=Not Found\"\r\n\r\ncall :dk_color %Gray% \"Checking SvcRestartTask Status          [!taskinfo!. System might deactivate later.]\"\r\nif not defined showfix (\r\necho \"!taskinfo!\" | findstr /i \"Removed Not Found\" %nul1% && (\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\n) || (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and run the script again.\"\r\n)\r\necho:\r\n)\r\n)\r\n)\r\n)\r\n\r\n::==============================\r\n\r\nexit /b\r\n\r\n::  This code checks for invalid registry keys in HKLM\\SYSTEM\\WPA. This issue may appear even on healthy systems\r\n\r\n:wpatest:\r\n$wpaKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME).OpenSubKey(\"SYSTEM\\\\WPA\")\r\n$count = 0\r\nforeach ($subkeyName in $wpaKey.GetSubKeyNames()) {\r\n    if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n        $count++\r\n    }\r\n}\r\n$osVersion = [System.Environment]::OSVersion.Version\r\n$minBuildNumber = 14393\r\nif ($osVersion.Build -ge $minBuildNumber) {\r\n    $subkeyHashTable = @{}\r\n    foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {\r\n        if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n            $keyNumber = $subkeyName -replace '.*-', ''\r\n            $subkeyHashTable[$keyNumber] = $true\r\n        }\r\n    }\r\n    for ($i=1; $i -le $count; $i++) {\r\n        if (-not $subkeyHashTable.ContainsKey(\"$i\")) {\r\n            Write-Output \"Total Keys $count. Error Found - $i key does not exist.\"\r\n\t\t\t$wpaKey.Close()\r\n\t\t\texit\r\n        }\r\n    }\r\n}\r\n$wpaKey.GetSubKeyNames() | ForEach-Object {\r\n    if ($_ -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {\r\n        if ($PSVersionTable.PSVersion.Major -lt 3) {\r\n            cmd /c \"reg query \"HKLM\\SYSTEM\\WPA\\$_\" /ve /t REG_BINARY >nul 2>&1\"\r\n\t\t\tif ($LASTEXITCODE -ne 0) {\r\n            Write-Host \"Total Keys $count. Error Found - Binary Data is corrupt.\"\r\n\t\t\t$wpaKey.Close()\r\n\t\t\texit\r\n\t\t\t}\r\n        } else {\r\n            $subkey = $wpaKey.OpenSubKey($_)\r\n            $p = $subkey.GetValueNames()\r\n            if (($p | Where-Object { $subkey.GetValueKind($_) -eq [Microsoft.Win32.RegistryValueKind]::Binary }).Count -eq 0) {\r\n                Write-Host \"Total Keys $count. Error Found - Binary Data is corrupt.\"\r\n\t\t\t\t$wpaKey.Close()\r\n\t\t\t\texit\r\n            }\r\n        }\r\n    }\r\n}\r\n$count\r\n$wpaKey.Close()\r\n:wpatest:\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_color\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3'\r\n) else if not exist %ps% (\r\necho %~3\r\n)\r\nexit /b\r\n\r\n:dk_color2\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[%~3%~4%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'\r\n) else if not exist %ps% (\r\necho %~3 %~6\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_done\r\n\r\necho:\r\nif %_unattended%==1 timeout /t 2 & exit /b\r\n\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 exit /b\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:tsforge:\r\n$src = @'\r\n#if !POWERSHELL2\r\nnamespace ActivationWs\r\n{\r\n\r\n/*\r\n\r\nThis code is adapted from ActivationWs.\r\nOriginal Repository: https://github.com/dadorner-msft/activationws\r\n\r\nMIT License\r\n\r\nCopyright (c) Daniel Dorner\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\nSOFTWARE.\r\n\r\n*/\r\n\r\nusing System;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Net;\r\nusing System.Security.Cryptography;\r\nusing System.Text;\r\nusing System.Xml.Linq;\r\n\r\n    public static class ActivationHelper {\r\n        // Key for HMAC/SHA256 signature.\r\n        private static readonly byte[] MacKey = new byte[64] {\r\n            254,  49, 152, 117, 251,  72, 132, 134,\r\n            156, 243, 241, 206, 153, 168, 144, 100,\r\n            171,  87,  31, 202,  71,   4,  80,  88,\r\n            48,   36, 226,  20,  98, 135, 121, 160,\r\n            0,     0,   0,   0,   0,   0,   0,   0,\r\n            0,     0,   0,   0,   0,   0,   0,   0,\r\n            0,     0,   0,   0,   0,   0,   0,   0,\r\n            0,     0,   0,   0,   0,   0,   0,   0\r\n        };\r\n\r\n        private const string Action = \"http://www.microsoft.com/BatchActivationService/BatchActivate\";\r\n\r\n        private static readonly Uri Uri = new Uri(\"https://activation.sls.microsoft.com/BatchActivation/BatchActivation.asmx\");\r\n\r\n        private static readonly XNamespace SoapSchemaNs = \"http://schemas.xmlsoap.org/soap/envelope/\";\r\n        private static readonly XNamespace XmlSchemaInstanceNs = \"http://www.w3.org/2001/XMLSchema-instance\";\r\n        private static readonly XNamespace XmlSchemaNs = \"http://www.w3.org/2001/XMLSchema\";\r\n        private static readonly XNamespace BatchActivationServiceNs = \"http://www.microsoft.com/BatchActivationService\";\r\n        private static readonly XNamespace BatchActivationRequestNs = \"http://www.microsoft.com/DRM/SL/BatchActivationRequest/1.0\";\r\n        private static readonly XNamespace BatchActivationResponseNs = \"http://www.microsoft.com/DRM/SL/BatchActivationResponse/1.0\";\r\n\r\n        public static string CallWebService(int requestType, string installationId, string extendedProductId) {\r\n            XDocument soapRequest = CreateSoapRequest(requestType, installationId, extendedProductId);\r\n            HttpWebRequest webRequest = CreateWebRequest(soapRequest);\r\n            XDocument soapResponse = new XDocument();\r\n\r\n            try {\r\n                IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);\r\n                asyncResult.AsyncWaitHandle.WaitOne();\r\n\r\n                // Read data from the response stream.\r\n                using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))\r\n                using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream())) {\r\n                    soapResponse = XDocument.Parse(streamReader.ReadToEnd());\r\n                }\r\n\r\n                return ParseSoapResponse(soapResponse);\r\n\r\n            } catch {\r\n                throw;\r\n            }\r\n        }\r\n\r\n        private static XDocument CreateSoapRequest(int requestType, string installationId, string extendedProductId) {\r\n            // Create an activation request.           \r\n            XElement activationRequest = new XElement(BatchActivationRequestNs + \"ActivationRequest\",\r\n                new XElement(BatchActivationRequestNs + \"VersionNumber\", \"2.0\"),\r\n                new XElement(BatchActivationRequestNs + \"RequestType\", requestType),\r\n                new XElement(BatchActivationRequestNs + \"Requests\",\r\n                    new XElement(BatchActivationRequestNs + \"Request\",\r\n                        new XElement(BatchActivationRequestNs + \"PID\", extendedProductId),\r\n                        requestType == 1 ? new XElement(BatchActivationRequestNs + \"IID\", installationId) : null)\r\n                )\r\n            );\r\n\r\n            // Get the unicode byte array of activationRequest and convert it to Base64.\r\n            byte[] bytes = Encoding.Unicode.GetBytes(activationRequest.ToString());\r\n            string requestXml = Convert.ToBase64String(bytes);\r\n\r\n            XDocument soapRequest = new XDocument();\r\n\r\n            using (HMACSHA256 hMACSHA = new HMACSHA256(MacKey)) {\r\n                // Convert the HMAC hashed data to Base64.\r\n                string digest = Convert.ToBase64String(hMACSHA.ComputeHash(bytes));\r\n\r\n                soapRequest = new XDocument(\r\n                new XDeclaration(\"1.0\", \"UTF-8\", \"no\"),\r\n                new XElement(SoapSchemaNs + \"Envelope\",\r\n                    new XAttribute(XNamespace.Xmlns + \"soap\", SoapSchemaNs),\r\n                    new XAttribute(XNamespace.Xmlns + \"xsi\", XmlSchemaInstanceNs),\r\n                    new XAttribute(XNamespace.Xmlns + \"xsd\", XmlSchemaNs),\r\n                    new XElement(SoapSchemaNs + \"Body\",\r\n                        new XElement(BatchActivationServiceNs + \"BatchActivate\",\r\n                            new XElement(BatchActivationServiceNs + \"request\",\r\n                                new XElement(BatchActivationServiceNs + \"Digest\", digest),\r\n                                new XElement(BatchActivationServiceNs + \"RequestXml\", requestXml)\r\n                            )\r\n                        )\r\n                    )\r\n                ));\r\n\r\n            }\r\n\r\n            return soapRequest;\r\n        }\r\n\r\n        private static HttpWebRequest CreateWebRequest(XDocument soapRequest) {\r\n            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Uri);\r\n            webRequest.Accept = \"text/xml\";\r\n            webRequest.ContentType = \"text/xml; charset=\\\"utf-8\\\"\";\r\n            webRequest.Headers.Add(\"SOAPAction\", Action);\r\n            webRequest.Host = \"activation.sls.microsoft.com\";\r\n            webRequest.Method = \"POST\";\r\n\r\n            try {\r\n                // Insert SOAP envelope\r\n                using (Stream stream = webRequest.GetRequestStream()) {\r\n                    soapRequest.Save(stream);\r\n                }\r\n\r\n                return webRequest;\r\n\r\n            } catch {\r\n                throw;\r\n            }\r\n        }\r\n\r\n        private static string ParseSoapResponse(XDocument soapResponse) {\r\n            if (soapResponse == null) {\r\n                throw new ArgumentNullException(\"soapResponse\", \"The remote server returned an unexpected response.\");\r\n            }\r\n\r\n            if (!soapResponse.Descendants(BatchActivationServiceNs + \"ResponseXml\").Any()) {\r\n                throw new Exception(\"The remote server returned an unexpected response\");\r\n            }\r\n\r\n            try {\r\n                XDocument responseXml = XDocument.Parse(soapResponse.Descendants(BatchActivationServiceNs + \"ResponseXml\").First().Value);\r\n\r\n                if (responseXml.Descendants(BatchActivationResponseNs + \"ErrorCode\").Any()) {\r\n                    string errorCode = responseXml.Descendants(BatchActivationResponseNs + \"ErrorCode\").First().Value;\r\n\r\n                    switch (errorCode) {\r\n                        case \"0x7F\":\r\n                            throw new Exception(\"The Multiple Activation Key has exceeded its limit\");\r\n\r\n                        case \"0x67\":\r\n                            throw new Exception(\"The product key has been blocked\");\r\n\r\n                        case \"0x68\":\r\n                            throw new Exception(\"Invalid product key\");\r\n\r\n                        case \"0x86\":\r\n                            throw new Exception(\"Invalid key type\");\r\n\r\n                        case \"0x90\":\r\n                            throw new Exception(\"Please check the Installation ID and try again\");\r\n\r\n                        default:\r\n                            throw new Exception(string.Format(\"The remote server reported an error ({0})\", errorCode));\r\n                    }\r\n\r\n                } else if (responseXml.Descendants(BatchActivationResponseNs + \"ResponseType\").Any()) {\r\n                    string responseType = responseXml.Descendants(BatchActivationResponseNs + \"ResponseType\").First().Value;\r\n\r\n                    switch (responseType) {\r\n                        case \"1\":\r\n                            string confirmationId = responseXml.Descendants(BatchActivationResponseNs + \"CID\").First().Value;\r\n                            return confirmationId;\r\n\r\n                        case \"2\":\r\n                            string activationsRemaining = responseXml.Descendants(BatchActivationResponseNs + \"ActivationRemaining\").First().Value;\r\n                            return activationsRemaining;\r\n\r\n                        default:\r\n                            throw new Exception(\"The remote server returned an unrecognized response\");\r\n                    }\r\n\r\n                } else {\r\n                    throw new Exception(\"The remote server returned an unrecognized response\");\r\n                }\r\n\r\n            } catch {\r\n                throw;\r\n            }\r\n        }\r\n    }\r\n}\r\n#endif\r\n\r\n// LibTSforge/Common.cs\r\nnamespace LibTSforge\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using System.Runtime.InteropServices;\r\n    using System.Text;\r\n\r\n    public enum PSVersion\r\n    {\r\n        Vista,\r\n        Win7,\r\n        Win8,\r\n        WinBlue,\r\n        WinModern\r\n    }\r\n\r\n    public static class Constants\r\n    {\r\n        public static readonly byte[] UniversalHWIDBlock =\r\n        {\r\n            0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00,\r\n            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n            0x00, 0x00, 0x01, 0x0c, 0x01, 0x00\r\n        };\r\n\r\n        public static readonly byte[] KMSv4Response =\r\n        {\r\n            0x00, 0x00, 0x04, 0x00, 0x62, 0x00, 0x00, 0x00, 0x30, 0x00, 0x35, 0x00, 0x34, 0x00, 0x32, 0x00,\r\n            0x36, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x30, 0x00, 0x32, 0x00, 0x30, 0x00, 0x36, 0x00, 0x2D, 0x00,\r\n            0x31, 0x00, 0x36, 0x00, 0x31, 0x00, 0x2D, 0x00, 0x36, 0x00, 0x35, 0x00, 0x35, 0x00, 0x35, 0x00,\r\n            0x30, 0x00, 0x36, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x33, 0x00, 0x2D, 0x00, 0x31, 0x00, 0x30, 0x00,\r\n            0x33, 0x00, 0x33, 0x00, 0x2D, 0x00, 0x39, 0x00, 0x32, 0x00, 0x30, 0x00, 0x30, 0x00, 0x2E, 0x00,\r\n            0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x36, 0x00, 0x35, 0x00,\r\n            0x32, 0x00, 0x30, 0x00, 0x31, 0x00, 0x33, 0x00, 0x00, 0x00, 0xDE, 0x19, 0x02, 0xCF, 0x1F, 0x35,\r\n            0x97, 0x4E, 0x8A, 0x8F, 0xB8, 0x07, 0xB1, 0x92, 0xB5, 0xB5, 0x97, 0x42, 0xEC, 0x3A, 0x76, 0x84,\r\n            0xD5, 0x01, 0x32, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x60, 0x27, 0x00, 0x00, 0xC4, 0x1E,\r\n            0xAA, 0x8B, 0xDD, 0x0C, 0xAB, 0x55, 0x6A, 0xCE, 0xAF, 0xAC, 0x7F, 0x5F, 0xBD, 0xE9\r\n        };\r\n\r\n        public static readonly byte[] KMSv5Response =\r\n        {\r\n            0x00, 0x00, 0x05, 0x00, 0xBE, 0x96, 0xF9, 0x04, 0x54, 0x17, 0x3F, 0xAF, 0xE3, 0x08, 0x50, 0xEB,\r\n            0x22, 0xBA, 0x53, 0xBF, 0xF2, 0x6A, 0x7B, 0xC9, 0x05, 0x1D, 0xB5, 0x19, 0xDF, 0x98, 0xE2, 0x71,\r\n            0x4D, 0x00, 0x61, 0xE9, 0x9D, 0x03, 0xFB, 0x31, 0xF9, 0x1F, 0x2E, 0x60, 0x59, 0xC7, 0x73, 0xC8,\r\n            0xE8, 0xB6, 0xE1, 0x2B, 0x39, 0xC6, 0x35, 0x0E, 0x68, 0x7A, 0xAA, 0x4F, 0x28, 0x23, 0x12, 0x18,\r\n            0xE3, 0xAA, 0x84, 0x81, 0x6E, 0x82, 0xF0, 0x3F, 0xD9, 0x69, 0xA9, 0xDF, 0xBA, 0x5F, 0xCA, 0x32,\r\n            0x54, 0xB2, 0x52, 0x3B, 0x3E, 0xD1, 0x5C, 0x65, 0xBC, 0x3E, 0x59, 0x0D, 0x15, 0x9F, 0x37, 0xEC,\r\n            0x30, 0x9C, 0xCC, 0x1B, 0x39, 0x0D, 0x21, 0x32, 0x29, 0xA2, 0xDD, 0xC7, 0xC1, 0x69, 0xF2, 0x72,\r\n            0x3F, 0x00, 0x98, 0x1E, 0xF8, 0x9A, 0x79, 0x44, 0x5D, 0x25, 0x80, 0x7B, 0xF5, 0xE1, 0x7C, 0x68,\r\n            0x25, 0xAA, 0x0D, 0x67, 0x98, 0xE5, 0x59, 0x9B, 0x04, 0xC1, 0x23, 0x33, 0x48, 0xFB, 0x28, 0xD0,\r\n            0x76, 0xDF, 0x01, 0x56, 0xE7, 0xEC, 0xBF, 0x1A, 0xA2, 0x22, 0x28, 0xCA, 0xB1, 0xB4, 0x4C, 0x30,\r\n            0x14, 0x6F, 0xD2, 0x2E, 0x01, 0x2A, 0x04, 0xE3, 0xBD, 0xA7, 0x41, 0x2F, 0xC9, 0xEF, 0x53, 0xC0,\r\n            0x70, 0x48, 0xF1, 0xB2, 0xB6, 0xEA, 0xE7, 0x0F, 0x7A, 0x15, 0xD1, 0xA6, 0xFE, 0x23, 0xC8, 0xF3,\r\n            0xE1, 0x02, 0x9E, 0xA0, 0x4E, 0xBD, 0xF5, 0xEA, 0x53, 0x74, 0x8E, 0x74, 0xA1, 0xA1, 0xBD, 0xBE,\r\n            0x66, 0xC4, 0x73, 0x8F, 0x24, 0xA7, 0x2A, 0x2F, 0xE3, 0xD9, 0xF4, 0x28, 0xD9, 0xF8, 0xA3, 0x93,\r\n            0x03, 0x9E, 0x29, 0xAB\r\n        };\r\n\r\n        public static readonly byte[] KMSv6Response =\r\n        {\r\n            0x00, 0x00, 0x06, 0x00, 0x54, 0xD3, 0x40, 0x08, 0xF3, 0xCD, 0x03, 0xEF, 0xC8, 0x15, 0x87, 0x9E,\r\n            0xCA, 0x2E, 0x85, 0xFB, 0xE6, 0xF6, 0x73, 0x66, 0xFB, 0xDA, 0xBB, 0x7B, 0xB1, 0xBC, 0xD6, 0xF9,\r\n            0x5C, 0x41, 0xA0, 0xFE, 0xE1, 0x74, 0xC4, 0xBB, 0x91, 0xE5, 0xDE, 0x6D, 0x3A, 0x11, 0xD5, 0xFC,\r\n            0x68, 0xC0, 0x7B, 0x82, 0xB2, 0x24, 0xD1, 0x85, 0xBA, 0x45, 0xBF, 0xF1, 0x26, 0xFA, 0xA5, 0xC6,\r\n            0x61, 0x70, 0x69, 0x69, 0x6E, 0x0F, 0x0B, 0x60, 0xB7, 0x3D, 0xE8, 0xF1, 0x47, 0x0B, 0x65, 0xFD,\r\n            0xA7, 0x30, 0x1E, 0xF6, 0xA4, 0xD0, 0x79, 0xC4, 0x58, 0x8D, 0x81, 0xFD, 0xA7, 0xE7, 0x53, 0xF1,\r\n            0x67, 0x78, 0xF0, 0x0F, 0x60, 0x8F, 0xC8, 0x16, 0x35, 0x22, 0x94, 0x48, 0xCB, 0x0F, 0x8E, 0xB2,\r\n            0x1D, 0xF7, 0x3E, 0x28, 0x42, 0x55, 0x6B, 0x07, 0xE3, 0xE8, 0x51, 0xD5, 0xFA, 0x22, 0x0C, 0x86,\r\n            0x65, 0x0D, 0x3F, 0xDD, 0x8D, 0x9B, 0x1B, 0xC9, 0xD3, 0xB8, 0x3A, 0xEC, 0xF1, 0x11, 0x19, 0x25,\r\n            0xF7, 0x84, 0x4A, 0x4C, 0x0A, 0xB5, 0x31, 0x94, 0x37, 0x76, 0xCE, 0xE7, 0xAB, 0xA9, 0x69, 0xDF,\r\n            0xA4, 0xC9, 0x22, 0x6C, 0x23, 0xFF, 0x6B, 0xFC, 0xDA, 0x78, 0xD8, 0xC4, 0x8F, 0x74, 0xBB, 0x26,\r\n            0x05, 0x00, 0x98, 0x9B, 0xE5, 0xE2, 0xAD, 0x0D, 0x57, 0x95, 0x80, 0x66, 0x8E, 0x43, 0x74, 0x87,\r\n            0x93, 0x1F, 0xF4, 0xB2, 0x2C, 0x20, 0x5F, 0xD8, 0x9C, 0x4C, 0x56, 0xB3, 0x57, 0x44, 0x62, 0x68,\r\n            0x8D, 0xAA, 0x40, 0x11, 0x9D, 0x84, 0x62, 0x0E, 0x43, 0x8A, 0x1D, 0xF0, 0x1C, 0x49, 0xD8, 0x56,\r\n            0xEF, 0x4C, 0xD3, 0x64, 0xBA, 0x0D, 0xEF, 0x87, 0xB5, 0x2C, 0x88, 0xF3, 0x18, 0xFF, 0x3A, 0x8C,\r\n            0xF5, 0xA6, 0x78, 0x5C, 0x62, 0xE3, 0x9E, 0x4C, 0xB6, 0x31, 0x2D, 0x06, 0x80, 0x92, 0xBC, 0x2E,\r\n            0x92, 0xA6, 0x56, 0x96\r\n        };\r\n\r\n        // 2^31 - 8 minutes\r\n        public static readonly ulong TimerMax = (ulong)TimeSpan.FromMinutes(2147483640).Ticks;\r\n\r\n        public static readonly string ZeroCID = new string('0', 48);\r\n    }\r\n\r\n    public static class BinaryReaderExt\r\n    {\r\n        public static void Align(this BinaryReader reader, int to)\r\n        {\r\n            int pos = (int)reader.BaseStream.Position;\r\n            reader.BaseStream.Seek(-pos & (to - 1), SeekOrigin.Current);\r\n        }\r\n\r\n        public static string ReadNullTerminatedString(this BinaryReader reader, int maxLen)\r\n        {\r\n            return Encoding.Unicode.GetString(reader.ReadBytes(maxLen)).Split(new char[] { '\\0' }, 2)[0];\r\n        }\r\n    }\r\n\r\n    public static class BinaryWriterExt\r\n    {\r\n        public static void Align(this BinaryWriter writer, int to)\r\n        {\r\n            int pos = (int)writer.BaseStream.Position;\r\n            writer.WritePadding(-pos & (to - 1));\r\n        }\r\n\r\n        public static void WritePadding(this BinaryWriter writer, int len)\r\n        {\r\n            writer.Write(Enumerable.Repeat((byte)0, len).ToArray());\r\n        }\r\n\r\n        public static void WriteFixedString(this BinaryWriter writer, string str, int bLen)\r\n        {\r\n            writer.Write(Encoding.ASCII.GetBytes(str));\r\n            writer.WritePadding(bLen - str.Length);\r\n        }\r\n\r\n        public static void WriteFixedString16(this BinaryWriter writer, string str, int bLen)\r\n        {\r\n            byte[] bstr = Utils.EncodeString(str);\r\n            writer.Write(bstr);\r\n            writer.WritePadding(bLen - bstr.Length);\r\n        }\r\n\r\n        public static byte[] GetBytes(this BinaryWriter writer)\r\n        {\r\n            return ((MemoryStream)writer.BaseStream).ToArray();\r\n        }\r\n    }\r\n\r\n    public static class ByteArrayExt\r\n    {\r\n        public static byte[] CastToArray<T>(this T data) where T : struct\r\n        {\r\n            int size = Marshal.SizeOf(typeof(T));\r\n            byte[] result = new byte[size];\r\n            GCHandle handle = GCHandle.Alloc(result, GCHandleType.Pinned);\r\n            try\r\n            {\r\n                Marshal.StructureToPtr(data, handle.AddrOfPinnedObject(), false);\r\n            }\r\n            finally\r\n            {\r\n                handle.Free();\r\n            }\r\n            return result;\r\n        }\r\n    }\r\n\r\n    public static class FileStreamExt\r\n    {\r\n        public static byte[] ReadAllBytes(this FileStream fs)\r\n        {\r\n            BinaryReader br = new BinaryReader(fs);\r\n            return br.ReadBytes((int)fs.Length);\r\n        }\r\n\r\n        public static void WriteAllBytes(this FileStream fs, byte[] data)\r\n        {\r\n            fs.Seek(0, SeekOrigin.Begin);\r\n            fs.SetLength(data.Length);\r\n            fs.Write(data, 0, data.Length);\r\n        }\r\n    }\r\n\r\n    public static class Utils\r\n    {\r\n        [DllImport(\"kernel32.dll\")]\r\n        public static extern uint GetSystemDefaultLCID();\r\n\r\n        [DllImport(\"kernel32.dll\")]\r\n        public static extern bool Wow64EnableWow64FsRedirection(bool Wow64FsEnableRedirection);\r\n\r\n        public static string DecodeString(byte[] data)\r\n        {\r\n            return Encoding.Unicode.GetString(data).Trim('\\0');\r\n        }\r\n\r\n        public static byte[] EncodeString(string str)\r\n        {\r\n            return Encoding.Unicode.GetBytes(str + '\\0');\r\n        }\r\n\r\n        public static uint CRC32(byte[] data)\r\n        {\r\n            const uint polynomial = 0x04C11DB7;\r\n            uint crc = 0xffffffff;\r\n\r\n            foreach (byte b in data)\r\n            {\r\n                crc ^= (uint)b << 24;\r\n                for (int bit = 0; bit < 8; bit++)\r\n                {\r\n                    if ((crc & 0x80000000) != 0)\r\n                    {\r\n                        crc = (crc << 1) ^ polynomial;\r\n                    }\r\n                    else\r\n                    {\r\n                        crc <<= 1;\r\n                    }\r\n                }\r\n            }\r\n            return ~crc;\r\n        }\r\n\r\n        public static string GetArchitecture()\r\n        {\r\n            string arch = Environment.GetEnvironmentVariable(\"PROCESSOR_ARCHITECTURE\", EnvironmentVariableTarget.Machine).ToUpperInvariant();\r\n            return arch == \"AMD64\" ? \"X64\" : arch;\r\n        }\r\n\r\n        public static PSVersion DetectVersion()\r\n        {\r\n            int build = Environment.OSVersion.Version.Build;\r\n\r\n            if (build >= 9600) return PSVersion.WinModern;\r\n            if (build >= 6000 && build <= 6003) return PSVersion.Vista;\r\n            if (build >= 7600 && build <= 7602) return PSVersion.Win7;\r\n            if (build == 9200) return PSVersion.Win8;\r\n\r\n            throw new NotSupportedException(\"Unable to auto-detect version info\");\r\n        }\r\n    }\r\n\r\n    public static class Logger\r\n    {\r\n        public static bool HideOutput = false;\r\n\r\n        public static void WriteLine(string line)\r\n        {\r\n            if (!HideOutput) Console.WriteLine(line);\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/SPP/PKeyConfig.cs\r\nnamespace LibTSforge.SPP\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using System.Text;\r\n    using System.Xml;\r\n\r\n    public enum PKeyAlgorithm\r\n    {\r\n        PKEY2005,\r\n        PKEY2009\r\n    }\r\n\r\n    public class KeyRange\r\n    {\r\n        public int Start;\r\n        public int End;\r\n        public string EulaType;\r\n        public string PartNumber;\r\n        public bool Valid;\r\n\r\n        public bool Contains(int n)\r\n        {\r\n            return Start <= n && n <= End;\r\n        }\r\n    }\r\n\r\n    public class ProductConfig\r\n    {\r\n        public int GroupId;\r\n        public string Edition;\r\n        public string Description;\r\n        public string Channel;\r\n        public bool Randomized;\r\n        public PKeyAlgorithm Algorithm;\r\n        public List<KeyRange> Ranges;\r\n        public Guid ActivationId;\r\n\r\n        private List<KeyRange> GetPkeyRanges()\r\n        {\r\n            if (Ranges.Count == 0)\r\n            {\r\n                throw new ArgumentException(\"No key ranges.\");\r\n            }\r\n\r\n            if (Algorithm == PKeyAlgorithm.PKEY2005)\r\n            {\r\n                return Ranges;\r\n            }\r\n\r\n            List<KeyRange> FilteredRanges = Ranges.Where(r => !r.EulaType.Contains(\"WAU\")).ToList();\r\n\r\n            if (FilteredRanges.Count == 0)\r\n            {\r\n                throw new NotSupportedException(\"Specified Activation ID is usable only for Windows Anytime Upgrade. Please use a non-WAU Activation ID instead.\");\r\n            }\r\n\r\n            return FilteredRanges;\r\n        }\r\n\r\n        public ProductKey GetRandomKey()\r\n        {\r\n            List<KeyRange> KeyRanges = GetPkeyRanges();\r\n            Random rnd = new Random();\r\n\r\n            KeyRange range = KeyRanges[rnd.Next(KeyRanges.Count)];\r\n            int serial = rnd.Next(range.Start, range.End);\r\n\r\n            return new ProductKey(serial, 0, false, Algorithm, this, range);\r\n        }\r\n    }\r\n\r\n    public class PKeyConfig\r\n    {\r\n        public readonly Dictionary<Guid, ProductConfig> Products = new Dictionary<Guid, ProductConfig>();\r\n        private readonly List<Guid> loadedPkeyConfigs = new List<Guid>();\r\n\r\n        public void LoadConfig(Guid actId)\r\n        {\r\n            string pkcData;\r\n            Guid pkcFileId = SLApi.GetPkeyConfigFileId(actId);\r\n\r\n            if (loadedPkeyConfigs.Contains(pkcFileId)) return;\r\n\r\n            string licConts = SLApi.GetLicenseContents(pkcFileId);\r\n\r\n            using (TextReader tr = new StringReader(licConts))\r\n            {\r\n                XmlDocument lic = new XmlDocument();\r\n                lic.Load(tr);\r\n\r\n                XmlNamespaceManager nsmgr = new XmlNamespaceManager(lic.NameTable);\r\n                nsmgr.AddNamespace(\"rg\", \"urn:mpeg:mpeg21:2003:01-REL-R-NS\");\r\n                nsmgr.AddNamespace(\"r\", \"urn:mpeg:mpeg21:2003:01-REL-R-NS\");\r\n                nsmgr.AddNamespace(\"tm\", \"http://www.microsoft.com/DRM/XrML2/TM/v2\");\r\n\r\n                XmlNode root = lic.DocumentElement;\r\n                XmlNode pkcDataNode = root.SelectSingleNode(\"/rg:licenseGroup/r:license/r:otherInfo/tm:infoTables/tm:infoList/tm:infoBin[@name=\\\"pkeyConfigData\\\"]\", nsmgr);\r\n                pkcData = Encoding.UTF8.GetString(Convert.FromBase64String(pkcDataNode.InnerText));\r\n            }\r\n\r\n            using (TextReader tr = new StringReader(pkcData))\r\n            {\r\n                XmlDocument lic = new XmlDocument();\r\n                lic.Load(tr);\r\n\r\n                XmlNamespaceManager nsmgr = new XmlNamespaceManager(lic.NameTable);\r\n                nsmgr.AddNamespace(\"p\", \"http://www.microsoft.com/DRM/PKEY/Configuration/2.0\");\r\n                XmlNodeList configNodes = lic.SelectNodes(\"//p:ProductKeyConfiguration/p:Configurations/p:Configuration\", nsmgr);\r\n                XmlNodeList rangeNodes = lic.SelectNodes(\"//p:ProductKeyConfiguration/p:KeyRanges/p:KeyRange\", nsmgr);\r\n                XmlNodeList pubKeyNodes = lic.SelectNodes(\"//p:ProductKeyConfiguration/p:PublicKeys/p:PublicKey\", nsmgr);\r\n\r\n                Dictionary<int, PKeyAlgorithm> algorithms = new Dictionary<int, PKeyAlgorithm>();\r\n                Dictionary<string, List<KeyRange>> ranges = new Dictionary<string, List<KeyRange>>();\r\n\r\n                Dictionary<string, PKeyAlgorithm> algoConv = new Dictionary<string, PKeyAlgorithm>\r\n                {\r\n                    { \"msft:rm/algorithm/pkey/2005\", PKeyAlgorithm.PKEY2005 },\r\n                    { \"msft:rm/algorithm/pkey/2009\", PKeyAlgorithm.PKEY2009 }\r\n                };\r\n\r\n                foreach (XmlNode pubKeyNode in pubKeyNodes)\r\n                {\r\n                    int group = int.Parse(pubKeyNode.SelectSingleNode(\"./p:GroupId\", nsmgr).InnerText);\r\n                    algorithms[group] = algoConv[pubKeyNode.SelectSingleNode(\"./p:AlgorithmId\", nsmgr).InnerText];\r\n                }\r\n\r\n                foreach (XmlNode rangeNode in rangeNodes)\r\n                {\r\n                    string refActIdStr = rangeNode.SelectSingleNode(\"./p:RefActConfigId\", nsmgr).InnerText;\r\n\r\n                    if (!ranges.ContainsKey(refActIdStr))\r\n                    {\r\n                        ranges[refActIdStr] = new List<KeyRange>();\r\n                    }\r\n\r\n                    KeyRange keyRange = new KeyRange\r\n                    {\r\n                        Start = int.Parse(rangeNode.SelectSingleNode(\"./p:Start\", nsmgr).InnerText),\r\n                        End = int.Parse(rangeNode.SelectSingleNode(\"./p:End\", nsmgr).InnerText),\r\n                        EulaType = rangeNode.SelectSingleNode(\"./p:EulaType\", nsmgr).InnerText,\r\n                        PartNumber = rangeNode.SelectSingleNode(\"./p:PartNumber\", nsmgr).InnerText,\r\n                        Valid = rangeNode.SelectSingleNode(\"./p:IsValid\", nsmgr).InnerText.ToLower() == \"true\"\r\n                    };\r\n\r\n                    ranges[refActIdStr].Add(keyRange);\r\n                }\r\n\r\n                foreach (XmlNode configNode in configNodes)\r\n                {\r\n                    string refActIdStr = configNode.SelectSingleNode(\"./p:ActConfigId\", nsmgr).InnerText;\r\n                    Guid refActId = new Guid(refActIdStr);\r\n                    int group = int.Parse(configNode.SelectSingleNode(\"./p:RefGroupId\", nsmgr).InnerText);\r\n                    List<KeyRange> keyRanges;\r\n                    ranges.TryGetValue(refActIdStr, out keyRanges);\r\n\r\n                    if (keyRanges == null) \r\n                    {\r\n                        continue;\r\n                    }\r\n\r\n                    if (keyRanges.Count > 0 && !Products.ContainsKey(refActId))\r\n                    {\r\n                        PKeyAlgorithm algorithm;\r\n                        algorithms.TryGetValue(group, out algorithm);\r\n\r\n                        ProductConfig productConfig = new ProductConfig\r\n                        {\r\n                            GroupId = group,\r\n                            Edition = configNode.SelectSingleNode(\"./p:EditionId\", nsmgr).InnerText,\r\n                            Description = configNode.SelectSingleNode(\"./p:ProductDescription\", nsmgr).InnerText,\r\n                            Channel = configNode.SelectSingleNode(\"./p:ProductKeyType\", nsmgr).InnerText,\r\n                            Randomized = configNode.SelectSingleNode(\"./p:ProductKeyType\", nsmgr).InnerText.ToLower() == \"true\",\r\n                            Algorithm = algorithm,\r\n                            Ranges = keyRanges,\r\n                            ActivationId = refActId\r\n                        };\r\n\r\n                        Products[refActId] = productConfig;\r\n                    }\r\n                }\r\n            }\r\n\r\n            loadedPkeyConfigs.Add(pkcFileId);\r\n        }\r\n\r\n        public ProductConfig MatchParams(int group, int serial)\r\n        {\r\n            foreach (ProductConfig config in Products.Values)\r\n            {\r\n                if (config.GroupId == group)\r\n                {\r\n                    foreach (KeyRange range in config.Ranges)\r\n                    {\r\n                        if (range.Contains(serial))\r\n                        {\r\n                            return config;\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n\r\n            throw new FileNotFoundException(\"Failed to find product matching supplied product key parameters.\");\r\n        }\r\n\r\n        public void LoadAllConfigs(Guid appId)\r\n        {\r\n            foreach (Guid actId in SLApi.GetActivationIds(appId))\r\n            {\r\n                try\r\n                {\r\n                    LoadConfig(actId);\r\n                } \r\n                catch (ArgumentException)\r\n                {\r\n\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/SPP/ProductKey.cs\r\nnamespace LibTSforge.SPP\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using Crypto;\r\n    using PhysicalStore;\r\n\r\n    public class ProductKey\r\n    {\r\n        private static readonly string ALPHABET = \"BCDFGHJKMPQRTVWXY2346789\";\r\n\r\n        private readonly ulong klow;\r\n        private readonly ulong khigh;\r\n\r\n        public int Group;\r\n        public int Serial;\r\n        public ulong Security;\r\n        public bool Upgrade;\r\n        public PKeyAlgorithm Algorithm;\r\n        public readonly string EulaType;\r\n        public readonly string PartNumber;\r\n        public readonly string Edition;\r\n        public readonly string Channel;\r\n        public readonly Guid ActivationId;\r\n\r\n        private string mpc;\r\n        private string pid2;\r\n\r\n        public byte[] KeyBytes\r\n        {\r\n            get { return BitConverter.GetBytes(klow).Concat(BitConverter.GetBytes(khigh)).ToArray(); }\r\n        }\r\n\r\n        public ProductKey()\r\n        {\r\n\r\n        }\r\n\r\n        public ProductKey(int serial, ulong security, bool upgrade, PKeyAlgorithm algorithm, ProductConfig config, KeyRange range)\r\n        {\r\n            Group = config.GroupId;\r\n            Serial = serial;\r\n            Security = security;\r\n            Upgrade = upgrade;\r\n            Algorithm = algorithm;\r\n            EulaType = range.EulaType;\r\n            PartNumber = range.PartNumber.Split(':', ';')[0];\r\n            Edition = config.Edition;\r\n            Channel = config.Channel;\r\n            ActivationId = config.ActivationId;\r\n\r\n            klow = ((security & 0x3fff) << 50 | ((ulong)serial & 0x3fffffff) << 20 | ((ulong)Group & 0xfffff));\r\n            khigh = ((upgrade ? (ulong)1 : 0) << 49 | ((security >> 14) & 0x7fffffffff));\r\n\r\n            uint checksum = Utils.CRC32(KeyBytes) & 0x3ff;\r\n\r\n            khigh |= ((ulong)checksum << 39);\r\n        }\r\n\r\n        public string GetAlgoUri()\r\n        {\r\n            return \"msft:rm/algorithm/pkey/\" + (Algorithm == PKeyAlgorithm.PKEY2005 ? \"2005\" : (Algorithm == PKeyAlgorithm.PKEY2009 ? \"2009\" : \"Unknown\"));\r\n        }\r\n\r\n        public Guid GetPkeyId()\r\n        {\r\n            VariableBag pkb = new VariableBag(PSVersion.WinModern);\r\n            pkb.Blocks.AddRange(new[]\r\n            {\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyBindingProductKey\",\r\n                    ValueAsStr = ToString()\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = \"SppPkeyBindingMiscData\",\r\n                    Value = new byte[] { }\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyBindingAlgorithm\",\r\n                    ValueAsStr = GetAlgoUri()\r\n                }\r\n            });\r\n\r\n            return new Guid(CryptoUtils.SHA256Hash(pkb.Serialize()).Take(16).ToArray());\r\n        }\r\n\r\n        public string GetMPC()\r\n        {\r\n            if (mpc != null)\r\n            {\r\n                return mpc;\r\n            }\r\n\r\n            int build = Environment.OSVersion.Version.Build;\r\n\r\n            mpc = build >= 10240 ? \"03612\" :\r\n                    build >= 9600 ? \"06401\" :\r\n                    build >= 9200 ? \"05426\" :\r\n                    \"55041\";\r\n\r\n            // setup.cfg doesn't exist in Windows 8+\r\n            string setupcfg = string.Format(@\"{0}\\oobe\\{1}\", Environment.SystemDirectory, \"setup.cfg\");\r\n\r\n            if (!File.Exists(setupcfg) || Edition.Contains(\";\"))\r\n            {\r\n                return mpc;\r\n            }\r\n\r\n            string mpcKey = string.Format(\"{0}.{1}=\", Utils.GetArchitecture(), Edition);\r\n            string localMPC = File.ReadAllLines(setupcfg).FirstOrDefault(line => line.Contains(mpcKey));\r\n            if (localMPC != null)\r\n            {\r\n                mpc = localMPC.Split('=')[1].Trim();\r\n            }\r\n\r\n            return mpc;\r\n        }\r\n\r\n        public string GetPid2()\r\n        {\r\n            if (pid2 != null)\r\n            {\r\n                return pid2;\r\n            }\r\n\r\n            pid2 = \"\";\r\n\r\n            if (Algorithm == PKeyAlgorithm.PKEY2005)\r\n            {\r\n                string mpc = GetMPC();\r\n                string serialHigh;\r\n                int serialLow;\r\n                int lastPart;\r\n\r\n                if (EulaType == \"OEM\")\r\n                {\r\n                    serialHigh = \"OEM\";\r\n                    serialLow = ((Group / 2) % 100) * 10000 + (Serial / 100000);\r\n                    lastPart = Serial % 100000;\r\n                }\r\n                else\r\n                {\r\n                    serialHigh = (Serial / 1000000).ToString(\"D3\");\r\n                    serialLow = Serial % 1000000;\r\n                    lastPart = ((Group / 2) % 100) * 1000 + new Random().Next(1000);\r\n                }\r\n\r\n                int checksum = 0;\r\n\r\n                foreach (char c in serialLow.ToString())\r\n                {\r\n                    checksum += int.Parse(c.ToString());\r\n                }\r\n                checksum = 7 - (checksum % 7);\r\n\r\n                pid2 = string.Format(\"{0}-{1}-{2:D6}{3}-{4:D5}\", mpc, serialHigh, serialLow, checksum, lastPart);\r\n            }\r\n\r\n            return pid2;\r\n        }\r\n\r\n        public byte[] GetPid3()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(0xA4);\r\n            writer.Write(0x3);\r\n            writer.WriteFixedString(GetPid2(), 24);\r\n            writer.Write(Group);\r\n            writer.WriteFixedString(PartNumber, 16);\r\n            writer.WritePadding(0x6C);\r\n            byte[] data = writer.GetBytes();\r\n            byte[] crc = BitConverter.GetBytes(~Utils.CRC32(data.Reverse().ToArray())).Reverse().ToArray();\r\n            writer.Write(crc);\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public byte[] GetPid4()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(0x4F8);\r\n            writer.Write(0x4);\r\n            writer.WriteFixedString16(GetExtendedPid(), 0x80);\r\n            writer.WriteFixedString16(ActivationId.ToString(), 0x80);\r\n            writer.WritePadding(0x10);\r\n            writer.WriteFixedString16(Edition, 0x208);\r\n            writer.Write(Upgrade ? (ulong)1 : 0);\r\n            writer.WritePadding(0x50);\r\n            writer.WriteFixedString16(PartNumber, 0x80);\r\n            writer.WriteFixedString16(Channel, 0x80);\r\n            writer.WriteFixedString16(EulaType, 0x80);\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public string GetExtendedPid()\r\n        {\r\n            string mpc = GetMPC();\r\n            int serialHigh = Serial / 1000000;\r\n            int serialLow = Serial % 1000000;\r\n            int licenseType;\r\n            uint lcid = Utils.GetSystemDefaultLCID();\r\n            int build = Environment.OSVersion.Version.Build;\r\n            int dayOfYear = DateTime.Now.DayOfYear;\r\n            int year = DateTime.Now.Year;\r\n\r\n            switch (EulaType)\r\n            {\r\n                case \"OEM\":\r\n                    licenseType = 2;\r\n                    break;\r\n\r\n                case \"Volume\":\r\n                    licenseType = 3;\r\n                    break;\r\n\r\n                default:\r\n                    licenseType = 0;\r\n                    break;\r\n            }\r\n\r\n            return string.Format(\r\n                \"{0}-{1:D5}-{2:D3}-{3:D6}-{4:D2}-{5:D4}-{6:D4}.0000-{7:D3}{8:D4}\",\r\n                mpc,\r\n                Group,\r\n                serialHigh,\r\n                serialLow,\r\n                licenseType,\r\n                lcid,\r\n                build,\r\n                dayOfYear,\r\n                year\r\n            );\r\n        }\r\n\r\n        public byte[] GetPhoneData(PSVersion version)\r\n        {\r\n            if (version == PSVersion.Win7)\r\n            {\r\n                ulong shortauth = ((ulong)Group << 41) | (Security << 31) | ((ulong)Serial << 1) | (Upgrade ? (ulong)1 : 0);\r\n                return BitConverter.GetBytes(shortauth);\r\n            }\r\n\r\n            int serialHigh = Serial / 1000000;\r\n            int serialLow = Serial % 1000000;\r\n\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            string algoId = Algorithm == PKeyAlgorithm.PKEY2005 ? \"B8731595-A2F6-430B-A799-FBFFB81A8D73\" : \"660672EF-7809-4CFD-8D54-41B7FB738988\";\r\n\r\n            writer.Write(new Guid(algoId).ToByteArray());\r\n            writer.Write(Group);\r\n            writer.Write(serialHigh);\r\n            writer.Write(serialLow);\r\n            writer.Write(Upgrade ? 1 : 0);\r\n            writer.Write(Security);\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public override string ToString()\r\n        {\r\n            string keyStr = \"\";\r\n            Random rnd = new Random(Group * 1000000000 + Serial);\r\n\r\n            if (Algorithm == PKeyAlgorithm.PKEY2005)\r\n            {\r\n                keyStr = \"H4X3DH4X3DH4X3DH4X3D\";\r\n\r\n                for (int i = 0; i < 5; i++)\r\n                {\r\n                    keyStr += ALPHABET[rnd.Next(24)];\r\n                }\r\n            }\r\n            else if (Algorithm == PKeyAlgorithm.PKEY2009)\r\n            {\r\n                int last = 0;\r\n                byte[] bKey = KeyBytes;\r\n\r\n                for (int i = 24; i >= 0; i--)\r\n                {\r\n                    int current = 0;\r\n\r\n                    for (int j = 14; j >= 0; j--)\r\n                    {\r\n                        current *= 0x100;\r\n                        current += bKey[j];\r\n                        bKey[j] = (byte)(current / 24);\r\n                        current %= 24;\r\n                        last = current;\r\n                    }\r\n\r\n                    keyStr = ALPHABET[current] + keyStr;\r\n                }\r\n\r\n                keyStr = keyStr.Substring(1, last) + \"N\" + keyStr.Substring(last + 1, keyStr.Length - last - 1);\r\n            }\r\n\r\n            for (int i = 5; i < keyStr.Length; i += 6)\r\n            {\r\n                keyStr = keyStr.Insert(i, \"-\");\r\n            }\r\n\r\n            return keyStr;\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/SPP/SLAPI.cs\r\nnamespace LibTSforge.SPP\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.Linq;\r\n    using System.Runtime.InteropServices;\r\n    using System.Text;\r\n\r\n    public static class SLApi\r\n    {\r\n        private enum SLIDTYPE\r\n        {\r\n            SL_ID_APPLICATION,\r\n            SL_ID_PRODUCT_SKU,\r\n            SL_ID_LICENSE_FILE,\r\n            SL_ID_LICENSE,\r\n            SL_ID_PKEY,\r\n            SL_ID_ALL_LICENSES,\r\n            SL_ID_ALL_LICENSE_FILES,\r\n            SL_ID_STORE_TOKEN,\r\n            SL_ID_LAST\r\n        }\r\n\r\n        private enum SLDATATYPE\r\n        {\r\n            SL_DATA_NONE,\r\n            SL_DATA_SZ,\r\n            SL_DATA_DWORD,\r\n            SL_DATA_BINARY,\r\n            SL_DATA_MULTI_SZ,\r\n            SL_DATA_SUM\r\n        }\r\n\r\n        [StructLayout(LayoutKind.Sequential)]\r\n        private struct SL_LICENSING_STATUS\r\n        {\r\n            public Guid SkuId;\r\n            public uint eStatus;\r\n            public uint dwGraceTime;\r\n            public uint dwTotalGraceDays;\r\n            public uint hrReason;\r\n            public ulong qwValidityExpiration;\r\n        }\r\n\r\n        public static readonly Guid WINDOWS_APP_ID = new Guid(\"55c92734-d682-4d71-983e-d6ec3f16059f\");\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode, PreserveSig = false)]\r\n        private static extern void SLOpen(out IntPtr hSLC);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode, PreserveSig = false)]\r\n        private static extern void SLClose(IntPtr hSLC);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetWindowsInformationDWORD(string ValueName, ref int Value);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLInstallProofOfPurchase(IntPtr hSLC, string pwszPKeyAlgorithm, string pwszPKeyString, uint cbPKeySpecificData, byte[] pbPKeySpecificData, ref Guid PKeyId);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLUninstallProofOfPurchase(IntPtr hSLC, ref Guid PKeyId);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetPKeyInformation(IntPtr hSLC, ref Guid pPKeyId, string pwszValueName, out SLDATATYPE peDataType, out uint pcbValue, out IntPtr ppbValue);\r\n\r\n        [DllImport(\"slcext.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLActivateProduct(IntPtr hSLC, ref Guid pProductSkuId, byte[] cbAppSpecificData, byte[] pvAppSpecificData, byte[] pActivationInfo, string pwszProxyServer, ushort wProxyPort);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGenerateOfflineInstallationId(IntPtr hSLC, ref Guid pProductSkuId, ref string ppwszInstallationId);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLDepositOfflineConfirmationId(IntPtr hSLC, ref Guid pProductSkuId, string pwszInstallationId, string pwszConfirmationId);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetSLIDList(IntPtr hSLC, SLIDTYPE eQueryIdType, ref Guid pQueryId, SLIDTYPE eReturnIdType, out uint pnReturnIds, out IntPtr ppReturnIds);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode, PreserveSig = false)]\r\n        private static extern void SLGetLicensingStatusInformation(IntPtr hSLC, ref Guid pAppID, IntPtr pProductSkuId, string pwszRightName, out uint pnStatusCount, out IntPtr ppLicensingStatus);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetInstalledProductKeyIds(IntPtr hSLC, ref Guid pProductSkuId, out uint pnProductKeyIds, out IntPtr ppProductKeyIds);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLConsumeWindowsRight(uint unknown);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetProductSkuInformation(IntPtr hSLC, ref Guid pProductSkuId, string pwszValueName, out SLDATATYPE peDataType, out uint pcbValue, out IntPtr ppbValue);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLGetLicense(IntPtr hSLC, ref Guid pLicenseFileId, out uint pcbLicenseFile, out IntPtr ppbLicenseFile);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLSetCurrentProductKey(IntPtr hSLC, ref Guid pProductSkuId, ref Guid pProductKeyId);\r\n\r\n        [DllImport(\"slc.dll\", CharSet = CharSet.Unicode)]\r\n        private static extern uint SLFireEvent(IntPtr hSLC, string pwszEventId, ref Guid pApplicationId);\r\n\r\n        private class SLContext : IDisposable\r\n        {\r\n            public readonly IntPtr Handle;\r\n\r\n            public SLContext()\r\n            {\r\n                SLOpen(out Handle);\r\n            }\r\n\r\n            public void Dispose()\r\n            {\r\n                SLClose(Handle);\r\n                GC.SuppressFinalize(this);\r\n            }\r\n\r\n            ~SLContext()\r\n            {\r\n                Dispose();\r\n            }\r\n        }\r\n\r\n        public static Guid GetDefaultActivationID(Guid appId, bool includeActivated)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                IntPtr pLicStat;\r\n\r\n                SLGetLicensingStatusInformation(sl.Handle, ref appId, IntPtr.Zero, null, out count, out pLicStat);\r\n\r\n                unsafe\r\n                {\r\n                    SL_LICENSING_STATUS* licensingStatuses = (SL_LICENSING_STATUS*)pLicStat;\r\n                    for (int i = 0; i < count; i++)\r\n                    {\r\n                        SL_LICENSING_STATUS slStatus = licensingStatuses[i];\r\n\r\n                        Guid actId = slStatus.SkuId;\r\n                        if (GetInstalledPkeyID(actId) == Guid.Empty) continue;\r\n                        if (IsAddon(actId)) continue;\r\n                        if (!includeActivated && (slStatus.eStatus == 1)) continue;\r\n\r\n                        return actId;\r\n                    }\r\n                }\r\n\r\n                return Guid.Empty;\r\n            }\r\n        }\r\n\r\n        public static string GetInstallationID(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                string installationId = null;\r\n                return SLGenerateOfflineInstallationId(sl.Handle, ref actId, ref installationId) == 0 ? installationId : null;\r\n            }\r\n        }\r\n\r\n        public static Guid GetInstalledPkeyID(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                IntPtr pProductKeyIds;\r\n\r\n                uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_PKEY, out count, out pProductKeyIds);\r\n\r\n                if (status != 0 || count == 0)\r\n                {\r\n                    return Guid.Empty;\r\n                }\r\n\r\n                unsafe { return *(Guid*)pProductKeyIds; }\r\n            }\r\n        }\r\n\r\n        public static uint DepositConfirmationID(Guid actId, string installationId, string confirmationId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                return SLDepositOfflineConfirmationId(sl.Handle, ref actId, installationId, confirmationId);\r\n            }\r\n        }\r\n\r\n        public static void RefreshLicenseStatus()\r\n        {\r\n            SLConsumeWindowsRight(0);\r\n        }\r\n\r\n        public static void RefreshTrustedTime(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                SLDATATYPE type;\r\n                uint count;\r\n                IntPtr ppbValue;\r\n\r\n                SLGetProductSkuInformation(sl.Handle, ref actId, \"TrustedTime\", out type, out count, out ppbValue);\r\n            }\r\n        }\r\n\r\n        public static void FireStateChangedEvent(Guid appId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                SLFireEvent(sl.Handle, \"msft:rm/event/licensingstatechanged\", ref appId);\r\n            }\r\n        }\r\n\r\n        public static Guid GetAppId(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                IntPtr pAppIds;\r\n\r\n                uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_APPLICATION, out count, out pAppIds);\r\n\r\n                if (status != 0 || count == 0)\r\n                {\r\n                    return Guid.Empty;\r\n                }\r\n\r\n                unsafe { return *(Guid*)pAppIds; }\r\n            }\r\n        }\r\n\r\n        public static bool IsAddon(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                SLDATATYPE type;\r\n                IntPtr ppbValue;\r\n\r\n                uint status = SLGetProductSkuInformation(sl.Handle, ref actId, \"DependsOn\", out type, out count, out ppbValue);\r\n                return (int)status >= 0 && status != 0xC004F012;\r\n            }\r\n        }\r\n\r\n        public static Guid GetLicenseFileId(Guid licId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                IntPtr ppReturnLics;\r\n\r\n                uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_LICENSE, ref licId, SLIDTYPE.SL_ID_LICENSE_FILE, out count, out ppReturnLics);\r\n\r\n                if (status != 0 || count == 0)\r\n                {\r\n                    return Guid.Empty;\r\n                }\r\n\r\n                unsafe { return *(Guid*)ppReturnLics; }\r\n            }\r\n        }\r\n\r\n        public static Guid GetPkeyConfigFileId(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                SLDATATYPE type;\r\n                uint len;\r\n                IntPtr ppReturnLics;\r\n\r\n                uint status = SLGetProductSkuInformation(sl.Handle, ref actId, \"pkeyConfigLicenseId\", out type, out len, out ppReturnLics);\r\n\r\n                if (status != 0 || len == 0)\r\n                {\r\n                    return Guid.Empty;\r\n                }\r\n\r\n                Guid pkcId = new Guid(Marshal.PtrToStringAuto(ppReturnLics));\r\n                return GetLicenseFileId(pkcId);\r\n            }\r\n        }\r\n\r\n        public static string GetLicenseContents(Guid fileId)\r\n        {\r\n            if (fileId == Guid.Empty) throw new ArgumentException(\"License contents could not be retrieved.\");\r\n\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint dataLen;\r\n                IntPtr dataPtr;\r\n\r\n                if (SLGetLicense(sl.Handle, ref fileId, out dataLen, out dataPtr) != 0)\r\n                {\r\n                    return null;\r\n                }\r\n\r\n                byte[] data = new byte[dataLen];\r\n                Marshal.Copy(dataPtr, data, 0, (int)dataLen);\r\n\r\n                data = data.Skip(Array.IndexOf(data, (byte)'<')).ToArray();\r\n                return Encoding.UTF8.GetString(data);\r\n            }\r\n        }\r\n\r\n        public static bool IsPhoneActivatable(Guid actId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                SLDATATYPE type;\r\n                IntPtr ppbValue;\r\n\r\n                uint status = SLGetProductSkuInformation(sl.Handle, ref actId, \"msft:sl/EUL/PHONE/PUBLIC\", out type, out count, out ppbValue);\r\n                return status != 0xC004F012;\r\n            }\r\n        }\r\n\r\n        public static string GetPKeyChannel(Guid pkeyId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                SLDATATYPE type;\r\n                uint len;\r\n                IntPtr ppbValue;\r\n\r\n                uint status = SLGetPKeyInformation(sl.Handle, ref pkeyId, \"Channel\", out type, out len, out ppbValue);\r\n\r\n                if (status != 0 || len == 0)\r\n                {\r\n                    return null;\r\n                }\r\n\r\n                return Marshal.PtrToStringAuto(ppbValue);\r\n            }\r\n        }\r\n\r\n        public static string GetMetaStr(Guid actId, string value)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint len;\r\n                SLDATATYPE type;\r\n                IntPtr ppbValue;\r\n\r\n                uint status = SLGetProductSkuInformation(sl.Handle, ref actId, value, out type, out len, out ppbValue);\r\n\r\n                if (status != 0 || len == 0 || type != SLDATATYPE.SL_DATA_SZ)\r\n                {\r\n                    return null;\r\n                }\r\n\r\n                return Marshal.PtrToStringAuto(ppbValue);\r\n            }\r\n        }\r\n\r\n        public static List<Guid> GetActivationIds(Guid appId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                uint count;\r\n                IntPtr pLicStat;\r\n\r\n                SLGetLicensingStatusInformation(sl.Handle, ref appId, IntPtr.Zero, null, out count, out pLicStat);\r\n\r\n                List<Guid> result = new List<Guid>();\r\n\r\n                unsafe\r\n                {\r\n                    SL_LICENSING_STATUS* licensingStatuses = (SL_LICENSING_STATUS*)pLicStat;\r\n                    for (int i = 0; i < count; i++)\r\n                    {\r\n                        result.Add(licensingStatuses[i].SkuId);\r\n                    }\r\n                }\r\n\r\n                return result;\r\n            }\r\n        }\r\n\r\n        public static uint SetCurrentProductKey(Guid actId, Guid pkeyId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                return SLSetCurrentProductKey(sl.Handle, ref actId, ref pkeyId);\r\n            }\r\n        }\r\n\r\n        public static uint InstallProductKey(ProductKey pkey)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                Guid pkeyId = Guid.Empty;\r\n                return SLInstallProofOfPurchase(sl.Handle, pkey.GetAlgoUri(), pkey.ToString(), 0, null, ref pkeyId);\r\n            }\r\n        }\r\n\r\n        public static void UninstallProductKey(Guid pkeyId)\r\n        {\r\n            using (SLContext sl = new SLContext())\r\n            {\r\n                SLUninstallProofOfPurchase(sl.Handle, ref pkeyId);\r\n            }\r\n        }\r\n\r\n        public static void UninstallAllProductKeys(Guid appId)\r\n        {\r\n            foreach (Guid actId in GetActivationIds(appId))\r\n            {\r\n                Guid pkeyId = GetInstalledPkeyID(actId);\r\n                if (pkeyId == Guid.Empty) continue;\r\n                if (IsAddon(actId)) continue;\r\n                UninstallProductKey(pkeyId);\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/SPP/SPPUtils.cs\r\nnamespace LibTSforge.SPP\r\n{\r\n    using Microsoft.Win32;\r\n    using System;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using System.ServiceProcess;\r\n    using Crypto;\r\n    using PhysicalStore;\r\n    using TokenStore;\r\n\r\n    public static class SPPUtils\r\n    {\r\n        public static void KillSPP(PSVersion version)\r\n        {\r\n            ServiceController sc;\r\n\r\n            string svcName = version == PSVersion.Vista ? \"slsvc\" : \"sppsvc\";\r\n\r\n            try\r\n            {\r\n                sc = new ServiceController(svcName);\r\n\r\n                if (sc.Status == ServiceControllerStatus.Stopped)\r\n                    return;\r\n            }\r\n            catch (InvalidOperationException ex)\r\n            {\r\n                throw new InvalidOperationException(string.Format(\"Unable to access {0}: \", svcName) + ex.Message);\r\n            }\r\n\r\n            Logger.WriteLine(string.Format(\"Stopping {0}...\", svcName));\r\n\r\n            bool stopped = false;\r\n\r\n            for (int i = 0; stopped == false && i < 1080; i++)\r\n            {\r\n                try\r\n                {\r\n                    if (sc.Status != ServiceControllerStatus.StopPending)\r\n                        sc.Stop();\r\n\r\n                    sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(500));\r\n                }\r\n                catch (System.ServiceProcess.TimeoutException)\r\n                {\r\n                    continue;\r\n                }\r\n                catch (InvalidOperationException ex)\r\n                {\r\n                    Logger.WriteLine(\"Warning: Stopping sppsvc failed, retrying. Details: \" + ex.Message);\r\n                    System.Threading.Thread.Sleep(500);\r\n                    continue;\r\n                }\r\n\r\n                stopped = true;\r\n            }\r\n\r\n            if (!stopped)\r\n                throw new System.TimeoutException(string.Format(\"Failed to stop {0}\", svcName));\r\n\r\n            Logger.WriteLine(string.Format(\"{0} stopped successfully.\", svcName));\r\n\r\n            if (version == PSVersion.Vista && SPSys.IsSpSysRunning())\r\n            {\r\n                Logger.WriteLine(\"Unloading spsys...\");\r\n\r\n                int status = SPSys.ControlSpSys(false);\r\n\r\n                if (status < 0)\r\n                {\r\n                    throw new IOException(\"Failed to unload spsys\");\r\n                }\r\n\r\n                Logger.WriteLine(\"spsys unloaded successfully.\");\r\n            }\r\n        }\r\n\r\n        public static void RestartSPP(PSVersion version)\r\n        {\r\n            if (version == PSVersion.Vista)\r\n            {\r\n                ServiceController sc;\r\n\r\n                try\r\n                {\r\n                    sc = new ServiceController(\"slsvc\");\r\n\r\n                    if (sc.Status == ServiceControllerStatus.Running)\r\n                        return;\r\n                }\r\n                catch (InvalidOperationException ex)\r\n                {\r\n                    throw new InvalidOperationException(\"Unable to access slsvc: \" + ex.Message);\r\n                }\r\n\r\n                Logger.WriteLine(\"Starting slsvc...\");\r\n\r\n                bool started = false;\r\n\r\n                for (int i = 0; started == false && i < 360; i++)\r\n                {\r\n                    try\r\n                    {\r\n                        if (sc.Status != ServiceControllerStatus.StartPending)\r\n                            sc.Start();\r\n\r\n                        sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMilliseconds(500));\r\n                    }\r\n                    catch (System.ServiceProcess.TimeoutException)\r\n                    {\r\n                        continue;\r\n                    }\r\n                    catch (InvalidOperationException ex)\r\n                    {\r\n                        Logger.WriteLine(\"Warning: Starting slsvc failed, retrying. Details: \" + ex.Message);\r\n                        System.Threading.Thread.Sleep(500);\r\n                        continue;\r\n                    }\r\n\r\n                    started = true;\r\n                }\r\n\r\n                if (!started)\r\n                    throw new System.TimeoutException(\"Failed to start slsvc\");\r\n\r\n                Logger.WriteLine(\"slsvc started successfully.\");\r\n            }\r\n\r\n            SLApi.RefreshLicenseStatus();\r\n        }\r\n\r\n        public static bool DetectCurrentKey()\r\n        {\r\n            SLApi.RefreshLicenseStatus();\r\n\r\n            using (RegistryKey wpaKey = Registry.LocalMachine.OpenSubKey(@\"SYSTEM\\WPA\"))\r\n            {\r\n                foreach (string subKey in wpaKey.GetSubKeyNames())\r\n                {\r\n                    if (subKey.StartsWith(\"8DEC0AF1\"))\r\n                    {\r\n                        return subKey.Contains(\"P\");\r\n                    }\r\n                }\r\n            }\r\n\r\n            throw new FileNotFoundException(\"Failed to autodetect key type, specify physical store key with /prod or /test arguments.\");\r\n        }\r\n\r\n        public static string GetPSPath(PSVersion version)\r\n        {\r\n            switch (version)\r\n            {\r\n                case PSVersion.Vista:\r\n                case PSVersion.Win7:\r\n                    return Directory.GetFiles(\r\n                        Environment.GetFolderPath(Environment.SpecialFolder.System),\r\n                        \"7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0\")\r\n                    .FirstOrDefault() ?? \"\";\r\n                default:\r\n                    string psDir = Environment.ExpandEnvironmentVariables(\r\n                        (string)Registry.GetValue(\r\n                            @\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\",\r\n                            \"TokenStore\",\r\n                            \"\"\r\n                        )\r\n                    );\r\n                    string psPath = Path.Combine(psDir, \"data.dat\");\r\n\r\n                    if (string.IsNullOrEmpty(psDir) || !File.Exists(psPath))\r\n                    {\r\n                        string[] psDirs =\r\n                        {\r\n                            @\"spp\\store\",\r\n                            @\"spp\\store\\2.0\",\r\n                            @\"spp\\store_test\",\r\n                            @\"spp\\store_test\\2.0\"\r\n                        };\r\n\r\n                        foreach (string dir in psDirs)\r\n                        {\r\n                            psPath = Path.Combine(\r\n                                Path.Combine(\r\n                                    Environment.GetFolderPath(Environment.SpecialFolder.System),\r\n                                    dir\r\n                                ),\r\n                                \"data.dat\"\r\n                            );\r\n\r\n                            if (File.Exists(psPath)) return psPath;\r\n                        }\r\n                    } \r\n                    else\r\n                    {\r\n                        return psPath;\r\n                    }\r\n\r\n                    throw new FileNotFoundException(\"Failed to locate physical store.\");\r\n            }\r\n        }\r\n\r\n        public static string GetTokensPath(PSVersion version)\r\n        {\r\n            switch (version)\r\n            {\r\n                case PSVersion.Vista:\r\n                    return Path.Combine(\r\n                        Environment.ExpandEnvironmentVariables(\"%WINDIR%\"),\r\n                        @\"ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareLicensing\\tokens.dat\"\r\n                    );\r\n                case PSVersion.Win7:\r\n                    return Path.Combine(\r\n                        Environment.ExpandEnvironmentVariables(\"%WINDIR%\"),\r\n                        @\"ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareProtectionPlatform\\tokens.dat\"\r\n                    );\r\n                default:\r\n                    string tokDir = Environment.ExpandEnvironmentVariables(\r\n                        (string)Registry.GetValue(\r\n                            @\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\",\r\n                            \"TokenStore\",\r\n                            \"\"\r\n                        )\r\n                    );\r\n                    string tokPath = Path.Combine(tokDir, \"tokens.dat\");\r\n\r\n                    if (string.IsNullOrEmpty(tokDir) || !File.Exists(tokPath))\r\n                    {\r\n                        string[] tokDirs =\r\n                        {\r\n                            @\"spp\\store\",\r\n                            @\"spp\\store\\2.0\",\r\n                            @\"spp\\store_test\",\r\n                            @\"spp\\store_test\\2.0\"\r\n                        };\r\n\r\n                        foreach (string dir in tokDirs)\r\n                        {\r\n                            tokPath = Path.Combine(\r\n                                Path.Combine(\r\n                                    Environment.GetFolderPath(Environment.SpecialFolder.System),\r\n                                    dir\r\n                                ),\r\n                                \"tokens.dat\"\r\n                            );\r\n\r\n                            if (File.Exists(tokPath)) return tokPath;\r\n                        }\r\n                    }\r\n                    else\r\n                    {\r\n                        return tokPath;\r\n                    }\r\n\r\n                    throw new FileNotFoundException(\"Failed to locate token store.\");\r\n            }\r\n        }\r\n\r\n        public static IPhysicalStore GetStore(PSVersion version, bool production)\r\n        {\r\n            string psPath = GetPSPath(version);\r\n\r\n            switch (version)\r\n            {\r\n                case PSVersion.Vista:\r\n                    return new PhysicalStoreVista(psPath, production);\r\n                case PSVersion.Win7:\r\n                    return new PhysicalStoreWin7(psPath, production);\r\n                default:\r\n                    return new PhysicalStoreModern(psPath, production, version);\r\n            }\r\n        }\r\n\r\n        public static ITokenStore GetTokenStore(PSVersion version)\r\n        {\r\n            string tokPath = GetTokensPath(version);\r\n\r\n            return new TokenStoreModern(tokPath);\r\n        }\r\n\r\n        public static void DumpStore(PSVersion version, bool production, string filePath, string encrFilePath)\r\n        {\r\n            bool manageSpp = false;\r\n\r\n            if (encrFilePath == null)\r\n            {\r\n                encrFilePath = GetPSPath(version);\r\n                manageSpp = true;\r\n                KillSPP(version);\r\n            }\r\n\r\n            if (string.IsNullOrEmpty(encrFilePath) || !File.Exists(encrFilePath))\r\n            {\r\n                throw new FileNotFoundException(\"Store does not exist at expected path '\" + encrFilePath + \"'.\");\r\n            }\r\n\r\n            try\r\n            {\r\n                using (FileStream fs = File.Open(encrFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))\r\n                {\r\n                    byte[] encrData = fs.ReadAllBytes();\r\n                    File.WriteAllBytes(filePath, PhysStoreCrypto.DecryptPhysicalStore(encrData, production, version));\r\n                }\r\n                Logger.WriteLine(\"Store dumped successfully to '\" + filePath + \"'.\");\r\n            }\r\n            finally\r\n            {\r\n                if (manageSpp)\r\n                {\r\n                    RestartSPP(version);\r\n                }\r\n            }\r\n        }\r\n\r\n        public static void LoadStore(PSVersion version, bool production, string filePath)\r\n        {\r\n            if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))\r\n            {\r\n                throw new FileNotFoundException(\"Store file '\" + filePath + \"' does not exist.\");\r\n            }\r\n\r\n            KillSPP(version);\r\n\r\n            using (IPhysicalStore store = GetStore(version, production))\r\n            {\r\n                store.WriteRaw(File.ReadAllBytes(filePath));\r\n            }\r\n\r\n            RestartSPP(version);\r\n\r\n            Logger.WriteLine(\"Loaded store file successfully.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/SPP/SPSys.cs\r\nnamespace LibTSforge.SPP\r\n{\r\n    using Microsoft.Win32.SafeHandles;\r\n    using System;\r\n    using System.Runtime.InteropServices;\r\n\r\n    public class SPSys\r\n    {\r\n        [DllImport(\"kernel32.dll\", CharSet = CharSet.Auto, SetLastError = true)]\r\n        private static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);\r\n        private static SafeFileHandle CreateFileSafe(string device)\r\n        {\r\n            return new SafeFileHandle(CreateFile(device, 0xC0000000, 0, IntPtr.Zero, 3, 0, IntPtr.Zero), true);\r\n        }\r\n\r\n        [return: MarshalAs(UnmanagedType.Bool)]\r\n        [DllImport(\"kernel32.dll\", CharSet = CharSet.Auto, SetLastError = true)]\r\n        private static extern bool DeviceIoControl([In] SafeFileHandle hDevice, [In] uint dwIoControlCode, [In] IntPtr lpInBuffer, [In] int nInBufferSize, [Out] IntPtr lpOutBuffer, [In] int nOutBufferSize, out int lpBytesReturned, [In] IntPtr lpOverlapped);\r\n\r\n        public static bool IsSpSysRunning()\r\n        {\r\n            SafeFileHandle file = CreateFileSafe(@\"\\\\.\\SpDevice\");\r\n            IntPtr buffer = Marshal.AllocHGlobal(1);\r\n            int bytesReturned;\r\n            DeviceIoControl(file, 0x80006008, IntPtr.Zero, 0, buffer, 1, out bytesReturned, IntPtr.Zero);\r\n            bool running = Marshal.ReadByte(buffer) != 0;\r\n            Marshal.FreeHGlobal(buffer);\r\n            file.Close();\r\n            return running;\r\n        }\r\n\r\n        public static int ControlSpSys(bool start)\r\n        {\r\n            SafeFileHandle file = CreateFileSafe(@\"\\\\.\\SpDevice\");\r\n            IntPtr buffer = Marshal.AllocHGlobal(4);\r\n            int bytesReturned;\r\n            DeviceIoControl(file, start ? 0x8000a000 : 0x8000a004, IntPtr.Zero, 0, buffer, 4, out bytesReturned, IntPtr.Zero);\r\n            int result = Marshal.ReadInt32(buffer);\r\n            Marshal.FreeHGlobal(buffer);\r\n            file.Close();\r\n            return result;\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Crypto/CryptoUtils.cs\r\nnamespace LibTSforge.Crypto\r\n{\r\n    using System;\r\n    using System.Linq;\r\n    using System.Security.Cryptography;\r\n\r\n    public static class CryptoUtils\r\n    {\r\n        public static byte[] GenerateRandomKey(int len)\r\n        {\r\n            byte[] rand = new byte[len];\r\n            Random r = new Random();\r\n            r.NextBytes(rand);\r\n\r\n            return rand;\r\n        }\r\n\r\n        public static byte[] AESEncrypt(byte[] data, byte[] key)\r\n        {\r\n            using (Aes aes = Aes.Create())\r\n            {\r\n                aes.Key = key;\r\n                aes.Mode = CipherMode.CBC;\r\n                aes.Padding = PaddingMode.PKCS7;\r\n\r\n                ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, Enumerable.Repeat((byte)0, 16).ToArray());\r\n                byte[] encryptedData = encryptor.TransformFinalBlock(data, 0, data.Length);\r\n                return encryptedData;\r\n            }\r\n        }\r\n\r\n        public static byte[] AESDecrypt(byte[] data, byte[] key)\r\n        {\r\n            using (Aes aes = Aes.Create())\r\n            {\r\n                aes.Key = key;\r\n                aes.Mode = CipherMode.CBC;\r\n                aes.Padding = PaddingMode.PKCS7;\r\n\r\n                ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, Enumerable.Repeat((byte)0, 16).ToArray());\r\n                byte[] decryptedData = decryptor.TransformFinalBlock(data, 0, data.Length);\r\n                return decryptedData;\r\n            }\r\n        }\r\n\r\n        public static byte[] RSADecrypt(byte[] rsaKey, byte[] data)\r\n        {\r\n\r\n            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())\r\n            {\r\n                rsa.ImportCspBlob(rsaKey);\r\n                return rsa.Decrypt(data, false);\r\n            }\r\n        }\r\n\r\n        public static byte[] RSAEncrypt(byte[] rsaKey, byte[] data)\r\n        {\r\n            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())\r\n            {\r\n                rsa.ImportCspBlob(rsaKey);\r\n                return rsa.Encrypt(data, false);\r\n            }\r\n        }\r\n\r\n        public static byte[] RSASign(byte[] rsaKey, byte[] data)\r\n        {\r\n            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())\r\n            {\r\n                rsa.ImportCspBlob(rsaKey);\r\n                RSAPKCS1SignatureFormatter formatter = new RSAPKCS1SignatureFormatter(rsa);\r\n                formatter.SetHashAlgorithm(\"SHA1\");\r\n\r\n                byte[] hash;\r\n                using (SHA1 sha1 = SHA1.Create())\r\n                {\r\n                    hash = sha1.ComputeHash(data);\r\n                }\r\n\r\n                return formatter.CreateSignature(hash);\r\n            }\r\n        }\r\n\r\n        public static bool RSAVerifySignature(byte[] rsaKey, byte[] data, byte[] signature)\r\n        {\r\n            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())\r\n            {\r\n                rsa.ImportCspBlob(rsaKey);\r\n                RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(rsa);\r\n                deformatter.SetHashAlgorithm(\"SHA1\");\r\n\r\n                byte[] hash;\r\n                using (SHA1 sha1 = SHA1.Create())\r\n                {\r\n                    hash = sha1.ComputeHash(data);\r\n                }\r\n\r\n                return deformatter.VerifySignature(hash, signature);\r\n            }\r\n        }\r\n\r\n        public static byte[] HMACSign(byte[] key, byte[] data)\r\n        {\r\n            HMACSHA1 hmac = new HMACSHA1(key);\r\n            return hmac.ComputeHash(data);\r\n        }\r\n\r\n        public static bool HMACVerify(byte[] key, byte[] data, byte[] signature)\r\n        {\r\n            return Enumerable.SequenceEqual(signature, HMACSign(key, data));\r\n        }\r\n\r\n        public static byte[] SaltSHASum(byte[] salt, byte[] data)\r\n        {\r\n            SHA1 sha1 = SHA1.Create();\r\n            byte[] sha_data = salt.Concat(data).ToArray();\r\n            return sha1.ComputeHash(sha_data);\r\n        }\r\n\r\n        public static bool SaltSHAVerify(byte[] salt, byte[] data, byte[] checksum)\r\n        {\r\n            return Enumerable.SequenceEqual(checksum, SaltSHASum(salt, data));\r\n        }\r\n\r\n        public static byte[] SHA256Hash(byte[] data)\r\n        {\r\n            using (SHA256 sha256 = SHA256.Create())\r\n            {\r\n                return sha256.ComputeHash(data);\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Crypto/Keys.cs\r\nnamespace LibTSforge.Crypto\r\n{\r\n    public static class Keys\r\n    {\r\n        public static readonly byte[] PRODUCTION = {\r\n            0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00,\r\n            0x01, 0x00, 0x01, 0x00, 0x29, 0x87, 0xBA, 0x3F, 0x52, 0x90, 0x57, 0xD8, 0x12, 0x26, 0x6B, 0x38,\r\n            0xB2, 0x3B, 0xF9, 0x67, 0x08, 0x4F, 0xDD, 0x8B, 0xF5, 0xE3, 0x11, 0xB8, 0x61, 0x3A, 0x33, 0x42,\r\n            0x51, 0x65, 0x05, 0x86, 0x1E, 0x00, 0x41, 0xDE, 0xC5, 0xDD, 0x44, 0x60, 0x56, 0x3D, 0x14, 0x39,\r\n            0xB7, 0x43, 0x65, 0xE9, 0xF7, 0x2B, 0xA5, 0xF0, 0xA3, 0x65, 0x68, 0xE9, 0xE4, 0x8B, 0x5C, 0x03,\r\n            0x2D, 0x36, 0xFE, 0x28, 0x4C, 0xD1, 0x3C, 0x3D, 0xC1, 0x90, 0x75, 0xF9, 0x6E, 0x02, 0xE0, 0x58,\r\n            0x97, 0x6A, 0xCA, 0x80, 0x02, 0x42, 0x3F, 0x6C, 0x15, 0x85, 0x4D, 0x83, 0x23, 0x6A, 0x95, 0x9E,\r\n            0x38, 0x52, 0x59, 0x38, 0x6A, 0x99, 0xF0, 0xB5, 0xCD, 0x53, 0x7E, 0x08, 0x7C, 0xB5, 0x51, 0xD3,\r\n            0x8F, 0xA3, 0x0D, 0xA0, 0xFA, 0x8D, 0x87, 0x3C, 0xFC, 0x59, 0x21, 0xD8, 0x2E, 0xD9, 0x97, 0x8B,\r\n            0x40, 0x60, 0xB1, 0xD7, 0x2B, 0x0A, 0x6E, 0x60, 0xB5, 0x50, 0xCC, 0x3C, 0xB1, 0x57, 0xE4, 0xB7,\r\n            0xDC, 0x5A, 0x4D, 0xE1, 0x5C, 0xE0, 0x94, 0x4C, 0x5E, 0x28, 0xFF, 0xFA, 0x80, 0x6A, 0x13, 0x53,\r\n            0x52, 0xDB, 0xF3, 0x04, 0x92, 0x43, 0x38, 0xB9, 0x1B, 0xD9, 0x85, 0x54, 0x7B, 0x14, 0xC7, 0x89,\r\n            0x16, 0x8A, 0x4B, 0x82, 0xA1, 0x08, 0x02, 0x99, 0x23, 0x48, 0xDD, 0x75, 0x9C, 0xC8, 0xC1, 0xCE,\r\n            0xB0, 0xD7, 0x1B, 0xD8, 0xFB, 0x2D, 0xA7, 0x2E, 0x47, 0xA7, 0x18, 0x4B, 0xF6, 0x29, 0x69, 0x44,\r\n            0x30, 0x33, 0xBA, 0xA7, 0x1F, 0xCE, 0x96, 0x9E, 0x40, 0xE1, 0x43, 0xF0, 0xE0, 0x0D, 0x0A, 0x32,\r\n            0xB4, 0xEE, 0xA1, 0xC3, 0x5E, 0x9B, 0xC7, 0x7F, 0xF5, 0x9D, 0xD8, 0xF2, 0x0F, 0xD9, 0x8F, 0xAD,\r\n            0x75, 0x0A, 0x00, 0xD5, 0x25, 0x43, 0xF7, 0xAE, 0x51, 0x7F, 0xB7, 0xDE, 0xB7, 0xAD, 0xFB, 0xCE,\r\n            0x83, 0xE1, 0x81, 0xFF, 0xDD, 0xA2, 0x77, 0xFE, 0xEB, 0x27, 0x1F, 0x10, 0xFA, 0x82, 0x37, 0xF4,\r\n            0x7E, 0xCC, 0xE2, 0xA1, 0x58, 0xC8, 0xAF, 0x1D, 0x1A, 0x81, 0x31, 0x6E, 0xF4, 0x8B, 0x63, 0x34,\r\n            0xF3, 0x05, 0x0F, 0xE1, 0xCC, 0x15, 0xDC, 0xA4, 0x28, 0x7A, 0x9E, 0xEB, 0x62, 0xD8, 0xD8, 0x8C,\r\n            0x85, 0xD7, 0x07, 0x87, 0x90, 0x2F, 0xF7, 0x1C, 0x56, 0x85, 0x2F, 0xEF, 0x32, 0x37, 0x07, 0xAB,\r\n            0xB0, 0xE6, 0xB5, 0x02, 0x19, 0x35, 0xAF, 0xDB, 0xD4, 0xA2, 0x9C, 0x36, 0x80, 0xC6, 0xDC, 0x82,\r\n            0x08, 0xE0, 0xC0, 0x5F, 0x3C, 0x59, 0xAA, 0x4E, 0x26, 0x03, 0x29, 0xB3, 0x62, 0x58, 0x41, 0x59,\r\n            0x3A, 0x37, 0x43, 0x35, 0xE3, 0x9F, 0x34, 0xE2, 0xA1, 0x04, 0x97, 0x12, 0x9D, 0x8C, 0xAD, 0xF7,\r\n            0xFB, 0x8C, 0xA1, 0xA2, 0xE9, 0xE4, 0xEF, 0xD9, 0xC5, 0xE5, 0xDF, 0x0E, 0xBF, 0x4A, 0xE0, 0x7A,\r\n            0x1E, 0x10, 0x50, 0x58, 0x63, 0x51, 0xE1, 0xD4, 0xFE, 0x57, 0xB0, 0x9E, 0xD7, 0xDA, 0x8C, 0xED,\r\n            0x7D, 0x82, 0xAC, 0x2F, 0x25, 0x58, 0x0A, 0x58, 0xE6, 0xA4, 0xF4, 0x57, 0x4B, 0xA4, 0x1B, 0x65,\r\n            0xB9, 0x4A, 0x87, 0x46, 0xEB, 0x8C, 0x0F, 0x9A, 0x48, 0x90, 0xF9, 0x9F, 0x76, 0x69, 0x03, 0x72,\r\n            0x77, 0xEC, 0xC1, 0x42, 0x4C, 0x87, 0xDB, 0x0B, 0x3C, 0xD4, 0x74, 0xEF, 0xE5, 0x34, 0xE0, 0x32,\r\n            0x45, 0xB0, 0xF8, 0xAB, 0xD5, 0x26, 0x21, 0xD7, 0xD2, 0x98, 0x54, 0x8F, 0x64, 0x88, 0x20, 0x2B,\r\n            0x14, 0xE3, 0x82, 0xD5, 0x2A, 0x4B, 0x8F, 0x4E, 0x35, 0x20, 0x82, 0x7E, 0x1B, 0xFE, 0xFA, 0x2C,\r\n            0x79, 0x6C, 0x6E, 0x66, 0x94, 0xBB, 0x0A, 0xEB, 0xBA, 0xD9, 0x70, 0x61, 0xE9, 0x47, 0xB5, 0x82,\r\n            0xFC, 0x18, 0x3C, 0x66, 0x3A, 0x09, 0x2E, 0x1F, 0x61, 0x74, 0xCA, 0xCB, 0xF6, 0x7A, 0x52, 0x37,\r\n            0x1D, 0xAC, 0x8D, 0x63, 0x69, 0x84, 0x8E, 0xC7, 0x70, 0x59, 0xDD, 0x2D, 0x91, 0x1E, 0xF7, 0xB1,\r\n            0x56, 0xED, 0x7A, 0x06, 0x9D, 0x5B, 0x33, 0x15, 0xDD, 0x31, 0xD0, 0xE6, 0x16, 0x07, 0x9B, 0xA5,\r\n            0x94, 0x06, 0x7D, 0xC1, 0xE9, 0xD6, 0xC8, 0xAF, 0xB4, 0x1E, 0x2D, 0x88, 0x06, 0xA7, 0x63, 0xB8,\r\n            0xCF, 0xC8, 0xA2, 0x6E, 0x84, 0xB3, 0x8D, 0xE5, 0x47, 0xE6, 0x13, 0x63, 0x8E, 0xD1, 0x7F, 0xD4,\r\n            0x81, 0x44, 0x38, 0xBF\r\n        };\r\n\r\n        public static readonly byte[] TEST = {\r\n            0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00,\r\n            0x01, 0x00, 0x01, 0x00, 0x0F, 0xBE, 0x77, 0xB8, 0xDD, 0x54, 0x36, 0xDD, 0x67, 0xD4, 0x17, 0x66,\r\n            0xC4, 0x13, 0xD1, 0x3F, 0x1E, 0x16, 0x0C, 0x16, 0x35, 0xAB, 0x6D, 0x3D, 0x34, 0x51, 0xED, 0x3F,\r\n            0x57, 0x14, 0xB6, 0xB7, 0x08, 0xE9, 0xD9, 0x7A, 0x80, 0xB3, 0x5F, 0x9B, 0x3A, 0xFD, 0x9E, 0x37,\r\n            0x3A, 0x53, 0x72, 0x67, 0x92, 0x60, 0xC3, 0xEF, 0xB5, 0x8E, 0x1E, 0xCF, 0x9D, 0x9C, 0xD3, 0x90,\r\n            0xE5, 0xDD, 0xF4, 0xDB, 0xF3, 0xD6, 0x65, 0xB3, 0xC1, 0xBD, 0x69, 0xE1, 0x76, 0x95, 0xD9, 0x37,\r\n            0xB8, 0x5E, 0xCA, 0x3D, 0x98, 0xFC, 0x50, 0x5C, 0x98, 0xAE, 0xE3, 0x7C, 0x4C, 0x27, 0xC3, 0xD0,\r\n            0xCE, 0x78, 0x06, 0x51, 0x68, 0x23, 0xE6, 0x70, 0xF8, 0x7C, 0xAE, 0x36, 0xBE, 0x41, 0x57, 0xE2,\r\n            0xC3, 0x2D, 0xAF, 0x21, 0xB1, 0xB3, 0x15, 0x81, 0x19, 0x26, 0x6B, 0x10, 0xB3, 0xE9, 0xD1, 0x45,\r\n            0x21, 0x77, 0x9C, 0xF6, 0xE1, 0xDD, 0xB6, 0x78, 0x9D, 0x1D, 0x32, 0x61, 0xBC, 0x2B, 0xDB, 0x86,\r\n            0xFB, 0x07, 0x24, 0x10, 0x19, 0x4F, 0x09, 0x6D, 0x03, 0x90, 0xD4, 0x5E, 0x30, 0x85, 0xC5, 0x58,\r\n            0x7E, 0x5D, 0xAE, 0x9F, 0x64, 0x93, 0x04, 0x82, 0x09, 0x0E, 0x1C, 0x66, 0xA8, 0x95, 0x91, 0x51,\r\n            0xB2, 0xED, 0x9A, 0x75, 0x04, 0x87, 0x50, 0xAC, 0xCC, 0x20, 0x06, 0x45, 0xB9, 0x7B, 0x42, 0x53,\r\n            0x9A, 0xD1, 0x29, 0xFC, 0xEF, 0xB9, 0x47, 0x16, 0x75, 0x69, 0x05, 0x87, 0x2B, 0xCB, 0x54, 0x9C,\r\n            0x21, 0x2D, 0x50, 0x8E, 0x12, 0xDE, 0xD3, 0x6B, 0xEC, 0x92, 0xA1, 0xB1, 0xE9, 0x4B, 0xBF, 0x6B,\r\n            0x9A, 0x38, 0xC7, 0x13, 0xFA, 0x78, 0xA1, 0x3C, 0x1E, 0xBB, 0x38, 0x31, 0xBB, 0x0C, 0x9F, 0x70,\r\n            0x1A, 0x31, 0x00, 0xD7, 0x5A, 0xA5, 0x84, 0x24, 0x89, 0x80, 0xF5, 0x88, 0xC2, 0x31, 0x18, 0xDC,\r\n            0x53, 0x05, 0x5D, 0xFA, 0x81, 0xDC, 0xE1, 0xCE, 0xA4, 0xAA, 0xBA, 0x07, 0xDA, 0x28, 0x4F, 0x64,\r\n            0x0E, 0x84, 0x9B, 0x06, 0xDE, 0xC8, 0x78, 0x66, 0x2F, 0x17, 0x25, 0xA8, 0x9C, 0x99, 0xFC, 0xBC,\r\n            0x7D, 0x01, 0x42, 0xD7, 0x35, 0xBF, 0x19, 0xF6, 0x3F, 0x20, 0xD9, 0x98, 0x9B, 0x5D, 0xDD, 0x39,\r\n            0xBE, 0x81, 0x00, 0x0B, 0xDE, 0x6F, 0x14, 0xCA, 0x7E, 0xF8, 0xC0, 0x26, 0xA8, 0x1D, 0xD1, 0x16,\r\n            0x88, 0x64, 0x87, 0x36, 0x45, 0x37, 0x50, 0xDA, 0x6C, 0xEB, 0x85, 0xB5, 0x43, 0x29, 0x88, 0x6F,\r\n            0x2F, 0xFE, 0x8D, 0x12, 0x8B, 0x72, 0xB7, 0x5A, 0xCB, 0x66, 0xC2, 0x2E, 0x1D, 0x7D, 0x42, 0xA6,\r\n            0xF4, 0xFE, 0x26, 0x5D, 0x54, 0x9E, 0x77, 0x1D, 0x97, 0xC2, 0xF3, 0xFD, 0x60, 0xB3, 0x22, 0x88,\r\n            0xCA, 0x27, 0x99, 0xDF, 0xC8, 0xB1, 0xD7, 0xC6, 0x54, 0xA6, 0x50, 0xB9, 0x54, 0xF5, 0xDE, 0xFE,\r\n            0xE1, 0x81, 0xA2, 0xBE, 0x81, 0x9F, 0x48, 0xFF, 0x2F, 0xB8, 0xA4, 0xB3, 0x17, 0xD8, 0xC1, 0xB9,\r\n            0x5D, 0x21, 0x3D, 0xA2, 0xED, 0x1C, 0x96, 0x66, 0xEE, 0x1F, 0x47, 0xCF, 0x62, 0xFA, 0xD6, 0xC1,\r\n            0x87, 0x5B, 0xC4, 0xE5, 0xD9, 0x08, 0x38, 0x22, 0xFA, 0x21, 0xBD, 0xF2, 0x88, 0xDA, 0xE2, 0x24,\r\n            0x25, 0x1F, 0xF1, 0x0B, 0x2D, 0xAE, 0x04, 0xBE, 0xA6, 0x7F, 0x75, 0x8C, 0xD9, 0x97, 0xE1, 0xCA,\r\n            0x35, 0xB9, 0xFC, 0x6F, 0x01, 0x68, 0x11, 0xD3, 0x68, 0x32, 0xD0, 0xC1, 0x69, 0xA3, 0xCF, 0x9B,\r\n            0x10, 0xE4, 0x69, 0xA7, 0xCF, 0xE1, 0xFE, 0x2A, 0x07, 0x9E, 0xC1, 0x37, 0x84, 0x68, 0xE5, 0xC5,\r\n            0xAB, 0x25, 0xEC, 0x7D, 0x7D, 0x74, 0x6A, 0xD1, 0xD5, 0x4D, 0xD7, 0xE1, 0x7D, 0xDE, 0x30, 0x4B,\r\n            0xE6, 0x5D, 0xCD, 0x91, 0x59, 0xF6, 0x80, 0xFD, 0xC6, 0x3C, 0xDD, 0x94, 0x7F, 0x15, 0x9D, 0xEF,\r\n            0x2F, 0x00, 0x62, 0xD7, 0xDA, 0xB9, 0xB3, 0xD9, 0x8D, 0xE8, 0xD7, 0x3C, 0x96, 0x45, 0x5D, 0x1E,\r\n            0x50, 0xFB, 0xAA, 0x43, 0xD3, 0x47, 0x77, 0x81, 0xE9, 0x67, 0xE4, 0xFE, 0xDF, 0x42, 0x79, 0xCB,\r\n            0xA7, 0xAD, 0x5D, 0x48, 0xF5, 0xB7, 0x74, 0x96, 0x12, 0x23, 0x06, 0x70, 0x42, 0x68, 0x7A, 0x44,\r\n            0xFC, 0xA0, 0x31, 0x7F, 0x68, 0xCA, 0xA2, 0x14, 0x5D, 0xA3, 0xCF, 0x42, 0x23, 0xAB, 0x47, 0xF6,\r\n            0xB2, 0xFC, 0x6D, 0xF1\r\n        };\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Crypto/PhysStoreCrypto.cs\r\nnamespace LibTSforge.Crypto\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using System.Text;\r\n\r\n    public static class PhysStoreCrypto\r\n    {\r\n        public static byte[] DecryptPhysicalStore(byte[] data, bool production, PSVersion version)\r\n        {\r\n            byte[] rsaKey = production ? Keys.PRODUCTION : Keys.TEST;\r\n            BinaryReader br = new BinaryReader(new MemoryStream(data));\r\n            br.BaseStream.Seek(0x10, SeekOrigin.Begin);\r\n            byte[] aesKeySig = br.ReadBytes(0x80);\r\n            byte[] encAesKey = br.ReadBytes(0x80);\r\n\r\n            if (!CryptoUtils.RSAVerifySignature(rsaKey, encAesKey, aesKeySig))\r\n            {\r\n                throw new Exception(\"Failed to decrypt physical store.\");\r\n            }\r\n\r\n            byte[] aesKey = CryptoUtils.RSADecrypt(rsaKey, encAesKey);\r\n            byte[] decData = CryptoUtils.AESDecrypt(br.ReadBytes((int)br.BaseStream.Length - 0x110), aesKey);\r\n            byte[] hmacKey = decData.Take(0x10).ToArray(); // SHA-1 salt on Vista\r\n            byte[] hmacSig = decData.Skip(0x10).Take(0x14).ToArray(); // SHA-1 hash on Vista\r\n            byte[] psData = decData.Skip(0x28).ToArray();\r\n\r\n            if (version != PSVersion.Vista)\r\n            {\r\n                if (!CryptoUtils.HMACVerify(hmacKey, psData, hmacSig))\r\n                {\r\n                    throw new InvalidDataException(\"Failed to verify HMAC. Physical store is corrupt.\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                if (!CryptoUtils.SaltSHAVerify(hmacKey, psData, hmacSig))\r\n                {\r\n                    throw new InvalidDataException(\"Failed to verify checksum. Physical store is corrupt.\");\r\n                }\r\n            }\r\n\r\n            return psData;\r\n        }\r\n\r\n        public static byte[] EncryptPhysicalStore(byte[] data, bool production, PSVersion version)\r\n        {\r\n            Dictionary<PSVersion, int> versionTable = new Dictionary<PSVersion, int>\r\n            {\r\n                {PSVersion.Vista, 2},\r\n                {PSVersion.Win7, 5},\r\n                {PSVersion.Win8, 1},\r\n                {PSVersion.WinBlue, 2},\r\n                {PSVersion.WinModern, 3}\r\n            };\r\n\r\n            byte[] rsaKey = production ? Keys.PRODUCTION : Keys.TEST;\r\n\r\n            byte[] aesKey = Encoding.UTF8.GetBytes(\"massgrave.dev :3\");\r\n            byte[] hmacKey = CryptoUtils.GenerateRandomKey(0x10);\r\n\r\n            byte[] encAesKey = CryptoUtils.RSAEncrypt(rsaKey, aesKey);\r\n            byte[] aesKeySig = CryptoUtils.RSASign(rsaKey, encAesKey);\r\n            byte[] hmacSig = version != PSVersion.Vista ? CryptoUtils.HMACSign(hmacKey, data) : CryptoUtils.SaltSHASum(hmacKey, data);\r\n\r\n            byte[] decData = { };\r\n            decData = decData.Concat(hmacKey).Concat(hmacSig).Concat(BitConverter.GetBytes(0)).Concat(data).ToArray();\r\n            byte[] encData = CryptoUtils.AESEncrypt(decData, aesKey);\r\n\r\n            BinaryWriter bw = new BinaryWriter(new MemoryStream());\r\n            bw.Write(versionTable[version]);\r\n            bw.Write(Encoding.UTF8.GetBytes(\"UNTRUSTSTORE\"));\r\n            bw.Write(aesKeySig);\r\n            bw.Write(encAesKey);\r\n            bw.Write(encData);\r\n\r\n            return bw.GetBytes();\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/GenPKeyInstall.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using Microsoft.Win32;\r\n    using PhysicalStore;\r\n    using SPP;\r\n    using TokenStore;\r\n\r\n    public static class GenPKeyInstall\r\n    {\r\n        private static void WritePkey2005RegistryValues(PSVersion version, ProductKey pkey)\r\n        {\r\n            Logger.WriteLine(\"Writing registry data for Windows product key...\");\r\n            Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\", \"ProductId\", pkey.GetPid2());\r\n            Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\", \"DigitalProductId\", pkey.GetPid3());\r\n            Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\", \"DigitalProductId4\", pkey.GetPid4());\r\n\r\n            if (Registry.GetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Registration\", \"ProductId\", null) != null)\r\n            {\r\n                Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Registration\", \"ProductId\", pkey.GetPid2());\r\n                Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Registration\", \"DigitalProductId\", pkey.GetPid3());\r\n                Registry.SetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Registration\", \"DigitalProductId4\", pkey.GetPid4());\r\n            }\r\n\r\n            if (pkey.Channel == \"Volume:CSVLK\" && version != PSVersion.Win7)\r\n            {\r\n                Registry.SetValue(@\"HKEY_USERS\\S-1-5-20\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\", \"KmsHostConfig\", 1);\r\n            }\r\n        }\r\n\r\n        public static void InstallGenPKey(PSVersion version, bool production, Guid actId)\r\n        {\r\n            if (version == PSVersion.Vista) throw new NotSupportedException(\"This feature is not supported on Windows Vista/Server 2008.\");\r\n            if (actId == Guid.Empty) throw new ArgumentException(\"Activation ID must be specified for generated product key install.\");\r\n\r\n            PKeyConfig pkc = new PKeyConfig();\r\n            \r\n            try\r\n            {\r\n                pkc.LoadConfig(actId);\r\n            }\r\n            catch (ArgumentException)\r\n            {\r\n                pkc.LoadAllConfigs(SLApi.GetAppId(actId));\r\n            }\r\n\r\n            ProductConfig config;\r\n            pkc.Products.TryGetValue(actId, out config);\r\n\r\n            if (config == null) throw new ArgumentException(\"Activation ID \" + actId + \" not found in PKeyConfig.\");\r\n\r\n            ProductKey pkey = config.GetRandomKey();\r\n\r\n            Guid instPkeyId = SLApi.GetInstalledPkeyID(actId);\r\n            if (instPkeyId != Guid.Empty) SLApi.UninstallProductKey(instPkeyId);\r\n\r\n            if (pkey.Algorithm == PKeyAlgorithm.PKEY2009)\r\n            {\r\n                uint status = SLApi.InstallProductKey(pkey);\r\n                Logger.WriteLine(string.Format(\"Installing generated product key {0} status {1:X}\", pkey, status));\r\n\r\n                if ((int)status < 0)\r\n                {\r\n                    throw new ApplicationException(\"Failed to install generated product key.\");\r\n                }\r\n\r\n                Logger.WriteLine(\"Successfully deposited generated product key.\");\r\n                return;\r\n            }\r\n\r\n            Logger.WriteLine(\"Key range is PKEY2005, creating fake key data...\");\r\n\r\n            if (pkey.Channel == \"Volume:GVLK\" && version == PSVersion.Win7) throw new NotSupportedException(\"Fake GVLK generation is not supported on Windows 7.\");\r\n\r\n            VariableBag pkb = new VariableBag(version);\r\n            pkb.Blocks.AddRange(new[]\r\n            {\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyBindingProductKey\",\r\n                    ValueAsStr = pkey.ToString()\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyBindingMPC\",\r\n                    ValueAsStr = pkey.GetMPC()\r\n                },\r\n                new CRCBlockModern {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = \"SppPkeyBindingPid2\",\r\n                    ValueAsStr = pkey.GetPid2()\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = \"SppPkeyBindingPid3\",\r\n                    Value = pkey.GetPid3()\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = \"SppPkeyBindingPid4\",\r\n                    Value = pkey.GetPid4()\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyChannelId\",\r\n                    ValueAsStr = pkey.Channel\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.STRING,\r\n                    KeyAsStr = \"SppPkeyBindingEditionId\",\r\n                    ValueAsStr = pkey.Edition\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = (version == PSVersion.Win7) ? \"SppPkeyShortAuthenticator\" : \"SppPkeyPhoneActivationData\",\r\n                    Value = pkey.GetPhoneData(version)\r\n                },\r\n                new CRCBlockModern\r\n                {\r\n                    DataType = CRCBlockType.BINARY,\r\n                    KeyAsStr = \"SppPkeyBindingMiscData\",\r\n                    Value = new byte[] { }\r\n                }\r\n            });\r\n\r\n            Guid appId = SLApi.GetAppId(actId);\r\n            string pkeyId = pkey.GetPkeyId().ToString();\r\n            bool isAddon = SLApi.IsAddon(actId);\r\n            string currEdition = SLApi.GetMetaStr(actId, \"Family\");\r\n\r\n            if (appId == SLApi.WINDOWS_APP_ID && !isAddon)\r\n            {\r\n                SLApi.UninstallAllProductKeys(appId);\r\n            }\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            using (IPhysicalStore ps = SPPUtils.GetStore(version, production))\r\n            {\r\n                using (ITokenStore tks = SPPUtils.GetTokenStore(version))\r\n                {\r\n                    Logger.WriteLine(\"Writing to physical store and token store...\");\r\n\r\n                    string suffix = (version == PSVersion.Win8 || version == PSVersion.WinBlue || version == PSVersion.WinModern) ? \"_--\" : \"\";\r\n                    string metSuffix = suffix + \"_met\";\r\n\r\n                    if (appId == SLApi.WINDOWS_APP_ID && !isAddon)\r\n                    {\r\n                        string edTokName = \"msft:spp/token/windows/productkeyid/\" + currEdition;\r\n\r\n                        TokenMeta edToken = tks.GetMetaEntry(edTokName);\r\n                        edToken.Data[\"windowsComponentEditionPkeyId\"] = pkeyId;\r\n                        edToken.Data[\"windowsComponentEditionSkuId\"] = actId.ToString();\r\n                        tks.SetEntry(edTokName, \"xml\", edToken.Serialize());\r\n\r\n                        WritePkey2005RegistryValues(version, pkey);\r\n                    }\r\n\r\n                    string uriMapName = \"msft:spp/token/PKeyIdUriMapper\" + metSuffix;\r\n                    TokenMeta uriMap = tks.GetMetaEntry(uriMapName);\r\n                    uriMap.Data[pkeyId] = pkey.GetAlgoUri();\r\n                    tks.SetEntry(uriMapName, \"xml\", uriMap.Serialize());\r\n\r\n                    string skuMetaName = actId + metSuffix;\r\n                    TokenMeta skuMeta = tks.GetMetaEntry(skuMetaName);\r\n\r\n                    foreach (string k in skuMeta.Data.Keys)\r\n                    {\r\n                        if (k.StartsWith(\"pkeyId_\"))\r\n                        {\r\n                            skuMeta.Data.Remove(k);\r\n                            break;\r\n                        }\r\n                    }\r\n\r\n                    skuMeta.Data[\"pkeyId\"] = pkeyId;\r\n                    skuMeta.Data[\"pkeyIdList\"] = pkeyId;\r\n                    tks.SetEntry(skuMetaName, \"xml\", skuMeta.Serialize());\r\n\r\n                    string psKey = string.Format(\"SPPSVC\\\\{0}\\\\{1}\", appId, actId);\r\n                    ps.DeleteBlock(psKey, pkeyId);\r\n                    ps.AddBlock(new PSBlock\r\n                    {\r\n                        Type = BlockType.NAMED,\r\n                        Flags = (version == PSVersion.WinModern) ? (uint)0x402 : 0x2,\r\n                        KeyAsStr = psKey,\r\n                        ValueAsStr = pkeyId,\r\n                        Data = pkb.Serialize()\r\n                    });\r\n\r\n                    string cachePath = SPPUtils.GetTokensPath(version).Replace(\"tokens.dat\", @\"cache\\cache.dat\");\r\n                    if (File.Exists(cachePath)) File.Delete(cachePath);\r\n                }\r\n            }\r\n\r\n            SLApi.RefreshTrustedTime(actId);\r\n            Logger.WriteLine(\"Successfully deposited fake product key.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/GracePeriodReset.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System.Collections.Generic;\r\n    using System.Linq;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class GracePeriodReset\r\n    {\r\n        public static void Reset(PSVersion version, bool production)\r\n        {\r\n            SPPUtils.KillSPP(version);\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                string value = \"msft:sl/timer\";\r\n                List<PSBlock> blocks = store.FindBlocks(value).ToList();\r\n\r\n                foreach (PSBlock block in blocks)\r\n                {\r\n                    store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);\r\n                }\r\n            }\r\n\r\n            SPPUtils.RestartSPP(version);\r\n            Logger.WriteLine(\"Successfully reset all grace and evaluation period timers.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/KeyChangeLockDelete.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System.Collections.Generic;\r\n    using System.Linq;\r\n    using PhysicalStore;\r\n    using SPP;\r\n    using System;\r\n\r\n    public static class KeyChangeLockDelete\r\n    {\r\n        public static void Delete(PSVersion version, bool production)\r\n        {\r\n            if (version == PSVersion.Vista) throw new NotSupportedException(\"This feature is not supported on Windows Vista/Server 2008.\");\r\n\r\n            SPPUtils.KillSPP(version);\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                List<string> values = new List<string>\r\n                {\r\n                    \"msft:spp/timebased/AB\",\r\n                    \"msft:spp/timebased/CD\"\r\n                };\r\n                List<PSBlock> blocks = new List<PSBlock>();\r\n                foreach (string value in values)\r\n                {\r\n                    blocks.AddRange(store.FindBlocks(value).ToList());\r\n                }\r\n                foreach (PSBlock block in blocks)\r\n                {\r\n                    store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);\r\n                }\r\n            }\r\n            Logger.WriteLine(\"Successfully removed the key change lock.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/KMSHostCharge.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class KMSHostCharge\r\n    {\r\n        public static void Charge(PSVersion version, bool production, Guid actId)\r\n        {\r\n            if (actId == Guid.Empty)\r\n            {\r\n                actId = SLApi.GetDefaultActivationID(SLApi.WINDOWS_APP_ID, true);\r\n\r\n                if (actId == Guid.Empty)\r\n                {\r\n                    throw new NotSupportedException(\"No applicable activation IDs found.\");\r\n                }\r\n            }\r\n\r\n            if (SLApi.GetPKeyChannel(SLApi.GetInstalledPkeyID(actId)) != \"Volume:CSVLK\")\r\n            {\r\n                throw new NotSupportedException(\"Non-Volume:CSVLK product key installed.\");\r\n            }\r\n\r\n            Guid appId = SLApi.GetAppId(actId);\r\n            int totalClients = 50;\r\n            int currClients = 25;\r\n            byte[] hwidBlock = Constants.UniversalHWIDBlock;\r\n            string key = string.Format(\"SPPSVC\\\\{0}\", appId);\r\n            long ldapTimestamp = DateTime.Now.ToFileTime();\r\n\r\n            byte[] cmidGuids = { };\r\n            byte[] reqCounts = { };\r\n            byte[] kmsChargeData = { };\r\n\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n\r\n            if (version == PSVersion.Vista)\r\n            {\r\n                writer.Write(new byte[44]);\r\n                writer.Seek(0, SeekOrigin.Begin);\r\n\r\n                writer.Write(totalClients);\r\n                writer.Write(43200);\r\n                writer.Write(32);\r\n\r\n                writer.Seek(20, SeekOrigin.Begin);\r\n                writer.Write((byte)currClients);\r\n\r\n                writer.Seek(32, SeekOrigin.Begin);\r\n                writer.Write((byte)currClients);\r\n\r\n                writer.Seek(0, SeekOrigin.End);\r\n\r\n                for (int i = 0; i < currClients; i++)\r\n                {\r\n                    writer.Write(Guid.NewGuid().ToByteArray());\r\n                    writer.Write(ldapTimestamp - (10 * (i + 1)));\r\n                }\r\n\r\n                kmsChargeData = writer.GetBytes();\r\n            } \r\n            else\r\n            {\r\n                for (int i = 0; i < currClients; i++)\r\n                {\r\n                    writer.Write(ldapTimestamp - (10 * (i + 1)));\r\n                    writer.Write(Guid.NewGuid().ToByteArray());\r\n                }\r\n\r\n                cmidGuids = writer.GetBytes();\r\n\r\n                writer = new BinaryWriter(new MemoryStream());\r\n\r\n                writer.Write(new byte[40]);\r\n\r\n                writer.Seek(4, SeekOrigin.Begin);\r\n                writer.Write((byte)currClients);\r\n\r\n                writer.Seek(24, SeekOrigin.Begin);\r\n                writer.Write((byte)currClients);\r\n\r\n                reqCounts = writer.GetBytes();\r\n            }\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                if (version != PSVersion.Vista)\r\n                {\r\n                    VariableBag kmsCountData = new VariableBag(version);\r\n                    kmsCountData.Blocks.AddRange(new[]\r\n                    {\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.BINARY,\r\n                            KeyAsStr = \"SppBindingLicenseData\",\r\n                            Value = hwidBlock\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.UINT,\r\n                            Key = new byte[] { },\r\n                            ValueAsInt = (uint)totalClients\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.UINT,\r\n                            Key = new byte[] { },\r\n                            ValueAsInt = 1051200000\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.UINT,\r\n                            Key = new byte[] { },\r\n                            ValueAsInt = (uint)currClients\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.BINARY,\r\n                            Key = new byte[] { },\r\n                            Value = cmidGuids\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.BINARY,\r\n                            Key = new byte[] { },\r\n                            Value = reqCounts\r\n                        }\r\n                    });\r\n\r\n                    kmsChargeData = kmsCountData.Serialize();\r\n                }\r\n\r\n                string countVal = version == PSVersion.Vista ? \"C8F6FFF1-79CE-404C-B150-F97991273DF1\" : string.Format(\"msft:spp/kms/host/2.0/store/counters/{0}\", appId);\r\n\r\n                store.DeleteBlock(key, countVal);\r\n                store.AddBlock(new PSBlock\r\n                {\r\n                    Type = BlockType.NAMED,\r\n                    Flags = (version == PSVersion.WinModern) ? (uint)0x400 : 0,\r\n                    KeyAsStr = key,\r\n                    ValueAsStr = countVal,\r\n                    Data = kmsChargeData\r\n                });\r\n\r\n                Logger.WriteLine(string.Format(\"Set charge count to {0} successfully.\", currClients));\r\n            }\r\n\r\n            SPPUtils.RestartSPP(version);\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/RearmReset.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System.Collections.Generic;\r\n    using System.Linq;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class RearmReset\r\n    {\r\n        public static void Reset(PSVersion version, bool production)\r\n        {\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                List<PSBlock> blocks;\r\n\r\n                if (version == PSVersion.Vista)\r\n                {\r\n                    blocks = store.FindBlocks(\"740D70D8-6448-4b2f-9063-4A7A463600C5\").ToList();\r\n                }\r\n                else if (version == PSVersion.Win7)\r\n                {\r\n                    blocks = store.FindBlocks(0xA0000).ToList();\r\n                }\r\n                else\r\n                {\r\n                    blocks = store.FindBlocks(\"__##USERSEP-RESERVED##__$$REARM-COUNT$$\").ToList();\r\n                }\r\n\r\n                foreach (PSBlock block in blocks)\r\n                {\r\n                    if (version == PSVersion.Vista)\r\n                    {\r\n                        store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);\r\n                    }\r\n                    else if (version == PSVersion.Win7)\r\n                    {\r\n                        store.SetBlock(block.KeyAsStr, block.ValueAsInt, new byte[8]);\r\n                    }\r\n                    else\r\n                    {\r\n                        store.SetBlock(block.KeyAsStr, block.ValueAsStr, new byte[8]);\r\n                    }\r\n                }\r\n\r\n                Logger.WriteLine(\"Successfully reset all rearm counters.\");\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/SetIIDParams.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using PhysicalStore;\r\n    using SPP;\r\n    using System.IO;\r\n    using System;\r\n\r\n    public static class SetIIDParams\r\n    {\r\n        public static void SetParams(PSVersion version, bool production, Guid actId, PKeyAlgorithm algorithm, int group, int serial, ulong security)\r\n        {\r\n            if (version == PSVersion.Vista) throw new NotSupportedException(\"This feature is not supported on Windows Vista/Server 2008.\");\r\n\r\n            Guid appId;\r\n\r\n            if (actId == Guid.Empty)\r\n            {\r\n                appId = SLApi.WINDOWS_APP_ID;\r\n                actId = SLApi.GetDefaultActivationID(appId, true);\r\n\r\n                if (actId == Guid.Empty)\r\n                {\r\n                    throw new Exception(\"No applicable activation IDs found.\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                appId = SLApi.GetAppId(actId);\r\n            }\r\n\r\n            Guid pkeyId = SLApi.GetInstalledPkeyID(actId);\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                string key = string.Format(\"SPPSVC\\\\{0}\\\\{1}\", appId, actId);\r\n                PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());\r\n\r\n                if (keyBlock == null)\r\n                {\r\n                    throw new InvalidDataException(\"Failed to get product key data for activation ID \" + actId + \".\");\r\n                }\r\n\r\n                VariableBag pkb = new VariableBag(keyBlock.Data, version);\r\n\r\n                ProductKey pkey = new ProductKey\r\n                {\r\n                    Group = group,\r\n                    Serial = serial,\r\n                    Security = security,\r\n                    Algorithm = algorithm,\r\n                    Upgrade = false\r\n                };\r\n\r\n                string blockName = version == PSVersion.Win7 ? \"SppPkeyShortAuthenticator\" : \"SppPkeyPhoneActivationData\";\r\n                pkb.SetBlock(blockName, pkey.GetPhoneData(version));\r\n                store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());\r\n            }\r\n\r\n            Logger.WriteLine(\"Successfully set IID parameters.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/TamperedFlagsDelete.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System.Linq;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class TamperedFlagsDelete\r\n    {\r\n        public static void DeleteTamperFlags(PSVersion version, bool production)\r\n        {\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                if (version == PSVersion.Vista)\r\n                {\r\n                    DeleteFlag(store, \"6BE8425B-E3CF-4e86-A6AF-5863E3DCB606\");\r\n                }\r\n                else if (version == PSVersion.Win7)\r\n                {\r\n                    SetFlag(store, 0xA0001);\r\n                }\r\n                else\r\n                {\r\n                    DeleteFlag(store, \"__##USERSEP-RESERVED##__$$RECREATED-FLAG$$\");\r\n                    DeleteFlag(store, \"__##USERSEP-RESERVED##__$$RECOVERED-FLAG$$\");\r\n                }\r\n\r\n                Logger.WriteLine(\"Successfully cleared the tamper state.\");\r\n            }\r\n\r\n            SPPUtils.RestartSPP(version);\r\n        }\r\n\r\n        private static void DeleteFlag(IPhysicalStore store, string flag)\r\n        {\r\n            store.FindBlocks(flag).ToList().ForEach(block => store.DeleteBlock(block.KeyAsStr, block.ValueAsStr));\r\n        }\r\n\r\n        private static void SetFlag(IPhysicalStore store, uint flag)\r\n        {\r\n            store.FindBlocks(flag).ToList().ForEach(block => store.SetBlock(block.KeyAsStr, block.ValueAsInt, new byte[8]));\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Modifiers/UniqueIdDelete.cs\r\nnamespace LibTSforge.Modifiers\r\n{\r\n    using System;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class UniqueIdDelete\r\n    {\r\n        public static void DeleteUniqueId(PSVersion version, bool production, Guid actId)\r\n        {\r\n            if (version == PSVersion.Vista) throw new NotSupportedException(\"This feature is not supported on Windows Vista/Server 2008.\");\r\n\r\n            Guid appId;\r\n\r\n            if (actId == Guid.Empty)\r\n            {\r\n                appId = SLApi.WINDOWS_APP_ID;\r\n                actId = SLApi.GetDefaultActivationID(appId, true);\r\n\r\n                if (actId == Guid.Empty)\r\n                {\r\n                    throw new Exception(\"No applicable activation IDs found.\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                appId = SLApi.GetAppId(actId);\r\n            }\r\n\r\n            Guid pkeyId = SLApi.GetInstalledPkeyID(actId);\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                string key = string.Format(\"SPPSVC\\\\{0}\\\\{1}\", appId, actId);\r\n                PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());\r\n\r\n                if (keyBlock == null)\r\n                {\r\n                    throw new Exception(\"No product key found.\");\r\n                }\r\n\r\n                VariableBag pkb = new VariableBag(keyBlock.Data, version);\r\n\r\n                pkb.DeleteBlock(\"SppPkeyUniqueIdToken\");\r\n\r\n                store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());\r\n            }\r\n\r\n            Logger.WriteLine(\"Successfully removed Unique ID for product key ID \" + pkeyId);\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Activators/KMS4K.cs\r\nnamespace LibTSforge.Activators\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public class KMS4k\r\n    {\r\n        public static void Activate(PSVersion version, bool production, Guid actId)\r\n        {\r\n            Guid appId;\r\n            if (actId == Guid.Empty)\r\n            {\r\n                appId = SLApi.WINDOWS_APP_ID;\r\n                actId = SLApi.GetDefaultActivationID(appId, true);\r\n\r\n                if (actId == Guid.Empty)\r\n                {\r\n                    throw new NotSupportedException(\"No applicable activation IDs found.\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                appId = SLApi.GetAppId(actId);\r\n            }\r\n\r\n            if (SLApi.GetPKeyChannel(SLApi.GetInstalledPkeyID(actId)) != \"Volume:GVLK\")\r\n            {\r\n                throw new NotSupportedException(\"Non-Volume:GVLK product key installed.\");\r\n            }\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                string key = string.Format(\"SPPSVC\\\\{0}\\\\{1}\", appId, actId);\r\n\r\n                ulong unknown = 0;\r\n                ulong time1;\r\n                ulong time2 = (ulong)DateTime.UtcNow.ToFileTime();\r\n                ulong expiry = Constants.TimerMax;\r\n\r\n                if (version == PSVersion.Vista || version == PSVersion.Win7)\r\n                {\r\n                    unknown = 0x800000000;\r\n                    time1 = 0;\r\n                }\r\n                else\r\n                {\r\n                    long creationTime = BitConverter.ToInt64(store.GetBlock(\"__##USERSEP##\\\\$$_RESERVED_$$\\\\NAMESPACE__\", \"__##USERSEP-RESERVED##__$$GLOBAL-CREATION-TIME$$\").Data, 0);\r\n                    long tickCount = BitConverter.ToInt64(store.GetBlock(\"__##USERSEP##\\\\$$_RESERVED_$$\\\\NAMESPACE__\", \"__##USERSEP-RESERVED##__$$GLOBAL-TICKCOUNT-UPTIME$$\").Data, 0);\r\n                    long deltaTime = BitConverter.ToInt64(store.GetBlock(key, \"__##USERSEP-RESERVED##__$$UP-TIME-DELTA$$\").Data, 0);\r\n\r\n                    time1 = (ulong)(creationTime + tickCount + deltaTime);\r\n                    time2 /= 10000;\r\n                    expiry /= 10000;\r\n                }\r\n\r\n                if (version == PSVersion.Vista)\r\n                {\r\n                    VistaTimer vistaTimer = new VistaTimer\r\n                    {\r\n                        Time = time2,\r\n                        Expiry = Constants.TimerMax\r\n                    };\r\n\r\n                    string vistaTimerName = string.Format(\"msft:sl/timer/VLExpiration/VOLUME/{0}/{1}\", appId, actId);\r\n\r\n                    store.DeleteBlock(key, vistaTimerName);\r\n                    store.DeleteBlock(key, actId.ToString());\r\n\r\n                    BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n                    writer.Write(Constants.KMSv4Response.Length);\r\n                    writer.Write(Constants.KMSv4Response);\r\n                    writer.Write(Constants.UniversalHWIDBlock);\r\n                    byte[] kmsData = writer.GetBytes();\r\n\r\n                    store.AddBlocks(new[]\r\n                    {\r\n                        new PSBlock\r\n                        {\r\n                            Type = BlockType.TIMER,\r\n                            Flags = 0,\r\n                            KeyAsStr = key,\r\n                            ValueAsStr = vistaTimerName,\r\n                            Data = vistaTimer.CastToArray()\r\n                        },\r\n                        new PSBlock\r\n                        {\r\n                            Type = BlockType.NAMED,\r\n                            Flags = 0,\r\n                            KeyAsStr = key,\r\n                            ValueAsStr = actId.ToString(),\r\n                            Data = kmsData\r\n                        }\r\n                    });\r\n                }\r\n                else\r\n                {\r\n                    byte[] hwidBlock = Constants.UniversalHWIDBlock;\r\n                    byte[] kmsResp;\r\n\r\n                    switch (version)\r\n                    {\r\n                        case PSVersion.Win7:\r\n                            kmsResp = Constants.KMSv4Response;\r\n                            break;\r\n                        case PSVersion.Win8:\r\n                            kmsResp = Constants.KMSv5Response;\r\n                            break;\r\n                        case PSVersion.WinBlue:\r\n                        case PSVersion.WinModern:\r\n                            kmsResp = Constants.KMSv6Response;\r\n                            break;\r\n                        default:\r\n                            throw new NotSupportedException(\"Unsupported PSVersion.\");\r\n                    }\r\n\r\n                    VariableBag kmsBinding = new VariableBag(version);\r\n\r\n                    kmsBinding.Blocks.AddRange(new[]\r\n                    {\r\n                    new CRCBlockModern\r\n                    {\r\n                        DataType = CRCBlockType.BINARY,\r\n                        Key = new byte[] { },\r\n                        Value = kmsResp\r\n                    },\r\n                    new CRCBlockModern\r\n                    {\r\n                        DataType = CRCBlockType.STRING,\r\n                        Key = new byte[] { },\r\n                        ValueAsStr = \"msft:rm/algorithm/hwid/4.0\"\r\n                    },\r\n                    new CRCBlockModern\r\n                    {\r\n                        DataType = CRCBlockType.BINARY,\r\n                        KeyAsStr = \"SppBindingLicenseData\",\r\n                        Value = hwidBlock\r\n                    }\r\n                    });\r\n\r\n                    if (version == PSVersion.WinModern)\r\n                    {\r\n                        kmsBinding.Blocks.AddRange(new[]\r\n                        {\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.STRING,\r\n                            Key = new byte[] { },\r\n                            ValueAsStr = \"massgrave.dev\"\r\n                        },\r\n                        new CRCBlockModern\r\n                        {\r\n                            DataType = CRCBlockType.STRING,\r\n                            Key = new byte[] { },\r\n                            ValueAsStr = \"6969\"\r\n                        }\r\n                        });\r\n                    }\r\n\r\n                    byte[] kmsBindingData = kmsBinding.Serialize();\r\n\r\n                    Timer kmsTimer = new Timer\r\n                    {\r\n                        Unknown = unknown,\r\n                        Time1 = time1,\r\n                        Time2 = time2,\r\n                        Expiry = expiry\r\n                    };\r\n\r\n                    string storeVal = string.Format(\"msft:spp/kms/bind/2.0/store/{0}/{1}\", appId, actId);\r\n                    string timerVal = string.Format(\"msft:spp/kms/bind/2.0/timer/{0}/{1}\", appId, actId);\r\n\r\n                    store.DeleteBlock(key, storeVal);\r\n                    store.DeleteBlock(key, timerVal);\r\n\r\n                    store.AddBlocks(new[]\r\n                    {\r\n                    new PSBlock\r\n                    {\r\n                        Type = BlockType.NAMED,\r\n                        Flags = (version == PSVersion.WinModern) ? (uint)0x400 : 0,\r\n                        KeyAsStr = key,\r\n                        ValueAsStr = storeVal,\r\n                        Data = kmsBindingData\r\n                    },\r\n                    new PSBlock\r\n                    {\r\n                        Type = BlockType.TIMER,\r\n                        Flags = (version == PSVersion.Win7) ? (uint)0 : 0x4,\r\n                        KeyAsStr = key,\r\n                        ValueAsStr = timerVal,\r\n                        Data = kmsTimer.CastToArray()\r\n                    }\r\n                    });\r\n                }\r\n            }\r\n\r\n            SPPUtils.RestartSPP(version);\r\n            SLApi.FireStateChangedEvent(appId);\r\n            Logger.WriteLine(\"Activated using KMS4k successfully.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/Activators/ZeroCID.cs\r\nnamespace LibTSforge.Activators\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using Crypto;\r\n    using PhysicalStore;\r\n    using SPP;\r\n\r\n    public static class ZeroCID\r\n    {\r\n        private static void Deposit(Guid actId, string instId)\r\n        {\r\n            uint status = SLApi.DepositConfirmationID(actId, instId, Constants.ZeroCID);\r\n            Logger.WriteLine(string.Format(\"Depositing fake CID status {0:X}\", status));\r\n\r\n            if (status != 0)\r\n            {\r\n                throw new InvalidOperationException(\"Failed to deposit fake CID.\");\r\n            }\r\n        }\r\n\r\n        public static void Activate(PSVersion version, bool production, Guid actId)\r\n        {\r\n            Guid appId;\r\n\r\n            if (actId == Guid.Empty)\r\n            {\r\n                appId = SLApi.WINDOWS_APP_ID;\r\n                actId = SLApi.GetDefaultActivationID(appId, false);\r\n\r\n                if (actId == Guid.Empty)\r\n                {\r\n                    throw new NotSupportedException(\"No applicable activation IDs found.\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                appId = SLApi.GetAppId(actId);\r\n            }\r\n\r\n            if (!SLApi.IsPhoneActivatable(actId))\r\n            {\r\n                throw new NotSupportedException(\"Phone license is unavailable for this product.\");\r\n            }\r\n\r\n            string instId = SLApi.GetInstallationID(actId);\r\n            Guid pkeyId = SLApi.GetInstalledPkeyID(actId);\r\n\r\n            if (version == PSVersion.Vista || version == PSVersion.Win7)\r\n            {\r\n                Deposit(actId, instId);\r\n            }\r\n\r\n            SPPUtils.KillSPP(version);\r\n\r\n            Logger.WriteLine(\"Writing TrustedStore data...\");\r\n\r\n            using (IPhysicalStore store = SPPUtils.GetStore(version, production))\r\n            {\r\n                byte[] hwidBlock = Constants.UniversalHWIDBlock;\r\n\r\n                Logger.WriteLine(\"Activation ID: \" + actId);\r\n                Logger.WriteLine(\"Installation ID: \" + instId);\r\n                Logger.WriteLine(\"Product Key ID: \" + pkeyId);\r\n\r\n                byte[] iidHash;\r\n\r\n                if (version == PSVersion.Vista)\r\n                {\r\n                    iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId)).Take(0x10).ToArray();\r\n                }\r\n                else if (version == PSVersion.Win7)\r\n                {\r\n                    iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId));\r\n                }\r\n                else\r\n                {\r\n                    iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId + '\\0' + Constants.ZeroCID));\r\n                }\r\n\r\n                string key = string.Format(\"SPPSVC\\\\{0}\\\\{1}\", appId, actId);\r\n                PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());\r\n\r\n                if (keyBlock == null)\r\n                {\r\n                    throw new InvalidDataException(\"Failed to get product key data for activation ID \" + actId + \".\");\r\n                }\r\n\r\n                VariableBag pkb = new VariableBag(keyBlock.Data, version);\r\n\r\n                byte[] pkeyData;\r\n\r\n                if (version == PSVersion.Vista)\r\n                {\r\n                    pkeyData = pkb.GetBlock(\"PKeyBasicInfo\").Value;\r\n                    string uniqueId = Utils.DecodeString(pkeyData.Skip(0x120).Take(0x80).ToArray());\r\n                    string extPid = Utils.DecodeString(pkeyData.Skip(0x1A0).Take(0x80).ToArray());\r\n\r\n                    uint group;\r\n                    uint.TryParse(extPid.Split('-')[1], out group);\r\n\r\n                    if (group == 0)\r\n                    {\r\n                        throw new FormatException(\"Extended PID has invalid format.\");\r\n                    }\r\n\r\n                    ulong shortauth;\r\n\r\n                    try\r\n                    {\r\n                        shortauth = BitConverter.ToUInt64(Convert.FromBase64String(uniqueId.Split('&')[1]), 0);\r\n                    } \r\n                    catch\r\n                    {\r\n                        throw new FormatException(\"Key Unique ID has invalid format.\");\r\n                    }\r\n\r\n                    shortauth |= (ulong)group << 41;\r\n                    pkeyData = BitConverter.GetBytes(shortauth);\r\n                }\r\n                else if (version == PSVersion.Win7)\r\n                {\r\n                    pkeyData = pkb.GetBlock(\"SppPkeyShortAuthenticator\").Value;\r\n                }\r\n                else\r\n                {\r\n                    pkeyData = pkb.GetBlock(\"SppPkeyPhoneActivationData\").Value;\r\n                }\r\n\r\n                pkb.DeleteBlock(\"SppPkeyVirtual\");\r\n                store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());\r\n\r\n                BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n                writer.Write(iidHash.Length);\r\n                writer.Write(iidHash);\r\n                writer.Write(hwidBlock.Length);\r\n                writer.Write(hwidBlock);\r\n                byte[] tsHwidData = writer.GetBytes();\r\n\r\n                writer = new BinaryWriter(new MemoryStream());\r\n                writer.Write(iidHash.Length);\r\n                writer.Write(iidHash);\r\n                writer.Write(pkeyData.Length);\r\n                writer.Write(pkeyData);\r\n                byte[] tsPkeyInfoData = writer.GetBytes();\r\n\r\n                string phoneVersion = version == PSVersion.Vista ? \"6.0\" : \"7.0\";\r\n                Guid indexSlid = version == PSVersion.Vista ? actId : pkeyId;\r\n                string hwidBlockName = string.Format(\"msft:Windows/{0}/Phone/Cached/HwidBlock/{1}\", phoneVersion, indexSlid);\r\n                string pkeyInfoName = string.Format(\"msft:Windows/{0}/Phone/Cached/PKeyInfo/{1}\", phoneVersion, indexSlid);\r\n\r\n                store.DeleteBlock(key, hwidBlockName);\r\n                store.DeleteBlock(key, pkeyInfoName);\r\n\r\n                store.AddBlocks(new[] {\r\n                    new PSBlock\r\n                    {\r\n                        Type = BlockType.NAMED,\r\n                        Flags = 0,\r\n                        KeyAsStr = key,\r\n                        ValueAsStr = hwidBlockName,\r\n                        Data = tsHwidData\r\n                    }, \r\n                    new PSBlock\r\n                    {\r\n                        Type = BlockType.NAMED,\r\n                        Flags = 0,\r\n                        KeyAsStr = key,\r\n                        ValueAsStr = pkeyInfoName,\r\n                        Data = tsPkeyInfoData\r\n                    }\r\n                });\r\n            }\r\n\r\n            if (version != PSVersion.Vista && version != PSVersion.Win7)\r\n            {\r\n                Deposit(actId, instId);\r\n            }\r\n\r\n            SPPUtils.RestartSPP(version);\r\n            SLApi.FireStateChangedEvent(appId);\r\n            Logger.WriteLine(\"Activated using ZeroCID successfully.\");\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/TokenStore/Common.cs\r\nnamespace LibTSforge.TokenStore\r\n{\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n\r\n    public class TokenEntry\r\n    {\r\n        public string Name;\r\n        public string Extension;\r\n        public byte[] Data;\r\n        public bool Populated;\r\n    }\r\n\r\n    public class TokenMeta\r\n    {\r\n        public string Name;\r\n        public readonly Dictionary<string, string> Data = new Dictionary<string, string>();\r\n\r\n        public byte[] Serialize()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(1);\r\n            byte[] nameBytes = Utils.EncodeString(Name);\r\n            writer.Write(nameBytes.Length);\r\n            writer.Write(nameBytes);\r\n\r\n            foreach (KeyValuePair<string, string> kv in Data)\r\n            {\r\n                byte[] keyBytes = Utils.EncodeString(kv.Key);\r\n                byte[] valueBytes = Utils.EncodeString(kv.Value);\r\n                writer.Write(keyBytes.Length);\r\n                writer.Write(valueBytes.Length);\r\n                writer.Write(keyBytes);\r\n                writer.Write(valueBytes);\r\n            }\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        private void Deserialize(byte[] data)\r\n        {\r\n            BinaryReader reader = new BinaryReader(new MemoryStream(data));\r\n            reader.ReadInt32();\r\n            int nameLen = reader.ReadInt32();\r\n            Name = reader.ReadNullTerminatedString(nameLen);\r\n\r\n            while (reader.BaseStream.Position < data.Length - 0x8)\r\n            {\r\n                int keyLen = reader.ReadInt32();\r\n                int valueLen = reader.ReadInt32();\r\n                string key = reader.ReadNullTerminatedString(keyLen);\r\n                string value = reader.ReadNullTerminatedString(valueLen);\r\n                Data[key] = value;\r\n            }\r\n        }\r\n\r\n        public TokenMeta(byte[] data)\r\n        {\r\n            Deserialize(data);\r\n        }\r\n\r\n        public TokenMeta()\r\n        {\r\n\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/TokenStore/ITokenStore.cs\r\nnamespace LibTSforge.TokenStore\r\n{\r\n    using System;\r\n\r\n    public interface ITokenStore : IDisposable\r\n    {\r\n        void Deserialize();\r\n        void Serialize();\r\n        void AddEntry(TokenEntry entry);\r\n        void AddEntries(TokenEntry[] entries);\r\n        void DeleteEntry(string name, string ext);\r\n        void DeleteUnpopEntry(string name, string ext);\r\n        TokenEntry GetEntry(string name, string ext);\r\n        TokenMeta GetMetaEntry(string name);\r\n        void SetEntry(string name, string ext, byte[] data);\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/TokenStore/TokenStoreModern.cs\r\nnamespace LibTSforge.TokenStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using System.Linq;\r\n    using Crypto;\r\n\r\n    public class TokenStoreModern : ITokenStore\r\n    {\r\n        private static readonly uint VERSION = 3;\r\n        private static readonly int ENTRY_SIZE = 0x9E;\r\n        private static readonly int BLOCK_SIZE = 0x4020;\r\n        private static readonly int ENTRIES_PER_BLOCK = BLOCK_SIZE / ENTRY_SIZE;\r\n        private static readonly int BLOCK_PAD_SIZE = 0x66;\r\n\r\n        private static readonly byte[] CONTS_HEADER = Enumerable.Repeat((byte)0x55, 0x20).ToArray();\r\n        private static readonly byte[] CONTS_FOOTER = Enumerable.Repeat((byte)0xAA, 0x20).ToArray();\r\n\r\n        private List<TokenEntry> Entries = new List<TokenEntry>();\r\n        private readonly FileStream TokensFile;\r\n\r\n        public void Deserialize()\r\n        {\r\n            if (TokensFile.Length < BLOCK_SIZE) return;\r\n\r\n            TokensFile.Seek(0x24, SeekOrigin.Begin);\r\n            uint nextBlock;\r\n\r\n            BinaryReader reader = new BinaryReader(TokensFile);\r\n            do\r\n            {\r\n                reader.ReadUInt32();\r\n                nextBlock = reader.ReadUInt32();\r\n\r\n                for (int i = 0; i < ENTRIES_PER_BLOCK; i++)\r\n                {\r\n                    uint curOffset = reader.ReadUInt32();\r\n                    bool populated = reader.ReadUInt32() == 1;\r\n                    uint contentOffset = reader.ReadUInt32();\r\n                    uint contentLength = reader.ReadUInt32();\r\n                    uint allocLength = reader.ReadUInt32();\r\n                    byte[] contentData = { };\r\n\r\n                    if (populated)\r\n                    {\r\n                        reader.BaseStream.Seek(contentOffset + 0x20, SeekOrigin.Begin);\r\n                        uint dataLength = reader.ReadUInt32();\r\n\r\n                        if (dataLength != contentLength)\r\n                        {\r\n                            throw new FormatException(\"Data length in tokens content is inconsistent with entry.\");\r\n                        }\r\n\r\n                        reader.ReadBytes(0x20);\r\n                        contentData = reader.ReadBytes((int)contentLength);\r\n                    }\r\n\r\n                    reader.BaseStream.Seek(curOffset + 0x14, SeekOrigin.Begin);\r\n\r\n                    Entries.Add(new TokenEntry\r\n                    {\r\n                        Name = reader.ReadNullTerminatedString(0x82),\r\n                        Extension = reader.ReadNullTerminatedString(0x8),\r\n                        Data = contentData,\r\n                        Populated = populated\r\n                    });\r\n                }\r\n\r\n                reader.BaseStream.Seek(nextBlock, SeekOrigin.Begin);\r\n            } while (nextBlock != 0);\r\n        }\r\n\r\n        public void Serialize()\r\n        {\r\n            MemoryStream tokens = new MemoryStream();\r\n\r\n            using (BinaryWriter writer = new BinaryWriter(tokens))\r\n            {\r\n                writer.Write(VERSION);\r\n                writer.Write(CONTS_HEADER);\r\n\r\n                int curBlockOffset = (int)writer.BaseStream.Position;\r\n                int curEntryOffset = curBlockOffset + 0x8;\r\n                int curContsOffset = curBlockOffset + BLOCK_SIZE;\r\n\r\n                for (int eIndex = 0; eIndex < ((Entries.Count / ENTRIES_PER_BLOCK) + 1) * ENTRIES_PER_BLOCK; eIndex++)\r\n                {\r\n                    TokenEntry entry;\r\n\r\n                    if (eIndex < Entries.Count)\r\n                    {\r\n                        entry = Entries[eIndex];\r\n                    }\r\n                    else\r\n                    {\r\n                        entry = new TokenEntry\r\n                        {\r\n                            Name = \"\",\r\n                            Extension = \"\",\r\n                            Populated = false,\r\n                            Data = new byte[] { }\r\n                        };\r\n                    }\r\n\r\n                    writer.BaseStream.Seek(curBlockOffset, SeekOrigin.Begin);\r\n                    writer.Write(curBlockOffset);\r\n                    writer.Write(0);\r\n\r\n                    writer.BaseStream.Seek(curEntryOffset, SeekOrigin.Begin);\r\n                    writer.Write(curEntryOffset);\r\n                    writer.Write(entry.Populated ? 1 : 0);\r\n                    writer.Write(entry.Populated ? curContsOffset : 0);\r\n                    writer.Write(entry.Populated ? entry.Data.Length : -1);\r\n                    writer.Write(entry.Populated ? entry.Data.Length : -1);\r\n                    writer.WriteFixedString16(entry.Name, 0x82);\r\n                    writer.WriteFixedString16(entry.Extension, 0x8);\r\n                    curEntryOffset = (int)writer.BaseStream.Position;\r\n\r\n                    if (entry.Populated)\r\n                    {\r\n                        writer.BaseStream.Seek(curContsOffset, SeekOrigin.Begin);\r\n                        writer.Write(CONTS_HEADER);\r\n                        writer.Write(entry.Data.Length);\r\n                        writer.Write(CryptoUtils.SHA256Hash(entry.Data));\r\n                        writer.Write(entry.Data);\r\n                        writer.Write(CONTS_FOOTER);\r\n                        curContsOffset = (int)writer.BaseStream.Position;\r\n                    }\r\n\r\n                    if ((eIndex + 1) % ENTRIES_PER_BLOCK == 0 && eIndex != 0)\r\n                    {\r\n                        if (eIndex < Entries.Count)\r\n                        {\r\n                            writer.BaseStream.Seek(curBlockOffset + 0x4, SeekOrigin.Begin);\r\n                            writer.Write(curContsOffset);\r\n                        }\r\n\r\n                        writer.BaseStream.Seek(curEntryOffset, SeekOrigin.Begin);\r\n                        writer.WritePadding(BLOCK_PAD_SIZE);\r\n\r\n                        writer.BaseStream.Seek(curBlockOffset, SeekOrigin.Begin);\r\n                        byte[] blockData = new byte[BLOCK_SIZE - 0x20];\r\n\r\n                        tokens.Read(blockData, 0, BLOCK_SIZE - 0x20);\r\n                        byte[] blockHash = CryptoUtils.SHA256Hash(blockData);\r\n\r\n                        writer.BaseStream.Seek(curBlockOffset + BLOCK_SIZE - 0x20, SeekOrigin.Begin);\r\n                        writer.Write(blockHash);\r\n\r\n                        curBlockOffset = curContsOffset;\r\n                        curEntryOffset = curBlockOffset + 0x8;\r\n                        curContsOffset = curBlockOffset + BLOCK_SIZE;\r\n                    }\r\n                }\r\n\r\n                tokens.SetLength(curBlockOffset);\r\n            }\r\n\r\n            byte[] tokensData = tokens.ToArray();\r\n            byte[] tokensHash = CryptoUtils.SHA256Hash(tokensData.Take(0x4).Concat(tokensData.Skip(0x24)).ToArray());\r\n\r\n            tokens = new MemoryStream(tokensData);\r\n\r\n            BinaryWriter tokWriter = new BinaryWriter(TokensFile);\r\n            using (BinaryReader reader = new BinaryReader(tokens))\r\n            {\r\n                TokensFile.Seek(0, SeekOrigin.Begin);\r\n                TokensFile.SetLength(tokens.Length);\r\n                tokWriter.Write(reader.ReadBytes(0x4));\r\n                reader.ReadBytes(0x20);\r\n                tokWriter.Write(tokensHash);\r\n                tokWriter.Write(reader.ReadBytes((int)reader.BaseStream.Length - 0x4));\r\n            }\r\n        }\r\n\r\n        public void AddEntry(TokenEntry entry)\r\n        {\r\n            Entries.Add(entry);\r\n        }\r\n\r\n        public void AddEntries(TokenEntry[] entries)\r\n        {\r\n            Entries.AddRange(entries);\r\n        }\r\n\r\n        public void DeleteEntry(string name, string ext)\r\n        {\r\n            foreach (TokenEntry entry in Entries)\r\n            {\r\n                if (entry.Name == name && entry.Extension == ext)\r\n                {\r\n                    Entries.Remove(entry);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void DeleteUnpopEntry(string name, string ext)\r\n        {\r\n            List<TokenEntry> delEntries = new List<TokenEntry>();\r\n            foreach (TokenEntry entry in Entries)\r\n            {\r\n                if (entry.Name == name && entry.Extension == ext && !entry.Populated)\r\n                {\r\n                    delEntries.Add(entry);\r\n                }\r\n            }\r\n\r\n            Entries = Entries.Except(delEntries).ToList();\r\n        }\r\n\r\n        public TokenEntry GetEntry(string name, string ext)\r\n        {\r\n            foreach (TokenEntry entry in Entries)\r\n            {\r\n                if (entry.Name == name && entry.Extension == ext)\r\n                {\r\n                    if (!entry.Populated) continue;\r\n                    return entry;\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public TokenMeta GetMetaEntry(string name)\r\n        {\r\n            DeleteUnpopEntry(name, \"xml\");\r\n            TokenEntry entry = GetEntry(name, \"xml\");\r\n            TokenMeta meta;\r\n\r\n            if (entry == null)\r\n            {\r\n                meta = new TokenMeta\r\n                {\r\n                    Name = name\r\n                };\r\n            }\r\n            else\r\n            {\r\n                meta = new TokenMeta(entry.Data);\r\n            }\r\n\r\n            return meta;\r\n        }\r\n\r\n        public void SetEntry(string name, string ext, byte[] data)\r\n        {\r\n            for (int i = 0; i < Entries.Count; i++)\r\n            {\r\n                TokenEntry entry = Entries[i];\r\n\r\n                if (entry.Name == name && entry.Extension == ext && entry.Populated)\r\n                {\r\n                    entry.Data = data;\r\n                    Entries[i] = entry;\r\n                    return;\r\n                }\r\n            }\r\n\r\n            Entries.Add(new TokenEntry\r\n            {\r\n                Populated = true,\r\n                Name = name,\r\n                Extension = ext,\r\n                Data = data\r\n            });\r\n        }\r\n\r\n        public TokenStoreModern(string tokensPath)\r\n        {\r\n            TokensFile = File.Open(tokensPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            Deserialize();\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            Serialize();\r\n            TokensFile.Close();\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/Common.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System.Runtime.InteropServices;\r\n\r\n    public enum BlockType : uint\r\n    {\r\n        NONE,\r\n        NAMED,\r\n        ATTRIBUTE,\r\n        TIMER\r\n    }\r\n\r\n    [StructLayout(LayoutKind.Sequential, Pack = 1)]\r\n    public struct Timer\r\n    {\r\n        public ulong Unknown;\r\n        public ulong Time1;\r\n        public ulong Time2;\r\n        public ulong Expiry;\r\n    }\r\n\r\n    [StructLayout(LayoutKind.Sequential, Pack = 1)]\r\n    public struct VistaTimer\r\n    {\r\n        public ulong Time;\r\n        public ulong Expiry;\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/IPhysicalStore.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n\r\n    public class PSBlock\r\n    {\r\n        public BlockType Type;\r\n        public uint Flags;\r\n        public uint Unknown = 0;\r\n        public byte[] Key;\r\n        public string KeyAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Key);\r\n            }\r\n            set\r\n            {\r\n                Key = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public byte[] Value;\r\n        public string ValueAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Value);\r\n            }\r\n            set\r\n            {\r\n                Value = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint ValueAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Value, 0);\r\n            }\r\n            set\r\n            {\r\n                Value = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n        public byte[] Data;\r\n        public string DataAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Data);\r\n            }\r\n            set\r\n            {\r\n                Data = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint DataAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Data, 0);\r\n            }\r\n            set\r\n            {\r\n                Data = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n    }\r\n\r\n    public interface IPhysicalStore : IDisposable\r\n    {\r\n        PSBlock GetBlock(string key, string value);\r\n        PSBlock GetBlock(string key, uint value);\r\n        void AddBlock(PSBlock block);\r\n        void AddBlocks(IEnumerable<PSBlock> blocks);\r\n        void SetBlock(string key, string value, byte[] data);\r\n        void SetBlock(string key, string value, string data);\r\n        void SetBlock(string key, string value, uint data);\r\n        void SetBlock(string key, uint value, byte[] data);\r\n        void SetBlock(string key, uint value, string data);\r\n        void SetBlock(string key, uint value, uint data);\r\n        void DeleteBlock(string key, string value);\r\n        void DeleteBlock(string key, uint value);\r\n        byte[] Serialize();\r\n        void Deserialize(byte[] data);\r\n        byte[] ReadRaw();\r\n        void WriteRaw(byte[] data);\r\n        IEnumerable<PSBlock> FindBlocks(string valueSearch);\r\n        IEnumerable<PSBlock> FindBlocks(uint valueSearch);\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/PhysicalStoreModern.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using Crypto;\r\n\r\n    public class ModernBlock\r\n    {\r\n        public BlockType Type;\r\n        public uint Flags;\r\n        public uint Unknown;\r\n        public byte[] Value;\r\n        public string ValueAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Value);\r\n            }\r\n            set\r\n            {\r\n                Value = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint ValueAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Value, 0);\r\n            }\r\n            set\r\n            {\r\n                Value = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n        public byte[] Data;\r\n        public string DataAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Data);\r\n            }\r\n            set\r\n            {\r\n                Data = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint DataAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Data, 0);\r\n            }\r\n            set\r\n            {\r\n                Data = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n\r\n        public void Encode(BinaryWriter writer)\r\n        {\r\n            writer.Write((uint)Type);\r\n            writer.Write(Flags);\r\n            writer.Write((uint)Value.Length);\r\n            writer.Write((uint)Data.Length);\r\n            writer.Write(Unknown);\r\n            writer.Write(Value);\r\n            writer.Write(Data);\r\n        }\r\n\r\n        public static ModernBlock Decode(BinaryReader reader)\r\n        {\r\n            uint type = reader.ReadUInt32();\r\n            uint flags = reader.ReadUInt32();\r\n\r\n            uint valueLen = reader.ReadUInt32();\r\n            uint dataLen = reader.ReadUInt32();\r\n            uint unk3 = reader.ReadUInt32();\r\n\r\n            byte[] value = reader.ReadBytes((int)valueLen);\r\n            byte[] data = reader.ReadBytes((int)dataLen);\r\n\r\n            return new ModernBlock\r\n            {\r\n                Type = (BlockType)type,\r\n                Flags = flags,\r\n                Unknown = unk3,\r\n                Value = value,\r\n                Data = data,\r\n            };\r\n        }\r\n    }\r\n\r\n    public sealed class PhysicalStoreModern : IPhysicalStore\r\n    {\r\n        private byte[] PreHeaderBytes = { };\r\n        private readonly Dictionary<string, List<ModernBlock>> Data = new Dictionary<string, List<ModernBlock>>();\r\n        private readonly FileStream TSFile;\r\n        private readonly PSVersion Version;\r\n        private readonly bool Production;\r\n\r\n        public byte[] Serialize()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(PreHeaderBytes);\r\n            writer.Write(Data.Keys.Count);\r\n\r\n            foreach (string key in Data.Keys)\r\n            {\r\n                List<ModernBlock> blocks = Data[key];\r\n                byte[] keyNameEnc = Utils.EncodeString(key);\r\n\r\n                writer.Write(keyNameEnc.Length);\r\n                writer.Write(keyNameEnc);\r\n                writer.Write(blocks.Count);\r\n                writer.Align(4);\r\n\r\n                foreach (ModernBlock block in blocks)\r\n                {\r\n                    block.Encode(writer);\r\n                    writer.Align(4);\r\n                }\r\n            }\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public void Deserialize(byte[] data)\r\n        {\r\n            BinaryReader reader = new BinaryReader(new MemoryStream(data));\r\n            PreHeaderBytes = reader.ReadBytes(8);\r\n\r\n            while (reader.BaseStream.Position < data.Length - 0x4)\r\n            {\r\n                uint numKeys = reader.ReadUInt32();\r\n\r\n                for (int i = 0; i < numKeys; i++)\r\n                {\r\n                    uint lenKeyName = reader.ReadUInt32();\r\n                    string keyName = Utils.DecodeString(reader.ReadBytes((int)lenKeyName)); uint numValues = reader.ReadUInt32();\r\n\r\n                    reader.Align(4);\r\n\r\n                    Data[keyName] = new List<ModernBlock>();\r\n\r\n                    for (int j = 0; j < numValues; j++)\r\n                    {\r\n                        Data[keyName].Add(ModernBlock.Decode(reader));\r\n                        reader.Align(4);\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        public void AddBlock(PSBlock block)\r\n        {\r\n            if (!Data.ContainsKey(block.KeyAsStr))\r\n            {\r\n                Data[block.KeyAsStr] = new List<ModernBlock>();\r\n            }\r\n\r\n            Data[block.KeyAsStr].Add(new ModernBlock\r\n            {\r\n                Type = block.Type,\r\n                Flags = block.Flags,\r\n                Unknown = block.Unknown,\r\n                Value = block.Value,\r\n                Data = block.Data\r\n            });\r\n        }\r\n\r\n        public void AddBlocks(IEnumerable<PSBlock> blocks)\r\n        {\r\n            foreach (PSBlock block in blocks)\r\n            {\r\n                AddBlock(block);\r\n            }\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, string value)\r\n        {\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            foreach (ModernBlock block in blocks)\r\n            {\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = Utils.EncodeString(key),\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, uint value)\r\n        {\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            foreach (ModernBlock block in blocks)\r\n            {\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = Utils.EncodeString(key),\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public void SetBlock(string key, string value, byte[] data)\r\n        {\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            for (int i = 0; i < blocks.Count; i++)\r\n            {\r\n                ModernBlock block = blocks[i];\r\n\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    block.Data = data;\r\n                    blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n\r\n            Data[key] = blocks;\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, byte[] data)\r\n        {\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            for (int i = 0; i < blocks.Count; i++)\r\n            {\r\n                ModernBlock block = blocks[i];\r\n\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    block.Data = data;\r\n                    blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n\r\n            Data[key] = blocks;\r\n        }\r\n\r\n        public void SetBlock(string key, string value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, string value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void DeleteBlock(string key, string value)\r\n        {\r\n            if (!Data.ContainsKey(key))\r\n            {\r\n                return;\r\n            }\r\n\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            foreach (ModernBlock block in blocks)\r\n            {\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    blocks.Remove(block);\r\n                    break;\r\n                }\r\n            }\r\n\r\n            Data[key] = blocks;\r\n        }\r\n\r\n        public void DeleteBlock(string key, uint value)\r\n        {\r\n            if (!Data.ContainsKey(key))\r\n            {\r\n                return;\r\n            }\r\n\r\n            List<ModernBlock> blocks = Data[key];\r\n\r\n            foreach (ModernBlock block in blocks)\r\n            {\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    blocks.Remove(block);\r\n                    break;\r\n                }\r\n            }\r\n\r\n            Data[key] = blocks;\r\n        }\r\n\r\n        public PhysicalStoreModern(string tsPath, bool production, PSVersion version)\r\n        {\r\n            TSFile = File.Open(tsPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSFile.ReadAllBytes(), production, version));\r\n            TSFile.Seek(0, SeekOrigin.Begin);\r\n            Version = version;\r\n            Production = production;\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            if (TSFile.CanWrite)\r\n            {\r\n                byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, Version);\r\n                TSFile.SetLength(data.LongLength);\r\n                TSFile.Seek(0, SeekOrigin.Begin);\r\n                TSFile.WriteAllBytes(data);\r\n                TSFile.Close();\r\n            }\r\n        }\r\n\r\n        public byte[] ReadRaw()\r\n        {\r\n            byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSFile.ReadAllBytes(), Production, Version);\r\n            TSFile.Seek(0, SeekOrigin.Begin);\r\n            return data;\r\n        }\r\n\r\n        public void WriteRaw(byte[] data)\r\n        {\r\n            byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, Version);\r\n            TSFile.SetLength(encrData.LongLength);\r\n            TSFile.Seek(0, SeekOrigin.Begin);\r\n            TSFile.WriteAllBytes(encrData);\r\n            TSFile.Close();\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(string valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (string key in Data.Keys)\r\n            {\r\n                List<ModernBlock> values = Data[key];\r\n\r\n                foreach (ModernBlock block in values)\r\n                {\r\n                    if (block.ValueAsStr.Contains(valueSearch))\r\n                    {\r\n                        results.Add(new PSBlock\r\n                        {\r\n                            Type = block.Type,\r\n                            Flags = block.Flags,\r\n                            KeyAsStr = key,\r\n                            Value = block.Value,\r\n                            Data = block.Data\r\n                        });\r\n                    }\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(uint valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (string key in Data.Keys)\r\n            {\r\n                List<ModernBlock> values = Data[key];\r\n\r\n                foreach (ModernBlock block in values)\r\n                {\r\n                    if (block.ValueAsInt == valueSearch)\r\n                    {\r\n                        results.Add(new PSBlock\r\n                        {\r\n                            Type = block.Type,\r\n                            Flags = block.Flags,\r\n                            KeyAsStr = key,\r\n                            Value = block.Value,\r\n                            Data = block.Data\r\n                        });\r\n                    }\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/PhysicalStoreVista.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using Crypto;\r\n\r\n    public class VistaBlock\r\n    {\r\n        public BlockType Type;\r\n        public uint Flags;\r\n        public byte[] Value;\r\n        public string ValueAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Value);\r\n            }\r\n            set\r\n            {\r\n                Value = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint ValueAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Value, 0);\r\n            }\r\n            set\r\n            {\r\n                Value = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n        public byte[] Data;\r\n        public string DataAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Data);\r\n            }\r\n            set\r\n            {\r\n                Data = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint DataAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Data, 0);\r\n            }\r\n            set\r\n            {\r\n                Data = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n\r\n        internal void Encode(BinaryWriter writer)\r\n        {\r\n            writer.Write((uint)Type);\r\n            writer.Write(Flags);\r\n            writer.Write(Value.Length);\r\n            writer.Write(Data.Length);\r\n            writer.Write(Value);\r\n            writer.Write(Data);\r\n        }\r\n\r\n        internal static VistaBlock Decode(BinaryReader reader)\r\n        {\r\n            uint type = reader.ReadUInt32();\r\n            uint flags = reader.ReadUInt32();\r\n\r\n            int valueLen = reader.ReadInt32();\r\n            int dataLen = reader.ReadInt32();\r\n\r\n            byte[] value = reader.ReadBytes(valueLen);\r\n            byte[] data = reader.ReadBytes(dataLen);\r\n            return new VistaBlock\r\n            {\r\n                Type = (BlockType)type,\r\n                Flags = flags,\r\n                Value = value,\r\n                Data = data,\r\n            };\r\n        }\r\n    }\r\n\r\n    public sealed class PhysicalStoreVista : IPhysicalStore\r\n    {\r\n        private byte[] PreHeaderBytes = { };\r\n        private readonly List<VistaBlock> Blocks = new List<VistaBlock>();\r\n        private readonly FileStream TSPrimary;\r\n        private readonly FileStream TSSecondary;\r\n        private readonly bool Production;\r\n\r\n        public byte[] Serialize()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(PreHeaderBytes);\r\n\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                block.Encode(writer);\r\n                writer.Align(4);\r\n            }\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public void Deserialize(byte[] data)\r\n        {\r\n            int len = data.Length;\r\n\r\n            BinaryReader reader = new BinaryReader(new MemoryStream(data));\r\n            PreHeaderBytes = reader.ReadBytes(8);\r\n\r\n            while (reader.BaseStream.Position < len - 0x14)\r\n            {\r\n                Blocks.Add(VistaBlock.Decode(reader));\r\n                reader.Align(4);\r\n            }\r\n        }\r\n\r\n        public void AddBlock(PSBlock block)\r\n        {\r\n            Blocks.Add(new VistaBlock\r\n            {\r\n                Type = block.Type,\r\n                Flags = block.Flags,\r\n                Value = block.Value,\r\n                Data = block.Data\r\n            });\r\n        }\r\n\r\n        public void AddBlocks(IEnumerable<PSBlock> blocks)\r\n        {\r\n            foreach (PSBlock block in blocks)\r\n            {\r\n                AddBlock(block);\r\n            }\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, string value)\r\n        {\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = new byte[0],\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, uint value)\r\n        {\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = new byte[0],\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public void SetBlock(string key, string value, byte[] data)\r\n        {\r\n            for (int i = 0; i < Blocks.Count; i++)\r\n            {\r\n                VistaBlock block = Blocks[i];\r\n\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    block.Data = data;\r\n                    Blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, byte[] data)\r\n        {\r\n            for (int i = 0; i < Blocks.Count; i++)\r\n            {\r\n                VistaBlock block = Blocks[i];\r\n\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    block.Data = data;\r\n                    Blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void SetBlock(string key, string value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, string value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void DeleteBlock(string key, string value)\r\n        {\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsStr == value)\r\n                {\r\n                    Blocks.Remove(block);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void DeleteBlock(string key, uint value)\r\n        {\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsInt == value)\r\n                {\r\n                    Blocks.Remove(block);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public PhysicalStoreVista(string primaryPath, bool production)\r\n        {\r\n            TSPrimary = File.Open(primaryPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            TSSecondary = File.Open(primaryPath.Replace(\"-0.\", \"-1.\"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            Production = production;\r\n\r\n            Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), production, PSVersion.Vista));\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            if (TSPrimary.CanWrite && TSSecondary.CanWrite)\r\n            {\r\n                byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, PSVersion.Vista);\r\n\r\n                TSPrimary.SetLength(data.LongLength);\r\n                TSSecondary.SetLength(data.LongLength);\r\n\r\n                TSPrimary.Seek(0, SeekOrigin.Begin);\r\n                TSSecondary.Seek(0, SeekOrigin.Begin);\r\n\r\n                TSPrimary.WriteAllBytes(data);\r\n                TSSecondary.WriteAllBytes(data);\r\n\r\n                TSPrimary.Close();\r\n                TSSecondary.Close();\r\n            }\r\n        }\r\n\r\n        public byte[] ReadRaw()\r\n        {\r\n            byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), Production, PSVersion.Vista);\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n            return data;\r\n        }\r\n\r\n        public void WriteRaw(byte[] data)\r\n        {\r\n            byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, PSVersion.Vista);\r\n\r\n            TSPrimary.SetLength(encrData.LongLength);\r\n            TSSecondary.SetLength(encrData.LongLength);\r\n\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n            TSSecondary.Seek(0, SeekOrigin.Begin);\r\n\r\n            TSPrimary.WriteAllBytes(encrData);\r\n            TSSecondary.WriteAllBytes(encrData);\r\n\r\n            TSPrimary.Close();\r\n            TSSecondary.Close();\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(string valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsStr.Contains(valueSearch))\r\n                {\r\n                    results.Add(new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = new byte[0],\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    });\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(uint valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (VistaBlock block in Blocks)\r\n            {\r\n                if (block.ValueAsInt == valueSearch)\r\n                {\r\n                    results.Add(new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = new byte[0],\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    });\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/PhysicalStoreWin7.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n    using Crypto;\r\n\r\n    public class Win7Block\r\n    {\r\n        public BlockType Type;\r\n        public uint Flags;\r\n        public byte[] Key;\r\n        public string KeyAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Key);\r\n            }\r\n            set\r\n            {\r\n                Key = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public byte[] Value;\r\n        public string ValueAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Value);\r\n            }\r\n            set\r\n            {\r\n                Value = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint ValueAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Value, 0);\r\n            }\r\n            set\r\n            {\r\n                Value = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n        public byte[] Data;\r\n        public string DataAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Data);\r\n            }\r\n            set\r\n            {\r\n                Data = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint DataAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Data, 0);\r\n            }\r\n            set\r\n            {\r\n                Data = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n\r\n        internal void Encode(BinaryWriter writer)\r\n        {\r\n            writer.Write((uint)Type);\r\n            writer.Write(Flags);\r\n            writer.Write(Key.Length);\r\n            writer.Write(Value.Length);\r\n            writer.Write(Data.Length);\r\n            writer.Write(Key);\r\n            writer.Write(Value);\r\n            writer.Write(Data);\r\n        }\r\n\r\n        internal static Win7Block Decode(BinaryReader reader)\r\n        {\r\n            uint type = reader.ReadUInt32();\r\n            uint flags = reader.ReadUInt32();\r\n\r\n            int keyLen = reader.ReadInt32();\r\n            int valueLen = reader.ReadInt32();\r\n            int dataLen = reader.ReadInt32();\r\n\r\n            byte[] key = reader.ReadBytes(keyLen);\r\n            byte[] value = reader.ReadBytes(valueLen);\r\n            byte[] data = reader.ReadBytes(dataLen);\r\n            return new Win7Block\r\n            {\r\n                Type = (BlockType)type,\r\n                Flags = flags,\r\n                Key = key,\r\n                Value = value,\r\n                Data = data,\r\n            };\r\n        }\r\n    }\r\n\r\n    public sealed class PhysicalStoreWin7 : IPhysicalStore\r\n    {\r\n        private byte[] PreHeaderBytes = { };\r\n        private readonly List<Win7Block> Blocks = new List<Win7Block>();\r\n        private readonly FileStream TSPrimary;\r\n        private readonly FileStream TSSecondary;\r\n        private readonly bool Production;\r\n\r\n        public byte[] Serialize()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n            writer.Write(PreHeaderBytes);\r\n\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                block.Encode(writer);\r\n                writer.Align(4);\r\n            }\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public void Deserialize(byte[] data)\r\n        {\r\n            int len = data.Length;\r\n\r\n            BinaryReader reader = new BinaryReader(new MemoryStream(data));\r\n            PreHeaderBytes = reader.ReadBytes(8);\r\n\r\n            while (reader.BaseStream.Position < len - 0x14)\r\n            {\r\n                Blocks.Add(Win7Block.Decode(reader));\r\n                reader.Align(4);\r\n            }\r\n        }\r\n\r\n        public void AddBlock(PSBlock block)\r\n        {\r\n            Blocks.Add(new Win7Block\r\n            {\r\n                Type = block.Type,\r\n                Flags = block.Flags,\r\n                Key = block.Key,\r\n                Value = block.Value,\r\n                Data = block.Data\r\n            });\r\n        }\r\n\r\n        public void AddBlocks(IEnumerable<PSBlock> blocks)\r\n        {\r\n            foreach (PSBlock block in blocks)\r\n            {\r\n                AddBlock(block);\r\n            }\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, string value)\r\n        {\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key && block.ValueAsStr == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = block.Key,\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public PSBlock GetBlock(string key, uint value)\r\n        {\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key && block.ValueAsInt == value)\r\n                {\r\n                    return new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = block.Key,\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    };\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public void SetBlock(string key, string value, byte[] data)\r\n        {\r\n            for (int i = 0; i < Blocks.Count; i++)\r\n            {\r\n                Win7Block block = Blocks[i];\r\n\r\n                if (block.KeyAsStr == key && block.ValueAsStr == value)\r\n                {\r\n                    block.Data = data;\r\n                    Blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, byte[] data)\r\n        {\r\n            for (int i = 0; i < Blocks.Count; i++)\r\n            {\r\n                Win7Block block = Blocks[i];\r\n\r\n                if (block.KeyAsStr == key && block.ValueAsInt == value)\r\n                {\r\n                    block.Data = data;\r\n                    Blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void SetBlock(string key, string value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, string value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, string data)\r\n        {\r\n            SetBlock(key, value, Utils.EncodeString(data));\r\n        }\r\n\r\n        public void SetBlock(string key, uint value, uint data)\r\n        {\r\n            SetBlock(key, value, BitConverter.GetBytes(data));\r\n        }\r\n\r\n        public void DeleteBlock(string key, string value)\r\n        {\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key && block.ValueAsStr == value)\r\n                {\r\n                    Blocks.Remove(block);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void DeleteBlock(string key, uint value)\r\n        {\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key && block.ValueAsInt == value)\r\n                {\r\n                    Blocks.Remove(block);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public PhysicalStoreWin7(string primaryPath, bool production)\r\n        {\r\n            TSPrimary = File.Open(primaryPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            TSSecondary = File.Open(primaryPath.Replace(\"-0.\", \"-1.\"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);\r\n            Production = production;\r\n\r\n            Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), production, PSVersion.Win7));\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            if (TSPrimary.CanWrite && TSSecondary.CanWrite)\r\n            {\r\n                byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, PSVersion.Win7);\r\n\r\n                TSPrimary.SetLength(data.LongLength);\r\n                TSSecondary.SetLength(data.LongLength);\r\n\r\n                TSPrimary.Seek(0, SeekOrigin.Begin);\r\n                TSSecondary.Seek(0, SeekOrigin.Begin);\r\n\r\n                TSPrimary.WriteAllBytes(data);\r\n                TSSecondary.WriteAllBytes(data);\r\n\r\n                TSPrimary.Close();\r\n                TSSecondary.Close();\r\n            }\r\n        }\r\n\r\n        public byte[] ReadRaw()\r\n        {\r\n            byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), Production, PSVersion.Win7);\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n            return data;\r\n        }\r\n\r\n        public void WriteRaw(byte[] data)\r\n        {\r\n            byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, PSVersion.Win7);\r\n\r\n            TSPrimary.SetLength(encrData.LongLength);\r\n            TSSecondary.SetLength(encrData.LongLength);\r\n\r\n            TSPrimary.Seek(0, SeekOrigin.Begin);\r\n            TSSecondary.Seek(0, SeekOrigin.Begin);\r\n\r\n            TSPrimary.WriteAllBytes(encrData);\r\n            TSSecondary.WriteAllBytes(encrData);\r\n\r\n            TSPrimary.Close();\r\n            TSSecondary.Close();\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(string valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.ValueAsStr.Contains(valueSearch))\r\n                {\r\n                    results.Add(new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = block.Key,\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    });\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n\r\n        public IEnumerable<PSBlock> FindBlocks(uint valueSearch)\r\n        {\r\n            List<PSBlock> results = new List<PSBlock>();\r\n\r\n            foreach (Win7Block block in Blocks)\r\n            {\r\n                if (block.ValueAsInt == valueSearch)\r\n                {\r\n                    results.Add(new PSBlock\r\n                    {\r\n                        Type = block.Type,\r\n                        Flags = block.Flags,\r\n                        Key = block.Key,\r\n                        Value = block.Value,\r\n                        Data = block.Data\r\n                    });\r\n                }\r\n            }\r\n\r\n            return results;\r\n        }\r\n    }\r\n}\r\n\r\n\r\n// LibTSforge/PhysicalStore/VariableBag.cs\r\nnamespace LibTSforge.PhysicalStore\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n\r\n    public enum CRCBlockType : uint\r\n    {\r\n        UINT = 1 << 0,\r\n        STRING = 1 << 1,\r\n        BINARY = 1 << 2\r\n    }\r\n\r\n    public abstract class CRCBlock\r\n    {\r\n        public CRCBlockType DataType;\r\n        public byte[] Key;\r\n        public string KeyAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Key);\r\n            }\r\n            set\r\n            {\r\n                Key = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public byte[] Value;\r\n        public string ValueAsStr\r\n        {\r\n            get\r\n            {\r\n                return Utils.DecodeString(Value);\r\n            }\r\n            set\r\n            {\r\n                Value = Utils.EncodeString(value);\r\n            }\r\n        }\r\n        public uint ValueAsInt\r\n        {\r\n            get\r\n            {\r\n                return BitConverter.ToUInt32(Value, 0);\r\n            }\r\n            set\r\n            {\r\n                Value = BitConverter.GetBytes(value);\r\n            }\r\n        }\r\n\r\n        public abstract void Encode(BinaryWriter writer);\r\n        public abstract void Decode(BinaryReader reader);\r\n        public abstract uint CRC();\r\n    }\r\n\r\n    public class CRCBlockVista : CRCBlock\r\n    {\r\n        public override void Encode(BinaryWriter writer)\r\n        {\r\n            uint crc = CRC();\r\n            writer.Write((uint)DataType);\r\n            writer.Write(0);\r\n            writer.Write(Key.Length);\r\n            writer.Write(Value.Length);\r\n            writer.Write(crc);\r\n\r\n            writer.Write(Key);\r\n\r\n            writer.Write(Value);\r\n        }\r\n\r\n        public override void Decode(BinaryReader reader)\r\n        {\r\n            uint type = reader.ReadUInt32();\r\n            reader.ReadUInt32();\r\n            uint lenName = reader.ReadUInt32();\r\n            uint lenVal = reader.ReadUInt32();\r\n            uint crc = reader.ReadUInt32();\r\n\r\n            byte[] key = reader.ReadBytes((int)lenName);\r\n            byte[] value = reader.ReadBytes((int)lenVal);\r\n\r\n            DataType = (CRCBlockType)type;\r\n            Key = key;\r\n            Value = value;\r\n\r\n            if (CRC() != crc)\r\n            {\r\n                throw new InvalidDataException(\"Invalid CRC in variable bag.\");\r\n            }\r\n        }\r\n\r\n        public override uint CRC()\r\n        {\r\n            return Utils.CRC32(Value);\r\n        }\r\n    }\r\n\r\n    public class CRCBlockModern : CRCBlock\r\n    {\r\n        public override void Encode(BinaryWriter writer)\r\n        {\r\n            uint crc = CRC();\r\n            writer.Write(crc);\r\n            writer.Write((uint)DataType);\r\n            writer.Write(Key.Length);\r\n            writer.Write(Value.Length);\r\n\r\n            writer.Write(Key);\r\n            writer.Align(8);\r\n\r\n            writer.Write(Value);\r\n            writer.Align(8);\r\n        }\r\n\r\n        public override void Decode(BinaryReader reader)\r\n        {\r\n            uint crc = reader.ReadUInt32();\r\n            uint type = reader.ReadUInt32();\r\n            uint lenName = reader.ReadUInt32();\r\n            uint lenVal = reader.ReadUInt32();\r\n\r\n            byte[] key = reader.ReadBytes((int)lenName);\r\n            reader.Align(8);\r\n\r\n            byte[] value = reader.ReadBytes((int)lenVal);\r\n            reader.Align(8);\r\n\r\n            DataType = (CRCBlockType)type;\r\n            Key = key;\r\n            Value = value;\r\n\r\n            if (CRC() != crc)\r\n            {\r\n                throw new InvalidDataException(\"Invalid CRC in variable bag.\");\r\n            }\r\n        }\r\n\r\n        public override uint CRC()\r\n        {\r\n            BinaryWriter wtemp = new BinaryWriter(new MemoryStream());\r\n            wtemp.Write(0);\r\n            wtemp.Write((uint)DataType);\r\n            wtemp.Write(Key.Length);\r\n            wtemp.Write(Value.Length);\r\n            wtemp.Write(Key);\r\n            wtemp.Write(Value);\r\n            return Utils.CRC32(wtemp.GetBytes());\r\n        }\r\n    }\r\n\r\n    public class VariableBag\r\n    {\r\n        public List<CRCBlock> Blocks = new List<CRCBlock>();\r\n        private readonly PSVersion Version;\r\n\r\n        private void Deserialize(byte[] data)\r\n        {\r\n            int len = data.Length;\r\n\r\n            BinaryReader reader = new BinaryReader(new MemoryStream(data));\r\n\r\n            while (reader.BaseStream.Position < len - 0x10)\r\n            {\r\n                CRCBlock block;\r\n\r\n                if (Version == PSVersion.Vista)\r\n                {\r\n                    block = new CRCBlockVista();\r\n                }\r\n                else\r\n                {\r\n                    block = new CRCBlockModern();\r\n                }\r\n\r\n                block.Decode(reader);\r\n                Blocks.Add(block);\r\n            }\r\n        }\r\n\r\n        public byte[] Serialize()\r\n        {\r\n            BinaryWriter writer = new BinaryWriter(new MemoryStream());\r\n\r\n            foreach (CRCBlock block in Blocks)\r\n            {\r\n                if (Version == PSVersion.Vista)\r\n                {\r\n                    ((CRCBlockVista)block).Encode(writer);\r\n                } else\r\n                {\r\n                    ((CRCBlockModern)block).Encode(writer);\r\n                }\r\n            }\r\n\r\n            return writer.GetBytes();\r\n        }\r\n\r\n        public CRCBlock GetBlock(string key)\r\n        {\r\n            foreach (CRCBlock block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key)\r\n                {\r\n                    return block;\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public void SetBlock(string key, byte[] value)\r\n        {\r\n            for (int i = 0; i < Blocks.Count; i++)\r\n            {\r\n                CRCBlock block = Blocks[i];\r\n\r\n                if (block.KeyAsStr == key)\r\n                {\r\n                    block.Value = value;\r\n                    Blocks[i] = block;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public void DeleteBlock(string key)\r\n        {\r\n            foreach (CRCBlock block in Blocks)\r\n            {\r\n                if (block.KeyAsStr == key)\r\n                {\r\n                    Blocks.Remove(block);\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n\r\n        public VariableBag(byte[] data, PSVersion version)\r\n        {\r\n            Version = version;\r\n            Deserialize(data);\r\n        }\r\n\r\n        public VariableBag(PSVersion version)\r\n        {\r\n            Version = version;\r\n        }\r\n    }\r\n}\r\n'@\r\n$ErrorActionPreference = 'Stop'\r\n$binPath = \"$env:_work\\BIN\\LibTSforge.dll\"\r\n$psMajorVer = (Get-Host).Version.Major\r\n$build = [System.Environment]::OSVersion.Version.Build\r\n\r\nif (Test-Path -LiteralPath $binPath) {\r\n    Write-Host \"LibTSforge.dll found in BIN folder. Loading the DLL...\"\r\n    Add-Type -Path $binPath\r\n}\r\nelse {\r\n    $cp = [CodeDom.Compiler.CompilerParameters] [string[]]@(\"System.dll\", \"System.Core.dll\", \"System.ServiceProcess.dll\", \"System.Xml.dll\", \"System.Xml.Linq.dll\")\r\n    if ($psMajorVer -le 2) { $cp.CompilerOptions = \"/define:POWERSHELL2 /unsafe\" } else { $cp.CompilerOptions = \"/unsafe\" }\r\n    $lang = if ($psMajorVer -gt 2) { \"CSharp\" } else { \"CSharpVersion3\" }\r\n\r\n    $ctemp = \"$env:SystemRoot\\Temp\\\"\r\n    if (-Not (Test-Path -Path $ctemp)) { New-Item -Path $ctemp -ItemType Directory > $null }\r\n    $env:TMP = $ctemp\r\n    $env:TEMP = $ctemp\r\n\r\n    $cp.GenerateInMemory = $true\r\n    Add-Type -Language $lang -TypeDefinition $src -CompilerParameters $cp\r\n}\r\n\r\nif ($env:_debug -eq '0') {\r\n    [LibTSforge.Logger]::HideOutput = $true\r\n}\r\n[void][LibTSforge.Utils]::Wow64EnableWow64FsRedirection($false)\r\n$ver = [LibTSforge.Utils]::DetectVersion()\r\n$prod = [LibTSforge.SPP.SPPUtils]::DetectCurrentKey()\r\n$tsactids = @($args)\r\n\r\nfunction Get-WmiInfo {\r\n    param ([string]$tsactid, [string]$property)\r\n    \r\n    $query = \"SELECT ID, $property FROM SoftwareLicensingProduct WHERE ID='$tsactid'\"\r\n    $record = Get-WmiObject -Query $query\r\n    if ($record) {\r\n        return $record.$property\r\n    }\r\n}\r\n\r\nfunction slGetSkuInfo($SkuId) {\r\n    $t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)\r\n    $t.DefinePInvokeMethod('SLOpen', 'slc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n    $t.DefinePInvokeMethod('SLClose', 'slc.dll', 22, 1, [IntPtr], @([IntPtr]), 1, 3).SetImplementationFlags(128)\r\n    $t.DefinePInvokeMethod('SLGetProductSkuInformation', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n    $w = $t.CreateType()\r\n    $hSLC = 0\r\n    try {\r\n        [void]$w::SLOpen([ref]$hSLC)\r\n        $c = 0; $b = 0\r\n        $r = $w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, \"msft:sl/EUL/PHONE/PUBLIC\", [ref]$null, [ref]$c, [ref]$b)\r\n        return ($r -eq 0)\r\n    }\r\n    finally {\r\n        [void]$w::SLClose($hSLC)\r\n    }\r\n}\r\n\r\nif (-not $env:resetstuff) {\r\n    foreach ($tsactid in $tsactids) {\r\n        try {\r\n            $activated = $null\r\n            $prodDes = Get-WmiInfo -tsactid $tsactid -property \"Description\"\r\n            $prodName = Get-WmiInfo -tsactid $tsactid -property \"Name\"\r\n            if ($prodName) {\r\n                $nameParts = $prodName -split ',', 2\r\n                $prodName = if ($nameParts.Count -gt 1) { ($nameParts[1].Trim() -split '[ ,]')[0] } else { $null }\r\n            }\r\n            if (-not $env:_vis -and -not $env:oldks) {\r\n                [LibTSforge.Modifiers.GenPKeyInstall]::InstallGenPKey($ver, $prod, $tsactid)\r\n            }\r\n            if ($prodName -match 'Office' -and $prodDes -notmatch 'KMS' -and -not (slGetSkuInfo($tsactid))) {\r\n                $licenseStatus = Get-WmiInfo -tsactid $tsactid -property \"LicenseStatus\"\r\n                if ($licenseStatus -eq 1) {\r\n                    Write-Host \"[$prodName] is already permanently activated.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                    continue\r\n                }\r\n            }\r\n            if ($env:tsmethod -eq \"StaticCID\") {\r\n                [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\r\n                $attempts = @(\r\n                    @(100055, 1000043, 1338662172562478),\r\n                    @(1345, 1003020, 6311608238084405)\r\n                )\r\n                foreach ($params in $attempts) {\r\n                    [LibTSforge.Modifiers.SetIIDParams]::SetParams($ver, $prod, $tsactid, [LibTSforge.SPP.PKeyAlgorithm]::PKEY2009, $params[0], $params[1], $params[2])\r\n                    $instId = [LibTSforge.SPP.SLApi]::GetInstallationID($tsactid)\r\n                    $confId = [ActivationWs.ActivationHelper]::CallWebService(1, $instId, \"31337-42069-123-456789-04-1337-2600.0000-2542001\")\r\n                    $result = [LibTSforge.SPP.SLApi]::DepositConfirmationID($tsactid, $instId, $confId)\r\n                    if ($result -eq 0) { break }\r\n                }\r\n                [LibTSforge.SPP.SPPUtils]::RestartSPP($ver)\r\n            }\r\n            elseif ($env:tsmethod -eq \"KMS4k\") {\r\n                [LibTSforge.Activators.KMS4k]::Activate($ver, $prod, $tsactid)\r\n            }\r\n            else {\r\n                [LibTSforge.Activators.ZeroCID]::Activate($ver, $prod, $tsactid)\r\n            }\r\n            if ($env:tsmethod -eq \"KMS4k\") {\r\n                $GracePeriodStatus = Get-WmiInfo -tsactid $tsactid -property \"GracePeriodRemaining\"\r\n                if ($GracePeriodStatus -eq 259200 -or ([datetime]::Now.AddMinutes($GracePeriodStatus)).Year -gt 2038) {\r\n                    if ((($build -ge 26100 -and $GracePeriodStatus -ge 259200) -or \r\n                            ($build -lt 26100 -and $GracePeriodStatus -gt 259200))) {\r\n                        $activated = 1\r\n                    }\r\n                }\r\n            }\r\n            else {\r\n                $licenseStatus = Get-WmiInfo -tsactid $tsactid -property \"LicenseStatus\"\r\n                if ($licenseStatus -eq 1) { $activated = 1 }\r\n            }\r\n            if ($activated) {\r\n                if ($prodDes -match 'KMS' -and $prodDes -notmatch 'CLIENT') {\r\n                    [LibTSforge.Modifiers.KMSHostCharge]::Charge($ver, $prod, $tsactid)\r\n                    Write-Host \"[$prodName] CSVLK is permanently activated with $env:tsmethod.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                    Write-Host \"[$prodName] CSVLK is charged with 25 clients for 30 days.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                }\r\n                else {\r\n                    if ($env:tsmethod -eq \"KMS4k\") {\r\n                        if ($build -ge 26100) {\r\n                            Write-Host \"[$prodName] is activated with KMS4k for over 4,000 years.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                            Write-Host \"From build 26100.7019, Windows will always display and stay at 180 days remaining if the actual period is longer.\" -ForegroundColor White -BackgroundColor Darkgray\r\n                        }\r\n                        else {\r\n                            Write-Host \"[$prodName] is activated till $([DateTime]::Now.AddMinutes($GracePeriodStatus).ToString('yyyy-MM-dd HH:mm:ss')) with $env:tsmethod.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                        }\r\n                    }\r\n                    else {\r\n                        Write-Host \"[$prodName] is permanently activated with $env:tsmethod.\" -ForegroundColor White -BackgroundColor DarkGreen\r\n                    }\r\n                }\r\n            }\r\n            else {\r\n                Write-Host \"[$prodName] activation has failed.\" -ForegroundColor White -BackgroundColor DarkRed\r\n                $errcode = 3\r\n            }\r\n        }\r\n        catch {\r\n            $errcode = 3\r\n            Write-Host \"$($_.Exception.Message)\" -ForegroundColor Red -BackgroundColor Black\r\n            Write-Host \"[$prodName] activation has failed.\" -ForegroundColor White -BackgroundColor DarkRed\r\n        }\r\n    }\r\n}\r\n\r\nif ($env:resetstuff) {\r\n    try {\r\n        if (-not $env:_vis) { [LibTSforge.Modifiers.TamperedFlagsDelete]::DeleteTamperFlags($ver, $prod) }\r\n        [LibTSforge.SPP.SLApi]::RefreshLicenseStatus()\r\n        [LibTSforge.Modifiers.RearmReset]::Reset($ver, $prod)\r\n        [LibTSforge.Modifiers.GracePeriodReset]::Reset($ver, $prod)\r\n        if (-not $env:_vis) { [LibTSforge.Modifiers.KeyChangeLockDelete]::Delete($ver, $prod) }\r\n    }\r\n    catch {\r\n        $errcode = 3\r\n        Write-Host \"$($_.Exception.Message)\" -ForegroundColor Red -BackgroundColor Black\r\n    }\r\n}\r\n\r\nExit $errcode\r\n:tsforge:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get Windows Activation ID\r\n\r\n:wintsid:\r\n$SysPath = \"$env:SystemRoot\\System32\"\r\nif (Test-Path \"$env:SystemRoot\\Sysnative\\reg.exe\") {\r\n    $SysPath = \"$env:SystemRoot\\Sysnative\"\r\n}\r\n\r\nfunction Windows-ActID {\r\n    param (\r\n        [string]$edition,\r\n        [string]$keytype\r\n    )\r\n    \r\n    $filePatterns = @(\r\n        \"$SysPath\\spp\\tokens\\skus\\$edition\\$edition*.xrm-ms\",\r\n        \"$SysPath\\spp\\tokens\\skus\\Security-SPP-Component-SKU-$edition\\*-$edition-*.xrm-ms\"\r\n    )\r\n    \r\n    switch ($keytype) {\r\n        \"zero\" {\r\n            $licenseTypes = @('OEM_DM', 'OEM_COA_SLP', 'OEM_COA_NSLP', 'MAK', 'RETAIL')\r\n        }\r\n        \"ks\" {\r\n            $licenseTypes = @('KMSCLIENT')\r\n        }\r\n        \"avma\" {\r\n            $licenseTypes = @('VIRTUAL_MACHINE')\r\n        }\r\n        \"kmshost\" {\r\n            $licenseTypes = @('KMS_')\r\n        }\r\n    }\r\n    \r\n    $softwareLicensingProducts = Get-WmiObject -Query \"SELECT ID, Description, LicenseFamily FROM SoftwareLicensingProduct WHERE ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f'\" | Where-Object { $_.LicenseFamily -eq $edition }\r\n    \r\n    $orderedLicenses = @()\r\n    foreach ($type in $licenseTypes) {\r\n        $orderedLicenses += $softwareLicensingProducts | Where-Object { $_.Description -match $type } | Select-Object -ExpandProperty ID\r\n    }\r\n    \r\n    $fileIds = @()\r\n    $muiLockedIds = @()\r\n    $kmsCountedIdCounts = @{}\r\n\r\n    $t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)\r\n\r\n    $methods = @(\r\n        @{name = 'SLOpen'; returnType = [Int32]; parameters = @([IntPtr].MakeByRefType()) },\r\n        @{name = 'SLClose'; returnType = [Int32]; parameters = @([IntPtr]) },\r\n        @{name = 'SLGetProductSkuInformation'; returnType = [Int32]; parameters = @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()) },\r\n        @{name = 'SLGetLicense'; returnType = [Int32]; parameters = @([IntPtr], [Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()) }\r\n    )\r\n    \r\n    foreach ($method in $methods) {\r\n        $t.DefinePInvokeMethod($method.name, 'slc.dll', 22, 1, $method.returnType, $method.parameters, 1, 3).SetImplementationFlags(128)\r\n    }\r\n    \r\n    $w = $t.CreateType()\r\n    $m = [Runtime.InteropServices.Marshal]\r\n\r\n    function GetLicenseInfo($SkuId, $checkType) {\r\n        $result = $false\r\n        $c = 0; $b = 0\r\n        \r\n        [void]$w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, \"fileId\", [ref]$null, [ref]$c, [ref]$b)\r\n        $FileId = $m::PtrToStringUni($b)\r\n        \r\n        $c = 0; $b = 0\r\n        [void]$w::SLGetLicense($hSLC, [ref][Guid]$FileId, [ref]$c, [ref]$b)\r\n        $blob = New-Object byte[] $c; $m::Copy($b, $blob, 0, $c)\r\n        $cont = [Text.Encoding]::UTF8.GetString($blob)\r\n        $xml = [xml]$cont.SubString($cont.IndexOf('<r'))\r\n        \r\n        if ($checkType -eq 'MUI') {\r\n            $xml.licenseGroup.license[0].grant | foreach {\r\n                $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Kernel-MUI-Language-Allowed' } | foreach {\r\n                    if ($_.InnerText -ne 'EMPTY') { $result = $true }\r\n                }\r\n            }\r\n        }\r\n        elseif ($checkType -eq 'KMS') {\r\n            $xml.licenseGroup.license[0].grant | foreach {\r\n                $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Security-SPP-KmsCountedIdList' } | foreach {\r\n                    $result = ($_.InnerText.Replace(' ', '').Replace(\"`n\", '') -split ',').Count\r\n                }\r\n            }\r\n        }\r\n        \r\n        return $result\r\n    }\r\n\r\n    $hSLC = 0; [void]$w::SLOpen([ref]$hSLC)\r\n\r\n    foreach ($id in $orderedLicenses) {\r\n        if ($keytype -eq 'kmshost') {\r\n            $kmsCount = GetLicenseInfo $id 'KMS'\r\n            if ($kmsCount -gt 0) {\r\n                $kmsCountedIdCounts[$id] = $kmsCount\r\n            }\r\n        }\r\n        if ($edition -notcontains \"CountrySpecific\" -and (GetLicenseInfo $id 'MUI')) {\r\n            $muiLockedIds += $id\r\n        }\r\n    }\r\n    \r\n    foreach ($filePattern in $filePatterns) {\r\n        $files = Get-ChildItem -Path $filePattern -Filter '*.xrm-ms' -ErrorAction SilentlyContinue\r\n        foreach ($file in $files) {\r\n            if ($null -ne $file.FullName) {\r\n                $content = Get-Content -Path $file.FullName -ErrorAction SilentlyContinue | Out-String\r\n                foreach ($id in $orderedLicenses) {\r\n                    if ($content -match \"name=`\"productSkuId`\">\\{$id\\}\" -and -not ($file.Name -match 'Beta|Test')) {\r\n                        $fileIds += $id\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n    \r\n    if ($kmsCountedIdCounts.Count -gt 0) {\r\n        $idWithMostIds = $kmsCountedIdCounts.GetEnumerator() | Sort-Object Value -Descending\r\n        $fileIds = $idWithMostIds | Select-Object -ExpandProperty Key\r\n    }\r\n    else {\r\n        if ($fileIds.Count -eq 0) {\r\n            $fileIds = $orderedLicenses\r\n        }\r\n    \r\n        $fileIds = $orderedLicenses | Where-Object { $fileIds -contains $_ -and $muiLockedIds -notcontains $_ } | Select-Object -Unique\r\n    }\r\n    \r\n    [void]$w::SLClose($hSLC)\r\n    \r\n    $pkeyconfig = \"$SysPath\\spp\\tokens\\pkeyconfig\\pkeyconfig.xrm-ms\"\r\n    if ($keytype -eq 'kmshost') {\r\n        $csvlkPath = \"$SysPath\\spp\\tokens\\pkeyconfig\\pkeyconfig-csvlk.xrm-ms\"\r\n        if (Test-Path $csvlkPath) {\r\n            $pkeyconfig = $csvlkPath\r\n        }\r\n    }\r\n    \r\n    $data = [xml][Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(([xml](get-content $pkeyconfig)).licenseGroup.license.otherInfo.infoTables.infoList.infoBin.InnerText))\r\n    \r\n    $betaIds = @()\r\n    $excludedIds = @()\r\n    $checkedIds = @()\r\n    \r\n    foreach ($id in $fileIds) {\r\n        $actConfig = $data.ProductKeyConfiguration.Configurations.Configuration | Where-Object { $_.ActConfigId -eq \"{$id}\" }\r\n        if ($actConfig) {\r\n            $productDescription = $actConfig.ProductDescription\r\n            $productEditionID = $actConfig.EditionID\r\n            if ($productDescription -match 'MUI locked|Tencent|Qihoo|WAU') {\r\n                $excludedIds += $id\r\n                continue\r\n            }\r\n    \r\n            if ($productDescription -match 'Beta|RC |Next |Test|Pre-') {\r\n                $betaIds += $id\r\n                continue\r\n            }\r\n    \r\n            if ($keytype -ne 'kmshost' -and $productEditionID -eq '$edition') {\r\n                $checkedIds += $id\r\n                continue\r\n            }\r\n    \r\n            $refGroupId = $actConfig.RefGroupId\r\n            $publicKey = $data.ProductKeyConfiguration.PublicKeys.PublicKey | Where-Object { $_.GroupId -eq $refGroupId -and $_.AlgorithmId -eq 'msft:rm/algorithm/pkey/2009' }\r\n            if ($publicKey) {\r\n                $keyRanges = $data.ProductKeyConfiguration.KeyRanges.KeyRange | Where-Object { $_.RefActConfigId -eq \"{$id}\" }\r\n                foreach ($keyRange in $keyRanges) {\r\n                    if ($keyRange.EulaType -match 'WAU') {\r\n                        $excludedIds += $id\r\n                        break\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n    \r\n    $prefinalIds = @()\r\n    $finalIds = @()\r\n    \r\n    $prefinalIds = $fileIds | Where-Object { $excludedIds -notcontains $_ } | Select-Object -Unique\r\n    $finalIds = $prefinalIds | Where-Object { $betaIds -notcontains $_ } | Select-Object -Unique\r\n    \r\n    if ($finalIds.Count -eq 0) {\r\n        $finalIds = $prefinalIds\r\n    }\r\n    \r\n    if ($checkedIds.Count -gt 0) {\r\n        $finalIds = $checkedIds + $finalIds\r\n    }\r\n    \r\n    $firstId = $finalIds | Select-Object -First 1\r\n    return $firstId.ToLower()\r\n}\r\n\r\nWindows-ActID -edition \"$env:tsedition\" -keytype \"$env:keytype\"\r\n:wintsid:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get Office Activation ID\r\n\r\n:offtsid:\r\nfunction Office-ActID {\r\n    param (\r\n        [string]$pkeypath,\r\n        [string]$edition,\r\n        [string]$keytype\r\n    )\r\n\r\n    switch ($keytype) {\r\n        \"zero\" { $productKeyTypes = @(\"OEM:NONSLP\",\"Volume:MAK\",\"Retail\") }\r\n        \"ks\" { $productKeyTypes = @(\"Volume:GVLK\") }\r\n    }\r\n\r\n    $data = [xml][Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(([xml](Get-Content $pkeypath)).licenseGroup.license.otherInfo.infoTables.infoList.infoBin.InnerText))\r\n    $configurations = $data.ProductKeyConfiguration.Configurations.Configuration\r\n\r\n    $filteredConfigs = @()\r\n    foreach ($type in $productKeyTypes) {\r\n        $filteredConfigs += $configurations | Where-Object { \r\n            $_.EditionId -eq $edition -and \r\n            $_.ProductKeyType -eq $type -and \r\n            $_.ProductDescription -notmatch 'demo|MSDN|PIN'\r\n        }\r\n    }\r\n\r\n    $filterPreview = $filteredConfigs | Where-Object { $_.ProductDescription -notmatch 'preview|c2r' }\r\n\r\n    if ($filterPreview.Count -ne 0) {\r\n        $filteredConfigs = $filterPreview\r\n    } \r\n\r\n    $firstConfig = ($filteredConfigs | Select-Object -First 1).ActConfigID -replace '^\\{|\\}$', ''\r\n    return $firstConfig.ToLower()\r\n}\r\n\r\nOffice-ActID -pkeypath \"$env:pkeypath\" -edition \"$env:_License\" -keytype \"$env:keytype\"\r\n:offtsid:\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Office version number\r\n::  2nd column = Activation ID\r\n::  3rd column = Product ID from branding.xml\r\n::  4th column = Edition\r\n::  5th column = Other Edition IDs if they are part of the same primary product (For reference only)\r\n::  Separator  = \"_\"\r\n\r\n:msiofficedata\r\n\r\nfor %%# in (\r\n14_4d463c2c-0505-4626-8cdb-a4da82e2d8ed_0015_AccessR\r\n14_745fb377-0a59-4ca9-b9a9-c359557a2c4e_001C_AccessRuntimeR\r\n14_95ab3ec8-4106-4f9d-b632-03c019d1d23f_0015_AccessVL\r\n14_4eaff0d0-c6cb-4187-94f3-c7656d49a0aa_0016_ExcelR_[HSExcelR]\r\n14_71dc86ff-f056-40d0-8ffb-9592705c9b76_0016_ExcelVL\r\n14_7004b7f0-6407-4f45-8eac-966e5f868bde_00BA_GrooveR\r\n14_fdad0dfa-417d-4b4f-93e4-64ea8867b7fd_00BA_GrooveVL\r\n14_7b7d1f17-fdcb-4820-9789-9bec6e377821_0013_HomeBusinessR_[HomeBusinessDemoR]\r\n14_19316117-30a8-4773-8fd9-7f7231f4e060_011E_HomeBusinessSubR\r\n14_09e2d37e-474b-4121-8626-58ad9be5776f_002F_HomeStudentR_[HomeStudentDemoR]\r\n14_ef1da464-01c8-43a6-91af-e4e5713744f9_0044_InfoPathR\r\n14_85e22450-b741-430c-a172-a37962c938af_0044_InfoPathVL\r\n14_14f5946a-debc-4716-babc-7e2c240fec08_000F_MondoR\r\n14_533b656a-4425-480b-8e30-1a2358898350_000F_MondoVL\r\n14_c1ceda8b-c578-4d5d-a4aa-23626be4e234_003D_ProfessionalR_[OEM-SingleImage]Exception\r\n14_3f7aa693-9a7e-44fc-9309-bb3d8e604925_00A1_OneNoteR_[HSOneNoteR]\r\n14_6860b31f-6a67-48b8-84b9-e312b3485c4b_00A1_OneNoteVL\r\n14_fbf4ac36-31c8-4340-8666-79873129cf40_001A_OutlookR\r\n14_a9aeabd8-63b8-4079-a28e-f531807fd6b8_001A_OutlookVL\r\n14_acb51361-c0db-4895-9497-1831c41f31a6_0033_PersonalR_[PersonalDemoR,PersonalPrepaidR]\r\n14_133c8359-4e93-4241-8118-30bb18737ea0_0018_PowerPointR_[HSPowerPointR]\r\n14_38252940-718c-4aa6-81a4-135398e53851_0018_PowerPointVL\r\n14_8b559c37-0117-413e-921b-b853aeb6e210_0014_ProfessionalR_[ProfessionalAcadR,ProfessionalDemoR]\r\n14_725714d7-d58f-4d12-9fa8-35873c6f7215_003B_ProjectProR_[ProjectProMSDNR]\r\n14_4d06f72e-fd50-4bc2-a24b-d448d7f17ef2_011F_ProjectProSubR\r\n14_1cf57a59-c532-4e56-9a7d-ffa2fe94b474_003B_ProjectProVL\r\n14_688f6589-2bd9-424e-a152-b13f36aa6de1_003A_ProjectStdR\r\n14_11b39439-6b93-4642-9570-f2eb81be2238_003A_ProjectStdVL\r\n14_71af7e84-93e6-4363-9b69-699e04e74071_0011_ProPlusR_[ProPlusAcadR,ProPlusMSDNR,Sub4R]\r\n14_e98ef0c0-71c4-42ce-8305-287d8721e26c_011D_ProPlusSubR\r\n14_fdf3ecb9-b56f-43b2-a9b8-1b48b6bae1a7_0011_ProPlusVL_[ProPlusAcadVL]\r\n14_98677603-a668-4fa4-9980-3f1f05f78f69_0019_PublisherR\r\n14_3d014759-b128-4466-9018-e80f6320d9d0_0019_PublisherVL\r\n14_dbe3aee0-5183-4ff7-8142-66050173cb01_008B_SmallBusBasicsR_[SmallBusBasicsMSDNR]\r\n14_8090771e-d41a-4482-929e-de87f1f47e46_008B_SmallBusBasicsVL\r\n14_b78df69e-0966-40b1-ae85-30a5134dedd0_0017_SPDR\r\n14_d3422cfb-8d8b-4ead-99f9-eab0ccd990d7_0012_StandardR\r\n14_1f76e346-e0be-49bc-9954-70ec53a4fcfe_0012_StandardVL_[StandardAcadVL]\r\n14_2745e581-565a-4670-ae90-6bf7c57ffe43_0066_StarterR\r\n14_66cad568-c2dc-459d-93ec-2f3cb967ee34_0057_VisioSIR_Prem[Pro,Std]Exception\r\n14_36756cb8-8e69-4d11-9522-68899507cd6a_0057_VisioSIVL_Prem[Pro,Std]Exception\r\n14_db3bbc9c-ce52-41d1-a46f-1a1d68059119_001B_WordR_[HSWordR]\r\n14_98d4050e-9c98-49bf-9be1-85e12eb3ab13_001B_WordVL\r\n:: Office 2013\r\n15_ab4d047b-97cf-4126-a69f-34df08e2f254_0015_AccessRetail\r\n15_259de5be-492b-44b3-9d78-9645f848f7b0_001C_AccessRuntimeRetail\r\n15_4374022d-56b8-48c1-9bb7-d8f2fc726343_0015_AccessVolume\r\n15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_0016_ExcelRetail\r\n15_ac1ae7fd-b949-4e04-a330-849bc40638cf_0016_ExcelVolume\r\n15_cfaf5356-49e3-48a8-ab3c-e729ab791250_00BA_GrooveRetail\r\n15_4825ac28-ce41-45a7-9e6e-1fed74057601_00BA_GrooveVolume\r\n15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_00E7_HomeBusinessPipcRetail\r\n15_cd256150-a898-441f-aac0-9f8f33390e45_0013_HomeBusinessRetail\r\n15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_00CE_HomeStudentARMRetail\r\n15_ebef9f05-5273-404a-9253-c5e252f50555_00DA_HomeStudentPlusARMRetail\r\n15_98685d21-78bd-4c62-bc4f-653344a63035_002F_HomeStudentRetail\r\n15_44984381-406e-4a35-b1c3-e54f499556e2_0044_InfoPathRetail\r\n15_9e016989-4007-42a6-8051-64eb97110cf2_0044_InfoPathVolume\r\n15_9103f3ce-1084-447a-827e-d6097f68c895_00EA_LyncAcademicRetail\r\n15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_012D_LyncEntryRetail\r\n15_fada6658-bfc6-4c4e-825a-59a89822cda8_012C_LyncRetail\r\n15_e1264e10-afaf-4439-a98b-256df8bb156f_012C_LyncVolume\r\n15_3169c8df-f659-4f95-9cc6-3115e6596e83_000F_MondoRetail\r\n15_f33485a0-310b-4b72-9a0e-b1d605510dbd_000F_MondoVolume\r\n15_3391e125-f6e4-4b1e-899c-a25e6092d40d_00A1_OneNoteFreeRetail\r\n15_8b524bcc-67ea-4876-a509-45e46f6347e8_00A1_OneNoteRetail\r\n15_b067e965-7521-455b-b9f7-c740204578a2_00A1_OneNoteVolume\r\n15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_001A_OutlookRetail\r\n15_8d577c50-ae5e-47fd-a240-24986f73d503_001A_OutlookVolume\r\n15_5aab8561-1686-43f7-9ff5-2c861da58d17_00E6_PersonalPipcRetail\r\n15_17e9df2d-ed91-4382-904b-4fed6a12caf0_0033_PersonalRetail\r\n15_31743b82-bfbc-44b6-aa12-85d42e644d5b_0018_PowerPointRetail\r\n15_e40dcb44-1d5c-4085-8e8f-943f33c4f004_0018_PowerPointVolume\r\n15_4e26cac1-e15a-4467-9069-cb47b67fe191_00E8_ProfessionalPipcRetail\r\n15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_0014_ProfessionalRetail\r\n15_f2435de4-5fc0-4e5b-ac97-34f515ec5ee7_003B_ProjectProRetail\r\n15_ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32_003B_ProjectProVolume\r\n15_5517e6a2-739b-4822-946f-7f0f1c5934b1_003A_ProjectStdRetail\r\n15_2b9e4a37-6230-4b42-bee2-e25ce86c8c7a_003A_ProjectStdVolume\r\n15_064383fa-1538-491c-859b-0ecab169a0ab_0011_ProPlusRetail\r\n15_2b88c4f2-ea8f-43cd-805e-4d41346e18a7_0011_ProPlusVolume\r\n15_c3a0814a-70a4-471f-af37-2313a6331111_0019_PublisherRetail\r\n15_38ea49f6-ad1d-43f1-9888-99a35d7c9409_0019_PublisherVolume\r\n15_ba3e3833-6a7e-445a-89d0-7802a9a68588_0017_SPDRetail\r\n15_32255c0a-16b4-4ce2-b388-8a4267e219eb_0012_StandardRetail\r\n15_a24cca51-3d54-4c41-8a76-4031f5338cb2_0012_StandardVolume\r\n15_15d12ad4-622d-4257-976c-5eb3282fb93d_0051_VisioProRetail\r\n15_3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d_0051_VisioProVolume\r\n15_dae597ce-5823-4c77-9580-7268b93a4b23_0053_VisioStdRetail\r\n15_44a1f6ff-0876-4edb-9169-dbb43101ee89_0053_VisioStdVolume\r\n15_191509f2-6977-456f-ab30-cf0492b1e93a_001B_WordRetail\r\n15_9cedef15-be37-4ff0-a08a-13a045540641_001B_WordVolume\r\n:: Office 365 - 15.0 version\r\n15_befee371-a2f5-4648-85db-a2c55fdf324c_00E9_O365BusinessRetail\r\n15_537ea5b5-7d50-4876-bd38-a53a77caca32_00D6_O365HomePremRetail\r\n15_149dbce7-a48e-44db-8364-a53386cd4580_00D4_O365ProPlusRetail\r\n15_bacd4614-5bef-4a5e-bafc-de4c788037a2_00D5_O365SmallBusPremRetail\r\n:: Office 365 - 16.0 version\r\n16_6337137e-7c07-4197-8986-bece6a76fc33_00E9_O365BusinessRetail\r\n16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_00D6_O365EduCloudRetail\r\n16_537ea5b5-7d50-4876-bd38-a53a77caca32_00D6_O365HomePremRetail\r\n16_149dbce7-a48e-44db-8364-a53386cd4580_00D4_O365ProPlusRetail\r\n16_bacd4614-5bef-4a5e-bafc-de4c788037a2_00D5_O365SmallBusPremRetail\r\n:: Office 2016\r\n16_bfa358b0-98f1-4125-842e-585fa13032e6_0015_AccessRetail\r\n16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_001C_AccessRuntimeRetail\r\n16_3b2fa33f-cd5a-43a5-bd95-f49f3f546b0b_0015_AccessVolume\r\n16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_0016_ExcelRetail\r\n16_685062a7-6024-42e7-8c5f-6bb9e63e697f_0016_ExcelVolume\r\n16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_00E7_HomeBusinessPipcRetail\r\n16_86834d00-7896-4a38-8fae-32f20b86fa2b_0013_HomeBusinessRetail\r\n16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_00CE_HomeStudentARMRetail\r\n16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_00DA_HomeStudentPlusARMRetail\r\n16_c28acdb8-d8b3-4199-baa4-024d09e97c99_002F_HomeStudentRetail\r\n16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_002F_HomeStudentVNextRetail\r\n16_b21367df-9545-4f02-9f24-240691da0e58_000F_MondoRetail\r\n16_2cd0ea7e-749f-4288-a05e-567c573b2a6c_000F_MondoVolume\r\n16_436366de-5579-4f24-96db-3893e4400030_00A3_OneNoteFreeRetail\r\n16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_00A1_OneNoteRetail\r\n16_23b672da-a456-4860-a8f3-e062a501d7e8_00A1_OneNoteVolume\r\n16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_001A_OutlookRetail\r\n16_50059979-ac6f-4458-9e79-710bcb41721a_001A_OutlookVolume\r\n16_5aab8561-1686-43f7-9ff5-2c861da58d17_00E6_PersonalPipcRetail\r\n16_a9f645a1-0d6a-4978-926a-abcb363b72a6_0033_PersonalRetail\r\n16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_0018_PowerPointRetail\r\n16_9b4060c9-a7f5-4a66-b732-faf248b7240f_0018_PowerPointVolume\r\n16_4e26cac1-e15a-4467-9069-cb47b67fe191_00E8_ProfessionalPipcRetail\r\n16_d64edc00-7453-4301-8428-197343fafb16_0014_ProfessionalRetail\r\n16_0f42f316-00b1-48c5-ada4-2f52b5720ad0_003B_ProjectProRetail\r\n16_82f502b5-b0b0-4349-bd2c-c560df85b248_003B_ProjectProVolume\r\n16_16728639-a9ab-4994-b6d8-f81051e69833_003B_ProjectProXVolume\r\n16_e9f0b3fc-962f-4944-ad06-05c10b6bcd5e_003A_ProjectStdRetail\r\n16_82e6b314-2a62-4e51-9220-61358dd230e6_003A_ProjectStdVolume\r\n16_431058f0-c059-44c5-b9e7-ed2dd46b6789_003A_ProjectStdXVolume\r\n16_de52bd50-9564-4adc-8fcb-a345c17f84f9_0011_ProPlusRetail\r\n16_c47456e3-265d-47b6-8ca0-c30abbd0ca36_0011_ProPlusVolume\r\n16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_0019_PublisherRetail\r\n16_fcc1757b-5d5f-486a-87cf-c4d6dedb6032_0019_PublisherVolume\r\n16_971cd368-f2e1-49c1-aedd-330909ce18b6_012D_SkypeforBusinessEntryRetail\r\n16_418d2b9f-b491-4d7f-84f1-49e27cc66597_012C_SkypeforBusinessRetail\r\n16_03ca3b9a-0869-4749-8988-3cbc9d9f51bb_012C_SkypeforBusinessVolume\r\n16_9103f3ce-1084-447a-827e-d6097f68c895_012C_SkypeServiceBypassRetail\r\n16_4a31c291-3a12-4c64-b8ab-cd79212be45e_0012_StandardRetail\r\n16_0ed94aac-2234-4309-ba29-74bdbb887083_0012_StandardVolume\r\n16_2dfe2075-2d04-4e43-816a-eb60bbb77574_0051_VisioProRetail\r\n16_295b2c03-4b1c-4221-b292-1411f468bd02_0051_VisioProVolume\r\n16_0594dc12-8444-4912-936a-747ca742dbdb_0051_VisioProXVolume\r\n16_c76dbcbc-d71b-4f45-b5b3-b7494cb4e23e_0053_VisioStdRetail\r\n16_44151c2d-c398-471f-946f-7660542e3369_0053_VisioStdVolume\r\n16_1d1c6879-39a3-47a5-9a6d-aceefa6a289d_0053_VisioStdXVolume\r\n16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_001B_WordRetail\r\n16_c3000759-551f-4f4a-bcac-a4b42cbf1de2_001B_WordVolume\r\n) do (\r\nfor /f \"tokens=1-5 delims=_\" %%A in (\"%%#\") do (\r\n\r\nif \"%oVer%\"==\"%%A\" (\r\nreg query \"%1\\Registration\\{%%B}\" /v ProductCode %nul2% | find /i \"-%%C-\" %nul% && (\r\nreg query \"%1\\Common\\InstalledPackages\" %nul2% | find /i \"-%%C-\" %nul% && (\r\nif defined _oIds (set _oIds=!_oIds! %%D) else (set _oIds=%%D)\r\nif /i 003D==%%C set SingleImage=1\r\n)\r\n)\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Office version\r\n::  2nd column = Volume or free retail product\r\n::  3rd column = Retail product names that needs to be converted to the Volume product mentioned in 2nd column\r\n::  Separator  = \"_\"\r\n\r\n:tsksdata\r\n\r\nset f=\r\nfor %%# in (\r\n:: Office 2013\r\n15_AccessVolume_-AccessRetail-\r\n15_AccessRuntimeRetail\r\n15_ExcelVolume_-ExcelRetail-\r\n15_GrooveVolume_-GrooveRetail-\r\n15_InfoPathVolume_-InfoPathRetail-\r\n15_LyncAcademicRetail\r\n15_LyncEntryRetail\r\n15_LyncVolume_-LyncRetail-\r\n15_MondoRetail\r\n15_MondoVolume_-O365BusinessRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-\r\n15_OneNoteFreeRetail\r\n15_OneNoteVolume_-OneNoteRetail-\r\n15_OutlookVolume_-OutlookRetail-\r\n15_PowerPointVolume_-PowerPointRetail-\r\n15_ProjectProVolume_-ProjectProRetail-\r\n15_ProjectStdVolume_-ProjectStdRetail-\r\n15_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-\r\n15_PublisherVolume_-PublisherRetail-\r\n15_SPDRetail\r\n15_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-PersonalPipcRetail-PersonalRetail-\r\n15_VisioProVolume_-VisioProRetail-\r\n15_VisioStdVolume_-VisioStdRetail-\r\n15_WordVolume_-WordRetail-\r\n:: Office 2016\r\n16_AccessRuntimeRetail\r\n16_AccessVolume_-AccessRetail-\r\n16_ExcelVolume_-ExcelRetail-\r\n16_MondoRetail\r\n16_MondoVolume_-O365AppsBasicRetail-O365BusinessRetail-O365EduCloudRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-\r\n16_OneNoteFreeRetail\r\n16_OneNoteVolume_-OneNoteRetail-OneNote2021Retail-\r\n16_OutlookVolume_-OutlookRetail-\r\n16_PowerPointVolume_-PowerPointRetail-\r\n16_ProjectProVolume_-ProjectProRetail-\r\n16_ProjectProXVolume\r\n16_ProjectStdVolume_-ProjectStdRetail-\r\n16_ProjectStdXVolume\r\n16_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-\r\n16_PublisherVolume_-PublisherRetail-\r\n16_SkypeServiceBypassRetail\r\n16_SkypeforBusinessEntryRetail\r\n16_SkypeforBusinessVolume_-SkypeforBusinessRetail-\r\n16_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-HomeStudentVNextRetail-PersonalPipcRetail-PersonalRetail-\r\n16_VisioProVolume_-VisioProRetail-\r\n16_VisioProXVolume\r\n16_VisioStdVolume_-VisioStdRetail-\r\n16_VisioStdXVolume\r\n16_WordVolume_-WordRetail-\r\n:: Office 2019\r\n16_AccessRuntime2019Retail\r\n16_Access2019Volume_-Access2019Retail-\r\n16_Excel2019Volume_-Excel2019Retail-\r\n16_Outlook2019Volume_-Outlook2019Retail-\r\n16_PowerPoint2019Volume_-PowerPoint2019Retail-\r\n16_ProjectPro2019Volume_-ProjectPro2019Retail-\r\n16_ProjectStd2019Volume_-ProjectStd2019Retail-\r\n16_ProPlus2019Volume_-ProPlus2019Retail-Professional2019Retail-\r\n16_Publisher2019Volume_-Publisher2019Retail-\r\n16_SkypeforBusiness2019Volume_-SkypeforBusiness2019Retail-\r\n16_SkypeforBusinessEntry2019Retail\r\n16_Standard2019Volume_-Standard2019Retail-HomeBusiness2019Retail-HomeStudentARM2019Retail-HomeStudentPlusARM2019Retail-HomeStudent2019Retail-Personal2019Retail-\r\n16_VisioPro2019Volume_-VisioPro2019Retail-\r\n16_VisioStd2019Volume_-VisioStd2019Retail-\r\n16_Word2019Volume_-Word2019Retail-\r\n:: Office 2021\r\n:: OneNote2021Volume KMS license is not available\r\n16_AccessRuntime2021Retail\r\n16_Access2021Volume_-Access2021Retail-\r\n16_Excel2021Volume_-Excel2021Retail-\r\n16_Outlook2021Volume_-Outlook2021Retail-\r\n16_OneNoteFree2021Retail\r\n16_PowerPoint2021Volume_-PowerPoint2021Retail-\r\n16_ProjectPro2021Volume_-ProjectPro2021Retail-\r\n16_ProjectStd2021Volume_-ProjectStd2021Retail-\r\n16_ProPlus2021Volume_-ProPlus2021Retail-Professional2021Retail-\r\n16_Publisher2021Volume_-Publisher2021Retail-\r\n16_SkypeforBusiness2021Volume_-SkypeforBusiness2021Retail-\r\n16_Standard2021Volume_-Standard2021Retail-HomeBusiness2021Retail-HomeStudent2021Retail-Personal2021Retail-\r\n16_VisioPro2021Volume_-VisioPro2021Retail-\r\n16_VisioStd2021Volume_-VisioStd2021Retail-\r\n16_Word2021Volume_-Word2021Retail-\r\n:: Office 2024\r\n16_Access2024Volume_-Access2024Retail-\r\n16_Excel2024Volume_-Excel2024Retail-\r\n16_Outlook2024Volume_-Outlook2024Retail-\r\n16_PowerPoint2024Volume_-PowerPoint2024Retail-\r\n16_ProjectPro2024Volume_-ProjectPro2024Retail-\r\n16_ProjectStd2024Volume_-ProjectStd2024Retail-\r\n16_ProPlus2024Volume_-ProPlus2024Retail-\r\n16_SkypeforBusiness2024Volume\r\n16_Standard2024Volume_-Home2024Retail-HomeBusiness2024Retail-\r\n16_VisioPro2024Volume_-VisioPro2024Retail-\r\n16_VisioStd2024Volume_-VisioStd2024Retail-\r\n16_Word2024Volume_-Word2024Retail-\r\n) do (\r\nfor /f \"tokens=1-3 delims=_\" %%A in (\"%%#\") do (\r\n\r\nif %1==chkprod if \"%oVer%\"==\"%%A\" if not defined foundprod (\r\nif /i \"%%B\"==\"%2\" set foundprod=1\r\n)\r\n\r\nif %1==getinfo if \"%oVer%\"==\"%%A\" (\r\necho: %%C | find /i \"-%2-\" %nul% && (\r\nset _License=%%B\r\nset _altoffid=%%B\r\n)\r\n)\r\n\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ts_getedition\r\n\r\nset tsedition=\r\nset _wtarget=\r\n\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do if not errorlevel 1 call set \"_wtarget= !_wtarget! %%a \"\r\n\r\n::  SKU and Edition ID database\r\n\r\nfor %%# in (\r\n1:Ultimate\r\n2:HomeBasic\r\n3:HomePremium\r\n4:Enterprise\r\n5:HomeBasicN\r\n6:Business\r\n7:ServerStandard\r\n8:ServerDatacenter\r\n9:ServerSBSStandard\r\n10:ServerEnterprise\r\n11:Starter\r\n12:ServerDatacenterCore\r\n13:ServerStandardCore\r\n14:ServerEnterpriseCore\r\n15:ServerEnterpriseIA64\r\n16:BusinessN\r\n17:ServerWeb\r\n18:ServerHPC\r\n19:ServerHomeStandard\r\n20:ServerStorageExpress\r\n21:ServerStorageStandard\r\n22:ServerStorageWorkgroup\r\n23:ServerStorageEnterprise\r\n24:ServerWinSB\r\n25:ServerSBSPremium\r\n26:HomePremiumN\r\n27:EnterpriseN\r\n28:UltimateN\r\n29:ServerWebCore\r\n30:ServerMediumBusinessManagement\r\n31:ServerMediumBusinessSecurity\r\n32:ServerMediumBusinessMessaging\r\n33:ServerWinFoundation\r\n34:ServerHomePremium\r\n35:ServerWinSBV\r\n36:ServerStandardV\r\n37:ServerDatacenterV\r\n38:ServerEnterpriseV\r\n39:ServerDatacenterVCore\r\n40:ServerStandardVCore\r\n41:ServerEnterpriseVCore\r\n42:ServerHyperCore\r\n43:ServerStorageExpressCore\r\n44:ServerStorageStandardCore\r\n45:ServerStorageWorkgroupCore\r\n46:ServerStorageEnterpriseCore\r\n47:StarterN\r\n48:Professional\r\n49:ProfessionalN\r\n50:ServerSolution\r\n51:ServerForSBSolutions\r\n52:ServerSolutionsPremium\r\n53:ServerSolutionsPremiumCore\r\n54:ServerSolutionEM\r\n55:ServerForSBSolutionsEM\r\n56:ServerEmbeddedSolution\r\n57:ServerEmbeddedSolutionCore\r\n58:ProfessionalEmbedded\r\n59:ServerEssentialManagement\r\n60:ServerEssentialAdditional\r\n61:ServerEssentialManagementSvc\r\n62:ServerEssentialAdditionalSvc\r\n63:ServerSBSPremiumCore\r\n64:ServerHPCV\r\n65:Embedded\r\n66:StarterE\r\n67:HomeBasicE\r\n68:HomePremiumE\r\n69:ProfessionalE\r\n70:EnterpriseE\r\n71:UltimateE\r\n72:EnterpriseEval\r\n74:Prerelease\r\n76:ServerMultiPointStandard\r\n77:ServerMultiPointPremium\r\n79:ServerStandardEval\r\n80:ServerDatacenterEval\r\n81:PrereleaseARM\r\n82:PrereleaseN\r\n84:EnterpriseNEval\r\n85:EmbeddedAutomotive\r\n86:EmbeddedIndustryA\r\n87:ThinPC\r\n88:EmbeddedA\r\n89:EmbeddedIndustry\r\n90:EmbeddedE\r\n91:EmbeddedIndustryE\r\n92:EmbeddedIndustryAE\r\n93:ProfessionalPlus\r\n95:ServerStorageWorkgroupEval\r\n96:ServerStorageStandardEval\r\n97:CoreARM\r\n98:CoreN\r\n99:CoreCountrySpecific\r\n100:CoreSingleLanguage\r\n101:Core\r\n103:ProfessionalWMC\r\n104:MobileCore\r\n105:EmbeddedIndustryEval\r\n106:EmbeddedIndustryEEval\r\n107:EmbeddedEval\r\n108:EmbeddedEEval\r\n109:CoreSystemServer\r\n110:ServerCloudStorage\r\n111:CoreConnected\r\n112:ProfessionalStudent\r\n113:CoreConnectedN\r\n114:ProfessionalStudentN\r\n115:CoreConnectedSingleLanguage\r\n116:CoreConnectedCountrySpecific\r\n117:ConnectedCar\r\n118:IndustryHandheld\r\n119:PPIPRO\r\n120:ServerARM64\r\n121:Education\r\n122:EducationN\r\n123:IoTUAP\r\n124:ServerHI\r\n125:EnterpriseS\r\n126:EnterpriseSN\r\n127:ProfessionalS\r\n128:ProfessionalSN\r\n129:EnterpriseSEval\r\n130:EnterpriseSNEval\r\n131:IoTUAPCommercial\r\n133:MobileEnterprise\r\n134:AnalogOneCoreEnterprise\r\n135:AnalogOneCore\r\n136:Holographic\r\n138:ProfessionalSingleLanguage\r\n139:ProfessionalCountrySpecific\r\n140:EnterpriseSubscription\r\n141:EnterpriseSubscriptionN\r\n143:ServerDatacenterNano\r\n144:ServerStandardNano\r\n145:ServerDatacenterACor\r\n146:ServerStandardACor\r\n147:ServerDatacenterCor\r\n148:ServerStandardCor\r\n149:UtilityVM\r\n159:ServerDatacenterEvalCor\r\n160:ServerStandardEvalCor\r\n161:ProfessionalWorkstation\r\n162:ProfessionalWorkstationN\r\n163:ServerAzure\r\n164:ProfessionalEducation\r\n165:ProfessionalEducationN\r\n168:ServerAzureCor\r\n169:ServerAzureNano\r\n171:EnterpriseG\r\n172:EnterpriseGN\r\n173:BusinessSubscription\r\n174:BusinessSubscriptionN\r\n175:ServerRdsh\r\n178:Cloud\r\n179:CloudN\r\n180:HubOS\r\n182:OneCoreUpdateOS\r\n183:CloudE\r\n184:Andromeda\r\n185:IoTOS\r\n186:CloudEN\r\n187:IoTEdgeOS\r\n188:IoTEnterprise\r\n189:ModernPC\r\n191:IoTEnterpriseS\r\n192:SystemOS\r\n193:NativeOS\r\n194:GameCoreXbox\r\n195:GameOS\r\n196:DurangoHostOS\r\n197:ScarlettHostOS\r\n198:Keystone\r\n199:CloudHost\r\n200:CloudMOS\r\n201:CloudCore\r\n202:CloudEditionN\r\n203:CloudEdition\r\n204:WinVOS\r\n205:IoTEnterpriseSK\r\n206:IoTEnterpriseK\r\n207:IoTEnterpriseSEval\r\n208:AgentBridge\r\n209:NanoHost\r\n210:WNC\r\n406:ServerAzureStackHCICor\r\n407:ServerTurbine\r\n408:ServerTurbineCor\r\n\r\nREM Some old edition names with same SKU ID\r\n\r\n4:ProEnterprise\r\n6:ProStandard\r\n10:ProSBS\r\n16:ProStandardN\r\n18:ServerComputeCluster\r\n19:ServerHome\r\n30:ServerMidmarketStandard\r\n31:ServerMidmarketEdge\r\n32:ServerMidmarketPremium\r\n33:ServerSBSPrime\r\n42:ServerHyper\r\n64:ServerComputeClusterV\r\n85:EmbeddedIapetus\r\n86:EmbeddedTethys\r\n88:EmbeddedDione\r\n89:EmbeddedRhea\r\n90:EmbeddedEnceladus\r\n109:ServerNano\r\n124:ServerCloudHostInfrastructure\r\n133:MobileBusiness\r\n134:HololensEnterprise\r\n145:ServerDatacenterSCor\r\n146:ServerStandardSCor\r\n147:ServerDatacenterWSCor\r\n148:ServerStandardWSCor\r\n189:Lite\r\n) do (\r\nfor /f \"tokens=1-2 delims=:\" %%A in (\"%%#\") do if \"%osSKU%\"==\"%%A\" if not defined tsedition (\r\necho \"%_wtarget%\" | find /i \" %%B \" %nul% && set tsedition=%%B\r\n)\r\n)\r\n\r\nif defined tsedition exit /b\r\n\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionNameFromId', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [IntPtr].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionNameFromId(%osSKU%, [ref]$out);$s=[Runtime.InteropServices.Marshal]::PtrToStringUni($out); $s\r\n\r\nfor %%# in (pkeyhelper.dll) do @if not \"%%~$PATH:#\"==\"\" (\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (\r\necho \"%_wtarget%\" | find /i \" %%a \" %nul% && set tsedition=%%a\r\n)\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n:: Leave empty line below\r\n"
  },
  {
    "path": "MAS/Separate-Files-Version/Activators/_ReadMe.txt",
    "content": "--------------------------------------------------------------------------------------\r\nActivation Type        Supported Product        Activation Period\r\n--------------------------------------------------------------------------------------\r\n\r\nHWID                -  Windows 10-11          -  Permanent                           \r\nOhook               -  Office                 -  Permanent                           \r\nTSforge             -  Windows / ESU / Office -  Permanent                           \r\nOnline KMS          -  Windows / Office       -  180 Days. Lifetime With Renewal Task\r\n\r\n--------------------------------------------------------------------------------------\r\n\r\nCheck the below link for more details:\r\nhttps://massgrave.dev/chart"
  },
  {
    "path": "MAS/Separate-Files-Version/Change_Office_Edition.cmd",
    "content": "@set masver=3.10\r\n@echo off\r\n\r\n\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\nset re1=\r\nset re2=\r\nset \"_cmdf=%~f0\"\r\nfor %%# in (%*) do (\r\nif /i \"%%#\"==\"re1\" set re1=1\r\nif /i \"%%#\"==\"re2\" set re2=1\r\nif /i \"%%#\"==\"-qedit\" (set re1=1&set re2=1)\r\n)\r\n\r\n:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows\r\n:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\Sysnative\\cmd.exe if not defined re1 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\Sysnative\\cmd.exe /c \"\"!_cmdf!\" %* re1\"\r\nexit /b\r\n)\r\n\r\n:: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\SysArm32\\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\SysArm32\\cmd.exe /c \"\"!_cmdf!\" %* re2\"\r\nexit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset \"blank=\"\r\nset \"mas=ht%blank%tps%blank%://m%blank%ass%blank%grave.dev/\"\r\nset \"github=ht%blank%tps%blank%://github.com/m%blank%assgra%blank%vel/Micro%blank%soft-Acti%blank%vation-Scripts\"\r\nset \"selfgit=ht%blank%tps%blank%://git.acti%blank%vated.win/Micr%blank%osoft-Act%blank%ivation-Scripts\"\r\n\r\n::  Check if Null service is working, it's important for the batch script\r\n\r\nsc query Null | find /i \"RUNNING\"\r\nif %errorlevel% NEQ 0 (\r\necho:\r\necho Null service is not running, script may crash...\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%fix_service\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20\r\n)\r\ncls\r\n\r\n::  Check LF line ending\r\n\r\npushd \"%~dp0\"\r\n>nul findstr /v \"$\" \"%~nx0\" && (\r\necho:\r\necho Error - Script either has LF line ending issue or an empty line at the end of the script is missing.\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20 >nul\r\npopd\r\nexit /b\r\n)\r\npopd\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\ntitle  Change Office Edition %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args set _args=%_args:re1=%\r\nif defined _args set _args=%_args:re2=%\r\nif defined _args (\r\nfor %%A in (%_args%) do (\r\nif /i \"%%A\"==\"-el\"                    set _elev=1\r\n)\r\n)\r\n\r\nset \"nul1=1>nul\"\r\nset \"nul2=2>nul\"\r\nset \"nul6=2^>nul\"\r\nset \"nul=>nul 2>&1\"\r\n\r\ncall :dk_setvar\r\nset \"line=echo ___________________________________________________________________________________________\"\r\n\r\n::========================================================================================================================================\r\n\r\nif %winbuild% EQU 1 (\r\n%eline%\r\necho Failed to detect Windows build number.\r\necho:\r\nsetlocal EnableDelayedExpansion\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\nif exist \"%Systemdrive%\\Users\\WDAGUtilityAccount\" (\r\nsc query gcs | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Windows Sandbox detected.\r\necho The script cannot run due to missing licensing components. Aborting...\r\necho:\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 7600 (\r\n%eline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho This option is supported only for Windows 7/8/8.1/10/11 and their Server equivalents.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix special character limitations in path name\r\n\r\nset \"_work=%~dp0\"\r\nif \"%_work:~-1%\"==\"\\\" set \"_work=%_work:~0,-1%\"\r\n\r\nset \"_batf=%~f0\"\r\nset \"_batp=%_batf:'=''%\"\r\n\r\nset _PSarg=\"\"\"%~f0\"\"\" -el %_args%\r\nset _PSarg=%_PSarg:'=''%\r\n\r\nset \"_ttemp=%userprofile%\\AppData\\Local\\Temp\"\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\necho \"!_batf!\" | find /i \"!_ttemp!\" %nul1% && (\r\nif /i not \"!_work!\"==\"!_ttemp!\" (\r\n%eline%\r\necho The script was launched from the temp folder.\r\necho You are most likely running the script directly from the archive file.\r\necho:\r\necho Extract the archive file and launch the script from the extracted folder.\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Elevate script as admin and pass arguments and preventing loop\r\n\r\n%nul1% fltmc || (\r\nif not defined _elev %psc% \"start cmd.exe -arg '/c \\\"!_PSarg!\\\"' -verb runas\" && exit /b\r\n%eline%\r\necho This script needs admin rights.\r\necho Right click on this script and select 'Run as administrator'.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check PowerShell\r\n\r\n::pstst $ExecutionContext.SessionState.LanguageMode :pstst\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"if ($PSVersionTable.PSEdition -ne 'Core') {$f=[System.IO.File]::ReadAllText('!_batp!') -split ':pstst';. ([scriptblock]::Create($f[1]))}\" %nul6%') do (set tstresult=%%a)\r\n\r\nif /i not \"%tstresult%\"==\"FullLanguage\" (\r\n%eline%\r\nfor /f \"delims=\" %%a in ('%psc% \"$ExecutionContext.SessionState.LanguageMode\" %nul6%') do (set tstresult2=%%a)\r\necho Test 1 - %tstresult%\r\necho Test 2 - !tstresult2!\r\necho:\r\n\r\nREM check LanguageMode\r\n\r\necho: !tstresult2! | findstr /i \"ConstrainedLanguage RestrictedLanguage NoLanguage\" %nul1% && (\r\necho FullLanguage mode not found in PowerShell. Aborting...\r\necho If you have applied restrictions on Powershell then undo those changes.\r\nset fixes=%fixes% %mas%fix_powershell\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_powershell\"\r\ngoto dk_done\r\n)\r\n\r\nREM check Powershell core version\r\n\r\ncmd /c \"%psc% \"$PSVersionTable.PSEdition\"\" | find /i \"Core\" %nul1% && (\r\necho Windows Powershell is needed for MAS but it seems to be replaced with Powershell core. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n\r\nREM check for Mal-ware that may cause issues with Powershell\r\n\r\nfor /r \"%ProgramFiles%\\\" %%f in (secureboot.exe) do if exist \"%%f\" (\r\necho \"%%f\"\r\necho Mal%blank%ware found, PowerShell is not working properly.\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\ngoto dk_done\r\n)\r\n\r\nREM check if .NET is working properly\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\ncmd /c \"%psc% \"\"try {[System.AppDomain]::CurrentDomain.GetAssemblies(); [System.Math]::Sqrt(144)} catch {Exit 3}\"\"\" %nul%\r\nif !errorlevel!==3 (\r\necho Windows Powershell failed to load .NET command. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nREM check antivirus and other errors\r\n\r\necho PowerShell is not working properly. Aborting...\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\necho:\r\necho Your antivirus software might be blocking the script.\r\necho:\r\nsc query sense | find /i \"RUNNING\" %nul% && (\r\necho Installed Antivirus - Microsoft Defender for Endpoint\r\n)\r\ncmd /c \"%psc% \"\"$av = Get-WmiObject -Namespace root\\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { $n += $i.displayName }; if ($n) { Write-Host ('Installed Antivirus - ' + ($n -join ', '))}\"\"\"\r\n)\r\n\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Disable QuickEdit and launch from conhost.exe to avoid Terminal app\r\n\r\nif %winbuild% GEQ 17763 (\r\nset terminal=1\r\n) else (\r\nset terminal=\r\n)\r\n\r\n::  Check if script is running in Terminal app\r\n\r\nif defined terminal (\r\nset lines=0\r\nfor /f \"skip=3 tokens=* delims=\" %%A in ('mode con') do if \"!lines!\"==\"0\" (\r\nfor %%B in (%%A) do set lines=%%B\r\n)\r\nif !lines! GEQ 100 set terminal=\r\n)\r\n\r\nif %_unattended%==1 goto :skipQE\r\nfor %%# in (%_args%) do (if /i \"%%#\"==\"-qedit\" goto :skipQE)\r\n\r\n::  Relaunch to disable QuickEdit in the current session and use conhost.exe instead of the Terminal app\r\n::  This code disables QuickEdit for the current cmd.exe session without making permanent registry changes\r\n::  It is included because clicking on the script window can pause execution, causing confusion that the script has stopped due to an error\r\n\r\nset resetQE=1\r\nreg query HKCU\\Console /v QuickEdit %nul2% | find /i \"0x0\" %nul1% && set resetQE=0\r\nreg add HKCU\\Console /v QuickEdit /t REG_DWORD /d 0 /f %nul1%\r\n\r\nif defined terminal (\r\nstart conhost.exe \"!_batf!\" %_args% -qedit\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n) else if %resetQE% EQU 1 (\r\nstart cmd.exe /c \"\"!_batf!\" %_args% -qedit\"\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n)\r\n\r\n:skipQE\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check for updates\r\n\r\nset -=\r\nset old=\r\nset pingp=\r\nset upver=%masver:.=%\r\n\r\nfor %%A in (\r\nactiv%-%ated.win\r\nmass%-%grave.dev\r\n) do if not defined pingp (\r\nfor /f \"delims=[] tokens=2\" %%B in ('ping -n 1 %%A') do (\r\nif not \"%%B\"==\"\" (set old=1& set pingp=1)\r\nfor /f \"delims=[] tokens=2\" %%C in ('ping -n 1 updatecheck%upver%.%%A') do (\r\nif not \"%%C\"==\"\" set old=\r\n)\r\n)\r\n)\r\n\r\nif defined old (\r\necho ________________________________________________\r\n%eline%\r\necho Your version of MAS [%masver%] is outdated.\r\necho ________________________________________________\r\necho:\r\nif not %_unattended%==1 (\r\necho [1] Get Latest MAS\r\necho [0] Continue Anyway\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 rem\r\nif !errorlevel!==1 (start %selfgit% & start %github% & start %mas% & exit /b)\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\nif not defined terminal mode 98, 30\r\ntitle  Change Office Edition %masver%\r\n\r\necho:\r\necho Initializing...\r\necho:\r\n\r\n::========================================================================================================================================\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_reflection\r\ncall :dk_ckeckwmic\r\ncall :dk_sppissue\r\n\r\nfor /f \"tokens=6-7 delims=[]. \" %%i in ('ver') do if not \"%%j\"==\"\" (\r\nset fullbuild=%%i.%%j\r\n) else (\r\nfor /f \"tokens=3\" %%G in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR\" %nul6%') do if not errorlevel 1 set /a \"UBR=%%G\"\r\nfor /f \"skip=2 tokens=3,4 delims=. \" %%G in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildLabEx') do (\r\nif defined UBR (set \"fullbuild=%%G.!UBR!\") else (set \"fullbuild=%%G.%%H\")\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Windows Edition\r\n::  This is just to ensure that SPP/WMI are functional\r\n\r\ncls\r\nset osedition=0\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do if not errorlevel 1 (call set \"osedition=%%a\")\r\n\r\nif %osedition%==0 (\r\n%eline%\r\necho Failed to detect OS Edition. Aborting...\r\ncall :dk_color %Blue% \"To fix this issue, activate Windows from the main menu.\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check installed Office 16.0 C2R\r\n\r\nset o16c2r=\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" (set o16c2r=1&set o16c2r_reg=%_86%\\ClickToRun)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\" (set o16c2r=1&set o16c2r_reg=%_68%\\ClickToRun)\r\n\r\nif not defined o16c2r_reg (\r\n%eline%\r\necho Office C2R 2016 or later is not installed, which is required for this script.\r\necho Download and install Office from below URL and try again.\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto dk_done\r\n)\r\n\r\ncall :ch_getinfo\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check minimum required details\r\n\r\nif %verchk% LSS 9029 (\r\n%eline%\r\necho Installed Office version is %_version%.\r\necho Minimum required version is 16.0.9029.2167\r\necho Aborting...\r\ncall :dk_color %Blue% \"Download and install latest Office from below URL and try again.\"\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto dk_done\r\n)\r\n\r\nfor %%A in (\r\n_oArch\r\n_updch\r\n_lang\r\n_clversion\r\n_version\r\n_AudienceData\r\n_oIds\r\n_c2rXml\r\n_c2rExe\r\n_c2rCexe\r\n_masterxml\r\n) do (\r\nif not defined %%A (\r\n%eline%\r\necho Failed to find %%A. Aborting...\r\ncall :dk_color %Blue% \"Download and install Office from below URL and try again.\"\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 10240 if defined ltscfound (\r\n%eline%\r\necho Installed Office appears to be from the Volume channel %ltsc19%%ltsc21%%ltsc24%,\r\necho which is not officially supported on your Windows build version %winbuild%.\r\necho Aborting...\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\nset unsupbuild=\r\nif %winbuild% LSS 10240 if %winbuild% GEQ 9200 if %verchk% GTR 16026 set unsupbuild=1\r\nif %winbuild% LSS 9200 if %verchk% GTR 12527 set unsupbuild=1\r\n\r\nif defined unsupbuild (\r\n%eline%\r\necho Unsupported Office %verchk% is installed on your Windows build version %winbuild%.\r\necho Aborting...\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:oemenu\r\n\r\ncls\r\nset fixes=\r\nif not defined terminal mode 76, 25\r\ntitle  Change Office Edition %masver%\r\necho:\r\necho:\r\necho:\r\necho:\r\necho         ____________________________________________________________\r\necho:\r\necho                 [1] Change all editions\r\necho                 [2] Add edition\r\necho                 [3] Remove edition\r\necho:\r\necho                 [4] Add/Remove apps\r\necho                 ____________________________________________\r\necho:\r\necho                 [5] Change Office Update Channel\r\necho                 [0] %_exitmsg%\r\necho         ____________________________________________________________\r\necho: \r\ncall :dk_color2 %_White% \"           \" %_Green% \"Choose a menu option using your keyboard [1,2,3,4,5,0]\"\r\nchoice /C:123450 /N\r\nset _el=!errorlevel!\r\nif !_el!==6  exit /b\r\nif !_el!==5  goto :oe_changeupdchnl\r\nif !_el!==4  goto :oe_editedition\r\nif !_el!==3  goto :oe_removeedition\r\nif !_el!==2  set change=0& goto :oe_edition\r\nif !_el!==1  set change=1& goto :oe_edition\r\ngoto :oemenu\r\n\r\n::========================================================================================================================================\r\n\r\n:oe_edition\r\n\r\ncls\r\ncall :oe_chkinternet\r\nif not defined _int (\r\ngoto :oe_goback\r\n)\r\n\r\ncls\r\nif not defined terminal mode 76, 25\r\nif %change%==1 (\r\ntitle  Change all editions %masver%\r\n) else (\r\ntitle  Add edition %masver%\r\n)\r\n\r\necho:\r\necho:\r\necho:\r\necho:\r\necho                 O365/Mondo editions have the latest features.     \r\necho         ____________________________________________________________\r\necho:\r\necho                 [1] Office Suites     - Retail\r\necho                 [2] Office Suites     - Volume\r\necho                 [3] Office SingleApps - Retail\r\necho                 [4] Office SingleApps - Volume\r\necho                 ____________________________________________\r\necho:\r\necho                 [0] Go Back\r\necho         ____________________________________________________________\r\necho: \r\ncall :dk_color2 %_White% \"            \" %_Green% \"Choose a menu option using your keyboard [1,2,3,4,0]\"\r\nchoice /C:12340 /N\r\nset _el=!errorlevel!\r\nif !_el!==5  goto :oemenu\r\nif !_el!==4  set list=SingleApps_Volume&goto :oe_editionchangepre\r\nif !_el!==3  set list=SingleApps_Retail&goto :oe_editionchangepre\r\nif !_el!==2  set list=Suites_Volume&goto :oe_editionchangepre\r\nif !_el!==1  set list=Suites_Retail&goto :oe_editionchangepre\r\ngoto :oe_edition\r\n\r\n::========================================================================================================================================\r\n\r\n:oe_editionchangepre\r\n\r\ncls\r\nset editedition=\r\ncall :ch_getinfo\r\ncall :oe_tempcleanup\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getlist\\:.*';. ([scriptblock]::Create($f[1]))\"\r\n\r\n:oe_editionchange\r\n\r\ncls\r\nif not defined terminal (\r\nmode 98, 45\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=44;$B.Height=100;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\n\r\nif not exist %SystemRoot%\\Temp\\%list%.txt (\r\n%eline%\r\necho Failed to generate available editions list.\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto :oe_goback\r\n)\r\n\r\nset inpt=\r\nset counter=0\r\nset verified=0\r\nset _notfound=\r\nset targetedition=\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"Installed Office editions: %_oIds%\"\r\ncall :dk_color %Gray% \"You can select one of the following Office Editions.\"\r\nif %winbuild% LSS 10240 (\r\necho Unsupported products such as 2019/2021/2024 are excluded from this list.\r\n) else (\r\nfor %%# in (2019 2021 2024) do (\r\nfind /i \"%%#\" \"%SystemRoot%\\Temp\\%list%.txt\" %nul1% || (\r\nif defined _notfound (set _notfound=%%#, !_notfound!) else (set _notfound=%%#)\r\n)\r\n)\r\nif defined _notfound call :dk_color %Gray% \"Office !_notfound! is not in this list because old version [%_version%] of Office is installed.\"\r\n)\r\n%line%\r\necho:\r\n\r\nfor /f \"usebackq delims=\" %%A in (%SystemRoot%\\Temp\\%list%.txt) do (\r\nset /a counter+=1\r\nif !counter! LSS 10 (\r\necho [!counter!]  %%A\r\n) else (\r\necho [!counter!] %%A\r\n)\r\nset targetedition!counter!=%%A\r\n)\r\n\r\n%line%\r\necho:\r\necho [0]  Go Back\r\necho:\r\ncall :dk_color %_Green% \"Enter an option number using your keyboard and press Enter to confirm:\"\r\nset /p inpt=\r\nif \"%inpt%\"==\"\" goto :oe_editionchange\r\nif \"%inpt%\"==\"0\" (call :oe_tempcleanup & goto :oe_edition)\r\nfor /l %%i in (1,1,%counter%) do (if \"%inpt%\"==\"%%i\" set verified=1)\r\nset targetedition=!targetedition%inpt%!\r\nif %verified%==0 goto :oe_editionchange\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set app exclusions\r\n\r\n:oe_excludeappspre\r\n\r\ncls\r\nset suites=\r\necho %list% | find /i \"Suites\" %nul1% && (\r\nset suites=1\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getappnames\\:.*';. ([scriptblock]::Create($f[1]))\"\r\nif not exist %SystemRoot%\\Temp\\getAppIds.txt (\r\n%eline%\r\necho Failed to generate available apps list.\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto :oe_goback\r\n)\r\n)\r\n\r\nfor %%# in (\r\nAccess\r\nExcel\r\nLync\r\nOneNote\r\nOutlook\r\nPowerPoint\r\nProject\r\nPublisher\r\nVisio\r\nWord\r\n) do (\r\nif defined suites (\r\nfind /i \"%%#\" \"%SystemRoot%\\Temp\\getAppIds.txt\" %nul1% && (set %%#_st=On) || (set %%#_st=)\r\n) else (\r\nset %%#_st=\r\n)\r\n)\r\n\r\nif defined Lync_st set Lync_st=Off\r\nset OneDrive_st=Off\r\nif defined suites (set Teams_st=Off) else (set Teams_st=)\r\n\r\n:oe_excludeapps\r\n\r\ncls\r\nif not defined terminal mode 98, 32\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"Target edition: %targetedition%\"\r\ncall :dk_color %Gray% \"To exclude the apps listed below from installation, toggle them from On to Off.\"\r\nif defined editedition call :dk_color %Gray% \"Note: The On/Off status below does not reflect the current status of the installed apps.\"\r\n%line%\r\nif defined suites echo:\r\nif defined Access_st     echo [A] Access           : %Access_st%\r\nif defined Excel_st      echo [E] Excel            : %Excel_st%\r\nif defined OneNote_st    echo [N] OneNote          : %OneNote_st%\r\nif defined Outlook_st    echo [O] Outlook          : %Outlook_st%\r\nif defined PowerPoint_st echo [P] PowerPoint       : %PowerPoint_st%\r\nif defined Project_st    echo [J] Project          : %Project_st%\r\nif defined Publisher_st  echo [R] Publisher        : %Publisher_st%\r\nif defined Visio_st      echo [V] Visio            : %Visio_st%\r\nif defined Word_st       echo [W] Word             : %Word_st%\r\necho:\r\nif defined Lync_st       echo [L] SkypeForBusiness : %Lync_st%\r\nif defined OneDrive_st   echo [D] OneDrive         : %OneDrive_st%\r\nif defined Teams_st      echo [T] Teams            : %Teams_st%\r\n%line%\r\necho:\r\necho [1] Continue\r\necho [0] Go Back\r\n%line%\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard:\"\r\nchoice /C:AENOPJRVWLDT10 /N\r\nset _el=!errorlevel!\r\nif !_el!==14 goto :oemenu\r\nif !_el!==13 call :excludelist & goto :oe_editionchangefinal\r\nif !_el!==12 if defined Teams_st      (if \"%Teams_st%\"==\"Off\"      (set Teams_st=ON)      else (set Teams_st=Off))\r\nif !_el!==11 if defined OneDrive_st   (if \"%OneDrive_st%\"==\"Off\"   (set OneDrive_st=ON)   else (set OneDrive_st=Off))\r\nif !_el!==10 if defined Lync_st       (if \"%Lync_st%\"==\"Off\"       (set Lync_st=ON)       else (set Lync_st=Off))\r\nif !_el!==9  if defined Word_st       (if \"%Word_st%\"==\"Off\"       (set Word_st=ON)       else (set Word_st=Off))\r\nif !_el!==8  if defined Visio_st      (if \"%Visio_st%\"==\"Off\"      (set Visio_st=ON)      else (set Visio_st=Off))\r\nif !_el!==7  if defined Publisher_st  (if \"%Publisher_st%\"==\"Off\"  (set Publisher_st=ON)  else (set Publisher_st=Off))\r\nif !_el!==6  if defined Project_st    (if \"%Project_st%\"==\"Off\"    (set Project_st=ON)    else (set Project_st=Off))\r\nif !_el!==5  if defined PowerPoint_st (if \"%PowerPoint_st%\"==\"Off\" (set PowerPoint_st=ON) else (set PowerPoint_st=Off))\r\nif !_el!==4  if defined Outlook_st    (if \"%Outlook_st%\"==\"Off\"    (set Outlook_st=ON)    else (set Outlook_st=Off))\r\nif !_el!==3  if defined OneNote_st    (if \"%OneNote_st%\"==\"Off\"    (set OneNote_st=ON)    else (set OneNote_st=Off))\r\nif !_el!==2  if defined Excel_st      (if \"%Excel_st%\"==\"Off\"      (set Excel_st=ON)      else (set Excel_st=Off))\r\nif !_el!==1  if defined Access_st     (if \"%Access_st%\"==\"Off\"     (set Access_st=ON)     else (set Access_st=Off))\r\ngoto :oe_excludeapps\r\n\r\n:excludelist\r\n\r\nset excludelist=\r\nfor %%# in (\r\naccess\r\nexcel\r\nonenote\r\noutlook\r\npowerpoint\r\nproject\r\npublisher\r\nvisio\r\nword\r\nlync\r\nonedrive\r\nteams\r\n) do (\r\nif /i \"!%%#_st!\"==\"Off\" if defined excludelist (set excludelist=!excludelist!,%%#) else (set excludelist=,%%#)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Final command to change/add edition\r\n\r\n:oe_editionchangefinal\r\n\r\ncls\r\nif not defined terminal mode 105, 32\r\n\r\n::  Check for Project and Visio with unsupported language\r\n\r\nset projvis=\r\nset langmatched=\r\necho: %Project_st% %Visio_st% | find /i \"ON\" %nul% && set projvis=1\r\necho: %targetedition% | findstr /i \"Project Visio\" %nul% && set projvis=1\r\n\r\nif defined projvis (\r\nfor %%# in (\r\nar-sa\r\ncs-cz\r\nda-dk\r\nde-de\r\nel-gr\r\nen-us\r\nes-es\r\nfi-fi\r\nfr-fr\r\nhe-il\r\nhu-hu\r\nit-it\r\nja-jp\r\nko-kr\r\nnb-no\r\nnl-nl\r\npl-pl\r\npt-br\r\npt-pt\r\nro-ro\r\nru-ru\r\nsk-sk\r\nsl-si\r\nsv-se\r\ntr-tr\r\nuk-ua\r\nzh-cn\r\nzh-tw\r\n) do (\r\nif /i \"%_lang%\"==\"%%#\" set langmatched=1\r\n)\r\nif not defined langmatched (\r\n%eline%\r\necho %_lang% language is not available for Project/Visio apps.\r\ncall :dk_color %Blue% \"Install Office in the supported language for Project/Visio from the below URL.\"\r\nset fixes=%fixes% %mas%genuine-installation-media\r\ncall :dk_color %_Yellow% \"%mas%genuine-installation-media\"\r\ngoto :oe_goback\r\n)\r\n)\r\n\r\n::  Thanks to @abbodi1406 for first discovering OfficeClickToRun.exe uses\r\n::  Thanks to @may for the suggestion to use it to change edition with CDN as a source\r\n::  OfficeClickToRun.exe with productstoadd method is used here to add editions\r\n::  It uses delta updates, meaning that since it's using same installed build, it will consume very less Internet\r\n\r\ncall :oe_getlangs\r\n\r\nset \"c2rcommand=\"%_c2rExe%\" platform=%_oArch% culture=%_lang% productstoadd=%targetedition%.16_%_allLangs% cdnbaseurl.16=http://officecdn.microsoft.com/pr/%_updch% baseurl.16=http://officecdn.microsoft.com/pr/%_updch% version.16=%_version% mediatype.16=CDN sourcetype.16=CDN deliverymechanism=%_updch% %targetedition%.excludedapps.16=groove%excludelist% flt.useteamsaddon=disabled flt.usebingaddononinstall=disabled flt.usebingaddononupdate=disabled\"\r\n\r\nif %change%==1 (\r\nset \"c2rcommand=!c2rcommand! productstoremove=AllProducts\"\r\n)\r\n\r\necho:\r\necho Running the below command, please wait...\r\necho:\r\necho %c2rcommand%\r\n%c2rcommand%\r\nset errorcode=%errorlevel%\r\ntimeout /t 10 %nul%\r\n\r\necho:\r\nset suggestchannel=\r\n\r\nif %errorcode% EQU 0 (\r\nif %change%==1 (\r\necho %targetedition% | find /i \"2019Volume\" %nul% && (\r\nif not defined ltsc19 set suggestchannel=Production::LTSC\r\nif /i not %_AudienceData%==Production::LTSC set suggestchannel=Production::LTSC\r\nif /i not %_updch%==F2E724C1-748F-4B47-8FB8-8E0D210E9208 set suggestchannel=Production::LTSC\r\n)\r\n\r\necho %targetedition% | find /i \"2021Volume\" %nul% && (\r\nif not defined ltsc21 set suggestchannel=Production::LTSC2021\r\nif /i not %_AudienceData%==Production::LTSC2021 set suggestchannel=Production::LTSC2021\r\nif /i not %_updch%==5030841D-C919-4594-8D2D-84AE4F96E58E set suggestchannel=Production::LTSC2021\r\n)\r\n\r\necho %targetedition% | find /i \"2024Volume\" %nul% && (\r\nif not defined ltsc24 set suggestchannel=Production::LTSC2024\r\nif /i not %_AudienceData%==Production::LTSC2024 set suggestchannel=Production::LTSC2024\r\nif /i not %_updch%==7983BAC0-E531-40CF-BE00-FD24FE66619C set suggestchannel=Production::LTSC2024\r\n)\r\n\r\necho %targetedition% | findstr /R \"20.*Volume\" %nul% || (\r\nif defined ltscfound set suggestchannel=Production::CC\r\necho %_AudienceData% | find /i \"LTSC\" %nul% && set suggestchannel=Production::CC\r\n)\r\n\r\nif defined suggestchannel (\r\ncall :dk_color %Gray% \"Mismatch found in update channel and installed product.\"\r\ncall :dk_color %Blue% \"It is recommended to change the update channel to [!suggestchannel!] from the previous menu.\"\r\n)\r\necho:\r\n)\r\ncall :dk_color %Gray% \"To activate Office, run the activation option from the main menu.\"\r\n) else (\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\ncall :oe_tempcleanup\r\ngoto :oe_goback\r\n\r\n::========================================================================================================================================\r\n\r\n::  Edit Office edition\r\n\r\n:oe_editedition\r\n\r\ncls\r\ntitle  Add/Remove Apps %masver%\r\n\r\ncall :oe_chkinternet\r\nif not defined _int (\r\ngoto :oe_goback\r\n)\r\n\r\nset change=0\r\nset editedition=1\r\ncall :ch_getinfo\r\ncls\r\n\r\nif not defined terminal (\r\nmode 98, 35\r\n)\r\n\r\nset inpt=\r\nset counter=0\r\nset verified=0\r\nset targetedition=\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"You can edit [add/remove apps] one of the following Office editions.\"\r\n%line%\r\necho:\r\n\r\nfor %%A in (%_oIds%) do (\r\nset /a counter+=1\r\necho [!counter!] %%A\r\nset targetedition!counter!=%%A\r\n)\r\n\r\n%line%\r\necho:\r\necho [0]  Go Back\r\necho:\r\ncall :dk_color %_Green% \"Enter an option number using your keyboard and press Enter to confirm:\"\r\nset /p inpt=\r\nif \"%inpt%\"==\"\" goto :oe_editedition\r\nif \"%inpt%\"==\"0\" goto :oemenu\r\nfor /l %%i in (1,1,%counter%) do (if \"%inpt%\"==\"%%i\" set verified=1)\r\nset targetedition=!targetedition%inpt%!\r\nif %verified%==0 goto :oe_editedition\r\n\r\n::===============\r\n\r\ncls\r\nif not defined terminal mode 98, 32\r\n\r\necho %targetedition% | findstr /i \"Access Excel OneNote Outlook PowerPoint Project Publisher Skype Visio Word\" %nul% && (set list=SingleApps) || (set list=Suites)\r\ngoto :oe_excludeappspre\r\n\r\n::========================================================================================================================================\r\n\r\n::  Remove Office editions\r\n\r\n:oe_removeedition\r\n\r\ntitle  Remove Office editions %masver%\r\n\r\ncall :ch_getinfo\r\n\r\ncls\r\nif not defined terminal (\r\nmode 98, 35\r\n)\r\n\r\nset counter=0\r\nfor %%A in (%_oIds%) do (set /a counter+=1)\r\n\r\nif !counter! LEQ 1 (\r\necho:\r\necho Only \"%_oIds%\" product is installed.\r\necho This option is available only when multiple products are installed.\r\ngoto :oe_goback\r\n)\r\n\r\n::===============\r\n\r\nset inpt=\r\nset counter=0\r\nset verified=0\r\nset targetedition=\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"You can uninstall one of the following Office editions.\"\r\n%line%\r\necho:\r\n\r\nfor %%A in (%_oIds%) do (\r\nset /a counter+=1\r\necho [!counter!] %%A\r\nset targetedition!counter!=%%A\r\n)\r\n\r\n%line%\r\necho:\r\necho [0]  Go Back\r\necho:\r\ncall :dk_color %_Green% \"Enter an option number using your keyboard and press Enter to confirm:\"\r\nset /p inpt=\r\nif \"%inpt%\"==\"\" goto :oe_removeedition\r\nif \"%inpt%\"==\"0\" goto :oemenu\r\nfor /l %%i in (1,1,%counter%) do (if \"%inpt%\"==\"%%i\" set verified=1)\r\nset targetedition=!targetedition%inpt%!\r\nif %verified%==0 goto :oe_removeedition\r\n\r\n::===============\r\n\r\ncls\r\nif not defined terminal mode 105, 32\r\n\r\ncall :oe_getlangs %targetedition%\r\nset \"c2rcommand=\"%_c2rExe%\" platform=%_oArch% productstoremove=%targetedition%.16_%_allLangs%\"\r\n\r\necho:\r\necho Running the below command, please wait...\r\necho:\r\necho %c2rcommand%\r\n%c2rcommand%\r\n\r\nif %errorlevel% NEQ 0 (\r\necho:\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\ngoto :oe_goback\r\n\r\n::========================================================================================================================================\r\n\r\n::  Change Office update channel\r\n\r\n:oe_changeupdchnl\r\n\r\ntitle  Change Office update channel %masver%\r\ncall :ch_getinfo\r\n\r\ncls\r\nif not defined terminal (\r\nmode 98, 33\r\n)\r\n\r\ncall :oe_chkinternet\r\nif not defined _int (\r\ngoto :oe_goback\r\n)\r\n\r\nif %winbuild% LSS 10240 (\r\necho %_oIds% | findstr \"2019 2021 2024\" %nul% && (\r\n%eline%\r\necho Installed Office editions: %_oIds%\r\necho Unsupported Office edition is installed on your Windows build version %winbuild%.\r\ngoto :oe_goback\r\n)\r\nif defined ltscfound (\r\n%eline%\r\necho Installed Office update channel: %ltsc19%%ltsc21%%ltsc24%\r\necho Unsupported Office update channel is installed on your Windows build version %winbuild%.\r\ngoto :oe_goback\r\n)\r\n)\r\n\r\n::===============\r\n\r\nset inpt=\r\nset counter=0\r\nset verified=0\r\nset targetFFN=\r\nset bypassFFN=\r\nset targetchannel=\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"Installed update channel: %_AudienceData%, %_version%, Client: %_clversion%\"\r\ncall :dk_color %Gray% \"Installed Office editions: %_oIds%\"\r\n%line%\r\necho:\r\n\r\nfor %%# in (\r\n\"5440fd1f-7ecb-4221-8110-145efaa6372f_Beta    / Insider Fast    -   Insiders::DevMain  -\"\r\n\"64256afe-f5d9-4f86-8936-8840a6a4f5be_Current / Monthly Preview -   Insiders::CC       -\"\r\n\"492350f6-3a01-4f97-b9c0-c7c6ddf67d60_Current / Monthly         - Production::CC       -\"\r\n\"55336b82-a18d-4dd6-b5f6-9e5095c314a6_Monthly Enterprise        - Production::MEC      -\"\r\n\"7ffbc6bf-bc32-4f92-8982-f9dd17fd3114_Semi Annual Enterprise    - Production::DC       -\"\r\n\"ea4a4090-de26-49d7-93c1-91bff9e53fc3_DevMain Channel           -    Dogfood::DevMain  -\"\r\n\"b61285dd-d9f7-41f2-9757-8f61cba4e9c8_Microsoft Elite           -  Microsoft::DevMain  -\"\r\n\"f2e724c1-748f-4b47-8fb8-8e0d210e9208_Perpetual2019 VL          - Production::LTSC     -\"\r\n\"1d2d2ea6-1680-4c56-ac58-a441c8c24ff9_Microsoft2019 VL          -  Microsoft::LTSC     -\"\r\n\"5030841d-c919-4594-8d2d-84ae4f96e58e_Perpetual2021 VL          - Production::LTSC2021 -\"\r\n\"86752282-5841-4120-ac80-db03ae6b5fdb_Microsoft2021 VL          -  Microsoft::LTSC2021 -\"\r\n\"7983bac0-e531-40cf-be00-fd24fe66619c_Perpetual2024 VL          - Production::LTSC2024 -\"\r\n\"c02d8fe6-5242-4da8-972f-82ee55e00671_Microsoft2024 VL          -  Microsoft::LTSC2024 -\"\r\n) do (\r\nfor /f \"tokens=1-2 delims=_\" %%A in (\"%%~#\") do (\r\nset bypass=\r\nset supported=\r\nif %winbuild% LSS 10240 (echo %%B | findstr /i \"LTSC DevMain\" %nul% || set supported=1) else (set supported=1)\r\nif %winbuild% GEQ 10240 (\r\nif defined ltsc19 echo %%B | find /i \"2019 VL\" %nul% || set bypass=1\r\nif defined ltsc21 echo %%B | find /i \"2021 VL\" %nul% || set bypass=1\r\nif defined ltsc24 echo %%B | find /i \"2024 VL\" %nul% || set bypass=1\r\nif not defined ltscfound echo %%B | find /i \"LTSC\" %nul% && set bypass=1\r\n)\r\nif defined supported (\r\nset /a counter+=1\r\nif !counter! LSS 10 (\r\nif defined bypass (echo [!counter!]  %%B  Unofficial change method will be used) else (echo [!counter!]  %%B)\r\n) else (\r\nif defined bypass (echo [!counter!] %%B  Unofficial change method will be used) else (echo [!counter!] %%B)\r\n)\r\nset targetFFN!counter!=%%A\r\nset targetchannel!counter!=%%B\r\nif defined bypass set bypassFFN=!bypassFFN!%%A\r\n)\r\n)\r\n)\r\n\r\n%line%\r\necho:\r\necho [R]  Learn about update channels\r\necho [0]  Go back\r\necho:\r\ncall :dk_color %_Green% \"Enter an option number using your keyboard and press Enter to confirm:\"\r\nset /p inpt=\r\nif \"%inpt%\"==\"\" goto :oe_changeupdchnl\r\nif \"%inpt%\"==\"0\" goto :oemenu\r\nif /i \"%inpt%\"==\"R\" start https://learn.microsoft.com/en-us/microsoft-365-apps/updates/overview-update-channels & goto :oe_changeupdchnl\r\nfor /l %%i in (1,1,%counter%) do (if \"%inpt%\"==\"%%i\" set verified=1)\r\nset targetFFN=!targetFFN%inpt%!\r\nset targetchannel=!targetchannel%inpt%!\r\nif %verified%==0 goto :oe_changeupdchnl\r\n\r\n::=======================\r\n\r\ncls\r\nif not defined terminal mode 105, 32\r\n\r\n::  Get build number for the target FFN, using build number with OfficeC2RClient.exe command to trigger updates provides accurate results\r\n\r\nset build=\r\nfor /f \"delims=\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getbuild\\:.*';. ([scriptblock]::Create($f[1]))\" %nul6%') do (set build=%%a)\r\necho \"%build%\" | find /i \"16.\" %nul% || set build=\r\n\r\necho:\r\nfor /f \"tokens=1 delims=-\" %%A in (\"%targetchannel%\") do (echo Target update channel: %%A)\r\necho Target build number: %build%\r\necho: %bypassFFN% | find /i \"%targetFFN%\" %nul% && goto :oe_changeunoff\r\n\r\ncall :oe_cleanupreg\r\n\r\nif not defined build (\r\nif %winbuild% GEQ 9200 call :dk_color %Gray% \"Failed to detect build number for the target FFN.\"\r\nset \"updcommand=\"%_c2rCexe%\" /update user\"\r\n) else (\r\nset \"updcommand=\"%_c2rCexe%\" /update user updatetoversion=%build%\"\r\n)\r\necho Running the below command to trigger updates...\r\necho:\r\necho %updcommand%\r\n%updcommand%\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\ngoto :oe_goback\r\n\r\n::=======================\r\n\r\n::  Unofficial method to change channel\r\n\r\n:oe_changeunoff\r\n\r\nset abortchange=\r\necho %targetchannel% | find /i \"2019 VL\" %nul% && (for %%A in (%_oIds%) do (echo %%A | find /i \"2019Volume\" %nul% || set abortchange=1))\r\necho %targetchannel% | find /i \"2021 VL\" %nul% && (for %%A in (%_oIds%) do (echo %%A | find /i \"2021Volume\" %nul% || set abortchange=1))\r\necho %targetchannel% | find /i \"2024 VL\" %nul% && (for %%A in (%_oIds%) do (echo %%A | find /i \"2024Volume\" %nul% || set abortchange=1))\r\n\r\nif defined abortchange (\r\n%eline%\r\necho Mismatch found in installed Office products and target update channel. Aborting...\r\necho Non-perpetual Office products are not suppported with Perpetual VL update channels.\r\ngoto :oe_goback\r\n)\r\n\r\nif not defined build (\r\n%eline%\r\ncall :dk_color %Red% \"Failed to detect build number for the target FFN.\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto :oe_goback\r\n)\r\n\r\nset buildchk=0\r\nfor /f \"tokens=3 delims=.\" %%a in (\"%build%\") do set \"buildchk=%%a\"\r\n\r\ncall :oe_getlangs %_firstoId%\r\n\r\necho %targetchannel% | find /i \"2019 VL\" %nul% && (\r\nfor %%A in (en-gb es-mx fr-ca) do (\r\necho %_allLangs% | find /i \"%%A\" %nul% && (\r\n%eline%\r\necho [%%A] language is not supported on the Office 2019 Perpetual VL update channel. Aborting...\r\ngoto :oe_goback\r\n)\r\n)\r\n)\r\n\r\nset \"c2rcommand=\"%_c2rExe%\" platform=%_oArch% culture=%_lang% productstoadd=%_firstoId%.16_%_allLangs% cdnbaseurl.16=http://officecdn.microsoft.com/pr/%targetFFN% baseurl.16=http://officecdn.microsoft.com/pr/%targetFFN% version.16=%build% mediatype.16=CDN sourcetype.16=CDN deliverymechanism=%targetFFN% %_firstoId%.excludedapps.16=%_firstoIdExcludelist% flt.useteamsaddon=disabled flt.usebingaddononinstall=disabled flt.usebingaddononupdate=disabled\"\r\nset \"c2rclientupdate=!c2rcommand! scenario=CLIENTUPDATE\"\r\n\r\nif %clverchk% LSS %buildchk% (\r\necho:\r\ncall :dk_color %Blue% \"Do not terminate the operation before it completes...\"\r\necho:\r\necho Updating Office C2R client with the command below, please wait...\r\necho:\r\necho %c2rclientupdate%\r\n%c2rclientupdate%\r\nfor /l %%i in (1,1,30) do (if !clverchk! LSS %buildchk% (call :ch_getinfo&timeout /t 10 %nul%))\r\n)\r\n\r\nif %clverchk% LSS %buildchk% (\r\necho:\r\ncall :dk_color %Red% \"Failed to update Office C2R client. Aborting...\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto :oe_goback\r\n)\r\n\r\ncall :oe_cleanupreg\r\n\r\necho Running the below command to change update channel, please wait...\r\necho:\r\necho %c2rcommand%\r\n%c2rcommand%\r\nset errorcode=%errorlevel%\r\ntimeout /t 10 %nul%\r\n\r\necho:\r\nif %errorcode% EQU 0 (\r\ncall :dk_color %Gray% \"Now run the Office activation option from the main menu.\"\r\n) else (\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:oe_goback\r\n\r\ncall :oe_tempcleanup\r\n\r\necho:\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 goto :oemenu\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to go back...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to go back...\"\r\npause %nul1%\r\n)\r\ngoto :oemenu\r\n\r\n::========================================================================================================================================\r\n\r\n:oe_cleanupreg\r\n\r\n::  Cleanup Office update related registries, thanks to @abbodi1406\r\n::  https://techcommunity.microsoft.com/t5/office-365-blog/how-to-manage-office-365-proplus-channels-for-it-pros/ba-p/795813\r\n::  https://learn.microsoft.com/en-us/microsoft-365-apps/updates/change-update-channels#considerations-when-changing-channels\r\n\r\necho:\r\necho Cleaning Office update registry keys...\r\necho Adding new update channel to registry keys...\r\necho:\r\n\r\n%nul% reg add %o16c2r_reg%\\Configuration /v CDNBaseUrl /t REG_SZ /d \"https://officecdn.microsoft.com/pr/%targetFFN%\" /f\r\n%nul% reg add %o16c2r_reg%\\Configuration /v UpdateChannel /t REG_SZ /d \"https://officecdn.microsoft.com/pr/%targetFFN%\" /f\r\n%nul% reg add %o16c2r_reg%\\Configuration /v UpdateChannelChanged /t REG_SZ /d \"True\" /f\r\n%nul% reg delete %o16c2r_reg%\\Configuration /v UnmanagedUpdateURL /f\r\n%nul% reg delete %o16c2r_reg%\\Configuration /v UpdateUrl /f\r\n%nul% reg delete %o16c2r_reg%\\Configuration /v UpdatePath /f\r\n%nul% reg delete %o16c2r_reg%\\Configuration /v UpdateToVersion /f\r\n%nul% reg delete %o16c2r_reg%\\Updates /v UpdateToVersion /f\r\n%nul% reg delete HKLM\\SOFTWARE\\Policies\\Microsoft\\office\\16.0\\common\\officeupdate /f\r\n%nul% reg delete HKLM\\SOFTWARE\\Policies\\Microsoft\\office\\16.0\\common\\officeupdate /f /reg:32\r\n%nul% reg delete HKCU\\SOFTWARE\\Policies\\Microsoft\\office\\16.0\\common\\officeupdate /f\r\n%nul% reg delete HKLM\\SOFTWARE\\Policies\\Microsoft\\cloud\\office\\16.0\\Common\\officeupdate /f\r\n%nul% reg delete HKLM\\SOFTWARE\\Policies\\Microsoft\\cloud\\office\\16.0\\Common\\officeupdate /f /reg:32\r\n%nul% reg delete HKCU\\Software\\Policies\\Microsoft\\cloud\\office\\16.0\\Common\\officeupdate /f\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:oe_tempcleanup\r\n\r\ndel /f /q %SystemRoot%\\Temp\\SingleApps_Volume.txt %nul%\r\ndel /f /q %SystemRoot%\\Temp\\SingleApps_Retail.txt %nul%\r\ndel /f /q %SystemRoot%\\Temp\\Suites_Volume.txt %nul%\r\ndel /f /q %SystemRoot%\\Temp\\Suites_Retail.txt %nul%\r\ndel /f /q %SystemRoot%\\Temp\\getAppIds.txt %nul%\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fetch required info\r\n\r\n:ch_getinfo\r\n\r\nset _oRoot=\r\nset _oArch=\r\nset _updch=\r\nset _oIds=\r\nset _firstoId=\r\nset _lang=\r\nset _cfolder=\r\nset _version=\r\nset _clversion=\r\nset _AudienceData=\r\nset _actconfig=\r\nset _c2rXml=\r\nset _c2rExe=\r\nset _c2rCexe=\r\nset _masterxml=\r\nset ltsc19=\r\nset ltsc21=\r\nset ltsc24=\r\nset ltscfound=\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg% /v InstallPath\" %nul6%') do (set \"_oRoot=%%b\\root\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v Platform\" %nul6%') do (set \"_oArch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ClientFolder\" %nul6%') do (set \"_cfolder=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v AudienceId\" %nul6%') do (set \"_updch=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ClientCulture\" %nul6%') do (set \"_lang=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v ClientVersionToReport\" %nul6%') do (set \"_clversion=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v VersionToReport\" %nul6%') do (set \"_version=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v AudienceData\" %nul6%') do (set \"_AudienceData=%%b\")\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\ProductReleaseIDs /v ActiveConfiguration\" %nul6%') do (set \"_actconfig=%%b\")\r\n\r\necho \"%o16c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=9) || (set _tok=8)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query \"%o16c2r_reg%\\ProductReleaseIDs\\%_actconfig%\" /f \".16\" /k %nul6% ^| findstr /i \"Retail Volume\"') do (\r\nif defined _oIds (set \"_oIds=!_oIds! %%a\") else (set \"_oIds=%%a\")\r\n)\r\nset _oIds=%_oIds:.16=%\r\nfor /f \"tokens=1\" %%A in (\"%_oIds%\") do set _firstoId=%%A\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\Configuration /v %_firstoId%.ExcludedApps\" %nul6%') do (set \"_firstoIdExcludelist=%%b\")\r\n\r\nset verchk=0\r\nset clverchk=0\r\nfor /f \"tokens=3 delims=.\" %%a in (\"%_version%\") do set \"verchk=%%a\"\r\nfor /f \"tokens=3 delims=.\" %%a in (\"%_clversion%\") do set \"clverchk=%%a\"\r\n\r\nif exist \"%_oRoot%\\Licenses16\\c2rpridslicensefiles_auto.xml\" set \"_c2rXml=%_oRoot%\\Licenses16\\c2rpridslicensefiles_auto.xml\"\r\n\r\nif exist \"%ProgramData%\\Microsoft\\ClickToRun\\ProductReleases\\%_actconfig%\\x-none.16\\MasterDescriptor.x-none.xml\" (\r\nset \"_masterxml=%ProgramData%\\Microsoft\\ClickToRun\\ProductReleases\\%_actconfig%\\x-none.16\\MasterDescriptor.x-none.xml\"\r\n)\r\n\r\nif exist \"%_cfolder%\\OfficeClickToRun.exe\" (\r\nset \"_c2rExe=%_cfolder%\\OfficeClickToRun.exe\"\r\n)\r\n\r\nif exist \"%_cfolder%\\OfficeC2RClient.exe\" (\r\nset \"_c2rCexe=%_cfolder%\\OfficeC2RClient.exe\"\r\n)\r\n\r\n::  Check LTSC version files\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %o16c2r_reg%\\ProductReleaseIDs\\%_actconfig%\" /s %nul6%') do (\r\necho \"%%b\" %nul2% | findstr \"16.0.103 16.0.104 16.0.105\" %nul% && set ltsc19=LTSC\r\necho \"%%b\" %nul2% | findstr \"16.0.14332\" %nul% && set ltsc21=LTSC2021\r\necho \"%%b\" %nul2% | findstr \"16.0.17932\" %nul% && set ltsc24=LTSC2024\r\n)\r\n\r\nif not \"%ltsc19%%ltsc21%%ltsc24%\"==\"\" set ltscfound=1\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check all the installed languages\r\n\r\n:oe_getlangs\r\n\r\nif \"%1\"==\"\" (\r\nset langreg=culture\r\n) else (\r\nset langreg=%1.16\r\n)\r\n\r\nset _allLangs=\r\necho \"%o16c2r_reg%\" | find /i \"Wow6432Node\" %nul1% && (set _tok=10) || (set _tok=9)\r\nfor /f \"tokens=%_tok% delims=\\\" %%a in ('reg query \"%o16c2r_reg%\\ProductReleaseIDs\\%_actconfig%\\%langreg%\" /f \"-\" /k ^| findstr /i \"%langreg%\\\\.*-.*\"') do (\r\nif defined _allLangs (set \"_allLangs=!_allLangs!_%%a\") else (set \"_allLangs=%%a\")\r\n)\r\n\r\nset _allLangs=%_allLangs:.16=%\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Internet connection\r\n\r\n:oe_chkinternet\r\n\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif !errorlevel!==0 (set _int=1)\r\n)\r\n\r\nif not defined _int (\r\n%eline%\r\ncall :dk_color %Red% \"Internet is not connected.\"\r\ncall :dk_color %Blue% \"Internet is required for this operation.\"\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get available build number for a FFN\r\n\r\n:getbuild:\r\n$Tls12 = [Enum]::ToObject([System.Net.SecurityProtocolType], 3072)\r\n[System.Net.ServicePointManager]::SecurityProtocol = $Tls12\r\n\r\n$FFN = $env:targetFFN\r\n$windowsBuild = [System.Environment]::OSVersion.Version.Build\r\n\r\n$baseUrl = \"https://mrodevicemgr.officeapps.live.com/mrodevicemgrsvc/api/v2/C2RReleaseData?audienceFFN=$FFN\"\r\n$url = if ($windowsBuild -lt 9200) { \"$baseUrl&osver=Client|6.1\" } elseif ($windowsBuild -lt 10240) { \"$baseUrl&osver=Client|6.3\" } else { $baseUrl }\r\n\r\n$response = if ($windowsBuild -ge 9200) { irm -Uri $url -Method Get } else { (New-Object System.Net.WebClient).DownloadString($url) }\r\n\r\nif ($windowsBuild -lt 9200) {\r\n    if ($response -match '\"AvailableBuild\"\\s*:\\s*\"([^\"]+)\"') { Write-Host $matches[1] }\r\n} else {\r\n    Write-Host $response.AvailableBuild\r\n}\r\n:getbuild:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get available edition list from c2rpridslicensefiles_auto.xml\r\n::  and filter the list using MasterDescriptor.x-none.xml\r\n::  and exclude unsupported products on Windows 7/8/8.1\r\n\r\n:getlist:\r\n$xmlPath1 = $env:_c2rXml\r\n$xmlPath2 = $env:_masterxml\r\n$outputDir = $env:SystemRoot + \"\\Temp\\\"\r\n$buildNumber = [System.Environment]::OSVersion.Version.Build\r\n$excludedKeywords = @(\"2019\", \"2021\", \"2024\")\r\n$productReleaseIds = @()\r\n\r\nif (Test-Path $xmlPath1) {\r\n    $xml1 = New-Object -TypeName System.Xml.XmlDocument\r\n    $xml1.Load($xmlPath1)\r\n    foreach ($node in $xml1.SelectNodes(\"//ProductReleaseId\")) {\r\n        $id = $node.GetAttribute(\"id\")\r\n        $exclude = $false\r\n        if ($buildNumber -lt 10240) {\r\n            foreach ($keyword in $excludedKeywords) {\r\n                if ($id -match $keyword) { $exclude = $true; break }\r\n            }\r\n        }\r\n        if ($id -ne \"CommonLicenseFiles\" -and -not $exclude) { $productReleaseIds += $id }\r\n    }\r\n}\r\n\r\n$categories = @{\r\n    \"Suites_Retail\" = @(); \"Suites_Volume\" = @()\r\n    \"SingleApps_Retail\" = @(); \"SingleApps_Volume\" = @()\r\n}\r\n\r\nforeach ($id in $productReleaseIds) {\r\n    $category = if ($id -match \"Retail\") { \"Retail\" } else { \"Volume\" }\r\n    $categories[\"SingleApps_$category\"] += $id\r\n}\r\n\r\nif (Test-Path $xmlPath2) {\r\n    $xml2 = New-Object -TypeName System.Xml.XmlDocument\r\n    $xml2.Load($xmlPath2)\r\n    foreach ($sku in $xml2.SelectNodes(\"//SKU\")) {\r\n        $skuId = $sku.GetAttribute(\"ID\")\r\n        if ($productReleaseIds -contains $skuId) {\r\n            $appIds = $sku.SelectNodes(\"Apps/App\") | ForEach-Object { $_.GetAttribute(\"id\") }\r\n            if ($appIds -contains \"Excel\" -and $appIds -contains \"Word\") {\r\n                $category = if ($skuId -match \"Retail\") { \"Retail\" } else { \"Volume\" }\r\n                $categories[\"Suites_$category\"] += $skuId\r\n                $categories[\"SingleApps_$category\"] = $categories[\"SingleApps_$category\"] | Where-Object { $_ -ne $skuId }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\nforeach ($section in $categories.Keys) {\r\n    $filePath = Join-Path -Path $outputDir -ChildPath \"$section.txt\"\r\n    $ids = $categories[$section]\r\n    if ($ids.Count -gt 0) { $ids | Out-File -FilePath $filePath -Encoding ASCII }\r\n}\r\n:getlist:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get App list for a specific product ID using MasterDescriptor.x-none.xml\r\n\r\n:getappnames:\r\n$xmlPath = $env:_masterxml\r\n$targetSkuId = $env:targetedition\r\n$outputDir = $env:SystemRoot + \"\\Temp\\\"\r\n$outputFile = Join-Path -Path $outputDir -ChildPath \"getAppIds.txt\"\r\n$excludeIds = @(\"shared\", \"PowerPivot\", \"PowerView\", \"MondoOnly\", \"OSM\", \"OSMUX\", \"Groove\", \"DCF\")\r\n\r\n$xml = New-Object -TypeName System.Xml.XmlDocument\r\n$xml.Load($xmlPath)\r\n\r\n$appIdsList = @()\r\n$skuNodes = $xml.SelectNodes(\"//SKU[@ID='$targetSkuId']\")\r\n\r\nforeach ($skuNode in $skuNodes) {\r\n    foreach ($app in $skuNode.SelectNodes(\"Apps/App\")) {\r\n        $appId = $app.GetAttribute(\"id\")\r\n        if ($excludeIds -notcontains $appId) {\r\n            $appIdsList += $appId\r\n        }\r\n    }\r\n}\r\n\r\nif ($appIdsList.Count -gt 0) {\r\n    $appIdsList | Out-File -FilePath $outputFile -Encoding ASCII\r\n}\r\n:getappnames:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set variables\r\n\r\n:dk_setvar\r\n\r\nset ps=%SysPath%\\WindowsPowerShell\\v1.0\\powershell.exe\r\nset psc=%ps% -nop -c\r\nset winbuild=1\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset _NCS=1\r\nif %winbuild% LSS 10586 set _NCS=0\r\nif %winbuild% GEQ 10586 reg query \"HKCU\\Console\" /v ForceV2 %nul2% | find /i \"0x0\" %nul1% && (set _NCS=0)\r\n\r\necho \"%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%\" | find /i \"ARM64\" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)\r\n\r\nif %_NCS% EQU 1 (\r\nfor /F %%a in ('echo prompt $E ^| cmd') do set \"esc=%%a\"\r\nset     \"Red=\"41;97m\"\"\r\nset    \"Gray=\"100;97m\"\"\r\nset   \"Green=\"42;97m\"\"\r\nset    \"Blue=\"44;97m\"\"\r\nset   \"White=\"107;91m\"\"\r\nset    \"_Red=\"40;91m\"\"\r\nset  \"_White=\"40;37m\"\"\r\nset  \"_Green=\"40;92m\"\"\r\nset \"_Yellow=\"40;93m\"\"\r\n) else (\r\nset     \"Red=\"Red\" \"white\"\"\r\nset    \"Gray=\"Darkgray\" \"white\"\"\r\nset   \"Green=\"DarkGreen\" \"white\"\"\r\nset    \"Blue=\"Blue\" \"white\"\"\r\nset   \"White=\"White\" \"Red\"\"\r\nset    \"_Red=\"Black\" \"Red\"\"\r\nset  \"_White=\"Black\" \"Gray\"\"\r\nset  \"_Green=\"Black\" \"Green\"\"\r\nset \"_Yellow=\"Black\" \"Yellow\"\"\r\n)\r\n\r\nset \"nceline=echo: &echo ==== ERROR ==== &echo:\"\r\nset \"eline=echo: &call :dk_color %Red% \"==== ERROR ====\" &echo:\"\r\nif %~z0 GEQ 200000 (\r\nset \"_exitmsg=Go back\"\r\nset \"_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option.\"\r\n) else (\r\nset \"_exitmsg=Exit\"\r\nset \"_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option.\"\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check wmic.exe\r\n\r\n:dk_ckeckwmic\r\n\r\nif %winbuild% LSS 9200 (set _wmic=1&exit /b)\r\nset _wmic=0\r\nfor %%# in (wmic.exe) do @if not \"%%~$PATH:#\"==\"\" (\r\ncmd /c \"wmic path Win32_ComputerSystem get CreationClassName /value\" %nul2% | find /i \"computersystem\" %nul1% && set _wmic=1\r\n)\r\nexit /b\r\n\r\n::  Show info for potential script stuck scenario\r\n\r\n:dk_sppissue\r\n\r\nsc start %_slser% %nul%\r\nset spperror=%errorlevel%\r\n\r\nif %spperror% NEQ 1056 if %spperror% NEQ 0 (\r\n%eline%\r\necho sc start %_slser% [Error Code: %spperror%]\r\nif %spperror% EQU 1053 (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\ncall :dk_color %Blue% \"If it still does not work, go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\n)\r\n)\r\n\r\necho:\r\n%psc% \"$job = Start-Job { (Get-WmiObject -Query 'SELECT * FROM %sps%').Version }; if (-not (Wait-Job $job -Timeout 30)) {write-host '%_slser% is not working correctly. Check this webpage for help - %mas%troubleshoot'}\"\r\nexit /b\r\n\r\n::  Common lines used in PowerShell reflection code\r\n\r\n:dk_reflection\r\n\r\nset ref=$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1);\r\nset ref=%ref% $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False);\r\nset ref=%ref% $TypeBuilder = $ModuleBuilder.DefineType(0);\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_color\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3'\r\n) else if not exist %ps% (\r\necho %~3\r\n)\r\nexit /b\r\n\r\n:dk_color2\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[%~3%~4%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'\r\n) else if not exist %ps% (\r\necho %~3 %~6\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_done\r\n\r\necho:\r\nif %_unattended%==1 timeout /t 2 & exit /b\r\n\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 exit /b\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n:: Leave empty line below\r\n"
  },
  {
    "path": "MAS/Separate-Files-Version/Change_Windows_Edition.cmd",
    "content": "@set masver=3.10\r\n@echo off\r\n\r\n\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\n\r\n::  To stage current edition while changing edition with CBS Upgrade Method, change 0 to 1 in below line\r\nset _stg=0\r\n\r\n\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\nset re1=\r\nset re2=\r\nset \"_cmdf=%~f0\"\r\nfor %%# in (%*) do (\r\nif /i \"%%#\"==\"re1\" set re1=1\r\nif /i \"%%#\"==\"re2\" set re2=1\r\nif /i \"%%#\"==\"-qedit\" (set re1=1&set re2=1)\r\n)\r\n\r\n:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows\r\n:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\Sysnative\\cmd.exe if not defined re1 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\Sysnative\\cmd.exe /c \"\"!_cmdf!\" %* re1\"\r\nexit /b\r\n)\r\n\r\n:: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\SysArm32\\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\SysArm32\\cmd.exe /c \"\"!_cmdf!\" %* re2\"\r\nexit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset \"blank=\"\r\nset \"mas=ht%blank%tps%blank%://m%blank%ass%blank%grave.dev/\"\r\nset \"github=ht%blank%tps%blank%://github.com/m%blank%assgra%blank%vel/Micro%blank%soft-Acti%blank%vation-Scripts\"\r\nset \"selfgit=ht%blank%tps%blank%://git.acti%blank%vated.win/Micr%blank%osoft-Act%blank%ivation-Scripts\"\r\n\r\n::  Check if Null service is working, it's important for the batch script\r\n\r\nsc query Null | find /i \"RUNNING\"\r\nif %errorlevel% NEQ 0 (\r\necho:\r\necho Null service is not running, script may crash...\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%fix_service\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20\r\n)\r\ncls\r\n\r\n::  Check LF line ending\r\n\r\npushd \"%~dp0\"\r\n>nul findstr /v \"$\" \"%~nx0\" && (\r\necho:\r\necho Error - Script either has LF line ending issue or an empty line at the end of the script is missing.\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20 >nul\r\npopd\r\nexit /b\r\n)\r\npopd\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\ntitle  Change Windows Edition %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args set _args=%_args:re1=%\r\nif defined _args set _args=%_args:re2=%\r\nif defined _args (\r\nfor %%A in (%_args%) do (\r\nif /i \"%%A\"==\"-el\"                    set _elev=1\r\n)\r\n)\r\n\r\nset \"nul1=1>nul\"\r\nset \"nul2=2>nul\"\r\nset \"nul6=2^>nul\"\r\nset \"nul=>nul 2>&1\"\r\n\r\ncall :dk_setvar\r\nset \"line=echo ___________________________________________________________________________________________\"\r\n\r\n::========================================================================================================================================\r\n\r\nif %winbuild% EQU 1 (\r\n%eline%\r\necho Failed to detect Windows build number.\r\necho:\r\nsetlocal EnableDelayedExpansion\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\nif exist \"%Systemdrive%\\Users\\WDAGUtilityAccount\" (\r\nsc query gcs | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Windows Sandbox detected.\r\necho The script cannot run due to missing licensing components. Aborting...\r\necho:\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 7600 (\r\n%eline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho This option is supported only for Windows 7/8/8.1/10/11 and their Server equivalents.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix special character limitations in path name\r\n\r\nset \"_work=%~dp0\"\r\nif \"%_work:~-1%\"==\"\\\" set \"_work=%_work:~0,-1%\"\r\n\r\nset \"_batf=%~f0\"\r\nset \"_batp=%_batf:'=''%\"\r\n\r\nset _PSarg=\"\"\"%~f0\"\"\" -el %_args%\r\nset _PSarg=%_PSarg:'=''%\r\n\r\nset \"_ttemp=%userprofile%\\AppData\\Local\\Temp\"\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\necho \"!_batf!\" | find /i \"!_ttemp!\" %nul1% && (\r\nif /i not \"!_work!\"==\"!_ttemp!\" (\r\n%eline%\r\necho The script was launched from the temp folder.\r\necho You are most likely running the script directly from the archive file.\r\necho:\r\necho Extract the archive file and launch the script from the extracted folder.\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Elevate script as admin and pass arguments and preventing loop\r\n\r\n%nul1% fltmc || (\r\nif not defined _elev %psc% \"start cmd.exe -arg '/c \\\"!_PSarg!\\\"' -verb runas\" && exit /b\r\n%eline%\r\necho This script needs admin rights.\r\necho Right click on this script and select 'Run as administrator'.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check PowerShell\r\n\r\n::pstst $ExecutionContext.SessionState.LanguageMode :pstst\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"if ($PSVersionTable.PSEdition -ne 'Core') {$f=[System.IO.File]::ReadAllText('!_batp!') -split ':pstst';. ([scriptblock]::Create($f[1]))}\" %nul6%') do (set tstresult=%%a)\r\n\r\nif /i not \"%tstresult%\"==\"FullLanguage\" (\r\n%eline%\r\nfor /f \"delims=\" %%a in ('%psc% \"$ExecutionContext.SessionState.LanguageMode\" %nul6%') do (set tstresult2=%%a)\r\necho Test 1 - %tstresult%\r\necho Test 2 - !tstresult2!\r\necho:\r\n\r\nREM check LanguageMode\r\n\r\necho: !tstresult2! | findstr /i \"ConstrainedLanguage RestrictedLanguage NoLanguage\" %nul1% && (\r\necho FullLanguage mode not found in PowerShell. Aborting...\r\necho If you have applied restrictions on Powershell then undo those changes.\r\nset fixes=%fixes% %mas%fix_powershell\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_powershell\"\r\ngoto dk_done\r\n)\r\n\r\nREM check Powershell core version\r\n\r\ncmd /c \"%psc% \"$PSVersionTable.PSEdition\"\" | find /i \"Core\" %nul1% && (\r\necho Windows Powershell is needed for MAS but it seems to be replaced with Powershell core. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n\r\nREM check for Mal-ware that may cause issues with Powershell\r\n\r\nfor /r \"%ProgramFiles%\\\" %%f in (secureboot.exe) do if exist \"%%f\" (\r\necho \"%%f\"\r\necho Mal%blank%ware found, PowerShell is not working properly.\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\ngoto dk_done\r\n)\r\n\r\nREM check if .NET is working properly\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\ncmd /c \"%psc% \"\"try {[System.AppDomain]::CurrentDomain.GetAssemblies(); [System.Math]::Sqrt(144)} catch {Exit 3}\"\"\" %nul%\r\nif !errorlevel!==3 (\r\necho Windows Powershell failed to load .NET command. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nREM check antivirus and other errors\r\n\r\necho PowerShell is not working properly. Aborting...\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\necho:\r\necho Your antivirus software might be blocking the script.\r\necho:\r\nsc query sense | find /i \"RUNNING\" %nul% && (\r\necho Installed Antivirus - Microsoft Defender for Endpoint\r\n)\r\ncmd /c \"%psc% \"\"$av = Get-WmiObject -Namespace root\\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { $n += $i.displayName }; if ($n) { Write-Host ('Installed Antivirus - ' + ($n -join ', '))}\"\"\"\r\n)\r\n\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Disable QuickEdit and launch from conhost.exe to avoid Terminal app\r\n\r\nif %winbuild% GEQ 17763 (\r\nset terminal=1\r\n) else (\r\nset terminal=\r\n)\r\n\r\n::  Check if script is running in Terminal app\r\n\r\nif defined terminal (\r\nset lines=0\r\nfor /f \"skip=3 tokens=* delims=\" %%A in ('mode con') do if \"!lines!\"==\"0\" (\r\nfor %%B in (%%A) do set lines=%%B\r\n)\r\nif !lines! GEQ 100 set terminal=\r\n)\r\n\r\nif %_unattended%==1 goto :skipQE\r\nfor %%# in (%_args%) do (if /i \"%%#\"==\"-qedit\" goto :skipQE)\r\n\r\n::  Relaunch to disable QuickEdit in the current session and use conhost.exe instead of the Terminal app\r\n::  This code disables QuickEdit for the current cmd.exe session without making permanent registry changes\r\n::  It is included because clicking on the script window can pause execution, causing confusion that the script has stopped due to an error\r\n\r\nset resetQE=1\r\nreg query HKCU\\Console /v QuickEdit %nul2% | find /i \"0x0\" %nul1% && set resetQE=0\r\nreg add HKCU\\Console /v QuickEdit /t REG_DWORD /d 0 /f %nul1%\r\n\r\nif defined terminal (\r\nstart conhost.exe \"!_batf!\" %_args% -qedit\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n) else if %resetQE% EQU 1 (\r\nstart cmd.exe /c \"\"!_batf!\" %_args% -qedit\"\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n)\r\n\r\n:skipQE\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check for updates\r\n\r\nset -=\r\nset old=\r\nset pingp=\r\nset upver=%masver:.=%\r\n\r\nfor %%A in (\r\nactiv%-%ated.win\r\nmass%-%grave.dev\r\n) do if not defined pingp (\r\nfor /f \"delims=[] tokens=2\" %%B in ('ping -n 1 %%A') do (\r\nif not \"%%B\"==\"\" (set old=1& set pingp=1)\r\nfor /f \"delims=[] tokens=2\" %%C in ('ping -n 1 updatecheck%upver%.%%A') do (\r\nif not \"%%C\"==\"\" set old=\r\n)\r\n)\r\n)\r\n\r\nif defined old (\r\necho ________________________________________________\r\n%eline%\r\necho Your version of MAS [%masver%] is outdated.\r\necho ________________________________________________\r\necho:\r\nif not %_unattended%==1 (\r\necho [1] Get Latest MAS\r\necho [0] Continue Anyway\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 rem\r\nif !errorlevel!==1 (start %selfgit% & start %github% & start %mas% & exit /b)\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nsetlocal DisableDelayedExpansion\r\n\r\n::  Check desktop location\r\n\r\nset desktop=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" /v Desktop') do call set \"desktop=%%b\"\r\nif not defined desktop for /f \"delims=\" %%a in ('%psc% \"& {write-host $([Environment]::GetFolderPath('Desktop'))}\"') do call set \"desktop=%%a\"\r\n\r\nif not defined desktop (\r\n%eline%\r\necho Unable to detect Desktop location, aborting...\r\ngoto dk_done\r\n)\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\nif not defined terminal mode 98, 30\r\ntitle  Change Windows Edition %masver%\r\n\r\necho:\r\necho Initializing...\r\necho:\r\n\r\nfor %%# in (\r\nsppsvc.exe\r\ndism.exe\r\n) do (\r\nif not exist %SysPath%\\%%# (\r\n%eline%\r\necho [%SysPath%\\%%#] file is missing, aborting...\r\ncall :dk_color %Blue% \"Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options.\"\r\ncall :dk_color %Blue% \"After that, restart system and try activation again.\"\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"If it still shows the same error, do this - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset spp=SoftwareLicensingProduct\r\nset sps=SoftwareLicensingService\r\n\r\ncall :dk_reflection\r\ncall :dk_ckeckwmic\r\ncall :dk_sppissue\r\n\r\nfor /f \"tokens=6-7 delims=[]. \" %%i in ('ver') do if not \"%%j\"==\"\" (\r\nset fullbuild=%%i.%%j\r\n) else (\r\nfor /f \"tokens=3\" %%G in ('\"reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v UBR\" %nul6%') do if not errorlevel 1 set /a \"UBR=%%G\"\r\nfor /f \"skip=2 tokens=3,4 delims=. \" %%G in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildLabEx') do (\r\nif defined UBR (set \"fullbuild=%%G.!UBR!\") else (set \"fullbuild=%%G.%%H\")\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Activation IDs\r\n\r\ncall :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f\r\nif not defined allapps (\r\n%eline%\r\necho Failed to find activation IDs. Aborting...\r\ncall :dk_color %Blue% \"To fix this issue, activate Windows from the main menu.\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check Windows Edition and branch\r\n\r\nset osedition=\r\nset dismnotworking=\r\n\r\nfor /f \"tokens=3 delims=: \" %%a in ('DISM /English /Online /Get-CurrentEdition %nul6% ^| find /i \"Current Edition :\"') do set \"osedition=%%a\"\r\nif not defined osedition set dismnotworking=1\r\n\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\nif not defined osedition %chkedi% do if not errorlevel 1 (call set \"osedition=%%a\")\r\n\r\nif not defined osedition (\r\n%eline%\r\necho Failed to detect OS edition, aborting...\r\ncall :dk_color %Blue% \"To fix this issue, activate Windows from the main menu.\"\r\ngoto dk_done\r\n)\r\n\r\nfor /f \"skip=2 tokens=3\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v EditionID %nul6%') do set \"regedition=%%a\"\r\nif /i not \"%osedition%\"==\"%regedition%\" (\r\nset \"showeditionerror=call :dk_color %_Yellow% \"[%osedition%] [Reg-%regedition%].\"\"\r\n)\r\n\r\nset branch=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" /v BuildBranch %nul6%') do set \"branch=%%b\"\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get target editions list\r\n\r\nset _target=\r\nset _dtarget=\r\nset _ptarget=\r\nset _ntarget=\r\nset _wtarget=\r\n\r\nif %winbuild% GEQ 10240 for /f \"tokens=4\" %%a in ('dism /online /english /Get-TargetEditions ^| findstr /i /c:\"Target Edition : \"') do (if defined _dtarget (set \"_dtarget= !_dtarget! %%a \") else (set \"_dtarget= %%a \"))\r\nif %winbuild% LSS 10240 for /f \"tokens=4\" %%a in ('%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':cbsxml\\:.*';. ([scriptblock]::Create($f[1])) -GetTargetEditions;\" ^| findstr /i /c:\"Target Edition : \"') do (if defined _ptarget (set \"_ptarget= !_ptarget! %%a \") else (set \"_ptarget= %%a \"))\r\n\r\nif %winbuild% GEQ 10240 if not exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" (\r\nif %winbuild% GEQ 17063 call :ced_edilist\r\nif /i \"%osedition:~0,4%\"==\"Core\" set _pro=Professional\r\nif /i \"%osedition%\"==\"CoreN\" set _pro=ProfessionalN\r\nset \"_dtarget= %_dtarget% !_wtarget! !_pro! \"\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nfor %%# in (CloudEdition CloudEditionN ServerRdsh) do if /i %osedition%==%%# (\r\ncls\r\necho:\r\ncall :dk_color %Red% \"==== Note ====\"\r\necho:\r\necho [EditionID:%osedition% ^| %fullbuild%]\r\necho:\r\necho Changing this edition may not remove \"%osedition%\"-specific features.\r\necho:\r\ncall :dk_color %_Yellow% \"Press [7] to continue anyway...\"\r\nchoice /c 7 /n\r\ncls\r\n)\r\n\r\nfor %%# in ( %_dtarget% %_ptarget% ) do if /i not \"%%#\"==\"%osedition%\" (\r\necho \"!_target!\" | find /i \" %%# \" %nul1% || set \"_target= !_target! %%# \"\r\n)\r\n\r\nif defined _target (\r\nfor %%# in (%_target%) do (\r\necho %%# | findstr /i \"CountrySpecific CloudEdition\" %nul% || (set \"_ntarget=!_ntarget! %%#\")\r\n)\r\n)\r\n\r\nif not defined _ntarget (\r\n%line%\r\necho:\r\nif defined dismnotworking call :dk_color %Red% \"DISM.exe is not working.\"\r\ncall :dk_color %Gray% \"Target editions not found.\"\r\necho Current Edition [%osedition% ^| %winbuild%] can not be changed to any other Edition.\r\n%line%\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:cedmenu2\r\n\r\ncls\r\nif not defined terminal mode 98, 30\r\nset inpt=\r\nset counter=0\r\nset verified=0\r\nset targetedition=\r\n\r\n%line%\r\necho:\r\ncall :dk_color %Gray% \"You can change the edition [%osedition%] [%fullbuild%] to one of the following.\"\r\n%showeditionerror%\r\nif defined dismnotworking (\r\ncall :dk_color %_Yellow% \"Note - DISM.exe is not working.\"\r\nif /i \"%osedition:~0,4%\"==\"Core\" call :dk_color %_Yellow% \"     - You will see more edition options to choose once its changed to Pro.\"\r\n)\r\n%line%\r\necho:\r\n\r\nfor %%A in (%_ntarget%) do (\r\nset /a counter+=1\r\nif /i %%A==IoTEnterprise (\r\necho [!counter!]  %%A [GAC, not LTSC]\r\n) else (\r\necho [!counter!]  %%A\r\n)\r\nset targetedition!counter!=%%A\r\n)\r\n\r\n%line%\r\necho:\r\necho [0]  %_exitmsg%\r\necho:\r\ncall :dk_color %_Green% \"Enter an option number using your keyboard and press Enter to confirm:\"\r\nset /p inpt=\r\nif \"%inpt%\"==\"\" goto cedmenu2\r\nif \"%inpt%\"==\"0\" exit /b\r\nfor /l %%i in (1,1,%counter%) do (if \"%inpt%\"==\"%%i\" set verified=1)\r\nset targetedition=!targetedition%inpt%!\r\nif %verified%==0 goto cedmenu2\r\n\r\n::========================================================================================================================================\r\n\r\nif %winbuild% LSS 10240 goto :cbsmethod\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" goto :ced_change_server\r\n\r\ncls\r\nif not defined terminal mode con cols=105 lines=32\r\n\r\nif /i \"%targetedition%\"==\"ServerRdsh\" (\r\necho:\r\ncall :dk_color %Red% \"==== Note ====\"\r\necho:\r\necho Once the edition is changed to \"%targetedition%\", \r\necho the system may not be able to properly change edition later.\r\necho:\r\necho [1] Continue Anyway\r\necho [0] Go Back\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 goto cedmenu2\r\nif !errorlevel!==1 rem\r\n)\r\n\r\ncls\r\nset key=\r\nset _chan=\r\nset _dismapi=0\r\n\r\n::  Check if DISM API or slmgr.vbs is required for edition upgrade\r\n\r\nif not exist \"%SysPath%\\spp\\tokens\\skus\\%targetedition%\\%targetedition%*.xrm-ms\" (\r\necho %_wtarget% | find /i \" %targetedition% \" || (\r\nset _dismapi=1\r\n)\r\n)\r\n\r\nset \"keyflow=Retail OEM:NONSLP OEM:DM Volume:MAK Volume:GVLK PGS:TB Retail:TB:Eval\"\r\n\r\ncall :ced_targetSKU %targetedition%\r\nif defined targetSKU call :ced_windowskey\r\nif defined key if defined pkeychannel set _chan=%pkeychannel%\r\nif not defined key call :changeeditiondata\r\nif not defined key if %_dismapi%==1 if /i \"%targetedition%\"==\"Professional\" (\r\nset key=VK7JG-NPHTM-C97JM-9MPGT-3V66T\r\nset _chan=Retail\r\n)\r\n\r\nif not defined key (\r\n%eline%\r\necho [%targetedition% ^| %winbuild%]\r\necho Failed to get product key from pkeyhelper.dll.\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Changing from Core to Non-Core & Changing editions in Windows build older than 17134 requires \"changepk /productkey\" or DISM Api method and restart\r\n::  In other cases, editions can be changed instantly with \"slmgr /ipk\"\r\n\r\nif %_dismapi%==1 (\r\nif not defined terminal mode con cols=105 lines=40\r\ncall :ced_rebootflag\r\nif defined rebootreq goto dk_done\r\n)\r\n\r\ncls\r\n%line%\r\necho:\r\n%showeditionerror%\r\nif defined dismnotworking call :dk_color %_Yellow% \"DISM.exe is not working.\"\r\necho Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...\r\necho:\r\n\r\nif %_dismapi%==1 (\r\ncall :dk_color %Green% \"Notes -\"\r\necho:\r\necho  - Save your work before continuing, the system will auto-restart.\r\necho:\r\necho  - You will need to activate with HWID option once the edition is changed.\r\n%line%\r\necho:\r\nchoice /C:21 /N /M \"[1] Continue [2] %_exitmsg% : \"\r\nif !errorlevel!==1 exit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nif %_dismapi%==0 (\r\necho Installing %_chan% key [%key%]\r\necho:\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey=\"%key%\" %nul%\r\nif %_wmic% EQU 0 %psc% \"try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\nset keyerror=!errorlevel!\r\ncmd /c exit /b !keyerror!\r\nif !keyerror! NEQ 0 set \"keyerror=[0x!=ExitCode!]\"\r\n\r\nif !keyerror! EQU 0 (\r\ncall :dk_refresh\r\ncall :dk_color %Green% \"[Successful]\"\r\necho:\r\ncall :dk_color %Gray% \"Reboot is required to fully change the edition.\"\r\n) else (\r\ncall :dk_color %Red% \"[Unsuccessful] [Error Code: !keyerror!]\"\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\n)\r\n)\r\n\r\nif %_dismapi%==1 (\r\necho:\r\necho Applying the DISM API method with %_chan% key %key%. Please wait...\r\necho:\r\n\r\ncall :ced_prep\r\nif defined preperror goto dk_done\r\n\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':dismapi\\:.*';. ([scriptblock]::Create($f[1])) %targetedition% %key%\"\r\ncall :ced_postprep\r\n)\r\n%line%\r\n\r\ngoto dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:cbsmethod\r\n\r\ncls\r\nif not defined terminal (\r\nmode con cols=105 lines=32\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\n\r\ncall :ced_rebootflag\r\nif defined rebootreq goto dk_done\r\n\r\necho:\r\n%showeditionerror%\r\nif defined dismnotworking call :dk_color %_Yellow% \"Note - DISM.exe is not working.\"\r\necho Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...\r\necho:\r\ncall :dk_color %Blue% \"Important - Save your work before continuing, the system will auto-restart.\"\r\necho:\r\nchoice /C:01 /N /M \"[1] Continue [0] %_exitmsg% : \"\r\nif %errorlevel%==1 exit /b\r\n\r\necho:\r\necho Initializing...\r\necho:\r\n\r\ncall :ced_prep\r\nif defined preperror goto dk_done\r\n\r\nif %_stg%==0 (set stage=) else (set stage=-StageCurrent)\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':cbsxml\\:.*';. ([scriptblock]::Create($f[1])) -SetEdition %targetedition% %stage%\"\r\ncall :ced_postprep\r\n%line%\r\n\r\ngoto dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ced_change_server\r\n\r\ncls\r\nif not defined terminal (\r\nmode con cols=105 lines=32\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\n\r\nset key=\r\nset _chan=\r\nset \"keyflow=Volume:GVLK Retail Volume:MAK OEM:NONSLP OEM:DM PGS:TB Retail:TB:Eval\"\r\n\r\ncall :ced_targetSKU %targetedition%\r\nif defined targetSKU call :ced_windowskey\r\nif defined key if defined pkeychannel set _chan=%pkeychannel%\r\nif not defined key call :changeeditiondata\r\n\r\nif not defined key (\r\n%eline%\r\necho [%targetedition% ^| %winbuild%]\r\necho Failed to get product key from pkeyhelper.dll.\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\ncall :ced_rebootflag\r\nif defined rebootreq goto dk_done\r\n\r\ncls\r\necho:\r\n%showeditionerror%\r\nif defined dismnotworking call :dk_color %_Yellow% \"Note - DISM.exe is not working.\"\r\necho Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...\r\necho:\r\n\r\ncall :ced_prep\r\nif defined preperror goto dk_done\r\n\r\necho Applying the command with %_chan% key...\r\necho DISM /online /Set-Edition:%targetedition% /ProductKey:%key% /AcceptEula\r\nDISM /online /Set-Edition:%targetedition% /ProductKey:%key% /AcceptEula\r\n\r\ncall :ced_postprep\r\n%line%\r\n\r\ngoto dk_done\r\n\r\n::========================================================================================================================================\r\n\r\n:ced_prep\r\n\r\nset _time=\r\nset preperror=\r\n\r\nfor /f %%a in ('%psc% \"(Get-Date).ToString('yyyyMMdd-HHmmssfff')\"') do set _time=%%a\r\n\r\n%psc% Stop-Service TrustedInstaller -force %nul%\r\n\r\nsc query TrustedInstaller | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Failed to stop the TrustedInstaller service.\r\necho Reboot your machine using the restart option and try again.\r\nset preperror=1\r\nexit /b\r\n)\r\n\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\backup_cbs_%_time%.log\" %nul%\r\ncopy /y /b \"%SystemRoot%\\logs\\DISM\\dism.log\" \"%SystemRoot%\\logs\\DISM\\backup_dism_%_time%.log\" %nul%\r\n\r\ndel /f /q \"%SystemRoot%\\logs\\cbs\\cbs.log\" %nul%\r\ndel /f /q \"%SystemRoot%\\logs\\DISM\\dism.log\" %nul%\r\n\r\n:: Initiate this to appear in fresh logs\r\n\r\ndism /online /english /Get-CurrentEdition %nul%\r\ndism /online /english /Get-TargetEditions %nul%\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ced_postprep\r\n\r\ntimeout /t 5 %nul1%\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\cbs_%_time%.log\" %nul%\r\ncopy /y /b \"%SystemRoot%\\logs\\DISM\\dism.log\" \"%SystemRoot%\\logs\\DISM\\dism_%_time%.log\" %nul%\r\n\r\nif not exist \"!desktop!\\ChangeEdition_Logs\\\" md \"!desktop!\\ChangeEdition_Logs\\\" %nul%\r\ncall :compresslog cbs\\cbs_%_time%.log ChangeEdition_Logs\\CBS %nul%\r\ncall :compresslog DISM\\dism_%_time%.log ChangeEdition_Logs\\DISM %nul%\r\n\r\necho:\r\nif %winbuild% GEQ 9200 %psc% \"if ((Get-WindowsOptionalFeature -Online -FeatureName NetFx3).State -eq 'Enabled') {Write-Host 'Checking .NET Framework 3.5 Status - Enabled'}\"\r\necho Log files are copied to the ChangeEdition_Logs folder on your desktop.\r\necho:\r\ncall :dk_color %Blue% \"In case there are errors, you should restart the system before trying again.\"\r\necho:\r\nset fixes=%fixes% %mas%change_edition_issues\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%change_edition_issues\"\r\nexit /b\r\n\r\n:compresslog\r\n\r\n::  https://stackoverflow.com/a/46268232\r\n\r\nset \"ddf=\"%SystemRoot%\\Temp\\%Random%%Random%%Random%%Random%\"\"\r\n%nul% del /q /f %ddf%\r\necho/.New Cabinet>%ddf%\r\necho/.set Cabinet=ON>>%ddf%\r\necho/.set CabinetFileCountThreshold=0;>>%ddf%\r\necho/.set Compress=ON>>%ddf%\r\necho/.set CompressionType=LZX>>%ddf%\r\necho/.set CompressionLevel=7;>>%ddf%\r\necho/.set CompressionMemory=21;>>%ddf%\r\necho/.set FolderFileCountThreshold=0;>>%ddf%\r\necho/.set FolderSizeThreshold=0;>>%ddf%\r\necho/.set GenerateInf=OFF>>%ddf%\r\necho/.set InfFileName=nul>>%ddf%\r\necho/.set MaxCabinetSize=0;>>%ddf%\r\necho/.set MaxDiskFileCount=0;>>%ddf%\r\necho/.set MaxDiskSize=0;>>%ddf%\r\necho/.set MaxErrors=1;>>%ddf%\r\necho/.set RptFileName=nul>>%ddf%\r\necho/.set UniqueFiles=ON>>%ddf%\r\nfor /f \"tokens=* delims=\" %%D in ('dir /a:-D/b/s \"%SystemRoot%\\logs\\%1\"') do (\r\n echo/\"%%~fD\"  /inf=no;>>%ddf%\r\n)\r\nmakecab /F %ddf% /D DiskDirectory1=\"\" /D CabinetNameTemplate=\"!desktop!\\%2_%_time%.cab\"\r\ndel /q /f %ddf%\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set variables\r\n\r\n:dk_setvar\r\n\r\nset ps=%SysPath%\\WindowsPowerShell\\v1.0\\powershell.exe\r\nset psc=%ps% -nop -c\r\nset winbuild=1\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset _NCS=1\r\nif %winbuild% LSS 10586 set _NCS=0\r\nif %winbuild% GEQ 10586 reg query \"HKCU\\Console\" /v ForceV2 %nul2% | find /i \"0x0\" %nul1% && (set _NCS=0)\r\n\r\necho \"%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%\" | find /i \"ARM64\" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)\r\n\r\nif %_NCS% EQU 1 (\r\nfor /F %%a in ('echo prompt $E ^| cmd') do set \"esc=%%a\"\r\nset     \"Red=\"41;97m\"\"\r\nset    \"Gray=\"100;97m\"\"\r\nset   \"Green=\"42;97m\"\"\r\nset    \"Blue=\"44;97m\"\"\r\nset   \"White=\"107;91m\"\"\r\nset    \"_Red=\"40;91m\"\"\r\nset  \"_White=\"40;37m\"\"\r\nset  \"_Green=\"40;92m\"\"\r\nset \"_Yellow=\"40;93m\"\"\r\n) else (\r\nset     \"Red=\"Red\" \"white\"\"\r\nset    \"Gray=\"Darkgray\" \"white\"\"\r\nset   \"Green=\"DarkGreen\" \"white\"\"\r\nset    \"Blue=\"Blue\" \"white\"\"\r\nset   \"White=\"White\" \"Red\"\"\r\nset    \"_Red=\"Black\" \"Red\"\"\r\nset  \"_White=\"Black\" \"Gray\"\"\r\nset  \"_Green=\"Black\" \"Green\"\"\r\nset \"_Yellow=\"Black\" \"Yellow\"\"\r\n)\r\n\r\nset \"nceline=echo: &echo ==== ERROR ==== &echo:\"\r\nset \"eline=echo: &call :dk_color %Red% \"==== ERROR ====\" &echo:\"\r\nif %~z0 GEQ 200000 (\r\nset \"_exitmsg=Go back\"\r\nset \"_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option.\"\r\n) else (\r\nset \"_exitmsg=Exit\"\r\nset \"_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option.\"\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Refresh license status\r\n\r\n:dk_refresh\r\n\r\nif %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call RefreshLicenseStatus %nul%\r\nif %_wmic% EQU 0 %psc% \"$null=(([WMICLASS]'%sps%').GetInstances()).RefreshLicenseStatus()\" %nul%\r\nexit /b\r\n\r\n::  Get all products Activation IDs\r\n\r\n:dk_actids\r\n\r\nset allapps=\r\nif %_wmic% EQU 1 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='%1') get ID /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkapp=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1''').Get()).ID ^| %% {echo ('ID='+$_)}\" %nul6%')\"\r\n%chkapp% do (if defined allapps (call set \"allapps=!allapps! %%a\") else (call set \"allapps=%%a\"))\r\nexit /b\r\n\r\n::  Get Edition list\r\n\r\n:ced_edilist\r\n\r\nif %_wmic% EQU 1 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('\"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL) get LicenseFamily /VALUE\" %nul6%')\"\r\nif %_wmic% EQU 0 set \"chkedi=for /f \"tokens=2 delims==\" %%a in ('%psc% \"(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}\" %nul6%')\"\r\n%chkedi% do call set \"_wtarget= !_wtarget! %%a \"\r\nexit /b\r\n\r\n::  Check wmic.exe\r\n\r\n:dk_ckeckwmic\r\n\r\nif %winbuild% LSS 9200 (set _wmic=1&exit /b)\r\nset _wmic=0\r\nfor %%# in (wmic.exe) do @if not \"%%~$PATH:#\"==\"\" (\r\ncmd /c \"wmic path Win32_ComputerSystem get CreationClassName /value\" %nul2% | find /i \"computersystem\" %nul1% && set _wmic=1\r\n)\r\nexit /b\r\n\r\n::  Show info for potential script stuck scenario\r\n\r\n:dk_sppissue\r\n\r\nsc start %_slser% %nul%\r\nset spperror=%errorlevel%\r\n\r\nif %spperror% NEQ 1056 if %spperror% NEQ 0 (\r\n%eline%\r\necho sc start %_slser% [Error Code: %spperror%]\r\nif %spperror% EQU 1053 (\r\ncall :dk_color %Blue% \"Reboot your machine using the restart option and try again.\"\r\ncall :dk_color %Blue% \"If it still does not work, go back to Main Menu, select Troubleshoot and run Fix WPA Registry option.\"\r\n)\r\n)\r\n\r\necho:\r\n%psc% \"$job = Start-Job { (Get-WmiObject -Query 'SELECT * FROM %sps%').Version }; if (-not (Wait-Job $job -Timeout 30)) {write-host '%_slser% is not working correctly. Check this webpage for help - %mas%troubleshoot'}\"\r\nexit /b\r\n\r\n::  Common lines used in PowerShell reflection code\r\n\r\n:dk_reflection\r\n\r\nset ref=$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1);\r\nset ref=%ref% $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False);\r\nset ref=%ref% $TypeBuilder = $ModuleBuilder.DefineType(0);\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check pending reboot flags\r\n\r\n:ced_rebootflag\r\n\r\nset rebootreq=\r\nreg query \"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending\" %nul% && set rebootreq=1\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired\" %nul% && set rebootreq=1\r\n\r\nif defined rebootreq (\r\n%eline%\r\necho Pending reboot flags found.\r\necho:\r\necho Make sure Windows is fully updated, restart the system and try again.\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Get Product Key from pkeyhelper.dll for future new editions\r\n::  It works on Windows 10 1803 (17134) and later builds.\r\n\r\n:k_pkey\r\n\r\ncall :dk_reflection\r\n\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SkuGetProductKeyForEdition', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [String], [String].MakeByRefType(), [String].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = ''; [void]$TypeBuilder.CreateType()::SkuGetProductKeyForEdition(%1, %2, [ref]$out, [ref]$null); $out\r\n\r\nset pkey=\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (set pkey=%%a)\r\nexit /b\r\n\r\n::  Get channel name for the key which was extracted from pkeyhelper.dll\r\n\r\n:k_pkeychannel\r\n\r\nset k=%1\r\nset m=[Runtime.InteropServices.Marshal]\r\nset p=%SysPath%\\spp\\tokens\\pkeyconfig\\pkeyconfig.xrm-ms\r\n\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('PidGenX', 'pidgenx.dll', 'Public, Static', 1, [int], @([String], [String], [String], [int], [IntPtr], [IntPtr], [IntPtr]), 1, 3);\r\nset d1=%d1% $r = [byte[]]::new(0x04F8); $r[0] = 0xF8; $r[1] = 0x04; $f = %m%::AllocHGlobal(0x04F8); %m%::Copy($r, 0, $f, 0x04F8);\r\nset d1=%d1% [void]$TypeBuilder.CreateType()::PidGenX('%k%', '%p%', '00000', 0, 0, 0, $f); %m%::Copy($f, $r, 0, 0x04F8); %m%::FreeHGlobal($f); [Text.Encoding]::Unicode.GetString($r, 1016, 128)\r\n\r\nset pkeychannel=\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (set pkeychannel=%%a)\r\nexit /b\r\n\r\n:ced_windowskey\r\n\r\nfor %%# in (pkeyhelper.dll) do @if \"%%~$PATH:#\"==\"\" exit /b\r\nfor %%# in (%keyflow%) do (\r\ncall :k_pkey %targetSKU% '%%#'\r\nif defined pkey call :k_pkeychannel !pkey!\r\nif /i \"!pkeychannel!\"==\"%%#\" (\r\nset key=!pkey!\r\nexit /b\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:ced_targetSKU\r\n\r\nset k=%1\r\nset targetSKU=\r\nfor %%# in (pkeyhelper.dll) do @if \"%%~$PATH:#\"==\"\" exit /b\r\n\r\ncall :dk_reflection\r\n\r\nset d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionIdFromName', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3);\r\nset d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionIdFromName('%k%', [ref]$out); $out\r\n\r\nfor /f %%a in ('%psc% \"%d1%\"') do if not errorlevel 1 (set targetSKU=%%a)\r\nif \"%targetSKU%\"==\"0\" set targetSKU=\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_color\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3'\r\n) else if not exist %ps% (\r\necho %~3\r\n)\r\nexit /b\r\n\r\n:dk_color2\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[%~3%~4%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'\r\n) else if not exist %ps% (\r\necho %~3 %~6\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_done\r\n\r\necho:\r\nif %_unattended%==1 timeout /t 2 & exit /b\r\n\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 exit /b\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  https://github.com/asdcorp/Set-WindowsCbsEdition\r\n\r\n:cbsxml:[\r\nparam (\r\n    [Parameter()]\r\n    [String]$SetEdition,\r\n\r\n    [Parameter()]\r\n    [Switch]$GetTargetEditions,\r\n\r\n    [Parameter()]\r\n    [Switch]$StageCurrent\r\n)\r\n\r\nfunction Get-AssemblyIdentity {\r\n    param (\r\n        [String]$PackageName\r\n    )\r\n\r\n    $PackageName = [String]$PackageName\r\n    $packageData = ($PackageName -split '~')\r\n\r\n    if($packageData[3] -eq '') {\r\n        $packageData[3] = 'neutral'\r\n    }\r\n\r\n    return \"<assemblyIdentity name=`\"$($packageData[0])`\" version=`\"$($packageData[4])`\" processorArchitecture=`\"$($packageData[2])`\" publicKeyToken=`\"$($packageData[1])`\" language=`\"$($packageData[3])`\" />\"\r\n}\r\n\r\nfunction Get-SxsName {\r\n    param (\r\n        [String]$PackageName\r\n    )\r\n\r\n    $name = ($PackageName -replace '[^A-z0-9\\-\\._]', '')\r\n\r\n    if($name.Length -gt 40) {\r\n        $name = ($name[0..18] -join '') + '\\.\\.' + ($name[-19..-1] -join '')\r\n    }\r\n\r\n    return $name.ToLower()\r\n}\r\n\r\nfunction Find-EditionXmlInSxs {\r\n    param (\r\n        [String]$Edition\r\n    )\r\n\r\n    $candidates = @($Edition, 'Client', 'Server')\r\n    $winSxs = $Env:SystemRoot + '\\WinSxS'\r\n    $allInSxs = Get-ChildItem -Path $winSxs | select Name\r\n\r\n    foreach($candidate in $candidates) {\r\n        $name = Get-SxsName -PackageName \"Microsoft-Windows-Editions-$candidate\"\r\n        $packages = $allInSxs | where name -Match ('^.*_'+$name+'_31bf3856ad364e35')\r\n\r\n        if($packages.Length -eq 0) {\r\n            continue\r\n        }\r\n\r\n        $package = $packages[-1].Name\r\n        $testPath = $winSxs + \"\\$package\\\" + $Edition + 'Edition.xml'\r\n\r\n        if(Test-Path -Path $testPath -PathType Leaf) {\r\n            return $testPath\r\n        }\r\n    }\r\n\r\n    return $null\r\n}\r\n\r\nfunction Find-EditionXml {\r\n    param (\r\n        [String]$Edition\r\n    )\r\n\r\n    $servicingEditions = $Env:SystemRoot + '\\servicing\\Editions'\r\n    $editionXml = $Edition + 'Edition.xml'\r\n\r\n    $editionXmlInServicing = $servicingEditions + '\\' + $editionXml\r\n\r\n    if(Test-Path -Path $editionXmlInServicing -PathType Leaf) {\r\n        return $editionXmlInServicing\r\n    }\r\n\r\n    return Find-EditionXmlInSxs -Edition $Edition\r\n}\r\n\r\nfunction Write-UpgradeCandidates {\r\n    param (\r\n        [HashTable]$InstallCandidates\r\n    )\r\n\r\n    $editionCount = 0\r\n    Write-Host 'Editions that can be upgraded to:'\r\n    foreach($candidate in $InstallCandidates.Keys) {\r\n        Write-Host \"Target Edition : $candidate\"\r\n        $editionCount++\r\n    }\r\n\r\n    if($editionCount -eq 0) {\r\n        Write-Host '(no editions are available)'\r\n    }\r\n}\r\n\r\nfunction Write-UpgradeXml {\r\n    param (\r\n        [Array]$RemovalCandidates,\r\n        [Array]$InstallCandidates,\r\n        [Boolean]$Stage\r\n    )\r\n\r\n    $removeAction = 'remove'\r\n    if($Stage) {\r\n        $removeAction = 'stage'\r\n    }\r\n\r\n    Write-Output '<?xml version=\"1.0\"?>'\r\n    Write-Output '<unattend xmlns=\"urn:schemas-microsoft-com:unattend\">'\r\n    Write-Output '<servicing>'\r\n\r\n    foreach($package in $InstallCandidates) {\r\n        Write-Output '<package action=\"install\">'\r\n        Write-Output (Get-AssemblyIdentity -PackageName $package)\r\n        Write-Output '</package>'\r\n    }\r\n\r\n    foreach($package in $RemovalCandidates) {\r\n        Write-Output \"<package action=`\"$removeAction`\">\"\r\n        Write-Output (Get-AssemblyIdentity -PackageName $package)\r\n        Write-Output '</package>'\r\n    }\r\n\r\n    Write-Output '</servicing>'\r\n    Write-Output '</unattend>'\r\n}\r\n\r\nfunction Write-Usage {\r\n    Get-Help $script:MyInvocation.MyCommand.Path -detailed\r\n}\r\n\r\n$version = '1.0'\r\n$getTargetsParam = $GetTargetEditions.IsPresent\r\n$stageCurrentParam = $StageCurrent.IsPresent\r\n\r\nif($SetEdition -eq '' -and ($false -eq $getTargetsParam)) {\r\n    Write-Usage\r\n    Exit 1\r\n}\r\n\r\n$removalCandidates = @();\r\n$installCandidates = @{};\r\n\r\n$packages = Get-ChildItem -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\Packages' | select Name | where { $_.name -match '^.*\\\\Microsoft-Windows-.*Edition~' }\r\nforeach($package in $packages) {\r\n    $state = (Get-ItemProperty -Path \"Registry::$($package.Name)\").CurrentState\r\n    $packageName = ($package.Name -split '\\\\')[-1]\r\n    $packageEdition = (($packageName -split 'Edition~')[0] -split 'Microsoft-Windows-')[-1]\r\n\r\n    if($state -eq 0x40) {\r\n        if($null -eq $installCandidates[$packageEdition]) {\r\n            $installCandidates[$packageEdition] = @()\r\n        }\r\n\r\n        if($false -eq ($installCandidates[$packageEdition] -contains $packageName)) {\r\n            $installCandidates[$packageEdition] = $installCandidates[$packageEdition] + @($packageName)\r\n        }\r\n    }\r\n\r\n    if((($state -eq 0x50) -or ($state -eq 0x70)) -and ($false -eq ($removalCandidates -contains $packageName))) {\r\n        $removalCandidates = $removalCandidates + @($packageName)\r\n    }\r\n}\r\n\r\nif($getTargetsParam) {\r\n    Write-UpgradeCandidates -InstallCandidates $installCandidates\r\n    Exit\r\n}\r\n\r\nif($false -eq ($installCandidates.Keys -contains $SetEdition)) {\r\n    Write-Error \"The system cannot be upgraded to `\"$SetEdition`\"\"\r\n    Exit 1\r\n}\r\n\r\n$xmlPath = $Env:SystemRoot + '\\Temp' + '\\CbsUpgrade.xml'\r\n\r\nWrite-UpgradeXml -RemovalCandidates $removalCandidates `\r\n    -InstallCandidates $installCandidates[$SetEdition] `\r\n    -Stage $stageCurrentParam >$xmlPath\r\n\r\n$editionXml = Find-EditionXml -Edition $SetEdition\r\nif($null -eq $editionXml) {\r\n    Write-Warning 'Unable to find edition specific settings XML. Proceeding without it...'\r\n}\r\n\r\nWrite-Host 'Starting the upgrade process. This may take a while...'\r\n\r\nDISM.EXE /English /NoRestart /Online /Apply-Unattend:$xmlPath\r\n$dismError = $LASTEXITCODE\r\n\r\nRemove-Item -Path $xmlPath -Force\r\n\r\nif(($dismError -ne 0) -and ($dismError -ne 3010)) {\r\n    Write-Error 'Failed to upgrade to the target edition'\r\n    Exit $dismError\r\n}\r\n\r\nif($null -ne $editionXml) {\r\n    $destination = $Env:SystemRoot + '\\' + $SetEdition + '.xml'\r\n    Copy-Item -Path $editionXml -Destination $destination\r\n\r\n    DISM.EXE /English /NoRestart /Online /Apply-Unattend:$editionXml\r\n    $dismError = $LASTEXITCODE\r\n\r\n    if(($dismError -ne 0) -and ($dismError -ne 3010)) {\r\n        Write-Error 'Failed to apply edition specific settings'\r\n        Exit $dismError\r\n    }\r\n}\r\n\r\nRestart-Computer\r\n:cbsxml:]\r\n\r\n::========================================================================================================================================\r\n\r\n::  Change edition using DISM API\r\n::  Thanks to Alex (aka may, ave9858)\r\n\r\n:dismapi:[\r\nparam (\r\n    [Parameter()]\r\n    [String]$TargetEdition,\r\n\r\n    [Parameter()]\r\n    [String]$Key\r\n)\r\n\r\n$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)\r\n$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)\r\n$TB = $ModuleBuilder.DefineType(0)\r\n\r\n[void]$TB.DefinePInvokeMethod('DismInitialize', 'DismApi.dll', 22, 1, [int], @([int], [IntPtr], [IntPtr]), 1, 3)\r\n[void]$TB.DefinePInvokeMethod('DismOpenSession', 'DismApi.dll', 22, 1, [int], @([String], [IntPtr], [IntPtr], [UInt32].MakeByRefType()), 1, 3)\r\n[void]$TB.DefinePInvokeMethod('_DismSetEdition', 'DismApi.dll', 22, 1, [int], @([UInt32], [String], [String], [IntPtr], [IntPtr], [IntPtr]), 1, 3)\r\n$Dism = $TB.CreateType()\r\n\r\n[void]$Dism::DismInitialize(2, 0, 0)\r\n$Session = 0\r\n[void]$Dism::DismOpenSession('DISM_{53BFAE52-B167-4E2F-A258-0A37B57FF845}', 0, 0, [ref]$Session)\r\nif (!$Dism::_DismSetEdition($Session, \"$TargetEdition\", \"$Key\", 0, 0, 0)) {\r\n    Restart-Computer\r\n}\r\n:dismapi:]\r\n\r\n::========================================================================================================================================\r\n\r\n::  1st column = Generic Retail/OEM/MAK/GVLK Key\r\n::  2nd column = Key Type\r\n::  3rd column = WMI Edition ID\r\n::  4th column = Version name incase same Edition ID is used in different OS versions with different key\r\n::  Separator  = _\r\n\r\n::  For Windows 10/11 editions, HWID key is listed where ever possible, in Server versions, KMS key is listed where ever possible.\r\n::  For Windows, generic keys are mentioned till 22000 and for Server, generic keys are mentioned till 17763, later ones are extracted from the pkeyhelper.dll\r\n\r\n:changeeditiondata\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" (\r\nif %winbuild% GTR 17763 exit /b\r\n) else (\r\nif %winbuild% GEQ 22000 exit /b\r\n)\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*CorEdition~*.mum\" (set Cor=Cor) else (set Cor=)\r\n\r\nset w=\r\nfor %%# in (\r\nXGVPP-NMH47-7TTHJ-W3FW7-8HV%w%2C__OEM:NONSLP_Enterprise\r\nD6RD9-D4N8T-RT9QX-YW6YT-FCW%w%WJ______Retail_Starter\r\n3V6Q6-NQXCX-V8YXR-9QCYV-QPF%w%CT__Volume:MAK_EnterpriseN\r\n3NFXW-2T27M-2BDW6-4GHRV-68X%w%RX______Retail_StarterN\r\nVK7JG-NPHTM-C97JM-9MPGT-3V6%w%6T______Retail_Professional\r\n2B87N-8KFHP-DKV6R-Y2C8J-PKC%w%KT______Retail_ProfessionalN\r\n4CPRK-NM3K3-X6XXQ-RXX86-WXC%w%HW______Retail_CoreN\r\nN2434-X9D7W-8PF6X-8DV9T-8TY%w%MD______Retail_CoreCountrySpecific\r\nBT79Q-G7N6G-PGBYW-4YWX6-6F4%w%BT______Retail_CoreSingleLanguage\r\nYTMG3-N6DKC-DKB77-7M9GH-8HV%w%X7______Retail_Core\r\nXKCNC-J26Q9-KFHD2-FKTHY-KD7%w%2Y__OEM:NONSLP_PPIPro\r\nYNMGQ-8RYV3-4PGQ3-C8XTP-7CF%w%BY______Retail_Education\r\n84NGF-MHBT6-FXBX8-QWJK7-DRR%w%8H______Retail_EducationN\r\nKCNVH-YKWX8-GJJB9-H9FDT-6F7%w%W2__Volume:MAK_EnterpriseS_VB\r\n43TBQ-NH92J-XKTM7-KT3KK-P39%w%PB__OEM:NONSLP_EnterpriseS_RS5\r\nNK96Y-D9CD8-W44CQ-R8YTK-DYJ%w%WX__OEM:NONSLP_EnterpriseS_RS1\r\nFWN7H-PF93Q-4GGP8-M8RF3-MDW%w%WW__OEM:NONSLP_EnterpriseS_TH\r\nRQFNW-9TPM3-JQ73T-QV4VQ-DV9%w%PT__Volume:MAK_EnterpriseSN_VB\r\nM33WV-NHY3C-R7FPM-BQGPT-239%w%PG__Volume:MAK_EnterpriseSN_RS5\r\n2DBW3-N2PJG-MVHW3-G7TDK-9HK%w%R4__Volume:MAK_EnterpriseSN_RS1\r\nNTX6B-BRYC2-K6786-F6MVQ-M7V%w%2X__Volume:MAK_EnterpriseSN_TH\r\nG3KNM-CHG6T-R36X3-9QDG6-8M8%w%K9______Retail_ProfessionalSingleLanguage\r\nHNGCC-Y38KG-QVK8D-WMWRK-X86%w%VK______Retail_ProfessionalCountrySpecific\r\nDXG7C-N36C4-C4HTG-X4T3X-2YV%w%77______Retail_ProfessionalWorkstation\r\nWYPNQ-8C467-V2W6J-TX4WX-WT2%w%RQ______Retail_ProfessionalWorkstationN\r\n8PTT6-RNW4C-6V7J2-C2D3X-MHB%w%PB______Retail_ProfessionalEducation\r\nGJTYN-HDMQY-FRR76-HVGC7-QPF%w%8P______Retail_ProfessionalEducationN\r\nC4NTJ-CX6Q2-VXDMR-XVKGM-F9D%w%JC__Volume:MAK_EnterpriseG\r\n46PN6-R9BK9-CVHKB-HWQ9V-MBJ%w%Y8__Volume:MAK_EnterpriseGN\r\nNJCF7-PW8QT-3324D-688JX-2YV%w%66______Retail_ServerRdsh\r\nXQQYW-NFFMW-XJPBH-K8732-CKF%w%FD______OEM:DM_IoTEnterprise\r\nQPM6N-7J2WJ-P88HH-P3YRH-YY7%w%4H__OEM:NONSLP_IoTEnterpriseS\r\nK9VKN-3BGWV-Y624W-MCRMQ-BHD%w%CD______Retail_CloudEditionN\r\nKY7PN-VR6RX-83W6Y-6DDYQ-T6R%w%4W______Retail_CloudEdition\r\nV3WVW-N2PV2-CGWC3-34QGF-VMJ%w%2C______Retail_Cloud\r\nNH9J3-68WK7-6FB93-4K3DF-DJ4%w%F6______Retail_CloudN\r\n2HN6V-HGTM8-6C97C-RK67V-JQP%w%FD______Retail_CloudE\r\nWC2BQ-8NRM3-FDDYY-2BFGV-KHK%w%QY_Volume:GVLK_ServerStandard%Cor%_RS1\r\nCB7KF-BWN84-R7R2Y-793K2-8XD%w%DG_Volume:GVLK_ServerDatacenter%Cor%_RS1\r\nJCKRF-N37P4-C2D82-9YXRT-4M6%w%3B_Volume:GVLK_ServerSolution_RS1\r\nQN4C6-GBJD2-FB422-GHWJK-GJG%w%2R_Volume:GVLK_ServerCloudStorage_RS1\r\nVP34G-4NPPG-79JTQ-864T4-R3M%w%QX_Volume:GVLK_ServerAzureCor_RS1\r\n9JQNQ-V8HQ6-PKB8H-GGHRY-R62%w%H6______Retail_ServerAzureNano_RS1\r\nVN8D3-PR82H-DB6BJ-J9P4M-92F%w%6J______Retail_ServerStorageStandard_RS1\r\n48TQX-NVK3R-D8QR3-GTHHM-8FH%w%XC______Retail_ServerStorageWorkgroup_RS1\r\n2HXDN-KRXHB-GPYC7-YCKFJ-7FV%w%DG_Volume:GVLK_ServerDatacenterACor_RS3\r\nPTXN8-JFHJM-4WC78-MPCBR-9W4%w%KR_Volume:GVLK_ServerStandardACor_RS3\r\n) do (\r\nfor /f \"tokens=1-4 delims=_\" %%A in (\"%%#\") do if /i %targetedition%==%%C (\r\n\r\nif not defined key (\r\nset 4th=%%D\r\nif not defined 4th (\r\nset \"key=%%A\" & set \"_chan=%%B\"\r\n) else (\r\necho \"%branch%\" | find /i \"%%D\" %nul1% && (set \"key=%%A\" & set \"_chan=%%B\")\r\n)\r\n)\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n:: Leave empty line below\r\n"
  },
  {
    "path": "MAS/Separate-Files-Version/Check_Activation_Status.cmd",
    "content": "@echo off\r\n\r\n\r\n::============================================================================\r\n::\r\n::  Check-Activation-Status\r\n::  Written by @abbodi1406\r\n::\r\n::============================================================================\r\n\r\n\r\n::  Set Environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\nset \"ps=%SysPath%\\WindowsPowerShell\\v1.0\\powershell.exe\"\r\nset \"_psc=%ps% -nop -c\"\r\nset \"_err===== ERROR ====\"\r\nset _pwsh=1\r\nif not exist %ps% set _pwsh=0\r\ncmd /c \"%_psc% \"$ExecutionContext.SessionState.LanguageMode\"\" | find /i \"FullLanguage\" 1>nul || (set _pwsh=0)\r\nif %_pwsh% equ 0 (\r\necho %_err%\r\ncmd /c \"%_psc% \"$ExecutionContext.SessionState.LanguageMode\"\"\r\necho Windows PowerShell is not working correctly.\r\necho It is required for this script to work.\r\ngoto :E_Exit\r\n)\r\nset \"_batf=%~f0\"\r\nset \"_batp=%_batf:'=''%\"\r\nsetlocal EnableDelayedExpansion\r\n%_psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':sppmgr\\:.*';. ([scriptblock]::Create($f[1]))\"\r\n\r\n:E_Exit\r\necho.\r\necho Press 0 key to exit.\r\nchoice /c 0 /n\r\nexit /b\r\n\r\n:sppmgr:\r\nparam (\r\n    [Parameter()]\r\n    [switch]\r\n    $All,\r\n    [Parameter()]\r\n    [switch]\r\n    $Dlv,\r\n    [Parameter()]\r\n    [switch]\r\n    $IID,\r\n    [Parameter()]\r\n    [switch]\r\n    $Pass\r\n)\r\n\r\nfunction CONOUT($strObj)\r\n{\r\n\tOut-Host -Input $strObj\r\n}\r\n\r\nfunction ExitScript($ExitCode = 0)\r\n{\r\n\tExit $ExitCode\r\n}\r\n\r\nif (-Not $PSVersionTable) {\r\n\t\"==== ERROR ====`r`n\"\r\n\t\"Windows PowerShell 1.0 is not supported by this script.\"\r\n\tExitScript 1\r\n}\r\n\r\nif ($ExecutionContext.SessionState.LanguageMode.value__ -NE 0) {\r\n\t\"==== ERROR ====`r`n\"\r\n\t\"Windows PowerShell is not running in Full Language Mode.\"\r\n\tExitScript 1\r\n}\r\n\r\n$winbuild = 1\r\ntry {\r\n\t$winbuild = [System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"$env:SystemRoot\\System32\\kernel32.dll\").FileBuildPart\r\n} catch {\r\n\t$winbuild = [int]([wmi]'Win32_OperatingSystem=@').BuildNumber\r\n}\r\n\r\nif ($winbuild -EQ 1) {\r\n\t\"==== ERROR ====`r`n\"\r\n\t\"Could not detect Windows build.\"\r\n\tExitScript 1\r\n}\r\n\r\nif ($winbuild -LT 2600) {\r\n\t\"==== ERROR ====`r`n\"\r\n\t\"This build of Windows is not supported by this script.\"\r\n\tExitScript 1\r\n}\r\n\r\nif ($All.IsPresent)\r\n{\r\n\t$isAll = {CONOUT \"`r\"}\r\n\t$noAll = {$null}\r\n}\r\nelse\r\n{\r\n\t$isAll = {$null}\r\n\t$noAll = {CONOUT \"`r\"}\r\n}\r\n$Dlv = $Dlv.IsPresent\r\n$IID = $IID.IsPresent -Or $Dlv.IsPresent\r\n\r\n$NT6 = $winbuild -GE 6000\r\n$NT7 = $winbuild -GE 7600\r\n$NT8 = $winbuild -GE 9200\r\n$NT9 = $winbuild -GE 9600\r\n\r\n$Admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)\r\n\r\n$line2 = \"============================================================\"\r\n$line3 = \"____________________________________________________________\"\r\n\r\nfunction echoWindows\r\n{\r\n\tCONOUT \"$line2\"\r\n\tCONOUT \"===                   Windows Status                     ===\"\r\n\tCONOUT \"$line2\"\r\n\t& $noAll\r\n}\r\n\r\nfunction echoOffice\r\n{\r\n\tif ($doMSG -EQ 0) {\r\n\t\treturn\r\n\t}\r\n\r\n\t& $isAll\r\n\tCONOUT \"$line2\"\r\n\tCONOUT \"===                   Office Status                      ===\"\r\n\tCONOUT \"$line2\"\r\n\t& $noAll\r\n\r\n\t$script:doMSG = 0\r\n}\r\n\r\nfunction strGetRegistry($strKey, $strName)\r\n{\r\n\ttry {\r\n\t\treturn [Microsoft.Win32.Registry]::GetValue($strKey, $strName, $null)\r\n\t} catch {\r\n\t\treturn $null\r\n\t}\r\n}\r\n\r\nfunction CheckOhook\r\n{\r\n\t$ohook = 0\r\n\t$paths = \"${env:ProgramFiles}\", \"${env:ProgramW6432}\", \"${env:ProgramFiles(x86)}\"\r\n\r\n\t15, 16 | foreach `\r\n\t{\r\n\t\t$A = $_; $paths | foreach `\r\n\t\t{\r\n\t\t\tif (Test-Path \"$($_)$('\\Microsoft Office\\Office')$($A)$('\\sppc*dll')\") {$ohook = 1}\r\n\t\t}\r\n\t}\r\n\r\n\t\"System\", \"SystemX86\" | foreach `\r\n\t{\r\n\t\t$A = $_; \"Office 15\", \"Office\" | foreach `\r\n\t\t{\r\n\t\t\t$B = $_; $paths | foreach `\r\n\t\t\t{\r\n\t\t\t\tif (Test-Path \"$($_)$('\\Microsoft ')$($B)$('\\root\\vfs\\')$($A)$('\\sppc*dll')\") {$ohook = 1}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tif ($ohook -EQ 0) {\r\n\t\treturn\r\n\t}\r\n\r\n\t& $isAll\r\n\tCONOUT \"$line2\"\r\n\tCONOUT \"===                Office Ohook Status                   ===\"\r\n\tCONOUT \"$line2\"\r\n\t$host.UI.WriteLine('Yellow', 'Black', \"`r`nOhook for permanent Office activation is installed.`r`nYou can ignore the below mentioned Office activation status.\")\r\n\t& $noAll\r\n}\r\n\r\n#region SSSS\r\nfunction BoolToWStr($bVal) {\r\n\t(\"TRUE\", \"FALSE\")[!$bVal]\r\n}\r\n\r\nfunction InitializePInvoke($LaDll, $bOffice) {\r\n\t$LaName = [IO.Path]::GetFileNameWithoutExtension($LaDll)\r\n\t$SLApp = $NT7 -Or $bOffice -Or ($LaName -EQ 'sppc' -And [Diagnostics.FileVersionInfo]::GetVersionInfo(\"$SysPath\\sppc.dll\").FilePrivatePart -GE 16501)\r\n\t$Win32 = $null\r\n\r\n\t$Marshal = [System.Runtime.InteropServices.Marshal]\r\n\t$Module = [AppDomain]::CurrentDomain.DefineDynamicAssembly(($LaName+\"_Assembly\"), 'Run').DefineDynamicModule(($LaName+\"_Module\"), $False)\r\n\t$Class = $Module.DefineType(($LaName+\"_Methods\"), 'Public, Abstract, Sealed, BeforeFieldInit', [Object], 0)\r\n\r\n\t$Class.DefinePInvokeMethod('SLClose', $LaDll, 22, 1, [Int32], @([IntPtr]), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLOpen', $LaDll, 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGenerateOfflineInstallationId', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGetSLIDList', $LaDll, 22, 1, [Int32], @([IntPtr], [UInt32], [Guid].MakeByRefType(), [UInt32], [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGetLicensingStatusInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [Guid].MakeByRefType(), [IntPtr], [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGetPKeyInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGetProductSkuInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t$Class.DefinePInvokeMethod('SLGetServiceInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\tif ($SLApp) {\r\n\t\t$Class.DefinePInvokeMethod('SLGetApplicationInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t}\r\n\tif ($bOffice) {\r\n\t\t$Win32 = $Class.CreateType()\r\n\t\treturn\r\n\t}\r\n\tif ($NT6) {\r\n\t\t$Class.DefinePInvokeMethod('SLGetWindowsInformation', 'slc.dll', 22, 1, [Int32], @([String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t\t$Class.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 22, 1, [Int32], @([String], [UInt32].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t\t$Class.DefinePInvokeMethod('SLIsGenuineLocal', 'slwga.dll', 22, 1, [Int32], @([Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr]), 1, 3).SetImplementationFlags(128)\r\n\t}\r\n\tif ($NT7) {\r\n\t\t$Class.DefinePInvokeMethod('SLIsWindowsGenuineLocal', 'slc.dll', 'Public, Static', 'Standard', [Int32], @([UInt32].MakeByRefType()), 'Winapi', 'Unicode').SetImplementationFlags('PreserveSig')\r\n\t}\r\n\r\n\tif ($DllSubscription) {\r\n\t\t$Class.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)\r\n\t\t$Struct = $Class.DefineNestedType('SubStatus', 'NestedPublic, SequentialLayout, Sealed, BeforeFieldInit', [ValueType], 0)\r\n\t\t[void]$Struct.DefineField('dwEnabled', [UInt32], 'Public')\r\n\t\t[void]$Struct.DefineField('dwSku', [UInt32], 6)\r\n\t\t[void]$Struct.DefineField('dwState', [UInt32], 6)\r\n\t\t$SubStatus = $Struct.CreateType()\r\n\t}\r\n\r\n\t$Win32 = $Class.CreateType()\r\n}\r\n\r\nfunction SlGetInfoIID($SkuId)\r\n{\r\n\t$bData = 0\r\n\r\n\tif ($Win32::SLGenerateOfflineInstallationId(\r\n\t\t$hSLC,\r\n\t\t[ref][Guid]$SkuId,\r\n\t\t[ref]$bData\r\n\t))\r\n\t{\r\n\t\treturn $null\r\n\t}\r\n\telse\r\n\t{\r\n\t\treturn $Marshal::PtrToStringUni($bData)\r\n\t}\r\n}\r\n\r\nfunction SlReturnData($hrRet, $tData, $cData, $bData) {\r\n\tif ($hrRet -NE 0 -Or $cData -EQ 0)\r\n\t{\r\n\t\treturn $null\r\n\t}\r\n\tif ($tData -EQ 1)\r\n\t{\r\n\t\treturn $Marshal::PtrToStringUni($bData)\r\n\t}\r\n\telseif ($tData -EQ 4)\r\n\t{\r\n\t\treturn $Marshal::ReadInt32($bData)\r\n\t}\r\n\telseif ($tData -EQ 3 -And $cData -EQ 8)\r\n\t{\r\n\t\treturn $Marshal::ReadInt64($bData)\r\n\t}\r\n\telse\r\n\t{\r\n\t\treturn $null\r\n\t}\r\n}\r\n\r\nfunction SlGetInfoPKey($PkeyId, $Value)\r\n{\r\n\t$tData = 0\r\n\t$cData = 0\r\n\t$bData = 0\r\n\r\n\t$hrRet = $Win32::SLGetPKeyInformation(\r\n\t\t$hSLC,\r\n\t\t[ref][Guid]$PkeyId,\r\n\t\t$Value,\r\n\t\t[ref]$tData,\r\n\t\t[ref]$cData,\r\n\t\t[ref]$bData\r\n\t)\r\n\r\n\treturn SlReturnData $hrRet $tData $cData $bData\r\n}\r\n\r\nfunction SlGetInfoSku($SkuId, $Value)\r\n{\r\n\t$tData = 0\r\n\t$cData = 0\r\n\t$bData = 0\r\n\r\n\t$hrRet = $Win32::SLGetProductSkuInformation(\r\n\t\t$hSLC,\r\n\t\t[ref][Guid]$SkuId,\r\n\t\t$Value,\r\n\t\t[ref]$tData,\r\n\t\t[ref]$cData,\r\n\t\t[ref]$bData\r\n\t)\r\n\r\n\treturn SlReturnData $hrRet $tData $cData $bData\r\n}\r\n\r\nfunction SlGetInfoApp($AppId, $Value)\r\n{\r\n\t$tData = 0\r\n\t$cData = 0\r\n\t$bData = 0\r\n\r\n\t$hrRet = $Win32::SLGetApplicationInformation(\r\n\t\t$hSLC,\r\n\t\t[ref][Guid]$AppId,\r\n\t\t$Value,\r\n\t\t[ref]$tData,\r\n\t\t[ref]$cData,\r\n\t\t[ref]$bData\r\n\t)\r\n\r\n\treturn SlReturnData $hrRet $tData $cData $bData\r\n}\r\n\r\nfunction SlGetInfoService($Value)\r\n{\r\n\t$tData = 0\r\n\t$cData = 0\r\n\t$bData = 0\r\n\r\n\t$hrRet = $Win32::SLGetServiceInformation(\r\n\t\t$hSLC,\r\n\t\t$Value,\r\n\t\t[ref]$tData,\r\n\t\t[ref]$cData,\r\n\t\t[ref]$bData\r\n\t)\r\n\r\n\treturn SlReturnData $hrRet $tData $cData $bData\r\n}\r\n\r\nfunction SlGetInfoSvcApp($strApp, $Value)\r\n{\r\n\tif ($SLApp)\r\n\t{\r\n\t\treturn SlGetInfoApp $strApp $Value\r\n\t}\r\n\telse\r\n\t{\r\n\t\treturn SlGetInfoService $Value\r\n\t}\r\n}\r\n\r\nfunction SlGetInfoLicensing($AppId, $SkuId)\r\n{\r\n\t$dwStatus = 0\r\n\t$dwGrace = 0\r\n\t$hrReason = 0\r\n\t$qwValidity = 0\r\n\r\n\t$cStatus = 0\r\n\t$pStatus = 0\r\n\r\n\t$hrRet = $Win32::SLGetLicensingStatusInformation(\r\n\t\t$hSLC,\r\n\t\t[ref][Guid]$AppId,\r\n\t\t[ref][Guid]$SkuId,\r\n\t\t0,\r\n\t\t[ref]$cStatus,\r\n\t\t[ref]$pStatus\r\n\t)\r\n\r\n\tif ($hrRet -NE 0 -Or $cStatus -EQ 0)\r\n\t{\r\n\t\treturn\r\n\t}\r\n\r\n\t[IntPtr]$ppStatus = [Int64]$pStatus + [Int64]40 * ($cStatus - 1)\r\n\t$dwStatus = $Marshal::ReadInt32($ppStatus, 16)\r\n\t$dwGrace = $Marshal::ReadInt32($ppStatus, 20)\r\n\t$hrReason = $Marshal::ReadInt32($ppStatus, 28)\r\n\t$qwValidity = $Marshal::ReadInt64($ppStatus, 32)\r\n\r\n\tif ($dwStatus -EQ 3)\r\n\t{\r\n\t\t$dwStatus = 5\r\n\t}\r\n\tif ($dwStatus -EQ 2)\r\n\t{\r\n\t\tif ($hrReason -EQ 0x4004F00D)\r\n\t\t{\r\n\t\t\t$dwStatus = 3\r\n\t\t}\r\n\t\telseif ($hrReason -EQ 0x4004F065)\r\n\t\t{\r\n\t\t\t$dwStatus = 4\r\n\t\t}\r\n\t\telseif ($hrReason -EQ 0x4004FC06)\r\n\t\t{\r\n\t\t\t$dwStatus = 6\r\n\t\t}\r\n\t}\r\n\r\n\treturn\r\n}\r\n\r\nfunction SlGetInfoSLID($AppId)\r\n{\r\n\t$cReturnIds = 0\r\n\t$pReturnIds = 0\r\n\r\n\t$hrRet = $Win32::SLGetSLIDList(\r\n\t\t$hSLC,\r\n\t\t0,\r\n\t\t[ref][Guid]$AppId,\r\n\t\t1,\r\n\t\t[ref]$cReturnIds,\r\n\t\t[ref]$pReturnIds\r\n\t)\r\n\r\n\tif ($hrRet -NE 0 -Or $cReturnIds -EQ 0)\r\n\t{\r\n\t\treturn\r\n\t}\r\n\r\n\t$a1List = @()\r\n\t$a2List = @()\r\n\t$a3List = @()\r\n\t$a4List = @()\r\n\r\n\tforeach ($i in 0..($cReturnIds - 1))\r\n\t{\r\n\t\t$bytes = New-Object byte[] 16\r\n\t\t$Marshal::Copy([Int64]$pReturnIds + [Int64]16 * $i, $bytes, 0, 16)\r\n\t\t$actid = ([Guid]$bytes).Guid\r\n\t\t$gPPK = SlGetInfoSku $actid \"pkeyId\"\r\n\t\t$gAdd = SlGetInfoSku $actid \"DependsOn\"\r\n\t\tif ($All.IsPresent) {\r\n\t\t\tif ($null -EQ $gPPK -And $null -NE $gAdd) { $a1List += @{id = $actid; pk = $null; ex = $true} }\r\n\t\t\tif ($null -EQ $gPPK -And $null -EQ $gAdd) { $a2List += @{id = $actid; pk = $null; ex = $false} }\r\n\t\t}\r\n\t\tif ($null -NE $gPPK -And $null -NE $gAdd) { $a3List += @{id = $actid; pk = $gPPK; ex = $true} }\r\n\t\tif ($null -NE $gPPK -And $null -EQ $gAdd) { $a4List += @{id = $actid; pk = $gPPK; ex = $false} }\r\n\t}\r\n\r\n\treturn ($a1List + $a2List + $a3List + $a4List)\r\n}\r\n\r\nfunction DetectSubscription {\r\n\ttry\r\n\t{\r\n\t\t$objSvc = New-Object PSObject\r\n\t\t$wmiSvc = [wmisearcher]\"SELECT SubscriptionType, SubscriptionStatus, SubscriptionEdition, SubscriptionExpiry FROM SoftwareLicensingService\"\r\n\t\t$wmiSvc.Options.Rewindable = $false\r\n\t\t$wmiSvc.Get() | select -Expand Properties -EA 0 | foreach { $objSvc | Add-Member 8 $_.Name $_.Value }\r\n\t\t$wmiSvc.Dispose()\r\n\t}\r\n\tcatch\r\n\t{\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($null -EQ $objSvc.SubscriptionType -Or $objSvc.SubscriptionType -EQ 120) {\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($objSvc.SubscriptionType -EQ 1) {\r\n\t\t$SubMsgType = \"Device based\"\r\n\t} else {\r\n\t\t$SubMsgType = \"User based\"\r\n\t}\r\n\r\n\tif ($objSvc.SubscriptionStatus -EQ 120) {\r\n\t\t$SubMsgStatus = \"Expired\"\r\n\t} elseif ($objSvc.SubscriptionStatus -EQ 100) {\r\n\t\t$SubMsgStatus = \"Disabled\"\r\n\t} elseif ($objSvc.SubscriptionStatus -EQ 1) {\r\n\t\t$SubMsgStatus = \"Active\"\r\n\t} else {\r\n\t\t$SubMsgStatus = \"Not active\"\r\n\t}\r\n\r\n\t$SubMsgExpiry = \"Unknown\"\r\n\tif ($objSvc.SubscriptionExpiry) {\r\n\t\tif ($objSvc.SubscriptionExpiry.Contains(\"unspecified\") -EQ $false) {$SubMsgExpiry = $objSvc.SubscriptionExpiry}\r\n\t}\r\n\r\n\t$SubMsgEdition = \"Unknown\"\r\n\tif ($objSvc.SubscriptionEdition) {\r\n\t\tif ($objSvc.SubscriptionEdition.Contains(\"UNKNOWN\") -EQ $false) {$SubMsgEdition = $objSvc.SubscriptionEdition}\r\n\t}\r\n\r\n\tCONOUT \"`nSubscription information:\"\r\n\tCONOUT \"    Type   : $SubMsgType\"\r\n\tCONOUT \"    Status : $SubMsgStatus\"\r\n\tCONOUT \"    Edition: $SubMsgEdition\"\r\n\tCONOUT \"    Expiry : $SubMsgExpiry\"\r\n}\r\n\r\nfunction DetectAdbaClient\r\n{\r\n\t$propADBA | foreach { set $_ (SlGetInfoSku $licID $_) }\r\n\tDetectActType\r\n\tCONOUT \"`nAD Activation client information:\"\r\n\tCONOUT \"    Object Name: $ADActivationObjectName\"\r\n\tCONOUT \"    Domain Name: $ADActivationObjectDN\"\r\n\tCONOUT \"    CSVLK Extended PID: $ADActivationCsvlkPID\"\r\n\tCONOUT \"    CSVLK Activation ID: $ADActivationCsvlkSkuID\"\r\n}\r\n\r\nfunction DetectAvmClient\r\n{\r\n\t$propAVMA | foreach { set $_ (SlGetInfoSku $licID $_) }\r\n\tCONOUT \"`nAutomatic VM Activation client information:\"\r\n\tif (-Not [String]::IsNullOrEmpty($InheritedActivationId)) {\r\n\t\tCONOUT \"    Guest IAID: $InheritedActivationId\"\r\n\t} else {\r\n\t\tCONOUT \"    Guest IAID: Not Available\"\r\n\t}\r\n\tif (-Not [String]::IsNullOrEmpty($InheritedActivationHostMachineName)) {\r\n\t\tCONOUT \"    Host machine name: $InheritedActivationHostMachineName\"\r\n\t} else {\r\n\t\tCONOUT \"    Host machine name: Not Available\"\r\n\t}\r\n\tif (-Not [String]::IsNullOrEmpty($InheritedActivationHostDigitalPid2)) {\r\n\t\tCONOUT \"    Host Digital PID2: $InheritedActivationHostDigitalPid2\"\r\n\t} else {\r\n\t\tCONOUT \"    Host Digital PID2: Not Available\"\r\n\t}\r\n\tif ($InheritedActivationActivationTime) {\r\n\t\t$IAAT = [DateTime]::FromFileTime($InheritedActivationActivationTime).ToString('yyyy-MM-dd hh:mm:ss tt')\r\n\t\tCONOUT \"    Activation time: $IAAT\"\r\n\t} else {\r\n\t\tCONOUT \"    Activation time: Not Available\"\r\n\t}\r\n}\r\n\r\nfunction DetectKmsHost\r\n{\r\n\t$IsKeyManagementService = SlGetInfoSvcApp $strApp 'IsKeyManagementService'\r\n\tif (-Not $IsKeyManagementService) {\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($Vista -Or $NT5) {\r\n\t\t$regk = $SLKeyPath\r\n\t} elseif ($strSLP -EQ $oslp) {\r\n\t\t$regk = $OPKeyPath\r\n\t} else {\r\n\t\t$regk = $SPKeyPath\r\n\t}\r\n\t$KMSListening = strGetRegistry $regk \"KeyManagementServiceListeningPort\"\r\n\t$KMSPublishing = strGetRegistry $regk \"DisableDnsPublishing\"\r\n\t$KMSPriority = strGetRegistry $regk \"EnableKmsLowPriority\"\r\n\r\n\tif (-Not $KMSListening) {$KMSListening = 1688}\r\n\tif (-Not $KMSPublishing) {$KMSPublishing = \"TRUE\"} else {$KMSPublishing = BoolToWStr (!$KMSPublishing)}\r\n\tif (-Not $KMSPriority) {$KMSPriority = \"FALSE\"} else {$KMSPriority = BoolToWStr $KMSPriority}\r\n\r\n\tif ($KMSPublishing -EQ \"TRUE\") {$KMSPublishing = \"Enabled\"} else {$KMSPublishing = \"Disabled\"}\r\n\tif ($KMSPriority -EQ \"TRUE\") {$KMSPriority = \"Low\"} else {$KMSPriority = \"Normal\"}\r\n\r\n\tif ($SLApp)\r\n\t{\r\n\t\t$propKMSServer | foreach { set $_ (SlGetInfoApp $strApp $_) }\r\n\t}\r\n\telse\r\n\t{\r\n\t\t$propKMSServer | foreach { set $_ (SlGetInfoService $_) }\r\n\t}\r\n\r\n\t$KMSRequests = $KeyManagementServiceTotalRequests\r\n\t$NoRequests = ($null -EQ $KMSRequests) -Or ($KMSRequests -EQ -1) -Or ($KMSRequests -EQ 4294967295)\r\n\r\n\tCONOUT \"`nKey Management Service host information:\"\r\n\tCONOUT \"    Current count: $KeyManagementServiceCurrentCount\"\r\n\tCONOUT \"    Listening on Port: $KMSListening\"\r\n\tCONOUT \"    DNS publishing: $KMSPublishing\"\r\n\tCONOUT \"    KMS priority: $KMSPriority\"\r\n\tif ($NoRequests) {\r\n\t\treturn\r\n\t}\r\n\tCONOUT \"`nKey Management Service cumulative requests received from clients:\"\r\n\tCONOUT \"    Total: $KeyManagementServiceTotalRequests\"\r\n\tCONOUT \"    Failed: $KeyManagementServiceFailedRequests\"\r\n\tCONOUT \"    Unlicensed: $KeyManagementServiceUnlicensedRequests\"\r\n\tCONOUT \"    Licensed: $KeyManagementServiceLicensedRequests\"\r\n\tCONOUT \"    Initial grace period: $KeyManagementServiceOOBGraceRequests\"\r\n\tCONOUT \"    Expired or Hardware out of tolerance: $KeyManagementServiceOOTGraceRequests\"\r\n\tCONOUT \"    Non-genuine grace period: $KeyManagementServiceNonGenuineGraceRequests\"\r\n\tif ($null -NE $KeyManagementServiceNotificationRequests) {CONOUT \"    Notification: $KeyManagementServiceNotificationRequests\"}\r\n}\r\n\r\nfunction DetectActType\r\n{\r\n\t$VLType = strGetRegistry ($SPKeyPath + '\\' + $strApp + '\\' + $licID) \"VLActivationType\"\r\n\tif ($null -EQ $VLType) {$VLType = strGetRegistry ($SPKeyPath + '\\' + $strApp) \"VLActivationType\"}\r\n\tif ($null -EQ $VLType) {$VLType = strGetRegistry ($SPKeyPath) \"VLActivationType\"}\r\n\tif ($null -EQ $VLType -Or $VLType -GT 3) {$VLType = 0}\r\n\tif ($null -NE $VLType) {CONOUT \"Configured Activation Type: $($VLActTypes[$VLType])\"}\r\n}\r\n\r\nfunction DetectKmsClient\r\n{\r\n\tif ($win8) {DetectActType}\r\n\tCONOUT \"`r\"\r\n\tif ($LicenseStatus -NE 1) {\r\n\t\tCONOUT \"Please activate the product in order to update KMS client information values.\"\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($NT7 -Or $strSLP -EQ $oslp) {\r\n\t\t$propKMSClient | foreach { set $_ (SlGetInfoSku $licID $_) }\r\n\t\tif ($strSLP -EQ $oslp) {$regk = $OPKeyPath} else {$regk = $SPKeyPath}\r\n\t\t$KMSCaching = strGetRegistry $regk \"DisableKeyManagementServiceHostCaching\"\r\n\t\tif (-Not $KMSCaching) {$KMSCaching = \"TRUE\"} else {$KMSCaching = BoolToWStr (!$KMSCaching)}\r\n\t}\r\n\r\n\t\"ClientMachineID\" | foreach { set $_ (SlGetInfoService $_) }\r\n\r\n\tif ($Vista) {\r\n\t\t$propKMSVista | foreach { set $_ (SlGetInfoService $_) }\r\n\t\t$KeyManagementServicePort = strGetRegistry $SLKeyPath \"KeyManagementServicePort\"\r\n\t\t$DiscoveredKeyManagementServiceName = strGetRegistry $NSKeyPath \"DiscoveredKeyManagementServiceName\"\r\n\t\t$DiscoveredKeyManagementServicePort = strGetRegistry $NSKeyPath \"DiscoveredKeyManagementServicePort\"\r\n\t}\r\n\r\n\tif ([String]::IsNullOrEmpty($KeyManagementServiceName)) {\r\n\t\t$KmsReg = $null\r\n\t} else {\r\n\t\tif (-Not $KeyManagementServicePort) {$KeyManagementServicePort = 1688}\r\n\t\t$KmsReg = \"Registered KMS machine name: ${KeyManagementServiceName}:${KeyManagementServicePort}\"\r\n\t}\r\n\r\n\tif ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceName)) {\r\n\t\t$KmsDns = \"DNS auto-discovery: KMS name not available\"\r\n\t\tif ($Vista -And -Not $Admin) {$KmsDns = \"DNS auto-discovery: Run the script as administrator to retrieve info\"}\r\n\t} else {\r\n\t\tif (-Not $DiscoveredKeyManagementServicePort) {$DiscoveredKeyManagementServicePort = 1688}\r\n\t\t$KmsDns = \"KMS machine name from DNS: ${DiscoveredKeyManagementServiceName}:${DiscoveredKeyManagementServicePort}\"\r\n\t}\r\n\r\n\tif ($null -NE $KMSCaching) {\r\n\t\tif ($KMSCaching -EQ \"TRUE\") {$KMSCaching = \"Enabled\"} else {$KMSCaching = \"Disabled\"}\r\n\t}\r\n\r\n\tif ($strSLP -EQ $wslp -And $NT9) {\r\n\t\tif ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceIpAddress)) {\r\n\t\t\t$DiscoveredKeyManagementServiceIpAddress = \"not available\"\r\n\t\t}\r\n\t}\r\n\r\n\tCONOUT \"Key Management Service client information:\"\r\n\tCONOUT \"    Client Machine ID (CMID): $ClientMachineID\"\r\n\tif ($null -EQ $KmsReg) {\r\n\t\tCONOUT \"    $KmsDns\"\r\n\t\tCONOUT \"    Registered KMS machine name: KMS name not available\"\r\n\t} else {\r\n\t\tCONOUT \"    $KmsReg\"\r\n\t}\r\n\tif ($null -NE $DiscoveredKeyManagementServiceIpAddress) {CONOUT \"    KMS machine IP address: $DiscoveredKeyManagementServiceIpAddress\"}\r\n\tCONOUT \"    KMS machine extended PID: $CustomerPID\"\r\n\tCONOUT \"    Activation interval: $VLActivationInterval minutes\"\r\n\tCONOUT \"    Renewal interval: $VLRenewalInterval minutes\"\r\n\tif ($null -NE $KMSCaching) {CONOUT \"    KMS host caching: $KMSCaching\"}\r\n\tif (-Not [String]::IsNullOrEmpty($KeyManagementServiceLookupDomain)) {CONOUT \"    KMS SRV record lookup domain: $KeyManagementServiceLookupDomain\"}\r\n}\r\n\r\nfunction GetResult($strSLP, $strApp, $entry)\r\n{\r\n\t$licID = $entry.id\r\n\t$propPrd | foreach { set $_ (SlGetInfoSku $licID $_) }\r\n\t. SlGetInfoLicensing $strApp $licID\r\n\t$LicenseStatus = $dwStatus\r\n\t$LicReason = $hrReason\r\n\t$EvaluationEndDate = $qwValidity\r\n\t$gprMnt = $dwGrace\r\n\r\n\t$pkid = $entry.pk\r\n\t$isPPK = $null -NE $pkid\r\n\r\n\t$add_on = $Name.IndexOf(\"add-on for\", 5)\r\n\tif ($add_on -NE -1) {\r\n\t\t$Name = $Name.Substring(0, $add_on + 7)\r\n\t}\r\n\r\n\t$licPHN = \"empty\"\r\n\tif ($Dlv -Or $All.IsPresent) {\r\n\t\t$licPHN = SlGetInfoSku $licID \"msft:sl/EUL/PHONE/PUBLIC\"\r\n\t}\r\n\r\n\tif ($LicenseStatus -EQ 0 -And !$isPPK) {\r\n\t\t& $isAll\r\n\t\tCONOUT \"Name: $Name\"\r\n\t\tCONOUT \"Description: $Description\"\r\n\t\tCONOUT \"Activation ID: $licID\"\r\n\t\tCONOUT \"License Status: Unlicensed\"\r\n\t\tif ($licPHN -NE \"empty\") {\r\n\t\t\t$gPHN = [String]::IsNullOrEmpty($licPHN) -NE $true\r\n\t\t\tCONOUT \"Phone activatable: $($gPHN.ToString())\"\r\n\t\t}\r\n\t\treturn\r\n\t}\r\n\r\n\t$winID = ($strApp -EQ $winApp)\r\n\t$winPR = ($winID -And -Not $entry.ex)\r\n\t$Vista = ($winID -And $NT6 -And -Not $NT7)\r\n\t$NT5 = ($strSLP -EQ $wslp -And $winbuild -LT 6001)\r\n\t$win8 = ($strSLP -EQ $wslp -And $NT8)\r\n\t$reapp = (\"Windows\", \"App\")[!$winID]\r\n\t$prmnt = (\"machine\", \"product\")[!$winPR]\r\n\r\n\tif ($Description.Contains(\"VOLUME_KMSCLIENT\")) {$cKmsClient = 1; $actTag = \"Volume\"}\r\n\tif ($Description.Contains(\"TIMEBASED_\")) {$cTblClient = 1; $actTag = \"Timebased\"}\r\n\tif ($Description.Contains(\"VIRTUAL_MACHINE_ACTIVATION\")) {$cAvmClient = 1; $actTag = \"Automatic VM\"}\r\n\tif ($null -EQ $cKmsClient -And $Description.Contains(\"VOLUME_KMS\")) {$cKmsServer = 1}\r\n\r\n\t$gprDay = [Math]::Round($gprMnt/1440)\r\n\t$_xpr = \"\"\r\n\t$inGrace = $false\r\n\tif ($gprMnt -GT 0) {\r\n\t\t$_xpr = [DateTime]::Now.AddMinutes($gprMnt).ToString('yyyy-MM-dd hh:mm:ss tt')\r\n\t\t$inGrace = $true\r\n\t}\r\n\r\n\t$LicenseMsg = \"Time remaining: $gprMnt minute(s) ($gprDay day(s))\"\r\n\tif ($LicenseStatus -EQ 0) {\r\n\t\t$LicenseInf = \"Unlicensed\"\r\n\t\t$LicenseMsg = $null\r\n\t}\r\n\tif ($LicenseStatus -EQ 1) {\r\n\t\t$LicenseInf = \"Licensed\"\r\n\t\tif ($gprMnt -EQ 0) {\r\n\t\t\t$LicenseMsg = $null\r\n\t\t\t$ExpireMsg = \"The $prmnt is permanently activated.\"\r\n\t\t} else {\r\n\t\t\t$LicenseMsg = \"$actTag activation expiration: $gprMnt minute(s) ($gprDay day(s))\"\r\n\t\t\tif ($inGrace) {$ExpireMsg = \"$actTag activation will expire $_xpr\"}\r\n\t\t}\r\n\t}\r\n\tif ($LicenseStatus -EQ 2) {\r\n\t\t$LicenseInf = \"Initial grace period\"\r\n\t\tif ($inGrace) {$ExpireMsg = \"$LicenseInf ends $_xpr\"}\r\n\t}\r\n\tif ($LicenseStatus -EQ 3) {\r\n\t\t$LicenseInf = \"Additional grace period (KMS license expired or hardware out of tolerance)\"\r\n\t\tif ($inGrace) {$ExpireMsg = \"Additional grace period ends $_xpr\"}\r\n\t}\r\n\tif ($LicenseStatus -EQ 4) {\r\n\t\t$LicenseInf = \"Non-genuine grace period\"\r\n\t\tif ($inGrace) {$ExpireMsg = \"$LicenseInf ends $_xpr\"}\r\n\t}\r\n\tif ($LicenseStatus -EQ 5 -And -Not $NT5) {\r\n\t\t$LicenseReason = '0x{0:X}' -f $LicReason\r\n\t\t$LicenseInf = \"Notification\"\r\n\t\t$LicenseMsg = \"Notification Reason: $LicenseReason\"\r\n\t\tif ($LicenseReason -EQ \"0xC004F00F\") {if ($null -NE $cKmsClient) {$LicenseMsg = $LicenseMsg + \" (KMS license expired).\"} else {$LicenseMsg = $LicenseMsg + \" (hardware out of tolerance).\"}}\r\n\t\tif ($LicenseReason -EQ \"0xC004F200\") {$LicenseMsg = $LicenseMsg + \" (non-genuine).\"}\r\n\t\tif ($LicenseReason -EQ \"0xC004F009\" -Or $LicenseReason -EQ \"0xC004F064\") {$LicenseMsg = $LicenseMsg + \" (grace time expired).\"}\r\n\t}\r\n\tif ($LicenseStatus -GT 5 -Or ($LicenseStatus -GT 4 -And $NT5)) {\r\n\t\t$LicenseInf = \"Unknown\"\r\n\t\t$LicenseMsg = $null\r\n\t}\r\n\tif ($LicenseStatus -EQ 6 -And -Not $Vista -And -Not $NT5) {\r\n\t\t$LicenseInf = \"Extended grace period\"\r\n\t\tif ($inGrace) {$ExpireMsg = \"$LicenseInf ends $_xpr\"}\r\n\t}\r\n\r\n\tif ($isPPK) {\r\n\t\t$propPkey | foreach { set $_ (SlGetInfoPKey $pkid $_) }\r\n\t}\r\n\r\n\tif ($winPR -And $isPPK -And -Not $NT8) {\r\n\t\t$uxd = SlGetInfoSku $licID 'UXDifferentiator'\r\n\t\t$script:primary += @{\r\n\t\t\taid = $licID;\r\n\t\t\tppk = $PartialProductKey;\r\n\t\t\tchn = $Channel;\r\n\t\t\tlst = $LicenseStatus;\r\n\t\t\tlcr = $LicReason;\r\n\t\t\tged = $gprMnt;\r\n\t\t\tevl = $EvaluationEndDate;\r\n\t\t\tdff = $uxd\r\n\t\t}\r\n\t}\r\n\r\n\tif ($IID -And $isPPK) {\r\n\t\t$OfflineInstallationId = SlGetInfoIID $licID\r\n\t}\r\n\r\n\tif ($Dlv) {\r\n\t\tif ($win8)\r\n\t\t{\r\n\t\t\t$RemainingSkuReArmCount = SlGetInfoSku $licID 'RemainingRearmCount'\r\n\t\t\t$RemainingAppReArmCount = SlGetInfoApp $strApp 'RemainingRearmCount'\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tif (($winID -And $NT7) -Or $strSLP -EQ $oslp)\r\n\t\t\t{\r\n\t\t\t\t$RemainingSLReArmCount = SlGetInfoApp $strApp 'RemainingRearmCount'\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t$RemainingSLReArmCount = SlGetInfoService 'RearmCount'\r\n\t\t\t}\r\n\t\t}\r\n\t\tif ($null -EQ $TrustedTime)\r\n\t\t{\r\n\t\t\t$TrustedTime = SlGetInfoSvcApp $strApp 'TrustedTime'\r\n\t\t}\r\n\t}\r\n\r\n\t& $isAll\r\n\tCONOUT \"Name: $Name\"\r\n\tCONOUT \"Description: $Description\"\r\n\tCONOUT \"Activation ID: $licID\"\r\n\tif ($null -NE $DigitalPID) {CONOUT \"Extended PID: $DigitalPID\"}\r\n\tif ($null -NE $DigitalPID2 -And $Dlv) {CONOUT \"Product ID: $DigitalPID2\"}\r\n\tif ($null -NE $OfflineInstallationId -And $IID) {CONOUT \"Installation ID: $OfflineInstallationId\"}\r\n\tif ($null -NE $Channel) {CONOUT \"Product Key Channel: $Channel\"}\r\n\tif ($null -NE $PartialProductKey) {CONOUT \"Partial Product Key: $PartialProductKey\"}\r\n\tCONOUT \"License Status: $LicenseInf\"\r\n\tif ($null -NE $LicenseMsg) {CONOUT \"$LicenseMsg\"}\r\n\tif ($LicenseStatus -NE 0 -And $EvaluationEndDate) {\r\n\t\t$EED = [DateTime]::FromFileTimeUtc($EvaluationEndDate).ToString('yyyy-MM-dd hh:mm:ss tt')\r\n\t\tCONOUT \"Evaluation End Date: $EED UTC\"\r\n\t}\r\n\tif ($LicenseStatus -NE 1 -And $licPHN -NE \"empty\") {\r\n\t\t$gPHN = [String]::IsNullOrEmpty($licPHN) -NE $true\r\n\t\tCONOUT \"Phone activatable: $($gPHN.ToString())\"\r\n\t}\r\n\tif ($Dlv) {\r\n\t\tif ($null -NE $RemainingSLReArmCount) {\r\n\t\t\tCONOUT \"Remaining $reapp rearm count: $RemainingSLReArmCount\"\r\n\t\t}\r\n\t\tif ($null -NE $RemainingSkuReArmCount) {\r\n\t\t\tCONOUT \"Remaining $reapp rearm count: $RemainingAppReArmCount\"\r\n\t\t\tCONOUT \"Remaining SKU rearm count: $RemainingSkuReArmCount\"\r\n\t\t}\r\n\t\tif ($LicenseStatus -NE 0 -And $TrustedTime) {\r\n\t\t\t$TTD = [DateTime]::FromFileTime($TrustedTime).ToString('yyyy-MM-dd hh:mm:ss tt')\r\n\t\t\tCONOUT \"Trusted time: $TTD\"\r\n\t\t}\r\n\t}\r\n\tif (!$isPPK) {\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($win8 -And $VLActivationType -EQ 1) {\r\n\t\tDetectAdbaClient\r\n\t\t$cKmsClient = $null\r\n\t}\r\n\r\n\tif ($winID -And $null -NE $cAvmClient) {\r\n\t\tDetectAvmClient\r\n\t}\r\n\r\n\t$chkSub = ($winPR -And $isSub)\r\n\r\n\t$chkSLS = ($null -NE $cKmsClient -Or $null -NE $cKmsServer -Or $chkSub)\r\n\r\n\tif (!$chkSLS) {\r\n\t\tif ($null -NE $ExpireMsg) {CONOUT \"`n    $ExpireMsg\"}\r\n\t\treturn\r\n\t}\r\n\r\n\tif ($null -NE $cKmsClient) {\r\n\t\tDetectKmsClient\r\n\t}\r\n\r\n\tif ($null -NE $cKmsServer) {\r\n\t\tif ($null -NE $ExpireMsg) {CONOUT \"`n    $ExpireMsg\"}\r\n\t\tDetectKmsHost\r\n\t} else {\r\n\t\tif ($null -NE $ExpireMsg) {CONOUT \"`n    $ExpireMsg\"}\r\n\t}\r\n\r\n\tif ($chkSub) {\r\n\t\tDetectSubscription\r\n\t}\r\n\r\n}\r\n\r\nfunction ParseList($strSLP, $strApp, $arrList)\r\n{\r\n\tforeach ($entry in $arrList)\r\n\t{\r\n\t\tGetResult $strSLP $strApp $entry\r\n\t\tCONOUT \"$line3\"\r\n\t\t& $noAll\r\n\t}\r\n}\r\n#endregion\r\n\r\n#region vNextDiag\r\nif ($PSVersionTable.PSVersion.Major -Lt 3)\r\n{\r\n\tfunction ConvertFrom-Json\r\n\t{\r\n\t\t[CmdletBinding()]\r\n\t\tParam(\r\n\t\t\t[Parameter(ValueFromPipeline=$true)][Object]$item\r\n\t\t)\r\n\t\t[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Web.Extensions\")\r\n\t\t$psjs = New-Object System.Web.Script.Serialization.JavaScriptSerializer\r\n\t\tReturn ,$psjs.DeserializeObject($item)\r\n\t}\r\n\tfunction ConvertTo-Json\r\n\t{\r\n\t\t[CmdletBinding()]\r\n\t\tParam(\r\n\t\t\t[Parameter(ValueFromPipeline=$true)][Object]$item\r\n\t\t)\r\n\t\t[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Web.Extensions\")\r\n\t\t$psjs = New-Object System.Web.Script.Serialization.JavaScriptSerializer\r\n\t\tReturn $psjs.Serialize($item)\r\n\t}\r\n}\r\n\r\nfunction PrintModePerPridFromRegistry\r\n{\r\n\t$vNextRegkey = \"HKCU:\\SOFTWARE\\Microsoft\\Office\\16.0\\Common\\Licensing\\LicensingNext\"\r\n\t$vNextPrids = Get-Item -Path $vNextRegkey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty 'property' -ErrorAction SilentlyContinue | Where-Object -FilterScript {$_.ToLower() -like \"*retail\" -or $_.ToLower() -like \"*volume\"}\r\n\tIf ($null -Eq $vNextPrids)\r\n\t{\r\n\t\tCONOUT \"`nNo registry keys found.\"\r\n\t\tReturn\r\n\t}\r\n\tCONOUT \"`r\"\r\n\t$vNextPrids | ForEach `\r\n\t{\r\n\t\t$mode = (Get-ItemProperty -Path $vNextRegkey -Name $_).$_\r\n\t\tSwitch ($mode)\r\n\t\t{\r\n\t\t\t2 { $mode = \"vNext\"; Break }\r\n\t\t\t3 { $mode = \"Device\"; Break }\r\n\t\t\tDefault { $mode = \"Legacy\"; Break }\r\n\t\t}\r\n\t\tCONOUT \"$_ = $mode\"\r\n\t}\r\n}\r\n\r\nfunction PrintSharedComputerLicensing\r\n{\r\n\t$scaRegKey = \"HKLM:\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration\"\r\n\t$scaValue = Get-ItemProperty -Path $scaRegKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty \"SharedComputerLicensing\" -ErrorAction SilentlyContinue\r\n\t$scaRegKey2 = \"HKLM:\\SOFTWARE\\Microsoft\\Office\\16.0\\Common\\Licensing\"\r\n\t$scaValue2 = Get-ItemProperty -Path $scaRegKey2 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty \"SharedComputerLicensing\" -ErrorAction SilentlyContinue\r\n\t$scaPolicyKey = \"HKLM:\\SOFTWARE\\Policies\\Microsoft\\Office\\16.0\\Common\\Licensing\"\r\n\t$scaPolicyValue = Get-ItemProperty -Path $scaPolicyKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty \"SharedComputerLicensing\" -ErrorAction SilentlyContinue\r\n\tIf ($null -Eq $scaValue -And $null -Eq $scaValue2 -And $null -Eq $scaPolicyValue)\r\n\t{\r\n\t\tCONOUT \"`nNo registry keys found.\"\r\n\t\tReturn\r\n\t}\r\n\t$scaModeValue = $scaValue -Or $scaValue2 -Or $scaPolicyValue\r\n\tIf ($scaModeValue -Eq 0)\r\n\t{\r\n\t\t$scaMode = \"Disabled\"\r\n\t}\r\n\tIf ($scaModeValue -Eq 1)\r\n\t{\r\n\t\t$scaMode = \"Enabled\"\r\n\t}\r\n\tCONOUT \"`nStatus: $scaMode\"\r\n\tCONOUT \"`r\"\r\n\t$tokenFiles = $null\r\n\t$tokenPath = \"${env:LOCALAPPDATA}\\Microsoft\\Office\\16.0\\Licensing\"\r\n\tIf (Test-Path $tokenPath)\r\n\t{\r\n\t\t$tokenFiles = Get-ChildItem -Path $tokenPath -Filter \"*authString*\" -Recurse | Where-Object { !$_.PSIsContainer }\r\n\t}\r\n\tIf ($null -Eq $tokenFiles -Or $tokenFiles.Length -Eq 0)\r\n\t{\r\n\t\tCONOUT \"No tokens found.\"\r\n\t\tReturn\r\n\t}\r\n\t$tokenFiles | ForEach `\r\n\t{\r\n\t\t$tokenParts = (Get-Content -Encoding Unicode -Path $_.FullName).Split('_')\r\n\t\t$output = New-Object PSObject\r\n\t\t$output | Add-Member 8 'ACID' $tokenParts[0];\r\n\t\t$output | Add-Member 8 'User' $tokenParts[3];\r\n\t\t$output | Add-Member 8 'NotBefore' $tokenParts[4];\r\n\t\t$output | Add-Member 8 'NotAfter' $tokenParts[5];\r\n\t\tWrite-Output $output\r\n\t}\r\n}\r\n\r\nfunction PrintLicensesInformation\r\n{\r\n\tParam(\r\n\t\t[ValidateSet(\"NUL\", \"Device\")]\r\n\t\t[String]$mode\r\n\t)\r\n\tIf ($mode -Eq \"NUL\")\r\n\t{\r\n\t\t$licensePath = \"${env:LOCALAPPDATA}\\Microsoft\\Office\\Licenses\"\r\n\t}\r\n\tElseIf ($mode -Eq \"Device\")\r\n\t{\r\n\t\t$licensePath = \"${env:PROGRAMDATA}\\Microsoft\\Office\\Licenses\"\r\n\t}\r\n\t$licenseFiles = $null\r\n\tIf (Test-Path $licensePath)\r\n\t{\r\n\t\t$licenseFiles = Get-ChildItem -Path $licensePath -Recurse | Where-Object { !$_.PSIsContainer }\r\n\t}\r\n\tIf ($null -Eq $licenseFiles -Or $licenseFiles.Length -Eq 0)\r\n\t{\r\n\t\tCONOUT \"`nNo licenses found.\"\r\n\t\tReturn\r\n\t}\r\n\t$licenseFiles | ForEach `\r\n\t{\r\n\t\t$license = (Get-Content -Encoding Unicode $_.FullName | ConvertFrom-Json).License\r\n\t\t$decodedLicense = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($license)) | ConvertFrom-Json\r\n\t\t$licenseType = $decodedLicense.LicenseType\r\n\t\tIf ($null -Ne $decodedLicense.ExpiresOn)\r\n\t\t{\r\n\t\t\t$expiry = [System.DateTime]::Parse($decodedLicense.ExpiresOn, $null, 'AdjustToUniversal')\r\n\t\t}\r\n\t\tElse\r\n\t\t{\r\n\t\t\t$expiry = New-Object System.DateTime\r\n\t\t}\r\n\t\t$licenseState = \"Grace\"\r\n\t\tIf ((Get-Date) -Gt (Get-Date $decodedLicense.Metadata.NotAfter))\r\n\t\t{\r\n\t\t\t$licenseState = \"RFM\"\r\n\t\t}\r\n\t\tElseIf ((Get-Date) -Lt (Get-Date $expiry))\r\n\t\t{\r\n\t\t\t$licenseState = \"Licensed\"\r\n\t\t}\r\n\t\t$output = New-Object PSObject\r\n\t\t$output | Add-Member 8 'File' $_.PSChildName;\r\n\t\t$output | Add-Member 8 'Version' $_.Directory.Name;\r\n\t\t$output | Add-Member 8 'Type' \"User|${licenseType}\";\r\n\t\t$output | Add-Member 8 'Product' $decodedLicense.ProductReleaseId;\r\n\t\t$output | Add-Member 8 'Acid' $decodedLicense.Acid;\r\n\t\tIf ($mode -Eq \"Device\") { $output | Add-Member 8 'DeviceId' $decodedLicense.Metadata.DeviceId; }\r\n\t\t$output | Add-Member 8 'LicenseState' $licenseState;\r\n\t\t$output | Add-Member 8 'EntitlementStatus' $decodedLicense.Status;\r\n\t\t$output | Add-Member 8 'EntitlementExpiration' (\"N/A\", $decodedLicense.ExpiresOn)[!($null -eq $decodedLicense.ExpiresOn)];\r\n\t\t$output | Add-Member 8 'ReasonCode' (\"N/A\", $decodedLicense.ReasonCode)[!($null -eq $decodedLicense.ReasonCode)];\r\n\t\t$output | Add-Member 8 'NotBefore' $decodedLicense.Metadata.NotBefore;\r\n\t\t$output | Add-Member 8 'NotAfter' $decodedLicense.Metadata.NotAfter;\r\n\t\t$output | Add-Member 8 'NextRenewal' $decodedLicense.Metadata.RenewAfter;\r\n\t\t$output | Add-Member 8 'TenantId' (\"N/A\", $decodedLicense.Metadata.TenantId)[!($null -eq $decodedLicense.Metadata.TenantId)];\r\n\t\t#$output.PSObject.Properties | foreach { $ht = @{} } { $ht[$_.Name] = $_.Value } { $output = $ht | ConvertTo-Json }\r\n\t\tWrite-Output $output\r\n\t}\r\n}\r\n\r\nfunction vNextDiagRun\r\n{\r\n\t$fNUL = ([IO.Directory]::Exists(\"${env:LOCALAPPDATA}\\Microsoft\\Office\\Licenses\")) -and ([IO.Directory]::GetFiles(\"${env:LOCALAPPDATA}\\Microsoft\\Office\\Licenses\", \"*\", 1).Length -GT 0)\r\n\t$fDev = ([IO.Directory]::Exists(\"${env:PROGRAMDATA}\\Microsoft\\Office\\Licenses\")) -and ([IO.Directory]::GetFiles(\"${env:PROGRAMDATA}\\Microsoft\\Office\\Licenses\", \"*\", 1).Length -GT 0)\r\n\t$rPID = $null -NE (GP \"HKCU:\\SOFTWARE\\Microsoft\\Office\\16.0\\Common\\Licensing\\LicensingNext\" -EA 0 | select -Expand 'property' -EA 0 | where -Filter {$_.ToLower() -like \"*retail\" -or $_.ToLower() -like \"*volume\"})\r\n\t$rSCA = $null -NE (GP \"HKLM:\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration\" -EA 0 | select -Expand \"SharedComputerLicensing\" -EA 0)\r\n\t$rSCL = $null -NE (GP \"HKLM:\\SOFTWARE\\Microsoft\\Office\\16.0\\Common\\Licensing\" -EA 0 | select -Expand \"SharedComputerLicensing\" -EA 0)\r\n\r\n\tif (($fNUL -Or $fDev -Or $rPID -Or $rSCA -Or $rSCL) -EQ $false) {\r\n\t\tReturn\r\n\t}\r\n\r\n\t& $isAll\r\n\tCONOUT \"$line2\"\r\n\tCONOUT \"===                  Office vNext Status                 ===\"\r\n\tCONOUT \"$line2\"\r\n\tCONOUT \"`n========== Mode per ProductReleaseId ==========\"\r\n\tPrintModePerPridFromRegistry\r\n\tCONOUT \"`n========== Shared Computer Licensing ==========\"\r\n\tPrintSharedComputerLicensing\r\n\tCONOUT \"`n========== vNext licenses ===========\"\r\n\tPrintLicensesInformation -Mode \"NUL\"\r\n\tCONOUT \"`n========== Device licenses ==========\"\r\n\tPrintLicensesInformation -Mode \"Device\"\r\n\tCONOUT \"$line3\"\r\n\tCONOUT \"`r\"\r\n}\r\n#endregion\r\n\r\n#region clic\r\n\r\n<#\r\n;;; Source: https://github.com/asdcorp/clic\r\n;;; Powershell port: abbodi1406\r\n\r\nCopyright 2023 asdcorp\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of\r\nthis software and associated documentation files (the \"Software\"), to deal in\r\nthe Software without restriction, including without limitation the rights to\r\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r\nthe Software, and to permit persons to whom the Software is furnished to do so,\r\nsubject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n#>\r\n\r\nfunction InitializeDigitalLicenseCheck {\r\n\t$CAB = [System.Reflection.Emit.CustomAttributeBuilder]\r\n\r\n\t$ICom = $Module.DefineType('EUM.IEUM', 'Public, Interface, Abstract, Import')\r\n\t$ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.ComImportAttribute].GetConstructor(@()), @()))\r\n\t$ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.GuidAttribute].GetConstructor(@([String])), @('F2DCB80D-0670-44BC-9002-CD18688730AF')))\r\n\t$ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.InterfaceTypeAttribute].GetConstructor(@([Int16])), @([Int16]1)))\r\n\r\n\t1..4 | % { [void]$ICom.DefineMethod('VF'+$_, 'Public, Virtual, HideBySig, NewSlot, Abstract', 'Standard, HasThis', [Void], @()) }\r\n\t[void]$ICom.DefineMethod('AcquireModernLicenseForWindows', 1478, 33, [Int32], @([Int32], [Int32].MakeByRefType()))\r\n\r\n\t$IEUM = $ICom.CreateType()\r\n}\r\n\r\nfunction PrintStateData {\r\n\t$pwszStateData = 0\r\n\t$cbSize = 0\r\n\r\n\tif ($Win32::SLGetWindowsInformation(\r\n\t\t\"Security-SPP-Action-StateData\",\r\n\t\t[ref]$null,\r\n\t\t[ref]$cbSize,\r\n\t\t[ref]$pwszStateData\r\n\t)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\t[string[]]$pwszStateString = $Marshal::PtrToStringUni($pwszStateData) -replace \";\", \"`n    \"\r\n\tCONOUT (\"    $pwszStateString\")\r\n\r\n\t$Marshal::FreeHGlobal($pwszStateData)\r\n\treturn $TRUE\r\n}\r\n\r\nfunction PrintLastActivationHResult {\r\n\t$pdwLastHResult = 0\r\n\t$cbSize = 0\r\n\r\n\tif ($Win32::SLGetWindowsInformation(\r\n\t\t\"Security-SPP-LastWindowsActivationHResult\",\r\n\t\t[ref]$null,\r\n\t\t[ref]$cbSize,\r\n\t\t[ref]$pdwLastHResult\r\n\t)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\tCONOUT (\"    LastActivationHResult=0x{0:x8}\" -f $Marshal::ReadInt32($pdwLastHResult))\r\n\r\n\t$Marshal::FreeHGlobal($pdwLastHResult)\r\n\treturn $TRUE\r\n}\r\n\r\nfunction PrintLastActivationTime {\r\n\t$pqwLastTime = 0\r\n\t$cbSize = 0\r\n\r\n\tif ($Win32::SLGetWindowsInformation(\r\n\t\t\"Security-SPP-LastWindowsActivationTime\",\r\n\t\t[ref]$null,\r\n\t\t[ref]$cbSize,\r\n\t\t[ref]$pqwLastTime\r\n\t)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\t$actTime = $Marshal::ReadInt64($pqwLastTime)\r\n\tif ($actTime -ne 0) {\r\n\t\tCONOUT (\"    LastActivationTime={0}\" -f [DateTime]::FromFileTimeUtc($actTime).ToString(\"yyyy/MM/dd:HH:mm:ss\"))\r\n\t}\r\n\r\n\t$Marshal::FreeHGlobal($pqwLastTime)\r\n\treturn $TRUE\r\n}\r\n\r\nfunction PrintIsWindowsGenuine {\r\n\t$dwGenuine = 0\r\n\r\n\tif ($Win32::SLIsWindowsGenuineLocal([ref]$dwGenuine)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\tif ($dwGenuine -lt 5) {\r\n\t\tCONOUT (\"    IsWindowsGenuine={0}\" -f $ppwszGenuineStates[$dwGenuine])\r\n\t} else {\r\n\t\tCONOUT (\"    IsWindowsGenuine={0}\" -f $dwGenuine)\r\n\t}\r\n\r\n\treturn $TRUE\r\n}\r\n\r\nfunction PrintDigitalLicenseStatus {\r\n\ttry {\r\n\t\t. InitializeDigitalLicenseCheck\r\n\t\t$ComObj = New-Object -Com EditionUpgradeManagerObj.EditionUpgradeManager\r\n\t} catch {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\t$parameters = 1, $null\r\n\r\n\tif ([EUM.IEUM].GetMethod(\"AcquireModernLicenseForWindows\").Invoke($ComObj, $parameters)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\t$dwReturnCode = $parameters[1]\r\n\t[bool]$bDigitalLicense = $FALSE\r\n\r\n\t$bDigitalLicense = (($dwReturnCode -ge 0) -and ($dwReturnCode -ne 1))\r\n\tCONOUT (\"    IsDigitalLicense={0}\" -f (BoolToWStr $bDigitalLicense))\r\n\r\n\treturn $TRUE\r\n}\r\n\r\nfunction PrintSubscriptionStatus {\r\n\t$dwSupported = 0\r\n\r\n\tif ($winbuild -ge 15063) {\r\n\t\t$pwszPolicy = \"ConsumeAddonPolicySet\"\r\n\t} else {\r\n\t\t$pwszPolicy = \"Allow-WindowsSubscription\"\r\n\t}\r\n\r\n\tif ($Win32::SLGetWindowsInformationDWORD($pwszPolicy, [ref]$dwSupported)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\tCONOUT (\"    SubscriptionSupportedEdition={0}\" -f (BoolToWStr $dwSupported))\r\n\r\n\t$pStatus = $Marshal::AllocHGlobal($Marshal::SizeOf([Type]$SubStatus))\r\n\tif ($Win32::ClipGetSubscriptionStatus([ref]$pStatus)) {\r\n\t\treturn $FALSE\r\n\t}\r\n\r\n\t$sStatus = [Activator]::CreateInstance($SubStatus)\r\n\t$sStatus = $Marshal::PtrToStructure($pStatus, [Type]$SubStatus)\r\n\t$Marshal::FreeHGlobal($pStatus)\r\n\r\n\tCONOUT (\"    SubscriptionEnabled={0}\" -f (BoolToWStr $sStatus.dwEnabled))\r\n\r\n\tif ($sStatus.dwEnabled -eq 0) {\r\n\t\treturn $TRUE\r\n\t}\r\n\r\n\tCONOUT (\"    SubscriptionSku={0}\" -f $sStatus.dwSku)\r\n\tCONOUT (\"    SubscriptionState={0}\" -f $sStatus.dwState)\r\n\r\n\treturn $TRUE\r\n}\r\n\r\nfunction ClicRun\r\n{\r\n\t& $isAll\r\n\tCONOUT \"Client Licensing Check information:\"\r\n\r\n\t$null = PrintStateData\r\n\t$null = PrintLastActivationHResult\r\n\t$null = PrintLastActivationTime\r\n\t$null = PrintIsWindowsGenuine\r\n\r\n\tif ($DllDigital) {\r\n\t\t$null = PrintDigitalLicenseStatus\r\n\t}\r\n\r\n\tif ($DllSubscription) {\r\n\t\t$null = PrintSubscriptionStatus\r\n\t}\r\n\r\n\tCONOUT \"$line3\"\r\n\t& $noAll\r\n}\r\n#endregion\r\n\r\n#region clc\r\nfunction clcGetExpireKrn\r\n{\r\n\t$tData = 0\r\n\t$cData = 0\r\n\t$bData = 0\r\n\r\n\t$hrRet = $Win32::SLGetWindowsInformation(\r\n\t\t\"Kernel-ExpirationDate\",\r\n\t\t[ref]$tData,\r\n\t\t[ref]$cData,\r\n\t\t[ref]$bData\r\n\t)\r\n\r\n\tif ($hrRet -Or !$cData -Or $tData -NE 3)\r\n\t{\r\n\t\treturn $null\r\n\t}\r\n\r\n\t$year = $Marshal::ReadInt16($bData, 0)\r\n\tif ($year -EQ 0 -Or $year -EQ 1601)\r\n\t{\r\n\t\t$rData = $null\r\n\t}\r\n\telse\r\n\t{\r\n\t\t$rData = '{0}/{1}/{2}:{3}:{4}:{5}' -f $year, $Marshal::ReadInt16($bData, 2), $Marshal::ReadInt16($bData, 4), $Marshal::ReadInt16($bData, 6), $Marshal::ReadInt16($bData, 8), $Marshal::ReadInt16($bData, 10)\r\n\t}\r\n\r\n\t#$Marshal::FreeHGlobal($bData)\r\n\treturn $rData\r\n}\r\n\r\nfunction clcGetExpireSys\r\n{\r\n\t$kuser = $Marshal::ReadInt64((New-Object IntPtr(0x7FFE02C8)))\r\n\r\n\tif ($kuser -EQ 0)\r\n\t{\r\n\t\treturn $null\r\n\t}\r\n\r\n\t$rData = [DateTime]::FromFileTimeUtc($kuser).ToString('yyyy/MM/dd:HH:mm:ss')\r\n\treturn $rData\r\n}\r\n\r\nfunction clcGetLicensingState($dwState)\r\n{\r\n\tif ($dwState -EQ 5) {\r\n\t\t$dwState = 3\r\n\t} elseif ($dwState -EQ 3 -Or $dwState -EQ 4 -Or $dwState -EQ 6) {\r\n\t\t$dwState = 2\r\n\t} elseif ($dwState -GT 6) {\r\n\t\t$dwState = 4\r\n\t}\r\n\r\n\t$rData = '{0}' -f $ppwszLicensingStates[$dwState]\r\n\treturn $rData\r\n}\r\n\r\nfunction clcGetGenuineState($AppId)\r\n{\r\n\t$dwGenuine = 0\r\n\r\n\tif ($NT7) {\r\n\t\t$hrRet = $Win32::SLIsWindowsGenuineLocal([ref]$dwGenuine)\r\n\t} else {\r\n\t\t$hrRet = $Win32::SLIsGenuineLocal([ref][Guid]$AppId, [ref]$dwGenuine, 0)\r\n\t}\r\n\r\n\tif ($hrRet)\r\n\t{\r\n\t\t$dwGenuine = 4\r\n\t}\r\n\r\n\tif ($dwGenuine -LT 5) {\r\n\t\t$rData = '{0}' -f $ppwszGenuineStates[$dwGenuine]\r\n\t} else {\r\n\t\t$rData = $dwGenuine\r\n\t}\r\n\treturn $rData\r\n}\r\n\r\nfunction ClcRun\r\n{\r\n\t$prs = $script:primary[0]\r\n\tif ($null -EQ $prs) {\r\n\t\treturn\r\n\t}\r\n\r\n\t$lState = clcGetLicensingState $prs.lst\r\n\t$uState = clcGetGenuineState $winApp\r\n\t$TbbKrn = clcGetExpireKrn\r\n\t$TbbSys = clcGetExpireSys\r\n\tif ($null -NE $TbbKrn) {\r\n\t\t$ked = $TbbKrn\r\n\t} elseif ($null -NE $TbbSys) {\r\n\t\t$ked = $TbbSys\r\n\t}\r\n\r\n\t& $isAll\r\n\tCONOUT \"Client Licensing Check information:\"\r\n\r\n\tCONOUT (\"    AppId={0}\" -f $winApp)\r\n\tif ($prs.ged) { CONOUT (\"    GraceEndDate={0}\" -f ([DateTime]::UtcNow.AddMinutes($prs.ged).ToString('yyyy/MM/dd:HH:mm:ss'))) }\r\n\tif ($null -NE $ked) { CONOUT (\"    KernelTimebombDate={0}\" -f $ked) }\r\n\tCONOUT (\"    LastConsumptionReason=0x{0:x8}\" -f $prs.lcr)\r\n\tif ($prs.evl) { CONOUT (\"    LicenseExpirationDate={0}\" -f ([DateTime]::FromFileTimeUtc($prs.evl).ToString('yyyy/MM/dd:HH:mm:ss'))) }\r\n\tCONOUT (\"    LicenseState={0}\" -f $lState)\r\n\tCONOUT (\"    PartialProductKey={0}\" -f $prs.ppk)\r\n\tCONOUT (\"    ProductKeyType={0}\" -f $prs.chn)\r\n\tCONOUT (\"    SkuId={0}\" -f $prs.aid)\r\n\tCONOUT (\"    uxDifferentiator={0}\" -f $prs.dff)\r\n\tCONOUT (\"    IsWindowsGenuine={0}\" -f $uState)\r\n\r\n\tCONOUT \"$line3\"\r\n\t& $noAll\r\n}\r\n#endregion\r\n\r\n$Host.UI.RawUI.WindowTitle = \"Check Activation Status\"\r\nif ($All.IsPresent) {\r\n\t$B=$Host.UI.RawUI.BufferSize;$B.Height=3000;$Host.UI.RawUI.BufferSize=$B;\r\n\tif (!$Pass.IsPresent) {clear;}\r\n}\r\n\r\n$SysPath = \"$env:SystemRoot\\System32\"\r\nif (Test-Path \"$env:SystemRoot\\Sysnative\\reg.exe\") {\r\n\t$SysPath = \"$env:SystemRoot\\Sysnative\"\r\n}\r\n\r\n$wslp = \"SoftwareLicensingProduct\"\r\n$wsls = \"SoftwareLicensingService\"\r\n$oslp = \"OfficeSoftwareProtectionProduct\"\r\n$osls = \"OfficeSoftwareProtectionService\"\r\n$winApp = \"55c92734-d682-4d71-983e-d6ec3f16059f\"\r\n$o14App = \"59a52881-a989-479d-af46-f275c6370663\"\r\n$o15App = \"0ff1ce15-a989-479d-af46-f275c6370663\"\r\n$isSub = ($winbuild -GE 26000) -And (Select-String -Path \"$SysPath\\wbem\\sppwmi.mof\" -Encoding unicode -Pattern \"SubscriptionType\")\r\n$DllDigital = ($winbuild -GE 14393) -And (Test-Path \"$SysPath\\EditionUpgradeManagerObj.dll\")\r\n$DllSubscription = ($winbuild -GE 14393) -And (Test-Path \"$SysPath\\Clipc.dll\")\r\n$VLActTypes = @(\"All\", \"AD\", \"KMS\", \"Token\")\r\n$OPKeyPath = \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform\"\r\n$SPKeyPath = \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\"\r\n$SLKeyPath = \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\"\r\n$NSKeyPath = \"HKEY_USERS\\S-1-5-20\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\"\r\n$propPrd = 'Name', 'Description', 'TrustedTime', 'VLActivationType'\r\n$propPkey = 'PartialProductKey', 'Channel', 'DigitalPID', 'DigitalPID2'\r\n$propKMSServer = 'KeyManagementServiceCurrentCount', 'KeyManagementServiceTotalRequests', 'KeyManagementServiceFailedRequests', 'KeyManagementServiceUnlicensedRequests', 'KeyManagementServiceLicensedRequests', 'KeyManagementServiceOOBGraceRequests', 'KeyManagementServiceOOTGraceRequests', 'KeyManagementServiceNonGenuineGraceRequests', 'KeyManagementServiceNotificationRequests'\r\n$propKMSClient = 'CustomerPID', 'KeyManagementServiceName', 'KeyManagementServicePort', 'DiscoveredKeyManagementServiceName', 'DiscoveredKeyManagementServicePort', 'DiscoveredKeyManagementServiceIpAddress', 'VLActivationInterval', 'VLRenewalInterval', 'KeyManagementServiceLookupDomain'\r\n$propKMSVista  = 'CustomerPID', 'KeyManagementServiceName', 'VLActivationInterval', 'VLRenewalInterval'\r\n$propADBA = 'ADActivationObjectName', 'ADActivationObjectDN', 'ADActivationCsvlkPID', 'ADActivationCsvlkSkuID'\r\n$propAVMA = 'InheritedActivationId', 'InheritedActivationHostMachineName', 'InheritedActivationHostDigitalPid2', 'InheritedActivationActivationTime'\r\n$primary = @()\r\n$ppwszGenuineStates = @(\r\n\t\"SL_GEN_STATE_IS_GENUINE\",\r\n\t\"SL_GEN_STATE_INVALID_LICENSE\",\r\n\t\"SL_GEN_STATE_TAMPERED\",\r\n\t\"SL_GEN_STATE_OFFLINE\",\r\n\t\"SL_GEN_STATE_LAST\"\r\n)\r\n$ppwszLicensingStates = @(\r\n\t\"SL_LICENSING_STATUS_UNLICENSED\",\r\n\t\"SL_LICENSING_STATUS_LICENSED\",\r\n\t\"SL_LICENSING_STATUS_IN_GRACE_PERIOD\",\r\n\t\"SL_LICENSING_STATUS_NOTIFICATION\",\r\n\t\"SL_LICENSING_STATUS_LAST\"\r\n)\r\n\r\n'cW1nd0ws', 'c0ff1ce15', 'c0ff1ce14', 'ospp14', 'ospp15' | foreach {set $_ @()}\r\n\r\n$offsvc = \"osppsvc\"\r\nif ($NT7 -Or -Not $NT6) {$winsvc = \"sppsvc\"} else {$winsvc = \"slsvc\"}\r\n\r\ntry {gsv $winsvc -EA 1 | Out-Null; $WsppHook = 1} catch {$WsppHook = 0}\r\ntry {gsv $offsvc -EA 1 | Out-Null; $OsppHook = 1} catch {$OsppHook = 0}\r\n\r\nif (Test-Path \"$SysPath\\sppc.dll\") {\r\n\t$SLdll = 'sppc.dll'\r\n} elseif (Test-Path \"$SysPath\\slc.dll\") {\r\n\t$SLdll = 'slc.dll'\r\n} else {\r\n\t$WsppHook = 0\r\n}\r\n\r\nif ($OsppHook -NE 0) {\r\n\t$OLdll = (strGetRegistry $OPKeyPath \"Path\") + 'osppc.dll'\r\n\tif (!(Test-Path \"$OLdll\")) {$OsppHook = 0}\r\n}\r\n\r\nif ($WsppHook -NE 0) {\r\n\tif ($NT6 -And -Not $NT7 -And -Not $Admin) {\r\n\t\tif ($null -EQ [Diagnostics.Process]::GetProcessesByName(\"$winsvc\")[0].ProcessName) {$WsppHook = 0; CONOUT \"`nError: failed to start $winsvc Service.`n\"}\r\n\t} else {\r\n\t\ttry {sasv $winsvc -EA 1} catch {$WsppHook = 0; CONOUT \"`nError: failed to start $winsvc Service.`n\"}\r\n\t}\r\n}\r\n\r\nif ($WsppHook -NE 0) {\r\n\t. InitializePInvoke $SLdll $false\r\n\t$hSLC = 0\r\n\t[void]$Win32::SLOpen([ref]$hSLC)\r\n\r\n\t$cW1nd0ws  = SlGetInfoSLID $winApp\r\n\t$c0ff1ce15 = SlGetInfoSLID $o15App\r\n\t$c0ff1ce14 = SlGetInfoSLID $o14App\r\n}\r\n\r\nif ($cW1nd0ws.Count -GT 0)\r\n{\r\n\techoWindows\r\n\tParseList $wslp $winApp $cW1nd0ws\r\n}\r\nelseif ($NT6)\r\n{\r\n\techoWindows\r\n\tCONOUT \"Error: product key not found.`n\"\r\n}\r\n\r\nif ($NT6 -And -Not $NT8) {\r\n\tClcRun\r\n}\r\n\r\nif ($NT8) {\r\n\tClicRun\r\n}\r\n\r\n$doMSG = 1\r\n\r\nif ($c0ff1ce15.Count -GT 0)\r\n{\r\n\tCheckOhook\r\n\techoOffice\r\n\tParseList $wslp $o15App $c0ff1ce15\r\n}\r\n\r\nif ($c0ff1ce14.Count -GT 0)\r\n{\r\n\techoOffice\r\n\tParseList $wslp $o14App $c0ff1ce14\r\n}\r\n\r\nif ($hSLC) {\r\n\t[void]$Win32::SLClose($hSLC)\r\n}\r\n\r\nif ($OsppHook -NE 0) {\r\n\ttry {sasv $offsvc -EA 1} catch {$OsppHook = 0; CONOUT \"`nError: failed to start $offsvc Service.`n\"}\r\n}\r\n\r\nif ($OsppHook -NE 0) {\r\n\t. InitializePInvoke \"$OLdll\" $true\r\n\t$hSLC = 0\r\n\t[void]$Win32::SLOpen([ref]$hSLC)\r\n\r\n\t$ospp15 = SlGetInfoSLID $o15App\r\n\t$ospp14 = SlGetInfoSLID $o14App\r\n}\r\n\r\nif ($ospp15.Count -GT 0)\r\n{\r\n\techoOffice\r\n\tParseList $oslp $o15App $ospp15\r\n}\r\n\r\nif ($ospp14.Count -GT 0)\r\n{\r\n\techoOffice\r\n\tParseList $oslp $o14App $ospp14\r\n}\r\n\r\nif ($hSLC) {\r\n\t[void]$Win32::SLClose($hSLC)\r\n}\r\n\r\nif ($NT7) {\r\n\tvNextDiagRun\r\n}\r\n\r\nExitScript 0\r\n:sppmgr:\r\n"
  },
  {
    "path": "MAS/Separate-Files-Version/Extract_OEM_Folder.cmd",
    "content": "@set masver=3.10\r\n@echo off\r\n\r\n\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\nset re1=\r\nset re2=\r\nset \"_cmdf=%~f0\"\r\nfor %%# in (%*) do (\r\nif /i \"%%#\"==\"re1\" set re1=1\r\nif /i \"%%#\"==\"re2\" set re2=1\r\nif /i \"%%#\"==\"-qedit\" (set re1=1&set re2=1)\r\n)\r\n\r\n:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows\r\n:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\Sysnative\\cmd.exe if not defined re1 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\Sysnative\\cmd.exe /c \"\"!_cmdf!\" %* re1\"\r\nexit /b\r\n)\r\n\r\n:: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\SysArm32\\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\SysArm32\\cmd.exe /c \"\"!_cmdf!\" %* re2\"\r\nexit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset \"blank=\"\r\nset \"mas=ht%blank%tps%blank%://m%blank%ass%blank%grave.dev/\"\r\nset \"github=ht%blank%tps%blank%://github.com/m%blank%assgra%blank%vel/Micro%blank%soft-Acti%blank%vation-Scripts\"\r\nset \"selfgit=ht%blank%tps%blank%://git.acti%blank%vated.win/Micr%blank%osoft-Act%blank%ivation-Scripts\"\r\n\r\n::  Check if Null service is working, it's important for the batch script\r\n\r\nsc query Null | find /i \"RUNNING\"\r\nif %errorlevel% NEQ 0 (\r\necho:\r\necho Null service is not running, script may crash...\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%fix_service\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20\r\n)\r\ncls\r\n\r\n::  Check LF line ending\r\n\r\npushd \"%~dp0\"\r\n>nul findstr /v \"$\" \"%~nx0\" && (\r\necho:\r\necho Error - Script either has LF line ending issue or an empty line at the end of the script is missing.\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20 >nul\r\npopd\r\nexit /b\r\n)\r\npopd\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\ntitle  Extract $OEM$ Folder %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args set _args=%_args:re1=%\r\nif defined _args set _args=%_args:re2=%\r\nif defined _args (\r\nfor %%A in (%_args%) do (\r\nif /i \"%%A\"==\"-el\"                    set _elev=1\r\n)\r\n)\r\n\r\nset \"nul1=1>nul\"\r\nset \"nul2=2>nul\"\r\nset \"nul6=2^>nul\"\r\nset \"nul=>nul 2>&1\"\r\n\r\ncall :dk_setvar\r\n\r\n::========================================================================================================================================\r\n\r\nif %winbuild% EQU 1 (\r\n%eline%\r\necho Failed to detect Windows build number.\r\necho:\r\nsetlocal EnableDelayedExpansion\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto done2\r\n)\r\n\r\nif exist \"%Systemdrive%\\Users\\WDAGUtilityAccount\" (\r\nsc query gcs | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Windows Sandbox detected.\r\necho The script cannot run due to missing licensing components. Aborting...\r\necho:\r\ngoto done2\r\n)\r\n)\r\n\r\nif %winbuild% LSS 6001 (\r\n%nceline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho MAS only supports Windows Vista/7/8/8.1/10/11 and their Server equivalents.\r\nif %winbuild% EQU 6000 (\r\necho:\r\necho Windows Vista RTM is not supported because Powershell cannot be installed.\r\necho Upgrade to Windows Vista SP1 or SP2.\r\n)\r\ngoto done2\r\n)\r\n\r\nif %winbuild% LSS 7600 if not exist \"%SysPath%\\WindowsPowerShell\\v1.0\\Modules\" (\r\n%nceline%\r\nif not exist %ps% (\r\necho PowerShell is not installed in your system.\r\n)\r\necho Install PowerShell 2.0 using the following URL.\r\necho:\r\necho https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\nif %_unattended%==0 start https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\ngoto done2\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix special character limitations in path name\r\n\r\nset \"_work=%~dp0\"\r\nif \"%_work:~-1%\"==\"\\\" set \"_work=%_work:~0,-1%\"\r\n\r\nset \"_batf=%~f0\"\r\nset \"_batp=%_batf:'=''%\"\r\n\r\nset _PSarg=\"\"\"%~f0\"\"\" -el %_args%\r\nset _PSarg=%_PSarg:'=''%\r\n\r\nset \"_ttemp=%userprofile%\\AppData\\Local\\Temp\"\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\necho \"!_batf!\" | find /i \"!_ttemp!\" %nul1% && (\r\nif /i not \"!_work!\"==\"!_ttemp!\" (\r\n%eline%\r\necho The script was launched from the temp folder.\r\necho You are most likely running the script directly from the archive file.\r\necho:\r\necho Extract the archive file and launch the script from the extracted folder.\r\ngoto done2\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Elevate script as admin and pass arguments and preventing loop\r\n\r\n%nul1% fltmc || (\r\nif not defined _elev %psc% \"start cmd.exe -arg '/c \\\"!_PSarg!\\\"' -verb runas\" && exit /b\r\n%eline%\r\necho This script needs admin rights.\r\necho Right click on this script and select 'Run as administrator'.\r\ngoto done2\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check PowerShell\r\n\r\n::pstst $ExecutionContext.SessionState.LanguageMode :pstst\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"if ($PSVersionTable.PSEdition -ne 'Core') {$f=[System.IO.File]::ReadAllText('!_batp!') -split ':pstst';. ([scriptblock]::Create($f[1]))}\" %nul6%') do (set tstresult=%%a)\r\n\r\nif /i not \"%tstresult%\"==\"FullLanguage\" (\r\n%eline%\r\nfor /f \"delims=\" %%a in ('%psc% \"$ExecutionContext.SessionState.LanguageMode\" %nul6%') do (set tstresult2=%%a)\r\necho Test 1 - %tstresult%\r\necho Test 2 - !tstresult2!\r\necho:\r\n\r\nREM check LanguageMode\r\n\r\necho: !tstresult2! | findstr /i \"ConstrainedLanguage RestrictedLanguage NoLanguage\" %nul1% && (\r\necho FullLanguage mode not found in PowerShell. Aborting...\r\necho If you have applied restrictions on Powershell then undo those changes.\r\nset fixes=%fixes% %mas%fix_powershell\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_powershell\"\r\ngoto done2\r\n)\r\n\r\nREM check Powershell core version\r\n\r\ncmd /c \"%psc% \"$PSVersionTable.PSEdition\"\" | find /i \"Core\" %nul1% && (\r\necho Windows Powershell is needed for MAS but it seems to be replaced with Powershell core. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto done2\r\n)\r\n\r\nREM check for Mal-ware that may cause issues with Powershell\r\n\r\nfor /r \"%ProgramFiles%\\\" %%f in (secureboot.exe) do if exist \"%%f\" (\r\necho \"%%f\"\r\necho Mal%blank%ware found, PowerShell is not working properly.\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\ngoto done2\r\n)\r\n\r\nREM check if .NET is working properly\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\ncmd /c \"%psc% \"\"try {[System.AppDomain]::CurrentDomain.GetAssemblies(); [System.Math]::Sqrt(144)} catch {Exit 3}\"\"\" %nul%\r\nif !errorlevel!==3 (\r\necho Windows Powershell failed to load .NET command. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto done2\r\n)\r\n)\r\n\r\nREM check antivirus and other errors\r\n\r\necho PowerShell is not working properly. Aborting...\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\necho:\r\necho Your antivirus software might be blocking the script.\r\necho:\r\nsc query sense | find /i \"RUNNING\" %nul% && (\r\necho Installed Antivirus - Microsoft Defender for Endpoint\r\n)\r\ncmd /c \"%psc% \"\"$av = Get-WmiObject -Namespace root\\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { $n += $i.displayName }; if ($n) { Write-Host ('Installed Antivirus - ' + ($n -join ', '))}\"\"\"\r\n)\r\n\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto done2\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Disable QuickEdit and launch from conhost.exe to avoid Terminal app\r\n\r\nif %winbuild% GEQ 17763 (\r\nset terminal=1\r\n) else (\r\nset terminal=\r\n)\r\n\r\n::  Check if script is running in Terminal app\r\n\r\nif defined terminal (\r\nset lines=0\r\nfor /f \"skip=3 tokens=* delims=\" %%A in ('mode con') do if \"!lines!\"==\"0\" (\r\nfor %%B in (%%A) do set lines=%%B\r\n)\r\nif !lines! GEQ 100 set terminal=\r\n)\r\n\r\nif %_unattended%==1 goto :skipQE\r\nfor %%# in (%_args%) do (if /i \"%%#\"==\"-qedit\" goto :skipQE)\r\n\r\n::  Relaunch to disable QuickEdit in the current session and use conhost.exe instead of the Terminal app\r\n::  This code disables QuickEdit for the current cmd.exe session without making permanent registry changes\r\n::  It is included because clicking on the script window can pause execution, causing confusion that the script has stopped due to an error\r\n\r\nset resetQE=1\r\nreg query HKCU\\Console /v QuickEdit %nul2% | find /i \"0x0\" %nul1% && set resetQE=0\r\nreg add HKCU\\Console /v QuickEdit /t REG_DWORD /d 0 /f %nul1%\r\n\r\nif defined terminal (\r\nstart conhost.exe \"!_batf!\" %_args% -qedit\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n) else if %resetQE% EQU 1 (\r\nstart cmd.exe /c \"\"!_batf!\" %_args% -qedit\"\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n)\r\n\r\n:skipQE\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check for updates\r\n\r\nset -=\r\nset old=\r\nset pingp=\r\nset upver=%masver:.=%\r\n\r\nfor %%A in (\r\nactiv%-%ated.win\r\nmass%-%grave.dev\r\n) do if not defined pingp (\r\nfor /f \"delims=[] tokens=2\" %%B in ('ping -n 1 %%A') do (\r\nif not \"%%B\"==\"\" (set old=1& set pingp=1)\r\nfor /f \"delims=[] tokens=2\" %%C in ('ping -n 1 updatecheck%upver%.%%A') do (\r\nif not \"%%C\"==\"\" set old=\r\n)\r\n)\r\n)\r\n\r\nif defined old (\r\necho ________________________________________________\r\n%eline%\r\necho Your version of MAS [%masver%] is outdated.\r\necho ________________________________________________\r\necho:\r\nif not %_unattended%==1 (\r\necho [1] Get Latest MAS\r\necho [0] Continue Anyway\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 rem\r\nif !errorlevel!==1 (start %selfgit% & start %github% & start %mas% & exit /b)\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nsetlocal DisableDelayedExpansion\r\n\r\n::  Check desktop location\r\n\r\nset desktop=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" /v Desktop') do call set \"desktop=%%b\"\r\nif not defined desktop for /f \"delims=\" %%a in ('%psc% \"& {write-host $([Environment]::GetFolderPath('Desktop'))}\"') do call set \"desktop=%%a\"\r\n\r\nset \"_pdesk=%desktop:'=''%\"\r\nset \"_dir=%desktop%\\$OEM$\\$$\\Setup\\Scripts\"\r\n\r\nif exist \"!desktop!\\\" (\r\n%eline%\r\necho Unable to detect Desktop location, aborting...\r\ngoto done2\r\n)\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\nif not defined terminal mode 78, 30\r\n\r\nif exist \"!desktop!\\$OEM$\\\" (\r\necho _____________________________________________________\r\n%eline%\r\necho The $OEM$ folder already exists on your Desktop.\r\necho _____________________________________________________\r\ngoto done2\r\n)\r\n\r\nset HWID_Activation.cmd=Activators\\HWID_Activation.cmd\r\nset Online_KMS_Activation.cmd=Activators\\Online_KMS_Activation.cmd\r\nset Ohook_Activation_AIO.cmd=Activators\\Ohook_Activation_AIO.cmd\r\nset TSforge_Activation.cmd=Activators\\TSforge_Activation.cmd\r\npushd \"!_work!\"\r\n\r\nset _nofile=\r\nfor %%# in (\r\n%HWID_Activation.cmd%\r\n%Online_KMS_Activation.cmd%\r\n%Ohook_Activation_AIO.cmd%\r\n%TSforge_Activation.cmd%\r\n) do (\r\nif not exist \"%%#\" set _nofile=1\r\n)\r\n\r\npopd\r\n\r\nif defined _nofile (\r\necho _____________________________________________________\r\n%eline%\r\necho Some files are missing in the 'Activators' folder.\r\necho _____________________________________________________\r\ngoto done2\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:Menu\r\n\r\ncls\r\nif not defined terminal mode 78, 30\r\necho:\r\necho:\r\necho:\r\necho:\r\necho:                     Extract $OEM$ folder on the desktop           \r\necho:         ____________________________________________________________\r\necho:\r\necho:            [1] HWID       [Windows]\r\necho:            [2] Ohook      [Office]\r\necho:            [3] TSforge    [Windows / ESU / Office]\r\necho:            [4] Online KMS [Windows / Office]\r\necho:\r\necho:            [5] HWID       [Windows] ^+ Ohook [Office]\r\necho:            [6] HWID       [Windows] ^+ Ohook [Office] ^+ TSforge [ESU]\r\necho:            [7] TSforge    [Windows / ESU] ^+ Ohook [Office]\r\necho:\r\ncall :dk_color2 %_White% \"            [R] \" %_Green% \"ReadMe\"\r\necho:            [0] Exit\r\necho:         ____________________________________________________________\r\necho:  \r\ncall :dk_color2 %_White% \"             \" %_Green% \"Choose a menu option using your keyboard :\"\r\nchoice /C:1234567R0 /N\r\nset _erl=%errorlevel%\r\n\r\nif %_erl%==9 exit /b\r\nif %_erl%==8 start %mas%oem-folder &goto :Menu\r\nif %_erl%==7 goto:tsforge_ohook\r\nif %_erl%==6 goto:hwid_ohook_tsforge\r\nif %_erl%==5 goto:hwid_ohook\r\nif %_erl%==4 goto:kms\r\nif %_erl%==3 goto:tsforge\r\nif %_erl%==2 goto:ohook\r\nif %_erl%==1 goto:hwid\r\ngoto :Menu\r\n\r\n::========================================================================================================================================\r\n\r\n:hwid\r\n\r\ncls\r\nmd \"!desktop!\\$OEM$\\$$\\Setup\\Scripts\"\r\npushd \"!_work!\"\r\ncopy /y /b \"%HWID_Activation.cmd%\" \"!_dir!\\HWID_Activation.cmd\" %nul%\r\npopd\r\ncall :export hwid_setup\r\n\r\nset _error=\r\nif not exist \"!_dir!\\HWID_Activation.cmd\" set _error=1\r\nif not exist \"!_dir!\\SetupComplete.cmd\" set _error=1\r\nif defined _error goto errorfound\r\n\r\nset oem=HWID\r\ngoto done\r\n\r\n:hwid_setup:\r\n@echo off\r\n\r\nfltmc >nul || exit /b\r\n\r\ncall \"%~dp0HWID_Activation.cmd\" /HWID\r\n\r\ncd \\\r\n(goto) 2>nul & (if \"%~dp0\"==\"%SystemRoot%\\Setup\\Scripts\\\" rd /s /q \"%~dp0\")\r\n:hwid_setup:\r\n\r\n::========================================================================================================================================\r\n\r\n:ohook\r\n\r\ncls\r\nmd \"!desktop!\\$OEM$\\$$\\Setup\\Scripts\"\r\npushd \"!_work!\"\r\ncopy /y /b %Ohook_Activation_AIO.cmd% \"!_dir!\\Ohook_Activation_AIO.cmd\" %nul%\r\npopd\r\ncall :export ohook_setup\r\n\r\nset _error=\r\nif not exist \"!_dir!\\Ohook_Activation_AIO.cmd\" set _error=1\r\nif not exist \"!_dir!\\SetupComplete.cmd\" set _error=1\r\nif defined _error goto errorfound\r\n\r\nset oem=Ohook\r\ngoto done\r\n\r\n:ohook_setup:\r\n@echo off\r\n\r\nfltmc >nul || exit /b\r\n\r\ncall \"%~dp0Ohook_Activation_AIO.cmd\" /Ohook\r\n\r\ncd \\\r\n(goto) 2>nul & (if \"%~dp0\"==\"%SystemRoot%\\Setup\\Scripts\\\" rd /s /q \"%~dp0\")\r\n:ohook_setup:\r\n\r\n::========================================================================================================================================\r\n\r\n:tsforge\r\n\r\ncls\r\nmd \"!desktop!\\$OEM$\\$$\\Setup\\Scripts\"\r\npushd \"!_work!\"\r\ncopy /y /b \"%TSforge_Activation.cmd%\" \"!_dir!\\TSforge_Activation.cmd\" %nul%\r\npopd\r\ncall :export tsforge_setup\r\n\r\nset _error=\r\nif not exist \"!_dir!\\TSforge_Activation.cmd\" set _error=1\r\nif not exist \"!_dir!\\SetupComplete.cmd\" set _error=1\r\nif defined _error goto errorfound\r\n\r\nset oem=TSforge\r\ngoto done\r\n\r\n:tsforge_setup:\r\n@echo off\r\n\r\nfltmc >nul || exit /b\r\n\r\ncall \"%~dp0TSforge_Activation.cmd\" /Z-WindowsESUOffice\r\n\r\ncd \\\r\n(goto) 2>nul & (if \"%~dp0\"==\"%SystemRoot%\\Setup\\Scripts\\\" rd /s /q \"%~dp0\")\r\n:tsforge_setup:\r\n\r\n::========================================================================================================================================\r\n\r\n:kms\r\n\r\ncls\r\nmd \"!desktop!\\$OEM$\\$$\\Setup\\Scripts\"\r\npushd \"!_work!\"\r\ncopy /y /b \"%Online_KMS_Activation.cmd%\" \"!_dir!\\Online_KMS_Activation.cmd\" %nul%\r\npopd\r\ncall :export kms_setup\r\n\r\nset _error=\r\nif not exist \"!_dir!\\Online_KMS_Activation.cmd\" set _error=1\r\nif not exist \"!_dir!\\SetupComplete.cmd\" set _error=1\r\nif defined _error goto errorfound\r\n\r\nset oem=Online KMS\r\ngoto done\r\n\r\n:kms_setup:\r\n@echo off\r\n\r\nfltmc >nul || exit /b\r\n\r\ncall \"%~dp0Online_KMS_Activation.cmd\" /K-WindowsOffice\r\n\r\ncd \\\r\n(goto) 2>nul & (if \"%~dp0\"==\"%SystemRoot%\\Setup\\Scripts\\\" rd /s /q \"%~dp0\")\r\n:kms_setup:\r\n\r\n::========================================================================================================================================\r\n\r\n:hwid_ohook\r\n\r\ncls\r\nmd \"!desktop!\\$OEM$\\$$\\Setup\\Scripts\"\r\npushd \"!_work!\"\r\ncopy /y /b \"%HWID_Activation.cmd%\" \"!_dir!\\HWID_Activation.cmd\" %nul%\r\ncopy /y /b \"%Ohook_Activation_AIO.cmd%\" \"!_dir!\\Ohook_Activation_AIO.cmd\" %nul%\r\npopd\r\ncall :export hwid_ohook_setup\r\n\r\nset _error=\r\nif not exist \"!_dir!\\HWID_Activation.cmd\" set _error=1\r\nif not exist \"!_dir!\\Ohook_Activation_AIO.cmd\" set _error=1\r\nif not exist \"!_dir!\\SetupComplete.cmd\" set _error=1\r\nif defined _error goto errorfound\r\n\r\nset oem=HWID [Windows] + Ohook [Office]\r\ngoto done\r\n\r\n:hwid_ohook_setup:\r\n@echo off\r\n\r\nfltmc >nul || exit /b\r\n\r\nsetlocal\r\ncall \"%~dp0HWID_Activation.cmd\" /HWID\r\nendlocal\r\n\r\nsetlocal\r\ncall \"%~dp0Ohook_Activation_AIO.cmd\" /Ohook\r\nendlocal\r\n\r\ncd \\\r\n(goto) 2>nul & (if \"%~dp0\"==\"%SystemRoot%\\Setup\\Scripts\\\" rd /s /q \"%~dp0\")\r\n:hwid_ohook_setup:\r\n\r\n::========================================================================================================================================\r\n\r\n:hwid_ohook_tsforge\r\n\r\ncls\r\nmd \"!desktop!\\$OEM$\\$$\\Setup\\Scripts\"\r\npushd \"!_work!\"\r\ncopy /y /b \"%HWID_Activation.cmd%\" \"!_dir!\\HWID_Activation.cmd\" %nul%\r\ncopy /y /b \"%Ohook_Activation_AIO.cmd%\" \"!_dir!\\Ohook_Activation_AIO.cmd\" %nul%\r\ncopy /y /b \"%TSforge_Activation.cmd%\" \"!_dir!\\TSforge_Activation.cmd\" %nul%\r\npopd\r\ncall :export hwid_ohook_tsforge_setup\r\n\r\nset _error=\r\nif not exist \"!_dir!\\HWID_Activation.cmd\" set _error=1\r\nif not exist \"!_dir!\\Ohook_Activation_AIO.cmd\" set _error=1\r\nif not exist \"!_dir!\\TSforge_Activation.cmd\" set _error=1\r\nif not exist \"!_dir!\\SetupComplete.cmd\" set _error=1\r\nif defined _error goto errorfound\r\n\r\nset oem=HWID [Windows] + Ohook [Office] + TSforge [ESU]\r\ngoto done\r\n\r\n:hwid_ohook_tsforge_setup:\r\n@echo off\r\n\r\nfltmc >nul || exit /b\r\n\r\nsetlocal\r\ncall \"%~dp0HWID_Activation.cmd\" /HWID\r\nendlocal\r\n\r\nsetlocal\r\ncall \"%~dp0Ohook_Activation_AIO.cmd\" /Ohook\r\nendlocal\r\n\r\nsetlocal\r\ncall \"%~dp0TSforge_Activation.cmd\" /Z-ESU\r\nendlocal\r\n\r\ncd \\\r\n(goto) 2>nul & (if \"%~dp0\"==\"%SystemRoot%\\Setup\\Scripts\\\" rd /s /q \"%~dp0\")\r\n:hwid_ohook_tsforge_setup:\r\n\r\n::========================================================================================================================================\r\n\r\n:tsforge_ohook\r\n\r\ncls\r\nmd \"!desktop!\\$OEM$\\$$\\Setup\\Scripts\"\r\npushd \"!_work!\"\r\ncopy /y /b \"%TSforge_Activation.cmd%\" \"!_dir!\\TSforge_Activation.cmd\" %nul%\r\ncopy /y /b \"%Ohook_Activation_AIO.cmd%\" \"!_dir!\\Ohook_Activation_AIO.cmd\" %nul%\r\npopd\r\ncall :export tsforge_ohook_setup\r\n\r\nset _error=\r\nif not exist \"!_dir!\\TSforge_Activation.cmd\" set _error=1\r\nif not exist \"!_dir!\\Ohook_Activation_AIO.cmd\" set _error=1\r\nif not exist \"!_dir!\\SetupComplete.cmd\" set _error=1\r\nif defined _error goto errorfound\r\n\r\nset oem=TSforge [Windows / ESU] + Ohook [Office]\r\ngoto done\r\n\r\n:tsforge_ohook_setup:\r\n@echo off\r\n\r\nfltmc >nul || exit /b\r\n\r\nsetlocal\r\ncall \"%~dp0TSforge_Activation.cmd\" /Z-Windows /Z-ESU\r\nendlocal\r\n\r\nsetlocal\r\ncall \"%~dp0Ohook_Activation_AIO.cmd\" /Ohook\r\nendlocal\r\n\r\ncd \\\r\n(goto) 2>nul & (if \"%~dp0\"==\"%SystemRoot%\\Setup\\Scripts\\\" rd /s /q \"%~dp0\")\r\n:tsforge_ohook_setup:\r\n\r\n::========================================================================================================================================\r\n\r\n:errorfound\r\n\r\n%eline%\r\necho The script failed to create the $OEM$ folder.\r\ngoto :done2\r\n\r\n:done\r\n\r\necho ______________________________________________________________\r\necho:\r\ncall :dk_color %Blue% \"%oem%\"\r\ncall :dk_color %Green% \"$OEM$ folder was successfully created on your Desktop.\"\r\necho ______________________________________________________________\r\n\r\n:done2\r\n\r\necho:\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 exit /b\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set variables\r\n\r\n:dk_setvar\r\n\r\nset ps=%SysPath%\\WindowsPowerShell\\v1.0\\powershell.exe\r\nset psc=%ps% -nop -c\r\nset winbuild=1\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset _NCS=1\r\nif %winbuild% LSS 10586 set _NCS=0\r\nif %winbuild% GEQ 10586 reg query \"HKCU\\Console\" /v ForceV2 %nul2% | find /i \"0x0\" %nul1% && (set _NCS=0)\r\n\r\necho \"%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%\" | find /i \"ARM64\" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)\r\n\r\nif %_NCS% EQU 1 (\r\nfor /F %%a in ('echo prompt $E ^| cmd') do set \"esc=%%a\"\r\nset     \"Red=\"41;97m\"\"\r\nset    \"Gray=\"100;97m\"\"\r\nset   \"Green=\"42;97m\"\"\r\nset    \"Blue=\"44;97m\"\"\r\nset   \"White=\"107;91m\"\"\r\nset    \"_Red=\"40;91m\"\"\r\nset  \"_White=\"40;37m\"\"\r\nset  \"_Green=\"40;92m\"\"\r\nset \"_Yellow=\"40;93m\"\"\r\n) else (\r\nset     \"Red=\"Red\" \"white\"\"\r\nset    \"Gray=\"Darkgray\" \"white\"\"\r\nset   \"Green=\"DarkGreen\" \"white\"\"\r\nset    \"Blue=\"Blue\" \"white\"\"\r\nset   \"White=\"White\" \"Red\"\"\r\nset    \"_Red=\"Black\" \"Red\"\"\r\nset  \"_White=\"Black\" \"Gray\"\"\r\nset  \"_Green=\"Black\" \"Green\"\"\r\nset \"_Yellow=\"Black\" \"Yellow\"\"\r\n)\r\n\r\nset \"nceline=echo: &echo ==== ERROR ==== &echo:\"\r\nset \"eline=echo: &call :dk_color %Red% \"==== ERROR ====\" &echo:\"\r\nif %~z0 GEQ 200000 (\r\nset \"_exitmsg=Go back\"\r\nset \"_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option.\"\r\n) else (\r\nset \"_exitmsg=Exit\"\r\nset \"_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option.\"\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Extract the text from batch script without character and file encoding issue\r\n\r\n:export\r\n\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split \\\":%~1\\:.*`r`n\\\"; [io.file]::WriteAllText('!_pdesk!\\$OEM$\\$$\\Setup\\Scripts\\SetupComplete.cmd',$f[1].Trim(),[System.Text.Encoding]::ASCII);\"\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_color\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3'\r\n) else if not exist %ps% (\r\necho %~3\r\n)\r\nexit /b\r\n\r\n:dk_color2\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[%~3%~4%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'\r\n) else if not exist %ps% (\r\necho %~3 %~6\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n:: Leave empty line below\r\n"
  },
  {
    "path": "MAS/Separate-Files-Version/Troubleshoot.cmd",
    "content": "@set masver=3.10\r\n@echo off\r\n\r\n\r\n\r\n::============================================================================\r\n::\r\n::   Homepage: m{}assgrave{dot}dev\r\n::\r\n::============================================================================\r\n\r\n\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set environment variables, it helps if they are misconfigured in the system\r\n\r\nsetlocal EnableExtensions\r\nsetlocal DisableDelayedExpansion\r\n\r\nset \"PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\"\r\n\r\nset \"SysPath=%SystemRoot%\\System32\"\r\nset \"Path=%SystemRoot%\\System32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\\"\r\nif exist \"%SystemRoot%\\Sysnative\\reg.exe\" (\r\nset \"SysPath=%SystemRoot%\\Sysnative\"\r\nset \"Path=%SystemRoot%\\Sysnative;%SystemRoot%;%SystemRoot%\\Sysnative\\Wbem;%SystemRoot%\\Sysnative\\WindowsPowerShell\\v1.0\\;%Path%\"\r\n)\r\n\r\nset \"ComSpec=%SysPath%\\cmd.exe\"\r\nset \"PSModulePath=%ProgramFiles%\\WindowsPowerShell\\Modules;%SysPath%\\WindowsPowerShell\\v1.0\\Modules\"\r\n\r\nset re1=\r\nset re2=\r\nset \"_cmdf=%~f0\"\r\nfor %%# in (%*) do (\r\nif /i \"%%#\"==\"re1\" set re1=1\r\nif /i \"%%#\"==\"re2\" set re2=1\r\nif /i \"%%#\"==\"-qedit\" (set re1=1&set re2=1)\r\n)\r\n\r\n:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows\r\n:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\Sysnative\\cmd.exe if not defined re1 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\Sysnative\\cmd.exe /c \"\"!_cmdf!\" %* re1\"\r\nexit /b\r\n)\r\n\r\n:: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows\r\n\r\nif exist %SystemRoot%\\SysArm32\\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (\r\nsetlocal EnableDelayedExpansion\r\nstart %SystemRoot%\\SysArm32\\cmd.exe /c \"\"!_cmdf!\" %* re2\"\r\nexit /b\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nset \"blank=\"\r\nset \"mas=ht%blank%tps%blank%://m%blank%ass%blank%grave.dev/\"\r\nset \"github=ht%blank%tps%blank%://github.com/m%blank%assgra%blank%vel/Micro%blank%soft-Acti%blank%vation-Scripts\"\r\nset \"selfgit=ht%blank%tps%blank%://git.acti%blank%vated.win/Micr%blank%osoft-Act%blank%ivation-Scripts\"\r\n\r\n::  Check if Null service is working, it's important for the batch script\r\n\r\nsc query Null | find /i \"RUNNING\"\r\nif %errorlevel% NEQ 0 (\r\necho:\r\necho Null service is not running, script may crash...\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%fix_service\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20\r\n)\r\ncls\r\n\r\n::  Check LF line ending\r\n\r\npushd \"%~dp0\"\r\n>nul findstr /v \"$\" \"%~nx0\" && (\r\necho:\r\necho Error - Script either has LF line ending issue or an empty line at the end of the script is missing.\r\necho:\r\necho:\r\necho Check this webpage for help - %mas%troubleshoot\r\necho:\r\necho:\r\nping 127.0.0.1 -n 20 >nul\r\npopd\r\nexit /b\r\n)\r\npopd\r\n\r\n::========================================================================================================================================\r\n\r\ncls\r\ncolor 07\r\ntitle  Troubleshoot %masver%\r\n\r\nset _args=\r\nset _elev=\r\nset _unattended=0\r\n\r\nset _args=%*\r\nif defined _args set _args=%_args:\"=%\r\nif defined _args set _args=%_args:re1=%\r\nif defined _args set _args=%_args:re2=%\r\nif defined _args (\r\nfor %%A in (%_args%) do (\r\nif /i \"%%A\"==\"-el\"                    set _elev=1\r\n)\r\n)\r\n\r\nset \"nul1=1>nul\"\r\nset \"nul2=2>nul\"\r\nset \"nul6=2^>nul\"\r\nset \"nul=>nul 2>&1\"\r\n\r\ncall :dk_setvar\r\nset \"line=_________________________________________________________________________________________________\"\r\n\r\n::========================================================================================================================================\r\n\r\nif %winbuild% EQU 1 (\r\n%eline%\r\necho Failed to detect Windows build number.\r\necho:\r\nsetlocal EnableDelayedExpansion\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\nif exist \"%Systemdrive%\\Users\\WDAGUtilityAccount\" (\r\nsc query gcs | find /i \"RUNNING\" %nul% && (\r\n%eline%\r\necho Windows Sandbox detected.\r\necho The script cannot run due to missing licensing components. Aborting...\r\necho:\r\ngoto dk_done\r\n)\r\n)\r\n\r\nif %winbuild% LSS 6001 (\r\n%nceline%\r\necho Unsupported OS version detected [%winbuild%].\r\necho MAS only supports Windows Vista/7/8/8.1/10/11 and their Server equivalents.\r\nif %winbuild% EQU 6000 (\r\necho:\r\necho Windows Vista RTM is not supported because Powershell cannot be installed.\r\necho Upgrade to Windows Vista SP1 or SP2.\r\n)\r\ngoto dk_done\r\n)\r\n\r\nif %winbuild% LSS 7600 if not exist \"%SysPath%\\WindowsPowerShell\\v1.0\\Modules\" (\r\n%nceline%\r\nif not exist %ps% (\r\necho PowerShell is not installed in your system.\r\n)\r\necho Install PowerShell 2.0 using the following URL.\r\necho:\r\necho https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\nif %_unattended%==0 start https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix special character limitations in path name\r\n\r\nset \"_work=%~dp0\"\r\nif \"%_work:~-1%\"==\"\\\" set \"_work=%_work:~0,-1%\"\r\n\r\nset \"_batf=%~f0\"\r\nset \"_batp=%_batf:'=''%\"\r\n\r\nset _PSarg=\"\"\"%~f0\"\"\" -el %_args%\r\nset _PSarg=%_PSarg:'=''%\r\n\r\nset \"_ttemp=%userprofile%\\AppData\\Local\\Temp\"\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\necho \"!_batf!\" | find /i \"!_ttemp!\" %nul1% && (\r\nif /i not \"!_work!\"==\"!_ttemp!\" (\r\n%eline%\r\necho The script was launched from the temp folder.\r\necho You are most likely running the script directly from the archive file.\r\necho:\r\necho Extract the archive file and launch the script from the extracted folder.\r\ngoto dk_done\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Elevate script as admin and pass arguments and preventing loop\r\n\r\n%nul1% fltmc || (\r\nif not defined _elev %psc% \"start cmd.exe -arg '/c \\\"!_PSarg!\\\"' -verb runas\" && exit /b\r\n%eline%\r\necho This script needs admin rights.\r\necho Right click on this script and select 'Run as administrator'.\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check PowerShell\r\n\r\n::pstst $ExecutionContext.SessionState.LanguageMode :pstst\r\n\r\nfor /f \"delims=\" %%a in ('%psc% \"if ($PSVersionTable.PSEdition -ne 'Core') {$f=[System.IO.File]::ReadAllText('!_batp!') -split ':pstst';. ([scriptblock]::Create($f[1]))}\" %nul6%') do (set tstresult=%%a)\r\n\r\nif /i not \"%tstresult%\"==\"FullLanguage\" (\r\n%eline%\r\nfor /f \"delims=\" %%a in ('%psc% \"$ExecutionContext.SessionState.LanguageMode\" %nul6%') do (set tstresult2=%%a)\r\necho Test 1 - %tstresult%\r\necho Test 2 - !tstresult2!\r\necho:\r\n\r\nREM check LanguageMode\r\n\r\necho: !tstresult2! | findstr /i \"ConstrainedLanguage RestrictedLanguage NoLanguage\" %nul1% && (\r\necho FullLanguage mode not found in PowerShell. Aborting...\r\necho If you have applied restrictions on Powershell then undo those changes.\r\nset fixes=%fixes% %mas%fix_powershell\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%fix_powershell\"\r\ngoto dk_done\r\n)\r\n\r\nREM check Powershell core version\r\n\r\ncmd /c \"%psc% \"$PSVersionTable.PSEdition\"\" | find /i \"Core\" %nul1% && (\r\necho Windows Powershell is needed for MAS but it seems to be replaced with Powershell core. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n\r\nREM check for Mal-ware that may cause issues with Powershell\r\n\r\nfor /r \"%ProgramFiles%\\\" %%f in (secureboot.exe) do if exist \"%%f\" (\r\necho \"%%f\"\r\necho Mal%blank%ware found, PowerShell is not working properly.\r\nset fixes=%fixes% %mas%remove_mal%w%ware\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%remove_mal%w%ware\"\r\ngoto dk_done\r\n)\r\n\r\nREM check if .NET is working properly\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\ncmd /c \"%psc% \"\"try {[System.AppDomain]::CurrentDomain.GetAssemblies(); [System.Math]::Sqrt(144)} catch {Exit 3}\"\"\" %nul%\r\nif !errorlevel!==3 (\r\necho Windows Powershell failed to load .NET command. Aborting...\r\nset fixes=%fixes% %mas%in-place_repair_upgrade\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%in-place_repair_upgrade\"\r\ngoto dk_done\r\n)\r\n)\r\n\r\nREM check antivirus and other errors\r\n\r\necho PowerShell is not working properly. Aborting...\r\n\r\nif /i \"!tstresult2!\"==\"FullLanguage\" (\r\necho:\r\necho Your antivirus software might be blocking the script.\r\necho:\r\nsc query sense | find /i \"RUNNING\" %nul% && (\r\necho Installed Antivirus - Microsoft Defender for Endpoint\r\n)\r\ncmd /c \"%psc% \"\"$av = Get-WmiObject -Namespace root\\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { $n += $i.displayName }; if ($n) { Write-Host ('Installed Antivirus - ' + ($n -join ', '))}\"\"\"\r\n)\r\n\r\nset fixes=%fixes% %mas%troubleshoot\r\ncall :dk_color2 %Blue% \"Check this webpage for help - \" %_Yellow% \" %mas%troubleshoot\"\r\ngoto dk_done\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Disable QuickEdit and launch from conhost.exe to avoid Terminal app\r\n\r\nif %winbuild% GEQ 17763 (\r\nset terminal=1\r\n) else (\r\nset terminal=\r\n)\r\n\r\n::  Check if script is running in Terminal app\r\n\r\nif defined terminal (\r\nset lines=0\r\nfor /f \"skip=3 tokens=* delims=\" %%A in ('mode con') do if \"!lines!\"==\"0\" (\r\nfor %%B in (%%A) do set lines=%%B\r\n)\r\nif !lines! GEQ 100 set terminal=\r\n)\r\n\r\nif %_unattended%==1 goto :skipQE\r\nfor %%# in (%_args%) do (if /i \"%%#\"==\"-qedit\" goto :skipQE)\r\n\r\n::  Relaunch to disable QuickEdit in the current session and use conhost.exe instead of the Terminal app\r\n::  This code disables QuickEdit for the current cmd.exe session without making permanent registry changes\r\n::  It is included because clicking on the script window can pause execution, causing confusion that the script has stopped due to an error\r\n\r\nset resetQE=1\r\nreg query HKCU\\Console /v QuickEdit %nul2% | find /i \"0x0\" %nul1% && set resetQE=0\r\nreg add HKCU\\Console /v QuickEdit /t REG_DWORD /d 0 /f %nul1%\r\n\r\nif defined terminal (\r\nstart conhost.exe \"!_batf!\" %_args% -qedit\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n) else if %resetQE% EQU 1 (\r\nstart cmd.exe /c \"\"!_batf!\" %_args% -qedit\"\r\nstart reg add HKCU\\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%\r\nexit /b\r\n)\r\n\r\n:skipQE\r\n\r\n::========================================================================================================================================\r\n\r\n::  Check for updates\r\n\r\nset -=\r\nset old=\r\nset pingp=\r\nset upver=%masver:.=%\r\n\r\nfor %%A in (\r\nactiv%-%ated.win\r\nmass%-%grave.dev\r\n) do if not defined pingp (\r\nfor /f \"delims=[] tokens=2\" %%B in ('ping -n 1 %%A') do (\r\nif not \"%%B\"==\"\" (set old=1& set pingp=1)\r\nfor /f \"delims=[] tokens=2\" %%C in ('ping -n 1 updatecheck%upver%.%%A') do (\r\nif not \"%%C\"==\"\" set old=\r\n)\r\n)\r\n)\r\n\r\nif defined old (\r\necho ________________________________________________\r\n%eline%\r\necho Your version of MAS [%masver%] is outdated.\r\necho ________________________________________________\r\necho:\r\nif not %_unattended%==1 (\r\necho [1] Get Latest MAS\r\necho [0] Continue Anyway\r\necho:\r\ncall :dk_color %_Green% \"Choose a menu option using your keyboard [1,0] :\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 rem\r\nif !errorlevel!==1 (start %selfgit% & start %github% & start %mas% & exit /b)\r\n)\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\nsetlocal DisableDelayedExpansion\r\n\r\n::  Check desktop location\r\n\r\nset desktop=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" /v Desktop') do call set \"desktop=%%b\"\r\nif not defined desktop for /f \"delims=\" %%a in ('%psc% \"& {write-host $([Environment]::GetFolderPath('Desktop'))}\"') do call set \"desktop=%%a\"\r\n\r\nif not defined desktop (\r\n%eline%\r\necho Unable to detect Desktop location, aborting...\r\ngoto dk_done\r\n)\r\n\r\nsetlocal EnableDelayedExpansion\r\n\r\n::========================================================================================================================================\r\n\r\n:at_menu\r\n\r\ncls\r\ncolor 07\r\ntitle  Troubleshoot %masver%\r\nif not defined terminal mode 77, 30\r\n\r\necho:\r\necho:\r\necho:\r\necho:\r\necho:       _______________________________________________________________\r\necho:                                                   \r\ncall :dk_color2 %_White% \"             [1] \" %_Green% \"Help\"\r\necho:             ___________________________________________________\r\necho:                                                                      \r\necho:             [2] Dism RestoreHealth\r\necho:             [3] SFC Scannow\r\necho:                                                                      \r\necho:             [4] Fix WMI\r\necho:             [5] Fix Licensing\r\necho:             [6] Fix WPA Registry\r\necho:             ___________________________________________________\r\necho:\r\necho:             [0] %_exitmsg%\r\necho:       _______________________________________________________________\r\necho:          \r\ncall :dk_color2 %_White% \"            \" %_Green% \"Choose a menu option using your keyboard :\"\r\nchoice /C:1234560 /N\r\nset _erl=%errorlevel%\r\n\r\nif %_erl%==7 exit /b\r\nif %_erl%==6 start %mas%fix-wpa-registry &goto at_menu\r\nif %_erl%==5 goto:retokens\r\nif %_erl%==4 goto:fixwmi\r\nif %_erl%==3 goto:sfcscan\r\nif %_erl%==2 goto:dism_rest\r\nif %_erl%==1 (start %selfgit% & start %github% & start %mas%troubleshoot & goto at_menu)\r\ngoto :at_menu\r\n\r\n::========================================================================================================================================\r\n\r\n:dism_rest\r\n\r\ncls\r\nif not defined terminal mode 98, 30\r\ntitle  Dism /English /Online /Cleanup-Image /RestoreHealth\r\n\r\nif %winbuild% LSS 9200 (\r\n%eline%\r\necho Unsupported OS version detected.\r\necho This command only works on Windows 8/8.1/10/11 and their Server equivalents.\r\ngoto :at_back\r\n)\r\n\r\nset _int=\r\nfor %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (\r\nfor /f \"delims=[] tokens=2\" %%# in ('ping -n 1 %%a') do (if not \"%%#\"==\"\" set _int=1)\r\n)\r\n\r\necho:\r\nif defined _int (\r\necho      Checking Internet Connection  [Connected]\r\n) else (\r\ncall :dk_color2 %_White% \"     \" %Red% \"Checking Internet Connection  [Not connected]\"\r\n)\r\n\r\necho %line%\r\necho:\r\necho      DISM uses Windows Update to provide replacement files required to fix corruption.\r\necho      This will take 5-15 minutes or more..\r\necho %line%\r\necho:\r\necho      Notes:\r\necho:\r\ncall :dk_color2 %_White% \"     - \" %Gray% \"Make sure the internet is connected.\"\r\ncall :dk_color2 %_White% \"     - \" %Gray% \"Make sure that Windows update is properly working.\"\r\necho:\r\necho %line%\r\necho:\r\nchoice /C:09 /N /M \">    [9] Continue [0] Go back : \"\r\nif %errorlevel%==1 goto at_menu\r\n\r\ncls\r\nif not defined terminal mode 110, 30\r\n\r\nfor /f %%a in ('%psc% \"(Get-Date).ToString('yyyyMMdd-HHmmssfff')\"') do set _time=%%a\r\n\r\n%psc% Stop-Service TrustedInstaller -force %nul%\r\n\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\backup_cbs_%_time%.log\" %nul%\r\ncopy /y /b \"%SystemRoot%\\logs\\DISM\\dism.log\" \"%SystemRoot%\\logs\\DISM\\backup_dism_%_time%.log\" %nul%\r\ndel /f /q \"%SystemRoot%\\logs\\cbs\\cbs.log\" %nul%\r\ndel /f /q \"%SystemRoot%\\logs\\DISM\\dism.log\" %nul%\r\n\r\necho:\r\necho Applying the command...\r\necho dism /english /online /cleanup-image /restorehealth\r\ndism /english /online /cleanup-image /restorehealth\r\n\r\ntimeout /t 5 %nul1%\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\cbs_%_time%.log\" %nul%\r\ncopy /y /b \"%SystemRoot%\\logs\\DISM\\dism.log\" \"%SystemRoot%\\logs\\DISM\\dism_%_time%.log\" %nul%\r\n\r\nif not exist \"!desktop!\\AT_Logs\\\" md \"!desktop!\\AT_Logs\\\" %nul%\r\ncall :compresslog cbs\\cbs_%_time%.log AT_Logs\\RHealth_CBS %nul%\r\ncall :compresslog DISM\\dism_%_time%.log AT_Logs\\RHealth_DISM %nul%\r\n\r\nif not exist \"!desktop!\\AT_Logs\\RHealth_CBS_%_time%.cab\" (\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"!desktop!\\AT_Logs\\RHealth_CBS_%_time%.log\" %nul%\r\n)\r\n\r\nif not exist \"!desktop!\\AT_Logs\\RHealth_DISM_%_time%.cab\" (\r\ncopy /y /b \"%SystemRoot%\\logs\\DISM\\dism.log\" \"!desktop!\\AT_Logs\\RHealth_DISM_%_time%.log\" %nul%\r\n)\r\n\r\necho:\r\ncall :dk_color %Gray% \"CBS and DISM logs are copied to the AT_Logs folder on your desktop.\"\r\ngoto :at_back\r\n\r\n::========================================================================================================================================\r\n\r\n:sfcscan\r\n\r\ncls\r\nif not defined terminal mode 98, 30\r\ntitle  sfc /scannow\r\n\r\necho:\r\necho %line%\r\necho:    \r\necho      SFC will repair missing or corrupted system files.\r\necho      It is recommended you run the DISM option first before this one.\r\necho      This will take 10-15 minutes or more..\r\necho:\r\necho      If SFC could not fix something, then run the command again to see if it may be able \r\necho      to the next time. Sometimes it may take running the sfc /scannow command 3 times\r\necho      restarting the PC after each time to completely fix everything that it's able to.\r\necho:   \r\necho %line%\r\necho:\r\nchoice /C:09 /N /M \">    [9] Continue [0] Go back : \"\r\nif %errorlevel%==1 goto at_menu\r\n\r\ncls\r\nfor /f %%a in ('%psc% \"(Get-Date).ToString('yyyyMMdd-HHmmssfff')\"') do set _time=%%a\r\n\r\n%psc% Stop-Service TrustedInstaller -force %nul%\r\n\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\backup_cbs_%_time%.log\" %nul%\r\ndel /f /q \"%SystemRoot%\\logs\\cbs\\cbs.log\" %nul%\r\n\r\necho:\r\necho Applying the command...\r\necho sfc /scannow\r\nsfc /scannow\r\n\r\ntimeout /t 5 %nul1%\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"%SystemRoot%\\logs\\cbs\\cbs_%_time%.log\" %nul%\r\n\r\nif not exist \"!desktop!\\AT_Logs\\\" md \"!desktop!\\AT_Logs\\\" %nul%\r\ncall :compresslog cbs\\cbs_%_time%.log AT_Logs\\SFC_CBS %nul%\r\n\r\nif not exist \"!desktop!\\AT_Logs\\SFC_CBS_%_time%.cab\" (\r\ncopy /y /b \"%SystemRoot%\\logs\\cbs\\cbs.log\" \"!desktop!\\AT_Logs\\SFC_CBS_%_time%.log\" %nul%\r\n)\r\n\r\necho:\r\ncall :dk_color %Gray% \"The CBS log was copied to the AT_Logs folder on your Desktop.\"\r\ngoto :at_back\r\n\r\n::========================================================================================================================================\r\n\r\n:retokens\r\n\r\ncls\r\nif not defined terminal (\r\nmode 125, 32\r\n%psc% \"&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}\" %nul%\r\n)\r\ntitle  Fix Licensing ^(ClipSVC ^+ SPP ^+ OSPP^)\r\n\r\nif %winbuild% EQU 6001 (\r\n%eline%\r\necho This option is not supported on Windows Vista SP1.\r\necho Upgrade to Windows Vista SP2.\r\ngoto :at_back\r\n)\r\n\r\necho:\r\necho %line%\r\necho:   \r\necho      Notes:\r\necho:\r\necho       - This option helps in troubleshooting activation issues.\r\necho:\r\necho       - This option will:\r\necho            - Deactivate Windows and Office, you may need to reactivate.\r\necho              If Windows is activated with motherboard / OEM / Digital license\r\necho              then Windows will activate itself again.\r\necho:\r\necho            - Clear ClipSVC, SPP and OSPP licenses.\r\necho            - Fix permissions of SPP tokens folder and registries.\r\necho            - Trigger the repair option for Office.\r\necho:\r\ncall :dk_color2 %_White% \"      - \" %Blue% \"Apply this option only when it is necessary.\"\r\necho:\r\necho %line%\r\necho:\r\nchoice /C:09 /N /M \">    [9] Continue [0] Go back : \"\r\nif %errorlevel%==1 goto at_menu\r\n\r\n::========================================================================================================================================\r\n\r\n::  Rebuild ClipSVC Licences\r\n\r\ncls\r\n:cleanlicensing\r\n\r\necho:\r\necho %line%\r\necho:\r\ncall :dk_color %Blue% \"Rebuilding ClipSVC Licenses...\"\r\necho:\r\n\r\nif %winbuild% LSS 10240 (\r\necho ClipSVC license rebuilding is supported only on Windows 10/11.\r\necho Skipping...\r\ngoto :rebuildspptok\r\n)\r\n\r\n%psc% \"(([WMISEARCHER]'SELECT Name FROM SoftwareLicensingProduct WHERE LicenseStatus=1 AND GracePeriodRemaining=0 AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Name\" %nul2% | findstr /i \"Windows\" %nul1% && (\r\necho Windows is permanently activated.\r\necho Skipping...\r\ngoto :rebuildspptok\r\n)\r\n\r\nset _partial=\r\nset _keymatch=\r\nfor /f \"tokens=2 delims==\" %%# in ('%psc% \"(([WMISEARCHER]'SELECT PartialProductKey FROM SoftwareLicensingProduct WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).PartialProductKey | %% {echo ('PartialProductKey='+$_)}\" %nul6%') do set \"_partial=%%#\"\r\nfor %%# in (8HV2C QPFCT 3V66T PKCKT WXCHW 8TYMD 6F4BT 8HVX7 KD72Y 7CFBY DRR8H P39PB DYJWX MDWWW 9HKR4 M7V2X 2YV77 WT2RQ MHBPB QPF8P 2YV66 VMJ2C DJ4F6 CKFFD YY74H J8JXD BHDCD T6R4W D32MH RRK69 3PJBP) do if /i \"%_partial%\"==\"%%#\" set _keymatch=1\r\n\r\nif not defined _keymatch (\r\necho HWID activation key is not installed.\r\necho Skipping...\r\ngoto :rebuildspptok\r\n)\r\n\r\n%psc% \"If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}\"\r\nif errorlevel 1 (\r\necho Internet is not connected.\r\necho Skipping...\r\ngoto :rebuildspptok\r\n)\r\n\r\nset resfail=\r\nfor %%# in (\r\nlicensing.mp.microsoft.com/v7.0/licenses/content\r\nlogin.live.com/ppsecure/deviceaddcredential.srf\r\npurchase.mp.microsoft.com/v7.0/users/me/orders\r\n) do if not defined resfail (\r\n%psc% \"try { [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; irm https://%%# -Method POST } catch { if ($_.Exception.Response -eq $null) { Write-Host \"\"\"\"[%%#] $($_.Exception.Message)\"\"\"\" -ForegroundColor Red -BackgroundColor Black; exit 3 } }\"\r\nif !errorlevel!==3 set resfail=1\r\n)\r\n\r\nif defined resfail (\r\necho Failed to connect to licensing servers.\r\necho Skipping...\r\ngoto :rebuildspptok\r\n)\r\n\r\necho Stopping ClipSVC service...\r\n%psc% Stop-Service ClipSVC -force %nul%\r\ntimeout /t 2 %nul%\r\n\r\necho:\r\necho Applying the command to clean ClipSVC Licenses...\r\necho rundll32 clipc.dll,ClipCleanUpState\r\n\r\nrundll32 clipc.dll,ClipCleanUpState\r\n\r\nif %winbuild% LEQ 10240 (\r\necho [Successful]\r\n) else (\r\nif exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\tokens.dat\" (\r\ncall :dk_color %Red% \"[Failed]\"\r\n) else (\r\necho [Successful]\r\n)\r\n)\r\n\r\n::  Below registry key (Volatile & Protected) gets created after the ClipSVC License cleanup command, and gets automatically deleted after \r\n::  system restart. It needs to be deleted to activate the system without restart.\r\n\r\nset \"RegKey=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState\"\r\nset \"_ident=HKU\\S-1-5-19\\SOFTWARE\\Microsoft\\IdentityCRL\"\r\n\r\nreg query \"%RegKey%\" %nul% && %nul% call :regownstart\r\nreg delete \"%RegKey%\" /f %nul% \r\n\r\necho:\r\necho Deleting a Volatile ^& Protected Registry Key...\r\necho [%RegKey%]\r\nreg query \"%RegKey%\" %nul% && (\r\ncall :dk_color %Red% \"[Failed]\"\r\necho Reboot your machine using the restart option, that will delete this registry key automatically.\r\n) || (\r\necho [Successful]\r\n)\r\n\r\n::   Clear HWID token related registry to fix activation incase there is any corruption\r\n\r\necho:\r\necho Deleting IdentityCRL Registry Key...\r\necho [%_ident%]\r\nreg delete \"%_ident%\" /f %nul%\r\nreg query \"%_ident%\" %nul% && (\r\ncall :dk_color %Red% \"[Failed]\"\r\n) || (\r\necho [Successful]\r\n)\r\n\r\n%psc% Stop-Service ClipSVC -force %nul%\r\n\r\n::  Rebuild ClipSVC folder to fix permission issues\r\n\r\necho:\r\nif %winbuild% GTR 10240 (\r\necho Deleting folder %ProgramData%\\Microsoft\\Windows\\ClipSVC\\\r\nrmdir /s /q \"C:\\ProgramData\\Microsoft\\Windows\\ClipSvc\" %nul%\r\n\r\nif exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\\" (\r\ncall :dk_color %Red% \"[Failed]\"\r\n) else (\r\necho [Successful]\r\n)\r\n\r\necho:\r\necho Rebuilding the %ProgramData%\\Microsoft\\Windows\\ClipSVC\\ folder...\r\n%psc% Start-Service ClipSVC %nul%\r\ntimeout /t 3 %nul%\r\nif not exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\\" timeout /t 5 %nul%\r\nif not exist \"%ProgramData%\\Microsoft\\Windows\\ClipSVC\\\" (\r\ncall :dk_color %Red% \"[Failed]\"\r\n) else (\r\necho [Successful]\r\n)\r\n)\r\n\r\necho:\r\necho Restarting wlidsvc ^& LicenseManager services...\r\nfor %%# in (wlidsvc LicenseManager) do (%psc% \"Start-Job { Restart-Service %%# } | Wait-Job -Timeout 20 | Out-Null\")\r\n\r\n::========================================================================================================================================\r\n\r\n::  Rebuild SPP Tokens\r\n\r\n:rebuildspptok\r\n\r\necho:\r\necho %line%\r\necho:\r\ncall :dk_color %Blue% \"Rebuilding SPP licensing tokens...\"\r\necho:\r\n\r\necho Clearing KMS Cache...\r\necho:\r\ncall :_taskclear-cache\r\n\r\n%nul% reg query \"HKLM\\%SPPk%\\%_wApp%\" && (\r\necho Removing KMS38 protection...\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':regdel\\:.*';. ([scriptblock]::Create($f[1]))\"\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_wApp%\" /f\r\n%nul% reg query \"HKLM\\%SPPk%\\%_wApp%\" && (\r\ncall :dk_color %Red% \"Failed to remove KMS38 protection.\"\r\n) || (\r\necho Successfully removed KMS38 protection.\r\necho Successfully cleared KMS Cache.\r\n)\r\n) || (\r\necho Successfully cleared KMS Cache.\r\n)\r\necho:\r\n\r\ncall :scandat check\r\n\r\nif not defined token (\r\ncall :dk_color %Red% \"tokens.dat file not found.\"\r\n) else (\r\necho tokens.dat file: [%token%]\r\n)\r\n\r\nset tokenstore=\r\nset badregistry=\r\nfor /f \"skip=2 tokens=2*\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v TokenStore %nul6%') do call set \"tokenstore=%%b\"\r\nif %winbuild% GEQ 9200 if /i not \"%tokenstore%\"==\"%SysPath%\\spp\\store\" if /i not \"%tokenstore%\"==\"%SysPath%\\spp\\store\\2.0\" if /i not \"%tokenstore%\"==\"%SysPath%\\spp\\store_test\\2.0\" (\r\nset badregistry=1\r\necho:\r\ncall :dk_color %Red% \"Correct path not found in TokenStore Registry [%tokenstore%]\"\r\n)\r\n\r\n::  Check sppsvc permissions and apply fixes\r\n\r\nif %winbuild% GEQ 9200 if not defined badregistry (\r\necho:\r\necho Checking SPP permission related issues...\r\ncall :checkperms\r\nif defined permerror (\r\ncall :dk_color %Red% \"[!permerror!]\"\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':fixsppperms\\:.*';. ([scriptblock]::Create($f[1]))\" %nul%\r\ncall :checkperms\r\nif defined permerror (\r\ncall :dk_color %Red% \"[!permerror!] [Failed To Fix]\"\r\n) else (\r\ncall :dk_color %Green% \"[Successfully Fixed]\"\r\n)\r\n) else (\r\necho [No Error Found]\r\n)\r\n)\r\n\r\necho:\r\necho Stopping %_slser% service...\r\n%psc% Stop-Service %_slser% -force %nul%\r\n\r\nset w=\r\nset _sppint=\r\nfor %%# in (SppEx%w%tComObj.exe %_slexe%) do (reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" %nul% && (set _sppint=1))\r\nif defined _sppint (\r\necho:\r\necho Removing SPP IFEO registry keys...\r\nfor %%# in (SppE%w%xtComObj.exe %_slexe%) do (reg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" /f %nul%)\r\n)\r\n\r\nif %winbuild% LSS 9200 if not defined _vis (\r\nREM Fix issues caused by Update KB971033 in Windows 7\r\nREM https://support.microsoft.com/en-us/help/4487266\r\necho:\r\necho Checking Update KB971033...\r\n%psc% \"if (Get-Hotfix -Id KB971033 -ErrorAction SilentlyContinue) {Exit 3}\" %nul%\r\nif !errorlevel!==3 (\r\necho Found, uninstalling it...\r\nwusa /uninstall /quiet /norestart /kb:971033\r\n) else (\r\necho [Not Found]\r\n)\r\n%psc% Stop-Service sppuinotify -force %nul%\r\nsc config sppuinotify start= disabled\r\ndel /f /q %SysPath%\\7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0 /ah\r\n)\r\n\r\n::  Delete registry keys that are not deleted by activation scripts\r\n\r\nif not defined _vis (\r\necho:\r\necho Cleaning some licensing-related registry keys...\r\n%nul% reg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"ServiceSessionId\" /f\r\n%nul% reg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"LicStatusArray\" /f\r\n%nul% reg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"PolicyValuesArray\" /f\r\n%nul% reg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" /v \"actionlist\" /f\r\n%nul% reg delete \"HKLM\\SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform\\data\" /f\r\n)\r\n\r\necho:\r\ncall :scandat delete\r\ncall :scandat check\r\n\r\nif defined token (\r\necho:\r\ncall :dk_color %Red% \"Failed to delete .dat files.\"\r\necho:\r\n)\r\n\r\nif defined _vis (\r\n%psc% Start-Service %_slser% %nul%\r\n)\r\n\r\necho:\r\necho Reinstalling system licenses...\r\n%psc% \"$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif %errorlevel% NEQ 0 %psc% \"$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses\" %nul%\r\nif %errorlevel% EQU 0 (\r\necho [Successful]\r\n) else (\r\ncall :dk_color %Red% \"[Failed]\"\r\n)\r\n\r\ncall :scandat check\r\n\r\necho:\r\nif not defined token (\r\ncall :dk_color %Red% \"Failed to rebuild tokens.dat file.\"\r\n) else (\r\necho tokens.dat file was rebuilt successfully.\r\n)\r\n\r\nif %winbuild% LSS 9200 if not defined _vis (\r\nsc config sppuinotify start= demand\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n::  Rebuild OSPP Tokens\r\n\r\necho:\r\necho %line%\r\necho:\r\ncall :dk_color %Blue% \"Rebuilding OSPP licensing tokens...\"\r\necho:\r\n\r\nsc qc osppsvc %nul% || (\r\necho OSPP-based Office is not installed.\r\necho Skipping rebuilding OSPP tokens...\r\ngoto :repairoffice\r\n)\r\n\r\ncall :scandatospp check\r\n\r\nif not defined token (\r\ncall :dk_color %Red% \"tokens.dat file not found.\"\r\n) else (\r\necho tokens.dat file: [%token%]\r\n)\r\n\r\necho:\r\necho Stopping osppsvc service...\r\n%psc% Stop-Service osppsvc -force %nul%\r\n\r\necho:\r\ncall :scandatospp delete\r\ncall :scandatospp check\r\n\r\nif defined token (\r\necho:\r\ncall :dk_color %Red% \"Failed to delete .dat files.\"\r\necho:\r\n)\r\n\r\necho:\r\necho Starting osppsvc service to generate tokens.dat...\r\n%psc% Start-Service osppsvc %nul%\r\ncall :scandatospp check\r\nif not defined token (\r\n%psc% Stop-Service osppsvc -force %nul%\r\n%psc% Start-Service osppsvc %nul%\r\ntimeout /t 3 %nul%\r\n)\r\n\r\ncall :scandatospp check\r\n\r\necho:\r\nif not defined token (\r\ncall :dk_color %Red% \"Failed to rebuild tokens.dat file.\"\r\n) else (\r\necho tokens.dat file was rebuilt successfully.\r\n)\r\n\r\n::========================================================================================================================================\r\n\r\n:repairoffice\r\n\r\necho:\r\necho %line%\r\necho:\r\ncall :dk_color %Blue% \"Repairing Office licenses...\"\r\necho:\r\n\r\nfor %%# in (68 86) do (\r\nfor %%A in (msi14 msi15 msi16 c2r14 c2r15 c2r16) do (set %%A_%%#=&set %%Arepair%%#=)\r\n)\r\n\r\nset _68=HKLM\\SOFTWARE\\Microsoft\\Office\r\nset _86=HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\r\n\r\nreg query %_68%\\14.0\\CVH /f Click2run /k %nul% && (set \"c2r14_68=Office 14.0 C2R x86/x64\"  & set \"c2r14repair68=\")\r\nreg query %_86%\\14.0\\CVH /f Click2run /k %nul% && (set \"c2r14_86=Office 14.0 C2R x86\"      & set \"c2r14repair86=\")\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi14_86=Office 14.0 MSI x86\"      & call :getrepairsetup msi14repair86 14)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\14.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi14_68=Office 14.0 MSI x86/x64\"  & call :getrepairsetup msi14repair68 14)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi15_86=Office 15.0 MSI x86\"      & call :getrepairsetup msi15repair86 15)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi15_68=Office 15.0 MSI x86/x64\"  & call :getrepairsetup msi15repair68 15)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi16_86=Office 16.0 MSI x86\"      & call :getrepairsetup msi16repair86 16)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\16.0\\Common\\InstallRoot /v Path\" %nul6%') do if exist \"%%b\\*Picker.dll\" (set \"msi16_68=Office 16.0 MSI x86/x64\"  & call :getrepairsetup msi16repair68 16)\r\n\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set \"c2r15_86=Office 15.0 C2R x86\"      & call :getc2rrepair c2r15repair86 integratedoffice.exe)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\15.0\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses\\ProPlus*.xrm-ms\" (set \"c2r15_68=Office 15.0 C2R x86/x64\"  & call :getc2rrepair c2r15repair68 integratedoffice.exe)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_86%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set \"c2r16_86=Office 16.0 C2R x86\"      & call :getc2r16repair c2r16repair86 OfficeClickToRun.exe)\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %_68%\\ClickToRun /v InstallPath\" %nul6%') do if exist \"%%b\\root\\Licenses16\\ProPlus*.xrm-ms\"    (set \"c2r16_68=Office 16.0 C2R x86/x64\"  & call :getc2r16repair c2r16repair68 OfficeClickToRun.exe)\r\n\r\nset uwp16=\r\nif %winbuild% GEQ 10240 (\r\n%psc% \"Get-AppxPackage -name \"Microsoft.Office.Desktop\"\" | find /i \"Office\" %nul1% && set uwp16=Office 16.0 UWP\r\n)\r\n\r\nset /a counter=0\r\necho Checking installed Office versions...\r\necho:\r\n\r\nfor %%# in (\r\n\"%msi14_68%\"\r\n\"%msi14_86%\"\r\n\"%msi15_68%\"\r\n\"%msi15_86%\"\r\n\"%msi16_68%\"\r\n\"%msi16_86%\"\r\n\"%c2r14_68%\"\r\n\"%c2r14_86%\"\r\n\"%c2r15_68%\"\r\n\"%c2r15_86%\"\r\n\"%c2r16_68%\"\r\n\"%c2r16_86%\"\r\n\"%uwp16%\"\r\n) do (\r\nif not \"%%#\"==\"\"\"\" (\r\nset insoff=%%#\r\nset insoff=!insoff:\"=!\r\necho [!insoff!]\r\nset /a counter+=1\r\n)\r\n)\r\n\r\nif %counter% GTR 1 (\r\n%eline%\r\necho Multiple Office versions found.\r\necho It is recommended to only install one version of Office.\r\necho ________________________________________________________________\r\necho:\r\n)\r\n\r\necho:\r\nif %counter% EQU 0 (\r\necho Office ^(2010 and later^) is not installed.\r\ngoto :repairend\r\n) else if not defined c2r16_68 if not defined c2r16_86 (\r\ncall :dk_color %_Yellow% \"A new window will appear, in that window you need to select [Quick Repair] option.\"\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] to continue...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to continue...\"\r\npause %nul1%\r\n)\r\n)\r\n\r\nif defined uwp16 (\r\necho:\r\necho Skipping repair for Office 16.0 UWP... \r\necho:\r\n)\r\n\r\nset c2r14=\r\nif defined c2r14_68 set c2r14=1\r\nif defined c2r14_86 set c2r14=1\r\n\r\nif defined c2r14 (\r\necho:\r\necho Skipping repair for Office 14.0 C2R...\r\necho:\r\n)\r\n\r\nif defined msi14_68 if exist \"%msi14repair68%\" echo Running - \"%msi14repair68%\"                                        & \"%msi14repair68%\"\r\nif defined msi14_86 if exist \"%msi14repair86%\" echo Running - \"%msi14repair86%\"                                        & \"%msi14repair86%\"\r\nif defined msi15_68 if exist \"%msi15repair68%\" echo Running - \"%msi15repair68%\"                                        & \"%msi15repair68%\"\r\nif defined msi15_86 if exist \"%msi15repair86%\" echo Running - \"%msi15repair86%\"                                        & \"%msi15repair86%\"\r\nif defined msi16_68 if exist \"%msi16repair68%\" echo Running - \"%msi16repair68%\"                                        & \"%msi16repair68%\"\r\nif defined msi16_86 if exist \"%msi16repair86%\" echo Running - \"%msi16repair86%\"                                        & \"%msi16repair86%\"\r\nif defined c2r15_68 if exist \"%c2r15repair68%\" echo Running - \"%c2r15repair68%\" REPAIRUI RERUNMODE                     & \"%c2r15repair68%\" REPAIRUI RERUNMODE\r\nif defined c2r15_86 if exist \"%c2r15repair86%\" echo Running - \"%c2r15repair86%\" REPAIRUI RERUNMODE                     & \"%c2r15repair86%\" REPAIRUI RERUNMODE\r\nif defined c2r16_68 if exist \"%c2r16repair68%\" echo Running - \"%c2r16repair68%\" Scenario=Repair RepairType=QuickRepair & \"%c2r16repair68%\" Scenario=Repair RepairType=QuickRepair\r\nif defined c2r16_86 if exist \"%c2r16repair86%\" echo Running - \"%c2r16repair86%\" Scenario=Repair RepairType=QuickRepair & \"%c2r16repair86%\" Scenario=Repair RepairType=QuickRepair\r\n\r\n:repairend\r\n\r\necho:\r\necho %line%\r\necho:\r\necho:\r\ncall :dk_color %Green% \"Finished\"\r\ngoto :at_back\r\n\r\n:getc2rrepair\r\n\r\nfor %%# in (X86 X64) do (\r\nif exist \"%systemdrive%\\Program Files\\Microsoft Office 15\\Client%%#\\%2\" (\r\nset \"%1=%systemdrive%\\Program Files\\Microsoft Office 15\\Client%%#\\%2\"\r\n)\r\n)\r\nexit /b\r\n\r\n:getc2r16repair\r\n\r\nfor %%# in (%_68% %_86%) do (\r\nfor /f \"skip=2 tokens=2*\" %%a in ('\"reg query %%#\\ClickToRun\\Configuration /v ClientFolder\" %nul6%') do if exist \"%%b\\%2\" (set \"%1=%%b\\%2\")\r\n)\r\nexit /b\r\n\r\n:getrepairsetup\r\n\r\nset \"_common86=%systemdrive%\\Program Files (x86)\\Common Files\\Microsoft Shared\\OFFICE%2\\Office Setup Controller\\setup.exe\"\r\nset \"_common68=%systemdrive%\\Program Files\\Common Files\\Microsoft Shared\\OFFICE%2\\Office Setup Controller\\setup.exe\"\r\n\r\nif exist \"%_common86%\" set \"%1=%_common86%\"\r\nif exist \"%_common68%\" set \"%1=%_common68%\"\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:fixwmi\r\n\r\ncls\r\nif not defined terminal mode 98, 34\r\ntitle  Fix WMI\r\n\r\n::  https://techcommunity.microsoft.com/t5/ask-the-performance-team/wmi-repository-corruption-or-not/ba-p/375484\r\n\r\nif exist \"%SystemRoot%\\Servicing\\Packages\\Microsoft-Windows-Server*Edition~*.mum\" (\r\n%eline%\r\necho Rebuilding WMI is not recommended on Windows Server, aborting...\r\ngoto :at_back\r\n)\r\n\r\necho:\r\necho Checking WMI\r\ncall :checkwmi\r\n\r\n::  Apply basic fix first and check\r\n\r\nif defined error (\r\n%psc% Stop-Service Winmgmt -force %nul%\r\nwinmgmt /salvagerepository %nul%\r\ncall :checkwmi\r\n)\r\n\r\nif not defined error (\r\necho [Working]\r\necho No need to apply this option, aborting...\r\ngoto :at_back\r\n)\r\n\r\ncall :dk_color %Red% \"[Not Responding]\"\r\n\r\nset _corrupt=\r\nsc start Winmgmt %nul%\r\nif %errorlevel% EQU 1060 set _corrupt=1\r\nsc query Winmgmt %nul% || set _corrupt=1\r\nfor %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type) do if not defined _corrupt (reg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\Winmgmt /v %%G %nul% || set _corrupt=1)\r\n\r\necho:\r\nif defined _corrupt (\r\n%eline%\r\necho Winmgmt service is corrupted, aborting...\r\ngoto :at_back\r\n)\r\n\r\necho Disabling Winmgmt service\r\nsc config Winmgmt start= disabled %nul%\r\nif %errorlevel% EQU 0 (\r\necho [Successful]\r\n) else (\r\ncall :dk_color %Red% \"[Failed] Aborting...\"\r\nsc config Winmgmt start= auto %nul%\r\ngoto :at_back\r\n)\r\n\r\necho:\r\necho Stopping Winmgmt service\r\n%psc% Stop-Service Winmgmt -force %nul%\r\n%psc% Stop-Service Winmgmt -force %nul%\r\n%psc% Stop-Service Winmgmt -force %nul%\r\nsc query Winmgmt | find /i \"STOPPED\" %nul% && (\r\necho [Successful]\r\n) || (\r\ncall :dk_color %Red% \"[Failed]\"\r\ncall :dk_color %Blue% \"Its recommended to select [Restart] option and then apply Fix WMI option again.\"\r\necho %line%\r\necho:\r\nchoice /C:21 /N /M \"> [1] Restart  [2] Revert Back Changes :\"\r\nif !errorlevel!==1 (sc config Winmgmt start= auto %nul%&goto :at_back)\r\necho:\r\necho Restarting...\r\nshutdown -t 5 -r\r\nexit\r\n)\r\n\r\necho:\r\necho Deleting WMI repository\r\nrmdir /s /q \"%SysPath%\\wbem\\repository\\\" %nul%\r\nif exist \"%SysPath%\\wbem\\repository\\\" (\r\ncall :dk_color %Red% \"[Failed]\"\r\n) else (\r\necho [Successful]\r\n)\r\n\r\necho:\r\necho Enabling Winmgmt service\r\nsc config Winmgmt start= auto %nul%\r\nif %errorlevel% EQU 0 (\r\necho [Successful]\r\n) else (\r\ncall :dk_color %Red% \"[Failed]\"\r\n)\r\n\r\ncall :checkwmi\r\nif not defined error (\r\necho:\r\necho Checking WMI\r\ncall :dk_color %Green% \"[Working]\"\r\ngoto :at_back\r\n)\r\n\r\necho:\r\necho Registering .dll's and Compiling .mof's, .mfl's\r\ncall :registerobj %nul%\r\n\r\necho:\r\necho Checking WMI\r\ncall :checkwmi\r\nif defined error (\r\ncall :dk_color %Red% \"[Not Responding]\"\r\necho:\r\necho Run [Dism RestoreHealth] and [SFC Scannow] options and make sure there are no errors.\r\n) else (\r\ncall :dk_color %Green% \"[Working]\"\r\n)\r\n\r\ngoto :at_back\r\n\r\n:registerobj\r\n\r\n::  https://eskonr.com/2012/01/how-to-fix-wmi-issues-automatically/\r\n\r\n%psc% Stop-Service Winmgmt -force %nul%\r\ncd /d %SysPath%\\wbem\\\r\nregsvr32 /s %SysPath%\\scecli.dll\r\nregsvr32 /s %SysPath%\\userenv.dll\r\nmofcomp cimwin32.mof\r\nmofcomp cimwin32.mfl\r\nmofcomp rsop.mof\r\nmofcomp rsop.mfl\r\nfor /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s\r\nfor /f %%s in ('dir /b *.mof') do mofcomp %%s\r\nfor /f %%s in ('dir /b *.mfl') do mofcomp %%s\r\n\r\nwinmgmt /salvagerepository\r\nwinmgmt /resetrepository\r\nexit /b\r\n\r\n:checkwmi\r\n\r\n::  https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants\r\n\r\nset error=\r\n%psc% \"Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName\" %nul2% | find /i \"computersystem\" %nul1%\r\nif %errorlevel% NEQ 0 (set error=1& exit /b)\r\nwinmgmt /verifyrepository %nul%\r\nif %errorlevel% NEQ 0 (set error=1& exit /b)\r\n\r\n%psc% \"try { $null=([WMISEARCHER]'SELECT * FROM SoftwareLicensingService').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }\" %nul%\r\ncmd /c exit /b %errorlevel%\r\necho \"0x%=ExitCode%\" | findstr /i \"0x800410 0x800440 0x80131501\" %nul1%\r\nif %errorlevel% EQU 0 set error=1\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:at_back\r\n\r\necho:\r\necho %line%\r\necho:\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\ngoto :at_menu\r\n\r\n::========================================================================================================================================\r\n\r\n:compresslog\r\n\r\n::  https://stackoverflow.com/a/46268232\r\n\r\nset \"ddf=\"%SystemRoot%\\Temp\\%Random%%Random%%Random%%Random%\"\"\r\n%nul% del /q /f %ddf%\r\necho/.New Cabinet>%ddf%\r\necho/.set Cabinet=ON>>%ddf%\r\necho/.set CabinetFileCountThreshold=0;>>%ddf%\r\necho/.set Compress=ON>>%ddf%\r\necho/.set CompressionType=LZX>>%ddf%\r\necho/.set CompressionLevel=7;>>%ddf%\r\necho/.set CompressionMemory=21;>>%ddf%\r\necho/.set FolderFileCountThreshold=0;>>%ddf%\r\necho/.set FolderSizeThreshold=0;>>%ddf%\r\necho/.set GenerateInf=OFF>>%ddf%\r\necho/.set InfFileName=nul>>%ddf%\r\necho/.set MaxCabinetSize=0;>>%ddf%\r\necho/.set MaxDiskFileCount=0;>>%ddf%\r\necho/.set MaxDiskSize=0;>>%ddf%\r\necho/.set MaxErrors=1;>>%ddf%\r\necho/.set RptFileName=nul>>%ddf%\r\necho/.set UniqueFiles=ON>>%ddf%\r\nfor /f \"tokens=* delims=\" %%D in ('dir /a:-D/b/s \"%SystemRoot%\\logs\\%1\"') do (\r\n echo/\"%%~fD\"  /inf=no;>>%ddf%\r\n)\r\nmakecab /F %ddf% /D DiskDirectory1=\"\" /D CabinetNameTemplate=\"!desktop!\\%2_%_time%.cab\"\r\ndel /q /f %ddf%\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:checkperms\r\n\r\n::  This code checks if SPP has permission access to tokens folder and required registry keys. Incorrect permissions are often set by gaming spoofers.\r\n\r\nset permerror=\r\nif not exist \"%tokenstore%\\\" set \"permerror=Error Found In Token Folder\"\r\n\r\nif defined ps32onArm exit /b\r\n\r\nfor %%# in (\r\n\"%tokenstore%+FullControl\"\r\n\"HKLM:\\SYSTEM\\WPA+QueryValues, EnumerateSubKeys, WriteKey\"\r\n\"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform+SetValue\"\r\n) do for /f \"tokens=1,2 delims=+\" %%A in (%%#) do if not defined permerror (\r\n%psc% \"$acl = (Get-Acl '%%A' | fl | Out-String); if (-not ($acl -match 'NT SERVICE\\\\sppsvc Allow  %%B') -or ($acl -match 'NT SERVICE\\\\sppsvc Deny')) {Exit 2}\" %nul%\r\nif !errorlevel!==2 (\r\nif \"%%A\"==\"%tokenstore%\" (\r\nset \"permerror=Error Found In Token Folder\"\r\n) else (\r\nset \"permerror=Error Found In SPP Registries\"\r\n)\r\n)\r\n)\r\n\r\nREM  https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application\r\n\r\nif not defined permerror (\r\nreg query \"HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\" %nul% && (\r\nset \"pol=HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\Policies\"\r\nreg query \"!pol!\" %nul% || reg add \"!pol!\" %nul%\r\n%psc% \"$netServ = (New-Object Security.Principal.SecurityIdentifier('S-1-5-20')).Translate([Security.Principal.NTAccount]).Value; $aclString = Get-Acl 'Registry::!pol!' | Format-List | Out-String; if (-not ($aclString.Contains($netServ + ' Allow  FullControl') -or $aclString.Contains('NT SERVICE\\sppsvc Allow  FullControl')) -or ($aclString.Contains('Deny'))) {Exit 3}\" %nul%\r\nif !errorlevel!==3 set \"permerror=Error Found In S-1-5-20 SPP\"\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Clean existing K-M-S cache from the registry\r\n\r\n:_taskclear-cache\r\n\r\nset w=\r\nfor %%# in (SppE%w%xtComObj.exe sppsvc.exe SLsvc.exe) do (\r\nreg delete \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ima%w%ge File Execu%w%tion Options\\%%#\" /f %nul%\r\n)\r\n\r\nset \"OPPk=SOFTWARE\\Microsoft\\OfficeSoftwareProtectionPlatform\"\r\n\r\nif %winbuild% LSS 7600 (\r\nreg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\" %nul% && (\r\nset \"SPPk=SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SL\"\r\n)\r\n)\r\nif not defined SPPk (\r\nset \"SPPk=SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\"\r\n)\r\n\r\nset \"slp=SoftwareLicensingProduct\"\r\nset \"ospp=OfficeSoftwareProtectionProduct\"\r\n\r\nset \"_wApp=55c92734-d682-4d71-983e-d6ec3f16059f\"\r\nset \"_oApp=0ff1ce15-a989-479d-af46-f275c6370663\"\r\nset \"_oA14=59a52881-a989-479d-af46-f275c6370663\"\r\n\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServiceName /reg:32\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v KeyManagementServicePort /reg:32\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v DisableDnsPublishing\r\n%nul% reg delete \"HKLM\\%SPPk%\" /f /v DisableKeyManagementServiceHostCaching\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_wApp%\" /f\r\nif %winbuild% GEQ 9200 (\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_oApp%\" /f\r\n%nul% reg delete \"HKLM\\%SPPk%\\%_oApp%\" /f /reg:32\r\n)\r\nif %winbuild% GEQ 9600 (\r\n%nul% reg delete \"HKU\\S-1-5-20\\%SPPk%\\%_wApp%\" /f\r\n%nul% reg delete \"HKU\\S-1-5-20\\%SPPk%\\%_oApp%\" /f\r\n)\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v KeyManagementServiceName\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v KeyManagementServicePort\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v DisableDnsPublishing\r\n%nul% reg delete \"HKLM\\%OPPk%\" /f /v DisableKeyManagementServiceHostCaching\r\n%nul% reg delete \"HKLM\\%OPPk%\\%_oA14%\" /f\r\n%nul% reg delete \"HKLM\\%OPPk%\\%_oApp%\" /f\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Fix SPP related registry and folder permissions\r\n\r\n:fixsppperms:\r\n# Fix perms for Token Folder\r\n\r\nif ($env:permerror -eq 'Error Found In Token Folder') {\r\n    New-Item -Path $env:tokenstore -ItemType Directory -Force\r\n    $sddl = 'O:BAG:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;GR;;;BU)(A;;FR;;;BU)(A;OICI;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)'\r\n    $AclObject = New-Object System.Security.AccessControl.DirectorySecurity\r\n    $AclObject.SetSecurityDescriptorSddlForm($sddl)\r\n    Set-Acl -Path $env:tokenstore -AclObject $AclObject\r\n    exit\r\n}\r\n\r\n# Fix perms for SPP registries\r\n\r\nif ($env:permerror -eq 'Error Found In SPP Registries') {\r\n    $acl = Get-Acl 'HKLM:\\SYSTEM\\WPA'\r\n    $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\\sppsvc', 'QueryValues, EnumerateSubKeys, WriteKey', 'ContainerInherit, ObjectInherit', 'None', 'Allow')\r\n    $acl.ResetAccessRule($rule)\r\n    $acl.SetAccessRule($rule)\r\n    Set-Acl -Path 'HKLM:\\SYSTEM\\WPA' -AclObject $acl\r\n\t\r\n    $acl = Get-Acl 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform'\r\n    $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\\sppsvc', 'SetValue', 'ContainerInherit, ObjectInherit', 'None', 'Allow')\r\n    $acl.ResetAccessRule($rule)\r\n    $acl.SetAccessRule($rule)\r\n    Set-Acl -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform' -AclObject $acl\r\n    exit\r\n}\r\n\r\n# Fix perms for SPP in HKU\\S-1-5-20\r\n# https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application\r\n\r\nif ($env:permerror -ne 'Error Found In S-1-5-20 SPP') {\r\n    exit\r\n}\r\nif (-not (Test-Path 'Registry::HKU\\S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform')) {\r\n    exit\r\n}\r\n\r\n# https://stackoverflow.com/a/35843420\r\n\r\nfunction Take-Permissions {\r\n    param($rootKey, $key, [System.Security.Principal.SecurityIdentifier]$sid = 'S-1-5-32-545', $recurse = $true)\r\n    \r\n    switch -regex ($rootKey) {\r\n        'HKCU|HKEY_CURRENT_USER' { $rootKey = 'CurrentUser' }\r\n        'HKLM|HKEY_LOCAL_MACHINE' { $rootKey = 'LocalMachine' }\r\n        'HKCR|HKEY_CLASSES_ROOT' { $rootKey = 'ClassesRoot' }\r\n        'HKCC|HKEY_CURRENT_CONFIG' { $rootKey = 'CurrentConfig' }\r\n        'HKU|HKEY_USERS' { $rootKey = 'Users' }\r\n    }\r\n\r\n    ### Step 1 - escalate current process's privilege\r\n    # get SeTakeOwnership, SeBackup and SeRestore privileges before executes next lines, script needs Admin privilege\r\n    $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)\r\n    $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)\r\n    $TypeBuilder = $ModuleBuilder.DefineType(0)\r\n    $TypeBuilder.DefinePInvokeMethod('RtlAdjustPrivilege', 'ntdll.dll', 'Public, Static', 1, [int], @([int], [bool], [bool], [bool].MakeByRefType()), 1, 3) | Out-Null\r\n    9, 17, 18 | ForEach-Object { $TypeBuilder.CreateType()::RtlAdjustPrivilege($_, $true, $false, [ref]$false) | Out-Null }\r\n\r\n    function Take-KeyPermissions {\r\n        param($rootKey, $key, $sid, $recurse, $recurseLevel = 0)\r\n\r\n        ### Step 2 - get ownerships of key - it works only for current key\r\n        $regKey = [Microsoft.Win32.Registry]::$rootKey.OpenSubKey($key, 'ReadWriteSubTree', 'TakeOwnership')\r\n        $acl = New-Object System.Security.AccessControl.RegistrySecurity\r\n        $acl.SetOwner($sid)\r\n        $regKey.SetAccessControl($acl)\r\n\r\n        ### Step 3 - enable inheritance of permissions (not ownership) for current key from parent\r\n        $acl.SetAccessRuleProtection($false, $false)\r\n        $regKey.SetAccessControl($acl)\r\n\r\n        ### Step 4 - only for top-level key, change permissions for current key and propagate it for subkeys\r\n        # to enable propagations for subkeys, it needs to execute Steps 2-3 for each subkey (Step 5)\r\n        if ($recurseLevel -eq 0) {\r\n            $regKey = $regKey.OpenSubKey('', 'ReadWriteSubTree', 'ChangePermissions')\r\n            $rule = New-Object System.Security.AccessControl.RegistryAccessRule($sid, 'FullControl', 'ContainerInherit', 'None', 'Allow')\r\n            $acl.ResetAccessRule($rule)\r\n            $regKey.SetAccessControl($acl)\r\n        }\r\n\r\n        ### Step 5 - recursively repeat steps 2-5 for subkeys\r\n        if ($recurse) {\r\n            foreach ($subKey in $regKey.OpenSubKey('').GetSubKeyNames()) {\r\n                Take-KeyPermissions $rootKey ($key + '\\' + $subKey) $sid $recurse ($recurseLevel + 1)\r\n            }\r\n        }\r\n    }\r\n\r\n    Take-KeyPermissions $rootKey $key $sid $recurse\r\n}\r\n\r\nTake-Permissions \"Users\" \"S-1-5-20\\Software\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\" \"S-1-5-20\"\r\n:fixsppperms:\r\n\r\n::========================================================================================================================================\r\n\r\n::  Install License files using Powershell/WMI instead of slmgr.vbs\r\n\r\n:xrm:\r\nfunction InstallLicenseFile($Lsc) {\r\n    try {\r\n        $null = $sls.InstallLicense([IO.File]::ReadAllText($Lsc))\r\n    } catch {\r\n        $host.SetShouldExit($_.Exception.HResult)\r\n    }\r\n}\r\nfunction InstallLicenseArr($Str) {\r\n    $a = $Str -split ';'\r\n    ForEach ($x in $a) {InstallLicenseFile \"$x\"}\r\n}\r\nfunction InstallLicenseDir($Loc) {\r\n\tGet-ChildItem $Loc -Recurse -Filter *.xrm-ms | ForEach-Object {InstallLicenseFile $_.FullName}\r\n}\r\nfunction ReinstallLicenses() {\r\n\t$Paths = @(\"$env:SysPath\\oem\", \"$env:SysPath\\licensing\", \"$env:SysPath\\spp\\tokens\")\r\n\tforeach ($Path in $Paths) {\r\n    if (Test-Path $Path) { InstallLicenseDir \"$Path\" }\r\n\t}\r\n}\r\n:xrm:\r\n\r\n::========================================================================================================================================\r\n\r\n:scandat\r\n\r\nset token=\r\nfor %%# in (\r\n%SysPath%\\spp\\store_test\\2.0\\\r\n%SysPath%\\spp\\store\\\r\n%SysPath%\\spp\\store\\2.0\\\r\n%Systemdrive%\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareProtectionPlatform\\\r\n%Systemdrive%\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\Microsoft\\SoftwareLicensing\\\r\n) do (\r\n\r\nif %1==check (\r\nif exist %%#tokens.dat set token=%%#tokens.dat\r\n)\r\n\r\nif %1==delete (\r\nif exist %%# (\r\n%nul% dir /a-d /s \"%%#*.dat\" && (\r\nattrib -r -s -h \"%%#*.dat\" /S\r\ndel /S /F /Q \"%%#*.dat\"\r\n)\r\n)\r\n)\r\n)\r\nexit /b\r\n\r\n:scandatospp\r\n\r\nset token=\r\nfor %%# in (\r\n%ProgramData%\\Microsoft\\OfficeSoftwareProtectionPlatform\\\r\n) do (\r\n\r\nif %1==check (\r\nif exist %%#tokens.dat set token=%%#tokens.dat\r\n)\r\n\r\nif %1==delete (\r\nif exist %%# (\r\n%nul% dir /a-d /s \"%%#*.dat\" && (\r\nattrib -r -s -h \"%%#*.dat\" /S\r\ndel /S /F /Q \"%%#*.dat\"\r\n)\r\n)\r\n)\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:regownstart\r\n\r\n%psc% \"$f=[System.IO.File]::ReadAllText('!_batp!') -split ':regown\\:.*';. ([scriptblock]::Create($f[1]));\"\r\nexit /b\r\n\r\n::  Below code takes ownership of a volatile registry key and deletes it\r\n::  HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState\r\n\r\n:regown:\r\n$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)\r\n$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)\r\n$TypeBuilder = $ModuleBuilder.DefineType(0)\r\n\r\n$TypeBuilder.DefinePInvokeMethod('RtlAdjustPrivilege', 'ntdll.dll', 'Public, Static', 1, [int], @([int], [bool], [bool], [bool].MakeByRefType()), 1, 3) | Out-Null\r\n$TypeBuilder.CreateType()::RtlAdjustPrivilege(9, $true, $false, [ref]$false) | Out-Null\r\n\r\n$SID = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544')\r\n$IDN = ($SID.Translate([System.Security.Principal.NTAccount])).Value\r\n$Admin = New-Object System.Security.Principal.NTAccount($IDN)\r\n\r\n$path = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ClipSVC\\Volatile\\PersistedSystemState'\r\n$key = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64').OpenSubKey($path, 'ReadWriteSubTree', 'takeownership')\r\n\r\n$acl = $key.GetAccessControl()\r\n$acl.SetOwner($Admin)\r\n$key.SetAccessControl($acl)\r\n\r\n$rule = New-Object System.Security.AccessControl.RegistryAccessRule($Admin,\"FullControl\",\"Allow\")\r\n$acl.SetAccessRule($rule)\r\n$key.SetAccessControl($acl)\r\n:regown:\r\n\r\n::========================================================================================================================================\r\n\r\n::  This code runs to undo below registry key KMS38 protection\r\n::  HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\55c92734-d682-4d71-983e-d6ec3f16059f\r\n\r\n::  This option is not used in KMS38 anymore, it's here only to remove previous versions protection.\r\n\r\n:regdel:\r\nparam (\r\n    [switch]$protect\r\n)\r\n\r\n$SID = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544')\r\n$Admin = ($SID.Translate([System.Security.Principal.NTAccount])).Value\r\n\r\nif($protect) {\r\n$ruleArgs = @(\"$Admin\", \"Delete, SetValue\", \"ContainerInherit\", \"None\", \"Deny\")\r\n} else {\r\n$ruleArgs = @(\"$Admin\", \"FullControl\", \"Allow\")\r\n}\r\n\r\n$path = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform\\55c92734-d682-4d71-983e-d6ec3f16059f'\r\n$key = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64').OpenSubKey($path, 'ReadWriteSubTree', 'ChangePermissions')\r\n$acl = $key.GetAccessControl()\r\n\r\n$rule = [System.Security.AccessControl.RegistryAccessRule]::new.Invoke($ruleArgs)\r\n$acl.ResetAccessRule($rule)\r\n$key.SetAccessControl($acl)\r\n:regdel:\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_color\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3'\r\n) else if not exist %ps% (\r\necho %~3\r\n)\r\nexit /b\r\n\r\n:dk_color2\r\n\r\nif %_NCS% EQU 1 (\r\necho %esc%[%~1%~2%esc%[%~3%~4%esc%[0m\r\n) else if exist %ps% (\r\n%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'\r\n) else if not exist %ps% (\r\necho %~3 %~6\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n:dk_done\r\n\r\necho:\r\nif %_unattended%==1 timeout /t 2 & exit /b\r\n\r\nif defined fixes (\r\ncall :dk_color %White% \"Follow ALL the ABOVE blue lines.   \"\r\ncall :dk_color2 %Blue% \"Press [1] to Open Support Webpage \" %Gray% \" Press [0] to Ignore\"\r\nchoice /C:10 /N\r\nif !errorlevel!==2 exit /b\r\nif !errorlevel!==1 (start %selfgit% & start %github% & for %%# in (%fixes%) do (start %%#))\r\n)\r\n\r\nif defined terminal (\r\ncall :dk_color %_Yellow% \"Press [0] key to %_exitmsg%...\"\r\nchoice /c 0 /n\r\n) else (\r\ncall :dk_color %_Yellow% \"Press any key to %_exitmsg%...\"\r\npause %nul1%\r\n)\r\n\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n\r\n::  Set variables\r\n\r\n:dk_setvar\r\n\r\nset ps=%SysPath%\\WindowsPowerShell\\v1.0\\powershell.exe\r\nset psc=%ps% -nop -c\r\nset winbuild=1\r\nfor /f \"tokens=2 delims=[]\" %%G in ('ver') do for /f \"tokens=2,3,4 delims=. \" %%H in (\"%%~G\") do set \"winbuild=%%J\"\r\n\r\nset _slexe=sppsvc.exe& set _slser=sppsvc\r\nif %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %winbuild% LSS 7600 if exist \"%SysPath%\\SLsvc.exe\" (set _slexe=SLsvc.exe& set _slser=SLsvc)\r\nif %_slexe%==SLsvc.exe set _vis=1\r\n\r\nset _NCS=1\r\nif %winbuild% LSS 10586 set _NCS=0\r\nif %winbuild% GEQ 10586 reg query \"HKCU\\Console\" /v ForceV2 %nul2% | find /i \"0x0\" %nul1% && (set _NCS=0)\r\n\r\necho \"%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%\" | find /i \"ARM64\" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)\r\n\r\nif %_NCS% EQU 1 (\r\nfor /F %%a in ('echo prompt $E ^| cmd') do set \"esc=%%a\"\r\nset     \"Red=\"41;97m\"\"\r\nset    \"Gray=\"100;97m\"\"\r\nset   \"Green=\"42;97m\"\"\r\nset    \"Blue=\"44;97m\"\"\r\nset   \"White=\"107;91m\"\"\r\nset    \"_Red=\"40;91m\"\"\r\nset  \"_White=\"40;37m\"\"\r\nset  \"_Green=\"40;92m\"\"\r\nset \"_Yellow=\"40;93m\"\"\r\n) else (\r\nset     \"Red=\"Red\" \"white\"\"\r\nset    \"Gray=\"Darkgray\" \"white\"\"\r\nset   \"Green=\"DarkGreen\" \"white\"\"\r\nset    \"Blue=\"Blue\" \"white\"\"\r\nset   \"White=\"White\" \"Red\"\"\r\nset    \"_Red=\"Black\" \"Red\"\"\r\nset  \"_White=\"Black\" \"Gray\"\"\r\nset  \"_Green=\"Black\" \"Green\"\"\r\nset \"_Yellow=\"Black\" \"Yellow\"\"\r\n)\r\n\r\nset \"nceline=echo: &echo ==== ERROR ==== &echo:\"\r\nset \"eline=echo: &call :dk_color %Red% \"==== ERROR ====\" &echo:\"\r\nif %~z0 GEQ 200000 (\r\nset \"_exitmsg=Go back\"\r\nset \"_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option.\"\r\n) else (\r\nset \"_exitmsg=Exit\"\r\nset \"_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option.\"\r\n)\r\nexit /b\r\n\r\n::========================================================================================================================================\r\n:: Leave empty line below\r\n"
  },
  {
    "path": "MAS/Separate-Files-Version/_ReadMe.html",
    "content": "<html>\r\n<meta http-equiv=\"refresh\" content=\"0; url=https://massgrave.dev/\">\r\n</html>"
  },
  {
    "path": "README.md",
    "content": "<p align=\"center\"><img src=\"https://massgrave.dev/img/logo_small.png\" alt=\"MAS Logo\"></p>\r\n\r\n<h1 align=\"center\">Microsoft  Activation  Scripts (MAS)</h1>\r\n\r\n<p align=\"center\">Open-source Windows and Office activator featuring HWID, Ohook, TSforge, and Online KMS activation methods, along with advanced troubleshooting.</p>\r\n\r\n<hr>\r\n  \r\n## How to Activate Windows / Office / Extended Security Updates (ESU)?\r\n\r\n### Method 1 - PowerShell ❤️\r\n\r\n1. Click the **Start Menu**, type `PowerShell`, and open it.\r\n\r\n2. Copy and paste the code below and press **Enter.**  \r\n   - For **Windows 8.1, 10 and 11**:\r\n     ```\r\n     irm https://get.activated.win | iex\r\n     ```\r\n\t If the above is blocked (by ISP/DNS), try this (needs updated Windows 10 or 11):  \r\n\t ```\r\n\t iex (curl.exe -s --doh-url https://1.1.1.1/dns-query https://get.activated.win | Out-String)\r\n\t ```\r\n\t- **Script not launching? Use the below-listed Method 2.**\r\n\r\n3. In the menu that appears, type the number corresponding to one of the **Green** options.\r\n\r\n---\r\n\r\n### Method 2 - Traditional (Windows Vista and later)\r\n\r\n1.   Download the script:\r\n      *   [**MAS_AIO.cmd**](https://dev.azure.com/massgrave/Microsoft-Activation-Scripts/_apis/git/repositories/Microsoft-Activation-Scripts/items?path=/MAS/All-In-One-Version-KL/MAS_AIO.cmd&download=true) (Direct script)\r\n      *   [**MAS_AIO.zip**](https://dev.azure.com/massgrave/Microsoft-Activation-Scripts/_apis/git/repositories/Microsoft-Activation-Scripts/items?$format=zip) (If the direct script is blocked by your browser)\r\n2.   Run the `MAS_AIO.cmd` file.\r\n3.   In the menu that appears, type the number corresponding to one of the **Green** options.\r\n\r\n---\r\n\r\n> [!TIP]\r\n> - Some ISPs/DNS providers block access to our domains. You can bypass this by enabling [DNS-over-HTTPS (DoH)](https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/encrypted-dns-browsers/) in your browser. \r\n> - **Having trouble**? Visit our [troubleshooting page](https://massgrave.dev/troubleshoot) or raise an issue on [GitHub](https://github.com/massgravel/Microsoft-Activation-Scripts/issues).\r\n\r\n> [!NOTE]\r\n>\r\n> - The `irm` command in PowerShell downloads a script from a specified URL, and the `iex` command executes it.\r\n> - Always double-check the URL before executing the command and verify the source is trustworthy when manually downloading files.\r\n> - Be cautious of third parties spreading malware disguised as MAS by altering the URL in the PowerShell command.\r\n\r\n---\r\n\r\n<div align=\"center\">\r\n\t\r\n### Homepage - [https://massgrave.dev/](https://massgrave.dev/)\r\n  \r\n[![1.1]][1]\r\n[![1.2]][2]\r\n[![1.3]][3]\r\n[![1.4]][4]\r\n[![1.5]][5]\r\n[![1.6]][6]\r\n[![1.7]][7]\r\n\r\n[1.1]: https://massgrave.dev/img/logo_discord.png (Chat with us without signup)\r\n[1.2]: https://massgrave.dev/img/logo_reddit.png (Reddit)\r\n[1.3]: https://massgrave.dev/img/logo_bluesky.png (Bluesky)\r\n[1.4]: https://massgrave.dev/img/logo_x.png (Twitter)\r\n\r\n[1.5]: https://massgrave.dev/img/logo_github.png (GitHub)\r\n[1.6]: https://massgrave.dev/img/logo_azuredevops.png (AzureDevOps)\r\n[1.7]: https://massgrave.dev/img/logo_gitea.png (Self-hosted Git)\r\n\r\n[1]: https://discord.gg/j2yFsV5ZVC\r\n[2]: https://www.reddit.com/r/MAS_Activator\r\n[3]: https://bsky.app/profile/massgrave.dev\r\n[4]: https://twitter.com/massgravel\r\n[5]: https://github.com/massgravel/Microsoft-Activation-Scripts\r\n[6]: https://dev.azure.com/massgrave/_git/Microsoft-Activation-Scripts\r\n[7]: https://git.activated.win/Microsoft-Activation-Scripts\r\n\r\n---\r\n\r\nLatest Version: 3.10  \r\nRelease date: 28-Jan-2026\r\n"
  }
]