MAS_AIO.cmd 652 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580
  1. @::u78r-random
  2. @set masver=3.0
  3. @setlocal DisableDelayedExpansion
  4. @echo off
  5. :: For command line switches, check mass<>grave<.>dev/command_line_switches
  6. :: If you want to better understand script, read from MAS separate files version.
  7. ::============================================================================
  8. ::
  9. :: Homepage: mass<>grave<.>dev
  10. :: Email: mas.help@outlook.com
  11. ::
  12. ::============================================================================
  13. ::========================================================================================================================================
  14. :: Set environment variables, it helps if they are misconfigured in the system
  15. setlocal EnableExtensions
  16. setlocal DisableDelayedExpansion
  17. set "PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
  18. set "SysPath=%SystemRoot%\System32"
  19. set "Path=%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\"
  20. if exist "%SystemRoot%\Sysnative\reg.exe" (
  21. set "SysPath=%SystemRoot%\Sysnative"
  22. set "Path=%SystemRoot%\Sysnative;%SystemRoot%;%SystemRoot%\Sysnative\Wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%Path%"
  23. )
  24. set "ComSpec=%SysPath%\cmd.exe"
  25. set "PSModulePath=%ProgramFiles%\WindowsPowerShell\Modules;%SysPath%\WindowsPowerShell\v1.0\Modules"
  26. set re1=
  27. set re2=
  28. set "_cmdf=%~f0"
  29. for %%# in (%*) do (
  30. if /i "%%#"=="re1" set re1=1
  31. if /i "%%#"=="re2" set re2=1
  32. )
  33. :: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows
  34. :: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows
  35. if exist %SystemRoot%\Sysnative\cmd.exe if not defined re1 (
  36. setlocal EnableDelayedExpansion
  37. start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" %* re1"
  38. exit /b
  39. )
  40. :: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows
  41. if exist %SystemRoot%\SysArm32\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (
  42. setlocal EnableDelayedExpansion
  43. start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" %* re2"
  44. exit /b
  45. )
  46. ::========================================================================================================================================
  47. set "blank="
  48. set "mas=ht%blank%tps%blank%://mass%blank%grave.dev/"
  49. :: Check if Null service is working, it's important for the batch script
  50. sc query Null | find /i "RUNNING"
  51. if %errorlevel% NEQ 0 (
  52. echo:
  53. echo Null service is not running, script may crash...
  54. echo:
  55. echo:
  56. echo Help - %mas%fix_service
  57. echo:
  58. echo:
  59. ping 127.0.0.1 -n 20
  60. )
  61. cls
  62. :: Check LF line ending
  63. pushd "%~dp0"
  64. >nul findstr /v "$" "%~nx0" && (
  65. echo:
  66. echo Error - Script either has LF line ending issue or an empty line at the end of the script is missing.
  67. echo:
  68. echo:
  69. echo Help - %mas%troubleshoot
  70. echo:
  71. echo:
  72. ping 127.0.0.1 -n 20 >nul
  73. popd
  74. exit /b
  75. )
  76. popd
  77. ::========================================================================================================================================
  78. cls
  79. color 07
  80. title Microsoft_Activation_Scripts %masver%
  81. set _args=
  82. set _elev=
  83. set _unattended=0
  84. set _args=%*
  85. if defined _args set _args=%_args:"=%
  86. if defined _args set _args=%_args:re1=%
  87. if defined _args set _args=%_args:re2=%
  88. if defined _args (
  89. for %%A in (%_args%) do (
  90. if /i "%%A"=="-el" set _elev=1
  91. )
  92. )
  93. if defined _args echo "%_args%" | find /i "/" >nul && set _unattended=1
  94. ::========================================================================================================================================
  95. set "nul1=1>nul"
  96. set "nul2=2>nul"
  97. set "nul6=2^>nul"
  98. set "nul=>nul 2>&1"
  99. call :dk_setvar
  100. if %winbuild% EQU 1 (
  101. %eline%
  102. echo Failed to detect Windows build number.
  103. echo:
  104. setlocal EnableDelayedExpansion
  105. set fixes=%fixes% %mas%troubleshoot
  106. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  107. goto dk_done
  108. )
  109. if %winbuild% LSS 7600 (
  110. %nceline%
  111. echo Unsupported OS version detected [%winbuild%].
  112. echo Project is supported only for Windows 7/8/8.1/10/11 and their Server equivalents.
  113. goto dk_done
  114. )
  115. ::========================================================================================================================================
  116. :: Fix special character limitations in path name
  117. set "_work=%~dp0"
  118. if "%_work:~-1%"=="\" set "_work=%_work:~0,-1%"
  119. set "_batf=%~f0"
  120. set "_batp=%_batf:'=''%"
  121. set _PSarg="""%~f0""" -el %_args%
  122. set _PSarg=%_PSarg:'=''%
  123. set "_ttemp=%userprofile%\AppData\Local\Temp"
  124. setlocal EnableDelayedExpansion
  125. ::========================================================================================================================================
  126. echo "!_batf!" | find /i "!_ttemp!" %nul1% && (
  127. if /i not "!_work!"=="!_ttemp!" (
  128. %eline%
  129. echo The script was launched from the temp folder.
  130. echo You are most likely running the script directly from the archive file.
  131. echo:
  132. echo Extract the archive file and launch the script from the extracted folder.
  133. goto dk_done
  134. )
  135. )
  136. ::========================================================================================================================================
  137. :: Check PowerShell
  138. REM :PStest: $ExecutionContext.SessionState.LanguageMode :PStest:
  139. cmd /c "%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':PStest:\s*';iex ($f[1])"" | find /i "FullLanguage" %nul1% || (
  140. %eline%
  141. cmd /c "%psc% "$ExecutionContext.SessionState.LanguageMode""
  142. echo:
  143. cmd /c "%psc% "$ExecutionContext.SessionState.LanguageMode"" | find /i "FullLanguage" %nul1% && (
  144. echo Failed to run Powershell command but Powershell is working.
  145. echo:
  146. cmd /c "%psc% ""$av = Get-WmiObject -Namespace root\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { if ($i.displayName -notlike '*windows*') { $n += $i.displayName } }; if ($n) { Write-Host ('Installed 3rd party Antivirus might be blocking the script - ' + ($n -join ', ')) -ForegroundColor White -BackgroundColor Blue }"""
  147. echo:
  148. set fixes=%fixes% %mas%troubleshoot
  149. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  150. ) || (
  151. echo PowerShell is not working. Aborting...
  152. echo If you have applied restrictions on Powershell then undo those changes.
  153. echo:
  154. set fixes=%fixes% %mas%fix_powershell
  155. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%fix_powershell"
  156. )
  157. goto dk_done
  158. )
  159. ::========================================================================================================================================
  160. :: Elevate script as admin and pass arguments and preventing loop
  161. %nul1% fltmc || (
  162. if not defined _elev %psc% "start cmd.exe -arg '/c \"!_PSarg!\"' -verb runas" && exit /b
  163. %eline%
  164. echo This script needs admin rights.
  165. echo Right click on this script and select 'Run as administrator'.
  166. goto dk_done
  167. )
  168. ::========================================================================================================================================
  169. :: Disable QuickEdit and launch from conhost.exe to avoid Terminal app
  170. if %winbuild% GEQ 17763 (
  171. set terminal=1
  172. ) else (
  173. set terminal=
  174. )
  175. :: Check if script is running in Terminal app
  176. set r1=$TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);
  177. set r2=%r1% [void]$TB.DefinePInvokeMethod('GetConsoleWindow', 'kernel32.dll', 22, 1, [IntPtr], @(), 1, 3).SetImplementationFlags(128);
  178. set r3=%r2% [void]$TB.DefinePInvokeMethod('SendMessageW', 'user32.dll', 22, 1, [IntPtr], @([IntPtr], [UInt32], [IntPtr], [IntPtr]), 1, 3).SetImplementationFlags(128);
  179. set d1=%r3% $hIcon = $TB.CreateType(); $hWnd = $hIcon::GetConsoleWindow();
  180. set d2=%d1% echo $($hIcon::SendMessageW($hWnd, 127, 0, 0) -ne [IntPtr]::Zero);
  181. if defined terminal (
  182. %psc% "%d2%" %nul2% | find /i "True" %nul1% && set terminal=
  183. )
  184. if defined ps32onArm goto :skipQE
  185. if %_unattended%==1 goto :skipQE
  186. for %%# in (%_args%) do (if /i "%%#"=="-qedit" goto :skipQE)
  187. if defined terminal (
  188. set "launchcmd=start conhost.exe %psc%"
  189. ) else (
  190. set "launchcmd=%psc%"
  191. )
  192. :: Disable QuickEdit in current session
  193. set "d1=$t=[AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);"
  194. set "d2=$t.DefinePInvokeMethod('GetStdHandle', 'kernel32.dll', 22, 1, [IntPtr], @([Int32]), 1, 3).SetImplementationFlags(128);"
  195. set "d3=$t.DefinePInvokeMethod('SetConsoleMode', 'kernel32.dll', 22, 1, [Boolean], @([IntPtr], [Int32]), 1, 3).SetImplementationFlags(128);"
  196. set "d4=$k=$t.CreateType(); $b=$k::SetConsoleMode($k::GetStdHandle(-10), 0x0080);"
  197. %launchcmd% "%d1% %d2% %d3% %d4% & cmd.exe '/c' '!_PSarg! -qedit'" && (exit /b) || (set terminal=1)
  198. :skipQE
  199. ::========================================================================================================================================
  200. :: Check for updates
  201. set -=
  202. set old=
  203. set upver=%masver:.=%
  204. for /f "delims=[] tokens=2" %%# in ('ping -4 -n 1 activ%-%ated.win') do (
  205. if not "%%#"=="" set old=1
  206. for /f "delims=[] tokens=2" %%# in ('ping -4 -n 1 updatecheck%upver%.activ%-%ated.win') do (
  207. if not "%%#"=="" set old=
  208. )
  209. )
  210. if defined old (
  211. echo ________________________________________________
  212. %eline%
  213. echo Your version of MAS [%masver%] is outdated.
  214. echo ________________________________________________
  215. echo:
  216. if not %_unattended%==1 (
  217. echo [1] Get Latest MAS
  218. echo [0] Continue Anyway
  219. echo:
  220. call :dk_color %_Green% "Choose a menu option using your keyboard [1,0] :"
  221. choice /C:10 /N
  222. if !errorlevel!==2 rem
  223. if !errorlevel!==1 (start %mas% & exit /b)
  224. )
  225. )
  226. ::========================================================================================================================================
  227. if not exist "%SystemRoot%\Temp\" mkdir "%SystemRoot%\Temp" %nul%
  228. :: Run script with parameters in unattended mode
  229. set _elev=
  230. if defined _args echo "%_args%" | find /i "/S" %nul% && (set "_silent=%nul%") || (set _silent=)
  231. if defined _args echo "%_args%" | find /i "/" %nul% && (
  232. echo "%_args%" | find /i "/HWID" %nul% && (setlocal & cls & (call :HWIDActivation %_args% %_silent%) & endlocal)
  233. echo "%_args%" | find /i "/KMS38" %nul% && (setlocal & cls & (call :KMS38Activation %_args% %_silent%) & endlocal)
  234. echo "%_args%" | find /i "/Z-" %nul% && (setlocal & cls & (call :TSforgeActivation %_args% %_silent%) & endlocal)
  235. echo "%_args%" | find /i "/K-" %nul% && (setlocal & cls & (call :KMSActivation %_args% %_silent%) & endlocal)
  236. echo "%_args%" | find /i "/Ohook" %nul% && (setlocal & cls & (call :OhookActivation %_args% %_silent%) & endlocal)
  237. exit /b
  238. )
  239. ::========================================================================================================================================
  240. setlocal DisableDelayedExpansion
  241. :: Check desktop location
  242. set desktop=
  243. for /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"
  244. if not defined desktop for /f "delims=" %%a in ('%psc% "& {write-host $([Environment]::GetFolderPath('Desktop'))}"') do call set "desktop=%%a"
  245. set "_pdesk=%desktop:'=''%"
  246. setlocal EnableDelayedExpansion
  247. if not defined desktop (
  248. %eline%
  249. echo Unable to detect Desktop location, aborting...
  250. goto dk_done
  251. )
  252. ::========================================================================================================================================
  253. :MainMenu
  254. cls
  255. color 07
  256. title Microsoft %blank%Activation %blank%Scripts %masver%
  257. if not defined terminal mode 76, 34
  258. if %winbuild% GEQ 10240 if not exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" if not exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" set _hwidgo=1
  259. if %winbuild% GTR 14393 if exist "%SysPath%\spp\tokens\skus\EnterpriseSN\" set _hwidgo=
  260. if not defined _hwidgo set _tsforgego=1
  261. if %winbuild% GEQ 9200 set _ohookgo=1
  262. if %winbuild% LSS 9200 set _okmsgo=1
  263. echo:
  264. echo:
  265. echo:
  266. echo:
  267. echo: ______________________________________________________________
  268. echo:
  269. echo: Activation Methods:
  270. echo:
  271. if defined _hwidgo (
  272. call :dk_color3 %_White% " [1] " %_Green% "HWID" %_White% " - Windows"
  273. ) else (
  274. echo: [1] HWID - Windows
  275. )
  276. if defined _ohookgo (
  277. call :dk_color3 %_White% " [2] " %_Green% "Ohook" %_White% " - Office"
  278. ) else (
  279. echo: [2] Ohook - Office
  280. )
  281. if defined _tsforgego (
  282. call :dk_color3 %_White% " [3] " %_Green% "TSforge" %_White% " - Windows / Office / ESU"
  283. ) else (
  284. echo: [3] TSforge - Windows / Office / ESU
  285. )
  286. echo: [4] KMS38 - Windows
  287. if defined _okmsgo (
  288. call :dk_color3 %_White% " [5] " %_Green% "Online KMS" %_White% " - Windows / Office"
  289. ) else (
  290. echo: [5] Online KMS - Windows / Office
  291. )
  292. echo: __________________________________________________
  293. echo:
  294. echo: [6] Check Activation Status
  295. echo: [7] Change Windows Edition
  296. echo: [8] Change Office Edition
  297. echo: __________________________________________________
  298. echo:
  299. echo: [9] Troubleshoot
  300. echo: [E] Extras
  301. echo: [H] Help
  302. echo: [0] Exit
  303. echo: ______________________________________________________________
  304. echo:
  305. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,3...E,H,0] :"
  306. choice /C:123456789EH0 /N
  307. set _erl=%errorlevel%
  308. if %_erl%==12 exit /b
  309. if %_erl%==11 start %mas%troubleshoot & goto :MainMenu
  310. if %_erl%==10 goto :Extras
  311. if %_erl%==9 setlocal & call :troubleshoot & cls & endlocal & goto :MainMenu
  312. if %_erl%==8 setlocal & call :change_offedition & cls & endlocal & goto :MainMenu
  313. if %_erl%==7 setlocal & call :change_winedition & cls & endlocal & goto :MainMenu
  314. if %_erl%==6 setlocal & call :check_actstatus & cls & endlocal & goto :MainMenu
  315. if %_erl%==5 setlocal & call :KMSActivation & cls & endlocal & goto :MainMenu
  316. if %_erl%==4 setlocal & call :KMS38Activation & cls & endlocal & goto :MainMenu
  317. if %_erl%==3 setlocal & call :TSforgeActivation & cls & endlocal & goto :MainMenu
  318. if %_erl%==2 setlocal & call :OhookActivation & cls & endlocal & goto :MainMenu
  319. if %_erl%==1 setlocal & call :HWIDActivation & cls & endlocal & goto :MainMenu
  320. goto :MainMenu
  321. :dk_color3
  322. if %_NCS% EQU 1 (
  323. echo %esc%[%~1%~2%esc%[%~3%~4%esc%[%~5%~6%esc%[0m
  324. ) else (
  325. %psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'-NoNewline; write-host -back '%7' -fore '%8' '%9'
  326. )
  327. exit /b
  328. ::========================================================================================================================================
  329. :Extras
  330. cls
  331. title Extras
  332. if not defined terminal mode 76, 30
  333. echo:
  334. echo:
  335. echo:
  336. echo:
  337. echo:
  338. echo: ______________________________________________________
  339. echo:
  340. echo: [1] Extract $OEM$ Folder
  341. echo:
  342. echo: [2] Download Genuine Windows / Office
  343. echo: ____________________________________________
  344. echo:
  345. echo: [0] Go to Main Menu
  346. echo: ______________________________________________________
  347. echo:
  348. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,0] :"
  349. choice /C:120 /N
  350. set _erl=%errorlevel%
  351. if %_erl%==3 goto :MainMenu
  352. if %_erl%==2 start %mas%genuine-installation-media & goto :Extras
  353. if %_erl%==1 goto :Extract$OEM$
  354. goto :Extras
  355. ::========================================================================================================================================
  356. :Extract$OEM$
  357. cls
  358. title Extract $OEM$ Folder
  359. if not defined terminal mode 76, 30
  360. if exist "!desktop!\$OEM$\" (
  361. %eline%
  362. echo $OEM$ folder already exists on the Desktop.
  363. echo _____________________________________________________
  364. echo:
  365. call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
  366. choice /c 0 /n
  367. goto :Extras
  368. )
  369. :Extract$OEM$2
  370. cls
  371. title Extract $OEM$ Folder
  372. if not defined terminal mode 78, 30
  373. echo:
  374. echo:
  375. echo:
  376. echo:
  377. echo: Extract $OEM$ folder on the desktop
  378. echo: ____________________________________________________________
  379. echo:
  380. echo: [1] HWID [Windows]
  381. echo: [2] Ohook [Office]
  382. echo: [3] TSforge [Windows / ESU / Office]
  383. echo: [4] KMS38 [Windows]
  384. echo: [5] Online KMS [Windows / Office]
  385. echo:
  386. echo: [6] HWID [Windows] ^+ Ohook [Office]
  387. echo: [7] HWID [Windows] ^+ Ohook [Office] ^+ TSforge [ESU]
  388. echo: [8] TSforge [Windows] ^+ Online KMS [Office]
  389. echo:
  390. call :dk_color2 %_White% " [R] " %_Green% "ReadMe"
  391. echo: [0] Go Back
  392. echo: ____________________________________________________________
  393. echo:
  394. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard :"
  395. choice /C:12345678R0 /N
  396. set _erl=%errorlevel%
  397. if %_erl%==10 goto:Extras
  398. if %_erl%==9 start %mas%oem-folder &goto:Extract$OEM$2
  399. if %_erl%==8 (set "_oem=TSforge [Windows] + Online KMS [Office]" & set "para=/Z-Windows /K-Office" &goto:Extract$OEM$3)
  400. if %_erl%==7 (set "_oem=HWID [Windows] + Ohook [Office] + TSforge [ESU]" & set "para=/HWID /Ohook /Z-ESU" &goto:Extract$OEM$3)
  401. if %_erl%==6 (set "_oem=HWID [Windows] + Ohook [Office]" & set "para=/HWID /Ohook" &goto:Extract$OEM$3)
  402. if %_erl%==5 (set "_oem=Online KMS" & set "para=/K-WindowsOffice" &goto:Extract$OEM$3)
  403. if %_erl%==4 (set "_oem=KMS38" & set "para=/KMS38" &goto:Extract$OEM$3)
  404. if %_erl%==3 (set "_oem=TSforge" & set "para=/Z-WindowsESUOffice" &goto:Extract$OEM$3)
  405. if %_erl%==2 (set "_oem=Ohook" & set "para=/Ohook" &goto:Extract$OEM$3)
  406. if %_erl%==1 (set "_oem=HWID" & set "para=/HWID" &goto:Extract$OEM$3)
  407. goto :Extract$OEM$2
  408. ::========================================================================================================================================
  409. :Extract$OEM$3
  410. cls
  411. set "_dir=!desktop!\$OEM$\$$\Setup\Scripts"
  412. md "!_dir!\"
  413. :: Add random data on top to create unique file which helps in avoiding AV's detections
  414. %psc% "$f=[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)"
  415. (
  416. echo @echo off
  417. echo fltmc ^>nul ^|^| exit /b
  418. echo call "%%~dp0MAS_AIO.cmd" %para%
  419. echo cd \
  420. echo ^(goto^) 2^>nul ^& ^(if "%%~dp0"=="%%SystemRoot%%\Setup\Scripts\" rd /s /q "%%~dp0"^)
  421. )>"!_dir!\SetupComplete.cmd"
  422. set _error=
  423. if not exist "!_dir!\MAS_AIO.cmd" set _error=1
  424. if not exist "!_dir!\SetupComplete.cmd" set _error=1
  425. if defined _error (
  426. %eline%
  427. echo The script failed to create the $OEM$ folder.
  428. if exist "!desktop!\$OEM$\.*" rmdir /s /q "!desktop!\$OEM$\" %nul%
  429. ) else (
  430. echo:
  431. call :dk_color %Blue% "%_oem%"
  432. call :dk_color %Green% "$OEM$ folder was successfully created on your Desktop."
  433. )
  434. echo "%_oem%" | find /i "KMS38" 1>nul && (
  435. echo:
  436. echo To KMS38 activate Server Cor/Acor editions ^(No GUI Versions^),
  437. echo Check this page %mas%oem-folder
  438. )
  439. echo ___________________________________________________________________
  440. echo:
  441. call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
  442. choice /c 0 /n
  443. goto Extras
  444. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  445. :HWIDActivation
  446. :: To activate, run the script with "/HWID" parameter or change 0 to 1 in below line
  447. set _act=0
  448. :: 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
  449. set _NoEditionChange=0
  450. :: If value is changed in above lines or parameter is used then script will run in unattended mode
  451. ::========================================================================================================================================
  452. cls
  453. color 07
  454. title HWID Activation %masver%
  455. set _args=
  456. set _elev=
  457. set _unattended=0
  458. set _args=%*
  459. if defined _args set _args=%_args:"=%
  460. if defined _args (
  461. for %%A in (%_args%) do (
  462. if /i "%%A"=="/HWID" set _act=1
  463. if /i "%%A"=="/HWID-NoEditionChange" set _NoEditionChange=1
  464. if /i "%%A"=="-el" set _elev=1
  465. )
  466. )
  467. for %%A in (%_act% %_NoEditionChange%) do (if "%%A"=="1" set _unattended=1)
  468. ::========================================================================================================================================
  469. if %winbuild% LSS 10240 (
  470. %eline%
  471. echo Unsupported OS version detected [%winbuild%].
  472. echo HWID Activation is only supported on Windows 10/11.
  473. echo:
  474. call :dk_color %Blue% "Use TSforge activation option from the main menu."
  475. goto dk_done
  476. )
  477. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
  478. %eline%
  479. echo HWID Activation is not supported on Windows Server.
  480. call :dk_color %Blue% "Use TSforge activation option from the main menu."
  481. goto dk_done
  482. )
  483. setlocal EnableDelayedExpansion
  484. ::========================================================================================================================================
  485. cls
  486. if not defined terminal (
  487. mode 110, 34
  488. if exist "%SysPath%\spp\store_test\" mode 134, 34
  489. )
  490. title HWID Activation %masver%
  491. echo:
  492. echo Initializing...
  493. call :dk_chkmal
  494. for %%# in (
  495. sppsvc.exe
  496. ClipUp.exe
  497. ) do (
  498. if not exist %SysPath%\%%# (
  499. %eline%
  500. echo [%SysPath%\%%#] file is missing, aborting...
  501. echo:
  502. set fixes=%fixes% %mas%troubleshoot
  503. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  504. goto dk_done
  505. )
  506. )
  507. ::========================================================================================================================================
  508. set spp=SoftwareLicensingProduct
  509. set sps=SoftwareLicensingService
  510. call :dk_ckeckwmic
  511. call :dk_checksku
  512. call :dk_product
  513. call :dk_sppissue
  514. ::========================================================================================================================================
  515. :: Check if system is permanently activated or not
  516. call :dk_checkperm
  517. if defined _perm (
  518. cls
  519. echo ___________________________________________________________________________________________
  520. echo:
  521. call :dk_color2 %_White% " " %Green% "%winos% is already permanently activated."
  522. echo ___________________________________________________________________________________________
  523. if %_unattended%==1 goto dk_done
  524. echo:
  525. choice /C:10 /N /M "> [1] Activate Anyway [0] %_exitmsg% : "
  526. if errorlevel 2 exit /b
  527. )
  528. cls
  529. ::========================================================================================================================================
  530. :: Check Evaluation version
  531. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" (
  532. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Eval" %nul1% && (
  533. %eline%
  534. echo [%winos% ^| %winbuild%]
  535. echo:
  536. echo Evaluation editions cannot be activated outside of their evaluation period.
  537. call :dk_color %Blue% "Use TSforge activation option from the main menu to reset evaluation period."
  538. echo:
  539. set fixes=%fixes% %mas%evaluation_editions
  540. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%evaluation_editions"
  541. goto dk_done
  542. )
  543. )
  544. ::========================================================================================================================================
  545. set error=
  546. cls
  547. echo:
  548. call :dk_showosinfo
  549. :: Check Internet connection
  550. set _int=
  551. for %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (
  552. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
  553. )
  554. if not defined _int (
  555. %psc% "If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}"
  556. if !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)
  557. )
  558. if defined _int (
  559. echo Checking Internet Connection [Connected%ping_f%]
  560. ) else (
  561. set error=1
  562. call :dk_color %Red% "Checking Internet Connection [Not Connected]"
  563. call :dk_color %Blue% "Internet is required for HWID activation."
  564. )
  565. ::========================================================================================================================================
  566. echo Initiating Diagnostic Tests...
  567. set "_serv=ClipSVC wlidsvc sppsvc KeyIso LicenseManager Winmgmt"
  568. :: Client License Service (ClipSVC)
  569. :: Microsoft Account Sign-in Assistant
  570. :: Software Protection
  571. :: CNG Key Isolation
  572. :: Windows License Manager Service
  573. :: Windows Management Instrumentation
  574. call :dk_errorcheck
  575. ::========================================================================================================================================
  576. :: Detect Key
  577. set key=
  578. set altkey=
  579. set changekey=
  580. set altapplist=
  581. set altedition=
  582. set notworking=
  583. call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  584. if defined allapps call :hwiddata key
  585. if not defined key (
  586. for /f "delims=" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':getactivationid\:.*';iex ($f[1])"') do (set altapplist=%%a)
  587. if defined altapplist call :hwiddata key
  588. )
  589. if defined notworking call :hwidfallback
  590. if not defined key call :hwidfallback
  591. if defined altkey (set key=%altkey%&set changekey=1&set notworking=)
  592. if defined notworking if defined notfoundaltactID (
  593. call :dk_color %Red% "Checking Alternate Edition For HWID [%altedition% Activation ID Not Found]"
  594. )
  595. if not defined key (
  596. %eline%
  597. echo [%winos% ^| %winbuild% ^| SKU:%osSKU%]
  598. if not defined skunotfound (
  599. echo This product does not support HWID activation.
  600. echo Make sure you are using the latest version of the script.
  601. echo If you are, then try TSforge activation option from the main menu.
  602. set fixes=%fixes% %mas%
  603. echo %mas%
  604. ) else (
  605. echo Required license files not found in %SysPath%\spp\tokens\skus\
  606. set fixes=%fixes% %mas%troubleshoot
  607. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  608. )
  609. echo:
  610. goto dk_done
  611. )
  612. if defined notworking set error=1
  613. ::========================================================================================================================================
  614. :: Install key
  615. echo:
  616. if defined changekey (
  617. call :dk_color %Blue% "[%altedition%] edition product key will be used to enable HWID activation."
  618. echo:
  619. )
  620. if defined winsub (
  621. call :dk_color %Blue% "Windows Subscription [SKU ID-%slcSKU%] detected. Script will activate base edition [SKU ID-%regSKU%]."
  622. echo:
  623. )
  624. call :dk_inskey "[%key%]"
  625. ::========================================================================================================================================
  626. :: Change Windows region to USA to avoid activation issues as Windows store license is not available in many countries
  627. for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Control Panel\International\Geo" /v Name %nul6%') do set "name=%%b"
  628. for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Control Panel\International\Geo" /v Nation %nul6%') do set "nation=%%b"
  629. set regionchange=
  630. if not "%name%"=="US" (
  631. set regionchange=1
  632. %psc% "Set-WinHomeLocation -GeoId 244" %nul%
  633. if !errorlevel! EQU 0 (
  634. echo Changing Windows Region To USA [Successful]
  635. ) else (
  636. call :dk_color %Red% "Changing Windows Region To USA [Failed]"
  637. )
  638. )
  639. ::==========================================================================================================================================
  640. :: Generate GenuineTicket.xml and apply
  641. :: In some cases clipup -v -o method fails and in some cases service restart method fails as well
  642. :: To maximize success rate and get better error details, script will install tickets two times (service restart + clipup -v -o)
  643. set "tdir=%ProgramData%\Microsoft\Windows\ClipSVC\GenuineTicket"
  644. if not exist "%tdir%\" md "%tdir%\" %nul%
  645. if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
  646. if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
  647. if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*" del /f /q "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*" %nul%
  648. call :hwiddata ticket
  649. copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%
  650. if not exist "%tdir%\GenuineTicket.xml" (
  651. call :dk_color %Red% "Generating GenuineTicket.xml [Failed, aborting...]"
  652. echo [%encoded%]
  653. if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
  654. goto :dl_final
  655. ) else (
  656. echo Generating GenuineTicket.xml [Successful]
  657. )
  658. set "_xmlexist=if exist "%tdir%\GenuineTicket.xml""
  659. %_xmlexist% (
  660. %psc% "Start-Job { Restart-Service ClipSVC } | Wait-Job -Timeout 20 | Out-Null"
  661. %_xmlexist% timeout /t 2 %nul%
  662. %_xmlexist% timeout /t 2 %nul%
  663. %_xmlexist% (
  664. set error=1
  665. if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
  666. call :dk_color %Gray% "Installing GenuineTicket.xml [Failed with ClipSVC service restart, wait...]"
  667. )
  668. )
  669. copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%
  670. clipup -v -o
  671. set rebuildinfo=
  672. if not exist %ProgramData%\Microsoft\Windows\ClipSVC\tokens.dat (
  673. set error=1
  674. set rebuildinfo=1
  675. call :dk_color %Red% "Checking ClipSVC tokens.dat [Not Found]"
  676. )
  677. %_xmlexist% (
  678. set error=1
  679. set rebuildinfo=1
  680. call :dk_color %Red% "Installing GenuineTicket.xml [Failed With clipup -v -o]"
  681. )
  682. if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*.xml" (
  683. set error=1
  684. set rebuildinfo=1
  685. call :dk_color %Red% "Checking Ticket Migration [Failed]"
  686. )
  687. if not defined altapplist if not defined showfix if defined rebuildinfo (
  688. set showfix=1
  689. call :dk_color %Blue% "%_fixmsg%"
  690. )
  691. if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
  692. ::==========================================================================================================================================
  693. call :dk_product
  694. echo:
  695. echo Activating...
  696. call :dk_act
  697. call :dk_checkperm
  698. if defined _perm (
  699. echo:
  700. call :dk_color %Green% "%winos% is permanently activated with a digital license."
  701. goto :dl_final
  702. )
  703. ::==========================================================================================================================================
  704. :: Clear store ID related registry to fix activation if Internet is connected
  705. set "_ident=HKU\S-1-5-19\SOFTWARE\Microsoft\IdentityCRL"
  706. if %keyerror% EQU 0 if defined _int (
  707. reg delete "%_ident%" /f %nul%
  708. for %%# in (wlidsvc LicenseManager sppsvc) do (%psc% "Start-Job { Restart-Service %%# } | Wait-Job -Timeout 20 | Out-Null")
  709. call :dk_refresh
  710. call :dk_act
  711. call :dk_checkperm
  712. reg query "%_ident%" %nul% || (
  713. set error=1
  714. echo:
  715. call :dk_color %Red% "Generating New IdentityCRL Registry [Failed] [%_ident%]"
  716. )
  717. )
  718. ::==========================================================================================================================================
  719. :: Extended licensing servers tests incase error not found and activation failed
  720. if %keyerror% EQU 0 if not defined _perm if defined _int (
  721. ipconfig /flushdns %nul%
  722. set "tls=[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;"
  723. for %%# in (
  724. licensing.mp.microsoft.com/v7.0/licenses/content
  725. login.live.com/ppsecure/deviceaddcredential.srf
  726. purchase.mp.microsoft.com/v7.0/users/me/orders
  727. ) do if not defined resfail (
  728. %psc% "try { !tls! irm https://%%# -Method POST } catch { if ($_.Exception.Response -eq $null) { Write-Host """"[%%#] $($_.Exception.Message)"""" -ForegroundColor Red -BackgroundColor Black; exit 3 } }"
  729. if !errorlevel!==3 set resfail=1
  730. )
  731. )
  732. if defined resfail (
  733. set error=1
  734. for %%# in (
  735. live.com
  736. microsoft.com
  737. login.live.com
  738. purchase.mp.microsoft.com
  739. licensing.mp.microsoft.com
  740. ) do (
  741. findstr /i "%%#" "%SysPath%\drivers\etc\hosts" %nul1% && set "hosfail= [%%# Blocked in Hosts]"
  742. )
  743. call :dk_color %Red% "Checking Licensing Servers [Failed to Connect]!hosfail!"
  744. set fixes=%fixes% %mas%licensing-servers-issue
  745. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%licensing-servers-issue"
  746. )
  747. ::==========================================================================================================================================
  748. :: Windows update and store block check
  749. if %keyerror% EQU 0 if not defined _perm if defined _int (
  750. reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v DisableWindowsUpdateAccess %nul2% | find /i "0x1" %nul% && set wublock=1
  751. reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v DoNotConnectToWindowsUpdateInternetLocations %nul2% | find /i "0x1" %nul% && set wublock=1
  752. if defined wublock (
  753. call :dk_color %Red% "Checking Update Blocker In Registry [Found]"
  754. call :dk_color %Blue% "HWID activation needs working Windows updates, if you have used any tool to block updates, undo it."
  755. )
  756. reg query "HKLM\SOFTWARE\Policies\Microsoft\WindowsStore" /v DisableStoreApps %nul2% | find /i "0x1" %nul% && (
  757. set storeblock=1
  758. call :dk_color %Red% "Checking Store Blocker In Registry [Found]"
  759. call :dk_color %Blue% "If you have used any tool to block Store, undo it."
  760. )
  761. set wcount=0
  762. for %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type ServiceSidType RequiredPrivileges FailureActions) do (
  763. reg query HKLM\SYSTEM\CurrentControlSet\Services\wuauserv /v %%G %nul% || (set wucorrupt=1&set /a wcount+=1)
  764. )
  765. for %%G in (Parameters Security) do (
  766. reg query HKLM\SYSTEM\CurrentControlSet\Services\wuauserv\%%G %nul% || (set wucorrupt=1&set /a wcount+=1)
  767. )
  768. if defined wucorrupt (
  769. set error=1
  770. call :dk_color %Red% "Checking Windows Update Registry [Corruption Found]"
  771. if !wcount! GTR 2 (
  772. call :dk_color %Red% "Windows seems to be infected with Mal%w%ware."
  773. set fixes=%fixes% %mas%remove_mal%w%ware
  774. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%remove_mal%w%ware"
  775. ) else (
  776. call :dk_color %Blue% "HWID activation needs working Windows updates, if you have used any tool to block updates, undo it."
  777. )
  778. ) else (
  779. %psc% "Start-Job { Start-Service wuauserv } | Wait-Job -Timeout 20 | Out-Null"
  780. sc query wuauserv | find /i "RUNNING" %nul% || (
  781. set error=1
  782. set wuerror=1
  783. sc start wuauserv %nul%
  784. call :dk_color %Red% "Starting Windows Update Service [Failed] [!errorlevel!]"
  785. call :dk_color %Blue% "HWID activation needs working Windows updates, if you have used any tool to block updates, undo it."
  786. )
  787. )
  788. )
  789. ::==========================================================================================================================================
  790. :: Check Internet related error codes
  791. if %keyerror% EQU 0 if not defined _perm if defined _int (
  792. if not defined wucorrupt if not defined wublock if not defined wuerror if not defined storeblock if not defined resfail (
  793. echo "%error_code%" | findstr /i "0x80072e 0x80072f 0x800704cf 0x87e10bcf 0x800705b4" %nul% && (
  794. call :dk_color %Red% "Checking Internet Issues [Found] %error_code%"
  795. set fixes=%fixes% %mas%licensing-servers-issue
  796. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%licensing-servers-issue"
  797. )
  798. )
  799. )
  800. ::==========================================================================================================================================
  801. echo:
  802. if defined _perm (
  803. call :dk_color %Green% "%winos% is permanently activated with a digital license."
  804. ) else (
  805. call :dk_color %Red% "Activation Failed %error_code%"
  806. if defined notworking (
  807. call :dk_color %Blue% "At the time of writing, HWID Activation is not supported for this product."
  808. call :dk_color %Blue% "Use TSforge activation option from the main menu instead."
  809. ) else (
  810. if not defined error call :dk_color %Blue% "%_fixmsg%"
  811. set fixes=%fixes% %mas%troubleshoot
  812. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  813. )
  814. )
  815. ::========================================================================================================================================
  816. :dl_final
  817. echo:
  818. if defined regionchange (
  819. %psc% "Set-WinHomeLocation -GeoId %nation%" %nul%
  820. if !errorlevel! EQU 0 (
  821. echo Restoring Windows Region [Successful]
  822. ) else (
  823. call :dk_color %Red% "Restoring Windows Region [Failed] [%name% - %nation%]"
  824. )
  825. )
  826. REM if %osSKU%==175 call :dk_color %Red% "%winos% does not support activation on non-azure platforms."
  827. :: Trigger reevaluation of SPP's Scheduled Tasks
  828. if defined _perm (
  829. call :dk_reeval %nul%
  830. )
  831. goto :dk_done
  832. ::========================================================================================================================================
  833. :: Set variables
  834. :dk_setvar
  835. set psc=powershell.exe
  836. set winbuild=1
  837. for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
  838. set _NCS=1
  839. if %winbuild% LSS 10586 set _NCS=0
  840. if %winbuild% GEQ 10586 reg query "HKCU\Console" /v ForceV2 %nul2% | find /i "0x0" %nul1% && (set _NCS=0)
  841. echo "%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%" | find /i "ARM64" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)
  842. if %_NCS% EQU 1 (
  843. for /F %%a in ('echo prompt $E ^| cmd') do set "esc=%%a"
  844. set "Red="41;97m""
  845. set "Gray="100;97m""
  846. set "Green="42;97m""
  847. set "Blue="44;97m""
  848. set "White="107;91m""
  849. set "_Red="40;91m""
  850. set "_White="40;37m""
  851. set "_Green="40;92m""
  852. set "_Yellow="40;93m""
  853. ) else (
  854. set "Red="Red" "white""
  855. set "Gray="Darkgray" "white""
  856. set "Green="DarkGreen" "white""
  857. set "Blue="Blue" "white""
  858. set "White="White" "Red""
  859. set "_Red="Black" "Red""
  860. set "_White="Black" "Gray""
  861. set "_Green="Black" "Green""
  862. set "_Yellow="Black" "Yellow""
  863. )
  864. set "nceline=echo: &echo ==== ERROR ==== &echo:"
  865. set "eline=echo: &call :dk_color %Red% "==== ERROR ====" &echo:"
  866. if %~z0 GEQ 200000 (
  867. set "_exitmsg=Go back"
  868. set "_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option."
  869. ) else (
  870. set "_exitmsg=Exit"
  871. set "_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option."
  872. )
  873. exit /b
  874. :: Show OS info
  875. :dk_showosinfo
  876. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE') do set osarch=%%b
  877. for /f "tokens=6-7 delims=[]. " %%i in ('ver') do if not "%%j"=="" (
  878. set fullbuild=%%i.%%j
  879. ) else (
  880. for /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"
  881. for /f "skip=2 tokens=3,4 delims=. " %%G in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildLabEx') do (
  882. if defined UBR (set "fullbuild=%%G.!UBR!") else (set "fullbuild=%%G.%%H")
  883. )
  884. )
  885. echo Checking OS Info [%winos% ^| %fullbuild% ^| %osarch%]
  886. exit /b
  887. :: Check SKU value
  888. :dk_checksku
  889. call :dk_reflection
  890. set osSKU=
  891. set slcSKU=
  892. set wmiSKU=
  893. set regSKU=
  894. set winsub=
  895. if %winbuild% GEQ 14393 (set info=Kernel-BrandingInfo) else (set info=Kernel-ProductInfo)
  896. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3);
  897. set d1=%d1% $Sku = 0; [void]$TypeBuilder.CreateType()::SLGetWindowsInformationDWORD('%info%', [ref]$Sku); $Sku
  898. for /f "delims=" %%s in ('"%psc% %d1%"') do if not errorlevel 1 (set slcSKU=%%s)
  899. set slcSKU=%slcSKU: =%
  900. if "%slcSKU%"=="0" set slcSKU=
  901. for /f "tokens=* delims=0123456789" %%a in ("%slcSKU%") do (if not "[%%a]"=="[]" set slcSKU=)
  902. for /f "tokens=3 delims=." %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" /v OSProductPfn %nul6%') do set "regSKU=%%a"
  903. if %_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"
  904. if %_wmic% EQU 0 for /f "tokens=1" %%a in ('%psc% "([WMI]'Win32_OperatingSystem=@').OperatingSystemSKU" %nul6%') do if not errorlevel 1 set "wmiSKU=%%a"
  905. if %winbuild% GEQ 15063 %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':winsubstatus\:.*';iex ($f[1])" %nul2% | find /i "Subscription_is_activated" %nul% && (
  906. if defined regSKU if defined slcSKU if not "%regSKU%"=="%slcSKU%" (
  907. set winsub=1
  908. set osSKU=%regSKU%
  909. )
  910. )
  911. if not defined osSKU set osSKU=%slcSKU%
  912. if not defined osSKU set osSKU=%wmiSKU%
  913. if not defined osSKU set osSKU=%regSKU%
  914. exit /b
  915. :: Get Windows Subscription status
  916. :winsubstatus:
  917. $DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(6, 1).DefineDynamicModule(4).DefineType(2)
  918. [void]$DM.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  919. $m = [System.Runtime.InteropServices.Marshal]
  920. $p = $m::AllocHGlobal(12)
  921. $r = $DM.CreateType()::ClipGetSubscriptionStatus([ref]$p)
  922. if ($r -eq 0) {
  923. $enabled = $m::ReadInt32($p)
  924. if ($enabled -ge 1) {
  925. $state = $m::ReadInt32($p, 8)
  926. if ($state -eq 1) {
  927. "Subscription_is_activated."
  928. }
  929. }
  930. }
  931. :winsubstatus:
  932. :: Get Windows permanent activation status
  933. :dk_checkperm
  934. if %_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=
  935. if %_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=
  936. exit /b
  937. :: Refresh license status
  938. :dk_refresh
  939. if %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call RefreshLicenseStatus %nul%
  940. if %_wmic% EQU 0 %psc% "$null=(([WMICLASS]'%sps%').GetInstances()).RefreshLicenseStatus()" %nul%
  941. exit /b
  942. :: Install Key
  943. :dk_inskey
  944. if %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey="%key%" %nul%
  945. if %_wmic% EQU 0 %psc% "try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
  946. set keyerror=%errorlevel%
  947. cmd /c exit /b %keyerror%
  948. if %keyerror% NEQ 0 set "keyerror=[0x%=ExitCode%]"
  949. if %keyerror% EQU 0 (
  950. if %sps%==SoftwareLicensingService call :dk_refresh
  951. echo Installing Generic Product Key %~1 [Successful]
  952. ) else (
  953. call :dk_color %Red% "Installing Generic Product Key %~1 [Failed] %keyerror%"
  954. if not defined error (
  955. if defined altapplist call :dk_color %Red% "Activation ID not found for this key."
  956. call :dk_color %Blue% "%_fixmsg%"
  957. set showfix=1
  958. )
  959. set error=1
  960. )
  961. exit /b
  962. :: Activation command
  963. :dk_act
  964. set error_code=
  965. if %_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%
  966. if %_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%
  967. set error_code=%errorlevel%
  968. cmd /c exit /b %error_code%
  969. if %error_code% NEQ 0 (set "error_code=[Error Code: 0x%=ExitCode%]") else (set error_code=)
  970. exit /b
  971. :: Get all products Activation IDs
  972. :dk_actids
  973. set allapps=
  974. if %_wmic% EQU 1 set "chkapp=for /f "tokens=2 delims==" %%a in ('"wmic path %spp% where (ApplicationID='%1') get ID /VALUE" %nul6%')"
  975. if %_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%')"
  976. %chkapp% do (if defined allapps (call set "allapps=!allapps! %%a") else (call set "allapps=%%a"))
  977. :: Check potential script crash issue when user manually installs way too many licenses for Office (length limit in variable)
  978. if defined allapps if %1==0ff1ce15-a989-479d-af46-f275c6370663 (
  979. set len=0
  980. echo:!allapps!> %SystemRoot%\Temp\chklen
  981. for %%A in (%SystemRoot%\Temp\chklen) do (set len=%%~zA)
  982. del %SystemRoot%\Temp\chklen %nul%
  983. if !len! GTR 6000 (
  984. %eline%
  985. echo Too many licenses are installed, the script may crash.
  986. call :dk_color %Blue% "%_fixmsg%"
  987. timeout /t 30
  988. )
  989. )
  990. exit /b
  991. :: Get installed products Activation IDs
  992. :dk_actid
  993. set apps=
  994. if %_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%')"
  995. if %_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%')"
  996. %chkapp% do (if defined apps (call set "apps=!apps! %%a") else (call set "apps=%%a"))
  997. exit /b
  998. :: Trigger reevaluation, it helps in updating SPP tasks
  999. :dk_reeval
  1000. :: 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
  1001. set "ruleskey=HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\PersistedSystemState"
  1002. reg delete "%ruleskey%" /v "State" /f %nul%
  1003. reg delete "%ruleskey%" /v "SuppressRulesEngine" /f %nul%
  1004. set r1=$TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);
  1005. set r2=%r1% [void]$TB.DefinePInvokeMethod('SLpTriggerServiceWorker', 'sppc.dll', 22, 1, [Int32], @([UInt32], [IntPtr], [String], [UInt32]), 1, 3);
  1006. set d1=%r2% [void]$TB.CreateType()::SLpTriggerServiceWorker(0, 0, 'reeval', 0)
  1007. %psc% "Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null; %d1%"
  1008. exit /b
  1009. :: Get Activation IDs from licensing files if not found through WMI
  1010. :getactivationid:
  1011. $folderPath = "$env:SysPath\spp\tokens\skus"
  1012. $files = Get-ChildItem -Path $folderPath -Recurse -Filter "*.xrm-ms"
  1013. $guids = @()
  1014. foreach ($file in $files) {
  1015. $content = Get-Content -Path $file.FullName -Raw
  1016. $matches = [regex]::Matches($content, 'name="productSkuId">\{([0-9a-fA-F\-]+)\}')
  1017. foreach ($match in $matches) {
  1018. $guids += $match.Groups[1].Value
  1019. }
  1020. }
  1021. $guids = $guids | Select-Object -Unique
  1022. $guidsString = $guids -join " "
  1023. $guidsString
  1024. :getactivationid:
  1025. :: Install License files using Powershell/WMI instead of slmgr.vbs
  1026. :xrm:
  1027. function InstallLicenseFile($Lsc) {
  1028. try {
  1029. $null = $sls.InstallLicense([IO.File]::ReadAllText($Lsc))
  1030. } catch {
  1031. $host.SetShouldExit($_.Exception.HResult)
  1032. }
  1033. }
  1034. function InstallLicenseArr($Str) {
  1035. $a = $Str -split ';'
  1036. ForEach ($x in $a) {InstallLicenseFile "$x"}
  1037. }
  1038. function InstallLicenseDir($Loc) {
  1039. dir $Loc *.xrm-ms -af -s | select -expand FullName | % {InstallLicenseFile "$_"}
  1040. }
  1041. function ReinstallLicenses() {
  1042. $Oem = "$env:SysPath\oem"
  1043. $Spp = "$env:SysPath\spp\tokens"
  1044. InstallLicenseDir "$Spp"
  1045. If (Test-Path $Oem) {InstallLicenseDir "$Oem"}
  1046. }
  1047. :xrm:
  1048. :: Check wmic.exe
  1049. :dk_ckeckwmic
  1050. set _wmic=0
  1051. for %%# in (wmic.exe) do @if not "%%~$PATH:#"=="" (
  1052. cmd /c "wmic path Win32_ComputerSystem get CreationClassName /value" %nul2% | find /i "computersystem" %nul1% && set _wmic=1
  1053. )
  1054. exit /b
  1055. :: Show info for potential script stuck scenario
  1056. :dk_sppissue
  1057. sc start sppsvc %nul%
  1058. set spperror=%errorlevel%
  1059. if %spperror% NEQ 1056 if %spperror% NEQ 0 (
  1060. %eline%
  1061. echo sc start sppsvc [Error Code: %spperror%]
  1062. )
  1063. echo:
  1064. %psc% "$job = Start-Job { (Get-WmiObject -Query 'SELECT * FROM %sps%').Version }; if (-not (Wait-Job $job -Timeout 30)) {write-host 'sppsvc is not working correctly. Help - %mas%troubleshoot'}"
  1065. exit /b
  1066. :: Get Product name (WMI/REG methods are not reliable in all conditions, hence winbrand.dll method is used)
  1067. :dk_product
  1068. set d1=%ref% $meth = $TypeBuilder.DefinePInvokeMethod('BrandingFormatString', 'winbrand.dll', 'Public, Static', 1, [String], @([String]), 1, 3);
  1069. set d1=%d1% $meth.SetImplementationFlags(128); $TypeBuilder.CreateType()::BrandingFormatString('%%WINDOWS_LONG%%')
  1070. set winos=
  1071. for /f "delims=" %%s in ('"%psc% %d1%"') do if not errorlevel 1 (set winos=%%s)
  1072. echo "%winos%" | find /i "Windows" %nul1% || (
  1073. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName %nul6%') do set "winos=%%b"
  1074. if %winbuild% GEQ 22000 (
  1075. set winos=!winos:Windows 10=Windows 11!
  1076. )
  1077. )
  1078. if not defined winsub exit /b
  1079. :: Check base edition product name if Windows subscription license is found
  1080. for %%# in (pkeyhelper.dll) do @if "%%~$PATH:#"=="" exit /b
  1081. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionNameFromId', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [IntPtr].MakeByRefType()), 1, 3);
  1082. set d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionNameFromId(%regSKU%, [ref]$out);$s=[Runtime.InteropServices.Marshal]::PtrToStringUni($out); $s
  1083. for /f %%a in ('%psc% "%d1%"') do if not errorlevel 1 (
  1084. if %winbuild% GEQ 22000 (
  1085. set winos=Windows 11 %%a
  1086. ) else (
  1087. set winos=Windows 10 %%a
  1088. )
  1089. )
  1090. exit /b
  1091. :: Common lines used in PowerShell reflection code
  1092. :dk_reflection
  1093. set ref=$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1);
  1094. set ref=%ref% $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False);
  1095. set ref=%ref% $TypeBuilder = $ModuleBuilder.DefineType(0);
  1096. exit /b
  1097. ::========================================================================================================================================
  1098. :dk_chkmal
  1099. :: Many users unknowingly download mal-ware by using activators found through Google search.
  1100. :: This code aims to notify users that their system has been affected by mal-ware.
  1101. set w=
  1102. set results=
  1103. if exist "%ProgramFiles%\KM%w%Spico" set pupfound= KM%w%Spico
  1104. if not defined pupfound (
  1105. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\taskcache\tasks" /f Path /s | find /i "AutoPico" %nul% && set pupfound= KM%w%Spico
  1106. )
  1107. set hcount=0
  1108. for %%# in (avira.com kaspersky.com virustotal.com mcafee.com) do (
  1109. find /i "%%#" %SysPath%\drivers\etc\hosts %nul% && set /a hcount+=1)
  1110. if %hcount%==4 set "results=[Antivirus URLs are blocked in hosts]"
  1111. sc start sppsvc %nul%
  1112. echo "%errorlevel%" | findstr "577 225" %nul% && (
  1113. set "results=%results%[Likely File Infector]"
  1114. ) || (
  1115. if not exist %SysPath%\sppsvc.exe if not exist %SysPath%\alg.exe (set "results=%results%[Likely File Infector]")
  1116. )
  1117. if not "%results%%pupfound%"=="" (
  1118. if defined pupfound call :dk_color %Gray% "Checking PUP Activators [Found%pupfound%]"
  1119. if defined results call :dk_color %Red% "Checking Probable Mal%w%ware Infection..."
  1120. if defined results call :dk_color %Red% "%results%"
  1121. set fixes=%fixes% %mas%remove_mal%w%ware
  1122. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%remove_mal%w%ware"
  1123. echo:
  1124. )
  1125. :: Remove the scheduled task of R@1n-KMS (old version) that runs the activation command every minute, as it leads to high CPU usage.
  1126. if exist %SysPath%\Tasks\R@1n-KMS (
  1127. for /f %%A in ('dir /b /a:-d %SysPath%\Tasks\R@1n-KMS %nul6%') do (schtasks /delete /tn \R@1n-KMS\%%A /f %nul%)
  1128. )
  1129. exit /b
  1130. ::========================================================================================================================================
  1131. :dk_errorcheck
  1132. set showfix=
  1133. call :dk_chkmal
  1134. :: Check Sandboxing
  1135. sc query Null %nul% || (
  1136. set error=1
  1137. set showfix=1
  1138. call :dk_color %Red% "Checking Sandboxing [Found, script may not work properly.]"
  1139. call :dk_color %Blue% "If you are using any third-party antivirus, check if it is blocking the script."
  1140. echo:
  1141. )
  1142. ::========================================================================================================================================
  1143. :: Check corrupt services
  1144. set serv_cor=
  1145. for %%# in (%_serv%) do (
  1146. set _corrupt=
  1147. sc start %%# %nul%
  1148. if !errorlevel! EQU 1060 set _corrupt=1
  1149. sc query %%# %nul% || set _corrupt=1
  1150. for %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type) do if not defined _corrupt (
  1151. reg query HKLM\SYSTEM\CurrentControlSet\Services\%%# /v %%G %nul% || set _corrupt=1
  1152. )
  1153. if defined _corrupt (if defined serv_cor (set "serv_cor=!serv_cor! %%#") else (set "serv_cor=%%#"))
  1154. )
  1155. if defined serv_cor (
  1156. set error=1
  1157. set showfix=1
  1158. call :dk_color %Red% "Checking Corrupt Services [%serv_cor%]"
  1159. )
  1160. ::========================================================================================================================================
  1161. :: Check disabled services
  1162. set serv_ste=
  1163. for %%# in (%_serv%) do (
  1164. sc start %%# %nul%
  1165. if !errorlevel! EQU 1058 (if defined serv_ste (set "serv_ste=!serv_ste! %%#") else (set "serv_ste=%%#"))
  1166. )
  1167. :: Change disabled services startup type to default
  1168. set serv_csts=
  1169. set serv_cste=
  1170. if defined serv_ste (
  1171. for %%# in (%serv_ste%) do (
  1172. if /i %%#==ClipSVC (reg add "HKLM\SYSTEM\CurrentControlSet\Services\%%#" /v "Start" /t REG_DWORD /d "3" /f %nul% & sc config %%# start= demand %nul%)
  1173. if /i %%#==wlidsvc sc config %%# start= demand %nul%
  1174. if /i %%#==sppsvc (reg add "HKLM\SYSTEM\CurrentControlSet\Services\%%#" /v "Start" /t REG_DWORD /d "2" /f %nul% & sc config %%# start= delayed-auto %nul%)
  1175. if /i %%#==KeyIso sc config %%# start= demand %nul%
  1176. if /i %%#==LicenseManager sc config %%# start= demand %nul%
  1177. if /i %%#==Winmgmt sc config %%# start= auto %nul%
  1178. if !errorlevel!==0 (
  1179. if defined serv_csts (set "serv_csts=!serv_csts! %%#") else (set "serv_csts=%%#")
  1180. ) else (
  1181. if defined serv_cste (set "serv_cste=!serv_cste! %%#") else (set "serv_cste=%%#")
  1182. )
  1183. )
  1184. )
  1185. if defined serv_csts call :dk_color %Gray% "Enabling Disabled Services [Successful] [%serv_csts%]"
  1186. if defined serv_cste (
  1187. set error=1
  1188. call :dk_color %Red% "Enabling Disabled Services [Failed] [%serv_cste%]"
  1189. )
  1190. ::========================================================================================================================================
  1191. :: Check if the services are able to run or not
  1192. :: Workarounds are added to get correct status and error code because sc query doesn't output correct results in some conditions
  1193. set serv_e=
  1194. for %%# in (%_serv%) do (
  1195. set errorcode=
  1196. set checkerror=
  1197. sc query %%# | find /i "RUNNING" %nul% || (
  1198. %psc% "Start-Job { Start-Service %%# } | Wait-Job -Timeout 20 | Out-Null"
  1199. set errorcode=!errorlevel!
  1200. sc query %%# | find /i "RUNNING" %nul% || set checkerror=1
  1201. )
  1202. sc start %%# %nul%
  1203. if !errorlevel! NEQ 1056 if !errorlevel! NEQ 0 (set errorcode=!errorlevel!&set checkerror=1)
  1204. if defined checkerror if defined serv_e (set "serv_e=!serv_e!, %%#-!errorcode!") else (set "serv_e=%%#-!errorcode!")
  1205. )
  1206. if defined serv_e (
  1207. set error=1
  1208. call :dk_color %Red% "Starting Services [Failed] [%serv_e%]"
  1209. echo %serv_e% | findstr /i "ClipSVC-1058 sppsvc-1058" %nul% && (
  1210. call :dk_color %Blue% "Reboot your machine using the restart option to fix this error."
  1211. set showfix=1
  1212. )
  1213. echo %serv_e% | findstr /i "sppsvc-1060" %nul% && (
  1214. set fixes=%fixes% %mas%fix_service
  1215. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%fix_service"
  1216. set showfix=1
  1217. )
  1218. )
  1219. ::========================================================================================================================================
  1220. :: Various error checks
  1221. if defined safeboot_option (
  1222. set error=1
  1223. set showfix=1
  1224. call :dk_color2 %Red% "Checking Boot Mode [%safeboot_option%] " %Blue% "[Safe mode found. Run in normal mode.]"
  1225. )
  1226. :: https://learn.microsoft.com/windows-hardware/manufacture/desktop/windows-setup-states
  1227. for /f "skip=2 tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State" /v ImageState') do (set imagestate=%%B)
  1228. if /i not "%imagestate%"=="IMAGE_STATE_COMPLETE" (
  1229. call :dk_color %Gray% "Checking Windows Setup State [%imagestate%]"
  1230. echo "%imagestate%" | find /i "RESEAL" %nul% && (
  1231. set error=1
  1232. set showfix=1
  1233. call :dk_color %Blue% "You need to run it in normal mode in case you are running it in Audit Mode."
  1234. )
  1235. echo "%imagestate%" | find /i "UNDEPLOYABLE" %nul% && (
  1236. set fixes=%fixes% %mas%in-place_repair_upgrade
  1237. call :dk_color2 %Blue% "If the activation fails, do this - " %_Yellow% " %mas%in-place_repair_upgrade"
  1238. )
  1239. )
  1240. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinPE" /v InstRoot %nul% && (
  1241. set error=1
  1242. set showfix=1
  1243. call :dk_color2 %Red% "Checking WinPE " %Blue% "[WinPE mode found. Run in normal mode.]"
  1244. )
  1245. set wpainfo=
  1246. set wpaerror=
  1247. for /f "delims=" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':wpatest\:.*';iex ($f[1])" %nul6%') do (set wpainfo=%%a)
  1248. echo "%wpainfo%" | find /i "Error Found" %nul% && (
  1249. set error=1
  1250. set wpaerror=1
  1251. call :dk_color %Red% "Checking WPA Registry Errors [%wpainfo%]"
  1252. ) || (
  1253. echo Checking WPA Registry Count [%wpainfo%]
  1254. )
  1255. if not defined notwinact if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" (
  1256. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Eval" %nul1% || (
  1257. call :dk_color %Red% "Checking Eval Packages [Non-Eval Licenses are installed in Eval Windows]"
  1258. set fixes=%fixes% %mas%evaluation_editions
  1259. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%evaluation_editions"
  1260. )
  1261. )
  1262. set osedition=0
  1263. if %_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%')"
  1264. if %_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%')"
  1265. %chkedi% do if not errorlevel 1 (call set "osedition=%%a")
  1266. if %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"
  1267. :: Workaround for an issue in builds between 1607 and 1709 where ProfessionalEducation is shown as Professional
  1268. if not %osedition%==0 (
  1269. if "%osSKU%"=="164" set osedition=ProfessionalEducation
  1270. if "%osSKU%"=="165" set osedition=ProfessionalEducationN
  1271. )
  1272. if not defined notwinact (
  1273. if %osedition%==0 (
  1274. call :dk_color %Red% "Checking Edition Name [Not Found In Registry]"
  1275. ) else (
  1276. if 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" (
  1277. set skunotfound=1
  1278. call :dk_color %Red% "Checking License Files [Not Found] [%osedition%]"
  1279. )
  1280. if not exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*-%osedition%-*.mum" (
  1281. call :dk_color %Red% "Checking Package Files [Not Found] [%osedition%]"
  1282. )
  1283. )
  1284. )
  1285. %psc% "try { $null=([WMISEARCHER]'SELECT * FROM %sps%').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
  1286. set error_code=%errorlevel%
  1287. cmd /c exit /b %error_code%
  1288. if %error_code% NEQ 0 set "error_code=0x%=ExitCode%"
  1289. if %error_code% NEQ 0 (
  1290. set error=1
  1291. call :dk_color %Red% "Checking SoftwareLicensingService [Not Working] %error_code%"
  1292. )
  1293. set wmifailed=
  1294. if %_wmic% EQU 1 wmic path Win32_ComputerSystem get CreationClassName /value %nul2% | find /i "computersystem" %nul1%
  1295. if %_wmic% EQU 0 %psc% "Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName" %nul2% | find /i "computersystem" %nul1%
  1296. if %errorlevel% NEQ 0 set wmifailed=1
  1297. echo "%error_code%" | findstr /i "0x800410 0x800440 0x80131501" %nul1% && set wmifailed=1& :: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants
  1298. if defined wmifailed (
  1299. set error=1
  1300. call :dk_color %Red% "Checking WMI [Not Working]"
  1301. if not defined showfix call :dk_color %Blue% "Go back to Main Menu, select Troubleshoot and run Fix WMI option."
  1302. set showfix=1
  1303. )
  1304. if not defined notwinact (
  1305. if %winbuild% GEQ 10240 (
  1306. %nul% set /a "sum=%slcSKU%+%regSKU%+%wmiSKU%"
  1307. set /a "sum/=3"
  1308. if not "!sum!"=="%slcSKU%" (
  1309. call :dk_color %Gray% "Checking SLC/WMI/REG SKU [Difference Found - SLC:%slcSKU% WMI:%wmiSKU% Reg:%regSKU%]"
  1310. )
  1311. ) else (
  1312. %nul% set /a "sum=%slcSKU%+%wmiSKU%"
  1313. set /a "sum/=2"
  1314. if not "!sum!"=="%slcSKU%" (
  1315. call :dk_color %Gray% "Checking SLC/WMI SKU [Difference Found - SLC:%slcSKU% WMI:%wmiSKU%]"
  1316. )
  1317. )
  1318. )
  1319. reg query "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\PersistedTSReArmed" %nul% && (
  1320. set error=1
  1321. set showfix=1
  1322. call :dk_color2 %Red% "Checking Rearm " %Blue% "[System Restart Is Required]"
  1323. )
  1324. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ClipSVC\Volatile\PersistedSystemState" %nul% && (
  1325. set error=1
  1326. set showfix=1
  1327. call :dk_color2 %Red% "Checking ClipSVC " %Blue% "[System Restart Is Required]"
  1328. )
  1329. :: 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.
  1330. if exist "%SysPath%\wlms\wlms.exe" (
  1331. echo Checking Eval WLMS Service [Found]
  1332. )
  1333. reg query "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion" %nul% || (
  1334. set error=1
  1335. set showfix=1
  1336. call :dk_color %Red% "Checking HKU\S-1-5-20 Registry [Not Found]"
  1337. set fixes=%fixes% %mas%in-place_repair_upgrade
  1338. call :dk_color2 %Blue% "In case of activation issues, do this - " %_Yellow% " %mas%in-place_repair_upgrade"
  1339. )
  1340. for %%# in (SppEx%w%tComObj.exe sppsvc.exe sppsvc.exe\PerfOptions) do (
  1341. reg 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=%%#"))
  1342. )
  1343. if defined _sppint (
  1344. echo %_sppint% | find /i "PerfOptions" %nul% && (
  1345. call :dk_color %Red% "Checking SPP Interference In IFEO [%_sppint% - System might deactivate later]"
  1346. if not defined showfix call :dk_color %Blue% "%_fixmsg%"
  1347. set showfix=1
  1348. ) || (
  1349. echo Checking SPP In IFEO [%_sppint%]
  1350. )
  1351. )
  1352. 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 (
  1353. reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "SkipRearm" /t REG_DWORD /d "0" /f %nul%
  1354. call :dk_color %Red% "Checking SkipRearm [Default 0 Value Not Found. Changing To 0]"
  1355. %psc% "Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null"
  1356. )
  1357. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Plugins\Objects\msft:rm/algorithm/hwid/4.0" /f ba02fed39662 /d %nul% || (
  1358. call :dk_color %Red% "Checking SPP Registry Key [Incorrect ModuleId Found]"
  1359. set fixes=%fixes% %mas%issues_due_to_gaming_spoofers
  1360. call :dk_color2 %Blue% "Most likely caused by gaming spoofers. Help - " %_Yellow% " %mas%issues_due_to_gaming_spoofers"
  1361. set error=1
  1362. set showfix=1
  1363. )
  1364. set tokenstore=
  1365. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v TokenStore %nul6%') do call set "tokenstore=%%b"
  1366. if %winbuild% LSS 9200 set "tokenstore=%Systemdrive%\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform"
  1367. if %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" (
  1368. set toerr=1
  1369. set error=1
  1370. set showfix=1
  1371. call :dk_color %Red% "Checking TokenStore Registry Key [Correct Path Not Found] [%tokenstore%]"
  1372. set fixes=%fixes% %mas%troubleshoot
  1373. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  1374. )
  1375. :: This code creates token folder only if it's missing and sets default permission for it
  1376. if not defined toerr if not exist "%tokenstore%\" (
  1377. mkdir "%tokenstore%" %nul%
  1378. if %winbuild% LSS 9200 set "d=$sddl = 'O:NSG:NSD:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;NS)';"
  1379. if %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)';"
  1380. set "d=!d! $AclObject = New-Object System.Security.AccessControl.DirectorySecurity;"
  1381. set "d=!d! $AclObject.SetSecurityDescriptorSddlForm($sddl);"
  1382. set "d=!d! Set-Acl -Path %tokenstore% -AclObject $AclObject;"
  1383. %psc% "!d!" %nul%
  1384. if exist "%tokenstore%\" (
  1385. call :dk_color %Gray% "Checking SPP Token Folder [Not Found, Created Now] [%tokenstore%\]"
  1386. ) else (
  1387. call :dk_color %Red% "Checking SPP Token Folder [Not Found, Failed to Create] [%tokenstore%\]"
  1388. set error=1
  1389. set showfix=1
  1390. )
  1391. )
  1392. if not defined notwinact (
  1393. call :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f
  1394. if not defined apps (
  1395. %psc% "Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null; $sls = Get-WmiObject SoftwareLicensingService; $f=[io.file]::ReadAllText('!_batp!') -split ':xrm\:.*';iex ($f[1]); ReinstallLicenses" %nul%
  1396. call :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f
  1397. if not defined apps (
  1398. set "_notfoundids=Key Not Installed / Act ID Not Found"
  1399. call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  1400. if not defined allapps (
  1401. set error=1
  1402. set "_notfoundids=Not found"
  1403. )
  1404. call :dk_color %Red% "Checking Activation IDs [!_notfoundids!]"
  1405. )
  1406. )
  1407. )
  1408. if exist "%tokenstore%\" if not exist "%tokenstore%\tokens.dat" (
  1409. set error=1
  1410. call :dk_color %Red% "Checking SPP tokens.dat [Not Found] [%tokenstore%\]"
  1411. )
  1412. if %winbuild% GEQ 9200 if not exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" (
  1413. %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% || (
  1414. for /f "delims=" %%a in ('%psc% "(Get-ScheduledTask -TaskName 'SvcRestartTask' -TaskPath '\Microsoft\Windows\SoftwareProtectionPlatform\').State" %nul6%') do (set taskinfo=%%a)
  1415. echo !taskinfo! | find /i "Ready" %nul% || (
  1416. reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "actionlist" /f %nul%
  1417. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\SoftwareProtectionPlatform\SvcRestartTask" %nul% || set taskinfo=Removed
  1418. if "!taskinfo!"=="" set "taskinfo=Not Found"
  1419. call :dk_color %Red% "Checking SvcRestartTask Status [!taskinfo!, System might deactivate later]"
  1420. if not defined error call :dk_color %Blue% "Reboot your machine using the restart option."
  1421. )
  1422. )
  1423. )
  1424. :: This code checks if SPP has permission access to tokens folder and required registry keys. It's often caused by gaming spoofers.
  1425. set permerror=
  1426. if %winbuild% GEQ 9200 if not defined ps32onArm (
  1427. for %%# in (
  1428. "%tokenstore%+FullControl"
  1429. "HKLM:\SYSTEM\WPA+QueryValues, EnumerateSubKeys, WriteKey"
  1430. "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform+SetValue"
  1431. ) do for /f "tokens=1,2 delims=+" %%A in (%%#) do if not defined permerror (
  1432. %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%
  1433. if !errorlevel!==2 (
  1434. if "%%A"=="%tokenstore%" (
  1435. set "permerror=Error Found In Token Folder"
  1436. ) else (
  1437. set "permerror=Error Found In SPP Registries"
  1438. )
  1439. )
  1440. )
  1441. REM https://learn.microsoft.com/office/troubleshoot/activation/license-issue-when-start-office-application
  1442. if not defined permerror (
  1443. reg query "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion" %nul% && (
  1444. set "pol=HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Policies"
  1445. reg query "!pol!" %nul% || reg add "!pol!" %nul%
  1446. %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%
  1447. if !errorlevel!==3 set "permerror=Error Found In S-1-5-20 SPP"
  1448. )
  1449. )
  1450. if defined permerror (
  1451. set error=1
  1452. call :dk_color %Red% "Checking SPP Permissions [!permerror!]"
  1453. if not defined showfix call :dk_color %Blue% "%_fixmsg%"
  1454. set showfix=1
  1455. )
  1456. )
  1457. :: If required services are not disabled or corrupted + if there is any error + SoftwareLicensingService errorlevel is not Zero + no fix was shown before
  1458. if not defined serv_cor if not defined serv_cste if defined error if /i not %error_code%==0 if not defined showfix (
  1459. if not defined permerror if defined wpaerror (call :dk_color %Blue% "Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option." & set showfix=1)
  1460. if not defined showfix (
  1461. set showfix=1
  1462. call :dk_color %Blue% "%_fixmsg%"
  1463. if not defined permerror call :dk_color %Blue% "If activation still fails then run Fix WPA Registry option."
  1464. )
  1465. )
  1466. if not defined showfix if defined wpaerror (
  1467. set showfix=1
  1468. call :dk_color %Blue% "If activation fails then go back to Main Menu, select Troubleshoot and run Fix WPA Registry option."
  1469. )
  1470. exit /b
  1471. :: This code checks for invalid registry keys in HKLM\SYSTEM\WPA. This issue may appear even on healthy systems
  1472. :wpatest:
  1473. $wpaKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME).OpenSubKey("SYSTEM\\WPA")
  1474. $count = 0
  1475. foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {
  1476. if ($subkeyName -match '.*-.*-.*-.*-.*-') {
  1477. $count++
  1478. }
  1479. }
  1480. $osVersion = [System.Environment]::OSVersion.Version
  1481. $minBuildNumber = 14393
  1482. if ($osVersion.Build -ge $minBuildNumber) {
  1483. $subkeyHashTable = @{}
  1484. foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {
  1485. if ($subkeyName -match '.*-.*-.*-.*-.*-') {
  1486. $keyNumber = $subkeyName -replace '.*-', ''
  1487. $subkeyHashTable[$keyNumber] = $true
  1488. }
  1489. }
  1490. for ($i=1; $i -le $count; $i++) {
  1491. if (-not $subkeyHashTable.ContainsKey("$i")) {
  1492. Write-Output "Total Keys $count. Error Found - $i key does not exist."
  1493. $wpaKey.Close()
  1494. exit
  1495. }
  1496. }
  1497. }
  1498. $wpaKey.GetSubKeyNames() | ForEach-Object {
  1499. if ($_ -match '.*-.*-.*-.*-.*-') {
  1500. if ($PSVersionTable.PSVersion.Major -lt 3) {
  1501. cmd /c "reg query "HKLM\SYSTEM\WPA\$_" /ve /t REG_BINARY >nul 2>&1"
  1502. if ($LASTEXITCODE -ne 0) {
  1503. Write-Host "Total Keys $count. Error Found - Binary Data is corrupt."
  1504. $wpaKey.Close()
  1505. exit
  1506. }
  1507. } else {
  1508. $subkey = $wpaKey.OpenSubKey($_)
  1509. $p = $subkey.GetValueNames()
  1510. if (($p | Where-Object { $subkey.GetValueKind($_) -eq [Microsoft.Win32.RegistryValueKind]::Binary }).Count -eq 0) {
  1511. Write-Host "Total Keys $count. Error Found - Binary Data is corrupt."
  1512. $wpaKey.Close()
  1513. exit
  1514. }
  1515. }
  1516. }
  1517. }
  1518. $count
  1519. $wpaKey.Close()
  1520. :wpatest:
  1521. ::========================================================================================================================================
  1522. :dk_color
  1523. if %_NCS% EQU 1 (
  1524. echo %esc%[%~1%~2%esc%[0m
  1525. ) else (
  1526. %psc% write-host -back '%1' -fore '%2' '%3'
  1527. )
  1528. exit /b
  1529. :dk_color2
  1530. if %_NCS% EQU 1 (
  1531. echo %esc%[%~1%~2%esc%[%~3%~4%esc%[0m
  1532. ) else (
  1533. %psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'
  1534. )
  1535. exit /b
  1536. ::========================================================================================================================================
  1537. :dk_done
  1538. echo:
  1539. if %_unattended%==1 timeout /t 2 & exit /b
  1540. if defined fixes (
  1541. call :dk_color %White% "Follow ALL the ABOVE blue lines. "
  1542. call :dk_color2 %Blue% "Press [1] to Open Support Webpage " %Gray% " Press [0] to Ignore"
  1543. choice /C:10 /N
  1544. if !errorlevel!==1 (for %%# in (%fixes%) do (start %%#))
  1545. )
  1546. if defined terminal (
  1547. call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
  1548. choice /c 0 /n
  1549. ) else (
  1550. call :dk_color %_Yellow% "Press any key to %_exitmsg%..."
  1551. pause %nul1%
  1552. )
  1553. exit /b
  1554. ::========================================================================================================================================
  1555. :: 1st column = Activation ID
  1556. :: 2nd column = Generic Retail/OEM/MAK Key
  1557. :: 3rd column = SKU ID
  1558. :: 4th column = Key part number
  1559. :: 5th column = Ticket signature value. It's as it is, it's not encoded. (Check mass grave[.]dev/hwid#manual-activation to see how it's generated)
  1560. :: 6th column = 1 = activation is not working (at the time of writing this), 0 = activation is working
  1561. :: 7th column = Key Type
  1562. :: 8th column = WMI Edition ID (For reference only)
  1563. :: 9th column = Version name incase same Edition ID is used in different OS versions with different key
  1564. :: Separator = _
  1565. :hwiddata
  1566. set f=
  1567. for %%# in (
  1568. 8b351c9c-f398-4515-9900-09df49427262_XGVPP-NMH47-7TTHJ-W3FW7-8H%f%V2C___4_X19-99683_HGNKjkKcKQHO6n8srMUrDh/MElffBZarLqCMD9rWtgFKf3YzYOLDPEMGhuO/auNMKCeiU7ebFbQALS/MyZ7TvidMQ2dvzXeXXKzPBjfwQx549WJUU7qAQ9Txg9cR9SAT8b12Pry2iBk+nZWD9VtHK3kOnEYkvp5WTCTsrSi6Re4_0_OEM:NONSLP_Enterprise
  1569. c83cef07-6b72-4bbc-a28f-a00386872839_3V6Q6-NQXCX-V8YXR-9QCYV-QP%f%FCT__27_X19-98746_NHn2n0N1UfVf00CfaI5LCDMDsKdVAWpD/HAfUrcTAKsw9d2Sks4h5MhyH/WUx+B6dFi8ol7D3AHorR8y9dqVS1Bd2FdZNJl/tTR1PGwYn6KL88NS19aHmFNdX8s4438vaa+Ty8Qk8EDcwm/wscC8lQmi3/RgUKYdyGFvpbGSVlk_0_Volume:MAK_EnterpriseN
  1570. 4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T__48_X19-98841_Yl/jNfxJ1SnaIZCIZ4m6Pf3ySNoQXifNeqfltNaNctx+onwiivOx7qcSn8dFtURzgMzSOFnsRQzb5IrvuqHoxWWl1S3JIQn56FvKsvSx7aFXIX3+2Q98G1amPV/WEQ0uHA5d7Ya6An+g0Z0zRP7evGoomTs4YuweaWiZQjQzSpA_0_____Retail_Professional
  1571. 9fbaf5d6-4d83-4422-870d-fdda6e5858aa_2B87N-8KFHP-DKV6R-Y2C8J-PK%f%CKT__49_X19-98859_Ge0mRQbW8ALk7T09V+1k1yg66qoS0lhkgPIROOIOgxKmWPAvsiLAYPKDqM4+neFCA/qf1dHFmdh0VUrwFBPYsK251UeWuElj4bZFVISL6gUt1eZwbGfv5eurQ0i+qZiFv+CcQOEFsd5DD4Up6xPLLQS3nAXODL5rSrn2sHRoCVY_0_____Retail_ProfessionalN
  1572. f742e4ff-909d-4fe9-aacb-3231d24a0c58_4CPRK-NM3K3-X6XXQ-RXX86-WX%f%CHW__98_X19-98877_vel4ytVtnE8FhvN87Cflz9sbh5QwHD1YGOeej9QP7hF3vlBR4EX2/S/09gRneeXVbQnjDOCd2KFMKRUWHLM7ZhFBk8AtlG+kvUawPZ+CIrwrD3mhi7NMv8UX/xkLK3HnBupMEuEwsMJgCUD8Pn6om1mEiQebHBAqu4cT7GN9Y0g_0_____Retail_CoreN
  1573. 1d1bac85-7365-4fea-949a-96978ec91ae0_N2434-X9D7W-8PF6X-8DV9T-8T%f%YMD__99_X19-99652_Nv17eUTrr1TmUX6frlI7V69VR6yWb7alppCFJPcdjfI+xX4/Cf2np3zm7jmC+zxFb9nELUs477/ydw2KCCXFfM53bKpBQZKHE5+MdGJGxebOCcOtJ3hrkDJtwlVxTQmUgk5xnlmpk8PHg82M2uM5B7UsGLxGKK4d3hi0voSyKeI_0_____Retail_CoreCountrySpecific
  1574. 3ae2cc14-ab2d-41f4-972f-5e20142771dc_BT79Q-G7N6G-PGBYW-4YWX6-6F%f%4BT_100_X19-99661_FV2Eao/R5v8sGrfQeOjQ4daokVlNOlqRCDZXuaC45bQd5PsNU3t1b4AwWeYM8TAwbHauzr4tPG0UlsUqUikCZHy0poROx35bBBMBym6Zbm9wDBVyi7nCzBtwS86eOonQ3cU6WfZxhZRze0POdR33G3QTNPrnVIM2gf6nZJYqDOA_0_____Retail_CoreSingleLanguage
  1575. 2b1f36bb-c1cd-4306-bf5c-a0367c2d97d8_YTMG3-N6DKC-DKB77-7M9GH-8H%f%VX7_101_X19-98868_GH/jwFxIcdQhNxJIlFka8c1H48PF0y7TgJwaryAUzqSKXynONLw7MVciDJFVXTkCjbXSdxLSWpPIC50/xyy1rAf8aC7WuN/9cRNAvtFPC1IVAJaMeq1vf4mCqRrrxJQP6ZEcuAeHFzLe/LLovGWCd8rrs6BbBwJXCvAqXImvycQ_0_____Retail_Core
  1576. 2a6137f3-75c0-4f26-8e3e-d83d802865a4_XKCNC-J26Q9-KFHD2-FKTHY-KD%f%72Y_119_X19-99606_hci78IRWDLBtdbnAIKLDgV9whYgtHc1uYyp9y6FszE9wZBD5Nc8CUD2pI2s2RRd3M04C4O7M3tisB3Ov/XVjpAbxlX3MWfUR5w4MH0AphbuQX0p5MuHEDYyfqlRgBBRzOKePF06qfYvPQMuEfDpKCKFwNojQxBV8O0Arf5zmrIw_0_OEM:NONSLP_PPIPro
  1577. e558417a-5123-4f6f-91e7-385c1c7ca9d4_YNMGQ-8RYV3-4PGQ3-C8XTP-7C%f%FBY_121_X19-98886_x9tPFDZmjZMf29zFeHV5SHbXj8Wd8YAcCn/0hbpLcId4D7OWqkQKXxXHIegRlwcWjtII0sZ6WYB0HQV2KH3LvYRnWKpJ5SxeOgdzBIJ6fhegYGGyiXsBv9sEb3/zidPU6ZK9LugVGAcRZ6HQOiXyOw+Yf5H35iM+2oDZXSpjvJw_0_____Retail_Education
  1578. c5198a66-e435-4432-89cf-ec777c9d0352_84NGF-MHBT6-FXBX8-QWJK7-DR%f%R8H_122_X19-98892_jkL4YZkmBCJtvL1fT30ZPBcjmzshBSxjwrE0Q00AZ1hYnhrH+npzo1MPCT6ZRHw19ZLTz7wzyBb0qqcBVbtEjZW0Xs2MYLxgriyoONkhnPE6KSUJBw7C0enFVLHEqnVu/nkaOFfockN3bc+Eouw6W2lmHjklPHc9c6Clo04jul0_0_____Retail_EducationN
  1579. f6e29426-a256-4316-88bf-cc5b0f95ec0c_PJB47-8PN2T-MCGDY-JTY3D-CB%f%CPV_125_X23-50331_OPGhsyx+Ctw7w/KLMRNrY+fNBmKPjUG0R9RqkWk4e8ez+ExSJxSLLex5WhO5QSNgXLmEra+cCsN6C638aLjIdH2/L7D+8z/C6EDgRvbHMmidHg1lX3/O8lv0JudHkGtHJYewjorn/xXGY++vOCTQdZNk6qzEgmYSvPehKfdg8js_1_Volume:MAK_EnterpriseS_Ge
  1580. cce9d2de-98ee-4ce2-8113-222620c64a27_KCNVH-YKWX8-GJJB9-H9FDT-6F%f%7W2_125_X22-66075_GCqWmJOsTVun9z4QkE9n2XqBvt3ZWSPl9QmIh9Q2mXMG/QVt2IE7S+ES/NWlyTSNjLVySr1D2sGjxgEzy9kLwn7VENQVJ736h1iOdMj/3rdqLMSpTa813+nPSQgKpqJ3uMuvIvRP0FdB7Y4qt8qf9kNKK25A1QknioD/6YubL/4_1_Volume:MAK_EnterpriseS_VB
  1581. d06934ee-5448-4fd1-964a-cd077618aa06_43TBQ-NH92J-XKTM7-KT3KK-P3%f%9PB_125_X21-83233_EpB6qOCo8pRgO5kL4vxEHck2J1vxyd9OqvxUenDnYO9AkcGWat/D74ZcFg5SFlIya1U8l5zv+tsvZ4wAvQ1IaFW1PwOKJLOaGgejqZ41TIMdFGGw+G+s1RHsEnrWr3UOakTodby1aIMUMoqf3NdaM5aWFo8fOmqWC5/LnCoighs_0_OEM:NONSLP_EnterpriseS_RS5
  1582. 706e0cfd-23f4-43bb-a9af-1a492b9f1302_NK96Y-D9CD8-W44CQ-R8YTK-DY%f%JWX_125_X21-05035_ntcKmazIvLpZOryft28gWBHu1nHSbR+Gp143f/BiVe+BD2UjHBZfSR1q405xmQZsygz6VRK6+zm8FPR++71pkmArgCLhodCQJ5I4m7rAJNw/YX99pILphi1yCRcvHsOTGa825GUVXgf530tHT6hr0HQ1lGeGgG1hPekpqqBbTlg_0_OEM:NONSLP_EnterpriseS_RS1
  1583. faa57748-75c8-40a2-b851-71ce92aa8b45_FWN7H-PF93Q-4GGP8-M8RF3-MD%f%WWW_125_X19-99617_Fe9CDClilrAmwwT7Yhfx67GafWRQEpwyj8R+a4eaTqbpPcAt7d1hv1rx8Sa9AzopEGxIrb7IhiPoDZs0XaT1HN0/olJJ/MnD73CfBP4sdQdLTsSJE3dKMWYTQHpnjqRaS/pNBYRr8l9Mv8yfcP8uS2MjIQ1cRTqRmC7WMpShyCg_0_OEM:NONSLP_EnterpriseS_TH
  1584. 3d1022d8-969f-4222-b54b-327f5a5af4c9_2DBW3-N2PJG-MVHW3-G7TDK-9H%f%KR4_126_X21-04921_zLPNvcl1iqOefy0VLg+WZgNtRNhuGpn8+BFKjMqjaNOSKiuDcR6GNDS5FF1Aqk6/e6shJ+ohKzuwrnmYq3iNQ3I2MBlYjM5kuNfKs8Vl9dCjSpQr//GBGps6HtF2xrG/2g/yhtYC7FbtGDIE16uOeNKFcVg+XMb0qHE/5Etyfd8_0_Volume:MAK_EnterpriseSN_RS1
  1585. 60c243e1-f90b-4a1b-ba89-387294948fb6_NTX6B-BRYC2-K6786-F6MVQ-M7%f%V2X_126_X19-98770_kbXfe0z9Vi1S0yfxMWzI5+UtWsJKzxs7wLGUDLjrckFDn1bDQb4MvvuCK1w+Qrq33lemiGpNDspa+ehXiYEeSPFcCvUBpoMlGBFfzurNCHWiv3o1k3jBoawJr/VoDoVZfxhkps0fVoubf9oy6C6AgrkZ7PjCaS58edMcaUWvYYg_0_Volume:MAK_EnterpriseSN_TH
  1586. 01eb852c-424d-4060-94b8-c10d799d7364_3XP6D-CRND4-DRYM2-GM84D-4G%f%G8Y_139_X23-37869_PVW0XnRJnsWYjTqxb6StCi2tge/uUwegjdiFaFUiZpwdJ620RK+MIAsSq5S+egXXzIWNntoy2fB6BO8F1wBFmxP/mm/3rn5C33jtF5QrbNqY7X9HMbqSiC7zhs4v4u2Xa4oZQx8JQkwr8Q2c/NgHrOJKKRASsSckhunxZ+WVEuM_1_____Retail_ProfessionalCountrySpecific_Zn
  1587. eb6d346f-1c60-4643-b960-40ec31596c45_DXG7C-N36C4-C4HTG-X4T3X-2Y%f%V77_161_X21-43626_MaVqTkRrGnOqYizl15whCOKWzx01+BZTVAalvEuHXM+WV55jnIfhWmd/u1GqCd5OplqXdU959zmipK2Iwgu2nw/g91nW//sQiN/cUcvg1Lxo6pC3gAo1AjTpHmGIIf9XlZMYlD+Vl6gXsi/Auwh3yrSSFh5s7gOczZoDTqQwHXA_0_____Retail_ProfessionalWorkstation
  1588. 89e87510-ba92-45f6-8329-3afa905e3e83_WYPNQ-8C467-V2W6J-TX4WX-WT%f%2RQ_162_X21-43644_JVGQowLiCcPtGY9ndbBDV+rTu/q5ljmQTwQWZgBIQsrAeQjLD8jLEk/qse7riZ7tMT6PKFVNXeWqF7PhLAmACbE8O3Lvp65XMd/Oml9Daynj5/4n7unsffFHIHH8TGyO5j7xb4dkFNqC5TX3P8/1gQEkTIdZEOTQQXFu0L2SP5c_0_____Retail_ProfessionalWorkstationN
  1589. 62f0c100-9c53-4e02-b886-a3528ddfe7f6_8PTT6-RNW4C-6V7J2-C2D3X-MH%f%BPB_164_X21-04955_CEDgxI8f/fxMBiwmeXw5Of55DG32sbGALzHihXkdbYTDaE3pY37oAA4zwGHALzAFN/t254QImGPYR6hATgl+Cp804f7serJqiLeXY965Zy67I4CKIMBm49lzHLFJeDnVTjDB0wVyN29pvgO3+HLhZ22KYCpkRHFFMy2OKxS68Yc_0_____Retail_ProfessionalEducation
  1590. 13a38698-4a49-4b9e-8e83-98fe51110953_GJTYN-HDMQY-FRR76-HVGC7-QP%f%F8P_165_X21-04956_r35zp9OfxKSBcTxKWon3zFtbOiCufAPo6xRGY5DJqCRFKdB0jgZalNQitvjmaZ/Rlez2vjRJnEart4LrvyW4d9rrukAjR3+c3UkeTKwoD3qBl9AdRJbXCa2BdsoXJs1WVS4w4LuVzpB/SZDuggZt0F2DlMB427F5aflook/n1pY_0_____Retail_ProfessionalEducationN
  1591. df96023b-dcd9-4be2-afa0-c6c871159ebe_NJCF7-PW8QT-3324D-688JX-2Y%f%V66_175_X21-41295_rVpetYUmiRB48YJfCvJHiaZapJ0bO8gQDRoql+rq5IobiSRu//efV1VXqVpBkwILQRKgKIVONSTUF5y2TSxlDLbDSPKp7UHfbz17g6vRKLwOameYEz0ZcK3NTbApN/cMljHvvF/mBag1+sHjWu+eoFzk8H89k9nw8LMeVOPJRDc_0_____Retail_ServerRdsh
  1592. d4ef7282-3d2c-4cf0-9976-8854e64a8d1e_V3WVW-N2PV2-CGWC3-34QGF-VM%f%J2C_178_X21-32983_Xzme9hDZR6H0Yx0deURVdE6LiTOkVqWng5W/OTbkxRc0rq+mSYpo/f/yqhtwYlrkBPWx16Yok5Bvcb34vbKHvEAtxfYp4te20uexLzVOtBcoeEozARv4W/6MhYfl+llZtR5efsktj4N4/G4sVbuGvZ9nzNfQO9TwV6NGgGEj2Ec_0_____Retail_Cloud
  1593. af5c9381-9240-417d-8d35-eb40cd03e484_NH9J3-68WK7-6FB93-4K3DF-DJ%f%4F6_179_X21-32987_QGRDZOU/VZhYLOSdp2xDnFs8HInNZctcQlWCIrORVnxTQr55IJwN4vK3PJHjkfRLQ/bgUrcEIhyFbANqZFUq8yD1YNubb2bjNORgI/m8u85O9V7nDGtxzO/viEBSWyEHnrzLKKWYqkRQKbbSW3ungaZR0Ti5O2mAUI4HzAFej50_0_____Retail_CloudN
  1594. 8ab9bdd1-1f67-4997-82d9-8878520837d9_XQQYW-NFFMW-XJPBH-K8732-CK%f%FFD_188_X21-99378_djy0od0uuKd2rrIl+V1/2+MeRltNgW7FEeTNQsPMkVSL75NBphgoso4uS0JPv2D7Y1iEEvmVq6G842Kyt52QOwXgFWmP/IQ6Sq1dr+fHK/4Et7bEPrrGBEZoCfWqk0kdcZRPBij2KN6qCRWhrk1hX2g+U40smx/EYCLGh9HCi24_0_____OEM:DM_IoTEnterprise
  1595. ed655016-a9e8-4434-95d9-4345352c2552_QPM6N-7J2WJ-P88HH-P3YRH-YY%f%74H_191_X21-99682_qHs/PzfhYWdtSys2edzcz4h+Qs8aDqb8BIiQ/mJ/+0uyoJh1fitbRCIgiFh2WAGZXjdgB8hZeheNwHibd8ChXaXg4u+0XlOdFlaDTgTXblji8fjETzDBk9aGkeMCvyVXRuUYhTSdp83IqGHz7XuLwN2p/6AUArx9JZCoLGV8j3w_0_OEM:NONSLP_IoTEnterpriseS_VB
  1596. 6c4de1b8-24bb-4c17-9a77-7b939414c298_CGK42-GYN6Y-VD22B-BX98W-J8%f%JXD_191_X23-12617_J/fpIRynsVQXbp4qZNKp6RvOgZ/P2klILUKQguMlcwrBZybwNkHg/kM5LNOF/aDzEktbPnLnX40GEvKkYT6/qP4cMhn/SOY0/hYOkIdR34ilzNlVNq5xP7CMjCjaUYJe+6ydHPK6FpOuEoWOYYP5BZENKNGyBy4w4shkMAw19mA_0_OEM:NONSLP_IoTEnterpriseS_Ge
  1597. d4bdc678-0a4b-4a32-a5b3-aaa24c3b0f24_K9VKN-3BGWV-Y624W-MCRMQ-BH%f%DCD_202_X22-53884_kyoNx2s93U6OUSklB1xn+GXcwCJO1QTEtACYnChi8aXSoxGQ6H2xHfUdHVCwUA1OR0UeNcRrMmOzZBOEUBtdoGWSYPg9AMjvxlxq9JOzYAH+G6lT0UbCWgMSGGrqdcIfmshyEak3aUmsZK6l+uIAFCCZZ/HbbCRkkHC5rWKstMI_0_____Retail_CloudEditionN
  1598. 92fb8726-92a8-4ffc-94ce-f82e07444653_KY7PN-VR6RX-83W6Y-6DDYQ-T6%f%R4W_203_X22-53847_gD6HnT4jP4rcNu9u83gvDiQq1xs7QSujcDbo60Di5iSVa9/ihZ7nlhnA0eDEZfnoDXriRiPPqc09T6AhSnFxLYitAkOuPJqL5UMobIrab9dwTKlowqFolxoHhLOO4V92Hsvn/9JLy7rEzoiAWHhX/0cpMr3FCzVYPeUW1OyLT1A_0_____Retail_CloudEdition
  1599. 5a85300a-bfce-474f-ac07-a30983e3fb90_N979K-XWD77-YW3GB-HBGH6-D3%f%2MH_205_X23-15042_blZopkUuayCTgZKH4bOFiisH9GTAHG5/js6UX/qcMWWc3sWNxKSX1OLp1k3h8Xx1cFuvfG/fNAw/I83ssEtPY+A0Gx1JF4QpRqsGOqJ5ruQ2tGW56CJcCVHkB+i46nJAD759gYmy3pEYMQbmpWbhLx3MJ6kvwxKfU+0VCio8k50_0_____OEM:DM_IoTEnterpriseSK
  1600. 80083eae-7031-4394-9e88-4901973d56fe_P8Q7T-WNK7X-PMFXY-VXHBG-RR%f%K69_206_X23-62084_habUJ0hhAG0P8iIKaRQ74/wZQHyAdFlwHmrejNjOSRG08JeqilJlTM6V8G9UERLJ92/uMDVHIVOPXfN8Zdh8JuYO8oflPnqymIRmff/pU+Gpb871jV2JDA4Cft5gmn+ictKoN4VoSfEZRR+R5hzF2FsoCExDNNw6gLdjtiX94uA_0_____OEM:DM_IoTEnterpriseK
  1601. ) do (
  1602. for /f "tokens=1-9 delims=_" %%A in ("%%#") do (
  1603. REM Detect key
  1604. if %1==key if %osSKU%==%%C if not defined key (
  1605. echo "!allapps! !altapplist!" | find /i "%%A" %nul1% && (
  1606. if %%F==1 set notworking=1
  1607. set key=%%B
  1608. )
  1609. )
  1610. REM Generate ticket
  1611. if %1==ticket if "%key%"=="%%B" (
  1612. set "string=OSMajorVersion=5;OSMinorVersion=1;OSPlatformId=2;PP=0;Pfn=Microsoft.Windows.%%C.%%D_8wekyb3d8bbwe;PKeyIID=465145217131314304264339481117862266242033457260311819664735280;$([char]0)"
  1613. for /f "tokens=* delims=" %%i in ('%psc% [conv%f%ert]::ToBas%f%e64String([Text.En%f%coding]::Uni%f%code.GetBytes("""!string!"""^)^)') do set "encoded=%%i"
  1614. echo "!encoded!" | find "AAAA" %nul1% || exit /b
  1615. <nul set /p "=<?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>OA3xOriginalProductId=;OA3xOriginalProductKey=;SessionId=!encoded!;TimeStampClient=2022-10-11T12:00:00Z</properties><signatures><signature name="clientLockboxKey" method="rsa-sha256">%%E=</signature></signatures></genuineProperties></genuineAuthorization>" >"%tdir%\GenuineTicket"
  1616. )
  1617. )
  1618. )
  1619. exit /b
  1620. ::========================================================================================================================================
  1621. :: Below code is used to get alternate edition name and key if current edition doesn't support HWID activation
  1622. :: 1st column = Current SKU ID
  1623. :: 2nd column = Current Edition Name
  1624. :: 3rd column = Current Edition Activation ID
  1625. :: 4th column = Alternate Edition Activation ID
  1626. :: 5th column = Alternate Edition HWID Key
  1627. :: 6th column = Alternate Edition Name
  1628. :: Separator = _
  1629. :hwidfallback
  1630. set notfoundaltactID=
  1631. if %_NoEditionChange%==1 exit /b
  1632. for %%# in (
  1633. 125_EnterpriseS-2021_______________cce9d2de-98ee-4ce2-8113-222620c64a27_ed655016-a9e8-4434-95d9-4345352c2552_QPM6N-7J2WJ-P88HH-P3YRH-YY%f%74H_IoTEnterpriseS-2021
  1634. 125_EnterpriseS-2024_______________f6e29426-a256-4316-88bf-cc5b0f95ec0c_6c4de1b8-24bb-4c17-9a77-7b939414c298_CGK42-GYN6Y-VD22B-BX98W-J8%f%JXD_IoTEnterpriseS-2024
  1635. 138_ProfessionalSingleLanguage_____a48938aa-62fa-4966-9d44-9f04da3f72f2_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional
  1636. 139_ProfessionalCountrySpecific____f7af7d09-40e4-419c-a49b-eae366689ebd_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional
  1637. 139_ProfessionalCountrySpecific-Zn_01eb852c-424d-4060-94b8-c10d799d7364_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional
  1638. ) do (
  1639. for /f "tokens=1-6 delims=_" %%A in ("%%#") do if %osSKU%==%%A (
  1640. echo "!allapps! !altapplist!" | find /i "%%C" %nul1% && (
  1641. echo "!allapps!" | find /i "%%D" %nul1% && (
  1642. set altkey=%%E
  1643. set altedition=%%F
  1644. ) || (
  1645. set altedition=%%F
  1646. set notfoundaltactID=1
  1647. )
  1648. )
  1649. )
  1650. )
  1651. exit /b
  1652. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1653. :OhookActivation
  1654. :: To activate Office with Ohook activation, run the script with "/Ohook" parameter or change 0 to 1 in below line
  1655. set _act=0
  1656. :: To remove Ohook activation, run the script with /Ohook-Uninstall parameter or change 0 to 1 in below line
  1657. set _rem=0
  1658. :: If value is changed in above lines or parameter is used then script will run in unattended mode
  1659. ::========================================================================================================================================
  1660. cls
  1661. color 07
  1662. title Ohook Activation %masver%
  1663. set _args=
  1664. set _elev=
  1665. set _unattended=0
  1666. set _args=%*
  1667. if defined _args set _args=%_args:"=%
  1668. if defined _args (
  1669. for %%A in (%_args%) do (
  1670. if /i "%%A"=="/Ohook" set _act=1
  1671. if /i "%%A"=="/Ohook-Uninstall" set _rem=1
  1672. if /i "%%A"=="-el" set _elev=1
  1673. )
  1674. )
  1675. for %%A in (%_act% %_rem%) do (if "%%A"=="1" set _unattended=1)
  1676. ::========================================================================================================================================
  1677. if %winbuild% LSS 9200 (
  1678. %eline%
  1679. echo Unsupported OS version detected [%winbuild%].
  1680. echo Ohook Activation is supported only on Windows 8/10/11 and their server equivalents.
  1681. echo:
  1682. call :dk_color %Blue% "Use Online KMS activation option instead."
  1683. goto dk_done
  1684. )
  1685. ::========================================================================================================================================
  1686. if %_rem%==1 goto :oh_uninstall
  1687. :oh_menu
  1688. if %_unattended%==0 (
  1689. cls
  1690. if not defined terminal mode 76, 25
  1691. title Ohook Activation %masver%
  1692. call :oh_checkapps
  1693. echo:
  1694. echo:
  1695. echo:
  1696. echo:
  1697. if defined checknames (call :dk_color %_Yellow% " Close [!checknames!] before proceeding...")
  1698. echo ____________________________________________________________
  1699. echo:
  1700. echo [1] Install Ohook Office Activation
  1701. echo:
  1702. echo [2] Uninstall Ohook
  1703. echo ____________________________________________
  1704. echo:
  1705. echo [3] Download Office
  1706. echo:
  1707. echo [0] %_exitmsg%
  1708. echo ____________________________________________________________
  1709. echo:
  1710. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,3,0]"
  1711. choice /C:1230 /N
  1712. set _el=!errorlevel!
  1713. if !_el!==4 exit /b
  1714. if !_el!==3 start %mas%genuine-installation-media &goto :oh_menu
  1715. if !_el!==2 goto :oh_uninstall
  1716. if !_el!==1 goto :oh_menu2
  1717. goto :oh_menu
  1718. )
  1719. ::========================================================================================================================================
  1720. :oh_menu2
  1721. cls
  1722. if not defined terminal (
  1723. mode 130, 32
  1724. if exist "%SysPath%\spp\store_test\" mode 134, 32
  1725. %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%
  1726. )
  1727. title Ohook Activation %masver%
  1728. echo:
  1729. echo Initializing...
  1730. call :dk_chkmal
  1731. if not exist %SysPath%\sppsvc.exe (
  1732. %eline%
  1733. echo [%SysPath%\sppsvc.exe] file is missing, aborting...
  1734. echo:
  1735. set fixes=%fixes% %mas%troubleshoot
  1736. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  1737. goto dk_done
  1738. )
  1739. ::========================================================================================================================================
  1740. set spp=SoftwareLicensingProduct
  1741. set sps=SoftwareLicensingService
  1742. call :dk_reflection
  1743. call :dk_ckeckwmic
  1744. call :dk_product
  1745. call :dk_sppissue
  1746. ::========================================================================================================================================
  1747. set error=
  1748. cls
  1749. echo:
  1750. call :dk_showosinfo
  1751. ::========================================================================================================================================
  1752. echo Initiating Diagnostic Tests...
  1753. set "_serv=sppsvc Winmgmt"
  1754. :: Software Protection
  1755. :: Windows Management Instrumentation
  1756. set notwinact=1
  1757. set ohookact=1
  1758. call :dk_errorcheck
  1759. :: Check unsupported office versions
  1760. set o14msi=
  1761. set o14c2r=
  1762. set o16uwp=
  1763. set _68=HKLM\SOFTWARE\Microsoft\Office
  1764. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  1765. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o14msi=Office 2010 MSI )
  1766. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o14msi=Office 2010 MSI )
  1767. %nul% reg query %_68%\14.0\CVH /f Click2run /k && set o14c2r=Office 2010 C2R
  1768. %nul% reg query %_86%\14.0\CVH /f Click2run /k && set o14c2r=Office 2010 C2R
  1769. if %winbuild% GEQ 10240 (
  1770. for /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 )
  1771. )
  1772. if not "%o14msi%%o14c2r%%o16uwp%"=="" (
  1773. echo:
  1774. call :dk_color %Red% "Checking Unsupported Office Install [ %o14msi%%o14c2r%%o16uwp%]"
  1775. if not "%o14msi%%o16uwp%"=="" call :dk_color %Blue% "Use Online KMS option to activate it."
  1776. )
  1777. if %winbuild% GEQ 10240 %psc% "Get-AppxPackage -name "Microsoft.MicrosoftOfficeHub"" | find /i "Office" %nul1% && (
  1778. set ohub=1
  1779. )
  1780. ::========================================================================================================================================
  1781. :: Check supported office versions
  1782. call :oh_getpath
  1783. sc query ClickToRunSvc %nul%
  1784. set error1=%errorlevel%
  1785. if defined o16c2r if %error1% EQU 1060 (
  1786. call :dk_color %Red% "Checking ClickToRun Service [Not found, Office 16.0 files found]"
  1787. set o16c2r=
  1788. set error=1
  1789. )
  1790. sc query OfficeSvc %nul%
  1791. set error2=%errorlevel%
  1792. if defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (
  1793. call :dk_color %Red% "Checking ClickToRun Service [Not found, Office 15.0 files found]"
  1794. set o15c2r=
  1795. set error=1
  1796. )
  1797. if "%o16c2r%%o15c2r%%o16msi%%o15msi%"=="" (
  1798. set error=1
  1799. echo:
  1800. if not "%o14msi%%o14c2r%%o16uwp%"=="" (
  1801. call :dk_color %Red% "Checking Supported Office Install [Not Found]"
  1802. ) else (
  1803. call :dk_color %Red% "Checking Installed Office [Not Found]"
  1804. )
  1805. if defined ohub (
  1806. echo:
  1807. echo You only have the Office dashboard app installed, you need to install the full version of Office.
  1808. )
  1809. echo:
  1810. call :dk_color %Blue% "Download and install Office from the below URL and then try again."
  1811. echo:
  1812. set fixes=%fixes% %mas%genuine-installation-media
  1813. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  1814. goto dk_done
  1815. )
  1816. set multioffice=
  1817. if not "%o16c2r%%o15c2r%%o16msi%%o15msi%"=="1" set multioffice=1
  1818. if not "%o14msi%%o14c2r%%o16uwp%"=="" set multioffice=1
  1819. if defined multioffice (
  1820. call :dk_color %Gray% "Checking Multiple Office Install [Found, its recommended to install only one version]"
  1821. )
  1822. ::========================================================================================================================================
  1823. :: Check Windows Server
  1824. set winserver=
  1825. reg query "HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" /v ProductType %nul2% | find /i "WinNT" %nul1% || set winserver=1
  1826. if not defined winserver (
  1827. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Server" %nul1% && set winserver=1
  1828. )
  1829. ::========================================================================================================================================
  1830. :: Process Office 15.0 C2R
  1831. if not defined o15c2r goto :starto16c2r
  1832. call :oh_reset
  1833. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  1834. set oVer=15
  1835. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  1836. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  1837. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  1838. for /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")
  1839. if not defined _oArch for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v Platform" %nul6%') do (set "_oArch=%%b")
  1840. if not defined _version for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v version" %nul6%') do (set "_version=%%b")
  1841. if 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")
  1842. echo "%o15c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=10) || (set _tok=9)
  1843. for /f "tokens=%_tok% delims=\" %%a in ('reg query %o15c2r_reg%\ProductReleaseIDs\Active %nul6% ^| findstr /i "Retail Volume"') do (
  1844. echo "!_oIds!" | find /i " %%a " %nul1% || (set "_oIds= !_oIds! %%a ")
  1845. )
  1846. set "_oLPath=%_oRoot%\Licenses"
  1847. set "_oIntegrator=%_oRoot%\integration\integrator.exe"
  1848. if /i "%_oArch%"=="x64" (set "_hookPath=%_oRoot%\vfs\System" & set "_hook=sppc64.dll")
  1849. if /i "%_oArch%"=="x86" (set "_hookPath=%_oRoot%\vfs\SystemX86" & set "_hook=sppc32.dll")
  1850. if not "%osarch%"=="x86" (
  1851. if /i "%_oArch%"=="x64" set "_sppcPath=%SystemRoot%\System32\sppc.dll"
  1852. if /i "%_oArch%"=="x86" set "_sppcPath=%SystemRoot%\SysWOW64\sppc.dll"
  1853. ) else (
  1854. set "_sppcPath=%SystemRoot%\System32\sppc.dll"
  1855. )
  1856. echo:
  1857. echo Activating Office... [C2R ^| %_version% ^| %_oArch%]
  1858. if not defined _oIds (
  1859. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  1860. set error=1
  1861. goto :starto16c2r
  1862. )
  1863. call :oh_fixprids
  1864. call :oh_process
  1865. call :oh_hookinstall
  1866. ::========================================================================================================================================
  1867. :starto16c2r
  1868. :: Process Office 16.0 C2R
  1869. if not defined o16c2r goto :startmsi
  1870. call :oh_reset
  1871. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  1872. set oVer=16
  1873. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  1874. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  1875. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  1876. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v AudienceData" %nul6%') do (set "_AudienceData=^| %%b ")
  1877. for /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")
  1878. echo "%o16c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=9) || (set _tok=8)
  1879. for /f "tokens=%_tok% delims=\" %%a in ('reg query "%o16c2r_reg%\ProductReleaseIDs" /s /f ".16" /k %nul6% ^| findstr /i "Retail Volume"') do (
  1880. echo "!_oIds!" | find /i " %%a " %nul1% || (set "_oIds= !_oIds! %%a ")
  1881. )
  1882. set _oIds=%_oIds:.16=%
  1883. set _o16c2rIds=%_oIds%
  1884. set "_oLPath=%_oRoot%\Licenses16"
  1885. set "_oIntegrator=%_oRoot%\integration\integrator.exe"
  1886. if /i "%_oArch%"=="x64" (set "_hookPath=%_oRoot%\vfs\System" & set "_hook=sppc64.dll")
  1887. if /i "%_oArch%"=="x86" (set "_hookPath=%_oRoot%\vfs\SystemX86" & set "_hook=sppc32.dll")
  1888. if not "%osarch%"=="x86" (
  1889. if /i "%_oArch%"=="x64" set "_sppcPath=%SystemRoot%\System32\sppc.dll"
  1890. if /i "%_oArch%"=="x86" set "_sppcPath=%SystemRoot%\SysWOW64\sppc.dll"
  1891. ) else (
  1892. set "_sppcPath=%SystemRoot%\System32\sppc.dll"
  1893. )
  1894. echo:
  1895. echo Activating Office... [C2R ^| %_version% %_AudienceData%^| %_oArch%]
  1896. if not defined _oIds (
  1897. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  1898. set error=1
  1899. goto :startmsi
  1900. )
  1901. call :oh_fixprids
  1902. call :oh_process
  1903. call :oh_hookinstall
  1904. ::========================================================================================================================================
  1905. :: Old version (16.0.9xxxx and below) of Office with subscription license key may show a banner to sign in to fix license issue.
  1906. :: Although script applies a Resiliency registry entry to fix that but it doesn't work on old office versions.
  1907. :: Below code checks that condition and informs the user to update the Office.
  1908. if defined _sublic (
  1909. if not exist "%_oLPath%\Word2019VL_KMS_Client_AE*.xrm-ms" (
  1910. call :dk_color %Gray% "Checking Old Office With Sub License [Found. Update Office, otherwise, it may show a licensing issue-related banner.]"
  1911. )
  1912. )
  1913. ::========================================================================================================================================
  1914. :: mass grave[.]dev/office-license-is-not-genuine
  1915. :: Add registry keys for volume products so that 'non-genuine' banner won't appear
  1916. :: 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
  1917. set "kmskey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\0ff1ce15-a989-479d-af46-f275c6370663"
  1918. echo "%_oIds%" | find /i "Volume" %nul1% && (
  1919. if %winbuild% GEQ 9200 (
  1920. if not "%osarch%"=="x86" (
  1921. reg delete "%kmskey%" /f /reg:32 %nul%
  1922. reg add "%kmskey%" /f /v KeyManagementServiceName /t REG_SZ /d "10.0.0.10" /reg:32 %nul%
  1923. )
  1924. reg delete "%kmskey%" /f %nul%
  1925. reg add "%kmskey%" /f /v KeyManagementServiceName /t REG_SZ /d "10.0.0.10" %nul%
  1926. echo Adding a Registry to Prevent Banner [Successful]
  1927. )
  1928. )
  1929. ::========================================================================================================================================
  1930. :startmsi
  1931. if defined o15msi call :oh_processmsi 15 %o15msi_reg%
  1932. if defined o16msi call :oh_processmsi 16 %o16msi_reg%
  1933. ::========================================================================================================================================
  1934. call :oh_clearblock
  1935. call :oh_uninstkey
  1936. call :oh_licrefresh
  1937. ::========================================================================================================================================
  1938. echo:
  1939. if not defined error (
  1940. call :dk_color %Green% "Office is permanently activated."
  1941. if defined ohub call :dk_color %Gray% "Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app."
  1942. echo Help: %mas%troubleshoot
  1943. ) else (
  1944. call :dk_color %Red% "Some errors were detected."
  1945. if not defined ierror if not defined showfix if not defined serv_cor if not defined serv_cste call :dk_color %Blue% "%_fixmsg%"
  1946. echo:
  1947. set fixes=%fixes% %mas%troubleshoot
  1948. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  1949. )
  1950. goto :dk_done
  1951. ::========================================================================================================================================
  1952. :oh_uninstall
  1953. cls
  1954. if not defined terminal mode 99, 32
  1955. title Uninstall Ohook Activation %masver%
  1956. set _present=
  1957. set _unerror=
  1958. call :oh_reset
  1959. call :oh_getpath
  1960. echo:
  1961. echo Uninstalling Ohook activation...
  1962. echo:
  1963. if defined o16c2r_reg (for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg% /v InstallPath" %nul6%') do (set "_16CHook=%%b\root\vfs"))
  1964. if defined o15c2r_reg (for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg% /v InstallPath" %nul6%') do (set "_15CHook=%%b\root\vfs"))
  1965. if defined o16msi_reg (for /f "skip=2 tokens=2*" %%a in ('"reg query %o16msi_reg%\Common\InstallRoot /v Path" %nul6%') do (set "_16MHook=%%b"))
  1966. if defined o15msi_reg (for /f "skip=2 tokens=2*" %%a in ('"reg query %o15msi_reg%\Common\InstallRoot /v Path" %nul6%') do (set "_15MHook=%%b"))
  1967. if 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))
  1968. if 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))
  1969. if 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))
  1970. if 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))
  1971. if 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))
  1972. if 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))
  1973. for %%# in (15 16) do (
  1974. for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do (
  1975. if 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)
  1976. )
  1977. )
  1978. for %%# in (System SystemX86) do (
  1979. for %%G in ("Office 15" "Office") do (
  1980. for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do (
  1981. if 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)
  1982. )
  1983. )
  1984. )
  1985. reg query HKCU\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency %nul% && (
  1986. echo:
  1987. echo Deleting - Registry keys for skipping license check
  1988. reg load HKU\DEF_TEMP %SystemDrive%\Users\Default\NTUSER.DAT %nul%
  1989. reg 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
  1990. reg unload HKU\DEF_TEMP %nul%
  1991. set _sidlist=
  1992. for /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))
  1993. if not defined _sidlist (
  1994. for /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)
  1995. )
  1996. for %%# in (!_sidlist!) do (
  1997. reg query HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency %nul% && reg delete HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /f
  1998. reg query HKU\%%#\Software %nul% || (
  1999. for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
  2000. reg load HKU\%%# "%%b\NTUSER.DAT" %nul%
  2001. reg query HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency %nul% && reg delete HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /f
  2002. reg unload HKU\%%# %nul%
  2003. )
  2004. )
  2005. )
  2006. )
  2007. set "kmskey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\0ff1ce15-a989-479d-af46-f275c6370663"
  2008. reg query "%kmskey%" %nul% && (
  2009. echo:
  2010. echo Deleting - Registry keys for preventing non-genuine banner
  2011. reg delete "%kmskey%" /f
  2012. )
  2013. reg query "%kmskey%" /reg:32 %nul% && (
  2014. reg delete "%kmskey%" /f /reg:32
  2015. )
  2016. echo __________________________________________________________________________________________
  2017. echo:
  2018. if not defined _present (
  2019. echo Ohook activation is not installed.
  2020. ) else (
  2021. if defined _unerror (
  2022. call :dk_color %Red% "Failed to uninstall Ohook activation."
  2023. call :oh_checkapps
  2024. if defined checknames (
  2025. call :dk_color %Blue% "Close [!checknames!] and try again."
  2026. call :dk_color %Blue% "If it is still not fixed, reboot your machine using the restart option and try again."
  2027. ) else (
  2028. call :dk_color %Blue% "Reboot your machine using the restart option and try again."
  2029. )
  2030. ) else (
  2031. call :dk_color %Green% "Successfully uninstalled Ohook activation."
  2032. )
  2033. )
  2034. echo __________________________________________________________________________________________
  2035. goto :dk_done
  2036. ::========================================================================================================================================
  2037. :oh_reset
  2038. set key=
  2039. set _oRoot=
  2040. set _oArch=
  2041. set _oIds=
  2042. set _oLPath=
  2043. set _hookPath=
  2044. set _hook=
  2045. set _sppcPath=
  2046. set _actid=
  2047. set _prod=
  2048. set _lic=
  2049. set _arr=
  2050. set _prids=
  2051. set _config=
  2052. set _version=
  2053. set _License=
  2054. set _oBranding=
  2055. exit /b
  2056. ::========================================================================================================================================
  2057. :oh_getpath
  2058. set o16c2r=
  2059. set o15c2r=
  2060. set o16msi=
  2061. set o15msi=
  2062. set _68=HKLM\SOFTWARE\Microsoft\Office
  2063. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  2064. for /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)
  2065. for /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)
  2066. for /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)
  2067. for /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)
  2068. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o16msi=1&set o16msi_reg=%_86%\16.0)
  2069. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o16msi=1&set o16msi_reg=%_68%\16.0)
  2070. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o15msi=1&set o15msi_reg=%_86%\15.0)
  2071. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o15msi=1&set o15msi_reg=%_68%\15.0)
  2072. exit /b
  2073. ::========================================================================================================================================
  2074. :: Some Office Retail to Volume converter tools may edit the ProductReleaseIds to add VL products. This code restores it because it may affect features.
  2075. :oh_fixprids
  2076. if not defined _prids (
  2077. call :dk_color %Gray% "Checking ProductReleaseIds In Registry [Not Found]"
  2078. exit /b
  2079. )
  2080. set _pridsR=
  2081. set _pridsE=
  2082. for /f "skip=2 tokens=2*" %%a in ('"reg query %_prids%" %nul6%') do (set "_pridsR=%%b")
  2083. set _pridsR=%_pridsR:,= %
  2084. for %%# in (%_pridsR%) do (echo %%# | findstr /I "%_oIds%" %nul1% || set _pridsE=1)
  2085. for %%# in (%_oIds%) do (echo %%# | findstr /I "%_pridsR%" %nul1% || set _pridsE=1)
  2086. if not defined _pridsE exit /b
  2087. reg add %_prids% /t REG_SZ /d "" /f %nul1%
  2088. for %%# in (%_oIds%) do (
  2089. for /f "skip=2 tokens=2*" %%a in ('reg query %_prids%') do if not "%%b"=="" (
  2090. reg add %_prids% /t REG_SZ /d "%%b,%%#" /f %nul1%
  2091. ) else (
  2092. reg add %_prids% /t REG_SZ /d "%%#" /f %nul1%
  2093. )
  2094. )
  2095. exit /b
  2096. ::========================================================================================================================================
  2097. :oh_installlic
  2098. if not defined _oLPath exit /b
  2099. if defined _oIntegrator (
  2100. if %oVer%==16 (
  2101. "!_oIntegrator!" /I /License PRIDName=%_License%.16 PidKey=%key% %nul%
  2102. ) else (
  2103. "!_oIntegrator!" /I /License PRIDName=%_License% PidKey=%key% %nul%
  2104. )
  2105. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  2106. echo "!allapps!" | find /i "!_actid!" %nul1% && exit /b
  2107. )
  2108. :: Fallback to manual method to install licenses incase integrator.exe is not working
  2109. set _License=%_License:XVolume=XC2RVL_%
  2110. set _License=%_License:O365EduCloudRetail=O365EduCloudEDUR_%
  2111. set _License=%_License:ProjectProRetail=ProjectProO365R_%
  2112. set _License=%_License:ProjectStdRetail=ProjectStdO365R_%
  2113. set _License=%_License:VisioProRetail=VisioProO365R_%
  2114. set _License=%_License:VisioStdRetail=VisioStdO365R_%
  2115. if defined _preview set _License=%_License:Volume=PreviewVL_%
  2116. set _License=%_License:Retail=R_%
  2117. set _License=%_License:Volume=VL_%
  2118. for %%# in ("!_oLPath!\client-issuance-*.xrm-ms") do (
  2119. if defined _arr (set "_arr=!_arr!;"!_oLPath!\%%~nx#"") else (set "_arr="!_oLPath!\%%~nx#"")
  2120. )
  2121. for %%# in ("!_oLPath!\%_License%*.xrm-ms") do (
  2122. if defined _arr (set "_arr=!_arr!;"!_oLPath!\%%~nx#"") else (set "_arr="!_oLPath!\%%~nx#"")
  2123. )
  2124. %psc% "$sls = Get-WmiObject %sps%; $f=[io.file]::ReadAllText('!_batp!') -split ':xrm\:.*';iex ($f[1]); InstallLicenseArr '!_arr!'; InstallLicenseFile '"!_oLPath!\pkeyconfig-office.xrm-ms"'" %nul%
  2125. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  2126. echo "!allapps!" | find /i "!_actid!" %nul1% || (
  2127. set error=1
  2128. call :dk_color %Red% "Installing Missing License Files [Office %oVer%.0 %_prod%] [Failed]"
  2129. )
  2130. exit /b
  2131. ::========================================================================================================================================
  2132. :oh_hookinstall
  2133. set ierror=
  2134. set hasherror=
  2135. if %_hook%==sppc32.dll set offset=2564
  2136. if %_hook%==sppc64.dll set offset=3076
  2137. del /s /q "%_hookPath%\sppcs.dll" %nul%
  2138. del /s /q "%_hookPath%\sppc.dll" %nul%
  2139. if exist "%_hookPath%\sppcs.dll" set "ierror=Remove Previous Ohook Install"
  2140. if exist "%_hookPath%\sppc.dll" set "ierror=Remove Previous Ohook Install"
  2141. mklink "%_hookPath%\sppcs.dll" "%_sppcPath%" %nul%
  2142. if not %errorlevel%==0 (
  2143. if not defined ierror set ierror=mklink
  2144. )
  2145. set exhook=
  2146. if exist "!_work!\BIN\%_hook%" set exhook=1
  2147. if not exist "%_hookPath%\sppc.dll" (
  2148. if defined exhook (
  2149. pushd "!_work!\BIN\"
  2150. copy /y /b "%_hook%" "%_hookPath%\sppc.dll" %nul%
  2151. popd
  2152. ) else (
  2153. call :oh_extractdll "%_hookPath%\sppc.dll" "%offset%"
  2154. )
  2155. )
  2156. if not exist "%_hookPath%\sppc.dll" (if not defined ierror set ierror=Copy)
  2157. echo:
  2158. if not defined ierror (
  2159. echo Symlinking System's sppc.dll to ["%_hookPath%\sppcs.dll"] [Successful]
  2160. if defined exhook (
  2161. echo Copying Custom %_hook% to ["%_hookPath%\sppc.dll"] [Successful]
  2162. ) else (
  2163. echo Extracting Custom %_hook% to ["%_hookPath%\sppc.dll"] [Successful]
  2164. )
  2165. ) else (
  2166. set error=1
  2167. call :dk_color %Red% "Installing Ohook [Failed to %ierror%]"
  2168. echo:
  2169. call :oh_checkapps
  2170. if defined checknames (
  2171. call :dk_color %Blue% "Close [!checknames!] and try again."
  2172. call :dk_color %Blue% "If it is still not fixed, reboot your machine using the restart option and try again."
  2173. ) else (
  2174. if /i not "%ierror%"=="Copy" call :dk_color %Blue% "Reboot your machine using the restart option and try again."
  2175. if /i "%ierror%"=="Copy" call :dk_color %Blue% "If you are using any third-party antivirus, check if it is blocking the script."
  2176. )
  2177. echo:
  2178. )
  2179. if not defined exhook if not defined ierror (
  2180. if defined hasherror (
  2181. set error=1
  2182. set ierror=1
  2183. call :dk_color %Red% "Modifying Hash of Custom %_hook% [Failed]"
  2184. ) else (
  2185. echo Modifying Hash of Custom %_hook% [Successful]
  2186. )
  2187. )
  2188. exit /b
  2189. ::========================================================================================================================================
  2190. :oh_process
  2191. for %%# in (%_oIds%) do (
  2192. set key=
  2193. set _actid=
  2194. set _lic=
  2195. set _preview=
  2196. set _License=%%#
  2197. echo %%# | find /i "2024" %nul% && (
  2198. if exist "!_oLPath!\ProPlus2024PreviewVL_*.xrm-ms" if not exist "!_oLPath!\ProPlus2024VL_*.xrm-ms" set _preview=-Preview
  2199. )
  2200. set _prod=%%#!_preview!
  2201. call :ohookdata getinfo !_prod!
  2202. if not "!key!"=="" (
  2203. echo "!allapps!" | find /i "!_actid!" %nul1% || call :oh_installlic
  2204. call :dk_inskey "[!key!] [!_prod!] [!_lic!]"
  2205. ) else (
  2206. set error=1
  2207. call :dk_color %Red% "Checking Product In Script [Office %oVer%.0 !_prod! not found in script]"
  2208. call :dk_color %Blue% "Make sure you are using the latest version of MAS."
  2209. set fixes=%fixes% %mas%
  2210. call :dk_color %_Yellow% "%mas%"
  2211. )
  2212. )
  2213. :: Add SharedComputerLicensing registry key if Retail Office C2R is installed on Windows Server
  2214. :: https://learn.microsoft.com/en-us/office/troubleshoot/office-suite-issues/click-to-run-office-on-terminal-server
  2215. if defined winserver if defined _config (
  2216. echo %_oIds% | find /i "Retail" %nul1% && (
  2217. set scaIsNeeded=1
  2218. reg add %_config% /v SharedComputerLicensing /t REG_SZ /d "1" /f %nul1%
  2219. echo Adding SharedComputerLicensing Reg [Successful] [Needed on Server With Retail Office]"
  2220. )
  2221. )
  2222. exit /b
  2223. ::========================================================================================================================================
  2224. :oh_processmsi
  2225. :: Process Office MSI Version
  2226. call :oh_reset
  2227. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  2228. set oVer=%1
  2229. for /f "skip=2 tokens=2*" %%a in ('"reg query %2\Common\InstallRoot /v Path" %nul6%') do (set "_oRoot=%%b")
  2230. for /f "skip=2 tokens=2*" %%a in ('"reg query %2\Common\ProductVersion /v LastProduct" %nul6%') do (set "_version=%%b")
  2231. if "%_oRoot:~-1%"=="\" set "_oRoot=%_oRoot:~0,-1%"
  2232. echo "%2" | find /i "Wow6432Node" %nul1% && set _oArch=x86
  2233. if not "%osarch%"=="x86" if not defined _oArch set _oArch=x64
  2234. if "%osarch%"=="x86" set _oArch=x86
  2235. if /i "%_oArch%"=="x64" (set "_hookPath=%_oRoot%" & set "_hook=sppc64.dll")
  2236. if /i "%_oArch%"=="x86" (set "_hookPath=%_oRoot%" & set "_hook=sppc32.dll")
  2237. if not "%osarch%"=="x86" (
  2238. if /i "%_oArch%"=="x64" set "_sppcPath=%SystemRoot%\System32\sppc.dll"
  2239. if /i "%_oArch%"=="x86" set "_sppcPath=%SystemRoot%\SysWOW64\sppc.dll"
  2240. ) else (
  2241. set "_sppcPath=%SystemRoot%\System32\sppc.dll"
  2242. )
  2243. set "_common=%CommonProgramFiles%"
  2244. if defined PROCESSOR_ARCHITEW6432 set "_common=%CommonProgramW6432%"
  2245. set "_common2=%CommonProgramFiles(x86)%"
  2246. for /r "%_common%\Microsoft Shared\OFFICE%oVer%\" %%f in (BRANDING.XML) do if exist "%%f" set "_oBranding=%%f"
  2247. if not defined _oBranding for /r "%_common2%\Microsoft Shared\OFFICE%oVer%\" %%f in (BRANDING.XML) do if exist "%%f" set "_oBranding=%%f"
  2248. call :ohookdata getmsiprod %2
  2249. echo:
  2250. echo Activating Office... [MSI ^| %_version% ^| %_oArch%]
  2251. if not defined _oBranding (
  2252. set error=1
  2253. call :dk_color %Red% "Checking BRANDING.XML [Not Found, aborting activation...]"
  2254. exit /b
  2255. )
  2256. if not defined _oIds (
  2257. set error=1
  2258. call :dk_color %Red% "Checking Installed Products [Product IDs not found, aborting activation...]"
  2259. exit /b
  2260. )
  2261. call :oh_process
  2262. call :oh_hookinstall
  2263. exit /b
  2264. ::========================================================================================================================================
  2265. :oh_clearblock
  2266. :: Find remnants of Office vNext/shared/device license block and remove it because it stops other licenses from appearing
  2267. :: https://learn.microsoft.com/office/troubleshoot/activation/reset-office-365-proplus-activation-state
  2268. set _sidlist=
  2269. for /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))
  2270. if not defined _sidlist (
  2271. for /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)
  2272. )
  2273. ::==========================
  2274. :: Load the unloaded useraccounts registry
  2275. set loadedsids=
  2276. set alrloadedsids=
  2277. for %%# in (%_sidlist%) do (
  2278. reg query HKU\%%#\Software %nul% && (
  2279. call set "alrloadedsids=%%alrloadedsids%% %%#"
  2280. ) || (
  2281. for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
  2282. reg load HKU\%%# "%%b\NTUSER.DAT" %nul%
  2283. reg query HKU\%%#\Software %nul% && (
  2284. call set "loadedsids=%%loadedsids%% %%#"
  2285. ) || (
  2286. reg unload HKU\%%# %nul%
  2287. )
  2288. )
  2289. )
  2290. )
  2291. ::==========================
  2292. set "_sidlist=%loadedsids% %alrloadedsids%"
  2293. set /a counter=0
  2294. for %%# in (%_sidlist%) do set /a counter+=1
  2295. if %counter% EQU 0 (
  2296. set error=1
  2297. call :dk_color %Red% "Checking User Accounts SID [Not Found]"
  2298. exit /b
  2299. )
  2300. if %counter% GTR 10 (
  2301. call :dk_color %Gray% "Checking Total User Accounts [%counter%]"
  2302. )
  2303. ::==========================
  2304. :: Clear the vNext/shared/device license blocks which may prevent ohook activation
  2305. rmdir /s /q "%ProgramData%\Microsoft\Office\Licenses\" %nul%
  2306. for %%x in (15 16) do (
  2307. for %%# in (%_sidlist%) do (
  2308. reg delete HKU\%%#\Software\Microsoft\Office\%%x.0\Common\Licensing /f %nul%
  2309. for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
  2310. rmdir /s /q "%%b\AppData\Local\Microsoft\Office\Licenses\" %nul%
  2311. rmdir /s /q "%%b\AppData\Local\Microsoft\Office\%%x.0\Licensing\" %nul%
  2312. )
  2313. )
  2314. reg delete "HKLM\SOFTWARE\Microsoft\Office\%%x.0\Common\Licensing" /f %nul%
  2315. reg delete "HKLM\SOFTWARE\Microsoft\Office\%%x.0\Common\Licensing" /f /reg:32 %nul%
  2316. reg delete "HKLM\SOFTWARE\Policies\Microsoft\Office\%%x.0\Common\Licensing" /f %nul%
  2317. reg delete "HKLM\SOFTWARE\Policies\Microsoft\Office\%%x.0\Common\Licensing" /f /reg:32 %nul%
  2318. )
  2319. :: Clear vNext in UWP Office
  2320. if defined o16uwpapplist (
  2321. for %%# in (%_sidlist%) do (
  2322. for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
  2323. rmdir /s /q "%%b\AppData\Local\Packages\Microsoft.Office.Desktop_8wekyb3d8bbwe\LocalCache\Local\Microsoft\Office\Licenses\" %nul%
  2324. if exist "%%b\AppData\Local\Packages\Microsoft.Office.Desktop_8wekyb3d8bbwe\SystemAppData\Helium\User.dat" (
  2325. set defname=DEFTEMP-%%#
  2326. reg load HKU\!defname! "%%b\AppData\Local\Packages\Microsoft.Office.Desktop_8wekyb3d8bbwe\SystemAppData\Helium\User.dat" %nul%
  2327. reg delete HKU\!defname!\Software\Microsoft\Office\16.0\Common\Licensing /f %nul%
  2328. reg unload HKU\!defname! %nul%
  2329. )
  2330. )
  2331. )
  2332. )
  2333. :: Clear SharedComputerLicensing for office
  2334. :: https://learn.microsoft.com/en-us/deployoffice/overview-shared-computer-activation
  2335. if not defined scaIsNeeded (
  2336. reg delete HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v SharedComputerLicensing /f %nul%
  2337. reg delete HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v SharedComputerLicensing /f /reg:32 %nul%
  2338. reg delete HKLM\SOFTWARE\Microsoft\Office\15.0\ClickToRun\Configuration /v SharedComputerLicensing /f %nul%
  2339. reg delete HKLM\SOFTWARE\Microsoft\Office\15.0\ClickToRun\Configuration /v SharedComputerLicensing /f /reg:32 %nul%
  2340. )
  2341. :: Clear device-based-licensing
  2342. :: https://learn.microsoft.com/deployoffice/device-based-licensing
  2343. for /f %%# in ('reg query "%o16c2r_reg%\Configuration" /f *.DeviceBasedLicensing %nul6% ^| findstr REG_') do reg delete "%o16c2r_reg%\Configuration" /v %%# /f %nul%
  2344. :: Remove OEM registry key
  2345. :: https://support.microsoft.com/office/office-repeatedly-prompts-you-to-activate-on-a-new-pc-a9a6b05f-f6ce-4d1f-8d49-eb5007b64ba1
  2346. for %%# in (15 16) do (
  2347. reg delete "HKLM\SOFTWARE\Microsoft\Office\%%#.0\Common\OEM" /f %nul%
  2348. reg delete "HKLM\SOFTWARE\Microsoft\Office\%%#.0\Common\OEM" /f /reg:32 %nul%
  2349. )
  2350. reg delete "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Policies\0ff1ce15-a989-479d-af46-f275c6370663" /f %nul%
  2351. reg delete "HKU\S-1-5-20\Software\Microsoft\OfficeSoftwareProtectionPlatform\Policies\0ff1ce15-a989-479d-af46-f275c6370663" /f %nul%
  2352. reg delete "HKU\S-1-5-20\Software\Microsoft\OfficeSoftwareProtectionPlatform\Policies\59a52881-a989-479d-af46-f275c6370663" /f %nul%
  2353. echo Clearing Office License Blocks [Successfully cleared from all %counter% user accounts]
  2354. ::==========================
  2355. :: Some retail products attempt to validate the license and may show a banner "There was a problem checking this device's license status."
  2356. :: Resiliency registry entry can skip this check
  2357. set defname=DEFTEMP-%random%
  2358. for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v Default" %nul6%') do call set "defdat=%%b"
  2359. if defined o16c2r if defined ohookact (
  2360. if exist "%defdat%\NTUSER.DAT" (
  2361. reg load HKU\%defname% "%defdat%\NTUSER.DAT" %nul%
  2362. reg query HKU\%defname%\Software %nul% && (
  2363. reg add HKU\%defname%\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /v "TimeOfLastHeartbeatFailure" /t REG_SZ /d "2040-01-01T00:00:00Z" /f %nul%
  2364. )
  2365. reg unload HKU\%defname% %nul%
  2366. )
  2367. for %%# in (%_sidlist%) do (
  2368. reg delete HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /f %nul%
  2369. reg add HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /v "TimeOfLastHeartbeatFailure" /t REG_SZ /d "2040-01-01T00:00:00Z" /f %nul%
  2370. )
  2371. echo Adding Registry to Skip License Check [Successfully added to all %counter% ^& future new user accounts]
  2372. )
  2373. ::==========================
  2374. :: Unload the loaded useraccounts registry
  2375. for %%# in (%loadedsids%) do (
  2376. reg unload HKU\%%# %nul%
  2377. )
  2378. exit /b
  2379. ::========================================================================================================================================
  2380. :: Uninstall other / grace Keys
  2381. :oh_uninstkey
  2382. set upk_result=0
  2383. call :dk_actid 0ff1ce15-a989-479d-af46-f275c6370663
  2384. if "%_actprojvis%"=="1" (
  2385. for /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!"
  2386. for /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!"
  2387. )
  2388. for %%# in (%apps%) do (
  2389. echo "%_allactid%" | find /i "%%#" %nul1% || (
  2390. if %_wmic% EQU 1 wmic path %spp% where ID='%%#' call UninstallProductKey %nul%
  2391. if %_wmic% EQU 0 %psc% "$null=([WMI]'%spp%=''%%#''').UninstallProductKey()" %nul%
  2392. if !errorlevel!==0 (
  2393. set upk_result=1
  2394. ) else (
  2395. set error=1
  2396. set upk_result=2
  2397. )
  2398. )
  2399. )
  2400. if defined ohookact if not %upk_result%==0 echo:
  2401. if %upk_result%==1 echo Uninstalling Other/Grace Keys [Successful]
  2402. if %upk_result%==2 call :dk_color %Red% "Uninstalling Other/Grace Keys [Failed]"
  2403. exit /b
  2404. ::========================================================================================================================================
  2405. :: Refresh Windows Insider Preview Licenses
  2406. :: It required in Insider versions otherwise office may not activate
  2407. :oh_licrefresh
  2408. if exist "%SysPath%\spp\store_test\2.0\tokens.dat" (
  2409. %psc% "Stop-Service sppsvc -force; $sls = Get-WmiObject SoftwareLicensingService; $f=[io.file]::ReadAllText('!_batp!') -split ':xrm\:.*';iex ($f[1]); ReinstallLicenses" %nul%
  2410. if !errorlevel! NEQ 0 %psc% "$sls = Get-WmiObject SoftwareLicensingService; $f=[io.file]::ReadAllText('!_batp!') -split ':xrm\:.*';iex ($f[1]); ReinstallLicenses" %nul%
  2411. )
  2412. exit /b
  2413. ::========================================================================================================================================
  2414. :: Check running office apps and notify user
  2415. :oh_checkapps
  2416. set checkapps=
  2417. set checknames=
  2418. for /f "tokens=1" %%i in ('tasklist ^| findstr /I ".exe" %nul6%') do (set "checkapps=!checkapps! -%%i-")
  2419. for %%# in (
  2420. Access_msaccess.exe
  2421. Excel_excel.exe
  2422. Groove_groove.exe
  2423. Lync_lync.exe
  2424. OneNote_onenote.exe
  2425. Outlook_outlook.exe
  2426. PowerPoint_powerpnt.exe
  2427. Project_winproj.exe
  2428. Publisher_mspub.exe
  2429. Visio_visio.exe
  2430. Word_winword.exe
  2431. Lime_lime.exe
  2432. ) do (
  2433. for /f "tokens=1-2 delims=_" %%A in ("%%#") do (
  2434. echo !checkapps! | find /i "-%%B-" %nul1% && (if defined checknames (set "checknames=!checknames! %%A") else (set "checknames=%%A"))
  2435. )
  2436. )
  2437. exit /b
  2438. ::========================================================================================================================================
  2439. :: 1st column = Office version number
  2440. :: 2nd column = Activation ID
  2441. :: 3rd column = Generic key. Preference is given in this order, Retail:TB:Sub > Retail > OEM:NONSLP > Volume:MAK > Volume:GVLK
  2442. :: 4th column = Last part of license description
  2443. :: 5th column = Edition
  2444. :: Separator = "_"
  2445. :ohookdata
  2446. set f=
  2447. for %%# in (
  2448. :: Office 2013
  2449. 15_ab4d047b-97cf-4126-a69f-34df08e2f254_B7RFY-7NXPK-Q4342-Y9X2H-3J%f%X4X_Retail________AccessRetail
  2450. 15_259de5be-492b-44b3-9d78-9645f848f7b0_X3XNB-HJB7K-66THH-8DWQ3-XH%f%GJP_Bypass________AccessRuntimeRetail
  2451. 15_4374022d-56b8-48c1-9bb7-d8f2fc726343_9MF9G-CN32B-HV7XT-9XJ8T-9K%f%VF4_MAK___________AccessVolume
  2452. 15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_NT889-MBH4X-8MD4H-X8R2D-WQ%f%HF8_Retail________ExcelRetail
  2453. 15_ac1ae7fd-b949-4e04-a330-849bc40638cf_Y3N36-YCHDK-XYWBG-KYQVV-BD%f%TJ2_MAK___________ExcelVolume
  2454. 15_cfaf5356-49e3-48a8-ab3c-e729ab791250_BMK4W-6N88B-BP9QR-PHFCK-MG%f%7GF_Retail________GrooveRetail
  2455. 15_4825ac28-ce41-45a7-9e6e-1fed74057601_RN84D-7HCWY-FTCBK-JMXWM-HT%f%7GJ_MAK___________GrooveVolume
  2456. 15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_2WQNF-GBK4B-XVG6F-BBMX7-M4%f%F2Y_OEM-Perp______HomeBusinessPipcRetail
  2457. 15_a2b90e7a-a797-4713-af90-f0becf52a1dd_YWD4R-CNKVT-VG8VJ-9333B-RC%f%W9F_Subscription__HomeBusinessRetail
  2458. 15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_B92QY-NKYFQ-6KTKH-VWW2Q-3P%f%B3B_OEM-ARM_______HomeStudentARMRetail
  2459. 15_ebef9f05-5273-404a-9253-c5e252f50555_QPG96-CNT7M-KH36K-KY4HQ-M7%f%TBR_OEM-ARM_______HomeStudentPlusARMRetail
  2460. 15_f2de350d-3028-410a-bfae-283e00b44d0e_6WW3N-BDGM9-PCCHD-9QPP9-P3%f%4QG_Subscription__HomeStudentRetail
  2461. 15_44984381-406e-4a35-b1c3-e54f499556e2_RV7NQ-HY3WW-7CKWH-QTVMW-29%f%VHC_Retail________InfoPathRetail
  2462. 15_9e016989-4007-42a6-8051-64eb97110cf2_C4TGN-QQW6Y-FYKXC-6WJW7-X7%f%3VG_MAK___________InfoPathVolume
  2463. 15_9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY_PrepidBypass__LyncAcademicRetail
  2464. 15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_N42BF-CBY9F-W2C7R-X397X-DY%f%FQW_PrepidBypass__LyncEntryRetail
  2465. 15_fada6658-bfc6-4c4e-825a-59a89822cda8_89P23-2NK2R-JXM2M-3Q8R8-BW%f%M3Y_Retail________LyncRetail
  2466. 15_e1264e10-afaf-4439-a98b-256df8bb156f_3WKCD-RN489-4M7XJ-GJ2GQ-YB%f%FQ6_MAK___________LyncVolume
  2467. 15_69ec9152-153b-471a-bf35-77ec88683eae_VNWHF-FKFBW-Q2RGD-HYHWF-R3%f%HH2_Subscription__MondoRetail
  2468. 15_f33485a0-310b-4b72-9a0e-b1d605510dbd_2YNYQ-FQMVG-CB8KW-6XKYD-M7%f%RRJ_MAK___________MondoVolume
  2469. 15_3391e125-f6e4-4b1e-899c-a25e6092d40d_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%FF4_Bypass________OneNoteFreeRetail
  2470. 15_8b524bcc-67ea-4876-a509-45e46f6347e8_3KXXQ-PVN2C-8P7YY-HCV88-GV%f%GQ6_Retail________OneNoteRetail
  2471. 15_b067e965-7521-455b-b9f7-c740204578a2_JDMWF-NJC7B-HRCHY-WFT8G-BP%f%XD9_MAK___________OneNoteVolume
  2472. 15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_9N4RQ-CF8R2-HBVCB-J3C9V-94%f%P4D_Retail________OutlookRetail
  2473. 15_8d577c50-ae5e-47fd-a240-24986f73d503_HNG29-GGWRG-RFC8C-JTFP4-2J%f%9FH_MAK___________OutlookVolume
  2474. 15_5aab8561-1686-43f7-9ff5-2c861da58d17_9CYB3-NFMRW-YFDG6-XC7TF-BY%f%36J_OEM-Perp______PersonalPipcRetail
  2475. 15_17e9df2d-ed91-4382-904b-4fed6a12caf0_2NCQJ-MFRMH-TXV83-J7V4C-RV%f%RWC_Retail________PersonalRetail
  2476. 15_31743b82-bfbc-44b6-aa12-85d42e644d5b_HVMN2-KPHQH-DVQMK-7B3CM-FG%f%BFC_Retail________PowerPointRetail
  2477. 15_e40dcb44-1d5c-4085-8e8f-943f33c4f004_47DKN-HPJP7-RF9M3-VCYT2-TM%f%Q4G_MAK___________PowerPointVolume
  2478. 15_064383fa-1538-491c-859b-0ecab169a0ab_N3QMM-GKDT3-JQGX6-7X3MQ-4G%f%BG3_Retail________ProPlusRetail
  2479. 15_2b88c4f2-ea8f-43cd-805e-4d41346e18a7_QKHNX-M9GGH-T3QMW-YPK4Q-QR%f%P9V_MAK___________ProPlusVolume
  2480. 15_4e26cac1-e15a-4467-9069-cb47b67fe191_CF9DD-6CNW2-BJWJQ-CVCFX-Y7%f%TXD_OEM-Perp______ProfessionalPipcRetail
  2481. 15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_MBQBN-CQPT6-PXRMC-TYJFR-3C%f%8MY_Retail________ProfessionalRetail
  2482. 15_2f72340c-b555-418d-8b46-355944fe66b8_WPY8N-PDPY4-FC7TF-KMP7P-KW%f%YFY_Subscription__ProjectProRetail
  2483. 15_ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32_WFCT2-NBFQ7-JD7VV-MFJX6-6F%f%2CM_MAK___________ProjectProVolume
  2484. 15_58d95b09-6af6-453d-a976-8ef0ae0316b1_NTHQT-VKK6W-BRB87-HV346-Y9%f%6W8_Subscription__ProjectStdRetail
  2485. 15_2b9e4a37-6230-4b42-bee2-e25ce86c8c7a_3CNQX-T34TY-99RH4-C4YD2-KW%f%YGV_MAK___________ProjectStdVolume
  2486. 15_c3a0814a-70a4-471f-af37-2313a6331111_TWNCJ-YR84W-X7PPF-6DPRP-D6%f%7VC_Retail________PublisherRetail
  2487. 15_38ea49f6-ad1d-43f1-9888-99a35d7c9409_DJPHV-NCJV6-GWPT6-K26JX-C7%f%GX6_MAK___________PublisherVolume
  2488. 15_ba3e3833-6a7e-445a-89d0-7802a9a68588_3NY6J-WHT3F-47BDV-JHF36-23%f%43W_PrepidBypass__SPDRetail
  2489. 15_32255c0a-16b4-4ce2-b388-8a4267e219eb_V6VWN-KC2HR-YYDD6-9V7HQ-7T%f%7VP_Retail________StandardRetail
  2490. 15_a24cca51-3d54-4c41-8a76-4031f5338cb2_9TN6B-PCYH4-MCVDQ-KT83C-TM%f%Q7T_MAK___________StandardVolume
  2491. 15_a56a3b37-3a35-4bbb-a036-eee5f1898eee_NVK2G-2MY4G-7JX2P-7D6F2-VF%f%QBR_Subscription__VisioProRetail
  2492. 15_3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d_YN7CF-XRH6R-CGKRY-GKPV3-BG%f%7WF_MAK___________VisioProVolume
  2493. 15_980f9e3e-f5a8-41c8-8596-61404addf677_NCRB7-VP48F-43FYY-62P3R-36%f%7WK_Subscription__VisioStdRetail
  2494. 15_44a1f6ff-0876-4edb-9169-dbb43101ee89_RX63Y-4NFK2-XTYC8-C6B3W-YP%f%XPJ_MAK___________VisioStdVolume
  2495. 15_191509f2-6977-456f-ab30-cf0492b1e93a_NB77V-RPFQ6-PMMKQ-T87DV-M4%f%D84_Retail________WordRetail
  2496. 15_9cedef15-be37-4ff0-a08a-13a045540641_RPHPB-Y7NC4-3VYFM-DW7VD-G8%f%YJ8_MAK___________WordVolume
  2497. :: Office 365 - 15.0 version
  2498. 15_742178ed-6b28-42dd-b3d7-b7c0ea78741b_Y9NF9-M2QWD-FF6RJ-QJW36-RR%f%F2T_SubTest_______O365BusinessRetail
  2499. 15_a96f8dae-da54-4fad-bdc6-108da592707a_3NMDC-G7C3W-68RGP-CB4MH-4C%f%XCH_SubTest1______O365HomePremRetail
  2500. 15_e3dacc06-3bc2-4e13-8e59-8e05f3232325_H8DN8-Y2YP3-CR9JT-DHDR9-C7%f%GP3_Subscription2_O365ProPlusRetail
  2501. 15_0bc1dae4-6158-4a1c-a893-807665b934b2_2QCNB-RMDKJ-GC8PB-7QGQV-7Q%f%TQJ_Subscription2_O365SmallBusPremRetail
  2502. :: Office 365 - 16.0 version
  2503. 16_742178ed-6b28-42dd-b3d7-b7c0ea78741b_Y9NF9-M2QWD-FF6RJ-QJW36-RR%f%F2T_SubTest_______O365BusinessRetail
  2504. 16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_W62NQ-267QR-RTF74-PF2MH-JQ%f%MTH_Subscription__O365EduCloudRetail
  2505. 16_a96f8dae-da54-4fad-bdc6-108da592707a_3NMDC-G7C3W-68RGP-CB4MH-4C%f%XCH_SubTest1______O365HomePremRetail
  2506. 16_e3dacc06-3bc2-4e13-8e59-8e05f3232325_H8DN8-Y2YP3-CR9JT-DHDR9-C7%f%GP3_Subscription2_O365ProPlusRetail
  2507. 16_0bc1dae4-6158-4a1c-a893-807665b934b2_2QCNB-RMDKJ-GC8PB-7QGQV-7Q%f%TQJ_Subscription2_O365SmallBusPremRetail
  2508. :: Office 2016
  2509. 16_bfa358b0-98f1-4125-842e-585fa13032e6_WHK4N-YQGHB-XWXCC-G3HYC-6J%f%F94_Retail________AccessRetail
  2510. 16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_RNB7V-P48F4-3FYY6-2P3R3-63%f%BQV_PrepidBypass__AccessRuntimeRetail
  2511. 16_3b2fa33f-cd5a-43a5-bd95-f49f3f546b0b_JJ2Y4-N8KM3-Y8KY3-Y22FR-R3%f%KVK_MAK___________AccessVolume
  2512. 16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_RKJBN-VWTM2-BDKXX-RKQFD-JT%f%YQ2_Retail________ExcelRetail
  2513. 16_685062a7-6024-42e7-8c5f-6bb9e63e697f_FVGNR-X82B2-6PRJM-YT4W7-8H%f%V36_MAK___________ExcelVolume
  2514. 16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_2WQNF-GBK4B-XVG6F-BBMX7-M4%f%F2Y_OEM-Perp______HomeBusinessPipcRetail
  2515. 16_86834d00-7896-4a38-8fae-32f20b86fa2b_HM6FM-NVF78-KV9PM-F36B8-D9%f%MXD_Retail________HomeBusinessRetail
  2516. 16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_PBQPJ-NC22K-69MXD-KWMRF-WF%f%G77_OEM-ARM_______HomeStudentARMRetail
  2517. 16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_6F2NY-7RTX4-MD9KM-TJ43H-94%f%TBT_OEM-ARM_______HomeStudentPlusARMRetail
  2518. 16_c28acdb8-d8b3-4199-baa4-024d09e97c99_PNPRV-F2627-Q8JVC-3DGR9-WT%f%YRK_Retail________HomeStudentRetail
  2519. 16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_YWD4R-CNKVT-VG8VJ-9333B-RC%f%3B8_Retail________HomeStudentVNextRetail
  2520. 16_69ec9152-153b-471a-bf35-77ec88683eae_VNWHF-FKFBW-Q2RGD-HYHWF-R3%f%HH2_Subscription__MondoRetail
  2521. 16_2cd0ea7e-749f-4288-a05e-567c573b2a6c_FMTQQ-84NR8-2744R-MXF4P-PG%f%YR3_MAK___________MondoVolume
  2522. 16_436366de-5579-4f24-96db-3893e4400030_XYNTG-R96FY-369HX-YFPHY-F9%f%CPM_Bypass________OneNoteFreeRetail
  2523. 16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_FXF6F-CNC26-W643C-K6KB7-6X%f%XW3_Retail________OneNoteRetail
  2524. 16_23b672da-a456-4860-a8f3-e062a501d7e8_9TYVN-D76HK-BVMWT-Y7G88-9T%f%PPV_MAK___________OneNoteVolume
  2525. 16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_7N4KG-P2QDH-86V9C-DJFVF-36%f%9W9_Retail________OutlookRetail
  2526. 16_50059979-ac6f-4458-9e79-710bcb41721a_7QPNR-3HFDG-YP6T9-JQCKQ-KK%f%XXC_MAK___________OutlookVolume
  2527. 16_5aab8561-1686-43f7-9ff5-2c861da58d17_9CYB3-NFMRW-YFDG6-XC7TF-BY%f%36J_OEM-Perp______PersonalPipcRetail
  2528. 16_a9f645a1-0d6a-4978-926a-abcb363b72a6_FT7VF-XBN92-HPDJV-RHMBY-6V%f%KBF_Retail________PersonalRetail
  2529. 16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_N7GCB-WQT7K-QRHWG-TTPYD-7T%f%9XF_Retail________PowerPointRetail
  2530. 16_9b4060c9-a7f5-4a66-b732-faf248b7240f_X3RT9-NDG64-VMK2M-KQ6XY-DP%f%FGV_MAK___________PowerPointVolume
  2531. 16_de52bd50-9564-4adc-8fcb-a345c17f84f9_GM43N-F742Q-6JDDK-M622J-J8%f%GDV_Retail________ProPlusRetail
  2532. 16_c47456e3-265d-47b6-8ca0-c30abbd0ca36_FNVK8-8DVCJ-F7X3J-KGVQB-RC%f%2QY_MAK___________ProPlusVolume
  2533. 16_4e26cac1-e15a-4467-9069-cb47b67fe191_CF9DD-6CNW2-BJWJQ-CVCFX-Y7%f%TXD_OEM-Perp______ProfessionalPipcRetail
  2534. 16_d64edc00-7453-4301-8428-197343fafb16_NXFTK-YD9Y7-X9MMJ-9BWM6-J2%f%QVH_Retail________ProfessionalRetail
  2535. 16_2f72340c-b555-418d-8b46-355944fe66b8_WPY8N-PDPY4-FC7TF-KMP7P-KW%f%YFY_Subscription__ProjectProRetail
  2536. 16_82f502b5-b0b0-4349-bd2c-c560df85b248_PKC3N-8F99H-28MVY-J4RYY-CW%f%GDH_MAK___________ProjectProVolume
  2537. 16_16728639-a9ab-4994-b6d8-f81051e69833_JBNPH-YF2F7-Q9Y29-86CTG-C9%f%YGV_MAKC2R________ProjectProXVolume
  2538. 16_58d95b09-6af6-453d-a976-8ef0ae0316b1_NTHQT-VKK6W-BRB87-HV346-Y9%f%6W8_Subscription__ProjectStdRetail
  2539. 16_82e6b314-2a62-4e51-9220-61358dd230e6_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%G93_MAK___________ProjectStdVolume
  2540. 16_431058f0-c059-44c5-b9e7-ed2dd46b6789_N3W2Q-69MBT-27RD9-BH8V3-JT%f%2C8_MAKC2R________ProjectStdXVolume
  2541. 16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_WKWND-X6G9G-CDMTV-CPGYJ-6M%f%VBF_Retail________PublisherRetail
  2542. 16_fcc1757b-5d5f-486a-87cf-c4d6dedb6032_9QVN2-PXXRX-8V4W8-Q7926-TJ%f%GD8_MAK___________PublisherVolume
  2543. 16_9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY_PrepidBypass__SkypeServiceBypassRetail
  2544. 16_971cd368-f2e1-49c1-aedd-330909ce18b6_4N4D8-3J7Y3-YYW7C-73HD2-V8%f%RHY_PrepidBypass__SkypeforBusinessEntryRetail
  2545. 16_418d2b9f-b491-4d7f-84f1-49e27cc66597_PBJ79-77NY4-VRGFG-Y8WYC-CK%f%CRC_Retail________SkypeforBusinessRetail
  2546. 16_03ca3b9a-0869-4749-8988-3cbc9d9f51bb_DMTCJ-KNRKR-JV8TQ-V2CR2-VF%f%TFH_MAK___________SkypeforBusinessVolume
  2547. 16_4a31c291-3a12-4c64-b8ab-cd79212be45e_2FPWN-4H6CM-KD8QQ-8HCHC-P9%f%XYW_Retail________StandardRetail
  2548. 16_0ed94aac-2234-4309-ba29-74bdbb887083_WHGMQ-JNMGT-MDQVF-WDR69-KQ%f%BWC_MAK___________StandardVolume
  2549. 16_a56a3b37-3a35-4bbb-a036-eee5f1898eee_NVK2G-2MY4G-7JX2P-7D6F2-VF%f%QBR_Subscription__VisioProRetail
  2550. 16_295b2c03-4b1c-4221-b292-1411f468bd02_NRKT9-C8GP2-XDYXQ-YW72K-MG%f%92B_MAK___________VisioProVolume
  2551. 16_0594dc12-8444-4912-936a-747ca742dbdb_G98Q2-B6N77-CFH9J-K824G-XQ%f%CC4_MAKC2R________VisioProXVolume
  2552. 16_980f9e3e-f5a8-41c8-8596-61404addf677_NCRB7-VP48F-43FYY-62P3R-36%f%7WK_Subscription__VisioStdRetail
  2553. 16_44151c2d-c398-471f-946f-7660542e3369_XNCJB-YY883-JRW64-DPXMX-JX%f%CR6_MAK___________VisioStdVolume
  2554. 16_1d1c6879-39a3-47a5-9a6d-aceefa6a289d_B2HTN-JPH8C-J6Y6V-HCHKB-43%f%MGT_MAKC2R________VisioStdXVolume
  2555. 16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_P8K82-NQ7GG-JKY8T-6VHVY-88%f%GGD_Retail________WordRetail
  2556. 16_c3000759-551f-4f4a-bcac-a4b42cbf1de2_YHMWC-YN6V9-WJPXD-3WQKP-TM%f%VCV_MAK___________WordVolume
  2557. :: Office 2019
  2558. 16_518687bd-dc55-45b9-8fa6-f918e1082e83_WRYJ6-G3NP7-7VH94-8X7KP-JB%f%7HC_Retail________Access2019Retail
  2559. 16_385b91d6-9c2c-4a2e-86b5-f44d44a48c5f_6FWHX-NKYXK-BW34Q-7XC9F-Q9%f%PX7_MAK-AE________Access2019Volume
  2560. 16_22e6b96c-1011-4cd5-8b35-3c8fb6366b86_FGQNJ-JWJCG-7Q8MG-RMRGJ-9T%f%QVF_PrepidBypass__AccessRuntime2019Retail
  2561. 16_c201c2b7-02a1-41a8-b496-37c72910cd4a_KBPNW-64CMM-8KWCB-23F44-8B%f%7HM_Retail________Excel2019Retail
  2562. 16_05cb4e1d-cc81-45d5-a769-f34b09b9b391_8NT4X-GQMCK-62X4P-TW6QP-YK%f%PYF_MAK-AE________Excel2019Volume
  2563. 16_7fe09eef-5eed-4733-9a60-d7019df11cac_QBN2Y-9B284-9KW78-K48PB-R6%f%2YT_Retail________HomeBusiness2019Retail
  2564. 16_6303d14a-afad-431f-8434-81052a65f575_DJTNY-4HDWM-TDWB2-8PWC2-W2%f%RRT_OEM-ARM_______HomeStudentARM2019Retail
  2565. 16_215c841d-ffc1-4f03-bd11-5b27b6ab64cc_NM8WT-CFHB2-QBGXK-J8W6J-GV%f%K8F_OEM-ARM_______HomeStudentPlusARM2019Retail
  2566. 16_4539aa2c-5c31-4d47-9139-543a868e5741_XNWPM-32XQC-Y7QJC-QGGBV-YY%f%7JK_Retail________HomeStudent2019Retail
  2567. 16_20e359d5-927f-47c0-8a27-38adbdd27124_WR43D-NMWQQ-HCQR2-VKXDR-37%f%B7H_Retail________Outlook2019Retail
  2568. 16_92a99ed8-2923-4cb7-a4c5-31da6b0b8cf3_RN3QB-GT6D7-YB3VH-F3RPB-3G%f%QYB_MAK-AE________Outlook2019Volume
  2569. 16_2747b731-0f1f-413e-a92d-386ec1277dd8_NMBY8-V3CV7-BX6K6-2922Y-43%f%M7T_Retail________Personal2019Retail
  2570. 16_7e63cc20-ba37-42a1-822d-d5f29f33a108_HN27K-JHJ8R-7T7KK-WJYC3-FM%f%7MM_Retail________PowerPoint2019Retail
  2571. 16_13c2d7bf-f10d-42eb-9e93-abf846785434_29GNM-VM33V-WR23K-HG2DT-KT%f%QYR_MAK-AE________PowerPoint2019Volume
  2572. 16_a3072b8f-adcc-4e75-8d62-fdeb9bdfae57_BN4XJ-R9DYY-96W48-YK8DM-MY%f%7PY_Retail________ProPlus2019Retail
  2573. 16_6755c7a7-4dfe-46f5-bce8-427be8e9dc62_T8YBN-4YV3X-KK24Q-QXBD7-T3%f%C63_MAK-AE________ProPlus2019Volume
  2574. 16_1717c1e0-47d3-4899-a6d3-1022db7415e0_9NXDK-MRY98-2VJV8-GF73J-TQ%f%9FK_Retail________Professional2019Retail
  2575. 16_0d270ef7-5aaf-4370-a372-bc806b96adb7_JDTNC-PP77T-T9H2W-G4J2J-VH%f%8JK_Retail________ProjectPro2019Retail
  2576. 16_d4ebadd6-401b-40d5-adf4-a5d4accd72d1_TBXBD-FNWKJ-WRHBD-KBPHH-XD%f%9F2_MAK-AE________ProjectPro2019Volume
  2577. 16_bb7ffe5f-daf9-4b79-b107-453e1c8427b5_R3JNT-8PBDP-MTWCK-VD2V8-HM%f%KF9_Retail________ProjectStd2019Retail
  2578. 16_fdaa3c03-dc27-4a8d-8cbf-c3d843a28ddc_RBRFX-MQNDJ-4XFHF-7QVDR-JH%f%XGC_MAK-AE________ProjectStd2019Volume
  2579. 16_f053a7c7-f342-4ab8-9526-a1d6e5105823_4QC36-NW3YH-D2Y9D-RJPC7-VV%f%B9D_Retail________Publisher2019Retail
  2580. 16_40055495-be00-444e-99cc-07446729b53e_K8F2D-NBM32-BF26V-YCKFJ-29%f%Y9W_MAK-AE________Publisher2019Volume
  2581. 16_b639e55c-8f3e-47fe-9761-26c6a786ad6b_JBDKF-6NCD6-49K3G-2TV79-BK%f%P73_Retail________SkypeforBusiness2019Retail
  2582. 16_15a430d4-5e3f-4e6d-8a0a-14bf3caee4c7_9MNQ7-YPQ3B-6WJXM-G83T3-CB%f%BDK_MAK-AE________SkypeforBusiness2019Volume
  2583. 16_f88cfdec-94ce-4463-a969-037be92bc0e7_N9722-BV9H6-WTJTT-FPB93-97%f%8MK_PrepidBypass__SkypeforBusinessEntry2019Retail
  2584. 16_fdfa34dd-a472-4b85-bee6-cf07bf0aaa1c_NDGVM-MD27H-2XHVC-KDDX2-YK%f%P74_Retail________Standard2019Retail
  2585. 16_beb5065c-1872-409e-94e2-403bcfb6a878_NT3V6-XMBK7-Q66MF-VMKR4-FC%f%33M_MAK-AE________Standard2019Volume
  2586. 16_a6f69d68-5590-4e02-80b9-e7233dff204e_2NWVW-QGF4T-9CPMB-WYDQ9-7X%f%P79_Retail________VisioPro2019Retail
  2587. 16_f41abf81-f409-4b0d-889d-92b3e3d7d005_33YF4-GNCQ3-J6GDM-J67P3-FM%f%7QP_MAK-AE________VisioPro2019Volume
  2588. 16_4a582021-18c2-489f-9b3d-5186de48f1cd_263WK-3N797-7R437-28BKG-3V%f%8M8_Retail________VisioStd2019Retail
  2589. 16_933ed0e3-747d-48b0-9c2c-7ceb4c7e473d_BGNHX-QTPRJ-F9C9G-R8QQG-8T%f%27F_MAK-AE________VisioStd2019Volume
  2590. 16_72cee1c2-3376-4377-9f25-4024b6baadf8_JXR8H-NJ3MK-X66W8-78CWD-QR%f%VR2_Retail________Word2019Retail
  2591. 16_fe5fe9d5-3b06-4015-aa35-b146f85c4709_9F36R-PNVHH-3DXGQ-7CD2H-R9%f%D3V_MAK-AE________Word2019Volume
  2592. :: Office 2021
  2593. 16_f634398e-af69-48c9-b256-477bea3078b5_P286B-N3XYP-36QRQ-29CMP-RV%f%X9M_Retail________Access2021Retail
  2594. 16_ae17db74-16b0-430b-912f-4fe456e271db_JBH3N-P97FP-FRTJD-MGK2C-VF%f%WG6_MAK-AE________Access2021Volume
  2595. 16_844c36cb-851c-49e7-9079-12e62a049e2a_MNX9D-PB834-VCGY2-K2RW2-2D%f%P3D_Bypass________AccessRuntime2021Retail
  2596. 16_fb099c19-d48b-4a2f-a160-4383011060aa_V6QFB-7N7G9-PF7W9-M8FQM-MY%f%8G9_Retail________Excel2021Retail
  2597. 16_9da1ecdb-3a62-4273-a234-bf6d43dc0778_WNYR4-KMR9H-KVC8W-7HJ8B-K7%f%9DQ_MAK-AE________Excel2021Volume
  2598. 16_38b92b63-1dff-4be7-8483-2a839441a2bc_JM99N-4MMD8-DQCGJ-VMYFY-R6%f%3YK_Subscription__HomeBusiness2021Retail
  2599. 16_2f258377-738f-48dd-9397-287e43079958_N3CWD-38XVH-KRX2Y-YRP74-6R%f%BB2_Subscription__HomeStudent2021Retail
  2600. 16_279706f4-3a4b-4877-949b-f8c299cf0cc5_NB2TQ-3Y79C-77C6M-QMY7H-7Q%f%Y8P_Retail________OneNote2021Retail
  2601. 16_0c7af60d-0664-49fc-9b01-41b2dea81380_THNKC-KFR6C-Y86Q9-W8CB3-GF%f%7PD_MAK-AE________OneNote2021Volume
  2602. 16_778ccb9a-2f6a-44e5-853c-eb22b7609643_CNM3W-V94GB-QJQHH-BDQ3J-33%f%Y8H_Bypass________OneNoteFree2021Retail
  2603. 16_ecea2cfa-d406-4a7f-be0d-c6163250d126_4NCWR-9V92Y-34VB2-RPTHR-YT%f%GR7_Retail________Outlook2021Retail
  2604. 16_45bf67f9-0fc8-4335-8b09-9226cef8a576_JQ9MJ-QYN6B-67PX9-GYFVY-QJ%f%6TB_MAK-AE________Outlook2021Volume
  2605. 16_8f89391e-eedb-429d-af90-9d36fbf94de6_RRRYB-DN749-GCPW4-9H6VK-HC%f%HPT_Retail________Personal2021Retail
  2606. 16_c9bf5e86-f5e3-4ac6-8d52-e114a604d7bf_3KXXQ-PVN2C-8P7YY-HCV88-GV%f%M96_Retail1_______PowerPoint2021Retail
  2607. 16_716f2434-41b6-4969-ab73-e61e593a3875_39G2N-3BD9C-C4XCM-BD4QG-FV%f%YDY_MAK-AE________PowerPoint2021Volume
  2608. 16_c2f04adf-a5de-45c5-99a5-f5fddbda74a8_8WXTP-MN628-KY44G-VJWCK-C7%f%PCF_Retail________ProPlus2021Retail
  2609. 16_3f180b30-9b05-4fe2-aa8d-0c1c4790f811_RNHJY-DTFXW-HW9F8-4982D-MD%f%2CW_MAK-AE1_______ProPlus2021Volume
  2610. 16_96097a68-b5c5-4b19-8600-2e8d6841a0db_JRJNJ-33M7C-R73X3-P9XF7-R9%f%F6M_MAK-AE________ProPlusSPLA2021Volume
  2611. 16_711e48a6-1a79-4b00-af10-73f4ca3aaac4_DJPHV-NCJV6-GWPT6-K26JX-C7%f%PBG_Retail________Professional2021Retail
  2612. 16_3747d1d5-55a8-4bc3-b53d-19fff1913195_QKHNX-M9GGH-T3QMW-YPK4Q-QR%f%WMV_Retail________ProjectPro2021Retail
  2613. 16_17739068-86c4-4924-8633-1e529abc7efc_HVC34-CVNPG-RVCMT-X2JRF-CR%f%7RK_MAK-AE1_______ProjectPro2021Volume
  2614. 16_4ea64dca-227c-436b-813f-b6624be2d54c_2B96V-X9NJY-WFBRC-Q8MP2-7C%f%HRR_Retail________ProjectStd2021Retail
  2615. 16_84313d1e-47c8-4e27-8ced-0476b7ee46c4_3CNQX-T34TY-99RH4-C4YD2-KW%f%6WH_MAK-AE________ProjectStd2021Volume
  2616. 16_b769b746-53b1-4d89-8a68-41944dafe797_CDNFG-77T8D-VKQJX-B7KT3-KK%f%28V_Retail1_______Publisher2021Retail
  2617. 16_a0234cfe-99bd-4586-a812-4f296323c760_2KXJH-3NHTW-RDBPX-QFRXJ-MT%f%GXF_MAK-AE________Publisher2021Volume
  2618. 16_c3fb48b2-1fd4-4dc8-af39-819edf194288_DVBXN-HFT43-CVPRQ-J89TF-VM%f%MHG_Retail________SkypeforBusiness2021Retail
  2619. 16_6029109c-ceb8-4ee5-b324-f8eb2981e99a_R3FCY-NHGC7-CBPVP-8Q934-YT%f%GXG_MAK-AE________SkypeforBusiness2021Volume
  2620. 16_9e7e7b8e-a0e7-467b-9749-d0de82fb7297_HXNXB-J4JGM-TCF44-2X2CV-FJ%f%VVH_Retail________Standard2021Retail
  2621. 16_223a60d8-9002-4a55-abac-593f5b66ca45_2CJN4-C9XK2-HFPQ6-YH498-82%f%TXH_MAK-AE________Standard2021Volume
  2622. 16_b99ba8c4-e257-4b70-a31a-8bd308ce7073_BQWDW-NJ9YF-P7Y79-H6DCT-MK%f%Q9C_MAK-AE________StandardSPLA2021Volume
  2623. 16_814014d3-c30b-4f63-a493-3708e0dc0ba8_T6P26-NJVBR-76BK8-WBCDY-TX%f%3BC_Retail________VisioPro2021Retail
  2624. 16_c590605a-a08a-4cc7-8dc2-f1ffb3d06949_JNKBX-MH9P4-K8YYV-8CG2Y-VQ%f%2C8_MAK-AE________VisioPro2021Volume
  2625. 16_16d43989-a5ef-47e2-9ff1-272784caee24_89NYY-KB93R-7X22F-93QDF-DJ%f%6YM_Retail________VisioStd2021Retail
  2626. 16_d55f90ee-4ba2-4d02-b216-1300ee50e2af_BW43B-4PNFP-V637F-23TR2-J4%f%7TX_MAK-AE________VisioStd2021Volume
  2627. 16_fb33d997-4aa3-494e-8b58-03e9ab0f181d_VNCC4-CJQVK-BKX34-77Y8H-CY%f%XMR_Retail________Word2021Retail
  2628. 16_0c728382-95fb-4a55-8f12-62e605f91727_BJG97-NW3GM-8QQQ7-FH76G-68%f%6XM_MAK-AE________Word2021Volume
  2629. :: Office 2024
  2630. 16_8fdb1f1e-663f-4f2e-8fdb-7c35aee7d5ea_GNXWX-DF797-B2JT3-82W27-KH%f%PXT_MAK-AE________ProPlus2024Volume-Preview
  2631. 16_33b11b14-91fd-4f7b-b704-e64a055cf601_X86XX-N3QMW-B4WGQ-QCB69-V2%f%6KW_MAK-AE________ProjectPro2024Volume-Preview
  2632. 16_eb074198-7384-4bdd-8e6c-c3342dac8435_DW99Y-H7NT6-6B29D-8JQ8F-R3%f%QT7_MAK-AE________VisioPro2024Volume-Preview
  2633. 16_e563d108-7b0e-418a-8390-20e1d133d6bb_P6NMW-JMTRC-R6MQ6-HH3F2-BT%f%HKB_Retail________Access2024Retail
  2634. 16_f748e2f7-5951-4bc2-8a06-5a1fbe42f5f4_CXNJT-98HPP-92HX7-MX6GY-2P%f%VFR_MAK-AE________Access2024Volume
  2635. 16_f3a5e86a-e4f8-4d88-8220-1440c3bbcefa_82CNJ-W82TW-BY23W-BVJ6W-W4%f%8GP_Retail________Excel2024Retail
  2636. 16_523fbbab-c290-460d-a6c9-48e49709cb8e_7Y287-9N2KC-8MRR3-BKY82-2D%f%QRV_MAK-AE________Excel2024Volume
  2637. 16_885f83e0-5e18-4199-b8be-56697d0debfb_N69X7-73KPT-899FD-P8HQ4-QG%f%TP4_Retail________Home2024Retail
  2638. 16_acd4eccb-ff89-4e6a-9350-d2d56276ec69_PRKQM-YNPQR-77QT6-328D7-BD%f%223_Retail________HomeBusiness2024Retail
  2639. 16_6f5fd645-7119-44a4-91b4-eccfeeb738bf_2CFK4-N44KG-7XG89-CWDG6-P7%f%P27_Retail________Outlook2024Retail
  2640. 16_9a1e1bac-2d8b-4890-832f-0a68b27c16e0_NQPXP-WVB87-H3MMB-FYBW2-9Q%f%FPB_MAK-AE________Outlook2024Volume
  2641. 16_da9a57ae-81a8-4cb3-b764-5840e6b5d0bf_CT2KT-GTNWH-9HFGW-J2PWJ-XW%f%7KJ_Retail________PowerPoint2024Retail
  2642. 16_eca0d8a6-e21b-4622-9a87-a7103ff14012_RRXFN-JJ26R-RVWD2-V7WMP-27%f%PWQ_MAK-AE________PowerPoint2024Volume
  2643. 16_295dcc21-151a-4b4d-8f50-2b627ea197f6_GNJ6P-Y4RBM-C32WW-2VJKJ-MT%f%HKK_Retail________ProjectPro2024Retail
  2644. 16_2141d341-41aa-4e45-9ca1-201e117d6495_WNFMR-HK4R7-7FJVM-VQ3JC-76%f%HF6_MAK-AE1_______ProjectPro2024Volume
  2645. 16_ead42f74-817d-45b4-af6b-3beeb36ba650_C2PNM-2GQFC-CY3XR-WXCP4-GX%f%3XM_Retail________ProjectStd2024Retail
  2646. 16_4b6d9b9b-c16e-429d-babe-8bb84c3c27d6_F2VNW-MW8TT-K622Q-4D96H-PW%f%J8X_MAK-AE________ProjectStd2024Volume
  2647. 16_db249714-bb54-4422-8c78-2cc8d4c4a19f_VWCNX-7FKBD-FHJYG-XBR4B-88%f%KC6_Retail________ProPlus2024Retail
  2648. 16_d77244dc-2b82-4f0a-b8ae-1fca00b7f3e2_4YV2J-VNG7W-YGTP3-443TK-TF%f%8CP_MAK-AE1_______ProPlus2024Volume
  2649. 16_3046a03e-2277-4a51-8ccd-a6609eae8c19_XKRBW-KN2FF-G8CKY-HXVG6-FV%f%Y2V_MAK-AE________SkypeforBusiness2024Volume
  2650. 16_44a07f51-8263-4b2f-b2a5-70340055c646_GVG6N-6WCHH-K2MVP-RQ78V-3J%f%7GJ_MAK-AE1_______Standard2024Volume
  2651. 16_282d8f34-1111-4a6f-80fe-c17f70dec567_HGRBX-N68QF-6DY8J-CGX4W-XW%f%7KP_Retail________VisioPro2024Retail
  2652. 16_4c2f32bf-9d0b-4d8c-8ab1-b4c6a0b9992d_GBNHB-B2G3Q-G42YB-3MFC2-7C%f%JCX_MAK-AE________VisioPro2024Volume
  2653. 16_8504167d-887a-41ae-bd1d-f849d834352d_VBXPJ-38NR3-C4DKF-C8RT7-RG%f%HKQ_Retail________VisioStd2024Retail
  2654. 16_0978336b-5611-497c-9414-96effaff4938_YNFTY-63K7P-FKHXK-28YYT-D3%f%2XB_MAK-AE________VisioStd2024Volume
  2655. 16_f6b24e61-6aa7-4fd2-ab9b-4046cee4230a_XN33R-RP676-GMY2F-T3MH7-GC%f%VKR_Retail________Word2024Retail
  2656. 16_06142aa2-e935-49ca-af5d-08069a3d84f3_WD8CQ-6KNQM-8W2CX-2RT63-KK%f%3TP_MAK-AE________Word2024Volume
  2657. ) do (
  2658. for /f "tokens=1-5 delims=_" %%A in ("%%#") do (
  2659. if %1==getinfo if not defined key (
  2660. if %oVer%==%%A if /i "%2"=="%%E" (
  2661. set key=%%C
  2662. set _actid=%%B
  2663. set _allactid=!_allactid! %%B
  2664. set _lic=%%D
  2665. if %oVer%==16 (echo "%%D" | find /i "Subscription" %nul% && set _sublic=1)
  2666. )
  2667. )
  2668. if %1==getmsiprod if %oVer%==%%A (
  2669. for /f "tokens=*" %%x in ('findstr /i /c:"%%B" "%_oBranding%"') do set "prodId=%%x"
  2670. set prodId=!prodId:"/>=!
  2671. set prodId=!prodId:~-4!
  2672. reg query "%2\Registration\{%%B}" /v ProductCode %nul2% | find /i "-!prodId!-" %nul% && (
  2673. reg query "%2\Common\InstalledPackages" %nul2% | find /i "-!prodId!-" %nul% && (
  2674. if defined _oIds (set _oIds=!_oIds! %%E) else (set _oIds=%%E)
  2675. )
  2676. )
  2677. )
  2678. )
  2679. )
  2680. exit /b
  2681. ::========================================================================================================================================
  2682. :: This code is used to modify the timestamp value of sppc dll file in order to change checksums
  2683. :: It's done to lower the potential false positive detection by antivirus's. On each install, it will install a unique sppc dll file
  2684. :oh_extractdll
  2685. set b=
  2686. %psc% "$f=[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=[io.file]::ReadAllText('!_batp!') -split ':hexedit\:.*';iex ($m[1]);" %nul2% | find /i "Error found" %nul1% && set hasherror=1
  2687. exit /b
  2688. :hexedit:
  2689. # Use a MemoryStream to perform operations on the bytes
  2690. $MemoryStream = New-Object System.IO.MemoryStream
  2691. $Writer = New-Object System.IO.BinaryWriter($MemoryStream)
  2692. $Writer.Write($bytes)
  2693. # Define dynamic assembly, module, and type
  2694. $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)
  2695. $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)
  2696. $TypeBuilder = $ModuleBuilder.DefineType(0)
  2697. # Define P/Invoke method
  2698. [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)
  2699. # Create the type
  2700. $Imagehlp = $TypeBuilder.CreateType()
  2701. # Offset information
  2702. $timestampOffset = 136
  2703. $exportTimestampOffset = $offset
  2704. $checkSumOffset = 216
  2705. # Calculate timestamp
  2706. $currentTimestamp = [DateTime]::UtcNow
  2707. $unixTimestamp = [int]($currentTimestamp - (Get-Date -Year 1970 -Month 1 -Day 1 -Hour 0 -Minute 0 -Second 0)).TotalSeconds
  2708. # Change timestamps
  2709. $Writer.BaseStream.Position = $timestampOffset
  2710. $Writer.Write($unixTimestamp)
  2711. $Writer.BaseStream.Position = $exportTimestampOffset
  2712. $Writer.Write($unixTimestamp)
  2713. $Writer.Flush()
  2714. # Write the current state of the MemoryStream to a temporary file
  2715. $tempFilePath = [System.IO.Path]::Combine($env:windir, "Temp", [System.IO.Path]::GetRandomFileName())
  2716. [System.IO.File]::WriteAllBytes($tempFilePath, $MemoryStream.ToArray())
  2717. # Update hash using the temporary file
  2718. [int]$HeaderSum = 0
  2719. [int]$CheckSum = 0
  2720. [void]$Imagehlp::MapFileAndCheckSum($tempFilePath, [ref]$HeaderSum, [ref]$CheckSum)
  2721. # If the checksums don't match, update the checksum in the MemoryStream
  2722. if ($HeaderSum -ne $CheckSum) {
  2723. $Writer.BaseStream.Position = $checkSumOffset
  2724. $Writer.Write($CheckSum)
  2725. $Writer.Flush()
  2726. } else {
  2727. Write-host Error found
  2728. }
  2729. # Delete the temporary file
  2730. Remove-Item -Path $tempFilePath -Force
  2731. # Get the modified bytes
  2732. $modifiedBytes = $MemoryStream.ToArray()
  2733. # Write the modified bytes to the final file
  2734. [System.IO.File]::WriteAllBytes($PePath, $modifiedBytes)
  2735. [void]$Imagehlp::MapFileAndCheckSum($PePath, [ref]$HeaderSum, [ref]$CheckSum)
  2736. if ($HeaderSum -ne $CheckSum) {
  2737. Write-host Error found
  2738. }
  2739. $MemoryStream.Close()
  2740. :hexedit:
  2741. ::========================================================================================================================================
  2742. ::
  2743. :: This below blocks of text is encoded in base64 format
  2744. :: The blocks in labels "sppc32.dll" and "sppc64.dll" contains below files
  2745. ::
  2746. :: 09865ea5993215965e8f27a74b8a41d15fd0f60f5f404cb7a8b3c7757acdab02 *sppc32.dll
  2747. :: 393a1fa26deb3663854e41f2b687c188a9eacd87b23f17ea09422c4715cb5a9f *sppc64.dll
  2748. ::
  2749. :: The files are encoded in base64 to make AIO version.
  2750. ::
  2751. :: mass grave[.]dev/ohook
  2752. :: Here you can find the files source code and info on how to rebuild the identical sppc.dll files
  2753. ::
  2754. :: stackoverflow.com/a/35335273
  2755. :: Here you can check how to extract sppc.dll files from base64
  2756. ::
  2757. :: For any further question, feel free to contact us on mass grave[.]dev/contactus
  2758. ::
  2759. ::========================================================================================================================================
  2760. ::
  2761. :: 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
  2762. :: place these two files in that "BIN" folder. sppc32.dll, sppc64.dll
  2763. :: Script will auto pick that instead of using the below from base64 section. You can also delete the below code in that case.
  2764. ::
  2765. ::========================================================================================================================================
  2766. ::
  2767. :: Replace "-" with "A" and "_" with "a" before base64 conversion
  2768. :: It was changed to prevent antiviruses from detecting and flagging base64 encoding
  2769. :sppc32.dll:
  2770. TVqQ--M----E----//8--Lg---------Q-----------------------------------------------g-----4fug4-t-nNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4g_W4gRE9TIG1vZGUuDQ0KJ---------BQRQ--T-EH-MDc0GQ----------O--
  2771. DiML-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---------
  2772. ----------------------------------------------------------BsY---H------------------------------------C50ZXh0----c-E----Q-----g----Q------------------C---G-ucmRhdGE--Bg-----I-----I----G----------------
  2773. --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--
  2774. ----------------Q---wC5yZWxvYw--F-----C------g---CI------------------E---EI-----------------------------------------------------------------------------------------------------------------------------
  2775. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2776. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------FWJ5VZTjUXwg+wwx0Xw-----IlEJBSNRfSJ
  2777. RCQQi0UMx0QkD-----CJRCQEi0UIx0QkC--ggGqJBCTHRfQ-----6-oB--CLNXhggGqD7BiFwInDi0Xwd-qJBCQx2//WUesyi1X0x0QkB-oggGqJBCSJVCQI/xW-YIBqg+wMhcCLRfCJBCR0Cv/WuwE---BS6wP/1lCNZfiJ2FteXcNVieVXVlOD7DyLRRiLdRyJRCQQ
  2778. i0UUiXQkFIlEJ-yLRRCJRCQIi0UMiUQkBItFCIkEJOiE----McmD7BiJx4X-dVyLRRg5CHZV_9koiwYB2IN4E-B0RYlEJ-SLRQiJTeSJBCTo+/7//4tN5IX-dSwDHsdDE-E---DHQxQ-----x0MY-----MdDH-----DHQy------x0Mk-----EHrpI1l9In4W15fXcIY
  2779. -LgB----wgw-kP8lcGC-_pCQ/yVsYIBqkJD/////-----P////8-----------------------------------------------------------------------------------------------------------------------------------------------------
  2780. ------------------------------------------------TgBh-G0-ZQ---Ec-cgBh-GM-ZQ------------------------------------------------------------------------------------------------------------------------------
  2781. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2782. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2783. -----------------------------------------------------------------------------------------------------------------------------------U----------F6Ug-Bf-gBGwwEBIgB---k----H----ODf//+d-----EEOCIUCQg0FSIYD
  2784. gwQCj8NBxkHFD-QEK----EQ---BV4P//qg----BBDgiF-kINBU_H-4YEgwUCm8NBxkHHQcUMB-QQ----c----NPg//8I------------------------------------------------------------------------------------------------------------
  2785. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2786. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2787. ------------------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--
  2788. n0c--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
  2789. --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--
  2790. Wkk--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-
  2791. Bw-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
  2792. Q2FsbFNlcnZlcgBTUFBDUy5TTENsb3Nl-FNMQ2xvc2U-U1BQQ1MuU0xDb25zdW1lUmln_HQ-U0xDb25zdW1lUmln_HQ-U1BQQ1MuU0xEZXBvc2l0TWlncmF0_W9uQmxvYgBTTERlcG9z_XRN_WdyYXRpb25CbG9i-FNQUENTLlNMRGVwb3NpdE9mZmxpbmVDb25m_XJt
  2793. YXRpb25JZ-BTTERlcG9z_XRPZmZs_W5lQ29uZmlybWF0_W9uSWQ-U1BQQ1MuU0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklkRXg-U0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklkRXg-U1BQQ1MuU0xEZXBvc2l0U3RvcmVUb2tlbgBTTERlcG9z_XRTdG9y
  2794. ZVRv_2Vu-FNQUENTLlNMRmlyZUV2ZW50-FNMRmlyZUV2ZW50-FNQUENTLlNMR2F0_GVyTWlncmF0_W9uQmxvYgBTTEdhdGhlck1pZ3JhdGlvbkJsb2I-U1BQQ1MuU0xHYXRoZXJN_WdyYXRpb25CbG9iRXg-U0xHYXRoZXJN_WdyYXRpb25CbG9iRXg-U1BQQ1MuU0xH
  2795. ZW5lcmF0ZU9mZmxpbmVJbnN0YWxsYXRpb25JZ-BTTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklk-FNQUENTLlNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWRFe-BTTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklkRXg-U1BQQ1MuU0xHZXRBY3Rp
  2796. dmVM_WNlbnNlSW5mbwBTTEdldEFjdGl2ZUxpY2Vuc2VJbmZv-FNQUENTLlNMR2V0QXBwbGljYXRpb25JbmZvcm1hdGlvbgBTTEdldEFwcGxpY2F0_W9uSW5mb3JtYXRpb24-U1BQQ1MuU0xHZXRBcHBs_WNhdGlvblBvbGljeQBTTEdldEFwcGxpY2F0_W9uUG9s_WN5
  2797. -FNQUENTLlNMR2V0QXV0_GVudGljYXRpb25SZXN1bHQ-U0xHZXRBdXRoZW50_WNhdGlvblJlc3Vsd-BTUFBDUy5TTEdldEVuY3J5cHRlZFBJREV4-FNMR2V0RW5jcnlwdGVkUElERXg-U1BQQ1MuU0xHZXRHZW51_W5lSW5mb3JtYXRpb24-U0xHZXRHZW51_W5lSW5m
  2798. b3JtYXRpb24-U1BQQ1MuU0xHZXRJbnN0YWxsZWRQcm9kdWN0S2V5SWRz-FNMR2V0SW5zdGFsbGVkUHJvZHVjdEtleUlkcwBTUFBDUy5TTEdldExpY2Vuc2U-U0xHZXRM_WNlbnNl-FNQUENTLlNMR2V0TGljZW5zZUZpbGVJZ-BTTEdldExpY2Vuc2VG_WxlSWQ-U1BQ
  2799. Q1MuU0xHZXRM_WNlbnNlSW5mb3JtYXRpb24-U0xHZXRM_WNlbnNlSW5mb3JtYXRpb24-U0xHZXRM_WNlbnNpbmdTdGF0dXNJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFBLZXlJZ-BTTEdldFBLZXlJZ-BTUFBDUy5TTEdldFBLZXlJbmZvcm1hdGlvbgBTTEdldFBLZXlJ
  2800. bmZvcm1hdGlvbgBTUFBDUy5TTEdldFBvbGljeUluZm9ybWF0_W9u-FNMR2V0UG9s_WN5SW5mb3JtYXRpb24-U1BQQ1MuU0xHZXRQb2xpY3lJbmZvcm1hdGlvbkRXT1JE-FNMR2V0UG9s_WN5SW5mb3JtYXRpb25EV09SR-BTUFBDUy5TTEdldFByb2R1Y3RT_3VJbmZv
  2801. cm1hdGlvbgBTTEdldFByb2R1Y3RT_3VJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFNMSURM_XN0-FNMR2V0U0xJRExpc3Q-U1BQQ1MuU0xHZXRTZXJ2_WNlSW5mb3JtYXRpb24-U0xHZXRTZXJ2_WNlSW5mb3JtYXRpb24-U1BQQ1MuU0xJbnN0YWxsTGljZW5zZQBTTElu
  2802. c3RhbGxM_WNlbnNl-FNQUENTLlNMSW5zdGFsbFByb29mT2ZQdXJj_GFzZQBTTEluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U1BQQ1MuU0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNlRXg-U0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNlRXg-U1BQQ1MuU0xJc0dlbnVpbmVMb2Nh
  2803. bEV4-FNMSXNHZW51_W5lTG9jYWxFe-BTUFBDUy5TTExvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNMTG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U1BQQ1MuU0xPcGVu-FNMT3BlbgBTUFBDUy5TTFBlcnNpc3RBcHBs_WNhdGlvblBvbGlj_WVz-FNMUGVyc2lzdEFwcGxp
  2804. Y2F0_W9uUG9s_WNpZXM-U1BQQ1MuU0xQZXJz_XN0UlRTUGF5bG9hZE92ZXJy_WRl-FNMUGVyc2lzdFJUU1BheWxvYWRPdmVycmlkZQBTUFBDUy5TTFJlQXJt-FNMUmVBcm0-U1BQQ1MuU0xSZWdpc3RlckV2ZW50-FNMUmVn_XN0ZXJFdmVud-BTUFBDUy5TTFJlZ2lz
  2805. dGVyUGx1Z2lu-FNMUmVn_XN0ZXJQbHVn_W4-U1BQQ1MuU0xTZXRBdXRoZW50_WNhdGlvbkRhdGE-U0xTZXRBdXRoZW50_WNhdGlvbkRhdGE-U1BQQ1MuU0xTZXRDdXJyZW50UHJvZHVjdEtleQBTTFNldEN1cnJlbnRQcm9kdWN0S2V5-FNQUENTLlNMU2V0R2VudWlu
  2806. ZUluZm9ybWF0_W9u-FNMU2V0R2VudWluZUluZm9ybWF0_W9u-FNQUENTLlNMVW5pbnN0YWxsTGljZW5zZQBTTFVu_W5zdGFsbExpY2Vuc2U-U1BQQ1MuU0xVbmluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U0xVbmluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U1BQQ1MuU0xV
  2807. bmxvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNMVW5sb2FkQXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5TTFVucmVn_XN0ZXJFdmVud-BTTFVucmVn_XN0ZXJFdmVud-BTUFBDUy5TTFVucmVn_XN0ZXJQbHVn_W4-U0xVbnJlZ2lzdGVyUGx1Z2lu-FNQUENTLlNMcEF1
  2808. dGhlbnRpY2F0ZUdlbnVpbmVU_WNrZXRSZXNwb25zZQBTTHBBdXRoZW50_WNhdGVHZW51_W5lVGlj_2V0UmVzcG9uc2U-U1BQQ1MuU0xwQmVn_W5HZW51_W5lVGlj_2V0VHJhbnNhY3Rpb24-U0xwQmVn_W5HZW51_W5lVGlj_2V0VHJhbnNhY3Rpb24-U1BQQ1MuU0xw
  2809. Q2xlYXJBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTTHBDbGVhckFjdGl2YXRpb25JblByb2dyZXNz-FNQUENTLlNMcERlcG9z_XREb3dubGV2ZWxHZW51_W5lVGlj_2V0-FNMcERlcG9z_XREb3dubGV2ZWxHZW51_W5lVGlj_2V0-FNQUENTLlNMcERlcG9z_XRUb2tlbkFj
  2810. dGl2YXRpb25SZXNwb25zZQBTTHBEZXBvc2l0VG9rZW5BY3RpdmF0_W9uUmVzcG9uc2U-U1BQQ1MuU0xwR2VuZXJhdGVUb2tlbkFjdGl2YXRpb25D_GFsbGVuZ2U-U0xwR2VuZXJhdGVUb2tlbkFjdGl2YXRpb25D_GFsbGVuZ2U-U1BQQ1MuU0xwR2V0R2VudWluZUJs
  2811. b2I-U0xwR2V0R2VudWluZUJsb2I-U1BQQ1MuU0xwR2V0R2VudWluZUxvY2Fs-FNMcEdldEdlbnVpbmVMb2Nhb-BTUFBDUy5TTHBHZXRM_WNlbnNlQWNxdWlz_XRpb25JbmZv-FNMcEdldExpY2Vuc2VBY3F1_XNpdGlvbkluZm8-U1BQQ1MuU0xwR2V0TVNQ_WRJbmZv
  2812. cm1hdGlvbgBTTHBHZXRNU1BpZEluZm9ybWF0_W9u-FNQUENTLlNMcEdldE1hY2hpbmVVR1VJR-BTTHBHZXRNYWNo_W5lVUdVSUQ-U1BQQ1MuU0xwR2V0VG9rZW5BY3RpdmF0_W9uR3JhbnRJbmZv-FNMcEdldFRv_2VuQWN0_XZhdGlvbkdyYW50SW5mbwBTUFBDUy5T
  2813. THBJQUFjdGl2YXRlUHJvZHVjd-BTTHBJQUFjdGl2YXRlUHJvZHVjd-BTUFBDUy5TTHBJc0N1cnJlbnRJbnN0YWxsZWRQcm9kdWN0S2V5RGVmYXVsdEtleQBTTHBJc0N1cnJlbnRJbnN0YWxsZWRQcm9kdWN0S2V5RGVmYXVsdEtleQBTUFBDUy5TTHBQcm9jZXNzVk1Q
  2814. _XBlTWVzc2FnZQBTTHBQcm9jZXNzVk1Q_XBlTWVzc2FnZQBTUFBDUy5TTHBTZXRBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTTHBTZXRBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTUFBDUy5TTHBUcmlnZ2VyU2VydmljZVdvcmtlcgBTTHBUcmlnZ2VyU2VydmljZVdvcmtlcgBT
  2815. UFBDUy5TTHBWTEFjdGl2YXRlUHJvZHVjd-BTTHBWTEFjdGl2YXRlUHJvZHVjd-------------------------------------------------------------------------------------------------------------------------------------------
  2816. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2817. -------------------------------------------------------------------------------------------------------------------------------------------------------------FBg-------------Ohg--BsY---XG--------------
  2818. +G---Hhg--BkY--------------MYQ--gG------------------------------iG---Kpg--------yG--------DUY--------Ihg--CqY--------Mhg--------1G---------C-FNMR2V0TGljZW5z_W5nU3RhdHVzSW5mb3JtYXRpb24--QBTTEdldFByb2R1
  2819. Y3RT_3VJbmZvcm1hdGlvbg--3QNMb2NhbEZyZWU-RwFTdHJTdHJOSVc--G----Bg--BzcHBjcy5kbGw----UY---S0VSTkVMMzIuZGxs-----Chg--BTSExXQVBJLmRsb-----------------------------------------------------------------------
  2820. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2821. -----------------------------------------------------------B-B-----Y--C--------------------B--E----w--C--------------------B--kE--BI----WH---BwD-------------BwDN----FY-UwBf-FY-RQBS-FM-SQBP-E4-XwBJ-E4-
  2822. RgBP------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----
  2823. --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--
  2824. U-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--
  2825. QQBu-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-------
  2826. L--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-
  2827. _QBv-G4-------kE5-Q-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2828. -------Q---U----MzBIMGkwdjBSMVox------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2829. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2830. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2831. ----------------------------------------------------------------------------------------
  2832. :sppc32.dll:
  2833. :========================================================================================================================================
  2834. :: Replace "-" with "A" and "_" with "a" before base64 conversion
  2835. :: It was changed to prevent antiviruses from detecting and flagging base64 encoding
  2836. :sppc64.dll:
  2837. TVqQ--M----E----//8--Lg---------Q-----------------------------------------------g-----4fug4-t-nNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4g_W4gRE9TIG1vZGUuDQ0KJ---------BQRQ--ZIYH-MDc0GQ----------P--
  2838. LiIL-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---------
  2839. --------------------------------------------------------------------------------iH---Dg------------------------------------udGV4d----H-B----E-----I----E-------------------g--BgLnJkYXRh---g-----C-----C
  2840. ----Bg------------------Q---QC5wZGF0YQ--J------w-----g----g------------------E---E-ueGRhdGE--CQ-----Q-----I----K------------------B---B-LmVkYXRh--CNE----F-----S----D-------------------Q---QC5pZGF0YQ--
  2841. U-E---Bw-----g---B4------------------E---M-ucnNyYw---HgD----g-----Q----g------------------B---D---------------------------------------------------------------------------------------------------------
  2842. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2843. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------EFUU0iD7EhFMclMjQXvDw--SI1EJDjHRCQ0
  2844. -----EiJRCQoSI1EJDRIiUQkIEjHRCQ4-----OgF-Q--SItMJDhIix1ZY---hcBBicR0B//TRTHk6yhEi0QkNEiNF_kP--D/FUlg--BIi0wkOEiFwHQK/9NBv-E---Dr-v/TRIngSIPESFtBXMNBVUFUVVdWU0iD7Dgx9kyLrCSQ----SIusJJg---BMiWwkIEiJz0iJ
  2845. bCQo6J----BBicSFwHVEQTl1-HY+SGveKEiLVQBI-dqDeh--dChIifnoIv///4X-dRxI-10-SMdDE-E---BIx0MY-----EjHQy------SP/G67xEieBIg8Q4W15fXUFcQV3Du-E---DDkJCQkJCQkP8lel8--JCQDx+E------D/JXpf--CQk-8fh-------/yVKXw--
  2846. kJD/JTpf--CQkP//////////----------D//////////w----------------------------------------------------------------------------------------------------------------------------------------------------------
  2847. ------------------------------------------------TgBh-G0-ZQ---Ec-cgBh-GM-ZQ------------------------------------------------------------------------------------------------------------------------------
  2848. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2849. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2850. ------------------------------------------------------------------------------------------------------------------------------------E---iB----B---CIE---ExE---x----TEQ--GRE--CB-------------------------
  2851. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2852. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2853. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2854. --------------EH-w-HggMw-s----EMBw-MYggwB2-Gc-VQBM-C0----Q----------------------------------------------------------------------------------------------------------------------------------------------
  2855. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2856. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2857. -----------------------------------------------------------------------------------------------------MDc0GQ-----xlI---E---BD----Qw---ChQ---0UQ--QFI--M9S--DvUg--BVM--ClT--BdUw--oVM--OlT---XV---NVQ--GdU
  2858. --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--
  2859. 41s---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
  2860. --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--
  2861. CV4--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-
  2862. Mw-0-DU-Ng-3-Dg-OQ-6-Ds-P--9-D4-PwB--EE-QgBzcHBjLmRsb-BTUFBDUy5TTENhbGxTZXJ2ZXI-U0xDYWxsU2VydmVy-FNQUENTLlNMQ2xvc2U-U0xDbG9zZQBTUFBDUy5TTENvbnN1bWVS_Wdod-BTTENvbnN1bWVS_Wdod-BTUFBDUy5TTERlcG9z_XRN_Wdy
  2863. YXRpb25CbG9i-FNMRGVwb3NpdE1pZ3JhdGlvbkJsb2I-U1BQQ1MuU0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklk-FNMRGVwb3NpdE9mZmxpbmVDb25m_XJtYXRpb25JZ-BTUFBDUy5TTERlcG9z_XRPZmZs_W5lQ29uZmlybWF0_W9uSWRFe-BTTERlcG9z_XRP
  2864. ZmZs_W5lQ29uZmlybWF0_W9uSWRFe-BTUFBDUy5TTERlcG9z_XRTdG9yZVRv_2Vu-FNMRGVwb3NpdFN0b3JlVG9rZW4-U1BQQ1MuU0xG_XJlRXZlbnQ-U0xG_XJlRXZlbnQ-U1BQQ1MuU0xHYXRoZXJN_WdyYXRpb25CbG9i-FNMR2F0_GVyTWlncmF0_W9uQmxvYgBT
  2865. UFBDUy5TTEdhdGhlck1pZ3JhdGlvbkJsb2JFe-BTTEdhdGhlck1pZ3JhdGlvbkJsb2JFe-BTUFBDUy5TTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklk-FNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWQ-U1BQQ1MuU0xHZW5lcmF0ZU9mZmxpbmVJbnN0
  2866. YWxsYXRpb25JZEV4-FNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWRFe-BTUFBDUy5TTEdldEFjdGl2ZUxpY2Vuc2VJbmZv-FNMR2V0QWN0_XZlTGljZW5zZUluZm8-U1BQQ1MuU0xHZXRBcHBs_WNhdGlvbkluZm9ybWF0_W9u-FNMR2V0QXBwbGljYXRpb25J
  2867. bmZvcm1hdGlvbgBTUFBDUy5TTEdldEFwcGxpY2F0_W9uUG9s_WN5-FNMR2V0QXBwbGljYXRpb25Qb2xpY3k-U1BQQ1MuU0xHZXRBdXRoZW50_WNhdGlvblJlc3Vsd-BTTEdldEF1dGhlbnRpY2F0_W9uUmVzdWx0-FNQUENTLlNMR2V0RW5jcnlwdGVkUElERXg-U0xH
  2868. ZXRFbmNyeXB0ZWRQSURFe-BTUFBDUy5TTEdldEdlbnVpbmVJbmZvcm1hdGlvbgBTTEdldEdlbnVpbmVJbmZvcm1hdGlvbgBTUFBDUy5TTEdldEluc3RhbGxlZFByb2R1Y3RLZXlJZHM-U0xHZXRJbnN0YWxsZWRQcm9kdWN0S2V5SWRz-FNQUENTLlNMR2V0TGljZW5z
  2869. ZQBTTEdldExpY2Vuc2U-U1BQQ1MuU0xHZXRM_WNlbnNlRmlsZUlk-FNMR2V0TGljZW5zZUZpbGVJZ-BTUFBDUy5TTEdldExpY2Vuc2VJbmZvcm1hdGlvbgBTTEdldExpY2Vuc2VJbmZvcm1hdGlvbgBTTEdldExpY2Vuc2luZ1N0YXR1c0luZm9ybWF0_W9u-FNQUENT
  2870. LlNMR2V0UEtleUlk-FNMR2V0UEtleUlk-FNQUENTLlNMR2V0UEtleUluZm9ybWF0_W9u-FNMR2V0UEtleUluZm9ybWF0_W9u-FNQUENTLlNMR2V0UG9s_WN5SW5mb3JtYXRpb24-U0xHZXRQb2xpY3lJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFBvbGljeUluZm9ybWF0
  2871. _W9uRFdPUkQ-U0xHZXRQb2xpY3lJbmZvcm1hdGlvbkRXT1JE-FNQUENTLlNMR2V0UHJvZHVjdFNrdUluZm9ybWF0_W9u-FNMR2V0UHJvZHVjdFNrdUluZm9ybWF0_W9u-FNQUENTLlNMR2V0U0xJRExpc3Q-U0xHZXRTTElETGlzd-BTUFBDUy5TTEdldFNlcnZpY2VJ
  2872. bmZvcm1hdGlvbgBTTEdldFNlcnZpY2VJbmZvcm1hdGlvbgBTUFBDUy5TTEluc3RhbGxM_WNlbnNl-FNMSW5zdGFsbExpY2Vuc2U-U1BQQ1MuU0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNl-FNMSW5zdGFsbFByb29mT2ZQdXJj_GFzZQBTUFBDUy5TTEluc3RhbGxQcm9v
  2873. Zk9mUHVyY2hhc2VFe-BTTEluc3RhbGxQcm9vZk9mUHVyY2hhc2VFe-BTUFBDUy5TTElzR2VudWluZUxvY2FsRXg-U0xJc0dlbnVpbmVMb2NhbEV4-FNQUENTLlNMTG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xMb2FkQXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5T
  2874. TE9wZW4-U0xPcGVu-FNQUENTLlNMUGVyc2lzdEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xQZXJz_XN0QXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5TTFBlcnNpc3RSVFNQYXlsb2FkT3ZlcnJpZGU-U0xQZXJz_XN0UlRTUGF5bG9hZE92ZXJy_WRl-FNQUENTLlNMUmVB
  2875. cm0-U0xSZUFybQBTUFBDUy5TTFJlZ2lzdGVyRXZlbnQ-U0xSZWdpc3RlckV2ZW50-FNQUENTLlNMUmVn_XN0ZXJQbHVn_W4-U0xSZWdpc3RlclBsdWdpbgBTUFBDUy5TTFNldEF1dGhlbnRpY2F0_W9uRGF0YQBTTFNldEF1dGhlbnRpY2F0_W9uRGF0YQBTUFBDUy5T
  2876. TFNldEN1cnJlbnRQcm9kdWN0S2V5-FNMU2V0Q3VycmVudFByb2R1Y3RLZXk-U1BQQ1MuU0xTZXRHZW51_W5lSW5mb3JtYXRpb24-U0xTZXRHZW51_W5lSW5mb3JtYXRpb24-U1BQQ1MuU0xVbmluc3RhbGxM_WNlbnNl-FNMVW5pbnN0YWxsTGljZW5zZQBTUFBDUy5T
  2877. TFVu_W5zdGFsbFByb29mT2ZQdXJj_GFzZQBTTFVu_W5zdGFsbFByb29mT2ZQdXJj_GFzZQBTUFBDUy5TTFVubG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xVbmxvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNQUENTLlNMVW5yZWdpc3RlckV2ZW50-FNMVW5yZWdpc3Rl
  2878. ckV2ZW50-FNQUENTLlNMVW5yZWdpc3RlclBsdWdpbgBTTFVucmVn_XN0ZXJQbHVn_W4-U1BQQ1MuU0xwQXV0_GVudGljYXRlR2VudWluZVRpY2tldFJlc3BvbnNl-FNMcEF1dGhlbnRpY2F0ZUdlbnVpbmVU_WNrZXRSZXNwb25zZQBTUFBDUy5TTHBCZWdpbkdlbnVp
  2879. bmVU_WNrZXRUcmFuc2FjdGlvbgBTTHBCZWdpbkdlbnVpbmVU_WNrZXRUcmFuc2FjdGlvbgBTUFBDUy5TTHBDbGVhckFjdGl2YXRpb25JblByb2dyZXNz-FNMcENsZWFyQWN0_XZhdGlvbkluUHJvZ3Jlc3M-U1BQQ1MuU0xwRGVwb3NpdERvd25sZXZlbEdlbnVpbmVU
  2880. _WNrZXQ-U0xwRGVwb3NpdERvd25sZXZlbEdlbnVpbmVU_WNrZXQ-U1BQQ1MuU0xwRGVwb3NpdFRv_2VuQWN0_XZhdGlvblJlc3BvbnNl-FNMcERlcG9z_XRUb2tlbkFjdGl2YXRpb25SZXNwb25zZQBTUFBDUy5TTHBHZW5lcmF0ZVRv_2VuQWN0_XZhdGlvbkNoYWxs
  2881. ZW5nZQBTTHBHZW5lcmF0ZVRv_2VuQWN0_XZhdGlvbkNoYWxsZW5nZQBTUFBDUy5TTHBHZXRHZW51_W5lQmxvYgBTTHBHZXRHZW51_W5lQmxvYgBTUFBDUy5TTHBHZXRHZW51_W5lTG9jYWw-U0xwR2V0R2VudWluZUxvY2Fs-FNQUENTLlNMcEdldExpY2Vuc2VBY3F1
  2882. _XNpdGlvbkluZm8-U0xwR2V0TGljZW5zZUFjcXVpc2l0_W9uSW5mbwBTUFBDUy5TTHBHZXRNU1BpZEluZm9ybWF0_W9u-FNMcEdldE1TUGlkSW5mb3JtYXRpb24-U1BQQ1MuU0xwR2V0TWFj_GluZVVHVUlE-FNMcEdldE1hY2hpbmVVR1VJR-BTUFBDUy5TTHBHZXRU
  2883. b2tlbkFjdGl2YXRpb25HcmFudEluZm8-U0xwR2V0VG9rZW5BY3RpdmF0_W9uR3JhbnRJbmZv-FNQUENTLlNMcElBQWN0_XZhdGVQcm9kdWN0-FNMcElBQWN0_XZhdGVQcm9kdWN0-FNQUENTLlNMcElzQ3VycmVudEluc3RhbGxlZFByb2R1Y3RLZXlEZWZhdWx0S2V5
  2884. -FNMcElzQ3VycmVudEluc3RhbGxlZFByb2R1Y3RLZXlEZWZhdWx0S2V5-FNQUENTLlNMcFByb2Nlc3NWTVBpcGVNZXNzYWdl-FNMcFByb2Nlc3NWTVBpcGVNZXNzYWdl-FNQUENTLlNMcFNldEFjdGl2YXRpb25JblByb2dyZXNz-FNMcFNldEFjdGl2YXRpb25JblBy
  2885. b2dyZXNz-FNQUENTLlNMcFRy_WdnZXJTZXJ2_WNlV29y_2Vy-FNMcFRy_WdnZXJTZXJ2_WNlV29y_2Vy-FNQUENTLlNMcFZMQWN0_XZhdGVQcm9kdWN0-FNMcFZMQWN0_XZhdGVQcm9kdWN0--------------------------------------------------------
  2886. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2887. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2888. ----------------------------------------UH--------------IHE--Ihw--Boc--------------wcQ--oH---Hhw-------------ERx--Cwc-----------------------------D-c--------OJw--------------------cQ------------------
  2889. DHE------------------MBw--------4n--------------------Bx-------------------McQ-------------------gBTTEdldExpY2Vuc2luZ1N0YXR1c0luZm9ybWF0_W9u--E-U0xHZXRQcm9kdWN0U2t1SW5mb3JtYXRpb24--OgDTG9jYWxGcmVl-FEB
  2890. U3RyU3RyTklX--Bw----c---c3BwY3MuZGxs----FH---EtFUk5FTDMyLmRsb------oc---U0hMV0FQSS5kbGw-----------------------------------------------------------------------------------------------------------------
  2891. ----------------------------------------------------------------------------------------------------------------------------------------------E-E----Bg--I--------------------E--Q---D---I--------------
  2892. ------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-
  2893. bgBm-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-
  2894. bg------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----
  2895. cwBw-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-
  2896. ---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-
  2897. M--u-D----BE-----QBW-GE-cgBG-Gk-b-Bl-Ek-bgBm-G8------CQ-B----FQ-cgBh-G4-cwBs-GE-d-Bp-G8-bg------CQTkB---------------------------------------------------------------------------------------------------
  2898. ----------------------------------------------------------------------------------------
  2899. :sppc64.dll:
  2900. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2901. :TSforgeActivation
  2902. :: To activate Windows, run the script with "/Z-Windows" parameter or change 0 to 1 in below line
  2903. set _actwin=0
  2904. :: To activate Windows ESU, run the script with "/Z-ESU" parameter or change 0 to 1 in below line
  2905. set _actesu=0
  2906. :: To activate all Office apps (including Project/Visio), run the script with "/Z-Office" parameter or change 0 to 1 in below line
  2907. set _actoff=0
  2908. :: To activate only Project/Visio, run the script with "/Z-ProjectVisio" parameter or change 0 to 1 in below line
  2909. set _actprojvis=0
  2910. :: To activate all Windows/ESU/Office, run the script with "/Z-WindowsESUOffice" parameter or change 0 to 1 in below line
  2911. set _actwinesuoff=0
  2912. :: Advanced options:
  2913. :: To activate Windows K-M-S host (csvlk), run the script with "/Z-WinHost" parameter or change 0 to 1 in below line
  2914. set _actwinhost=0
  2915. :: To activate Office K-M-S host (csvlk), run the script with "/Z-OffHost" parameter or change 0 to 1 in below line
  2916. set _actoffhost=0
  2917. :: To activate Windows 8/8.1 APPX Sideloading (APPXLOB), run the script with "/Z-APPX" parameter or change 0 to 1 in below line
  2918. set _actappx=0
  2919. :: 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
  2920. :: or run the script with "/Z-ID-ActivationIdGoesHere" parameter. If you want to add multiple through parameter, pass each of them in separate parameters
  2921. set _actman=
  2922. set tsids=
  2923. :: 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
  2924. set _resall=0
  2925. :: Debug Mode:
  2926. :: To run the script in debug mode, change 0 to any parameter above that you want to run, in below line
  2927. set "_debug=0"
  2928. :: Script will run in unattended mode if parameters are used OR value is changed in above lines.
  2929. :: If multiple options are selected then script will only pick one from the advanced option.
  2930. ::========================================================================================================================================
  2931. cls
  2932. color 07
  2933. set KS=K%blank%MS
  2934. title TSforge Activation %masver%
  2935. set _args=
  2936. set _elev=
  2937. set _unattended=0
  2938. set _args=%*
  2939. if defined _args set _args=%_args:"=%
  2940. if defined _args set _args=%_args:re1=%
  2941. if defined _args set _args=%_args:re2=%
  2942. if defined _args for %%A in (%_args%) do (
  2943. if /i "%%A"=="-el" (set _elev=1)
  2944. if /i "%%A"=="/Z-Windows" (set _actwin=1)
  2945. if /i "%%A"=="/Z-ESU" (set _actesu=1)
  2946. if /i "%%A"=="/Z-Office" (set _actoff=1)
  2947. if /i "%%A"=="/Z-ProjectVisio" (set _actprojvis=1)
  2948. if /i "%%A"=="/Z-WindowsESUOffice" (set _actwinesuoff=1)
  2949. if /i "%%A"=="/Z-WinHost" (set _actwinhost=1)
  2950. if /i "%%A"=="/Z-OffHost" (set _actoffhost=1)
  2951. if /i "%%A"=="/Z-APPX" (set _actappx=1)
  2952. echo "%%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%%)
  2953. if /i "%%A"=="/Z-Reset" (set _resall=1)
  2954. )
  2955. if not defined tsids set _actman=0
  2956. for %%A in (%_actwin% %_actesu% %_actoff% %_actprojvis% %_actwinesuoff% %_actwinhost% %_actoffhost% %_actappx% %_actman% %_resall%) do (if "%%A"=="1" set _unattended=1)
  2957. ::========================================================================================================================================
  2958. :ts_menu
  2959. if %_unattended%==0 (
  2960. cls
  2961. if not defined terminal mode 76, 33
  2962. title TSforge Activation %masver%
  2963. echo:
  2964. echo:
  2965. echo:
  2966. echo ______________________________________________________________
  2967. echo:
  2968. echo [1] Activate - Windows
  2969. echo [2] Activate - Windows [ESU]
  2970. echo [3] Activate - Office [All]
  2971. echo [4] Activate - Office [Project/Visio]
  2972. echo [5] Activate - All
  2973. echo _______________________________________________
  2974. echo:
  2975. echo Advanced Options:
  2976. echo:
  2977. echo [A] Activate - Windows %KS% Host
  2978. echo [B] Activate - Office %KS% Host
  2979. echo [C] Activate - Windows 8/8.1 APPX Sideloading
  2980. echo [D] Activate - Manually Select Products
  2981. echo [E] Reset - Rearm/Timers/Tamper/Lock
  2982. echo _______________________________________________
  2983. echo:
  2984. echo [6] Remove TSforge Activation
  2985. echo [7] Download Office
  2986. echo [0] %_exitmsg%
  2987. echo ______________________________________________________________
  2988. echo:
  2989. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard..."
  2990. choice /C:12345ABCDE670 /N
  2991. set _el=!errorlevel!
  2992. if !_el!==13 exit /b
  2993. if !_el!==12 start %mas%genuine-installation-media & goto :ts_menu
  2994. if !_el!==11 call :ts_remove & cls & goto :ts_menu
  2995. if !_el!==10 cls & setlocal & set "_resall=1" & call :ts_start & endlocal & cls & goto :ts_menu
  2996. if !_el!==9 cls & setlocal & set "_actman=1" & call :ts_start & endlocal & cls & goto :ts_menu
  2997. if !_el!==8 cls & setlocal & set "_actappx=1" & call :ts_start & endlocal & cls & goto :ts_menu
  2998. if !_el!==7 cls & setlocal & set "_actoffhost=1" & call :ts_start & endlocal & cls & goto :ts_menu
  2999. if !_el!==6 cls & setlocal & set "_actwinhost=1" & call :ts_start & endlocal & cls & goto :ts_menu
  3000. if !_el!==5 cls & setlocal & set "_actwinesuoff=1" & call :ts_start & endlocal & cls & goto :ts_menu
  3001. if !_el!==4 cls & setlocal & set "_actprojvis=1" & call :ts_start & endlocal & cls & goto :ts_menu
  3002. if !_el!==3 cls & setlocal & set "_actoff=1" & call :ts_start & endlocal & cls & goto :ts_menu
  3003. if !_el!==2 cls & setlocal & set "_actesu=1" & call :ts_start & endlocal & cls & goto :ts_menu
  3004. if !_el!==1 cls & setlocal & set "_actwin=1" & call :ts_start & endlocal & cls & goto :ts_menu
  3005. goto :ts_menu
  3006. )
  3007. ::========================================================================================================================================
  3008. :ts_start
  3009. cls
  3010. if %_actwinesuoff%==1 (set height=38) else (set height=32)
  3011. if not defined terminal (
  3012. mode 125, %height%
  3013. if exist "%SysPath%\spp\store_test\" mode 134, %height%
  3014. %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%
  3015. )
  3016. title TSforge Activation %masver%
  3017. echo:
  3018. echo Initializing...
  3019. call :dk_chkmal
  3020. if not exist %SysPath%\sppsvc.exe (
  3021. %eline%
  3022. echo [%SysPath%\sppsvc.exe] file is missing, aborting...
  3023. echo:
  3024. set fixes=%fixes% %mas%troubleshoot
  3025. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  3026. goto dk_done
  3027. )
  3028. for /f "delims=" %%a in ('%psc% "[System.Environment]::Version.Major" %nul6%') do if "%%a"=="2" (
  3029. reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" /v Install %nul2% | find /i "0x1" %nul1% || (
  3030. %eline%
  3031. echo .NET 3.5 Framework is corrupt or missing. Aborting...
  3032. if exist "%SysPath%\spp\tokens\skus\Security-SPP-Component-SKU-Embedded" (
  3033. echo Install .NET Framework 4.8 and Windows Management Framework 5.1
  3034. )
  3035. echo:
  3036. set fixes=%fixes% %mas%troubleshoot
  3037. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  3038. goto dk_done
  3039. )
  3040. )
  3041. if %winbuild% LSS 9200 if exist "%SysPath%\wlms\wlms.exe" (
  3042. sc query wlms | find /i "RUNNING" %nul% && (
  3043. sc stop sppsvc %nul%
  3044. if !errorlevel! EQU 1051 (
  3045. %eline%
  3046. echo Evaluation WLMS service is running, sppsvc service can not be stopped. Aborting...
  3047. echo Install Non-Eval version for Windows build %winbuild%.
  3048. echo:
  3049. set fixes=%fixes% %mas%troubleshoot
  3050. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  3051. goto dk_done
  3052. )
  3053. )
  3054. )
  3055. ::========================================================================================================================================
  3056. if %_actwinesuoff%==1 (set "_actwin=1" & set "_actesu=1" & set "_actoff=1")
  3057. if %_actprojvis%==1 (set "_actoff=1")
  3058. set spp=SoftwareLicensingProduct
  3059. set sps=SoftwareLicensingService
  3060. call :dk_ckeckwmic
  3061. call :dk_checksku
  3062. call :dk_product
  3063. call :dk_sppissue
  3064. ::========================================================================================================================================
  3065. set error=
  3066. cls
  3067. echo:
  3068. call :dk_showosinfo
  3069. echo Initiating Diagnostic Tests...
  3070. set "_serv=sppsvc Winmgmt"
  3071. :: Software Protection
  3072. :: Windows Management Instrumentation
  3073. call :dk_errorcheck
  3074. if defined error (
  3075. call :dk_color %Red% "Some errors were detected. Aborting the operation..."
  3076. set fixes=%fixes% %mas%troubleshoot
  3077. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  3078. goto :dk_done
  3079. )
  3080. call :ts_getedition
  3081. if not defined tsedition (
  3082. call :dk_color %Red% "Checking Windows Edition ID [Not found in installed licenses, aborting...]"
  3083. set fixes=%fixes% %mas%troubleshoot
  3084. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  3085. goto :dk_done
  3086. )
  3087. ::========================================================================================================================================
  3088. if %_resall%==1 goto :ts_resetall
  3089. if %_actman%==1 goto :ts_actman
  3090. if %_actappx%==1 goto :ts_appxlob
  3091. if %_actwinhost%==1 goto :ts_whost
  3092. if %_actoffhost%==1 goto :ts_ohost
  3093. if not %_actwin%==1 goto :ts_esu
  3094. ::========================================================================================================================================
  3095. :: Process Windows
  3096. :: Check if system is permanently activated or not
  3097. echo:
  3098. echo Processing Windows...
  3099. echo %tsedition% | find /i "Eval" %nul1% && (
  3100. goto :ts_wineval
  3101. )
  3102. call :ts_checkwinperm
  3103. if defined _perm (
  3104. call :dk_color %Gray% "Checking OS Activation [Windows is already permanently activated]"
  3105. goto :ts_esu
  3106. )
  3107. set tempid=
  3108. set keytype=zero
  3109. for /f "delims=" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':wintsid\:.*';iex ($f[1])" %nul6%') do (
  3110. echo "%%a" | findstr /r ".*-.*-.*-.*-.*" %nul1% && (set tsids=!tsids! %%a& set tempid=%%a)
  3111. )
  3112. if defined tempid (
  3113. echo Checking Activation ID [%tempid%] [%tsedition%]
  3114. ) else (
  3115. call :dk_color %Red% "Checking Activation ID [Not Found] [%tsedition%] [%osSKU%]"
  3116. set error=1
  3117. goto :ts_esu
  3118. )
  3119. if defined winsub (
  3120. call :dk_color %Blue% "Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%]."
  3121. echo:
  3122. )
  3123. goto :ts_esu
  3124. ::========================================================================================================================================
  3125. :ts_wineval
  3126. call :dk_color %Gray% "Checking OS Edition [%tsedition%] [Evaluation edition found]"
  3127. call :dk_color %Blue% "Evaluation editions cannot be activated outside of evaluation period."
  3128. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
  3129. call :dk_color %Blue% "Script will reset evaluation period, but to permanently activate Windows,"
  3130. call :dk_color %Blue% "Go back to main menu and use [Change Edition] option and change to Non-eval edition."
  3131. ) else (
  3132. call :dk_color %Blue% "Script will reset evaluation period, but to permanently activate Windows, install Non-eval edition."
  3133. call :dk_color %_Yellow% "%mas%evaluation_editions"
  3134. )
  3135. :: Check Internet connection
  3136. set _int=
  3137. for %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (
  3138. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
  3139. )
  3140. if not defined _int (
  3141. %psc% "If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}"
  3142. if !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)
  3143. )
  3144. if defined _int (
  3145. echo Checking Internet Connection [Connected%ping_f%]
  3146. ) else (
  3147. set error=1
  3148. call :dk_color %Red% "Checking Internet Connection [Not Connected]"
  3149. call :dk_color %Blue% "Internet is required for Windows Evaluation activation."
  3150. )
  3151. :: List of products lacking activable evaluation keys and ISOs
  3152. :: c4b908d2-c4b9-439d-8ff0-48b656a24da4_EmbeddedIndustryEEval_8.1
  3153. :: 9b74255b-afe1-4da7-a143-98d1874b2a6c_EnterpriseNEval_8
  3154. :: 7fd0a88b-fb89-415f-9b79-84adc6a7cd56_EnterpriseNEval_8.1
  3155. :: 994578eb-193c-4c99-bea0-2483274c9afd_EnterpriseSNEval_2015
  3156. :: b9f3109c-bfa9-4f37-9824-6dba9ee62056_ServerStorageStandardEval_2012R2
  3157. :: 2d3b7269-65f4-467d-9d51-dbe0e5a4e668_ServerStorageWorkgroupEval_2012R2
  3158. :: --------
  3159. :: 1st column = Activation ID
  3160. :: 2nd column = Activable evaluation key
  3161. :: 3rd column = Edition ID
  3162. :: 4th column = Windows version (for reference only)
  3163. :: 5th column = NoAct = activation is not working
  3164. :: Separator = _
  3165. set f=
  3166. set key=
  3167. set eval=
  3168. if not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  3169. for %%# in (
  3170. d9eea459-1e6b-499d-8486-e68163f2a8be_N3QJR-YCWKK-RVJGK-GQFMX-T8%f%2BF_EmbeddedIndustryEval_8.1
  3171. fbd4c5c6-adc6-4740-bc65-b2dc6dc249c1_MJ8TN-42JH8-886MT-8THCF-36%f%67B_EnterpriseEval_8_NoAct_ REM New time based activation not available
  3172. 0eebbb45-29d4-49cb-ba87-a23db0cce40a_76FKW-8NR3K-QDH4P-3C87F-JH%f%TTW_EnterpriseEval_8.1
  3173. 3f4c0546-36c6-46a8-a37f-be13cdd0cf25_7HBDQ-QNKVG-K4RBF-HMBY6-YG%f%9R6_EnterpriseEval_10
  3174. 1f8dbfe8-defa-4676-b5a6-f76949a01540_4N8VT-7Y686-43DGV-THTW9-M9%f%8W7_EnterpriseNEval_10
  3175. 57a4ebb6-8e0c-41f8-b79e-8872ddc971ef_W63GF-7N4D9-GQH3K-K4FP7-9B%f%T6C_EnterpriseSEval_2015
  3176. b47dd250-fd6a-44c8-9217-03aca6e4812e_N4DMT-RJKDQ-XR6H7-3DKKP-3Y%f%JWT_EnterpriseSEval_2016
  3177. 267bf82d-08e8-4046-b061-9ef3f8ac2b5a_N7HMH-MK36Q-M4X93-76KQ2-6J%f%HWR_EnterpriseSEval_2019
  3178. aff25f1f-fb53-4e27-95ef-b8e5aca10ac6_9V4NK-624Y3-VK47R-Q27GP-27%f%PGF_EnterpriseSEval_2021
  3179. 399f0697-886b-4881-894c-4ff6c52e7d8f_CYPB3-XNV9V-QR4G4-Q3B8K-KQ%f%FGJ_EnterpriseSEval_2024
  3180. 6162e8c2-3c30-46e1-b964-0de603498e2d_R34N9-HJ6Q3-GBX4F-Q24KQ-49%f%DF7_EnterpriseSNEval_2016
  3181. aed14fc8-907d-44fb-a3a1-d5d8e638acb3_MHN9Q-RD9PW-BFHDQ-9FTWQ-WQ%f%PF8_EnterpriseSNEval_2019
  3182. 5dd0c869-eae9-40ce-af48-736692cd8e43_XCN62-29X92-C4T8X-WP82X-DY%f%MJ8_EnterpriseSNEval_2021
  3183. 522cc0dc-3c7b-4258-ae68-f297ca63b64e_Y8DJM-NPXF3-QG4MH-W7WJK-KQ%f%FGM_EnterpriseSNEval_2024
  3184. aa708397-8618-42de-b120-a44190ef456d_R63DV-9NPDX-QVWJF-HMR8V-M4%f%K7D_IoTEnterpriseSEval_2024
  3185. cd25b1e8-5839-4a96-a769-b6abe3aa5dee_73BMN-332G9-DX6B8-FGDT3-GF%f%YT6_ServerDatacenterEval_2012
  3186. e628c5e8-2300-4429-8b80-a8b21bd7ce0a_WPR94-KN3J7-MRB7X-JPJV8-RX%f%7J2_ServerDatacenterEval_2012R2
  3187. 01398239-85ff-487f-9e90-0e3cc5bcc92e_QVTQ9-GNRBH-JQ9G7-W7FBW-RX%f%9QR_ServerDatacenterEval_2016
  3188. 5ea4af9e-fd59-4691-b61c-1fc1ff3e309e_KNW3G-22YD2-7QKQJ-2RF2X-H6%f%F8M_ServerDatacenterEval_2019
  3189. 1d02774d-66ab-4c57-8b14-e254fdce09d4_PK7JN-24236-FH7JP-V792F-37%f%CYR_ServerDatacenterEval_2021
  3190. 96794a98-097f-42fe-8f28-2c38ea115229_M4RNW-CRTHF-TY7BG-DDHG6-J2%f%T92_ServerDatacenterEval_2025
  3191. 38d172c7-36b3-4e4b-b435-fd0b06b95c6e_RNFGD-WFFQR-XQ8BG-K7QQK-GJ%f%CP9_ServerStandardEval_2012
  3192. 4fc45a88-26b5-4cf9-9eef-769ee3f0a016_79M8M-N36BX-8YGJY-2G9KP-3Y%f%GPC_ServerStandardEval_2012R2
  3193. 9dfa8ec0-7665-4b9d-b2cb-bfc2dc37c9f4_9PBKX-4NHGT-QWV4C-4JD94-TV%f%KQ6_ServerStandardEval_2016
  3194. 7783a126-c108-4cf7-b59f-13c78c7a7337_J4WNC-H9BG3-6XRX4-3XD8K-Y7%f%XRX_ServerStandardEval_2019
  3195. c1a197b6-ba5e-4394-b9bf-b659a6c1b873_7PBJM-MNVPD-MBQD7-TYTY4-W8%f%JDY_ServerStandardEval_2021
  3196. 753c53a2-4274-4339-8c2e-f66c0b9646c5_YPBVM-HFNWQ-CTF9M-FR4RR-7H%f%9YG_ServerStandardEval_2025
  3197. 0de5ff31-2d62-4912-b1a8-3ea01d2461fd_3CKBN-3GJ8X-7YT4X-D8DDC-D6%f%69B_ServerStorageStandardEval_2012
  3198. fb08f53a-e597-40dc-9f08-8bbf99f19b92_NCJ6J-J23VR-DBYB3-QQBJF-W8%f%CP7_ServerStorageWorkgroupEval_2012
  3199. ) do (
  3200. for /f "tokens=1-5 delims=_" %%A in ("%%#") do if %tsedition%==%%C if not defined key (
  3201. echo "%allapps%" | find /i "%%A" %nul1% && (
  3202. set key=%%B
  3203. set eval=1
  3204. if /i "%%E"=="NoAct" set noact=1
  3205. echo Checking Activation ID [%%A] [%%C]
  3206. )
  3207. )
  3208. )
  3209. if not defined key (
  3210. set error=1
  3211. call :dk_color %Red% "Checking Activation ID [%tsedition% not found in the script]"
  3212. call :dk_color %Blue% "Make sure you are using the updated version of the script."
  3213. goto :ts_esu
  3214. )
  3215. set resetstuff=1
  3216. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':tsforge\:.*';iex ($f[1])"
  3217. set resetstuff=
  3218. if !errorlevel!==3 (
  3219. set error=1
  3220. call :dk_color %Red% "Resetting Rearm / GracePeriod [Failed]"
  3221. call :dk_color %Blue% "%_fixmsg%"
  3222. goto :ts_esu
  3223. ) else (
  3224. echo Resetting Rearm / GracePeriod [Successful]
  3225. )
  3226. %psc% "try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
  3227. set keyerror=%errorlevel%
  3228. cmd /c exit /b %keyerror%
  3229. if %keyerror% NEQ 0 set "keyerror=[0x%=ExitCode%]"
  3230. if %keyerror% EQU 0 (
  3231. call :dk_refresh
  3232. echo Installing Activable Evaluation Key [%key%] [Successful]
  3233. ) else (
  3234. set error=1
  3235. call :dk_color %Red% "Installing Activable Evaluation Key [%key%] [Failed] %keyerror%"
  3236. call :dk_color %Blue% "%_fixmsg%"
  3237. )
  3238. ::========================================================================================================================================
  3239. :ts_esu
  3240. if not %_actesu%==1 goto :ts_off
  3241. :: Process Windows ESU
  3242. echo:
  3243. echo Processing Windows ESU...
  3244. set esuexist=
  3245. set esuexistsup=
  3246. set esueditionlist=
  3247. set esuexistbutnosup=
  3248. for %%# in (EnterpriseS IoTEnterpriseS IoTEnterpriseSK) do (if /i %tsedition%==%%# set isltsc=1)
  3249. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" set isServer=1
  3250. if /i %tsedition%==Embedded (
  3251. if exist "%SystemRoot%\Servicing\Packages\WinEmb-Branding-Embedded-ThinPC-Package*.mum" set isThinpc=1
  3252. if exist "%SystemRoot%\Servicing\Packages\WinEmb-Branding-Embedded-POSReady7-Package*.mum" set subEdition=[POS]
  3253. if exist "%SystemRoot%\Servicing\Packages\WinEmb-Branding-Embedded-Standard-Package*.mum" set subEdition=[Standard]
  3254. )
  3255. if not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  3256. if not defined isThinpc if not defined isltsc for %%# in (
  3257. REM Windows7
  3258. 4220f546-f522-46df-8202-4d07afd26454_Client-ESU-Year3[1-3y]_-Enterprise-EnterpriseE-EnterpriseN-Professional-ProfessionalE-ProfessionalN-Ultimate-UltimateE-UltimateN-
  3259. 7e94be23-b161-4956-a682-146ab291774c_Client-ESU-Year6[4-6y]_-Enterprise-EnterpriseE-EnterpriseN-Professional-ProfessionalE-ProfessionalN-Ultimate-UltimateE-UltimateN-
  3260. REM Windows7EmbeddedPOSReady7
  3261. 4f1f646c-1e66-4908-acc7-d1606229b29e_POS-ESU-Year3[1-3y]_-Embedded[POS]-
  3262. REM Windows7EmbeddedStandard
  3263. 6aaf1c7d-527f-4ed5-b908-9fc039dfc654_WES-ESU-Year3[1-3y]_-Embedded[Standard]-
  3264. REM WindowsServer2008R2
  3265. 8e7bfb1e-acc1-4f56-abae-b80fce56cd4b_Server-ESU-PA[1-6y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-ServerEnterprise-ServerEnterpriseCore-ServerEnterpriseV-ServerEnterpriseVCore-
  3266. REM Windows8.1
  3267. 4afc620f-12a4-48ad-8015-2aebfbd6e47c_Client-ESU-Year3[1-3y]_-Enterprise-EnterpriseN-Professional-ProfessionalN-
  3268. 11be7019-a309-4763-9a09-091d1722ffe3_Client-FES-ESU-Year3[1-3y]_-EmbeddedIndustry-EmbeddedIndustryE-
  3269. REM WindowsServer2012/2012R2
  3270. 55b1dd2d-2209-4ea0-a805-06298bad25b3_Server-ESU-Year3[1-3y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-
  3271. REM Windows10
  3272. 83d49986-add3-41d7-ba33-87c7bfb5c0fb_Client-ESU-Year3[1-3y]_-Education-EducationN-Enterprise-EnterpriseN-Professional-ProfessionalEducation-ProfessionalEducationN-ProfessionalN-ProfessionalWorkstation-ProfessionalWorkstationN-
  3273. 0b533b5e-08b6-44f9-b885-c2de291ba456_Client-ESU-Year6[4-6y]_-Education-EducationN-Enterprise-EnterpriseN-Professional-ProfessionalEducation-ProfessionalEducationN-ProfessionalN-ProfessionalWorkstation-ProfessionalWorkstationN-
  3274. 4dac5a0c-5709-4595-a32c-14a56a4a6b31_Client-IoT-ESU-Year3[1-3y]_-IoTEnterprise- REM Removed IoTEnterpriseS because it already has longer support
  3275. f69e2d51-3bbd-4ddf-8da7-a145e9dca597_Client-IoT-ESU-Year6[4-6y]_-IoTEnterprise- REM Removed IoTEnterpriseS because it already has longer support
  3276. ) do (
  3277. for /f "tokens=1-3 delims=_" %%A in ("%%#") do (
  3278. echo "%allapps%" | find /i "%%A" %nul1% && (
  3279. set esuexist=1
  3280. echo "%%C" | find /i "-%tsedition%%subEdition%-" %nul1% && (
  3281. set esuexistsup=1
  3282. set esueditionlist=
  3283. set esuexistbutnosup=
  3284. set tsids=!tsids! %%A
  3285. echo Checking Activation ID [%%A] [%%B]
  3286. ) || (
  3287. if not defined esueditionlist set esueditionlist=%%C
  3288. set esuexistbutnosup=1
  3289. )
  3290. )
  3291. )
  3292. )
  3293. if defined esuexistsup (
  3294. echo "%tsids%" | find /i "4220f546-f522-46df-8202-4d07afd26454" %nul1% && (
  3295. echo "%tsids%" | find /i "7e94be23-b161-4956-a682-146ab291774c" %nul1% || (
  3296. call :dk_color %Gray% "Now update Windows to get Client-ESU-Year6[4-6y] license and activate that using this script."
  3297. )
  3298. )
  3299. goto :ts_off
  3300. )
  3301. if defined isltsc (
  3302. call :dk_color %Gray% "Checking Activation ID [%tsedition% LTSC already has longer support, ESU is not applicable]"
  3303. goto :ts_off
  3304. )
  3305. if defined esuexistbutnosup (
  3306. call :dk_color %Red% "Checking Activation ID [Commercial ESU is not supported for %tsedition%]"
  3307. call :dk_color %Blue% "Go back to Main Menu, select Change Windows Edition option and change to any of the below listed editions."
  3308. echo [%esueditionlist%]
  3309. goto :ts_off
  3310. )
  3311. set esuavail=
  3312. if %winbuild% LEQ 7602 if not defined isThinpc set esuavail=1
  3313. if %winbuild% GTR 7602 if %winbuild% LSS 10240 if defined isServer set esuavail=1
  3314. if %winbuild% GEQ 10240 if %winbuild% LEQ 19045 if not defined isServer set esuavail=1
  3315. if %winbuild% EQU 9600 set esuavail=1
  3316. if defined esuavail (
  3317. call :dk_color %Red% "Checking Activation ID [ESU license is not found, make sure Windows is fully updated]"
  3318. set fixes=%fixes% %mas%tsforge#windows-esu
  3319. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%tsforge#windows-esu"
  3320. ) else (
  3321. call :dk_color %Gray% "Checking Activation ID [ESU is not available for %winos%]"
  3322. )
  3323. ::========================================================================================================================================
  3324. :ts_off
  3325. if not %_actoff%==1 goto :ts_act
  3326. if %winbuild% LSS 9200 (
  3327. echo:
  3328. call :dk_color %Gray% "Checking Supported Office [TSforge for Office is supported on Windows 8 and later versions]"
  3329. call :dk_color %Blue% "On Windows 7 build, use Online %KS% activation option for Office instead."
  3330. goto :ts_act
  3331. )
  3332. :: Check ohook install
  3333. set ohook=
  3334. for %%# in (15 16) do (
  3335. for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do (
  3336. if exist "%%~A\Microsoft Office\Office%%#\sppc*dll" set ohook=1
  3337. )
  3338. )
  3339. for %%# in (System SystemX86) do (
  3340. for %%G in ("Office 15" "Office") do (
  3341. for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do (
  3342. if exist "%%~A\Microsoft %%~G\root\vfs\%%#\sppc*dll" set ohook=1
  3343. )
  3344. )
  3345. )
  3346. if defined ohook (
  3347. echo:
  3348. call :dk_color %Gray% "Checking Ohook [Ohook activation is already installed for Office]"
  3349. )
  3350. :: Check unsupported office versions
  3351. set o14msi=
  3352. set o14c2r=
  3353. set _68=HKLM\SOFTWARE\Microsoft\Office
  3354. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  3355. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o14msi=Office 2010 MSI )
  3356. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o14msi=Office 2010 MSI )
  3357. %nul% reg query %_68%\14.0\CVH /f Click2run /k && set o14c2r=Office 2010 C2R
  3358. %nul% reg query %_86%\14.0\CVH /f Click2run /k && set o14c2r=Office 2010 C2R
  3359. if not "%o14msi%%o14c2r%"=="" (
  3360. echo:
  3361. call :dk_color %Red% "Checking Unsupported Office Install [ %o14msi%%o14c2r%]"
  3362. )
  3363. if %winbuild% GEQ 10240 %psc% "Get-AppxPackage -name "Microsoft.MicrosoftOfficeHub"" | find /i "Office" %nul1% && (
  3364. set ohub=1
  3365. )
  3366. ::========================================================================================================================================
  3367. :: Check supported office versions
  3368. call :ts_getpath
  3369. set o16uwp=
  3370. set o16uwp_path=
  3371. if %winbuild% GEQ 10240 (
  3372. for /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"))
  3373. )
  3374. sc query ClickToRunSvc %nul%
  3375. set error1=%errorlevel%
  3376. if defined o16c2r if %error1% EQU 1060 (
  3377. echo:
  3378. call :dk_color %Red% "Checking ClickToRun Service [Not found, Office 16.0 files found]"
  3379. set o16c2r=
  3380. set error=1
  3381. )
  3382. sc query OfficeSvc %nul%
  3383. set error2=%errorlevel%
  3384. if defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (
  3385. echo:
  3386. call :dk_color %Red% "Checking ClickToRun Service [Not found, Office 15.0 files found]"
  3387. set o15c2r=
  3388. set error=1
  3389. )
  3390. if "%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%"=="" (
  3391. set error=1
  3392. set showfix=1
  3393. echo:
  3394. if not "%o14msi%%o14c2r%"=="" (
  3395. call :dk_color %Red% "Checking Supported Office Install [Not Found]"
  3396. ) else (
  3397. if %_actwin%==0 (
  3398. call :dk_color %Red% "Checking Installed Office [Not Found]"
  3399. ) else (
  3400. call :dk_color %Gray% "Checking Installed Office [Not Found]"
  3401. )
  3402. )
  3403. if defined ohub (
  3404. echo:
  3405. echo You have only Office dashboard app installed, you need to install full Office version.
  3406. )
  3407. call :dk_color %Blue% "Download and install Office from below URL and try again."
  3408. if %_actwin%==0 set fixes=%fixes% %mas%genuine-installation-media
  3409. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  3410. goto :ts_act
  3411. )
  3412. set multioffice=
  3413. if not "%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%"=="1" set multioffice=1
  3414. if not "%o14c2r%%o14msi%"=="" set multioffice=1
  3415. if defined multioffice (
  3416. echo:
  3417. call :dk_color %Gray% "Checking Multiple Office Install [Found. Recommended to install one version only]"
  3418. )
  3419. ::========================================================================================================================================
  3420. :: Check Windows Server
  3421. set winserver=
  3422. reg query "HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" /v ProductType %nul2% | find /i "WinNT" %nul1% || set winserver=1
  3423. if not defined winserver (
  3424. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Server" %nul1% && set winserver=1
  3425. )
  3426. ::========================================================================================================================================
  3427. :: Process Office UWP
  3428. if not defined o16uwp goto :ts_starto15c2r
  3429. call :ts_reset
  3430. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  3431. set oVer=16
  3432. set "_oLPath=%o16uwp_path%\Licenses16"
  3433. set "pkeypath=%o16uwp_path%\Office16\pkeyconfig-office.xrm-ms"
  3434. for /f "delims=" %%a in ('%psc% "(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty Dependencies) | Select-Object PackageFullName" %nul6%') do (set "o16uwpapplist=!o16uwpapplist! %%a")
  3435. echo "%o16uwpapplist%" | findstr /i "Access Excel OneNote Outlook PowerPoint Publisher SkypeForBusiness Word" %nul% && set "_oIds=O365HomePremRetail"
  3436. for %%# in (Project Visio) do (
  3437. echo "%o16uwpapplist%" | findstr /i "%%#" %nul% && (
  3438. set _lat=
  3439. if exist "%_oLPath%\%%#Pro2024VL*.xrm-ms" set "_oIds= !_oIds! %%#Pro2024Retail " & set _lat=1
  3440. if not defined _lat if exist "%_oLPath%\%%#Pro2021VL*.xrm-ms" set "_oIds= !_oIds! %%#Pro2021Retail " & set _lat=1
  3441. if not defined _lat if exist "%_oLPath%\%%#Pro2019VL*.xrm-ms" set "_oIds= !_oIds! %%#Pro2019Retail " & set _lat=1
  3442. if not defined _lat set "_oIds= !_oIds! %%#ProRetail "
  3443. )
  3444. )
  3445. set uwpinfo=%o16uwp_path:C:\Program Files\WindowsApps\Microsoft.Office.Desktop_=%
  3446. echo:
  3447. echo Processing Office... [UWP ^| %uwpinfo%]
  3448. if not defined _oIds (
  3449. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  3450. set error=1
  3451. goto :ts_starto15c2r
  3452. )
  3453. call :ts_process
  3454. ::========================================================================================================================================
  3455. :ts_starto15c2r
  3456. :: Process Office 15.0 C2R
  3457. if not defined o15c2r goto :ts_starto16c2r
  3458. call :ts_reset
  3459. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  3460. set oVer=15
  3461. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  3462. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  3463. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  3464. for /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")
  3465. if not defined _oArch for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v Platform" %nul6%') do (set "_oArch=%%b")
  3466. if not defined _version for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v version" %nul6%') do (set "_version=%%b")
  3467. if 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")
  3468. echo "%o15c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=10) || (set _tok=9)
  3469. for /f "tokens=%_tok% delims=\" %%a in ('reg query %o15c2r_reg%\ProductReleaseIDs\Active %nul6% ^| findstr /i "Retail Volume"') do (
  3470. echo "!_oIds!" | find /i " %%a " %nul1% || (set "_oIds= !_oIds! %%a ")
  3471. )
  3472. set "_oLPath=%_oRoot%\Licenses"
  3473. set "pkeypath=%_oRoot%\Office15\pkeyconfig-office.xrm-ms"
  3474. set "_oIntegrator=%_oRoot%\integration\integrator.exe"
  3475. echo:
  3476. echo Processing Office... [C2R ^| %_version% ^| %_oArch%]
  3477. if not defined _oIds (
  3478. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  3479. set error=1
  3480. goto :ts_starto16c2r
  3481. )
  3482. if "%_actprojvis%"=="0" call :oh_fixprids
  3483. call :ts_process
  3484. ::========================================================================================================================================
  3485. :ts_starto16c2r
  3486. :: Process Office 16.0 C2R
  3487. if not defined o16c2r goto :ts_startmsi
  3488. call :ts_reset
  3489. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  3490. set oVer=16
  3491. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  3492. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  3493. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  3494. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v AudienceData" %nul6%') do (set "_AudienceData=^| %%b ")
  3495. for /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")
  3496. echo "%o16c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=9) || (set _tok=8)
  3497. for /f "tokens=%_tok% delims=\" %%a in ('reg query "%o16c2r_reg%\ProductReleaseIDs" /s /f ".16" /k %nul6% ^| findstr /i "Retail Volume"') do (
  3498. echo "!_oIds!" | find /i " %%a " %nul1% || (set "_oIds= !_oIds! %%a ")
  3499. )
  3500. set _oIds=%_oIds:.16=%
  3501. set _o16c2rIds=%_oIds%
  3502. set "_oLPath=%_oRoot%\Licenses16"
  3503. set "pkeypath=%_oRoot%\Office16\pkeyconfig-office.xrm-ms"
  3504. set "_oIntegrator=%_oRoot%\integration\integrator.exe"
  3505. echo:
  3506. echo Processing Office... [C2R ^| %_version% %_AudienceData%^| %_oArch%]
  3507. if not defined _oIds (
  3508. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  3509. set error=1
  3510. goto :ts_startmsi
  3511. )
  3512. if "%_actprojvis%"=="0" call :oh_fixprids
  3513. call :ts_process
  3514. ::========================================================================================================================================
  3515. :ts_startmsi
  3516. if defined o15msi call :ts_processmsi 15 %o15msi_reg%
  3517. if defined o16msi call :ts_processmsi 16 %o16msi_reg%
  3518. ::========================================================================================================================================
  3519. echo:
  3520. call :oh_clearblock
  3521. if "%o16msi%%o15msi%"=="" if not "%o16uwp%%o16c2r%%o15c2r%"=="" call :oh_uninstkey
  3522. call :oh_licrefresh
  3523. goto :ts_act
  3524. ::========================================================================================================================================
  3525. :ts_whost
  3526. :: Process Windows K-M-S host
  3527. echo:
  3528. echo Processing Windows %KS% Host...
  3529. echo:
  3530. if %winbuild% GEQ 10586 (
  3531. call :dk_color %Gray% "With %KS% Host license, system may randomly change Windows Edition later. It is a Windows issue and can be safely ignored."
  3532. )
  3533. call :dk_color %Gray% "%KS% Host [Not to be confused with %KS% Client] license causes the sppsvc service to run continuously."
  3534. call :dk_color %Blue% "Only use this activation when necessary, you can revert to normal activation from the previous menu."
  3535. if %_unattended%==0 (
  3536. echo:
  3537. choice /C:0F /N /M "> [0] Go back [F] Continue : "
  3538. if !errorlevel!==1 exit /b
  3539. echo:
  3540. )
  3541. set _arr=
  3542. set tempid=
  3543. set keytype=kmshost
  3544. :: Install current edition csvlk license so that correct edition can reflect for csvlk
  3545. if %winbuild% GEQ 10586 (
  3546. for %%# in ("%SysPath%\spp\tokens\skus\%tsedition%\*CSVLK*.xrm-ms") do (
  3547. if defined _arr (set "_arr=!_arr!;"%SysPath%\spp\tokens\skus\%tsedition%\%%~nx#"") else (set "_arr="%SysPath%\spp\tokens\skus\%tsedition%\%%~nx#"")
  3548. )
  3549. if defined _arr %psc% "$sls = Get-WmiObject %sps%; $f=[io.file]::ReadAllText('!_batp!') -split ':xrm\:.*';iex ($f[1]); InstallLicenseArr '!_arr!'" %nul%
  3550. )
  3551. for /f "delims=" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':wintsid\:.*';iex ($f[1])" %nul6%') do (
  3552. echo "%%a" | findstr /r ".*-.*-.*-.*-.*" %nul1% && (set tsids=!tsids! %%a& set tempid=%%a)
  3553. )
  3554. if defined tempid (
  3555. echo Checking Activation ID [%tempid%] [%tsedition%]
  3556. ) else (
  3557. call :dk_color %Red% "Checking Activation ID [Not Found] [%tsedition%] [%osSKU%]"
  3558. call :dk_color %Blue% "%KS% Host license is not found on your system. It is available for the below editions."
  3559. call :dk_color %Blue% "Professional, Education, ProfessionalWorkstation, Enterprise, EnterpriseS, and Server editions, etc."
  3560. goto :ts_act
  3561. )
  3562. if defined winsub (
  3563. echo:
  3564. call :dk_color %Blue% "Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%]."
  3565. )
  3566. goto :ts_act
  3567. ::========================================================================================================================================
  3568. :ts_ohost
  3569. :: Process Office K-M-S host
  3570. echo:
  3571. echo Processing Office %KS% Host...
  3572. set ohostexist=
  3573. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  3574. set ohostids=%allapps%
  3575. call :dk_actids 59a52881-a989-479d-af46-f275c6370663
  3576. set ohostids=%ohostids% %allapps%
  3577. for %%# in (
  3578. bfe7a195-4f8f-4f0b-a622-cf13c7d16864_KMSHost2010-ProPlusVL
  3579. f3d89bbf-c0ec-47ce-a8fa-e5a5f97e447f_KMSHost2024Volume
  3580. 47f3b983-7c53-4d45-abc6-bcd91e2dd90a_KMSHost2021Volume
  3581. 70512334-47b4-44db-a233-be5ea33b914c_KMSHost2019Volume
  3582. 98ebfe73-2084-4c97-932c-c0cd1643bea7_KMSHost2016Volume
  3583. 2e28138a-847f-42bc-9752-61b03fff33cd_KMSHost2013Volume
  3584. ) do (
  3585. for /f "tokens=1-2 delims=_" %%A in ("%%#") do (
  3586. echo "%ohostids%" | find /i "%%A" %nul1% && (
  3587. set ohostexist=1
  3588. set tsids=!tsids! %%A
  3589. echo Checking Activation ID [%%A] [%%B]
  3590. )
  3591. )
  3592. )
  3593. if not defined ohostexist (
  3594. call :dk_color %Gray% "Checking Activation ID [Not found for Office %KS% Host]"
  3595. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%tsforge#office-kms-host"
  3596. )
  3597. echo:
  3598. call :dk_color %Gray% "%KS% Host [Not to be confused with %KS% Client] license causes the sppsvc service to run continuously."
  3599. call :dk_color %Gray% "Only use this activation when necessary."
  3600. goto :ts_act
  3601. ::========================================================================================================================================
  3602. :ts_appxlob
  3603. :: Process Windows 8/8.1 APPX Sideloading
  3604. echo:
  3605. echo Processing Windows 8/8.1 APPX Sideloading...
  3606. if %winbuild% LSS 9200 set noappx=1
  3607. if %winbuild% GTR 9600 set noappx=1
  3608. echo:
  3609. if defined noappx (
  3610. call :dk_color %Gray% "Checking Activation ID [APPX Sideloading feature is available only on Windows 8/8.1]"
  3611. goto :dk_done
  3612. )
  3613. set appxexist=
  3614. if not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  3615. for %%# in (
  3616. ec67814b-30e6-4a50-bf7b-d55daf729d1e_APPXLOB-Client
  3617. 251ef9bf-2005-442f-94c4-86307de7bb32_APPXLOB-Embedded-Industry
  3618. 1e58c9d7-e3f1-4f69-9039-1f162463ac2c_APPXLOB-Embedded-Standard
  3619. 3502d53e-5d43-436a-84af-714e8d334f8d_APPXLOB-Server
  3620. ) do (
  3621. for /f "tokens=1-2 delims=_" %%A in ("%%#") do (
  3622. echo "%allapps%" | find /i "%%A" %nul1% && (
  3623. set appxexist=1
  3624. set tsids=!tsids! %%A
  3625. echo Checking Activation ID [%%A] [%%B]
  3626. )
  3627. )
  3628. )
  3629. if not defined appxexist (
  3630. call :dk_color %Red% "Checking Activation ID [Not found]"
  3631. call :dk_color %Blue% "APPX Sideloading feature is available only on Pro and higher level editions."
  3632. )
  3633. goto :ts_act
  3634. ::========================================================================================================================================
  3635. :ts_resetall
  3636. echo:
  3637. echo Processing Reset of Rearm / Timers / Tamper / Lock...
  3638. echo:
  3639. set resetstuff=1
  3640. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':tsforge\:.*';iex ($f[1])"
  3641. if %errorlevel%==3 (
  3642. call :dk_color %Red% "Reset Failed."
  3643. set fixes=%fixes% %mas%troubleshoot
  3644. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  3645. ) else (
  3646. call :dk_color %Green% "Reset process has been successfully done."
  3647. )
  3648. goto :dk_done
  3649. ::========================================================================================================================================
  3650. :ts_actman
  3651. echo:
  3652. echo Processing Manual Activation...
  3653. echo:
  3654. call :dk_color %Gray% "This option is for advanced users, those who already know what they are doing."
  3655. call :dk_color %Blue% "Some activation IDs may cause system crash [MUI mismatch], or irreversible changes [CloudEdition etc]."
  3656. if %_unattended%==1 (
  3657. echo:
  3658. for %%# in (%tsids%) do (echo Activation ID - %%#)
  3659. goto :ts_act
  3660. )
  3661. call :dk_color %Blue% "Although the script will try to remove those IDs from the list, it is not fully guaranteed."
  3662. echo:
  3663. choice /C:0F /N /M "> [0] Go back [F] Continue : "
  3664. if %errorlevel%==1 exit /b
  3665. echo:
  3666. echo Fetching Supported Activation IDs list. Please wait...
  3667. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':listactids\:.*';iex ($f[1])"
  3668. if %errorlevel%==3 (
  3669. call :dk_color %Gray% "No supported activation ID found, aborting..."
  3670. goto :dk_done
  3671. )
  3672. for /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! "
  3673. echo:
  3674. call :dk_color %Gray% "Enter / Paste the Activation ID shown in first column in the opened text file, or just press Enter to return:"
  3675. echo Add space after each Activation ID if you are adding multiple:
  3676. echo:
  3677. set /p tsids=
  3678. del /f /q "%SystemRoot%\Temp\actids_159_*" %nul%
  3679. if not defined tsids goto :dk_done
  3680. for %%# in (%tsids%) do (
  3681. echo "%allactids%" | find /i " %%# " %nul1% || (
  3682. call :dk_color %Red% "[%%#] Incorrect Activation ID entered, aborting..."
  3683. goto :dk_done
  3684. )
  3685. )
  3686. goto :ts_act
  3687. :listactids:
  3688. $t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)
  3689. $t.DefinePInvokeMethod('SLOpen', 'slc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  3690. $t.DefinePInvokeMethod('SLClose', 'slc.dll', 22, 1, [IntPtr], @([IntPtr]), 1, 3).SetImplementationFlags(128)
  3691. $t.DefinePInvokeMethod('SLGetProductSkuInformation', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  3692. $t.DefinePInvokeMethod('SLGetLicense', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  3693. $w = $t.CreateType()
  3694. $m = [Runtime.InteropServices.Marshal]
  3695. function slGetSkuInfo($SkuId) {
  3696. $c = 0; $b = 0
  3697. $r = $w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, "msft:sl/EUL/PHONE/PUBLIC", [ref]$null, [ref]$c, [ref]$b)
  3698. return ($r -eq 0)
  3699. }
  3700. function IsMuiNotLocked($SkuId) {
  3701. $r = $true; $c = 0; $b = 0
  3702. $LicId = [Guid]::Empty
  3703. [void]$w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, "fileId", [ref]$null, [ref]$c, [ref]$b)
  3704. $FileId = $m::PtrToStringUni($b)
  3705. $c = 0; $b = 0
  3706. [void]$w::SLGetLicense($hSLC, [ref][Guid]$FileId, [ref]$c, [ref]$b)
  3707. $blob = New-Object byte[] $c; $m::Copy($b, $blob, 0, $c)
  3708. $cont = [Text.Encoding]::UTF8.GetString($blob)
  3709. $xml = [xml]$cont.SubString($cont.IndexOf('<r'))
  3710. $xml.licenseGroup.license[0].grant | foreach {
  3711. $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Kernel-MUI-Language-Allowed' } | foreach {
  3712. if ($_.InnerText -ne 'EMPTY') { $r = $false }
  3713. }
  3714. }
  3715. return $r
  3716. }
  3717. $hSLC = 0; [void]$w::SLOpen([ref]$hSLC)
  3718. $results = Get-WmiObject -Query "SELECT ID, Name, Description FROM SoftwareLicensingProduct"
  3719. $maxNameWidth = 60
  3720. $filteredResults = $results | Where-Object {
  3721. if ($env:tsedition -like "*CountrySpecific*") {
  3722. $true
  3723. }
  3724. else {
  3725. $_.Name -notlike "*CountrySpecific*"
  3726. }
  3727. } | Where-Object {
  3728. if ($env:tsedition -like "*CloudEdition*") {
  3729. $true
  3730. }
  3731. else {
  3732. $_.Name -notlike "*CloudEdition*"
  3733. }
  3734. } | Where-Object {
  3735. $_.Name -like "*CountrySpecific*" -or (IsMuiNotLocked $_.ID)
  3736. } | Where-Object {
  3737. slGetSkuInfo $_.ID
  3738. } | ForEach-Object {
  3739. "$($_.ID)`t$($_.Name.PadRight($maxNameWidth))`t$($_.Description)"
  3740. }
  3741. [void]$w::SLClose($hSLC)
  3742. if (-not $filteredResults) {
  3743. Exit 3
  3744. }
  3745. $sortedResults = $filteredResults | Sort-Object { $_.Split("`t")[1].Trim() }
  3746. $output = $sortedResults -join "`r`n"
  3747. $newGuid = [Guid]::NewGuid().Guid
  3748. $filename = "$env:SystemRoot\Temp\actids_159_$newGuid.txt"
  3749. $output | Set-Content -Path $filename -Encoding ASCII
  3750. Start-Process notepad.exe $filename
  3751. :listactids:
  3752. ::========================================================================================================================================
  3753. :ts_act
  3754. if defined eval (
  3755. echo:
  3756. echo Activating...
  3757. echo:
  3758. call :dk_act
  3759. set gpr=0
  3760. set gprdays=0
  3761. set actdone=
  3762. for /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"
  3763. set /a "gprdays=(!gpr!+1440-1)/1440"
  3764. if !gprdays! EQU 90 set actdone=1
  3765. if !gprdays! EQU 180 set actdone=1
  3766. if defined actdone (
  3767. call :dk_color %Green% "[%winos%] has been reset and activated successfully for !gprdays! days."
  3768. ) else (
  3769. set error=1
  3770. set showfix=1
  3771. call :dk_color %Red% "[%winos%] Activation Failed %error_code%. Remaining Period: !gprdays! days [!gpr! minutes]."
  3772. if not defined noact (
  3773. call :dk_color %Gray% "To activate, check your internet connection and ensure the date and time are correct."
  3774. ) else (
  3775. call :dk_color %Blue% "This Windows version is known to not activate due to MS Windows/Server issues."
  3776. )
  3777. set fixes=%fixes% %mas%troubleshoot
  3778. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  3779. )
  3780. )
  3781. if defined tsids (
  3782. echo:
  3783. echo Installing Forged Product Key Data...
  3784. echo Depositing Zero Confirmation ID...
  3785. echo:
  3786. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':tsforge\:.*';& ([ScriptBlock]::Create($f[1])) %tsids%"
  3787. if !errorlevel!==3 (
  3788. if %_actman%==0 call :dk_color %Blue% "%_fixmsg%"
  3789. set fixes=%fixes% %mas%troubleshoot
  3790. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  3791. ) else (
  3792. echo "%tsids%" | find /i "7e94be23-b161-4956-a682-146ab291774c" %nul1% && (
  3793. call :dk_color %Gray% "Windows Update can receive 1-3 years of ESU. 4-6 year ESU is not officially supported, but you can manually install updates."
  3794. )
  3795. echo "%tsids%" | findstr /i "4afc620f-12a4-48ad-8015-2aebfbd6e47c 11be7019-a309-4763-9a09-091d1722ffe3" %nul1% && (
  3796. call :dk_color %Gray% "ESU is not officially supported on Windows 8.1, but you can manually install updates until Jan-2024."
  3797. )
  3798. echo "%tsids%" | findstr /i "0b533b5e-08b6-44f9-b885-c2de291ba456 f69e2d51-3bbd-4ddf-8da7-a145e9dca597" %nul1% && (
  3799. call :dk_color %Gray% "Windows Update can receive 1-3 years of ESU. 4-6 year ESU license is added just as a placeholder."
  3800. )
  3801. )
  3802. if %_actwin%==1 for %%# in (407) do if %osSKU%==%%# (
  3803. call :dk_color %Red% "%winos% does not support activation on non-azure platforms."
  3804. )
  3805. if %_actoff%==1 if not defined error if defined ohub (
  3806. echo:
  3807. call :dk_color %Gray% "Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app."
  3808. )
  3809. REM Trigger reevaluation of SPP's Scheduled Tasks
  3810. call :dk_reeval %nul%
  3811. )
  3812. if not defined tsids if defined error if not defined showfix (
  3813. set fixes=%fixes% %mas%troubleshoot
  3814. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  3815. )
  3816. goto :dk_done
  3817. ::========================================================================================================================================
  3818. :ts_remove
  3819. cls
  3820. if not defined terminal (
  3821. mode 100, 30
  3822. )
  3823. title Remove TSforge Activation %masver%
  3824. echo:
  3825. echo TSforge activation doesn't modify any Windows component.
  3826. echo TSforge activation doesn't install any new file in the system.
  3827. echo:
  3828. echo Instead, it appends data to one of data files used by Software Protection Platform.
  3829. echo:
  3830. call :dk_color %Gray% "If you want to reset the activation status,"
  3831. call :dk_color %Blue% "%_fixmsg%"
  3832. echo:
  3833. goto :dk_done
  3834. ::========================================================================================================================================
  3835. :ts_reset
  3836. set key=
  3837. set _oRoot=
  3838. set _oArch=
  3839. set _oIds=
  3840. set _oLPath=
  3841. set _actid=
  3842. set _prod=
  3843. set _lic=
  3844. set _arr=
  3845. set _prids=
  3846. set _config=
  3847. set _version=
  3848. set _License=
  3849. set _oBranding=
  3850. exit /b
  3851. ::========================================================================================================================================
  3852. :ts_getpath
  3853. set o16c2r=
  3854. set o15c2r=
  3855. set o16msi=
  3856. set o15msi=
  3857. set _68=HKLM\SOFTWARE\Microsoft\Office
  3858. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  3859. for /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)
  3860. for /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)
  3861. for /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)
  3862. for /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)
  3863. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o16msi=1&set o16msi_reg=%_86%\16.0)
  3864. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o16msi=1&set o16msi_reg=%_68%\16.0)
  3865. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o15msi=1&set o15msi_reg=%_86%\15.0)
  3866. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o15msi=1&set o15msi_reg=%_68%\15.0)
  3867. exit /b
  3868. ::========================================================================================================================================
  3869. :ts_process
  3870. if not exist "%pkeypath%" (
  3871. call :dk_color %Red% "Checking pkeyconfig-office.xrm-ms [Not found. Aborting activation...]"
  3872. set error=1
  3873. exit /b
  3874. )
  3875. for %%# in (%_oIds%) do (
  3876. set _actid=
  3877. set _preview=
  3878. set _License=%%#
  3879. set skipprocess=
  3880. if "%_actprojvis%"=="1" (
  3881. echo %%# | findstr /i "Project Visio" %nul% || (
  3882. set skipprocess=1
  3883. call :dk_color %Gray% "Skipping Because Project/Visio Mode [%%#]"
  3884. )
  3885. )
  3886. if not defined skipprocess (
  3887. echo %%# | findstr /i "O365" %nul% && (
  3888. set _License=MondoRetail
  3889. set _altoffid=MondoRetail
  3890. call :ks_osppready
  3891. echo Converting Unsupported O365 Office [%%# To MondoRetail]
  3892. )
  3893. set keytype=zero
  3894. for /f "delims=" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':offtsid\:.*';iex ($f[1])" %nul6%') do (
  3895. echo "%%a" | findstr /r ".*-.*-.*-.*-.*" %nul1% && (set tsids=!tsids! %%a& set _actid=%%a)
  3896. )
  3897. set "_allactid=!tsids!"
  3898. if defined _actid (
  3899. echo Checking Activation ID [!_actid!] [!_License!]
  3900. ) else (
  3901. call :dk_color %Red% "Checking Activation ID [Office %oVer%.0 !_License! not found]"
  3902. set error=1
  3903. set showfix=1
  3904. set fixes=%fixes% %mas%troubleshoot
  3905. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  3906. )
  3907. echo %%# | find /i "2024" %nul% && (
  3908. if exist "!_oLPath!\ProPlus2024PreviewVL_*.xrm-ms" if not exist "!_oLPath!\ProPlus2024VL_*.xrm-ms" set _preview=1
  3909. )
  3910. if defined _actid (
  3911. echo "!allapps!" | find /i "!_actid!" %nul1% || call :oh_installlic
  3912. )
  3913. )
  3914. )
  3915. :: Add SharedComputerLicensing registry key if Retail Office C2R is installed on Windows Server
  3916. :: https://learn.microsoft.com/en-us/office/troubleshoot/office-suite-issues/click-to-run-office-on-terminal-server
  3917. if defined winserver if defined _config (
  3918. echo %_oIds% | find /i "Retail" %nul1% && (
  3919. set scaIsNeeded=1
  3920. reg add %_config% /v SharedComputerLicensing /t REG_SZ /d "1" /f %nul1%
  3921. echo Adding SharedComputerLicensing Reg [Successful] [Needed on Server With Retail Office]"
  3922. )
  3923. )
  3924. exit /b
  3925. ::========================================================================================================================================
  3926. :ts_processmsi
  3927. :: Process Office MSI Version
  3928. call :ts_reset
  3929. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  3930. set oVer=%1
  3931. for /f "skip=2 tokens=2*" %%a in ('"reg query %2\Common\InstallRoot /v Path" %nul6%') do (set "_oRoot=%%b")
  3932. for /f "skip=2 tokens=2*" %%a in ('"reg query %2\Common\ProductVersion /v LastProduct" %nul6%') do (set "_version=%%b")
  3933. if "%_oRoot:~-1%"=="\" set "_oRoot=%_oRoot:~0,-1%"
  3934. echo "%2" | find /i "Wow6432Node" %nul1% && set _oArch=x86
  3935. if not "%osarch%"=="x86" if not defined _oArch set _oArch=x64
  3936. if "%osarch%"=="x86" set _oArch=x86
  3937. set "_common=%CommonProgramFiles%"
  3938. if defined PROCESSOR_ARCHITEW6432 set "_common=%CommonProgramW6432%"
  3939. set "_common2=%CommonProgramFiles(x86)%"
  3940. for /r "%_common%\Microsoft Shared\OFFICE%oVer%\" %%f in (BRANDING.XML) do if exist "%%f" set "_oBranding=%%f"
  3941. if not defined _oBranding for /r "%_common2%\Microsoft Shared\OFFICE%oVer%\" %%f in (BRANDING.XML) do if exist "%%f" set "_oBranding=%%f"
  3942. if exist "%_common%\Microsoft Shared\OFFICE%oVer%\Office Setup Controller\pkeyconfig-office.xrm-ms" (
  3943. set "pkeypath=%_common%\Microsoft Shared\OFFICE%oVer%\Office Setup Controller\pkeyconfig-office.xrm-ms"
  3944. ) else if exist "%_common2%\Microsoft Shared\OFFICE%oVer%\Office Setup Controller\pkeyconfig-office.xrm-ms" (
  3945. set "pkeypath=%_common2%\Microsoft Shared\OFFICE%oVer%\Office Setup Controller\pkeyconfig-office.xrm-ms"
  3946. )
  3947. call :ts_msiofficedata %2
  3948. echo:
  3949. echo Processing Office... [MSI ^| %_version% ^| %_oArch%]
  3950. if not defined _oBranding (
  3951. set error=1
  3952. call :dk_color %Red% "Checking BRANDING.XML [Not Found. Aborting activation...]"
  3953. exit /b
  3954. )
  3955. if not defined _oIds (
  3956. set error=1
  3957. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  3958. exit /b
  3959. )
  3960. call :ts_process
  3961. exit /b
  3962. ::========================================================================================================================================
  3963. :: Get Windows permanent activation status (not counting csvlk)
  3964. :ts_checkwinperm
  3965. %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=
  3966. exit /b
  3967. ::========================================================================================================================================
  3968. :tsforge:
  3969. $src = @'
  3970. // Common.cs
  3971. namespace LibTSforge
  3972. {
  3973. using Microsoft.Win32;
  3974. using System;
  3975. using System.IO;
  3976. using System.Linq;
  3977. using System.Runtime.InteropServices;
  3978. using System.ServiceProcess;
  3979. using System.Text;
  3980. using LibTSforge.Crypto;
  3981. using LibTSforge.PhysicalStore;
  3982. using LibTSforge.SPP;
  3983. using LibTSforge.TokenStore;
  3984. public enum PSVersion
  3985. {
  3986. Vista,
  3987. Win7,
  3988. Win8Early,
  3989. Win8,
  3990. WinBlue,
  3991. WinModern
  3992. }
  3993. public static class Constants
  3994. {
  3995. public static readonly byte[] UniversalHWIDBlock =
  3996. {
  3997. 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00,
  3998. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3999. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  4000. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  4001. 0x00, 0x00, 0x01, 0x0c, 0x01, 0x00
  4002. };
  4003. public static readonly byte[] KMSv4Response =
  4004. {
  4005. 0x00, 0x00, 0x04, 0x00, 0x62, 0x00, 0x00, 0x00, 0x30, 0x00, 0x35, 0x00, 0x34, 0x00, 0x32, 0x00,
  4006. 0x36, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x30, 0x00, 0x32, 0x00, 0x30, 0x00, 0x36, 0x00, 0x2D, 0x00,
  4007. 0x31, 0x00, 0x36, 0x00, 0x31, 0x00, 0x2D, 0x00, 0x36, 0x00, 0x35, 0x00, 0x35, 0x00, 0x35, 0x00,
  4008. 0x30, 0x00, 0x36, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x33, 0x00, 0x2D, 0x00, 0x31, 0x00, 0x30, 0x00,
  4009. 0x33, 0x00, 0x33, 0x00, 0x2D, 0x00, 0x39, 0x00, 0x32, 0x00, 0x30, 0x00, 0x30, 0x00, 0x2E, 0x00,
  4010. 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x36, 0x00, 0x35, 0x00,
  4011. 0x32, 0x00, 0x30, 0x00, 0x31, 0x00, 0x33, 0x00, 0x00, 0x00, 0xDE, 0x19, 0x02, 0xCF, 0x1F, 0x35,
  4012. 0x97, 0x4E, 0x8A, 0x8F, 0xB8, 0x07, 0xB1, 0x92, 0xB5, 0xB5, 0x97, 0x42, 0xEC, 0x3A, 0x76, 0x84,
  4013. 0xD5, 0x01, 0x32, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x60, 0x27, 0x00, 0x00, 0xC4, 0x1E,
  4014. 0xAA, 0x8B, 0xDD, 0x0C, 0xAB, 0x55, 0x6A, 0xCE, 0xAF, 0xAC, 0x7F, 0x5F, 0xBD, 0xE9
  4015. };
  4016. public static readonly byte[] KMSv5Response =
  4017. {
  4018. 0x00, 0x00, 0x05, 0x00, 0xBE, 0x96, 0xF9, 0x04, 0x54, 0x17, 0x3F, 0xAF, 0xE3, 0x08, 0x50, 0xEB,
  4019. 0x22, 0xBA, 0x53, 0xBF, 0xF2, 0x6A, 0x7B, 0xC9, 0x05, 0x1D, 0xB5, 0x19, 0xDF, 0x98, 0xE2, 0x71,
  4020. 0x4D, 0x00, 0x61, 0xE9, 0x9D, 0x03, 0xFB, 0x31, 0xF9, 0x1F, 0x2E, 0x60, 0x59, 0xC7, 0x73, 0xC8,
  4021. 0xE8, 0xB6, 0xE1, 0x2B, 0x39, 0xC6, 0x35, 0x0E, 0x68, 0x7A, 0xAA, 0x4F, 0x28, 0x23, 0x12, 0x18,
  4022. 0xE3, 0xAA, 0x84, 0x81, 0x6E, 0x82, 0xF0, 0x3F, 0xD9, 0x69, 0xA9, 0xDF, 0xBA, 0x5F, 0xCA, 0x32,
  4023. 0x54, 0xB2, 0x52, 0x3B, 0x3E, 0xD1, 0x5C, 0x65, 0xBC, 0x3E, 0x59, 0x0D, 0x15, 0x9F, 0x37, 0xEC,
  4024. 0x30, 0x9C, 0xCC, 0x1B, 0x39, 0x0D, 0x21, 0x32, 0x29, 0xA2, 0xDD, 0xC7, 0xC1, 0x69, 0xF2, 0x72,
  4025. 0x3F, 0x00, 0x98, 0x1E, 0xF8, 0x9A, 0x79, 0x44, 0x5D, 0x25, 0x80, 0x7B, 0xF5, 0xE1, 0x7C, 0x68,
  4026. 0x25, 0xAA, 0x0D, 0x67, 0x98, 0xE5, 0x59, 0x9B, 0x04, 0xC1, 0x23, 0x33, 0x48, 0xFB, 0x28, 0xD0,
  4027. 0x76, 0xDF, 0x01, 0x56, 0xE7, 0xEC, 0xBF, 0x1A, 0xA2, 0x22, 0x28, 0xCA, 0xB1, 0xB4, 0x4C, 0x30,
  4028. 0x14, 0x6F, 0xD2, 0x2E, 0x01, 0x2A, 0x04, 0xE3, 0xBD, 0xA7, 0x41, 0x2F, 0xC9, 0xEF, 0x53, 0xC0,
  4029. 0x70, 0x48, 0xF1, 0xB2, 0xB6, 0xEA, 0xE7, 0x0F, 0x7A, 0x15, 0xD1, 0xA6, 0xFE, 0x23, 0xC8, 0xF3,
  4030. 0xE1, 0x02, 0x9E, 0xA0, 0x4E, 0xBD, 0xF5, 0xEA, 0x53, 0x74, 0x8E, 0x74, 0xA1, 0xA1, 0xBD, 0xBE,
  4031. 0x66, 0xC4, 0x73, 0x8F, 0x24, 0xA7, 0x2A, 0x2F, 0xE3, 0xD9, 0xF4, 0x28, 0xD9, 0xF8, 0xA3, 0x93,
  4032. 0x03, 0x9E, 0x29, 0xAB
  4033. };
  4034. public static readonly byte[] KMSv6Response =
  4035. {
  4036. 0x00, 0x00, 0x06, 0x00, 0x54, 0xD3, 0x40, 0x08, 0xF3, 0xCD, 0x03, 0xEF, 0xC8, 0x15, 0x87, 0x9E,
  4037. 0xCA, 0x2E, 0x85, 0xFB, 0xE6, 0xF6, 0x73, 0x66, 0xFB, 0xDA, 0xBB, 0x7B, 0xB1, 0xBC, 0xD6, 0xF9,
  4038. 0x5C, 0x41, 0xA0, 0xFE, 0xE1, 0x74, 0xC4, 0xBB, 0x91, 0xE5, 0xDE, 0x6D, 0x3A, 0x11, 0xD5, 0xFC,
  4039. 0x68, 0xC0, 0x7B, 0x82, 0xB2, 0x24, 0xD1, 0x85, 0xBA, 0x45, 0xBF, 0xF1, 0x26, 0xFA, 0xA5, 0xC6,
  4040. 0x61, 0x70, 0x69, 0x69, 0x6E, 0x0F, 0x0B, 0x60, 0xB7, 0x3D, 0xE8, 0xF1, 0x47, 0x0B, 0x65, 0xFD,
  4041. 0xA7, 0x30, 0x1E, 0xF6, 0xA4, 0xD0, 0x79, 0xC4, 0x58, 0x8D, 0x81, 0xFD, 0xA7, 0xE7, 0x53, 0xF1,
  4042. 0x67, 0x78, 0xF0, 0x0F, 0x60, 0x8F, 0xC8, 0x16, 0x35, 0x22, 0x94, 0x48, 0xCB, 0x0F, 0x8E, 0xB2,
  4043. 0x1D, 0xF7, 0x3E, 0x28, 0x42, 0x55, 0x6B, 0x07, 0xE3, 0xE8, 0x51, 0xD5, 0xFA, 0x22, 0x0C, 0x86,
  4044. 0x65, 0x0D, 0x3F, 0xDD, 0x8D, 0x9B, 0x1B, 0xC9, 0xD3, 0xB8, 0x3A, 0xEC, 0xF1, 0x11, 0x19, 0x25,
  4045. 0xF7, 0x84, 0x4A, 0x4C, 0x0A, 0xB5, 0x31, 0x94, 0x37, 0x76, 0xCE, 0xE7, 0xAB, 0xA9, 0x69, 0xDF,
  4046. 0xA4, 0xC9, 0x22, 0x6C, 0x23, 0xFF, 0x6B, 0xFC, 0xDA, 0x78, 0xD8, 0xC4, 0x8F, 0x74, 0xBB, 0x26,
  4047. 0x05, 0x00, 0x98, 0x9B, 0xE5, 0xE2, 0xAD, 0x0D, 0x57, 0x95, 0x80, 0x66, 0x8E, 0x43, 0x74, 0x87,
  4048. 0x93, 0x1F, 0xF4, 0xB2, 0x2C, 0x20, 0x5F, 0xD8, 0x9C, 0x4C, 0x56, 0xB3, 0x57, 0x44, 0x62, 0x68,
  4049. 0x8D, 0xAA, 0x40, 0x11, 0x9D, 0x84, 0x62, 0x0E, 0x43, 0x8A, 0x1D, 0xF0, 0x1C, 0x49, 0xD8, 0x56,
  4050. 0xEF, 0x4C, 0xD3, 0x64, 0xBA, 0x0D, 0xEF, 0x87, 0xB5, 0x2C, 0x88, 0xF3, 0x18, 0xFF, 0x3A, 0x8C,
  4051. 0xF5, 0xA6, 0x78, 0x5C, 0x62, 0xE3, 0x9E, 0x4C, 0xB6, 0x31, 0x2D, 0x06, 0x80, 0x92, 0xBC, 0x2E,
  4052. 0x92, 0xA6, 0x56, 0x96
  4053. };
  4054. // 2^31 - 1 minutes
  4055. public static ulong TimerMax = (ulong)TimeSpan.FromMinutes(2147483647).Ticks;
  4056. public static readonly string ZeroCID = new string('0', 48);
  4057. }
  4058. public static class BinaryReaderExt
  4059. {
  4060. public static void Align(this BinaryReader reader, int to)
  4061. {
  4062. int pos = (int)reader.BaseStream.Position;
  4063. reader.BaseStream.Seek(-pos & (to - 1), SeekOrigin.Current);
  4064. }
  4065. public static string ReadNullTerminatedString(this BinaryReader reader, int maxLen)
  4066. {
  4067. return Encoding.Unicode.GetString(reader.ReadBytes(maxLen)).Split(new char[] { '\0' }, 2)[0];
  4068. }
  4069. }
  4070. public static class BinaryWriterExt
  4071. {
  4072. public static void Align(this BinaryWriter writer, int to)
  4073. {
  4074. int pos = (int)writer.BaseStream.Position;
  4075. writer.WritePadding(-pos & (to - 1));
  4076. }
  4077. public static void WritePadding(this BinaryWriter writer, int len)
  4078. {
  4079. writer.Write(Enumerable.Repeat((byte)0, len).ToArray());
  4080. }
  4081. public static void WriteFixedString(this BinaryWriter writer, string str, int bLen)
  4082. {
  4083. writer.Write(Encoding.ASCII.GetBytes(str));
  4084. writer.WritePadding(bLen - str.Length);
  4085. }
  4086. public static void WriteFixedString16(this BinaryWriter writer, string str, int bLen)
  4087. {
  4088. byte[] bstr = Utils.EncodeString(str);
  4089. writer.Write(bstr);
  4090. writer.WritePadding(bLen - bstr.Length);
  4091. }
  4092. public static byte[] GetBytes(this BinaryWriter writer)
  4093. {
  4094. return ((MemoryStream)writer.BaseStream).ToArray();
  4095. }
  4096. }
  4097. public static class ByteArrayExt
  4098. {
  4099. public static byte[] CastToArray<T>(this T data) where T : struct
  4100. {
  4101. int size = Marshal.SizeOf(typeof(T));
  4102. byte[] result = new byte[size];
  4103. GCHandle handle = GCHandle.Alloc(result, GCHandleType.Pinned);
  4104. try
  4105. {
  4106. Marshal.StructureToPtr(data, handle.AddrOfPinnedObject(), false);
  4107. }
  4108. finally
  4109. {
  4110. handle.Free();
  4111. }
  4112. return result;
  4113. }
  4114. public static T CastToStruct<T>(this byte[] data) where T : struct
  4115. {
  4116. GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
  4117. try
  4118. {
  4119. IntPtr ptr = handle.AddrOfPinnedObject();
  4120. return (T)Marshal.PtrToStructure(ptr, typeof(T));
  4121. }
  4122. finally
  4123. {
  4124. handle.Free();
  4125. }
  4126. }
  4127. }
  4128. public static class FileStreamExt
  4129. {
  4130. public static byte[] ReadAllBytes(this FileStream fs)
  4131. {
  4132. BinaryReader br = new BinaryReader(fs);
  4133. return br.ReadBytes((int)fs.Length);
  4134. }
  4135. public static void WriteAllBytes(this FileStream fs, byte[] data)
  4136. {
  4137. fs.Seek(0, SeekOrigin.Begin);
  4138. fs.SetLength(data.Length);
  4139. fs.Write(data, 0, data.Length);
  4140. }
  4141. }
  4142. public static class Utils
  4143. {
  4144. public static string DecodeString(byte[] data)
  4145. {
  4146. return Encoding.Unicode.GetString(data).Trim('\0');
  4147. }
  4148. public static byte[] EncodeString(string str)
  4149. {
  4150. return Encoding.Unicode.GetBytes(str + '\0');
  4151. }
  4152. [DllImport("kernel32.dll")]
  4153. public static extern uint GetSystemDefaultLCID();
  4154. public static uint CRC32(byte[] data)
  4155. {
  4156. const uint polynomial = 0x04C11DB7;
  4157. uint crc = 0xffffffff;
  4158. foreach (byte b in data)
  4159. {
  4160. crc ^= (uint)b << 24;
  4161. for (int bit = 0; bit < 8; bit++)
  4162. {
  4163. if ((crc & 0x80000000) != 0)
  4164. {
  4165. crc = (crc << 1) ^ polynomial;
  4166. }
  4167. else
  4168. {
  4169. crc <<= 1;
  4170. }
  4171. }
  4172. }
  4173. return ~crc;
  4174. }
  4175. public static void KillSPP()
  4176. {
  4177. ServiceController sc;
  4178. try
  4179. {
  4180. sc = new ServiceController("sppsvc");
  4181. if (sc.Status == ServiceControllerStatus.Stopped)
  4182. return;
  4183. }
  4184. catch (InvalidOperationException ex)
  4185. {
  4186. throw new InvalidOperationException("Unable to access sppsvc: " + ex.Message);
  4187. }
  4188. Logger.WriteLine("Stopping sppsvc...");
  4189. bool stopped = false;
  4190. for (int i = 0; stopped == false && i < 60; i++)
  4191. {
  4192. try
  4193. {
  4194. if (sc.Status != ServiceControllerStatus.StopPending)
  4195. sc.Stop();
  4196. sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(500));
  4197. }
  4198. catch (System.ServiceProcess.TimeoutException)
  4199. {
  4200. continue;
  4201. }
  4202. catch (InvalidOperationException)
  4203. {
  4204. System.Threading.Thread.Sleep(500);
  4205. continue;
  4206. }
  4207. stopped = true;
  4208. }
  4209. if (!stopped)
  4210. throw new System.TimeoutException("Failed to stop sppsvc");
  4211. Logger.WriteLine("sppsvc stopped successfully.");
  4212. }
  4213. public static string GetPSPath(PSVersion version)
  4214. {
  4215. switch (version)
  4216. {
  4217. case PSVersion.Win7:
  4218. return Directory.GetFiles(
  4219. Environment.GetFolderPath(Environment.SpecialFolder.System),
  4220. "7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0")
  4221. .FirstOrDefault() ?? "";
  4222. case PSVersion.Win8Early:
  4223. case PSVersion.WinBlue:
  4224. case PSVersion.Win8:
  4225. case PSVersion.WinModern:
  4226. return Path.Combine(
  4227. Environment.ExpandEnvironmentVariables(
  4228. (string)Registry.GetValue(
  4229. @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform",
  4230. "TokenStore",
  4231. string.Empty
  4232. )
  4233. ),
  4234. "data.dat"
  4235. );
  4236. default:
  4237. return "";
  4238. }
  4239. }
  4240. public static string GetTokensPath(PSVersion version)
  4241. {
  4242. switch (version)
  4243. {
  4244. case PSVersion.Win7:
  4245. return Path.Combine(
  4246. Environment.ExpandEnvironmentVariables("%WINDIR%"),
  4247. @"ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat"
  4248. );
  4249. case PSVersion.Win8Early:
  4250. case PSVersion.WinBlue:
  4251. case PSVersion.Win8:
  4252. case PSVersion.WinModern:
  4253. return Path.Combine(
  4254. Environment.ExpandEnvironmentVariables(
  4255. (string)Registry.GetValue(
  4256. @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform",
  4257. "TokenStore",
  4258. string.Empty
  4259. )
  4260. ),
  4261. "tokens.dat"
  4262. );
  4263. default:
  4264. return "";
  4265. }
  4266. }
  4267. public static IPhysicalStore GetStore(PSVersion version, bool production)
  4268. {
  4269. string psPath;
  4270. try
  4271. {
  4272. psPath = GetPSPath(version);
  4273. }
  4274. catch
  4275. {
  4276. throw new FileNotFoundException("Failed to get path of physical store.");
  4277. }
  4278. if (string.IsNullOrEmpty(psPath) || !File.Exists(psPath))
  4279. {
  4280. throw new FileNotFoundException(string.Format("Physical store not found at expected path {0}.", psPath));
  4281. }
  4282. if (version == PSVersion.Vista)
  4283. {
  4284. throw new NotSupportedException("Physical store editing is not supported for Windows Vista.");
  4285. }
  4286. return version == PSVersion.Win7 ? new PhysicalStoreWin7(psPath, production) : (IPhysicalStore)new PhysicalStoreModern(psPath, production, version);
  4287. }
  4288. public static ITokenStore GetTokenStore(PSVersion version)
  4289. {
  4290. string tokPath;
  4291. try
  4292. {
  4293. tokPath = GetTokensPath(version);
  4294. }
  4295. catch
  4296. {
  4297. throw new FileNotFoundException("Failed to get path of physical store.");
  4298. }
  4299. if (string.IsNullOrEmpty(tokPath) || !File.Exists(tokPath))
  4300. {
  4301. throw new FileNotFoundException(string.Format("Token store not found at expected path {0}.", tokPath));
  4302. }
  4303. return new TokenStoreModern(tokPath);
  4304. }
  4305. public static string GetArchitecture()
  4306. {
  4307. string arch = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE", EnvironmentVariableTarget.Machine).ToUpperInvariant();
  4308. return arch == "AMD64" ? "X64" : arch;
  4309. }
  4310. public static PSVersion DetectVersion()
  4311. {
  4312. int build = Environment.OSVersion.Version.Build;
  4313. if (build >= 9600) return PSVersion.WinModern;
  4314. if (build >= 6000 && build <= 6003) return PSVersion.Vista;
  4315. if (build >= 7600 && build <= 7602) return PSVersion.Win7;
  4316. if (build == 9200) return PSVersion.Win8;
  4317. throw new NotSupportedException("Unable to auto-detect version info, please specify one manually using the /ver argument.");
  4318. }
  4319. public static bool DetectCurrentKey()
  4320. {
  4321. SLApi.RefreshLicenseStatus();
  4322. using (RegistryKey wpaKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\WPA"))
  4323. {
  4324. foreach (string subKey in wpaKey.GetSubKeyNames())
  4325. {
  4326. if (subKey.StartsWith("8DEC0AF1") && subKey.EndsWith("-1"))
  4327. {
  4328. return subKey.Contains("P");
  4329. }
  4330. }
  4331. }
  4332. throw new FileNotFoundException("Failed to autodetect key type, specify physical store key with /prod or /test arguments.");
  4333. }
  4334. public static void DumpStore(PSVersion version, bool production, string filePath, string encrFilePath)
  4335. {
  4336. if (encrFilePath == null)
  4337. {
  4338. encrFilePath = GetPSPath(version);
  4339. }
  4340. if (string.IsNullOrEmpty(encrFilePath) || !File.Exists(encrFilePath))
  4341. {
  4342. throw new FileNotFoundException("Store does not exist at expected path '" + encrFilePath + "'.");
  4343. }
  4344. KillSPP();
  4345. using (FileStream fs = File.Open(encrFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
  4346. {
  4347. byte[] encrData = fs.ReadAllBytes();
  4348. File.WriteAllBytes(filePath, PhysStoreCrypto.DecryptPhysicalStore(encrData, production));
  4349. }
  4350. Logger.WriteLine("Store dumped successfully to '" + filePath + "'.");
  4351. }
  4352. public static void LoadStore(PSVersion version, bool production, string filePath)
  4353. {
  4354. if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
  4355. {
  4356. throw new FileNotFoundException("Store file '" + filePath + "' does not exist.");
  4357. }
  4358. KillSPP();
  4359. using (IPhysicalStore store = GetStore(version, production))
  4360. {
  4361. store.WriteRaw(File.ReadAllBytes(filePath));
  4362. }
  4363. Logger.WriteLine("Loaded store file succesfully.");
  4364. }
  4365. }
  4366. public static class Logger
  4367. {
  4368. public static bool HideOutput = false;
  4369. public static void WriteLine(string line)
  4370. {
  4371. if (!HideOutput) Console.WriteLine(line);
  4372. }
  4373. }
  4374. }
  4375. // SPP/PKeyConfig.cs
  4376. namespace LibTSforge.SPP
  4377. {
  4378. using System;
  4379. using System.Collections.Generic;
  4380. using System.IO;
  4381. using System.Linq;
  4382. using System.Text;
  4383. using System.Xml;
  4384. public enum PKeyAlgorithm
  4385. {
  4386. PKEY2005,
  4387. PKEY2009
  4388. }
  4389. public class KeyRange
  4390. {
  4391. public int Start;
  4392. public int End;
  4393. public string EulaType;
  4394. public string PartNumber;
  4395. public bool Valid;
  4396. public bool Contains(int n)
  4397. {
  4398. return Start <= n && End <= n;
  4399. }
  4400. }
  4401. public class ProductConfig
  4402. {
  4403. public int GroupId;
  4404. public string Edition;
  4405. public string Description;
  4406. public string Channel;
  4407. public bool Randomized;
  4408. public PKeyAlgorithm Algorithm;
  4409. public List<KeyRange> Ranges;
  4410. public Guid ActivationId;
  4411. private List<KeyRange> GetPkeyRanges()
  4412. {
  4413. if (Ranges.Count == 0)
  4414. {
  4415. throw new ArgumentException("No key ranges.");
  4416. }
  4417. if (Algorithm == PKeyAlgorithm.PKEY2005)
  4418. {
  4419. return Ranges;
  4420. }
  4421. List<KeyRange> FilteredRanges = Ranges.Where(r => !r.EulaType.Contains("WAU")).ToList();
  4422. if (FilteredRanges.Count == 0)
  4423. {
  4424. throw new NotSupportedException("Specified Activation ID is usable only for Windows Anytime Upgrade. Please use a non-WAU Activation ID instead.");
  4425. }
  4426. return FilteredRanges;
  4427. }
  4428. public ProductKey GetRandomKey()
  4429. {
  4430. List<KeyRange> KeyRanges = GetPkeyRanges();
  4431. Random rnd = new Random();
  4432. KeyRange range = KeyRanges[rnd.Next(KeyRanges.Count)];
  4433. int serial = rnd.Next(range.Start, range.End);
  4434. return new ProductKey(serial, 0, false, Algorithm, this, range);
  4435. }
  4436. }
  4437. public class PKeyConfig
  4438. {
  4439. public Dictionary<Guid, ProductConfig> Products = new Dictionary<Guid, ProductConfig>();
  4440. private List<Guid> loadedPkeyConfigs = new List<Guid>();
  4441. public void LoadConfig(Guid actId)
  4442. {
  4443. string pkcData;
  4444. Guid pkcFileId = SLApi.GetPkeyConfigFileId(actId);
  4445. if (loadedPkeyConfigs.Contains(pkcFileId)) return;
  4446. string licConts = SLApi.GetLicenseContents(pkcFileId);
  4447. using (TextReader tr = new StringReader(licConts))
  4448. {
  4449. XmlDocument lic = new XmlDocument();
  4450. lic.Load(tr);
  4451. XmlNamespaceManager nsmgr = new XmlNamespaceManager(lic.NameTable);
  4452. nsmgr.AddNamespace("rg", "urn:mpeg:mpeg21:2003:01-REL-R-NS");
  4453. nsmgr.AddNamespace("r", "urn:mpeg:mpeg21:2003:01-REL-R-NS");
  4454. nsmgr.AddNamespace("tm", "http://www.microsoft.com/DRM/XrML2/TM/v2");
  4455. XmlNode root = lic.DocumentElement;
  4456. XmlNode pkcDataNode = root.SelectSingleNode("/rg:licenseGroup/r:license/r:otherInfo/tm:infoTables/tm:infoList/tm:infoBin[@name=\"pkeyConfigData\"]", nsmgr);
  4457. pkcData = Encoding.UTF8.GetString(Convert.FromBase64String(pkcDataNode.InnerText));
  4458. }
  4459. using (TextReader tr = new StringReader(pkcData))
  4460. {
  4461. XmlDocument lic = new XmlDocument();
  4462. lic.Load(tr);
  4463. XmlNamespaceManager nsmgr = new XmlNamespaceManager(lic.NameTable);
  4464. nsmgr.AddNamespace("p", "http://www.microsoft.com/DRM/PKEY/Configuration/2.0");
  4465. XmlNodeList configNodes = lic.SelectNodes("//p:ProductKeyConfiguration/p:Configurations/p:Configuration", nsmgr);
  4466. XmlNodeList rangeNodes = lic.SelectNodes("//p:ProductKeyConfiguration/p:KeyRanges/p:KeyRange", nsmgr);
  4467. XmlNodeList pubKeyNodes = lic.SelectNodes("//p:ProductKeyConfiguration/p:PublicKeys/p:PublicKey", nsmgr);
  4468. Dictionary<int, PKeyAlgorithm> algorithms = new Dictionary<int, PKeyAlgorithm>();
  4469. Dictionary<string, List<KeyRange>> ranges = new Dictionary<string, List<KeyRange>>();
  4470. Dictionary<string, PKeyAlgorithm> algoConv = new Dictionary<string, PKeyAlgorithm>
  4471. {
  4472. { "msft:rm/algorithm/pkey/2005", PKeyAlgorithm.PKEY2005 },
  4473. { "msft:rm/algorithm/pkey/2009", PKeyAlgorithm.PKEY2009 }
  4474. };
  4475. foreach (XmlNode pubKeyNode in pubKeyNodes)
  4476. {
  4477. int group = int.Parse(pubKeyNode.SelectSingleNode("./p:GroupId", nsmgr).InnerText);
  4478. algorithms[group] = algoConv[pubKeyNode.SelectSingleNode("./p:AlgorithmId", nsmgr).InnerText];
  4479. }
  4480. foreach (XmlNode rangeNode in rangeNodes)
  4481. {
  4482. string refActIdStr = rangeNode.SelectSingleNode("./p:RefActConfigId", nsmgr).InnerText;
  4483. if (!ranges.ContainsKey(refActIdStr))
  4484. {
  4485. ranges[refActIdStr] = new List<KeyRange>();
  4486. }
  4487. KeyRange keyRange = new KeyRange();
  4488. keyRange.Start = int.Parse(rangeNode.SelectSingleNode("./p:Start", nsmgr).InnerText);
  4489. keyRange.End = int.Parse(rangeNode.SelectSingleNode("./p:End", nsmgr).InnerText);
  4490. keyRange.EulaType = rangeNode.SelectSingleNode("./p:EulaType", nsmgr).InnerText;
  4491. keyRange.PartNumber = rangeNode.SelectSingleNode("./p:PartNumber", nsmgr).InnerText;
  4492. keyRange.Valid = rangeNode.SelectSingleNode("./p:IsValid", nsmgr).InnerText.ToLower() == "true";
  4493. ranges[refActIdStr].Add(keyRange);
  4494. }
  4495. foreach (XmlNode configNode in configNodes)
  4496. {
  4497. string refActIdStr = configNode.SelectSingleNode("./p:ActConfigId", nsmgr).InnerText;
  4498. Guid refActId = new Guid(refActIdStr);
  4499. int group = int.Parse(configNode.SelectSingleNode("./p:RefGroupId", nsmgr).InnerText);
  4500. List<KeyRange> keyRanges = ranges[refActIdStr];
  4501. if (keyRanges.Count > 0 && !Products.ContainsKey(refActId))
  4502. {
  4503. ProductConfig productConfig = new ProductConfig();
  4504. productConfig.GroupId = group;
  4505. productConfig.Edition = configNode.SelectSingleNode("./p:EditionId", nsmgr).InnerText;
  4506. productConfig.Description = configNode.SelectSingleNode("./p:ProductDescription", nsmgr).InnerText;
  4507. productConfig.Channel = configNode.SelectSingleNode("./p:ProductKeyType", nsmgr).InnerText;
  4508. productConfig.Randomized = configNode.SelectSingleNode("./p:ProductKeyType", nsmgr).InnerText.ToLower() == "true";
  4509. productConfig.Algorithm = algorithms[group];
  4510. productConfig.Ranges = keyRanges;
  4511. productConfig.ActivationId = refActId;
  4512. Products[refActId] = productConfig;
  4513. }
  4514. }
  4515. }
  4516. loadedPkeyConfigs.Add(pkcFileId);
  4517. }
  4518. public ProductConfig MatchParams(int group, int serial)
  4519. {
  4520. foreach (ProductConfig config in Products.Values)
  4521. {
  4522. if (config.GroupId == group)
  4523. {
  4524. foreach (KeyRange range in config.Ranges)
  4525. {
  4526. if (range.Contains(serial))
  4527. {
  4528. return config;
  4529. }
  4530. }
  4531. }
  4532. }
  4533. throw new FileNotFoundException("Failed to find product matching supplied product key parameters.");
  4534. }
  4535. public void LoadAllConfigs(Guid appId)
  4536. {
  4537. foreach (Guid actId in SLApi.GetActivationIds(appId))
  4538. {
  4539. try
  4540. {
  4541. LoadConfig(actId);
  4542. }
  4543. catch (ArgumentException)
  4544. {
  4545. }
  4546. }
  4547. }
  4548. public PKeyConfig()
  4549. {
  4550. }
  4551. }
  4552. }
  4553. // SPP/ProductKey.cs
  4554. namespace LibTSforge.SPP
  4555. {
  4556. using System;
  4557. using System.IO;
  4558. using System.Linq;
  4559. using LibTSforge.Crypto;
  4560. using LibTSforge.PhysicalStore;
  4561. public class ProductKey
  4562. {
  4563. private static readonly string ALPHABET = "BCDFGHJKMPQRTVWXY2346789";
  4564. private readonly ulong klow;
  4565. private readonly ulong khigh;
  4566. public int Group;
  4567. public int Serial;
  4568. public ulong Security;
  4569. public bool Upgrade;
  4570. public PKeyAlgorithm Algorithm;
  4571. public string EulaType;
  4572. public string PartNumber;
  4573. public string Edition;
  4574. public string Channel;
  4575. public Guid ActivationId;
  4576. private string mpc;
  4577. private string pid2;
  4578. public byte[] KeyBytes
  4579. {
  4580. get { return BitConverter.GetBytes(klow).Concat(BitConverter.GetBytes(khigh)).ToArray(); }
  4581. }
  4582. public ProductKey(int serial, ulong security, bool upgrade, PKeyAlgorithm algorithm, ProductConfig config, KeyRange range)
  4583. {
  4584. Group = config.GroupId;
  4585. Serial = serial;
  4586. Security = security;
  4587. Upgrade = upgrade;
  4588. Algorithm = algorithm;
  4589. EulaType = range.EulaType;
  4590. PartNumber = range.PartNumber.Split(':', ';')[0];
  4591. Edition = config.Edition;
  4592. Channel = config.Channel;
  4593. ActivationId = config.ActivationId;
  4594. klow = ((security & 0x3fff) << 50 | ((ulong)serial & 0x3fffffff) << 20 | ((ulong)Group & 0xfffff));
  4595. khigh = ((upgrade ? (ulong)1 : 0) << 49 | ((security >> 14) & 0x7fffffffff));
  4596. uint checksum = Utils.CRC32(KeyBytes) & 0x3ff;
  4597. khigh |= ((ulong)checksum << 39);
  4598. }
  4599. public string GetAlgoUri()
  4600. {
  4601. return "msft:rm/algorithm/pkey/" + (Algorithm == PKeyAlgorithm.PKEY2005 ? "2005" : (Algorithm == PKeyAlgorithm.PKEY2009 ? "2009" : "Unknown"));
  4602. }
  4603. public Guid GetPkeyId()
  4604. {
  4605. VariableBag pkb = new VariableBag();
  4606. pkb.Blocks.AddRange(new CRCBlock[]
  4607. {
  4608. new CRCBlock
  4609. {
  4610. DataType = CRCBlockType.STRING,
  4611. KeyAsStr = "SppPkeyBindingProductKey",
  4612. ValueAsStr = ToString()
  4613. },
  4614. new CRCBlock
  4615. {
  4616. DataType = CRCBlockType.BINARY,
  4617. KeyAsStr = "SppPkeyBindingMiscData",
  4618. Value = new byte[] { }
  4619. },
  4620. new CRCBlock
  4621. {
  4622. DataType = CRCBlockType.STRING,
  4623. KeyAsStr = "SppPkeyBindingAlgorithm",
  4624. ValueAsStr = GetAlgoUri()
  4625. }
  4626. });
  4627. return new Guid(CryptoUtils.SHA256Hash(pkb.Serialize()).Take(16).ToArray());
  4628. }
  4629. public string GetDefaultMPC()
  4630. {
  4631. int build = Environment.OSVersion.Version.Build;
  4632. string defaultMPC = build >= 10240 ? "03612" :
  4633. build >= 9600 ? "06401" :
  4634. build >= 9200 ? "05426" :
  4635. "55041";
  4636. return defaultMPC;
  4637. }
  4638. public string GetMPC()
  4639. {
  4640. if (mpc != null)
  4641. {
  4642. return mpc;
  4643. }
  4644. mpc = GetDefaultMPC();
  4645. // setup.cfg doesn't exist in Windows 8+
  4646. string setupcfg = string.Format("{0}\\oobe\\{1}", Environment.SystemDirectory, "setup.cfg");
  4647. if (!File.Exists(setupcfg) || Edition.Contains(";"))
  4648. {
  4649. return mpc;
  4650. }
  4651. string mpcKey = string.Format("{0}.{1}=", Utils.GetArchitecture(), Edition);
  4652. string localMPC = File.ReadAllLines(setupcfg).FirstOrDefault(line => line.Contains(mpcKey));
  4653. if (localMPC != null)
  4654. {
  4655. mpc = localMPC.Split('=')[1].Trim();
  4656. }
  4657. return mpc;
  4658. }
  4659. public string GetPid2()
  4660. {
  4661. if (pid2 != null)
  4662. {
  4663. return pid2;
  4664. }
  4665. pid2 = "";
  4666. if (Algorithm == PKeyAlgorithm.PKEY2005)
  4667. {
  4668. string mpc = GetMPC();
  4669. string serialHigh;
  4670. int serialLow;
  4671. int lastPart;
  4672. if (EulaType == "OEM")
  4673. {
  4674. serialHigh = "OEM";
  4675. serialLow = ((Group / 2) % 100) * 10000 + (Serial / 100000);
  4676. lastPart = Serial % 100000;
  4677. }
  4678. else
  4679. {
  4680. serialHigh = (Serial / 1000000).ToString("D3");
  4681. serialLow = Serial % 1000000;
  4682. lastPart = ((Group / 2) % 100) * 1000 + new Random().Next(1000);
  4683. }
  4684. int checksum = 0;
  4685. foreach (char c in serialLow.ToString())
  4686. {
  4687. checksum += int.Parse(c.ToString());
  4688. }
  4689. checksum = 7 - (checksum % 7);
  4690. pid2 = string.Format("{0}-{1}-{2:D6}{3}-{4:D5}", mpc, serialHigh, serialLow, checksum, lastPart);
  4691. }
  4692. return pid2;
  4693. }
  4694. public byte[] GetPid3()
  4695. {
  4696. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  4697. writer.Write(0xA4);
  4698. writer.Write(0x3);
  4699. writer.WriteFixedString(GetPid2(), 24);
  4700. writer.Write(Group);
  4701. writer.WriteFixedString(PartNumber, 16);
  4702. writer.WritePadding(0x6C);
  4703. byte[] data = writer.GetBytes();
  4704. byte[] crc = BitConverter.GetBytes(~Utils.CRC32(data.Reverse().ToArray())).Reverse().ToArray();
  4705. writer.Write(crc);
  4706. return writer.GetBytes();
  4707. }
  4708. public byte[] GetPid4()
  4709. {
  4710. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  4711. writer.Write(0x4F8);
  4712. writer.Write(0x4);
  4713. writer.WriteFixedString16(GetExtendedPid(), 0x80);
  4714. writer.WriteFixedString16(ActivationId.ToString(), 0x80);
  4715. writer.WritePadding(0x10);
  4716. writer.WriteFixedString16(Edition, 0x208);
  4717. writer.Write(Upgrade ? (ulong)1 : 0);
  4718. writer.WritePadding(0x50);
  4719. writer.WriteFixedString16(PartNumber, 0x80);
  4720. writer.WriteFixedString16(Channel, 0x80);
  4721. writer.WriteFixedString16(EulaType, 0x80);
  4722. return writer.GetBytes();
  4723. }
  4724. public string GetExtendedPid()
  4725. {
  4726. string mpc = GetMPC();
  4727. int serialHigh = Serial / 1000000;
  4728. int serialLow = Serial % 1000000;
  4729. int licenseType;
  4730. uint lcid = Utils.GetSystemDefaultLCID();
  4731. int build = Environment.OSVersion.Version.Build;
  4732. int dayOfYear = DateTime.Now.DayOfYear;
  4733. int year = DateTime.Now.Year;
  4734. switch (EulaType)
  4735. {
  4736. case "OEM":
  4737. licenseType = 2;
  4738. break;
  4739. case "Volume":
  4740. licenseType = 3;
  4741. break;
  4742. default:
  4743. licenseType = 0;
  4744. break;
  4745. }
  4746. return string.Format(
  4747. "{0}-{1:D5}-{2:D3}-{3:D6}-{4:D2}-{5:D4}-{6:D4}.0000-{7:D3}{8:D4}",
  4748. mpc,
  4749. Group,
  4750. serialHigh,
  4751. serialLow,
  4752. licenseType,
  4753. lcid,
  4754. build,
  4755. dayOfYear,
  4756. year
  4757. );
  4758. }
  4759. public byte[] GetPhoneData(PSVersion version)
  4760. {
  4761. if (version == PSVersion.Win7)
  4762. {
  4763. Random rnd = new Random(Group * 1000000000 + Serial);
  4764. byte[] data = new byte[8];
  4765. rnd.NextBytes(data);
  4766. return data;
  4767. }
  4768. int serialHigh = Serial / 1000000;
  4769. int serialLow = Serial % 1000000;
  4770. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  4771. writer.Write(new Guid("B8731595-A2F6-430B-A799-FBFFB81A8D73").ToByteArray());
  4772. writer.Write(Group);
  4773. writer.Write(serialHigh);
  4774. writer.Write(serialLow);
  4775. writer.Write(Upgrade ? 1 : 0);
  4776. writer.Write(Security);
  4777. return writer.GetBytes();
  4778. }
  4779. public override string ToString()
  4780. {
  4781. string keyStr = "";
  4782. Random rnd = new Random(Group * 1000000000 + Serial);
  4783. if (Algorithm == PKeyAlgorithm.PKEY2005)
  4784. {
  4785. keyStr = "H4X3DH4X3DH4X3DH4X3D";
  4786. for (int i = 0; i < 5; i++)
  4787. {
  4788. keyStr += ALPHABET[rnd.Next(24)];
  4789. }
  4790. }
  4791. else if (Algorithm == PKeyAlgorithm.PKEY2009)
  4792. {
  4793. int last = 0;
  4794. byte[] bKey = KeyBytes;
  4795. for (int i = 24; i >= 0; i--)
  4796. {
  4797. int current = 0;
  4798. for (int j = 14; j >= 0; j--)
  4799. {
  4800. current *= 0x100;
  4801. current += bKey[j];
  4802. bKey[j] = (byte)(current / 24);
  4803. current %= 24;
  4804. last = current;
  4805. }
  4806. keyStr = ALPHABET[current] + keyStr;
  4807. }
  4808. keyStr = keyStr.Substring(1, last) + "N" + keyStr.Substring(last + 1, keyStr.Length - last - 1);
  4809. }
  4810. for (int i = 5; i < keyStr.Length; i += 6)
  4811. {
  4812. keyStr = keyStr.Insert(i, "-");
  4813. }
  4814. return keyStr;
  4815. }
  4816. }
  4817. }
  4818. // SPP/SLAPI.cs
  4819. namespace LibTSforge.SPP
  4820. {
  4821. using System;
  4822. using System.Collections.Generic;
  4823. using System.Linq;
  4824. using System.Runtime.InteropServices;
  4825. using System.Text;
  4826. public static class SLApi
  4827. {
  4828. private enum SLIDTYPE
  4829. {
  4830. SL_ID_APPLICATION,
  4831. SL_ID_PRODUCT_SKU,
  4832. SL_ID_LICENSE_FILE,
  4833. SL_ID_LICENSE,
  4834. SL_ID_PKEY,
  4835. SL_ID_ALL_LICENSES,
  4836. SL_ID_ALL_LICENSE_FILES,
  4837. SL_ID_STORE_TOKEN,
  4838. SL_ID_LAST
  4839. }
  4840. private enum SLDATATYPE
  4841. {
  4842. SL_DATA_NONE,
  4843. SL_DATA_SZ,
  4844. SL_DATA_DWORD,
  4845. SL_DATA_BINARY,
  4846. SL_DATA_MULTI_SZ,
  4847. SL_DATA_SUM
  4848. }
  4849. [StructLayout(LayoutKind.Sequential)]
  4850. private struct SL_LICENSING_STATUS
  4851. {
  4852. public Guid SkuId;
  4853. public uint eStatus;
  4854. public uint dwGraceTime;
  4855. public uint dwTotalGraceDays;
  4856. public uint hrReason;
  4857. public ulong qwValidityExpiration;
  4858. }
  4859. public static readonly Guid WINDOWS_APP_ID = new Guid("55c92734-d682-4d71-983e-d6ec3f16059f");
  4860. [DllImport("sppc.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
  4861. private static extern void SLOpen(out IntPtr hSLC);
  4862. [DllImport("sppc.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
  4863. private static extern void SLClose(IntPtr hSLC);
  4864. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  4865. private static extern uint SLGetWindowsInformationDWORD(string ValueName, ref int Value);
  4866. [DllImport("sppc.dll", CharSet = CharSet.Unicode)]
  4867. private static extern uint SLInstallProofOfPurchase(IntPtr hSLC, string pwszPKeyAlgorithm, string pwszPKeyString, uint cbPKeySpecificData, byte[] pbPKeySpecificData, ref Guid PKeyId);
  4868. [DllImport("sppc.dll", CharSet = CharSet.Unicode)]
  4869. private static extern uint SLUninstallProofOfPurchase(IntPtr hSLC, ref Guid PKeyId);
  4870. [DllImport("sppc.dll", CharSet = CharSet.Unicode)]
  4871. private static extern uint SLGetPKeyInformation(IntPtr hSLC, ref Guid pPKeyId, string pwszValueName, out SLDATATYPE peDataType, out uint pcbValue, out IntPtr ppbValue);
  4872. [DllImport("sppcext.dll", CharSet = CharSet.Unicode)]
  4873. private static extern uint SLActivateProduct(IntPtr hSLC, ref Guid pProductSkuId, byte[] cbAppSpecificData, byte[] pvAppSpecificData, byte[] pActivationInfo, string pwszProxyServer, ushort wProxyPort);
  4874. [DllImport("sppc.dll", CharSet = CharSet.Unicode)]
  4875. private static extern uint SLGenerateOfflineInstallationId(IntPtr hSLC, ref Guid pProductSkuId, ref string ppwszInstallationId);
  4876. [DllImport("sppc.dll", CharSet = CharSet.Unicode)]
  4877. private static extern uint SLDepositOfflineConfirmationId(IntPtr hSLC, ref Guid pProductSkuId, string pwszInstallationId, string pwszConfirmationId);
  4878. [DllImport("sppc.dll", CharSet = CharSet.Unicode)]
  4879. private static extern uint SLGetSLIDList(IntPtr hSLC, SLIDTYPE eQueryIdType, ref Guid pQueryId, SLIDTYPE eReturnIdType, out uint pnReturnIds, out IntPtr ppReturnIds);
  4880. [DllImport("sppc.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
  4881. private static extern void SLGetLicensingStatusInformation(IntPtr hSLC, ref Guid pAppID, IntPtr pProductSkuId, string pwszRightName, out uint pnStatusCount, out IntPtr ppLicensingStatus);
  4882. [DllImport("sppc.dll", CharSet = CharSet.Unicode)]
  4883. private static extern uint SLGetInstalledProductKeyIds(IntPtr hSLC, ref Guid pProductSkuId, out uint pnProductKeyIds, out IntPtr ppProductKeyIds);
  4884. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  4885. private static extern uint SLConsumeWindowsRight(uint unknown);
  4886. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  4887. private static extern uint SLGetProductSkuInformation(IntPtr hSLC, ref Guid pProductSkuId, string pwszValueName, out SLDATATYPE peDataType, out uint pcbValue, out IntPtr ppbValue);
  4888. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  4889. private static extern uint SLGetProductSkuInformation(IntPtr hSLC, ref Guid pProductSkuId, string pwszValueName, IntPtr peDataType, out uint pcbValue, out IntPtr ppbValue);
  4890. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  4891. private static extern uint SLGetLicense(IntPtr hSLC, ref Guid pLicenseFileId, out uint pcbLicenseFile, out IntPtr ppbLicenseFile);
  4892. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  4893. private static extern uint SLSetCurrentProductKey(IntPtr hSLC, ref Guid pProductSkuId, ref Guid pProductKeyId);
  4894. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  4895. private static extern uint SLFireEvent(IntPtr hSLC, string pwszEventId, ref Guid pApplicationId);
  4896. public class SLContext : IDisposable
  4897. {
  4898. public readonly IntPtr Handle;
  4899. public SLContext()
  4900. {
  4901. SLOpen(out Handle);
  4902. }
  4903. public void Dispose()
  4904. {
  4905. SLClose(Handle);
  4906. GC.SuppressFinalize(this);
  4907. }
  4908. ~SLContext()
  4909. {
  4910. Dispose();
  4911. }
  4912. }
  4913. public static Guid GetDefaultActivationID(Guid appId, bool includeActivated)
  4914. {
  4915. using (SLContext sl = new SLContext())
  4916. {
  4917. uint count;
  4918. IntPtr pLicStat;
  4919. SLGetLicensingStatusInformation(sl.Handle, ref appId, IntPtr.Zero, null, out count, out pLicStat);
  4920. unsafe
  4921. {
  4922. SL_LICENSING_STATUS* licensingStatuses = (SL_LICENSING_STATUS*)pLicStat;
  4923. for (int i = 0; i < count; i++)
  4924. {
  4925. SL_LICENSING_STATUS slStatus = licensingStatuses[i];
  4926. Guid actId = slStatus.SkuId;
  4927. if (GetInstalledPkeyID(actId) == Guid.Empty) continue;
  4928. if (IsAddon(actId)) continue;
  4929. if (!includeActivated && (slStatus.eStatus == 1)) continue;
  4930. return actId;
  4931. }
  4932. }
  4933. return Guid.Empty;
  4934. }
  4935. }
  4936. public static string GetInstallationID(Guid actId)
  4937. {
  4938. using (SLContext sl = new SLContext())
  4939. {
  4940. string installationId = null;
  4941. return SLGenerateOfflineInstallationId(sl.Handle, ref actId, ref installationId) == 0 ? installationId : null;
  4942. }
  4943. }
  4944. public static Guid GetInstalledPkeyID(Guid actId)
  4945. {
  4946. using (SLContext sl = new SLContext())
  4947. {
  4948. uint status;
  4949. uint count;
  4950. IntPtr pProductKeyIds;
  4951. status = SLGetInstalledProductKeyIds(sl.Handle, ref actId, out count, out pProductKeyIds);
  4952. if (status != 0 || count == 0)
  4953. {
  4954. return Guid.Empty;
  4955. }
  4956. unsafe { return *(Guid*)pProductKeyIds; }
  4957. }
  4958. }
  4959. public static uint DepositConfirmationID(Guid actId, string installationId, string confirmationId)
  4960. {
  4961. using (SLContext sl = new SLContext())
  4962. {
  4963. return SLDepositOfflineConfirmationId(sl.Handle, ref actId, installationId, confirmationId);
  4964. }
  4965. }
  4966. public static void RefreshLicenseStatus()
  4967. {
  4968. SLConsumeWindowsRight(0);
  4969. }
  4970. public static bool RefreshTrustedTime(Guid actId)
  4971. {
  4972. using (SLContext sl = new SLContext())
  4973. {
  4974. SLDATATYPE type;
  4975. uint count;
  4976. IntPtr ppbValue;
  4977. uint status = SLGetProductSkuInformation(sl.Handle, ref actId, "TrustedTime", out type, out count, out ppbValue);
  4978. return (int)status >= 0 && status != 0xC004F012;
  4979. }
  4980. }
  4981. public static void FireStateChangedEvent(Guid appId)
  4982. {
  4983. using (SLContext sl = new SLContext())
  4984. {
  4985. SLFireEvent(sl.Handle, "msft:rm/event/licensingstatechanged", ref appId);
  4986. }
  4987. }
  4988. public static Guid GetAppId(Guid actId)
  4989. {
  4990. using (SLContext sl = new SLContext())
  4991. {
  4992. uint status;
  4993. uint count;
  4994. IntPtr pAppIds;
  4995. status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_APPLICATION, out count, out pAppIds);
  4996. if (status != 0 || count == 0)
  4997. {
  4998. return Guid.Empty;
  4999. }
  5000. unsafe { return *(Guid*)pAppIds; }
  5001. }
  5002. }
  5003. public static bool IsAddon(Guid actId)
  5004. {
  5005. using (SLContext sl = new SLContext())
  5006. {
  5007. uint count;
  5008. SLDATATYPE type;
  5009. IntPtr ppbValue;
  5010. uint status = SLGetProductSkuInformation(sl.Handle, ref actId, "DependsOn", out type, out count, out ppbValue);
  5011. return (int)status >= 0 && status != 0xC004F012;
  5012. }
  5013. }
  5014. public static Guid GetLicenseFileId(Guid licId)
  5015. {
  5016. using (SLContext sl = new SLContext())
  5017. {
  5018. uint status;
  5019. uint count;
  5020. IntPtr ppReturnLics;
  5021. status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_LICENSE, ref licId, SLIDTYPE.SL_ID_LICENSE_FILE, out count, out ppReturnLics);
  5022. if (status != 0 || count == 0)
  5023. {
  5024. return Guid.Empty;
  5025. }
  5026. unsafe { return *(Guid*)ppReturnLics; }
  5027. }
  5028. }
  5029. public static Guid GetPkeyConfigFileId(Guid actId)
  5030. {
  5031. using (SLContext sl = new SLContext())
  5032. {
  5033. SLDATATYPE type;
  5034. uint len;
  5035. IntPtr ppReturnLics;
  5036. uint status = SLGetProductSkuInformation(sl.Handle, ref actId, "pkeyConfigLicenseId", out type, out len, out ppReturnLics);
  5037. if (status != 0 || len == 0)
  5038. {
  5039. return Guid.Empty;
  5040. }
  5041. Guid pkcId = new Guid(Marshal.PtrToStringAuto(ppReturnLics));
  5042. return GetLicenseFileId(pkcId);
  5043. }
  5044. }
  5045. public static string GetLicenseContents(Guid fileId)
  5046. {
  5047. if (fileId == Guid.Empty) throw new ArgumentException("License contents could not be retrieved.");
  5048. using (SLContext sl = new SLContext())
  5049. {
  5050. uint dataLen;
  5051. IntPtr dataPtr;
  5052. if (SLGetLicense(sl.Handle, ref fileId, out dataLen, out dataPtr) != 0)
  5053. {
  5054. return null;
  5055. }
  5056. byte[] data = new byte[dataLen];
  5057. Marshal.Copy(dataPtr, data, 0, (int)dataLen);
  5058. data = data.Skip(Array.IndexOf(data, (byte)'<')).ToArray();
  5059. return Encoding.UTF8.GetString(data);
  5060. }
  5061. }
  5062. public static bool IsPhoneActivatable(Guid actId)
  5063. {
  5064. using (SLContext sl = new SLContext())
  5065. {
  5066. uint count;
  5067. SLDATATYPE type;
  5068. IntPtr ppbValue;
  5069. uint status = SLGetProductSkuInformation(sl.Handle, ref actId, "msft:sl/EUL/PHONE/PUBLIC", out type, out count, out ppbValue);
  5070. return status >= 0 && status != 0xC004F012;
  5071. }
  5072. }
  5073. public static string GetPKeyChannel(Guid pkeyId)
  5074. {
  5075. using (SLContext sl = new SLContext())
  5076. {
  5077. SLDATATYPE type;
  5078. uint len;
  5079. IntPtr ppbValue;
  5080. uint status = SLGetPKeyInformation(sl.Handle, ref pkeyId, "Channel", out type, out len, out ppbValue);
  5081. if (status != 0 || len == 0)
  5082. {
  5083. return null;
  5084. }
  5085. return Marshal.PtrToStringAuto(ppbValue);
  5086. }
  5087. }
  5088. public static string GetMetaStr(Guid actId, string value)
  5089. {
  5090. using (SLContext sl = new SLContext())
  5091. {
  5092. uint len;
  5093. SLDATATYPE type;
  5094. IntPtr ppbValue;
  5095. uint status = SLGetProductSkuInformation(sl.Handle, ref actId, value, out type, out len, out ppbValue);
  5096. if (status != 0 || len == 0 || type != SLDATATYPE.SL_DATA_SZ)
  5097. {
  5098. return null;
  5099. }
  5100. return Marshal.PtrToStringAuto(ppbValue);
  5101. }
  5102. }
  5103. public static List<Guid> GetActivationIds(Guid appId)
  5104. {
  5105. using (SLContext sl = new SLContext())
  5106. {
  5107. uint count;
  5108. IntPtr pLicStat;
  5109. SLGetLicensingStatusInformation(sl.Handle, ref appId, IntPtr.Zero, null, out count, out pLicStat);
  5110. List<Guid> result = new List<Guid>();
  5111. unsafe
  5112. {
  5113. SL_LICENSING_STATUS* licensingStatuses = (SL_LICENSING_STATUS*)pLicStat;
  5114. for (int i = 0; i < count; i++)
  5115. {
  5116. result.Add(licensingStatuses[i].SkuId);
  5117. }
  5118. }
  5119. return result;
  5120. }
  5121. }
  5122. public static uint SetCurrentProductKey(Guid actId, Guid pkeyId)
  5123. {
  5124. using (SLContext sl = new SLContext())
  5125. {
  5126. return SLSetCurrentProductKey(sl.Handle, ref actId, ref pkeyId);
  5127. }
  5128. }
  5129. public static uint InstallProductKey(ProductKey pkey)
  5130. {
  5131. using (SLContext sl = new SLContext())
  5132. {
  5133. Guid pkeyId = Guid.Empty;
  5134. return SLInstallProofOfPurchase(sl.Handle, pkey.GetAlgoUri(), pkey.ToString(), 0, null, ref pkeyId);
  5135. }
  5136. }
  5137. public static uint UninstallProductKey(Guid pkeyId)
  5138. {
  5139. using (SLContext sl = new SLContext())
  5140. {
  5141. return SLUninstallProofOfPurchase(sl.Handle, ref pkeyId);
  5142. }
  5143. }
  5144. public static void UninstallAllProductKeys(Guid appId)
  5145. {
  5146. foreach (Guid actId in GetActivationIds(appId))
  5147. {
  5148. Guid pkeyId = GetInstalledPkeyID(actId);
  5149. if (pkeyId == Guid.Empty) continue;
  5150. if (IsAddon(actId)) continue;
  5151. UninstallProductKey(pkeyId);
  5152. }
  5153. }
  5154. }
  5155. }
  5156. // Crypto/CryptoUtils.cs
  5157. namespace LibTSforge.Crypto
  5158. {
  5159. using System;
  5160. using System.Linq;
  5161. using System.Security.Cryptography;
  5162. public static class CryptoUtils
  5163. {
  5164. public static byte[] GenerateRandomKey(int len)
  5165. {
  5166. byte[] rand = new byte[len];
  5167. Random r = new Random();
  5168. r.NextBytes(rand);
  5169. return rand;
  5170. }
  5171. public static byte[] AESEncrypt(byte[] data, byte[] key)
  5172. {
  5173. using (Aes aes = Aes.Create())
  5174. {
  5175. aes.Key = key;
  5176. aes.Mode = CipherMode.CBC;
  5177. aes.Padding = PaddingMode.PKCS7;
  5178. ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, Enumerable.Repeat((byte)0, 16).ToArray());
  5179. byte[] encryptedData = encryptor.TransformFinalBlock(data, 0, data.Length);
  5180. return encryptedData;
  5181. }
  5182. }
  5183. public static byte[] AESDecrypt(byte[] data, byte[] key)
  5184. {
  5185. using (Aes aes = Aes.Create())
  5186. {
  5187. aes.Key = key;
  5188. aes.Mode = CipherMode.CBC;
  5189. aes.Padding = PaddingMode.PKCS7;
  5190. ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, Enumerable.Repeat((byte)0, 16).ToArray());
  5191. byte[] decryptedData = decryptor.TransformFinalBlock(data, 0, data.Length);
  5192. return decryptedData;
  5193. }
  5194. }
  5195. public static byte[] RSADecrypt(byte[] rsaKey, byte[] data)
  5196. {
  5197. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
  5198. {
  5199. rsa.ImportCspBlob(rsaKey);
  5200. return rsa.Decrypt(data, false);
  5201. }
  5202. }
  5203. public static byte[] RSAEncrypt(byte[] rsaKey, byte[] data)
  5204. {
  5205. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
  5206. {
  5207. rsa.ImportCspBlob(rsaKey);
  5208. return rsa.Encrypt(data, false);
  5209. }
  5210. }
  5211. public static byte[] RSASign(byte[] rsaKey, byte[] data)
  5212. {
  5213. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
  5214. {
  5215. rsa.ImportCspBlob(rsaKey);
  5216. RSAPKCS1SignatureFormatter formatter = new RSAPKCS1SignatureFormatter(rsa);
  5217. formatter.SetHashAlgorithm("SHA1");
  5218. byte[] hash;
  5219. using (SHA1 sha1 = SHA1.Create())
  5220. {
  5221. hash = sha1.ComputeHash(data);
  5222. }
  5223. return formatter.CreateSignature(hash);
  5224. }
  5225. }
  5226. public static bool RSAVerifySignature(byte[] rsaKey, byte[] data, byte[] signature)
  5227. {
  5228. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
  5229. {
  5230. rsa.ImportCspBlob(rsaKey);
  5231. RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(rsa);
  5232. deformatter.SetHashAlgorithm("SHA1");
  5233. byte[] hash;
  5234. using (SHA1 sha1 = SHA1.Create())
  5235. {
  5236. hash = sha1.ComputeHash(data);
  5237. }
  5238. return deformatter.VerifySignature(hash, signature);
  5239. }
  5240. }
  5241. public static byte[] HMACSign(byte[] key, byte[] data)
  5242. {
  5243. HMACSHA1 hmac = new HMACSHA1(key);
  5244. return hmac.ComputeHash(data);
  5245. }
  5246. public static bool HMACVerify(byte[] key, byte[] data, byte[] signature)
  5247. {
  5248. HMACSHA1 hmac = new HMACSHA1(key);
  5249. return Enumerable.SequenceEqual(signature, HMACSign(key, data));
  5250. }
  5251. public static byte[] SHA256Hash(byte[] data)
  5252. {
  5253. using (SHA256 sha256 = SHA256.Create())
  5254. {
  5255. return sha256.ComputeHash(data);
  5256. }
  5257. }
  5258. }
  5259. }
  5260. // Crypto/Keys.cs
  5261. namespace LibTSforge.Crypto
  5262. {
  5263. public static class Keys
  5264. {
  5265. public static readonly byte[] PRODUCTION = {
  5266. 0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00,
  5267. 0x01, 0x00, 0x01, 0x00, 0x29, 0x87, 0xBA, 0x3F, 0x52, 0x90, 0x57, 0xD8, 0x12, 0x26, 0x6B, 0x38,
  5268. 0xB2, 0x3B, 0xF9, 0x67, 0x08, 0x4F, 0xDD, 0x8B, 0xF5, 0xE3, 0x11, 0xB8, 0x61, 0x3A, 0x33, 0x42,
  5269. 0x51, 0x65, 0x05, 0x86, 0x1E, 0x00, 0x41, 0xDE, 0xC5, 0xDD, 0x44, 0x60, 0x56, 0x3D, 0x14, 0x39,
  5270. 0xB7, 0x43, 0x65, 0xE9, 0xF7, 0x2B, 0xA5, 0xF0, 0xA3, 0x65, 0x68, 0xE9, 0xE4, 0x8B, 0x5C, 0x03,
  5271. 0x2D, 0x36, 0xFE, 0x28, 0x4C, 0xD1, 0x3C, 0x3D, 0xC1, 0x90, 0x75, 0xF9, 0x6E, 0x02, 0xE0, 0x58,
  5272. 0x97, 0x6A, 0xCA, 0x80, 0x02, 0x42, 0x3F, 0x6C, 0x15, 0x85, 0x4D, 0x83, 0x23, 0x6A, 0x95, 0x9E,
  5273. 0x38, 0x52, 0x59, 0x38, 0x6A, 0x99, 0xF0, 0xB5, 0xCD, 0x53, 0x7E, 0x08, 0x7C, 0xB5, 0x51, 0xD3,
  5274. 0x8F, 0xA3, 0x0D, 0xA0, 0xFA, 0x8D, 0x87, 0x3C, 0xFC, 0x59, 0x21, 0xD8, 0x2E, 0xD9, 0x97, 0x8B,
  5275. 0x40, 0x60, 0xB1, 0xD7, 0x2B, 0x0A, 0x6E, 0x60, 0xB5, 0x50, 0xCC, 0x3C, 0xB1, 0x57, 0xE4, 0xB7,
  5276. 0xDC, 0x5A, 0x4D, 0xE1, 0x5C, 0xE0, 0x94, 0x4C, 0x5E, 0x28, 0xFF, 0xFA, 0x80, 0x6A, 0x13, 0x53,
  5277. 0x52, 0xDB, 0xF3, 0x04, 0x92, 0x43, 0x38, 0xB9, 0x1B, 0xD9, 0x85, 0x54, 0x7B, 0x14, 0xC7, 0x89,
  5278. 0x16, 0x8A, 0x4B, 0x82, 0xA1, 0x08, 0x02, 0x99, 0x23, 0x48, 0xDD, 0x75, 0x9C, 0xC8, 0xC1, 0xCE,
  5279. 0xB0, 0xD7, 0x1B, 0xD8, 0xFB, 0x2D, 0xA7, 0x2E, 0x47, 0xA7, 0x18, 0x4B, 0xF6, 0x29, 0x69, 0x44,
  5280. 0x30, 0x33, 0xBA, 0xA7, 0x1F, 0xCE, 0x96, 0x9E, 0x40, 0xE1, 0x43, 0xF0, 0xE0, 0x0D, 0x0A, 0x32,
  5281. 0xB4, 0xEE, 0xA1, 0xC3, 0x5E, 0x9B, 0xC7, 0x7F, 0xF5, 0x9D, 0xD8, 0xF2, 0x0F, 0xD9, 0x8F, 0xAD,
  5282. 0x75, 0x0A, 0x00, 0xD5, 0x25, 0x43, 0xF7, 0xAE, 0x51, 0x7F, 0xB7, 0xDE, 0xB7, 0xAD, 0xFB, 0xCE,
  5283. 0x83, 0xE1, 0x81, 0xFF, 0xDD, 0xA2, 0x77, 0xFE, 0xEB, 0x27, 0x1F, 0x10, 0xFA, 0x82, 0x37, 0xF4,
  5284. 0x7E, 0xCC, 0xE2, 0xA1, 0x58, 0xC8, 0xAF, 0x1D, 0x1A, 0x81, 0x31, 0x6E, 0xF4, 0x8B, 0x63, 0x34,
  5285. 0xF3, 0x05, 0x0F, 0xE1, 0xCC, 0x15, 0xDC, 0xA4, 0x28, 0x7A, 0x9E, 0xEB, 0x62, 0xD8, 0xD8, 0x8C,
  5286. 0x85, 0xD7, 0x07, 0x87, 0x90, 0x2F, 0xF7, 0x1C, 0x56, 0x85, 0x2F, 0xEF, 0x32, 0x37, 0x07, 0xAB,
  5287. 0xB0, 0xE6, 0xB5, 0x02, 0x19, 0x35, 0xAF, 0xDB, 0xD4, 0xA2, 0x9C, 0x36, 0x80, 0xC6, 0xDC, 0x82,
  5288. 0x08, 0xE0, 0xC0, 0x5F, 0x3C, 0x59, 0xAA, 0x4E, 0x26, 0x03, 0x29, 0xB3, 0x62, 0x58, 0x41, 0x59,
  5289. 0x3A, 0x37, 0x43, 0x35, 0xE3, 0x9F, 0x34, 0xE2, 0xA1, 0x04, 0x97, 0x12, 0x9D, 0x8C, 0xAD, 0xF7,
  5290. 0xFB, 0x8C, 0xA1, 0xA2, 0xE9, 0xE4, 0xEF, 0xD9, 0xC5, 0xE5, 0xDF, 0x0E, 0xBF, 0x4A, 0xE0, 0x7A,
  5291. 0x1E, 0x10, 0x50, 0x58, 0x63, 0x51, 0xE1, 0xD4, 0xFE, 0x57, 0xB0, 0x9E, 0xD7, 0xDA, 0x8C, 0xED,
  5292. 0x7D, 0x82, 0xAC, 0x2F, 0x25, 0x58, 0x0A, 0x58, 0xE6, 0xA4, 0xF4, 0x57, 0x4B, 0xA4, 0x1B, 0x65,
  5293. 0xB9, 0x4A, 0x87, 0x46, 0xEB, 0x8C, 0x0F, 0x9A, 0x48, 0x90, 0xF9, 0x9F, 0x76, 0x69, 0x03, 0x72,
  5294. 0x77, 0xEC, 0xC1, 0x42, 0x4C, 0x87, 0xDB, 0x0B, 0x3C, 0xD4, 0x74, 0xEF, 0xE5, 0x34, 0xE0, 0x32,
  5295. 0x45, 0xB0, 0xF8, 0xAB, 0xD5, 0x26, 0x21, 0xD7, 0xD2, 0x98, 0x54, 0x8F, 0x64, 0x88, 0x20, 0x2B,
  5296. 0x14, 0xE3, 0x82, 0xD5, 0x2A, 0x4B, 0x8F, 0x4E, 0x35, 0x20, 0x82, 0x7E, 0x1B, 0xFE, 0xFA, 0x2C,
  5297. 0x79, 0x6C, 0x6E, 0x66, 0x94, 0xBB, 0x0A, 0xEB, 0xBA, 0xD9, 0x70, 0x61, 0xE9, 0x47, 0xB5, 0x82,
  5298. 0xFC, 0x18, 0x3C, 0x66, 0x3A, 0x09, 0x2E, 0x1F, 0x61, 0x74, 0xCA, 0xCB, 0xF6, 0x7A, 0x52, 0x37,
  5299. 0x1D, 0xAC, 0x8D, 0x63, 0x69, 0x84, 0x8E, 0xC7, 0x70, 0x59, 0xDD, 0x2D, 0x91, 0x1E, 0xF7, 0xB1,
  5300. 0x56, 0xED, 0x7A, 0x06, 0x9D, 0x5B, 0x33, 0x15, 0xDD, 0x31, 0xD0, 0xE6, 0x16, 0x07, 0x9B, 0xA5,
  5301. 0x94, 0x06, 0x7D, 0xC1, 0xE9, 0xD6, 0xC8, 0xAF, 0xB4, 0x1E, 0x2D, 0x88, 0x06, 0xA7, 0x63, 0xB8,
  5302. 0xCF, 0xC8, 0xA2, 0x6E, 0x84, 0xB3, 0x8D, 0xE5, 0x47, 0xE6, 0x13, 0x63, 0x8E, 0xD1, 0x7F, 0xD4,
  5303. 0x81, 0x44, 0x38, 0xBF
  5304. };
  5305. public static readonly byte[] TEST = {
  5306. 0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00,
  5307. 0x01, 0x00, 0x01, 0x00, 0x0F, 0xBE, 0x77, 0xB8, 0xDD, 0x54, 0x36, 0xDD, 0x67, 0xD4, 0x17, 0x66,
  5308. 0xC4, 0x13, 0xD1, 0x3F, 0x1E, 0x16, 0x0C, 0x16, 0x35, 0xAB, 0x6D, 0x3D, 0x34, 0x51, 0xED, 0x3F,
  5309. 0x57, 0x14, 0xB6, 0xB7, 0x08, 0xE9, 0xD9, 0x7A, 0x80, 0xB3, 0x5F, 0x9B, 0x3A, 0xFD, 0x9E, 0x37,
  5310. 0x3A, 0x53, 0x72, 0x67, 0x92, 0x60, 0xC3, 0xEF, 0xB5, 0x8E, 0x1E, 0xCF, 0x9D, 0x9C, 0xD3, 0x90,
  5311. 0xE5, 0xDD, 0xF4, 0xDB, 0xF3, 0xD6, 0x65, 0xB3, 0xC1, 0xBD, 0x69, 0xE1, 0x76, 0x95, 0xD9, 0x37,
  5312. 0xB8, 0x5E, 0xCA, 0x3D, 0x98, 0xFC, 0x50, 0x5C, 0x98, 0xAE, 0xE3, 0x7C, 0x4C, 0x27, 0xC3, 0xD0,
  5313. 0xCE, 0x78, 0x06, 0x51, 0x68, 0x23, 0xE6, 0x70, 0xF8, 0x7C, 0xAE, 0x36, 0xBE, 0x41, 0x57, 0xE2,
  5314. 0xC3, 0x2D, 0xAF, 0x21, 0xB1, 0xB3, 0x15, 0x81, 0x19, 0x26, 0x6B, 0x10, 0xB3, 0xE9, 0xD1, 0x45,
  5315. 0x21, 0x77, 0x9C, 0xF6, 0xE1, 0xDD, 0xB6, 0x78, 0x9D, 0x1D, 0x32, 0x61, 0xBC, 0x2B, 0xDB, 0x86,
  5316. 0xFB, 0x07, 0x24, 0x10, 0x19, 0x4F, 0x09, 0x6D, 0x03, 0x90, 0xD4, 0x5E, 0x30, 0x85, 0xC5, 0x58,
  5317. 0x7E, 0x5D, 0xAE, 0x9F, 0x64, 0x93, 0x04, 0x82, 0x09, 0x0E, 0x1C, 0x66, 0xA8, 0x95, 0x91, 0x51,
  5318. 0xB2, 0xED, 0x9A, 0x75, 0x04, 0x87, 0x50, 0xAC, 0xCC, 0x20, 0x06, 0x45, 0xB9, 0x7B, 0x42, 0x53,
  5319. 0x9A, 0xD1, 0x29, 0xFC, 0xEF, 0xB9, 0x47, 0x16, 0x75, 0x69, 0x05, 0x87, 0x2B, 0xCB, 0x54, 0x9C,
  5320. 0x21, 0x2D, 0x50, 0x8E, 0x12, 0xDE, 0xD3, 0x6B, 0xEC, 0x92, 0xA1, 0xB1, 0xE9, 0x4B, 0xBF, 0x6B,
  5321. 0x9A, 0x38, 0xC7, 0x13, 0xFA, 0x78, 0xA1, 0x3C, 0x1E, 0xBB, 0x38, 0x31, 0xBB, 0x0C, 0x9F, 0x70,
  5322. 0x1A, 0x31, 0x00, 0xD7, 0x5A, 0xA5, 0x84, 0x24, 0x89, 0x80, 0xF5, 0x88, 0xC2, 0x31, 0x18, 0xDC,
  5323. 0x53, 0x05, 0x5D, 0xFA, 0x81, 0xDC, 0xE1, 0xCE, 0xA4, 0xAA, 0xBA, 0x07, 0xDA, 0x28, 0x4F, 0x64,
  5324. 0x0E, 0x84, 0x9B, 0x06, 0xDE, 0xC8, 0x78, 0x66, 0x2F, 0x17, 0x25, 0xA8, 0x9C, 0x99, 0xFC, 0xBC,
  5325. 0x7D, 0x01, 0x42, 0xD7, 0x35, 0xBF, 0x19, 0xF6, 0x3F, 0x20, 0xD9, 0x98, 0x9B, 0x5D, 0xDD, 0x39,
  5326. 0xBE, 0x81, 0x00, 0x0B, 0xDE, 0x6F, 0x14, 0xCA, 0x7E, 0xF8, 0xC0, 0x26, 0xA8, 0x1D, 0xD1, 0x16,
  5327. 0x88, 0x64, 0x87, 0x36, 0x45, 0x37, 0x50, 0xDA, 0x6C, 0xEB, 0x85, 0xB5, 0x43, 0x29, 0x88, 0x6F,
  5328. 0x2F, 0xFE, 0x8D, 0x12, 0x8B, 0x72, 0xB7, 0x5A, 0xCB, 0x66, 0xC2, 0x2E, 0x1D, 0x7D, 0x42, 0xA6,
  5329. 0xF4, 0xFE, 0x26, 0x5D, 0x54, 0x9E, 0x77, 0x1D, 0x97, 0xC2, 0xF3, 0xFD, 0x60, 0xB3, 0x22, 0x88,
  5330. 0xCA, 0x27, 0x99, 0xDF, 0xC8, 0xB1, 0xD7, 0xC6, 0x54, 0xA6, 0x50, 0xB9, 0x54, 0xF5, 0xDE, 0xFE,
  5331. 0xE1, 0x81, 0xA2, 0xBE, 0x81, 0x9F, 0x48, 0xFF, 0x2F, 0xB8, 0xA4, 0xB3, 0x17, 0xD8, 0xC1, 0xB9,
  5332. 0x5D, 0x21, 0x3D, 0xA2, 0xED, 0x1C, 0x96, 0x66, 0xEE, 0x1F, 0x47, 0xCF, 0x62, 0xFA, 0xD6, 0xC1,
  5333. 0x87, 0x5B, 0xC4, 0xE5, 0xD9, 0x08, 0x38, 0x22, 0xFA, 0x21, 0xBD, 0xF2, 0x88, 0xDA, 0xE2, 0x24,
  5334. 0x25, 0x1F, 0xF1, 0x0B, 0x2D, 0xAE, 0x04, 0xBE, 0xA6, 0x7F, 0x75, 0x8C, 0xD9, 0x97, 0xE1, 0xCA,
  5335. 0x35, 0xB9, 0xFC, 0x6F, 0x01, 0x68, 0x11, 0xD3, 0x68, 0x32, 0xD0, 0xC1, 0x69, 0xA3, 0xCF, 0x9B,
  5336. 0x10, 0xE4, 0x69, 0xA7, 0xCF, 0xE1, 0xFE, 0x2A, 0x07, 0x9E, 0xC1, 0x37, 0x84, 0x68, 0xE5, 0xC5,
  5337. 0xAB, 0x25, 0xEC, 0x7D, 0x7D, 0x74, 0x6A, 0xD1, 0xD5, 0x4D, 0xD7, 0xE1, 0x7D, 0xDE, 0x30, 0x4B,
  5338. 0xE6, 0x5D, 0xCD, 0x91, 0x59, 0xF6, 0x80, 0xFD, 0xC6, 0x3C, 0xDD, 0x94, 0x7F, 0x15, 0x9D, 0xEF,
  5339. 0x2F, 0x00, 0x62, 0xD7, 0xDA, 0xB9, 0xB3, 0xD9, 0x8D, 0xE8, 0xD7, 0x3C, 0x96, 0x45, 0x5D, 0x1E,
  5340. 0x50, 0xFB, 0xAA, 0x43, 0xD3, 0x47, 0x77, 0x81, 0xE9, 0x67, 0xE4, 0xFE, 0xDF, 0x42, 0x79, 0xCB,
  5341. 0xA7, 0xAD, 0x5D, 0x48, 0xF5, 0xB7, 0x74, 0x96, 0x12, 0x23, 0x06, 0x70, 0x42, 0x68, 0x7A, 0x44,
  5342. 0xFC, 0xA0, 0x31, 0x7F, 0x68, 0xCA, 0xA2, 0x14, 0x5D, 0xA3, 0xCF, 0x42, 0x23, 0xAB, 0x47, 0xF6,
  5343. 0xB2, 0xFC, 0x6D, 0xF1
  5344. };
  5345. }
  5346. }
  5347. // Crypto/PhysStoreCrypto.cs
  5348. namespace LibTSforge.Crypto
  5349. {
  5350. using System;
  5351. using System.Collections.Generic;
  5352. using System.IO;
  5353. using System.Linq;
  5354. using System.Text;
  5355. public static class PhysStoreCrypto
  5356. {
  5357. public static byte[] DecryptPhysicalStore(byte[] data, bool production)
  5358. {
  5359. byte[] rsaKey = production ? Keys.PRODUCTION : Keys.TEST;
  5360. BinaryReader br = new BinaryReader(new MemoryStream(data));
  5361. br.BaseStream.Seek(0x10, SeekOrigin.Begin);
  5362. byte[] aesKeySig = br.ReadBytes(0x80);
  5363. byte[] encAesKey = br.ReadBytes(0x80);
  5364. if (CryptoUtils.RSAVerifySignature(rsaKey, encAesKey, aesKeySig))
  5365. {
  5366. byte[] aesKey = CryptoUtils.RSADecrypt(rsaKey, encAesKey);
  5367. byte[] decData = CryptoUtils.AESDecrypt(br.ReadBytes((int)br.BaseStream.Length - 0x110), aesKey);
  5368. byte[] hmacKey = decData.Take(0x10).ToArray();
  5369. byte[] hmacSig = decData.Skip(0x10).Take(0x14).ToArray();
  5370. byte[] psData = decData.Skip(0x28).ToArray();
  5371. if (!CryptoUtils.HMACVerify(hmacKey, psData, hmacSig))
  5372. {
  5373. Logger.WriteLine("Warning: Failed to verify HMAC. Physical store is either corrupt or in Vista format.");
  5374. }
  5375. return psData;
  5376. }
  5377. throw new Exception("Failed to decrypt physical store.");
  5378. }
  5379. public static byte[] EncryptPhysicalStore(byte[] data, bool production, PSVersion version)
  5380. {
  5381. Dictionary<PSVersion, int> versionTable = new Dictionary<PSVersion, int>
  5382. {
  5383. {PSVersion.Win7, 5},
  5384. {PSVersion.Win8, 1},
  5385. {PSVersion.WinBlue, 2},
  5386. {PSVersion.WinModern, 3}
  5387. };
  5388. byte[] rsaKey = production ? Keys.PRODUCTION : Keys.TEST;
  5389. byte[] aesKey = Encoding.UTF8.GetBytes("massgrave.dev :3");
  5390. byte[] hmacKey = CryptoUtils.GenerateRandomKey(0x10);
  5391. byte[] encAesKey = CryptoUtils.RSAEncrypt(rsaKey, aesKey);
  5392. byte[] aesKeySig = CryptoUtils.RSASign(rsaKey, encAesKey);
  5393. byte[] hmacSig = CryptoUtils.HMACSign(hmacKey, data);
  5394. byte[] decData = new byte[] { };
  5395. decData = decData.Concat(hmacKey).Concat(hmacSig).Concat(BitConverter.GetBytes(0)).Concat(data).ToArray();
  5396. byte[] encData = CryptoUtils.AESEncrypt(decData, aesKey);
  5397. BinaryWriter bw = new BinaryWriter(new MemoryStream());
  5398. bw.Write(versionTable[version]);
  5399. bw.Write(Encoding.UTF8.GetBytes("UNTRUSTSTORE"));
  5400. bw.Write(aesKeySig);
  5401. bw.Write(encAesKey);
  5402. bw.Write(encData);
  5403. return bw.GetBytes();
  5404. }
  5405. }
  5406. }
  5407. // Modifiers/GenPKeyInstall.cs
  5408. namespace LibTSforge.Modifiers
  5409. {
  5410. using System;
  5411. using System.IO;
  5412. using Microsoft.Win32;
  5413. using LibTSforge.PhysicalStore;
  5414. using LibTSforge.SPP;
  5415. using LibTSforge.TokenStore;
  5416. public static class GenPKeyInstall
  5417. {
  5418. private static void WritePkey2005RegistryValues(PSVersion version, ProductKey pkey)
  5419. {
  5420. Logger.WriteLine("Writing registry data for Windows product key...");
  5421. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductId", pkey.GetPid2());
  5422. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId", pkey.GetPid3());
  5423. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId4", pkey.GetPid4());
  5424. if (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Registration", "ProductId", null) != null)
  5425. {
  5426. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Registration", "ProductId", pkey.GetPid2());
  5427. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Registration", "DigitalProductId", pkey.GetPid3());
  5428. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Registration", "DigitalProductId4", pkey.GetPid4());
  5429. }
  5430. if (pkey.Channel == "Volume:CSVLK" && version != PSVersion.Win7)
  5431. {
  5432. Registry.SetValue(@"HKEY_USERS\S-1-5-20\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", "KmsHostConfig", 1);
  5433. }
  5434. }
  5435. public static void InstallGenPKey(PSVersion version, bool production, Guid actId)
  5436. {
  5437. if (actId == Guid.Empty) throw new ArgumentException("Activation ID must be specified for generated product key install.");
  5438. PKeyConfig pkc = new PKeyConfig();
  5439. try
  5440. {
  5441. pkc.LoadConfig(actId);
  5442. }
  5443. catch (ArgumentException)
  5444. {
  5445. pkc.LoadAllConfigs(SLApi.GetAppId(actId));
  5446. }
  5447. ProductConfig config;
  5448. pkc.Products.TryGetValue(actId, out config);
  5449. if (config == null) throw new ArgumentException("Activation ID " + actId + " not found in PKeyConfig.");
  5450. ProductKey pkey = config.GetRandomKey();
  5451. Guid instPkeyId = SLApi.GetInstalledPkeyID(actId);
  5452. if (instPkeyId != Guid.Empty) SLApi.UninstallProductKey(instPkeyId);
  5453. if (pkey.Algorithm == PKeyAlgorithm.PKEY2009)
  5454. {
  5455. uint status = SLApi.InstallProductKey(pkey);
  5456. Logger.WriteLine(string.Format("Installing generated product key {0} status {1:X}", pkey.ToString(), status));
  5457. if ((int)status < 0)
  5458. {
  5459. throw new ApplicationException("Failed to install generated product key.");
  5460. }
  5461. Logger.WriteLine("Successfully deposited generated product key.");
  5462. return;
  5463. }
  5464. Logger.WriteLine("Key range is PKEY2005, creating fake key data...");
  5465. if (pkey.Channel == "Volume:GVLK" && version == PSVersion.Win7) throw new NotSupportedException("Fake GVLK generation is not supported on Windows 7.");
  5466. VariableBag pkb = new VariableBag();
  5467. pkb.Blocks.AddRange(new CRCBlock[]
  5468. {
  5469. new CRCBlock
  5470. {
  5471. DataType = CRCBlockType.STRING,
  5472. KeyAsStr = "SppPkeyBindingProductKey",
  5473. ValueAsStr = pkey.ToString()
  5474. },
  5475. new CRCBlock
  5476. {
  5477. DataType = CRCBlockType.STRING,
  5478. KeyAsStr = "SppPkeyBindingMPC",
  5479. ValueAsStr = pkey.GetMPC()
  5480. },
  5481. new CRCBlock {
  5482. DataType = CRCBlockType.BINARY,
  5483. KeyAsStr = "SppPkeyBindingPid2",
  5484. ValueAsStr = pkey.GetPid2()
  5485. },
  5486. new CRCBlock
  5487. {
  5488. DataType = CRCBlockType.BINARY,
  5489. KeyAsStr = "SppPkeyBindingPid3",
  5490. Value = pkey.GetPid3()
  5491. },
  5492. new CRCBlock
  5493. {
  5494. DataType = CRCBlockType.BINARY,
  5495. KeyAsStr = "SppPkeyBindingPid4",
  5496. Value = pkey.GetPid4()
  5497. },
  5498. new CRCBlock
  5499. {
  5500. DataType = CRCBlockType.STRING,
  5501. KeyAsStr = "SppPkeyChannelId",
  5502. ValueAsStr = pkey.Channel
  5503. },
  5504. new CRCBlock
  5505. {
  5506. DataType = CRCBlockType.STRING,
  5507. KeyAsStr = "SppPkeyBindingEditionId",
  5508. ValueAsStr = pkey.Edition
  5509. },
  5510. new CRCBlock
  5511. {
  5512. DataType = CRCBlockType.BINARY,
  5513. KeyAsStr = (version == PSVersion.Win7) ? "SppPkeyShortAuthenticator" : "SppPkeyPhoneActivationData",
  5514. Value = pkey.GetPhoneData(version)
  5515. },
  5516. new CRCBlock
  5517. {
  5518. DataType = CRCBlockType.BINARY,
  5519. KeyAsStr = "SppPkeyBindingMiscData",
  5520. Value = new byte[] { }
  5521. }
  5522. });
  5523. Guid appId = SLApi.GetAppId(actId);
  5524. string pkeyId = pkey.GetPkeyId().ToString();
  5525. bool isAddon = SLApi.IsAddon(actId);
  5526. string currEdition = SLApi.GetMetaStr(actId, "Family");
  5527. if (appId == SLApi.WINDOWS_APP_ID && !isAddon)
  5528. {
  5529. SLApi.UninstallAllProductKeys(appId);
  5530. }
  5531. Utils.KillSPP();
  5532. using (IPhysicalStore ps = Utils.GetStore(version, production))
  5533. {
  5534. using (ITokenStore tks = Utils.GetTokenStore(version))
  5535. {
  5536. Logger.WriteLine("Writing to physical store and token store...");
  5537. string suffix = (version == PSVersion.Win8 || version == PSVersion.WinBlue || version == PSVersion.WinModern) ? "_--" : "";
  5538. string metSuffix = suffix + "_met";
  5539. if (appId == SLApi.WINDOWS_APP_ID && !isAddon)
  5540. {
  5541. string edTokName = "msft:spp/token/windows/productkeyid/" + currEdition;
  5542. TokenMeta edToken = tks.GetMetaEntry(edTokName);
  5543. edToken.Data["windowsComponentEditionPkeyId"] = pkeyId;
  5544. edToken.Data["windowsComponentEditionSkuId"] = actId.ToString();
  5545. tks.SetEntry(edTokName, "xml", edToken.Serialize());
  5546. WritePkey2005RegistryValues(version, pkey);
  5547. }
  5548. string uriMapName = "msft:spp/token/PKeyIdUriMapper" + metSuffix;
  5549. TokenMeta uriMap = tks.GetMetaEntry(uriMapName);
  5550. uriMap.Data[pkeyId] = pkey.GetAlgoUri();
  5551. tks.SetEntry(uriMapName, "xml", uriMap.Serialize());
  5552. string skuMetaName = actId.ToString() + metSuffix;
  5553. TokenMeta skuMeta = tks.GetMetaEntry(skuMetaName);
  5554. foreach (string k in skuMeta.Data.Keys)
  5555. {
  5556. if (k.StartsWith("pkeyId_"))
  5557. {
  5558. skuMeta.Data.Remove(k);
  5559. break;
  5560. }
  5561. }
  5562. skuMeta.Data["pkeyId"] = pkeyId;
  5563. skuMeta.Data["pkeyIdList"] = pkeyId;
  5564. tks.SetEntry(skuMetaName, "xml", skuMeta.Serialize());
  5565. string psKey = string.Format("SPPSVC\\{0}\\{1}", appId, actId);
  5566. ps.DeleteBlock(psKey, pkeyId);
  5567. ps.AddBlock(new PSBlock
  5568. {
  5569. Type = BlockType.NAMED,
  5570. Flags = (version == PSVersion.WinModern) ? (uint)0x402 : 0x2,
  5571. KeyAsStr = psKey,
  5572. ValueAsStr = pkeyId,
  5573. Data = pkb.Serialize()
  5574. });
  5575. string cachePath = Utils.GetTokensPath(version).Replace("tokens.dat", @"cache\cache.dat");
  5576. if (File.Exists(cachePath)) File.Delete(cachePath);
  5577. }
  5578. }
  5579. SLApi.RefreshTrustedTime(actId);
  5580. Logger.WriteLine("Successfully deposited fake product key.");
  5581. }
  5582. }
  5583. }
  5584. // Modifiers/GracePeriodReset.cs
  5585. namespace LibTSforge.Modifiers
  5586. {
  5587. using System;
  5588. using System.Collections.Generic;
  5589. using System.Linq;
  5590. using LibTSforge.PhysicalStore;
  5591. public static class GracePeriodReset
  5592. {
  5593. public static void Reset(PSVersion version, bool production)
  5594. {
  5595. Utils.KillSPP();
  5596. Logger.WriteLine("Writing TrustedStore data...");
  5597. using (IPhysicalStore store = Utils.GetStore(version, production))
  5598. {
  5599. string value = "msft:sl/timer";
  5600. List<PSBlock> blocks = store.FindBlocks(value).ToList();
  5601. foreach (PSBlock block in blocks)
  5602. {
  5603. store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);
  5604. }
  5605. }
  5606. Logger.WriteLine("Successfully reset all grace and evaluation period timers.");
  5607. }
  5608. }
  5609. }
  5610. // Modifiers/KeyChangeLockDelete.cs
  5611. namespace LibTSforge.Modifiers
  5612. {
  5613. using System.Collections.Generic;
  5614. using System.Linq;
  5615. using LibTSforge.PhysicalStore;
  5616. using LibTSforge;
  5617. public static class KeyChangeLockDelete
  5618. {
  5619. public static void Delete(PSVersion version, bool production)
  5620. {
  5621. Utils.KillSPP();
  5622. Logger.WriteLine("Writing TrustedStore data...");
  5623. using (IPhysicalStore store = Utils.GetStore(version, production))
  5624. {
  5625. List<string> values = new List<string>
  5626. {
  5627. "msft:spp/timebased/AB",
  5628. "msft:spp/timebased/CD"
  5629. };
  5630. List<PSBlock> blocks = new List<PSBlock>();
  5631. foreach (string value in values)
  5632. {
  5633. blocks.AddRange(store.FindBlocks(value).ToList());
  5634. }
  5635. foreach (PSBlock block in blocks)
  5636. {
  5637. store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);
  5638. }
  5639. }
  5640. Logger.WriteLine("Successfully removed the key change lock.");
  5641. }
  5642. }
  5643. }
  5644. // Modifiers/KMSHostCharge.cs
  5645. namespace LibTSforge.Modifiers
  5646. {
  5647. using System;
  5648. using System.IO;
  5649. using LibTSforge.PhysicalStore;
  5650. using LibTSforge.SPP;
  5651. public static class KMSHostCharge
  5652. {
  5653. public static void Charge(PSVersion version, Guid actId, bool production)
  5654. {
  5655. if (actId == Guid.Empty)
  5656. {
  5657. actId = SLApi.GetDefaultActivationID(SLApi.WINDOWS_APP_ID, true);
  5658. if (actId == Guid.Empty)
  5659. {
  5660. throw new NotSupportedException("No applicable activation IDs found.");
  5661. }
  5662. }
  5663. if (SLApi.GetPKeyChannel(SLApi.GetInstalledPkeyID(actId)) != "Volume:CSVLK")
  5664. {
  5665. throw new NotSupportedException("Non-Volume:CSVLK product key installed.");
  5666. }
  5667. Guid appId = SLApi.GetAppId(actId);
  5668. int totalClients = 50;
  5669. int currClients = 25;
  5670. byte[] hwidBlock = Constants.UniversalHWIDBlock;
  5671. string key = string.Format("SPPSVC\\{0}", appId);
  5672. long ldapTimestamp = DateTime.Now.ToFileTime();
  5673. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  5674. for (int i = 0; i < currClients; i++)
  5675. {
  5676. writer.Write(ldapTimestamp - (10 * (i + 1)));
  5677. writer.Write(Guid.NewGuid().ToByteArray());
  5678. }
  5679. byte[] cmidGuids = writer.GetBytes();
  5680. writer = new BinaryWriter(new MemoryStream());
  5681. writer.Write(new byte[40]);
  5682. writer.Seek(4, SeekOrigin.Begin);
  5683. writer.Write((byte)currClients);
  5684. writer.Seek(24, SeekOrigin.Begin);
  5685. writer.Write((byte)currClients);
  5686. byte[] reqCounts = writer.GetBytes();
  5687. Utils.KillSPP();
  5688. Logger.WriteLine("Writing TrustedStore data...");
  5689. using (IPhysicalStore store = Utils.GetStore(version, production))
  5690. {
  5691. VariableBag kmsCountData = new VariableBag();
  5692. kmsCountData.Blocks.AddRange(new CRCBlock[]
  5693. {
  5694. new CRCBlock
  5695. {
  5696. DataType = CRCBlockType.BINARY,
  5697. KeyAsStr = "SppBindingLicenseData",
  5698. Value = hwidBlock
  5699. },
  5700. new CRCBlock
  5701. {
  5702. DataType = CRCBlockType.UINT,
  5703. Key = new byte[] { },
  5704. ValueAsInt = (uint)totalClients
  5705. },
  5706. new CRCBlock
  5707. {
  5708. DataType = CRCBlockType.UINT,
  5709. Key = new byte[] { },
  5710. ValueAsInt = 1051200000
  5711. },
  5712. new CRCBlock
  5713. {
  5714. DataType = CRCBlockType.UINT,
  5715. Key = new byte[] { },
  5716. ValueAsInt = (uint)currClients
  5717. },
  5718. new CRCBlock
  5719. {
  5720. DataType = CRCBlockType.BINARY,
  5721. Key = new byte[] { },
  5722. Value = cmidGuids
  5723. },
  5724. new CRCBlock
  5725. {
  5726. DataType = CRCBlockType.BINARY,
  5727. Key = new byte[] { },
  5728. Value = reqCounts
  5729. }
  5730. });
  5731. byte[] kmsChargeData = kmsCountData.Serialize();
  5732. string countVal = string.Format("msft:spp/kms/host/2.0/store/counters/{0}", appId);
  5733. store.DeleteBlock(key, countVal);
  5734. store.AddBlock(new PSBlock
  5735. {
  5736. Type = BlockType.NAMED,
  5737. Flags = (version == PSVersion.WinModern) ? (uint)0x400 : 0,
  5738. KeyAsStr = key,
  5739. ValueAsStr = countVal,
  5740. Data = kmsChargeData
  5741. });
  5742. Logger.WriteLine(string.Format("Set charge count to {0} successfully.", currClients));
  5743. }
  5744. }
  5745. }
  5746. }
  5747. // Modifiers/RearmReset.cs
  5748. namespace LibTSforge.Modifiers
  5749. {
  5750. using System;
  5751. using System.Collections.Generic;
  5752. using System.Linq;
  5753. using LibTSforge.PhysicalStore;
  5754. public static class RearmReset
  5755. {
  5756. public static void Reset(PSVersion version, bool production)
  5757. {
  5758. Utils.KillSPP();
  5759. Logger.WriteLine("Writing TrustedStore data...");
  5760. using (IPhysicalStore store = Utils.GetStore(version, production))
  5761. {
  5762. List<PSBlock> blocks;
  5763. if (version == PSVersion.Win7)
  5764. {
  5765. blocks = store.FindBlocks(0xA0000).ToList();
  5766. }
  5767. else
  5768. {
  5769. blocks = store.FindBlocks("__##USERSEP-RESERVED##__$$REARM-COUNT$$").ToList();
  5770. }
  5771. foreach (PSBlock block in blocks)
  5772. {
  5773. if (version == PSVersion.Win7)
  5774. {
  5775. store.SetBlock(block.KeyAsStr, block.ValueAsInt, new byte[8]);
  5776. }
  5777. else
  5778. {
  5779. store.SetBlock(block.KeyAsStr, block.ValueAsStr, new byte[8]);
  5780. }
  5781. }
  5782. Logger.WriteLine("Successfully reset all rearm counters.");
  5783. }
  5784. }
  5785. }
  5786. }
  5787. // Modifiers/TamperedFlagsDelete.cs
  5788. namespace LibTSforge.Modifiers
  5789. {
  5790. using System;
  5791. using System.Linq;
  5792. using LibTSforge.PhysicalStore;
  5793. public static class TamperedFlagsDelete
  5794. {
  5795. public static void DeleteTamperFlags(PSVersion version, bool production)
  5796. {
  5797. Utils.KillSPP();
  5798. Logger.WriteLine("Writing TrustedStore data...");
  5799. using (IPhysicalStore store = Utils.GetStore(version, production))
  5800. {
  5801. if (version != PSVersion.Win7)
  5802. {
  5803. string recreatedFlag = "__##USERSEP-RESERVED##__$$RECREATED-FLAG$$";
  5804. string recoveredFlag = "__##USERSEP-RESERVED##__$$RECOVERED-FLAG$$";
  5805. DeleteFlag(store, recreatedFlag);
  5806. DeleteFlag(store, recoveredFlag);
  5807. }
  5808. else
  5809. {
  5810. SetFlag(store, 0xA0001);
  5811. }
  5812. Logger.WriteLine("Successfully cleared the tamper state.");
  5813. }
  5814. }
  5815. private static void DeleteFlag(IPhysicalStore store, string flag)
  5816. {
  5817. store.FindBlocks(flag).ToList().ForEach(block => store.DeleteBlock(block.KeyAsStr, block.ValueAsStr));
  5818. }
  5819. private static void SetFlag(IPhysicalStore store, uint flag)
  5820. {
  5821. store.FindBlocks(flag).ToList().ForEach(block => store.SetBlock(block.KeyAsStr, block.ValueAsInt, new byte[8]));
  5822. }
  5823. }
  5824. }
  5825. // Modifiers/UniqueIdDelete.cs
  5826. namespace LibTSforge.Modifiers
  5827. {
  5828. using System;
  5829. using LibTSforge.PhysicalStore;
  5830. using LibTSforge.SPP;
  5831. public static class UniqueIdDelete
  5832. {
  5833. public static void DeleteUniqueId(PSVersion version, bool production, Guid actId)
  5834. {
  5835. Guid appId;
  5836. if (actId == Guid.Empty)
  5837. {
  5838. appId = SLApi.WINDOWS_APP_ID;
  5839. actId = SLApi.GetDefaultActivationID(appId, true);
  5840. if (actId == Guid.Empty)
  5841. {
  5842. throw new Exception("No applicable activation IDs found.");
  5843. }
  5844. }
  5845. else
  5846. {
  5847. appId = SLApi.GetAppId(actId);
  5848. }
  5849. string instId = SLApi.GetInstallationID(actId);
  5850. Guid pkeyId = SLApi.GetInstalledPkeyID(actId);
  5851. Utils.KillSPP();
  5852. Logger.WriteLine("Writing TrustedStore data...");
  5853. using (IPhysicalStore store = Utils.GetStore(version, production))
  5854. {
  5855. string key = string.Format("SPPSVC\\{0}\\{1}", appId, actId);
  5856. PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());
  5857. if (keyBlock == null)
  5858. {
  5859. throw new Exception("No product key found.");
  5860. }
  5861. VariableBag pkb = new VariableBag(keyBlock.Data);
  5862. pkb.DeleteBlock("SppPkeyUniqueIdToken");
  5863. store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());
  5864. }
  5865. Logger.WriteLine("Successfully removed Unique ID for product key ID " + pkeyId);
  5866. }
  5867. }
  5868. }
  5869. // Activators/ZeroCID.cs
  5870. namespace LibTSforge.Activators
  5871. {
  5872. using System;
  5873. using System.IO;
  5874. using LibTSforge.Crypto;
  5875. using LibTSforge.PhysicalStore;
  5876. using LibTSforge.SPP;
  5877. public static class ZeroCID
  5878. {
  5879. public static void Deposit(Guid actId, string instId)
  5880. {
  5881. uint status = SLApi.DepositConfirmationID(actId, instId, Constants.ZeroCID);
  5882. Logger.WriteLine(string.Format("Depositing fake CID status {0:X}", status));
  5883. if (status != 0)
  5884. {
  5885. throw new InvalidOperationException("Failed to deposit fake CID.");
  5886. }
  5887. }
  5888. public static void Activate(PSVersion version, bool production, Guid actId)
  5889. {
  5890. Guid appId;
  5891. if (actId == Guid.Empty)
  5892. {
  5893. appId = SLApi.WINDOWS_APP_ID;
  5894. actId = SLApi.GetDefaultActivationID(appId, false);
  5895. if (actId == Guid.Empty)
  5896. {
  5897. throw new NotSupportedException("No applicable activation IDs found.");
  5898. }
  5899. }
  5900. else
  5901. {
  5902. appId = SLApi.GetAppId(actId);
  5903. }
  5904. if (!SLApi.IsPhoneActivatable(actId))
  5905. {
  5906. throw new NotSupportedException("Phone license is unavailable for this product.");
  5907. }
  5908. string instId = SLApi.GetInstallationID(actId);
  5909. Guid pkeyId = SLApi.GetInstalledPkeyID(actId);
  5910. if (version == PSVersion.Win7)
  5911. {
  5912. Deposit(actId, instId);
  5913. }
  5914. Utils.KillSPP();
  5915. Logger.WriteLine("Writing TrustedStore data...");
  5916. using (IPhysicalStore store = Utils.GetStore(version, production))
  5917. {
  5918. byte[] hwidBlock = Constants.UniversalHWIDBlock;
  5919. Logger.WriteLine("Activation ID: " + actId);
  5920. Logger.WriteLine("Installation ID: " + instId);
  5921. Logger.WriteLine("Product Key ID: " + pkeyId);
  5922. byte[] iidHash;
  5923. if (version == PSVersion.Win7)
  5924. {
  5925. iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId));
  5926. }
  5927. else
  5928. {
  5929. iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId + '\0' + Constants.ZeroCID));
  5930. }
  5931. string key = string.Format("SPPSVC\\{0}\\{1}", appId, actId);
  5932. PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());
  5933. if (keyBlock == null)
  5934. {
  5935. throw new InvalidDataException("Failed to get product key data for activation ID " + actId + ".");
  5936. }
  5937. VariableBag pkb = new VariableBag(keyBlock.Data);
  5938. byte[] pkeyData;
  5939. if (version == PSVersion.Win7)
  5940. {
  5941. pkeyData = pkb.GetBlock("SppPkeyShortAuthenticator").Value;
  5942. }
  5943. else
  5944. {
  5945. pkeyData = pkb.GetBlock("SppPkeyPhoneActivationData").Value;
  5946. }
  5947. pkb.DeleteBlock("SppPkeyVirtual");
  5948. store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());
  5949. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  5950. writer.Write(0x20);
  5951. writer.Write(iidHash);
  5952. writer.Write(hwidBlock.Length);
  5953. writer.Write(hwidBlock);
  5954. byte[] tsHwidData = writer.GetBytes();
  5955. writer = new BinaryWriter(new MemoryStream());
  5956. writer.Write(0x20);
  5957. writer.Write(iidHash);
  5958. writer.Write(pkeyData.Length);
  5959. writer.Write(pkeyData);
  5960. byte[] tsPkeyInfoData = writer.GetBytes();
  5961. store.AddBlocks(new PSBlock[] {
  5962. new PSBlock
  5963. {
  5964. Type = BlockType.NAMED,
  5965. Flags = 0,
  5966. KeyAsStr = key,
  5967. ValueAsStr = "msft:Windows/7.0/Phone/Cached/HwidBlock/" + pkeyId,
  5968. Data = tsHwidData
  5969. },
  5970. new PSBlock
  5971. {
  5972. Type = BlockType.NAMED,
  5973. Flags = 0,
  5974. KeyAsStr = key,
  5975. ValueAsStr = "msft:Windows/7.0/Phone/Cached/PKeyInfo/" + pkeyId,
  5976. Data = tsPkeyInfoData
  5977. }
  5978. });
  5979. }
  5980. if (version != PSVersion.Win7)
  5981. {
  5982. Deposit(actId, instId);
  5983. }
  5984. SLApi.RefreshLicenseStatus();
  5985. SLApi.FireStateChangedEvent(appId);
  5986. Logger.WriteLine("Activated using ZeroCID successfully.");
  5987. }
  5988. }
  5989. }
  5990. // TokenStore/Common.cs
  5991. namespace LibTSforge.TokenStore
  5992. {
  5993. using System.Collections.Generic;
  5994. using System.IO;
  5995. public class TokenEntry
  5996. {
  5997. public string Name;
  5998. public string Extension;
  5999. public byte[] Data;
  6000. public bool Populated;
  6001. }
  6002. public class TokenMeta
  6003. {
  6004. public string Name;
  6005. public Dictionary<string, string> Data = new Dictionary<string, string>();
  6006. public byte[] Serialize()
  6007. {
  6008. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  6009. writer.Write(1);
  6010. byte[] nameBytes = Utils.EncodeString(Name);
  6011. writer.Write(nameBytes.Length);
  6012. writer.Write(nameBytes);
  6013. foreach (KeyValuePair<string, string> kv in Data)
  6014. {
  6015. byte[] keyBytes = Utils.EncodeString(kv.Key);
  6016. byte[] valueBytes = Utils.EncodeString(kv.Value);
  6017. writer.Write(keyBytes.Length);
  6018. writer.Write(valueBytes.Length);
  6019. writer.Write(keyBytes);
  6020. writer.Write(valueBytes);
  6021. }
  6022. return writer.GetBytes();
  6023. }
  6024. public void Deserialize(byte[] data)
  6025. {
  6026. BinaryReader reader = new BinaryReader(new MemoryStream(data));
  6027. reader.ReadInt32();
  6028. int nameLen = reader.ReadInt32();
  6029. Name = reader.ReadNullTerminatedString(nameLen);
  6030. while (reader.BaseStream.Position < data.Length - 0x8)
  6031. {
  6032. int keyLen = reader.ReadInt32();
  6033. int valueLen = reader.ReadInt32();
  6034. string key = reader.ReadNullTerminatedString(keyLen);
  6035. string value = reader.ReadNullTerminatedString(valueLen);
  6036. Data[key] = value;
  6037. }
  6038. }
  6039. public TokenMeta(byte[] data)
  6040. {
  6041. Deserialize(data);
  6042. }
  6043. public TokenMeta()
  6044. {
  6045. }
  6046. }
  6047. }
  6048. // TokenStore/ITokenStore.cs
  6049. namespace LibTSforge.TokenStore
  6050. {
  6051. using System;
  6052. public interface ITokenStore : IDisposable
  6053. {
  6054. void Deserialize();
  6055. void Serialize();
  6056. void AddEntry(TokenEntry entry);
  6057. void AddEntries(TokenEntry[] entries);
  6058. void DeleteEntry(string name, string ext);
  6059. void DeleteUnpopEntry(string name, string ext);
  6060. TokenEntry GetEntry(string name, string ext);
  6061. TokenMeta GetMetaEntry(string name);
  6062. void SetEntry(string name, string ext, byte[] data);
  6063. }
  6064. }
  6065. // TokenStore/TokenStoreModern.cs
  6066. namespace LibTSforge.TokenStore
  6067. {
  6068. using System;
  6069. using System.Collections.Generic;
  6070. using System.IO;
  6071. using System.Linq;
  6072. using LibTSforge.Crypto;
  6073. public class TokenStoreModern : ITokenStore
  6074. {
  6075. private static readonly uint VERSION = 3;
  6076. private static readonly int ENTRY_SIZE = 0x9E;
  6077. private static readonly int BLOCK_SIZE = 0x4020;
  6078. private static readonly int ENTRIES_PER_BLOCK = BLOCK_SIZE / ENTRY_SIZE;
  6079. private static readonly int BLOCK_PAD_SIZE = 0x66;
  6080. private static readonly byte[] CONTS_HEADER = Enumerable.Repeat((byte)0x55, 0x20).ToArray();
  6081. private static readonly byte[] CONTS_FOOTER = Enumerable.Repeat((byte)0xAA, 0x20).ToArray();
  6082. private List<TokenEntry> Entries = new List<TokenEntry>();
  6083. public FileStream TokensFile;
  6084. public void Deserialize()
  6085. {
  6086. if (TokensFile.Length < BLOCK_SIZE) return;
  6087. TokensFile.Seek(0x24, SeekOrigin.Begin);
  6088. uint nextBlock = 0;
  6089. BinaryReader reader = new BinaryReader(TokensFile);
  6090. do
  6091. {
  6092. uint curOffset = reader.ReadUInt32();
  6093. nextBlock = reader.ReadUInt32();
  6094. for (int i = 0; i < ENTRIES_PER_BLOCK; i++)
  6095. {
  6096. curOffset = reader.ReadUInt32();
  6097. bool populated = reader.ReadUInt32() == 1;
  6098. uint contentOffset = reader.ReadUInt32();
  6099. uint contentLength = reader.ReadUInt32();
  6100. uint allocLength = reader.ReadUInt32();
  6101. byte[] contentData = new byte[] { };
  6102. if (populated)
  6103. {
  6104. reader.BaseStream.Seek(contentOffset + 0x20, SeekOrigin.Begin);
  6105. uint dataLength = reader.ReadUInt32();
  6106. if (dataLength != contentLength)
  6107. {
  6108. throw new FormatException("Data length in tokens content is inconsistent with entry.");
  6109. }
  6110. reader.ReadBytes(0x20);
  6111. contentData = reader.ReadBytes((int)contentLength);
  6112. }
  6113. reader.BaseStream.Seek(curOffset + 0x14, SeekOrigin.Begin);
  6114. Entries.Add(new TokenEntry
  6115. {
  6116. Name = reader.ReadNullTerminatedString(0x82),
  6117. Extension = reader.ReadNullTerminatedString(0x8),
  6118. Data = contentData,
  6119. Populated = populated
  6120. });
  6121. }
  6122. reader.BaseStream.Seek(nextBlock, SeekOrigin.Begin);
  6123. } while (nextBlock != 0);
  6124. }
  6125. public void Serialize()
  6126. {
  6127. MemoryStream tokens = new MemoryStream();
  6128. using (BinaryWriter writer = new BinaryWriter(tokens))
  6129. {
  6130. writer.Write(VERSION);
  6131. writer.Write(CONTS_HEADER);
  6132. int curBlockOffset = (int)writer.BaseStream.Position;
  6133. int curEntryOffset = curBlockOffset + 0x8;
  6134. int curContsOffset = curBlockOffset + BLOCK_SIZE;
  6135. for (int eIndex = 0; eIndex < ((Entries.Count / ENTRIES_PER_BLOCK) + 1) * ENTRIES_PER_BLOCK; eIndex++)
  6136. {
  6137. TokenEntry entry;
  6138. if (eIndex < Entries.Count)
  6139. {
  6140. entry = Entries[eIndex];
  6141. }
  6142. else
  6143. {
  6144. entry = new TokenEntry
  6145. {
  6146. Name = "",
  6147. Extension = "",
  6148. Populated = false,
  6149. Data = new byte[] { }
  6150. };
  6151. }
  6152. writer.BaseStream.Seek(curBlockOffset, SeekOrigin.Begin);
  6153. writer.Write(curBlockOffset);
  6154. writer.Write(0);
  6155. writer.BaseStream.Seek(curEntryOffset, SeekOrigin.Begin);
  6156. writer.Write(curEntryOffset);
  6157. writer.Write(entry.Populated ? 1 : 0);
  6158. writer.Write(entry.Populated ? curContsOffset : 0);
  6159. writer.Write(entry.Populated ? entry.Data.Length : -1);
  6160. writer.Write(entry.Populated ? entry.Data.Length : -1);
  6161. writer.WriteFixedString16(entry.Name, 0x82);
  6162. writer.WriteFixedString16(entry.Extension, 0x8);
  6163. curEntryOffset = (int)writer.BaseStream.Position;
  6164. if (entry.Populated)
  6165. {
  6166. writer.BaseStream.Seek(curContsOffset, SeekOrigin.Begin);
  6167. writer.Write(CONTS_HEADER);
  6168. writer.Write(entry.Data.Length);
  6169. writer.Write(CryptoUtils.SHA256Hash(entry.Data));
  6170. writer.Write(entry.Data);
  6171. writer.Write(CONTS_FOOTER);
  6172. curContsOffset = (int)writer.BaseStream.Position;
  6173. }
  6174. if ((eIndex + 1) % ENTRIES_PER_BLOCK == 0 && eIndex != 0)
  6175. {
  6176. if (eIndex < Entries.Count)
  6177. {
  6178. writer.BaseStream.Seek(curBlockOffset + 0x4, SeekOrigin.Begin);
  6179. writer.Write(curContsOffset);
  6180. }
  6181. writer.BaseStream.Seek(curEntryOffset, SeekOrigin.Begin);
  6182. writer.WritePadding(BLOCK_PAD_SIZE);
  6183. writer.BaseStream.Seek(curBlockOffset, SeekOrigin.Begin);
  6184. byte[] blockHash;
  6185. byte[] blockData = new byte[BLOCK_SIZE - 0x20];
  6186. tokens.Read(blockData, 0, BLOCK_SIZE - 0x20);
  6187. blockHash = CryptoUtils.SHA256Hash(blockData);
  6188. writer.BaseStream.Seek(curBlockOffset + BLOCK_SIZE - 0x20, SeekOrigin.Begin);
  6189. writer.Write(blockHash);
  6190. curBlockOffset = curContsOffset;
  6191. curEntryOffset = curBlockOffset + 0x8;
  6192. curContsOffset = curBlockOffset + BLOCK_SIZE;
  6193. }
  6194. }
  6195. tokens.SetLength(curBlockOffset);
  6196. }
  6197. byte[] tokensData = tokens.ToArray();
  6198. byte[] tokensHash = CryptoUtils.SHA256Hash(tokensData.Take(0x4).Concat(tokensData.Skip(0x24)).ToArray());
  6199. tokens = new MemoryStream(tokensData);
  6200. BinaryWriter tokWriter = new BinaryWriter(TokensFile);
  6201. using (BinaryReader reader = new BinaryReader(tokens))
  6202. {
  6203. TokensFile.Seek(0, SeekOrigin.Begin);
  6204. TokensFile.SetLength(tokens.Length);
  6205. tokWriter.Write(reader.ReadBytes(0x4));
  6206. reader.ReadBytes(0x20);
  6207. tokWriter.Write(tokensHash);
  6208. tokWriter.Write(reader.ReadBytes((int)reader.BaseStream.Length - 0x4));
  6209. }
  6210. }
  6211. public void AddEntry(TokenEntry entry)
  6212. {
  6213. Entries.Add(entry);
  6214. }
  6215. public void AddEntries(TokenEntry[] entries)
  6216. {
  6217. Entries.AddRange(entries);
  6218. }
  6219. public void DeleteEntry(string name, string ext)
  6220. {
  6221. foreach (TokenEntry entry in Entries)
  6222. {
  6223. if (entry.Name == name && entry.Extension == ext)
  6224. {
  6225. Entries.Remove(entry);
  6226. return;
  6227. }
  6228. }
  6229. }
  6230. public void DeleteUnpopEntry(string name, string ext)
  6231. {
  6232. List<TokenEntry> delEntries = new List<TokenEntry>();
  6233. foreach (TokenEntry entry in Entries)
  6234. {
  6235. if (entry.Name == name && entry.Extension == ext && !entry.Populated)
  6236. {
  6237. delEntries.Add(entry);
  6238. }
  6239. }
  6240. Entries = Entries.Except(delEntries).ToList();
  6241. }
  6242. public TokenEntry GetEntry(string name, string ext)
  6243. {
  6244. foreach (TokenEntry entry in Entries)
  6245. {
  6246. if (entry.Name == name && entry.Extension == ext)
  6247. {
  6248. if (!entry.Populated) continue;
  6249. return entry;
  6250. }
  6251. }
  6252. return null;
  6253. }
  6254. public TokenMeta GetMetaEntry(string name)
  6255. {
  6256. DeleteUnpopEntry(name, "xml");
  6257. TokenEntry entry = GetEntry(name, "xml");
  6258. TokenMeta meta;
  6259. if (entry == null)
  6260. {
  6261. meta = new TokenMeta
  6262. {
  6263. Name = name
  6264. };
  6265. }
  6266. else
  6267. {
  6268. meta = new TokenMeta(entry.Data);
  6269. }
  6270. return meta;
  6271. }
  6272. public void SetEntry(string name, string ext, byte[] data)
  6273. {
  6274. for (int i = 0; i < Entries.Count; i++)
  6275. {
  6276. TokenEntry entry = Entries[i];
  6277. if (entry.Name == name && entry.Extension == ext && entry.Populated)
  6278. {
  6279. entry.Data = data;
  6280. Entries[i] = entry;
  6281. return;
  6282. }
  6283. }
  6284. Entries.Add(new TokenEntry
  6285. {
  6286. Populated = true,
  6287. Name = name,
  6288. Extension = ext,
  6289. Data = data
  6290. });
  6291. }
  6292. public TokenStoreModern(string tokensPath)
  6293. {
  6294. TokensFile = File.Open(tokensPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
  6295. Deserialize();
  6296. }
  6297. public TokenStoreModern()
  6298. {
  6299. }
  6300. public void Dispose()
  6301. {
  6302. Serialize();
  6303. TokensFile.Close();
  6304. }
  6305. }
  6306. }
  6307. // PhysicalStore/Common.cs
  6308. namespace LibTSforge.PhysicalStore
  6309. {
  6310. using System.Runtime.InteropServices;
  6311. public enum BlockType : uint
  6312. {
  6313. NONE,
  6314. NAMED,
  6315. ATTRIBUTE,
  6316. TIMER
  6317. }
  6318. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  6319. public struct Timer
  6320. {
  6321. public ulong Unknown;
  6322. public ulong Time1;
  6323. public ulong Time2;
  6324. public ulong Expiry;
  6325. }
  6326. }
  6327. // PhysicalStore/IPhysicalStore.cs
  6328. namespace LibTSforge.PhysicalStore
  6329. {
  6330. using System;
  6331. using System.Collections.Generic;
  6332. public class PSBlock
  6333. {
  6334. public BlockType Type;
  6335. public uint Flags;
  6336. public uint Unknown = 0;
  6337. public byte[] Key;
  6338. public string KeyAsStr
  6339. {
  6340. get
  6341. {
  6342. return Utils.DecodeString(Key);
  6343. }
  6344. set
  6345. {
  6346. Key = Utils.EncodeString(value);
  6347. }
  6348. }
  6349. public byte[] Value;
  6350. public string ValueAsStr
  6351. {
  6352. get
  6353. {
  6354. return Utils.DecodeString(Value);
  6355. }
  6356. set
  6357. {
  6358. Value = Utils.EncodeString(value);
  6359. }
  6360. }
  6361. public uint ValueAsInt
  6362. {
  6363. get
  6364. {
  6365. return BitConverter.ToUInt32(Value, 0);
  6366. }
  6367. set
  6368. {
  6369. Value = BitConverter.GetBytes(value);
  6370. }
  6371. }
  6372. public byte[] Data;
  6373. public string DataAsStr
  6374. {
  6375. get
  6376. {
  6377. return Utils.DecodeString(Data);
  6378. }
  6379. set
  6380. {
  6381. Data = Utils.EncodeString(value);
  6382. }
  6383. }
  6384. public uint DataAsInt
  6385. {
  6386. get
  6387. {
  6388. return BitConverter.ToUInt32(Data, 0);
  6389. }
  6390. set
  6391. {
  6392. Data = BitConverter.GetBytes(value);
  6393. }
  6394. }
  6395. }
  6396. public interface IPhysicalStore : IDisposable
  6397. {
  6398. PSBlock GetBlock(string key, string value);
  6399. PSBlock GetBlock(string key, uint value);
  6400. void AddBlock(PSBlock block);
  6401. void AddBlocks(IEnumerable<PSBlock> blocks);
  6402. void SetBlock(string key, string value, byte[] data);
  6403. void SetBlock(string key, string value, string data);
  6404. void SetBlock(string key, string value, uint data);
  6405. void SetBlock(string key, uint value, byte[] data);
  6406. void SetBlock(string key, uint value, string data);
  6407. void SetBlock(string key, uint value, uint data);
  6408. void DeleteBlock(string key, string value);
  6409. void DeleteBlock(string key, uint value);
  6410. byte[] Serialize();
  6411. void Deserialize(byte[] data);
  6412. byte[] ReadRaw();
  6413. void WriteRaw(byte[] data);
  6414. IEnumerable<PSBlock> FindBlocks(string valueSearch);
  6415. IEnumerable<PSBlock> FindBlocks(uint valueSearch);
  6416. }
  6417. }
  6418. // PhysicalStore/PhysicalStoreModern.cs
  6419. namespace LibTSforge.PhysicalStore
  6420. {
  6421. using System;
  6422. using System.Collections.Generic;
  6423. using System.IO;
  6424. using LibTSforge.Crypto;
  6425. public class ModernBlock
  6426. {
  6427. public BlockType Type;
  6428. public uint Flags;
  6429. public uint Unknown;
  6430. public byte[] Value;
  6431. public string ValueAsStr
  6432. {
  6433. get
  6434. {
  6435. return Utils.DecodeString(Value);
  6436. }
  6437. set
  6438. {
  6439. Value = Utils.EncodeString(value);
  6440. }
  6441. }
  6442. public uint ValueAsInt
  6443. {
  6444. get
  6445. {
  6446. return BitConverter.ToUInt32(Value, 0);
  6447. }
  6448. set
  6449. {
  6450. Value = BitConverter.GetBytes(value);
  6451. }
  6452. }
  6453. public byte[] Data;
  6454. public string DataAsStr
  6455. {
  6456. get
  6457. {
  6458. return Utils.DecodeString(Data);
  6459. }
  6460. set
  6461. {
  6462. Data = Utils.EncodeString(value);
  6463. }
  6464. }
  6465. public uint DataAsInt
  6466. {
  6467. get
  6468. {
  6469. return BitConverter.ToUInt32(Data, 0);
  6470. }
  6471. set
  6472. {
  6473. Data = BitConverter.GetBytes(value);
  6474. }
  6475. }
  6476. public void Encode(BinaryWriter writer)
  6477. {
  6478. writer.Write((uint)Type);
  6479. writer.Write(Flags);
  6480. writer.Write((uint)Value.Length);
  6481. writer.Write((uint)Data.Length);
  6482. writer.Write(Unknown);
  6483. writer.Write(Value);
  6484. writer.Write(Data);
  6485. }
  6486. public static ModernBlock Decode(BinaryReader reader)
  6487. {
  6488. uint type = reader.ReadUInt32();
  6489. uint flags = reader.ReadUInt32();
  6490. uint valueLen = reader.ReadUInt32();
  6491. uint dataLen = reader.ReadUInt32();
  6492. uint unk3 = reader.ReadUInt32();
  6493. byte[] value = reader.ReadBytes((int)valueLen);
  6494. byte[] data = reader.ReadBytes((int)dataLen);
  6495. return new ModernBlock
  6496. {
  6497. Type = (BlockType)type,
  6498. Flags = flags,
  6499. Unknown = unk3,
  6500. Value = value,
  6501. Data = data,
  6502. };
  6503. }
  6504. }
  6505. public sealed class PhysicalStoreModern : IPhysicalStore
  6506. {
  6507. private byte[] PreHeaderBytes = new byte[] { };
  6508. private readonly Dictionary<string, List<ModernBlock>> Data = new Dictionary<string, List<ModernBlock>>();
  6509. private readonly FileStream TSFile;
  6510. private readonly PSVersion Version;
  6511. private readonly bool Production;
  6512. public byte[] Serialize()
  6513. {
  6514. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  6515. writer.Write(PreHeaderBytes);
  6516. writer.Write(Data.Keys.Count);
  6517. foreach (string key in Data.Keys)
  6518. {
  6519. List<ModernBlock> blocks = Data[key];
  6520. byte[] keyNameEnc = Utils.EncodeString(key);
  6521. writer.Write(keyNameEnc.Length);
  6522. writer.Write(keyNameEnc);
  6523. writer.Write(blocks.Count);
  6524. writer.Align(4);
  6525. foreach (ModernBlock block in blocks)
  6526. {
  6527. block.Encode(writer);
  6528. writer.Align(4);
  6529. }
  6530. }
  6531. return writer.GetBytes();
  6532. }
  6533. public void Deserialize(byte[] data)
  6534. {
  6535. BinaryReader reader = new BinaryReader(new MemoryStream(data));
  6536. PreHeaderBytes = reader.ReadBytes(8);
  6537. while (reader.BaseStream.Position < data.Length - 0x4)
  6538. {
  6539. uint numKeys = reader.ReadUInt32();
  6540. for (int i = 0; i < numKeys; i++)
  6541. {
  6542. uint lenKeyName = reader.ReadUInt32();
  6543. string keyName = Utils.DecodeString(reader.ReadBytes((int)lenKeyName)); uint numValues = reader.ReadUInt32();
  6544. reader.Align(4);
  6545. Data[keyName] = new List<ModernBlock>();
  6546. for (int j = 0; j < numValues; j++)
  6547. {
  6548. Data[keyName].Add(ModernBlock.Decode(reader));
  6549. reader.Align(4);
  6550. }
  6551. }
  6552. }
  6553. }
  6554. public void AddBlock(PSBlock block)
  6555. {
  6556. if (!Data.ContainsKey(block.KeyAsStr))
  6557. {
  6558. Data[block.KeyAsStr] = new List<ModernBlock>();
  6559. }
  6560. Data[block.KeyAsStr].Add(new ModernBlock
  6561. {
  6562. Type = block.Type,
  6563. Flags = block.Flags,
  6564. Unknown = block.Unknown,
  6565. Value = block.Value,
  6566. Data = block.Data
  6567. });
  6568. }
  6569. public void AddBlocks(IEnumerable<PSBlock> blocks)
  6570. {
  6571. foreach (PSBlock block in blocks)
  6572. {
  6573. AddBlock(block);
  6574. }
  6575. }
  6576. public PSBlock GetBlock(string key, string value)
  6577. {
  6578. List<ModernBlock> blocks = Data[key];
  6579. foreach (ModernBlock block in blocks)
  6580. {
  6581. if (block.ValueAsStr == value)
  6582. {
  6583. return new PSBlock
  6584. {
  6585. Type = block.Type,
  6586. Flags = block.Flags,
  6587. Key = Utils.EncodeString(key),
  6588. Value = block.Value,
  6589. Data = block.Data
  6590. };
  6591. }
  6592. }
  6593. return null;
  6594. }
  6595. public PSBlock GetBlock(string key, uint value)
  6596. {
  6597. List<ModernBlock> blocks = Data[key];
  6598. foreach (ModernBlock block in blocks)
  6599. {
  6600. if (block.ValueAsInt == value)
  6601. {
  6602. return new PSBlock
  6603. {
  6604. Type = block.Type,
  6605. Flags = block.Flags,
  6606. Key = Utils.EncodeString(key),
  6607. Value = block.Value,
  6608. Data = block.Data
  6609. };
  6610. }
  6611. }
  6612. return null;
  6613. }
  6614. public void SetBlock(string key, string value, byte[] data)
  6615. {
  6616. List<ModernBlock> blocks = Data[key];
  6617. for (int i = 0; i < blocks.Count; i++)
  6618. {
  6619. ModernBlock block = blocks[i];
  6620. if (block.ValueAsStr == value)
  6621. {
  6622. block.Data = data;
  6623. blocks[i] = block;
  6624. break;
  6625. }
  6626. }
  6627. Data[key] = blocks;
  6628. }
  6629. public void SetBlock(string key, uint value, byte[] data)
  6630. {
  6631. List<ModernBlock> blocks = Data[key];
  6632. for (int i = 0; i < blocks.Count; i++)
  6633. {
  6634. ModernBlock block = blocks[i];
  6635. if (block.ValueAsInt == value)
  6636. {
  6637. block.Data = data;
  6638. blocks[i] = block;
  6639. break;
  6640. }
  6641. }
  6642. Data[key] = blocks;
  6643. }
  6644. public void SetBlock(string key, string value, string data)
  6645. {
  6646. SetBlock(key, value, Utils.EncodeString(data));
  6647. }
  6648. public void SetBlock(string key, string value, uint data)
  6649. {
  6650. SetBlock(key, value, BitConverter.GetBytes(data));
  6651. }
  6652. public void SetBlock(string key, uint value, string data)
  6653. {
  6654. SetBlock(key, value, Utils.EncodeString(data));
  6655. }
  6656. public void SetBlock(string key, uint value, uint data)
  6657. {
  6658. SetBlock(key, value, BitConverter.GetBytes(data));
  6659. }
  6660. public void DeleteBlock(string key, string value)
  6661. {
  6662. if (Data.ContainsKey(key))
  6663. {
  6664. List<ModernBlock> blocks = Data[key];
  6665. foreach (ModernBlock block in blocks)
  6666. {
  6667. if (block.ValueAsStr == value)
  6668. {
  6669. blocks.Remove(block);
  6670. break;
  6671. }
  6672. }
  6673. Data[key] = blocks;
  6674. }
  6675. }
  6676. public void DeleteBlock(string key, uint value)
  6677. {
  6678. if (Data.ContainsKey(key))
  6679. {
  6680. List<ModernBlock> blocks = Data[key];
  6681. foreach (ModernBlock block in blocks)
  6682. {
  6683. if (block.ValueAsInt == value)
  6684. {
  6685. blocks.Remove(block);
  6686. break;
  6687. }
  6688. }
  6689. Data[key] = blocks;
  6690. }
  6691. }
  6692. public PhysicalStoreModern(string tsPath, bool production, PSVersion version)
  6693. {
  6694. TSFile = File.Open(tsPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
  6695. Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSFile.ReadAllBytes(), production));
  6696. TSFile.Seek(0, SeekOrigin.Begin);
  6697. Version = version;
  6698. Production = production;
  6699. }
  6700. public void Dispose()
  6701. {
  6702. if (TSFile.CanWrite)
  6703. {
  6704. byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, Version);
  6705. TSFile.SetLength(data.LongLength);
  6706. TSFile.Seek(0, SeekOrigin.Begin);
  6707. TSFile.WriteAllBytes(data);
  6708. TSFile.Close();
  6709. }
  6710. }
  6711. public byte[] ReadRaw()
  6712. {
  6713. byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSFile.ReadAllBytes(), Production);
  6714. TSFile.Seek(0, SeekOrigin.Begin);
  6715. return data;
  6716. }
  6717. public void WriteRaw(byte[] data)
  6718. {
  6719. byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, Version);
  6720. TSFile.SetLength(encrData.LongLength);
  6721. TSFile.Seek(0, SeekOrigin.Begin);
  6722. TSFile.WriteAllBytes(encrData);
  6723. TSFile.Close();
  6724. }
  6725. public IEnumerable<PSBlock> FindBlocks(string valueSearch)
  6726. {
  6727. List<PSBlock> results = new List<PSBlock>();
  6728. foreach (string key in Data.Keys)
  6729. {
  6730. List<ModernBlock> values = Data[key];
  6731. foreach (ModernBlock block in values)
  6732. {
  6733. if (block.ValueAsStr.Contains(valueSearch))
  6734. {
  6735. results.Add(new PSBlock
  6736. {
  6737. Type = block.Type,
  6738. Flags = block.Flags,
  6739. KeyAsStr = key,
  6740. Value = block.Value,
  6741. Data = block.Data
  6742. });
  6743. }
  6744. }
  6745. }
  6746. return results;
  6747. }
  6748. public IEnumerable<PSBlock> FindBlocks(uint valueSearch)
  6749. {
  6750. List<PSBlock> results = new List<PSBlock>();
  6751. foreach (string key in Data.Keys)
  6752. {
  6753. List<ModernBlock> values = Data[key];
  6754. foreach (ModernBlock block in values)
  6755. {
  6756. if (block.ValueAsInt == valueSearch)
  6757. {
  6758. results.Add(new PSBlock
  6759. {
  6760. Type = block.Type,
  6761. Flags = block.Flags,
  6762. KeyAsStr = key,
  6763. Value = block.Value,
  6764. Data = block.Data
  6765. });
  6766. }
  6767. }
  6768. }
  6769. return results;
  6770. }
  6771. }
  6772. }
  6773. // PhysicalStore/PhysicalStoreWin7.cs
  6774. namespace LibTSforge.PhysicalStore
  6775. {
  6776. using System;
  6777. using System.Collections.Generic;
  6778. using System.IO;
  6779. using LibTSforge.Crypto;
  6780. public class Win7Block
  6781. {
  6782. public BlockType Type;
  6783. public uint Flags;
  6784. public byte[] Key;
  6785. public string KeyAsStr
  6786. {
  6787. get
  6788. {
  6789. return Utils.DecodeString(Key);
  6790. }
  6791. set
  6792. {
  6793. Key = Utils.EncodeString(value);
  6794. }
  6795. }
  6796. public byte[] Value;
  6797. public string ValueAsStr
  6798. {
  6799. get
  6800. {
  6801. return Utils.DecodeString(Value);
  6802. }
  6803. set
  6804. {
  6805. Value = Utils.EncodeString(value);
  6806. }
  6807. }
  6808. public uint ValueAsInt
  6809. {
  6810. get
  6811. {
  6812. return BitConverter.ToUInt32(Value, 0);
  6813. }
  6814. set
  6815. {
  6816. Value = BitConverter.GetBytes(value);
  6817. }
  6818. }
  6819. public byte[] Data;
  6820. public string DataAsStr
  6821. {
  6822. get
  6823. {
  6824. return Utils.DecodeString(Data);
  6825. }
  6826. set
  6827. {
  6828. Data = Utils.EncodeString(value);
  6829. }
  6830. }
  6831. public uint DataAsInt
  6832. {
  6833. get
  6834. {
  6835. return BitConverter.ToUInt32(Data, 0);
  6836. }
  6837. set
  6838. {
  6839. Data = BitConverter.GetBytes(value);
  6840. }
  6841. }
  6842. internal void Encode(BinaryWriter writer)
  6843. {
  6844. writer.Write((uint)Type);
  6845. writer.Write(Flags);
  6846. writer.Write(Key.Length);
  6847. writer.Write(Value.Length);
  6848. writer.Write(Data.Length);
  6849. writer.Write(Key);
  6850. writer.Write(Value);
  6851. writer.Write(Data);
  6852. }
  6853. internal static Win7Block Decode(BinaryReader reader)
  6854. {
  6855. uint type = reader.ReadUInt32();
  6856. uint flags = reader.ReadUInt32();
  6857. int keyLen = reader.ReadInt32();
  6858. int valueLen = reader.ReadInt32();
  6859. int dataLen = reader.ReadInt32();
  6860. byte[] key = reader.ReadBytes(keyLen);
  6861. byte[] value = reader.ReadBytes(valueLen);
  6862. byte[] data = reader.ReadBytes(dataLen);
  6863. return new Win7Block
  6864. {
  6865. Type = (BlockType)type,
  6866. Flags = flags,
  6867. Key = key,
  6868. Value = value,
  6869. Data = data,
  6870. };
  6871. }
  6872. }
  6873. public sealed class PhysicalStoreWin7 : IPhysicalStore
  6874. {
  6875. private byte[] PreHeaderBytes = new byte[] { };
  6876. private readonly List<Win7Block> Blocks = new List<Win7Block>();
  6877. private readonly FileStream TSPrimary;
  6878. private readonly FileStream TSSecondary;
  6879. private readonly bool Production;
  6880. public byte[] Serialize()
  6881. {
  6882. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  6883. writer.Write(PreHeaderBytes);
  6884. foreach (Win7Block block in Blocks)
  6885. {
  6886. block.Encode(writer);
  6887. writer.Align(4);
  6888. }
  6889. return writer.GetBytes();
  6890. }
  6891. public void Deserialize(byte[] data)
  6892. {
  6893. int len = data.Length;
  6894. BinaryReader reader = new BinaryReader(new MemoryStream(data));
  6895. PreHeaderBytes = reader.ReadBytes(8);
  6896. while (reader.BaseStream.Position < len - 0x14)
  6897. {
  6898. Blocks.Add(Win7Block.Decode(reader));
  6899. reader.Align(4);
  6900. }
  6901. }
  6902. public void AddBlock(PSBlock block)
  6903. {
  6904. Blocks.Add(new Win7Block
  6905. {
  6906. Type = block.Type,
  6907. Flags = block.Flags,
  6908. Key = block.Key,
  6909. Value = block.Value,
  6910. Data = block.Data
  6911. });
  6912. }
  6913. public void AddBlocks(IEnumerable<PSBlock> blocks)
  6914. {
  6915. foreach (PSBlock block in blocks)
  6916. {
  6917. AddBlock(block);
  6918. }
  6919. }
  6920. public PSBlock GetBlock(string key, string value)
  6921. {
  6922. foreach (Win7Block block in Blocks)
  6923. {
  6924. if (block.KeyAsStr == key && block.ValueAsStr == value)
  6925. {
  6926. return new PSBlock
  6927. {
  6928. Type = block.Type,
  6929. Flags = block.Flags,
  6930. Key = block.Key,
  6931. Value = block.Value,
  6932. Data = block.Data
  6933. };
  6934. }
  6935. }
  6936. return null;
  6937. }
  6938. public PSBlock GetBlock(string key, uint value)
  6939. {
  6940. foreach (Win7Block block in Blocks)
  6941. {
  6942. if (block.KeyAsStr == key && block.ValueAsInt == value)
  6943. {
  6944. return new PSBlock
  6945. {
  6946. Type = block.Type,
  6947. Flags = block.Flags,
  6948. Key = block.Key,
  6949. Value = block.Value,
  6950. Data = block.Data
  6951. };
  6952. }
  6953. }
  6954. return null;
  6955. }
  6956. public void SetBlock(string key, string value, byte[] data)
  6957. {
  6958. for (int i = 0; i < Blocks.Count; i++)
  6959. {
  6960. Win7Block block = Blocks[i];
  6961. if (block.KeyAsStr == key && block.ValueAsStr == value)
  6962. {
  6963. block.Data = data;
  6964. Blocks[i] = block;
  6965. break;
  6966. }
  6967. }
  6968. }
  6969. public void SetBlock(string key, uint value, byte[] data)
  6970. {
  6971. for (int i = 0; i < Blocks.Count; i++)
  6972. {
  6973. Win7Block block = Blocks[i];
  6974. if (block.KeyAsStr == key && block.ValueAsInt == value)
  6975. {
  6976. block.Data = data;
  6977. Blocks[i] = block;
  6978. break;
  6979. }
  6980. }
  6981. }
  6982. public void SetBlock(string key, string value, string data)
  6983. {
  6984. SetBlock(key, value, Utils.EncodeString(data));
  6985. }
  6986. public void SetBlock(string key, string value, uint data)
  6987. {
  6988. SetBlock(key, value, BitConverter.GetBytes(data));
  6989. }
  6990. public void SetBlock(string key, uint value, string data)
  6991. {
  6992. SetBlock(key, value, Utils.EncodeString(data));
  6993. }
  6994. public void SetBlock(string key, uint value, uint data)
  6995. {
  6996. SetBlock(key, value, BitConverter.GetBytes(data));
  6997. }
  6998. public void DeleteBlock(string key, string value)
  6999. {
  7000. foreach (Win7Block block in Blocks)
  7001. {
  7002. if (block.KeyAsStr == key && block.ValueAsStr == value)
  7003. {
  7004. Blocks.Remove(block);
  7005. return;
  7006. }
  7007. }
  7008. }
  7009. public void DeleteBlock(string key, uint value)
  7010. {
  7011. foreach (Win7Block block in Blocks)
  7012. {
  7013. if (block.KeyAsStr == key && block.ValueAsInt == value)
  7014. {
  7015. Blocks.Remove(block);
  7016. return;
  7017. }
  7018. }
  7019. }
  7020. public PhysicalStoreWin7(string primaryPath, bool production)
  7021. {
  7022. TSPrimary = File.Open(primaryPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
  7023. TSSecondary = File.Open(primaryPath.Replace("-0.", "-1."), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
  7024. Production = production;
  7025. Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), production));
  7026. TSPrimary.Seek(0, SeekOrigin.Begin);
  7027. }
  7028. public void Dispose()
  7029. {
  7030. if (TSPrimary.CanWrite && TSSecondary.CanWrite)
  7031. {
  7032. byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, PSVersion.Win7);
  7033. TSPrimary.SetLength(data.LongLength);
  7034. TSSecondary.SetLength(data.LongLength);
  7035. TSPrimary.Seek(0, SeekOrigin.Begin);
  7036. TSSecondary.Seek(0, SeekOrigin.Begin);
  7037. TSPrimary.WriteAllBytes(data);
  7038. TSSecondary.WriteAllBytes(data);
  7039. TSPrimary.Close();
  7040. TSSecondary.Close();
  7041. }
  7042. }
  7043. public byte[] ReadRaw()
  7044. {
  7045. byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), Production);
  7046. TSPrimary.Seek(0, SeekOrigin.Begin);
  7047. return data;
  7048. }
  7049. public void WriteRaw(byte[] data)
  7050. {
  7051. byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, PSVersion.Win7);
  7052. TSPrimary.SetLength(encrData.LongLength);
  7053. TSSecondary.SetLength(encrData.LongLength);
  7054. TSPrimary.Seek(0, SeekOrigin.Begin);
  7055. TSSecondary.Seek(0, SeekOrigin.Begin);
  7056. TSPrimary.WriteAllBytes(encrData);
  7057. TSSecondary.WriteAllBytes(encrData);
  7058. TSPrimary.Close();
  7059. TSSecondary.Close();
  7060. }
  7061. public IEnumerable<PSBlock> FindBlocks(string valueSearch)
  7062. {
  7063. List<PSBlock> results = new List<PSBlock>();
  7064. foreach (Win7Block block in Blocks)
  7065. {
  7066. if (block.ValueAsStr.Contains(valueSearch))
  7067. {
  7068. results.Add(new PSBlock
  7069. {
  7070. Type = block.Type,
  7071. Flags = block.Flags,
  7072. Key = block.Key,
  7073. Value = block.Value,
  7074. Data = block.Data
  7075. });
  7076. }
  7077. }
  7078. return results;
  7079. }
  7080. public IEnumerable<PSBlock> FindBlocks(uint valueSearch)
  7081. {
  7082. List<PSBlock> results = new List<PSBlock>();
  7083. foreach (Win7Block block in Blocks)
  7084. {
  7085. if (block.ValueAsInt == valueSearch)
  7086. {
  7087. results.Add(new PSBlock
  7088. {
  7089. Type = block.Type,
  7090. Flags = block.Flags,
  7091. Key = block.Key,
  7092. Value = block.Value,
  7093. Data = block.Data
  7094. });
  7095. }
  7096. }
  7097. return results;
  7098. }
  7099. }
  7100. }
  7101. // PhysicalStore/VariableBag.cs
  7102. namespace LibTSforge.PhysicalStore
  7103. {
  7104. using System;
  7105. using System.Collections.Generic;
  7106. using System.IO;
  7107. public enum CRCBlockType : uint
  7108. {
  7109. UINT = 1 << 0,
  7110. STRING = 1 << 1,
  7111. BINARY = 1 << 2
  7112. }
  7113. public class CRCBlock
  7114. {
  7115. public CRCBlockType DataType;
  7116. public byte[] Key;
  7117. public string KeyAsStr
  7118. {
  7119. get
  7120. {
  7121. return Utils.DecodeString(Key);
  7122. }
  7123. set
  7124. {
  7125. Key = Utils.EncodeString(value);
  7126. }
  7127. }
  7128. public byte[] Value;
  7129. public string ValueAsStr
  7130. {
  7131. get
  7132. {
  7133. return Utils.DecodeString(Value);
  7134. }
  7135. set
  7136. {
  7137. Value = Utils.EncodeString(value);
  7138. }
  7139. }
  7140. public uint ValueAsInt
  7141. {
  7142. get
  7143. {
  7144. return BitConverter.ToUInt32(Value, 0);
  7145. }
  7146. set
  7147. {
  7148. Value = BitConverter.GetBytes(value);
  7149. }
  7150. }
  7151. public void Encode(BinaryWriter writer)
  7152. {
  7153. uint crc = CRC();
  7154. writer.Write(crc);
  7155. writer.Write((uint)DataType);
  7156. writer.Write(Key.Length);
  7157. writer.Write(Value.Length);
  7158. writer.Write(Key);
  7159. writer.Align(8);
  7160. writer.Write(Value);
  7161. writer.Align(8);
  7162. }
  7163. public static CRCBlock Decode(BinaryReader reader)
  7164. {
  7165. uint crc = reader.ReadUInt32();
  7166. uint type = reader.ReadUInt32();
  7167. uint lenName = reader.ReadUInt32();
  7168. uint lenVal = reader.ReadUInt32();
  7169. byte[] key = reader.ReadBytes((int)lenName);
  7170. reader.Align(8);
  7171. byte[] value = reader.ReadBytes((int)lenVal);
  7172. reader.Align(8);
  7173. CRCBlock block = new CRCBlock
  7174. {
  7175. DataType = (CRCBlockType)type,
  7176. Key = key,
  7177. Value = value,
  7178. };
  7179. if (block.CRC() != crc)
  7180. {
  7181. throw new InvalidDataException("Invalid CRC in variable bag.");
  7182. }
  7183. return block;
  7184. }
  7185. public uint CRC()
  7186. {
  7187. BinaryWriter wtemp = new BinaryWriter(new MemoryStream());
  7188. wtemp.Write(0);
  7189. wtemp.Write((uint)DataType);
  7190. wtemp.Write(Key.Length);
  7191. wtemp.Write(Value.Length);
  7192. wtemp.Write(Key);
  7193. wtemp.Write(Value);
  7194. return Utils.CRC32(wtemp.GetBytes());
  7195. }
  7196. }
  7197. public class VariableBag
  7198. {
  7199. public List<CRCBlock> Blocks = new List<CRCBlock>();
  7200. public void Deserialize(byte[] data)
  7201. {
  7202. int len = data.Length;
  7203. BinaryReader reader = new BinaryReader(new MemoryStream(data));
  7204. while (reader.BaseStream.Position < len - 0x10)
  7205. {
  7206. Blocks.Add(CRCBlock.Decode(reader));
  7207. }
  7208. }
  7209. public byte[] Serialize()
  7210. {
  7211. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  7212. foreach (CRCBlock block in Blocks)
  7213. {
  7214. block.Encode(writer);
  7215. }
  7216. return writer.GetBytes();
  7217. }
  7218. public CRCBlock GetBlock(string key)
  7219. {
  7220. foreach (CRCBlock block in Blocks)
  7221. {
  7222. if (block.KeyAsStr == key)
  7223. {
  7224. return block;
  7225. }
  7226. }
  7227. return null;
  7228. }
  7229. public void SetBlock(string key, byte[] value)
  7230. {
  7231. for (int i = 0; i < Blocks.Count; i++)
  7232. {
  7233. CRCBlock block = Blocks[i];
  7234. if (block.KeyAsStr == key)
  7235. {
  7236. block.Value = value;
  7237. Blocks[i] = block;
  7238. break;
  7239. }
  7240. }
  7241. }
  7242. public void DeleteBlock(string key)
  7243. {
  7244. foreach (CRCBlock block in Blocks)
  7245. {
  7246. if (block.KeyAsStr == key)
  7247. {
  7248. Blocks.Remove(block);
  7249. return;
  7250. }
  7251. }
  7252. }
  7253. public VariableBag(byte[] data)
  7254. {
  7255. Deserialize(data);
  7256. }
  7257. public VariableBag()
  7258. {
  7259. }
  7260. }
  7261. }
  7262. '@
  7263. $ErrorActionPreference = 'Stop'
  7264. $cp = [CodeDom.Compiler.CompilerParameters] [string[]]@("System.dll", "System.Core.dll", "System.ServiceProcess.dll", "System.Xml.dll")
  7265. $cp.CompilerOptions = "/unsafe"
  7266. $lang = If ((Get-Host).Version.Major -gt 2) { "CSharp" } Else { "CSharpVersion3" }
  7267. $ctemp = "$env:SystemRoot\Temp\"
  7268. if (-Not (Test-Path -Path $ctemp)) { New-Item -Path $ctemp -ItemType Directory > $null }
  7269. $env:TMP = $ctemp
  7270. $env:TEMP = $ctemp
  7271. $cp.GenerateInMemory = $true
  7272. Add-Type -Language $lang -TypeDefinition $src -CompilerParameters $cp
  7273. if ($env:_debug -eq '0') {
  7274. [LibTSforge.Logger]::HideOutput = $true
  7275. }
  7276. $ver = [LibTSforge.Utils]::DetectVersion()
  7277. $prod = [LibTSforge.Utils]::DetectCurrentKey()
  7278. $tsactids = @($args)
  7279. function Get-WmiInfo {
  7280. param ([string]$tsactid, [string]$property)
  7281. $query = "SELECT ID, $property FROM SoftwareLicensingProduct WHERE ID='$tsactid'"
  7282. $record = Get-WmiObject -Query $query
  7283. if ($record) {
  7284. return $record.$property
  7285. }
  7286. }
  7287. if ($env:resetstuff -eq $null) {
  7288. foreach ($tsactid in $tsactids) {
  7289. try {
  7290. $prodDes = Get-WmiInfo -tsactid $tsactid -property "Description"
  7291. $prodName = Get-WmiInfo -tsactid $tsactid -property "Name"
  7292. if ($prodName) {
  7293. $nameParts = $prodName -split ',', 2
  7294. $prodName = if ($nameParts.Count -gt 1) { ($nameParts[1].Trim() -split '[ ,]')[0] } else { $null }
  7295. }
  7296. [LibTSforge.Modifiers.GenPKeyInstall]::InstallGenPKey($ver, $prod, $tsactid)
  7297. [LibTSforge.Activators.ZeroCID]::Activate($ver, $prod, $tsactid)
  7298. $licenseStatus = Get-WmiInfo -tsactid $tsactid -property "LicenseStatus"
  7299. if ($licenseStatus -eq 1) {
  7300. if ($prodDes -match 'KMS' -and $prodDes -notmatch 'CLIENT') {
  7301. [LibTSforge.Modifiers.KMSHostCharge]::Charge($ver, $tsactid, $prod)
  7302. Write-Host "[$prodName] CSVLK is permanently activated with ZeroCID." -ForegroundColor White -BackgroundColor DarkGreen
  7303. Write-Host "[$prodName] CSVLK is charged with 25 clients for 30 days." -ForegroundColor White -BackgroundColor DarkGreen
  7304. }
  7305. else {
  7306. Write-Host "[$prodName] is permanently activated with ZeroCID." -ForegroundColor White -BackgroundColor DarkGreen
  7307. }
  7308. }
  7309. else {
  7310. Write-Host "[$prodName] activation has failed." -ForegroundColor White -BackgroundColor DarkRed
  7311. $errcode = 3
  7312. }
  7313. }
  7314. catch {
  7315. $errcode = 3
  7316. Write-Host "$($_.Exception.Message)" -ForegroundColor Red -BackgroundColor Black
  7317. Write-Host "[$prodName] activation has failed." -ForegroundColor White -BackgroundColor DarkRed
  7318. }
  7319. }
  7320. }
  7321. if ($env:resetstuff -eq '1') {
  7322. try {
  7323. [LibTSforge.Modifiers.TamperedFlagsDelete]::DeleteTamperFlags($ver, $prod)
  7324. [LibTSforge.SPP.SLApi]::RefreshLicenseStatus()
  7325. [LibTSforge.Modifiers.RearmReset]::Reset($ver, $prod)
  7326. [LibTSforge.Modifiers.GracePeriodReset]::Reset($ver, $prod)
  7327. [LibTSforge.Modifiers.KeyChangeLockDelete]::Delete($ver, $prod)
  7328. }
  7329. catch {
  7330. $errcode = 3
  7331. Write-Host "$($_.Exception.Message)" -ForegroundColor Red -BackgroundColor Black
  7332. }
  7333. }
  7334. Exit $errcode
  7335. :tsforge:
  7336. ::========================================================================================================================================
  7337. :: Get Windows Activation ID
  7338. :wintsid:
  7339. $SysPath = "$env:SystemRoot\System32"
  7340. if (Test-Path "$env:SystemRoot\Sysnative\reg.exe") {
  7341. $SysPath = "$env:SystemRoot\Sysnative"
  7342. }
  7343. function Windows-ActID {
  7344. param (
  7345. [string]$edition,
  7346. [string]$keytype
  7347. )
  7348. $filePatterns = @(
  7349. "$SysPath\spp\tokens\skus\$edition\$edition*.xrm-ms",
  7350. "$SysPath\spp\tokens\skus\Security-SPP-Component-SKU-$edition\*-$edition-*.xrm-ms"
  7351. )
  7352. switch ($keytype) {
  7353. "zero" {
  7354. $licenseTypes = @('OEM_DM', 'OEM_COA_SLP', 'OEM_COA_NSLP', 'MAK', 'RETAIL')
  7355. }
  7356. "ks" {
  7357. $licenseTypes = @('KMSCLIENT')
  7358. }
  7359. "avma" {
  7360. $licenseTypes = @('VIRTUAL_MACHINE')
  7361. }
  7362. "kmshost" {
  7363. $licenseTypes = @('KMS_')
  7364. }
  7365. }
  7366. $softwareLicensingProducts = Get-WmiObject -Query "SELECT ID, Description, LicenseFamily FROM SoftwareLicensingProduct WHERE ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f'" | Where-Object { $_.LicenseFamily -eq $edition }
  7367. $orderedLicenses = @()
  7368. foreach ($type in $licenseTypes) {
  7369. $orderedLicenses += $softwareLicensingProducts | Where-Object { $_.Description -match $type } | Select-Object -ExpandProperty ID
  7370. }
  7371. $fileIds = @()
  7372. $muiLockedIds = @()
  7373. $kmsCountedIdCounts = @{}
  7374. $t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)
  7375. $methods = @(
  7376. @{name = 'SLOpen'; returnType = [Int32]; parameters = @([IntPtr].MakeByRefType()) },
  7377. @{name = 'SLClose'; returnType = [Int32]; parameters = @([IntPtr]) },
  7378. @{name = 'SLGetProductSkuInformation'; returnType = [Int32]; parameters = @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()) },
  7379. @{name = 'SLGetLicense'; returnType = [Int32]; parameters = @([IntPtr], [Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()) }
  7380. )
  7381. foreach ($method in $methods) {
  7382. $t.DefinePInvokeMethod($method.name, 'slc.dll', 22, 1, $method.returnType, $method.parameters, 1, 3).SetImplementationFlags(128)
  7383. }
  7384. $w = $t.CreateType()
  7385. $m = [Runtime.InteropServices.Marshal]
  7386. function GetLicenseInfo($SkuId, $checkType) {
  7387. $result = $false
  7388. $c = 0; $b = 0
  7389. [void]$w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, "fileId", [ref]$null, [ref]$c, [ref]$b)
  7390. $FileId = $m::PtrToStringUni($b)
  7391. $c = 0; $b = 0
  7392. [void]$w::SLGetLicense($hSLC, [ref][Guid]$FileId, [ref]$c, [ref]$b)
  7393. $blob = New-Object byte[] $c; $m::Copy($b, $blob, 0, $c)
  7394. $cont = [Text.Encoding]::UTF8.GetString($blob)
  7395. $xml = [xml]$cont.SubString($cont.IndexOf('<r'))
  7396. if ($checkType -eq 'MUI') {
  7397. $xml.licenseGroup.license[0].grant | foreach {
  7398. $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Kernel-MUI-Language-Allowed' } | foreach {
  7399. if ($_.InnerText -ne 'EMPTY') { $result = $true }
  7400. }
  7401. }
  7402. }
  7403. elseif ($checkType -eq 'KMS') {
  7404. $xml.licenseGroup.license[0].grant | foreach {
  7405. $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Security-SPP-KmsCountedIdList' } | foreach {
  7406. $result = ($_.InnerText.Replace(' ', '').Replace("`n", '') -split ',').Count
  7407. }
  7408. }
  7409. }
  7410. return $result
  7411. }
  7412. $hSLC = 0; [void]$w::SLOpen([ref]$hSLC)
  7413. foreach ($id in $orderedLicenses) {
  7414. if ($keytype -eq 'kmshost') {
  7415. $kmsCount = GetLicenseInfo $id 'KMS'
  7416. if ($kmsCount -gt 0) {
  7417. $kmsCountedIdCounts[$id] = $kmsCount
  7418. }
  7419. }
  7420. if ($edition -notcontains "CountrySpecific" -and (GetLicenseInfo $id 'MUI')) {
  7421. $muiLockedIds += $id
  7422. }
  7423. }
  7424. foreach ($filePattern in $filePatterns) {
  7425. $files = Get-ChildItem -Path $filePattern -Filter '*.xrm-ms' -ErrorAction SilentlyContinue
  7426. foreach ($file in $files) {
  7427. if ($null -ne $file.FullName) {
  7428. $content = Get-Content -Path $file.FullName -ErrorAction SilentlyContinue | Out-String
  7429. foreach ($id in $orderedLicenses) {
  7430. if ($content -match "name=`"productSkuId`">\{$id\}" -and -not ($file.Name -match 'Beta|Test')) {
  7431. $fileIds += $id
  7432. }
  7433. }
  7434. }
  7435. }
  7436. }
  7437. if ($kmsCountedIdCounts.Count -gt 0) {
  7438. $idWithMostIds = $kmsCountedIdCounts.GetEnumerator() | Sort-Object Value -Descending
  7439. $fileIds = $idWithMostIds | Select-Object -ExpandProperty Key
  7440. }
  7441. else {
  7442. if ($fileIds.Count -eq 0) {
  7443. $fileIds = $orderedLicenses
  7444. }
  7445. $fileIds = $orderedLicenses | Where-Object { $fileIds -contains $_ -and $muiLockedIds -notcontains $_ } | Select-Object -Unique
  7446. }
  7447. [void]$w::SLClose($hSLC)
  7448. $pkeyconfig = "$SysPath\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms"
  7449. if ($keytype -eq 'kmshost') {
  7450. $csvlkPath = "$SysPath\spp\tokens\pkeyconfig\pkeyconfig-csvlk.xrm-ms"
  7451. if (Test-Path $csvlkPath) {
  7452. $pkeyconfig = $csvlkPath
  7453. }
  7454. }
  7455. $data = [xml][Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(([xml](get-content $pkeyconfig)).licenseGroup.license.otherInfo.infoTables.infoList.infoBin.InnerText))
  7456. $betaIds = @()
  7457. $excludedIds = @()
  7458. $checkedIds = @()
  7459. foreach ($id in $fileIds) {
  7460. $actConfig = $data.ProductKeyConfiguration.Configurations.Configuration | Where-Object { $_.ActConfigId -eq "{$id}" }
  7461. if ($actConfig) {
  7462. $productDescription = $actConfig.ProductDescription
  7463. $productEditionID = $actConfig.EditionID
  7464. if ($productDescription -match 'MUI locked|Tencent|Qihoo|WAU') {
  7465. $excludedIds += $id
  7466. continue
  7467. }
  7468. if ($productDescription -match 'Beta|RC |Next |Test|Pre-') {
  7469. $betaIds += $id
  7470. continue
  7471. }
  7472. if ($keytype -ne 'kmshost' -and $productEditionID -eq '$edition') {
  7473. $checkedIds += $id
  7474. continue
  7475. }
  7476. $refGroupId = $actConfig.RefGroupId
  7477. $publicKey = $data.ProductKeyConfiguration.PublicKeys.PublicKey | Where-Object { $_.GroupId -eq $refGroupId -and $_.AlgorithmId -eq 'msft:rm/algorithm/pkey/2009' }
  7478. if ($publicKey) {
  7479. $keyRanges = $data.ProductKeyConfiguration.KeyRanges.KeyRange | Where-Object { $_.RefActConfigId -eq "{$id}" }
  7480. foreach ($keyRange in $keyRanges) {
  7481. if ($keyRange.EulaType -match 'WAU') {
  7482. $excludedIds += $id
  7483. break
  7484. }
  7485. }
  7486. }
  7487. }
  7488. }
  7489. $prefinalIds = @()
  7490. $finalIds = @()
  7491. $prefinalIds = $fileIds | Where-Object { $excludedIds -notcontains $_ } | Select-Object -Unique
  7492. $finalIds = $prefinalIds | Where-Object { $betaIds -notcontains $_ } | Select-Object -Unique
  7493. if ($finalIds.Count -eq 0) {
  7494. $finalIds = $prefinalIds
  7495. }
  7496. if ($checkedIds.Count -gt 0) {
  7497. $finalIds = $checkedIds + $finalIds
  7498. }
  7499. $firstId = $finalIds | Select-Object -First 1
  7500. return $firstId.ToLower()
  7501. }
  7502. Windows-ActID -edition "$env:tsedition" -keytype "$env:keytype"
  7503. :wintsid:
  7504. ::========================================================================================================================================
  7505. :: Get Office Activation ID
  7506. :offtsid:
  7507. function Office-ActID {
  7508. param (
  7509. [string]$pkeypath,
  7510. [string]$edition,
  7511. [string]$keytype
  7512. )
  7513. switch ($keytype) {
  7514. "zero" { $productKeyTypes = @("OEM:NONSLP","Volume:MAK","Retail") }
  7515. "ks" { $productKeyTypes = @("Volume:GVLK") }
  7516. }
  7517. $data = [xml][Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(([xml](Get-Content $pkeypath)).licenseGroup.license.otherInfo.infoTables.infoList.infoBin.InnerText))
  7518. $configurations = $data.ProductKeyConfiguration.Configurations.Configuration
  7519. $filteredConfigs = @()
  7520. foreach ($type in $productKeyTypes) {
  7521. $filteredConfigs += $configurations | Where-Object {
  7522. $_.EditionId -eq $edition -and
  7523. $_.ProductKeyType -eq $type -and
  7524. $_.ProductDescription -notmatch 'demo|MSDN|PIN'
  7525. }
  7526. }
  7527. $filterPreview = $filteredConfigs | Where-Object { $_.ProductDescription -notmatch 'preview' }
  7528. if ($filterPreview.Count -ne 0) {
  7529. $filteredConfigs = $filterPreview
  7530. }
  7531. $firstConfig = ($filteredConfigs | Select-Object -First 1).ActConfigID -replace '^\{|\}$', ''
  7532. return $firstConfig.ToLower()
  7533. }
  7534. Office-ActID -pkeypath "$env:pkeypath" -edition "$env:_License" -keytype "$env:keytype"
  7535. :offtsid:
  7536. ::========================================================================================================================================
  7537. :: 1st column = Office version number
  7538. :: 2nd column = Activation ID
  7539. :: 3rd column = Edition
  7540. :: Separator = "_"
  7541. :ts_msiofficedata
  7542. for %%# in (
  7543. :: Office 2013
  7544. 15_ab4d047b-97cf-4126-a69f-34df08e2f254_AccessRetail
  7545. 15_259de5be-492b-44b3-9d78-9645f848f7b0_AccessRuntimeRetail
  7546. 15_4374022d-56b8-48c1-9bb7-d8f2fc726343_AccessVolume
  7547. 15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_ExcelRetail
  7548. 15_ac1ae7fd-b949-4e04-a330-849bc40638cf_ExcelVolume
  7549. 15_cfaf5356-49e3-48a8-ab3c-e729ab791250_GrooveRetail
  7550. 15_4825ac28-ce41-45a7-9e6e-1fed74057601_GrooveVolume
  7551. 15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_HomeBusinessPipcRetail
  7552. 15_a2b90e7a-a797-4713-af90-f0becf52a1dd_HomeBusinessRetail
  7553. 15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_HomeStudentARMRetail
  7554. 15_ebef9f05-5273-404a-9253-c5e252f50555_HomeStudentPlusARMRetail
  7555. 15_f2de350d-3028-410a-bfae-283e00b44d0e_HomeStudentRetail
  7556. 15_44984381-406e-4a35-b1c3-e54f499556e2_InfoPathRetail
  7557. 15_9e016989-4007-42a6-8051-64eb97110cf2_InfoPathVolume
  7558. 15_9103f3ce-1084-447a-827e-d6097f68c895_LyncAcademicRetail
  7559. 15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_LyncEntryRetail
  7560. 15_fada6658-bfc6-4c4e-825a-59a89822cda8_LyncRetail
  7561. 15_e1264e10-afaf-4439-a98b-256df8bb156f_LyncVolume
  7562. 15_69ec9152-153b-471a-bf35-77ec88683eae_MondoRetail
  7563. 15_f33485a0-310b-4b72-9a0e-b1d605510dbd_MondoVolume
  7564. 15_3391e125-f6e4-4b1e-899c-a25e6092d40d_OneNoteFreeRetail
  7565. 15_8b524bcc-67ea-4876-a509-45e46f6347e8_OneNoteRetail
  7566. 15_b067e965-7521-455b-b9f7-c740204578a2_OneNoteVolume
  7567. 15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_OutlookRetail
  7568. 15_8d577c50-ae5e-47fd-a240-24986f73d503_OutlookVolume
  7569. 15_5aab8561-1686-43f7-9ff5-2c861da58d17_PersonalPipcRetail
  7570. 15_17e9df2d-ed91-4382-904b-4fed6a12caf0_PersonalRetail
  7571. 15_31743b82-bfbc-44b6-aa12-85d42e644d5b_PowerPointRetail
  7572. 15_e40dcb44-1d5c-4085-8e8f-943f33c4f004_PowerPointVolume
  7573. 15_064383fa-1538-491c-859b-0ecab169a0ab_ProPlusRetail
  7574. 15_2b88c4f2-ea8f-43cd-805e-4d41346e18a7_ProPlusVolume
  7575. 15_4e26cac1-e15a-4467-9069-cb47b67fe191_ProfessionalPipcRetail
  7576. 15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_ProfessionalRetail
  7577. 15_2f72340c-b555-418d-8b46-355944fe66b8_ProjectProRetail
  7578. 15_ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32_ProjectProVolume
  7579. 15_58d95b09-6af6-453d-a976-8ef0ae0316b1_ProjectStdRetail
  7580. 15_2b9e4a37-6230-4b42-bee2-e25ce86c8c7a_ProjectStdVolume
  7581. 15_c3a0814a-70a4-471f-af37-2313a6331111_PublisherRetail
  7582. 15_38ea49f6-ad1d-43f1-9888-99a35d7c9409_PublisherVolume
  7583. 15_ba3e3833-6a7e-445a-89d0-7802a9a68588_SPDRetail
  7584. 15_32255c0a-16b4-4ce2-b388-8a4267e219eb_StandardRetail
  7585. 15_a24cca51-3d54-4c41-8a76-4031f5338cb2_StandardVolume
  7586. 15_a56a3b37-3a35-4bbb-a036-eee5f1898eee_VisioProRetail
  7587. 15_3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d_VisioProVolume
  7588. 15_980f9e3e-f5a8-41c8-8596-61404addf677_VisioStdRetail
  7589. 15_44a1f6ff-0876-4edb-9169-dbb43101ee89_VisioStdVolume
  7590. 15_191509f2-6977-456f-ab30-cf0492b1e93a_WordRetail
  7591. 15_9cedef15-be37-4ff0-a08a-13a045540641_WordVolume
  7592. :: Office 365 - 15.0 version
  7593. 15_742178ed-6b28-42dd-b3d7-b7c0ea78741b_O365BusinessRetail
  7594. 15_a96f8dae-da54-4fad-bdc6-108da592707a_O365HomePremRetail
  7595. 15_e3dacc06-3bc2-4e13-8e59-8e05f3232325_O365ProPlusRetail
  7596. 15_0bc1dae4-6158-4a1c-a893-807665b934b2_O365SmallBusPremRetail
  7597. :: Office 365 - 16.0 version
  7598. 16_742178ed-6b28-42dd-b3d7-b7c0ea78741b_O365BusinessRetail
  7599. 16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_O365EduCloudRetail
  7600. 16_a96f8dae-da54-4fad-bdc6-108da592707a_O365HomePremRetail
  7601. 16_e3dacc06-3bc2-4e13-8e59-8e05f3232325_O365ProPlusRetail
  7602. 16_0bc1dae4-6158-4a1c-a893-807665b934b2_O365SmallBusPremRetail
  7603. :: Office 2016
  7604. 16_bfa358b0-98f1-4125-842e-585fa13032e6_AccessRetail
  7605. 16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_AccessRuntimeRetail
  7606. 16_3b2fa33f-cd5a-43a5-bd95-f49f3f546b0b_AccessVolume
  7607. 16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_ExcelRetail
  7608. 16_685062a7-6024-42e7-8c5f-6bb9e63e697f_ExcelVolume
  7609. 16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_HomeBusinessPipcRetail
  7610. 16_86834d00-7896-4a38-8fae-32f20b86fa2b_HomeBusinessRetail
  7611. 16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_HomeStudentARMRetail
  7612. 16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_HomeStudentPlusARMRetail
  7613. 16_c28acdb8-d8b3-4199-baa4-024d09e97c99_HomeStudentRetail
  7614. 16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_HomeStudentVNextRetail
  7615. 16_69ec9152-153b-471a-bf35-77ec88683eae_MondoRetail
  7616. 16_2cd0ea7e-749f-4288-a05e-567c573b2a6c_MondoVolume
  7617. 16_436366de-5579-4f24-96db-3893e4400030_OneNoteFreeRetail
  7618. 16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_OneNoteRetail
  7619. 16_23b672da-a456-4860-a8f3-e062a501d7e8_OneNoteVolume
  7620. 16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_OutlookRetail
  7621. 16_50059979-ac6f-4458-9e79-710bcb41721a_OutlookVolume
  7622. 16_5aab8561-1686-43f7-9ff5-2c861da58d17_PersonalPipcRetail
  7623. 16_a9f645a1-0d6a-4978-926a-abcb363b72a6_PersonalRetail
  7624. 16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_PowerPointRetail
  7625. 16_9b4060c9-a7f5-4a66-b732-faf248b7240f_PowerPointVolume
  7626. 16_de52bd50-9564-4adc-8fcb-a345c17f84f9_ProPlusRetail
  7627. 16_c47456e3-265d-47b6-8ca0-c30abbd0ca36_ProPlusVolume
  7628. 16_4e26cac1-e15a-4467-9069-cb47b67fe191_ProfessionalPipcRetail
  7629. 16_d64edc00-7453-4301-8428-197343fafb16_ProfessionalRetail
  7630. 16_2f72340c-b555-418d-8b46-355944fe66b8_ProjectProRetail
  7631. 16_82f502b5-b0b0-4349-bd2c-c560df85b248_ProjectProVolume
  7632. 16_16728639-a9ab-4994-b6d8-f81051e69833_ProjectProXVolume
  7633. 16_58d95b09-6af6-453d-a976-8ef0ae0316b1_ProjectStdRetail
  7634. 16_82e6b314-2a62-4e51-9220-61358dd230e6_ProjectStdVolume
  7635. 16_431058f0-c059-44c5-b9e7-ed2dd46b6789_ProjectStdXVolume
  7636. 16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_PublisherRetail
  7637. 16_fcc1757b-5d5f-486a-87cf-c4d6dedb6032_PublisherVolume
  7638. 16_9103f3ce-1084-447a-827e-d6097f68c895_SkypeServiceBypassRetail
  7639. 16_971cd368-f2e1-49c1-aedd-330909ce18b6_SkypeforBusinessEntryRetail
  7640. 16_418d2b9f-b491-4d7f-84f1-49e27cc66597_SkypeforBusinessRetail
  7641. 16_03ca3b9a-0869-4749-8988-3cbc9d9f51bb_SkypeforBusinessVolume
  7642. 16_4a31c291-3a12-4c64-b8ab-cd79212be45e_StandardRetail
  7643. 16_0ed94aac-2234-4309-ba29-74bdbb887083_StandardVolume
  7644. 16_a56a3b37-3a35-4bbb-a036-eee5f1898eee_VisioProRetail
  7645. 16_295b2c03-4b1c-4221-b292-1411f468bd02_VisioProVolume
  7646. 16_0594dc12-8444-4912-936a-747ca742dbdb_VisioProXVolume
  7647. 16_980f9e3e-f5a8-41c8-8596-61404addf677_VisioStdRetail
  7648. 16_44151c2d-c398-471f-946f-7660542e3369_VisioStdVolume
  7649. 16_1d1c6879-39a3-47a5-9a6d-aceefa6a289d_VisioStdXVolume
  7650. 16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_WordRetail
  7651. 16_c3000759-551f-4f4a-bcac-a4b42cbf1de2_WordVolume
  7652. ) do (
  7653. for /f "tokens=1-5 delims=_" %%A in ("%%#") do (
  7654. if "%oVer%"=="%%A" (
  7655. for /f "tokens=*" %%x in ('findstr /i /c:"%%B" "%_oBranding%"') do set "prodId=%%x"
  7656. set prodId=!prodId:"/>=!
  7657. set prodId=!prodId:~-4!
  7658. if "%oVer%"=="14" (
  7659. REM Exception case for Visio because wrong primary product ID is mentioned in Branding.xml
  7660. echo %%C | find /i "Visio" %nul% && set prodId=0057
  7661. )
  7662. reg query "%1\Registration\{%%B}" /v ProductCode %nul2% | find /i "-!prodId!-" %nul% && (
  7663. reg query "%1\Common\InstalledPackages" %nul2% | find /i "-!prodId!-" %nul% && (
  7664. if defined _oIds (set _oIds=!_oIds! %%C) else (set _oIds=%%C)
  7665. )
  7666. )
  7667. )
  7668. )
  7669. )
  7670. exit /b
  7671. ::========================================================================================================================================
  7672. :ts_getedition
  7673. set tsedition=
  7674. set _wtarget=
  7675. if %_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%')"
  7676. if %_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%')"
  7677. %chkedi% do if not errorlevel 1 call set "_wtarget= !_wtarget! %%a "
  7678. :: SKU and Edition ID database
  7679. for %%# in (
  7680. 1:Ultimate
  7681. 2:HomeBasic
  7682. 3:HomePremium
  7683. 4:Enterprise
  7684. 5:HomeBasicN
  7685. 6:Business
  7686. 7:ServerStandard
  7687. 8:ServerDatacenter
  7688. 9:ServerSBSStandard
  7689. 10:ServerEnterprise
  7690. 11:Starter
  7691. 12:ServerDatacenterCore
  7692. 13:ServerStandardCore
  7693. 14:ServerEnterpriseCore
  7694. 15:ServerEnterpriseIA64
  7695. 16:BusinessN
  7696. 17:ServerWeb
  7697. 18:ServerHPC
  7698. 19:ServerHomeStandard
  7699. 20:ServerStorageExpress
  7700. 21:ServerStorageStandard
  7701. 22:ServerStorageWorkgroup
  7702. 23:ServerStorageEnterprise
  7703. 24:ServerWinSB
  7704. 25:ServerSBSPremium
  7705. 26:HomePremiumN
  7706. 27:EnterpriseN
  7707. 28:UltimateN
  7708. 29:ServerWebCore
  7709. 30:ServerMediumBusinessManagement
  7710. 31:ServerMediumBusinessSecurity
  7711. 32:ServerMediumBusinessMessaging
  7712. 33:ServerWinFoundation
  7713. 34:ServerHomePremium
  7714. 35:ServerWinSBV
  7715. 36:ServerStandardV
  7716. 37:ServerDatacenterV
  7717. 38:ServerEnterpriseV
  7718. 39:ServerDatacenterVCore
  7719. 40:ServerStandardVCore
  7720. 41:ServerEnterpriseVCore
  7721. 42:ServerHyperCore
  7722. 43:ServerStorageExpressCore
  7723. 44:ServerStorageStandardCore
  7724. 45:ServerStorageWorkgroupCore
  7725. 46:ServerStorageEnterpriseCore
  7726. 47:StarterN
  7727. 48:Professional
  7728. 49:ProfessionalN
  7729. 50:ServerSolution
  7730. 51:ServerForSBSolutions
  7731. 52:ServerSolutionsPremium
  7732. 53:ServerSolutionsPremiumCore
  7733. 54:ServerSolutionEM
  7734. 55:ServerForSBSolutionsEM
  7735. 56:ServerEmbeddedSolution
  7736. 57:ServerEmbeddedSolutionCore
  7737. 58:ProfessionalEmbedded
  7738. 59:ServerEssentialManagement
  7739. 60:ServerEssentialAdditional
  7740. 61:ServerEssentialManagementSvc
  7741. 62:ServerEssentialAdditionalSvc
  7742. 63:ServerSBSPremiumCore
  7743. 64:ServerHPCV
  7744. 65:Embedded
  7745. 66:StarterE
  7746. 67:HomeBasicE
  7747. 68:HomePremiumE
  7748. 69:ProfessionalE
  7749. 70:EnterpriseE
  7750. 71:UltimateE
  7751. 72:EnterpriseEval
  7752. 74:Prerelease
  7753. 76:ServerMultiPointStandard
  7754. 77:ServerMultiPointPremium
  7755. 79:ServerStandardEval
  7756. 80:ServerDatacenterEval
  7757. 81:PrereleaseARM
  7758. 82:PrereleaseN
  7759. 84:EnterpriseNEval
  7760. 85:EmbeddedAutomotive
  7761. 86:EmbeddedIndustryA
  7762. 87:ThinPC
  7763. 88:EmbeddedA
  7764. 89:EmbeddedIndustry
  7765. 90:EmbeddedE
  7766. 91:EmbeddedIndustryE
  7767. 92:EmbeddedIndustryAE
  7768. 93:ProfessionalPlus
  7769. 95:ServerStorageWorkgroupEval
  7770. 96:ServerStorageStandardEval
  7771. 97:CoreARM
  7772. 98:CoreN
  7773. 99:CoreCountrySpecific
  7774. 100:CoreSingleLanguage
  7775. 101:Core
  7776. 103:ProfessionalWMC
  7777. 104:MobileCore
  7778. 105:EmbeddedIndustryEval
  7779. 106:EmbeddedIndustryEEval
  7780. 107:EmbeddedEval
  7781. 108:EmbeddedEEval
  7782. 109:CoreSystemServer
  7783. 110:ServerCloudStorage
  7784. 111:CoreConnected
  7785. 112:ProfessionalStudent
  7786. 113:CoreConnectedN
  7787. 114:ProfessionalStudentN
  7788. 115:CoreConnectedSingleLanguage
  7789. 116:CoreConnectedCountrySpecific
  7790. 117:ConnectedCar
  7791. 118:IndustryHandheld
  7792. 119:PPIPRO
  7793. 120:ServerARM64
  7794. 121:Education
  7795. 122:EducationN
  7796. 123:IoTUAP
  7797. 124:ServerHI
  7798. 125:EnterpriseS
  7799. 126:EnterpriseSN
  7800. 127:ProfessionalS
  7801. 128:ProfessionalSN
  7802. 129:EnterpriseSEval
  7803. 130:EnterpriseSNEval
  7804. 131:IoTUAPCommercial
  7805. 133:MobileEnterprise
  7806. 134:AnalogOneCoreEnterprise
  7807. 135:AnalogOneCore
  7808. 136:Holographic
  7809. 138:ProfessionalSingleLanguage
  7810. 139:ProfessionalCountrySpecific
  7811. 140:EnterpriseSubscription
  7812. 141:EnterpriseSubscriptionN
  7813. 143:ServerDatacenterNano
  7814. 144:ServerStandardNano
  7815. 145:ServerDatacenterACor
  7816. 146:ServerStandardACor
  7817. 147:ServerDatacenterCor
  7818. 148:ServerStandardCor
  7819. 149:UtilityVM
  7820. 159:ServerDatacenterEvalCor
  7821. 160:ServerStandardEvalCor
  7822. 161:ProfessionalWorkstation
  7823. 162:ProfessionalWorkstationN
  7824. 163:ServerAzure
  7825. 164:ProfessionalEducation
  7826. 165:ProfessionalEducationN
  7827. 168:ServerAzureCor
  7828. 169:ServerAzureNano
  7829. 171:EnterpriseG
  7830. 172:EnterpriseGN
  7831. 173:BusinessSubscription
  7832. 174:BusinessSubscriptionN
  7833. 175:ServerRdsh
  7834. 178:Cloud
  7835. 179:CloudN
  7836. 180:HubOS
  7837. 182:OneCoreUpdateOS
  7838. 183:CloudE
  7839. 184:Andromeda
  7840. 185:IoTOS
  7841. 186:CloudEN
  7842. 187:IoTEdgeOS
  7843. 188:IoTEnterprise
  7844. 189:ModernPC
  7845. 191:IoTEnterpriseS
  7846. 192:SystemOS
  7847. 193:NativeOS
  7848. 194:GameCoreXbox
  7849. 195:GameOS
  7850. 196:DurangoHostOS
  7851. 197:ScarlettHostOS
  7852. 198:Keystone
  7853. 199:CloudHost
  7854. 200:CloudMOS
  7855. 201:CloudCore
  7856. 202:CloudEditionN
  7857. 203:CloudEdition
  7858. 204:WinVOS
  7859. 205:IoTEnterpriseSK
  7860. 206:IoTEnterpriseK
  7861. 207:IoTEnterpriseSEval
  7862. 208:AgentBridge
  7863. 209:NanoHost
  7864. 210:WNC
  7865. 406:ServerAzureStackHCICor
  7866. 407:ServerTurbine
  7867. 408:ServerTurbineCor
  7868. REM Some old edition names with same SKU ID
  7869. 4:ProEnterprise
  7870. 6:ProStandard
  7871. 10:ProSBS
  7872. 16:ProStandardN
  7873. 18:ServerComputeCluster
  7874. 19:ServerHome
  7875. 30:ServerMidmarketStandard
  7876. 31:ServerMidmarketEdge
  7877. 32:ServerMidmarketPremium
  7878. 33:ServerSBSPrime
  7879. 42:ServerHyper
  7880. 64:ServerComputeClusterV
  7881. 85:EmbeddedIapetus
  7882. 86:EmbeddedTethys
  7883. 88:EmbeddedDione
  7884. 89:EmbeddedRhea
  7885. 90:EmbeddedEnceladus
  7886. 109:ServerNano
  7887. 124:ServerCloudHostInfrastructure
  7888. 133:MobileBusiness
  7889. 134:HololensEnterprise
  7890. 145:ServerDatacenterSCor
  7891. 146:ServerStandardSCor
  7892. 147:ServerDatacenterWSCor
  7893. 148:ServerStandardWSCor
  7894. 189:Lite
  7895. ) do (
  7896. for /f "tokens=1-2 delims=:" %%A in ("%%#") do if "%osSKU%"=="%%A" if not defined tsedition (
  7897. echo "%_wtarget%" | find /i " %%B " %nul% && set tsedition=%%B
  7898. )
  7899. )
  7900. if defined tsedition exit /b
  7901. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionNameFromId', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [IntPtr].MakeByRefType()), 1, 3);
  7902. set d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionNameFromId(%osSKU%, [ref]$out);$s=[Runtime.InteropServices.Marshal]::PtrToStringUni($out); $s
  7903. for %%# in (pkeyhelper.dll) do @if not "%%~$PATH:#"=="" (
  7904. for /f %%a in ('%psc% "%d1%"') do if not errorlevel 1 (
  7905. echo "%_wtarget%" | find /i " %%a " %nul% && set tsedition=%%a
  7906. )
  7907. )
  7908. exit /b
  7909. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7910. :KMS38Activation
  7911. :: To activate, run the script with "/KMS38" parameter or change 0 to 1 in below line
  7912. set _act=0
  7913. :: To remove KMS38 protection, run the script with /KMS38-RemoveProtection parameter or change 0 to 1 in below line
  7914. set _rem=0
  7915. :: To disable changing edition if current edition doesn't support KMS38 activation, change the value to 1 from 0 or run the script with "/KMS38-NoEditionChange" parameter
  7916. set _NoEditionChange=0
  7917. :: If value is changed in above lines or parameter is used then script will run in unattended mode
  7918. ::========================================================================================================================================
  7919. cls
  7920. color 07
  7921. title KMS38 Activation %masver%
  7922. set _args=
  7923. set _elev=
  7924. set _unattended=0
  7925. set _args=%*
  7926. if defined _args set _args=%_args:"=%
  7927. if defined _args (
  7928. for %%A in (%_args%) do (
  7929. if /i "%%A"=="/KMS38" set _act=1
  7930. if /i "%%A"=="/KMS38-RemoveProtection" set _rem=1
  7931. if /i "%%A"=="/KMS38-NoEditionChange" set _NoEditionChange=1
  7932. if /i "%%A"=="-el" set _elev=1
  7933. )
  7934. )
  7935. for %%A in (%_act% %_rem% %_NoEditionChange%) do (if "%%A"=="1" set _unattended=1)
  7936. ::========================================================================================================================================
  7937. set _k38=
  7938. call :dk_setvar
  7939. set "specific_kms=SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\55c92734-d682-4d71-983e-d6ec3f16059f"
  7940. if %winbuild% LSS 14393 (
  7941. %eline%
  7942. echo Unsupported OS version detected [%winbuild%].
  7943. echo KMS38 activation is only supported on Windows 10/11/Server, build 14393 and later.
  7944. echo:
  7945. if %winbuild% LSS 10240 (
  7946. call :dk_color %Blue% "Use TSforge activation option from the main menu."
  7947. ) else (
  7948. call :dk_color %Blue% "Use HWID activation option from the main menu."
  7949. )
  7950. goto dk_done
  7951. )
  7952. ::========================================================================================================================================
  7953. if %_rem%==1 goto :k_uninstall
  7954. :k_menu
  7955. if %_unattended%==0 (
  7956. cls
  7957. if not defined terminal mode 76, 25
  7958. title KMS38 Activation %masver%
  7959. echo:
  7960. echo:
  7961. echo:
  7962. echo:
  7963. echo: ______________________________________________________
  7964. echo:
  7965. echo [1] KMS38 Activation
  7966. echo ____________________________________________
  7967. echo:
  7968. echo [2] Remove KM38 Protection
  7969. echo:
  7970. echo [0] %_exitmsg%
  7971. echo: ______________________________________________________
  7972. echo:
  7973. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,0]"
  7974. choice /C:120 /N
  7975. set _el=!errorlevel!
  7976. if !_el!==3 exit /b
  7977. if !_el!==2 goto :k_uninstall
  7978. if !_el!==1 goto :k_menu2
  7979. goto :k_menu
  7980. )
  7981. ::========================================================================================================================================
  7982. :k_menu2
  7983. cls
  7984. if not defined terminal (
  7985. mode 110, 34
  7986. if exist "%SysPath%\spp\store_test\" mode 134, 34
  7987. )
  7988. title KMS38 Activation %masver%
  7989. echo:
  7990. echo Initializing...
  7991. call :dk_chkmal
  7992. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*CorEdition~*.mum" if not exist "%SysPath%\clipup.exe" set a_cor=1
  7993. if not exist %SysPath%\sppsvc.exe (set _fmiss=sppsvc.exe)
  7994. if not exist %SysPath%\ClipUp.exe if not defined a_cor (set _fmiss=%_fmiss%ClipUp.exe)
  7995. if defined _fmiss (
  7996. %eline%
  7997. echo [%_fmiss%] file is missing, aborting...
  7998. echo:
  7999. set fixes=%fixes% %mas%troubleshoot
  8000. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  8001. goto dk_done
  8002. )
  8003. ::========================================================================================================================================
  8004. set spp=SoftwareLicensingProduct
  8005. set sps=SoftwareLicensingService
  8006. call :dk_ckeckwmic
  8007. call :dk_checksku
  8008. call :dk_product
  8009. call :dk_sppissue
  8010. ::========================================================================================================================================
  8011. :: Check if system is permanently activated or not
  8012. call :dk_checkperm
  8013. if defined _perm (
  8014. cls
  8015. echo ___________________________________________________________________________________________
  8016. echo:
  8017. call :dk_color2 %_White% " " %Green% "%winos% is already permanently activated."
  8018. call :dk_color2 %_White% " " %Gray% "Activation is not required."
  8019. echo ___________________________________________________________________________________________
  8020. if %_unattended%==1 goto dk_done
  8021. echo:
  8022. choice /C:10 /N /M "> [1] Activate Anyway [0] %_exitmsg% : "
  8023. if errorlevel 2 exit /b
  8024. )
  8025. cls
  8026. ::========================================================================================================================================
  8027. :: Check Evaluation version
  8028. set _eval=
  8029. set _evalserv=
  8030. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" set _eval=1
  8031. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*EvalEdition~*.mum" set _evalserv=1
  8032. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*EvalCorEdition~*.mum" set _eval=1 & set _evalserv=1
  8033. if defined _eval (
  8034. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Eval" %nul1% && (
  8035. %eline%
  8036. echo [%winos% ^| %winbuild%]
  8037. if defined _evalserv (
  8038. echo Server Evaluation cannot be activated. Convert it to full Server OS.
  8039. echo:
  8040. call :dk_color %Blue% "Go Back to main menu and use [Change Edition] option."
  8041. ) else (
  8042. echo Evaluation editions cannot be activated outside of their evaluation period.
  8043. call :dk_color %Blue% "Use TSforge activation option from the main menu to reset evaluation period."
  8044. echo:
  8045. set fixes=%fixes% %mas%evaluation_editions
  8046. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%evaluation_editions"
  8047. )
  8048. goto dk_done
  8049. )
  8050. )
  8051. ::========================================================================================================================================
  8052. :: Check clipup.exe for the detection and activation of server cor and acor editions
  8053. if defined a_cor (
  8054. if not exist "!_work!\clipup.exe" (
  8055. %eline%
  8056. echo clipup.exe doesn't exist in Server Cor/Acor [No GUI] versions.
  8057. echo The file is required for KMS38 activation.
  8058. echo Check the below page for instructions on how to activate it.
  8059. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%kms38"
  8060. goto dk_done
  8061. )
  8062. )
  8063. :: Check file signature
  8064. if defined a_cor (
  8065. %psc% "if (-not (Get-AuthenticodeSignature -FilePath '!_work!\clipup.exe').IsOSBinary) {Exit 3}" %nul%
  8066. if !errorlevel!==3 (
  8067. %eline%
  8068. echo Valid digital signature not found in clipup.exe file.
  8069. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  8070. goto dk_done
  8071. )
  8072. )
  8073. ::========================================================================================================================================
  8074. set error=
  8075. cls
  8076. echo:
  8077. call :dk_showosinfo
  8078. ::========================================================================================================================================
  8079. echo Initiating Diagnostic Tests...
  8080. set "_serv=ClipSVC sppsvc KeyIso Winmgmt"
  8081. :: Client License Service (ClipSVC)
  8082. :: Software Protection
  8083. :: CNG Key Isolation
  8084. :: Windows Management Instrumentation
  8085. call :dk_errorcheck
  8086. ::========================================================================================================================================
  8087. :: Check if GVLK (KMS key) is already installed or not
  8088. call :k_channel
  8089. :: Detect Key
  8090. set key=
  8091. set pkey=
  8092. set altkey=
  8093. set changekey=
  8094. set altedition=
  8095. call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  8096. if defined allapps call :kms38data key
  8097. if not defined key call :k_gvlk %nul%
  8098. if defined allapps if not defined key call :kms38fallback
  8099. if defined altkey (set key=%altkey%&set changekey=1)
  8100. set /a UBR=0
  8101. if %osSKU%==191 if defined altkey if defined altedition (
  8102. for /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
  8103. if %winbuild% LSS 22598 if !UBR! LSS 2788 (
  8104. call :dk_color %Blue% "Windows must be updated to build 19044.2788 or higher for IotEnterpriseS KMS38 activation."
  8105. )
  8106. )
  8107. if not defined key if defined notfoundaltactID (
  8108. call :dk_color %Red% "Checking Alternate Edition for KMS38 [%altedition% Activation ID Not Found]"
  8109. )
  8110. if not defined key if not defined _gvlk (
  8111. echo:
  8112. echo [%winos% ^| %winbuild% ^| SKU:%osSKU%]
  8113. if exist "%SysPath%\spp\tokens\skus\%osedition%\*GVLK*.xrm-ms" set sppks=1
  8114. if defined skunotfound (
  8115. call :dk_color %Red% "Required license files not found in %SysPath%\spp\tokens\skus\"
  8116. set fixes=%fixes% %mas%troubleshoot
  8117. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  8118. )
  8119. if defined sppks (
  8120. call :dk_color %Red% "KMS38 activation is supported but failed to find the key."
  8121. set fixes=%fixes% %mas%troubleshoot
  8122. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  8123. )
  8124. if not defined skunotfound if not defined sppks (
  8125. call :dk_color %Red% "This product does not support KMS38 activation."
  8126. call :dk_color %Blue% "Use TSforge activation option from the main menu."
  8127. set fixes=%fixes% %mas%
  8128. echo %mas%
  8129. )
  8130. echo:
  8131. goto dk_done
  8132. )
  8133. ::========================================================================================================================================
  8134. :: Install key
  8135. echo:
  8136. if defined changekey (
  8137. call :dk_color %Blue% "[%altedition%] edition product key will be used to enable KMS38 activation."
  8138. echo:
  8139. )
  8140. if defined winsub (
  8141. call :dk_color %Blue% "Windows Subscription edition [SKU ID-%slcSKU%] found. Script will activate the base edition [SKU ID-%regSKU%]."
  8142. echo:
  8143. )
  8144. set _partial=
  8145. if not defined key (
  8146. if %_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=%%#"
  8147. if %_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=%%#"
  8148. call echo Checking Installed Product Key [Partial Key - %%_partial%%] [Volume:GVLK]
  8149. )
  8150. if defined key (
  8151. call :dk_inskey "[%key%]"
  8152. )
  8153. ::========================================================================================================================================
  8154. :: Check activation ID for setting specific KMS host
  8155. set app=
  8156. if %_wmic% EQU 1 for /f "tokens=2 delims==" %%a in ('"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' and Description like '%%KMSCLIENT%%' and PartialProductKey is not NULL AND LicenseDependsOn is NULL) get ID /VALUE" %nul6%') do call set "app=%%a"
  8157. if %_wmic% EQU 0 for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND Description like ''%%KMSCLIENT%%'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).ID | %% {echo ('ID='+$_)}" %nul6%') do call set "app=%%a"
  8158. if not defined app (
  8159. call :dk_color %Red% "Checking Installed GVLK Activation ID [Not Found] Aborting..."
  8160. set fixes=%fixes% %mas%troubleshoot
  8161. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  8162. goto :dk_done
  8163. )
  8164. ::========================================================================================================================================
  8165. :: Set specific KMS host to Local Host
  8166. :: By doing this, global KMS IP can not replace KMS38 activation but can be used with Office and other Windows Editions
  8167. echo:
  8168. %nul% reg delete "HKLM\%specific_kms%" /f
  8169. %nul% reg delete "HKU\S-1-5-20\%specific_kms%" /f
  8170. %nul% reg query "HKLM\%specific_kms%" && (
  8171. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':regdel\:.*';iex ($f[1])"
  8172. %nul% reg delete "HKLM\%specific_kms%" /f
  8173. )
  8174. set k_error=
  8175. %nul% reg add "HKLM\%specific_kms%\%app%" /f /v KeyManagementServiceName /t REG_SZ /d "127.0.0.2" || set k_error=1
  8176. %nul% reg add "HKLM\%specific_kms%\%app%" /f /v KeyManagementServicePort /t REG_SZ /d "1688" || set k_error=1
  8177. if not defined k_error (
  8178. echo Adding Specific KMS Host [LocalHost 127.0.0.2] [Successful]
  8179. ) else (
  8180. call :dk_color %Red% "Adding Specific KMS Host [LocalHost 127.0.0.2] [Failed]"
  8181. )
  8182. ::========================================================================================================================================
  8183. :: Copy clipup.exe to System32 directory to activate Server Cor/Acor editions
  8184. if defined a_cor (
  8185. set "_clipup=%systemroot%\System32\clipup.exe"
  8186. pushd "!_work!\"
  8187. copy /y /b "ClipUp.exe" "!_clipup!" %nul%
  8188. popd
  8189. echo:
  8190. if exist "!_clipup!" (
  8191. echo Copying clipup.exe File to [%systemroot%\System32\] [Successful]
  8192. ) else (
  8193. call :dk_color %Red% "Copying clipup.exe File to [%systemroot%\System32\] [Failed] Aborting..."
  8194. goto :k_final
  8195. )
  8196. )
  8197. ::========================================================================================================================================
  8198. :: Generate GenuineTicket.xml and apply
  8199. :: In some cases clipup -v -o method fails and in some cases service restart method fails as well
  8200. :: To maximize success rate and get better error details, script will install tickets two times (service restart + clipup -v -o)
  8201. set "tdir=%ProgramData%\Microsoft\Windows\ClipSVC\GenuineTicket"
  8202. if not exist "%tdir%\" md "%tdir%\" %nul%
  8203. if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
  8204. if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
  8205. if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*" del /f /q "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*" %nul%
  8206. :: Signature value is as it is, it's not encoded
  8207. :: Session ID is in Base64 encoded format. It's decoded value is "OSMajorVersion=5;OSMinorVersion=1;OSPlatformId=2;PP=0;GVLKExp=2038-01-19T03:14:07Z;DownlevelGenuineState=1;"
  8208. :: Check mass grave [.] dev/kms38#manual-activation to see how it's generated
  8209. set "signature=C52iGEoH+1VqzI6kEAqOhUyrWuEObnivzaVjyef8WqItVYd/xGDTZZ3bkxAI9hTpobPFNJyJx6a3uriXq3HVd7mlXfSUK9ydeoUdG4eqMeLwkxeb6jQWJzLOz41rFVSMtBL0e+ycCATebTaXS4uvFYaDHDdPw2lKY8ADj3MLgsA="
  8210. set "sessionId=TwBTAE0AYQBqAG8AcgBWAGUAcgBzAGkAbwBuAD0ANQA7AE8AUwBNAGkAbgBvAHIAVgBlAHIAcwBpAG8AbgA9ADEAOwBPAFMAUABsAGEAdABmAG8AcgBtAEkAZAA9ADIAOwBQAFAAPQAwADsARwBWAEwASwBFAHgAcAA9ADIAMAAzADgALQAwADEALQAxADkAVAAwADMAOgAxADQAOgAwADcAWgA7AEQAbwB3AG4AbABlAHYAZQBsAEcAZQBuAHUAaQBuAGUAUwB0AGEAdABlAD0AMQA7AAAA"
  8211. <nul set /p "=<?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>OA3xOriginalProductId=;OA3xOriginalProductKey=;SessionId=%sessionId%;TimeStampClient=2022-10-11T12:00:00Z</properties><signatures><signature name="clientLockboxKey" method="rsa-sha256">%signature%</signature></signatures></genuineProperties></genuineAuthorization>" >"%tdir%\GenuineTicket"
  8212. copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%
  8213. if not exist "%tdir%\GenuineTicket.xml" (
  8214. call :dk_color %Red% "Generating GenuineTicket.xml [Failed, aborting...]"
  8215. if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
  8216. goto :k_final
  8217. ) else (
  8218. echo Generating GenuineTicket.xml [Successful]
  8219. )
  8220. set "_xmlexist=if exist "%tdir%\GenuineTicket.xml""
  8221. :: Stop sppsvc
  8222. %psc% "Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null"
  8223. sc query sppsvc | find /i "STOPPED" %nul% && (
  8224. echo Stopping sppsvc Service [Successful]
  8225. ) || (
  8226. call :dk_color %Gray% "Stopping sppsvc Service [Failed]"
  8227. )
  8228. %_xmlexist% (
  8229. %psc% "Start-Job { Restart-Service ClipSVC } | Wait-Job -Timeout 20 | Out-Null"
  8230. %_xmlexist% timeout /t 2 %nul%
  8231. %_xmlexist% timeout /t 2 %nul%
  8232. %_xmlexist% (
  8233. set error=1
  8234. if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
  8235. call :dk_color %Gray% "Installing GenuineTicket.xml [Failed with ClipSVC service restart, wait...]"
  8236. )
  8237. )
  8238. copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%
  8239. clipup -v -o
  8240. set rebuildinfo=
  8241. if not exist %ProgramData%\Microsoft\Windows\ClipSVC\tokens.dat (
  8242. set error=1
  8243. set rebuildinfo=1
  8244. call :dk_color %Red% "Checking ClipSVC tokens.dat [Not Found]"
  8245. )
  8246. %_xmlexist% (
  8247. set error=1
  8248. set rebuildinfo=1
  8249. call :dk_color %Red% "Installing GenuineTicket.xml [Failed With clipup -v -o]"
  8250. )
  8251. if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*.xml" (
  8252. set error=1
  8253. set rebuildinfo=1
  8254. call :dk_color %Red% "Checking Ticket Migration [Failed]"
  8255. )
  8256. if not defined showfix if defined rebuildinfo (
  8257. set showfix=1
  8258. call :dk_color %Blue% "%_fixmsg%"
  8259. )
  8260. if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
  8261. ::==========================================================================================================================================
  8262. call :dk_product
  8263. echo:
  8264. echo Activating...
  8265. echo:
  8266. call :k_checkexp
  8267. if defined _k38 (
  8268. call :k_actinfo
  8269. goto :k_final
  8270. )
  8271. :: Clear 180 Days KMS Activation lock with Windows SKU specific rearm and without the need to restart the system
  8272. if %_wmic% EQU 1 wmic path %spp% where ID='%app%' call ReArmsku %nul%
  8273. if %_wmic% EQU 0 %psc% "$null=([WMI]'%spp%=''%app%''').ReArmsku()" %nul%
  8274. if %errorlevel%==0 (
  8275. echo Applying SKU-ID Rearm [Successful]
  8276. ) else (
  8277. call :dk_color %Red% "Applying SKU-ID Rearm [Failed]"
  8278. )
  8279. call :dk_refresh
  8280. echo:
  8281. call :k_checkexp
  8282. if defined _k38 (
  8283. call :k_actinfo
  8284. goto :k_final
  8285. )
  8286. call :dk_color %Red% "Activation Failed"
  8287. if not defined error call :dk_color %Blue% "%_fixmsg%"
  8288. set fixes=%fixes% %mas%troubleshoot
  8289. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  8290. ::========================================================================================================================================
  8291. :k_final
  8292. :: Remove the specific KMS host (LocalHost) added by the script if activation is not completed
  8293. echo:
  8294. if not defined _k38 (
  8295. %nul% reg delete "HKLM\%specific_kms%" /f
  8296. %nul% reg delete "HKU\S-1-5-20\%specific_kms%" /f
  8297. %nul% reg query "HKLM\%specific_kms%" && (
  8298. call :dk_color %Red% "Removing the Added Specific KMS Host [Failed]"
  8299. ) || (
  8300. echo Removing the Added Specific KMS Host [Successful]
  8301. )
  8302. )
  8303. :: Protect KMS38 if opted by the user and conditions are correct
  8304. if defined _k38 (
  8305. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':regdel\:.*';& ([ScriptBlock]::Create($f[1])) -protect"
  8306. %nul% reg delete "HKLM\%specific_kms%" /f
  8307. %nul% reg query "HKLM\%specific_kms%" && (
  8308. echo Protect KMS38 From KMS [Successful] [Locked a Registry Key]
  8309. ) || (
  8310. call :dk_color %Red% "Protect KMS38 From KMS [Failed to Lock a Registry Key]"
  8311. )
  8312. )
  8313. :: clipup.exe does not exist in server cor and acor editions by default, it was copied there with this script
  8314. if defined a_cor if exist "%_clipup%" del /f /q "%_clipup%" %nul%
  8315. if defined a_cor (
  8316. if exist "%_clipup%" (
  8317. call :dk_color %Red% "Deleting Copied clipup.exe File [Failed]"
  8318. ) else (
  8319. echo Deleting Copied clipup.exe File [Successful]
  8320. )
  8321. )
  8322. for %%# in (407) do if %osSKU%==%%# (
  8323. call :dk_color %Red% "%winos% does not support activation on non-azure platforms."
  8324. )
  8325. :: Trigger reevaluation of SPP's Scheduled Tasks
  8326. if defined _k38 (
  8327. call :dk_reeval %nul%
  8328. )
  8329. goto :dk_done
  8330. ::========================================================================================================================================
  8331. :k_uninstall
  8332. cls
  8333. if not defined terminal mode 99, 28
  8334. title Remove KMS38 Protection %masver%
  8335. %nul% reg delete "HKLM\%specific_kms%" /f
  8336. %nul% reg delete "HKU\S-1-5-20\%specific_kms%" /f
  8337. %nul% reg query "HKLM\%specific_kms%" && (
  8338. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':regdel\:.*';iex ($f[1])"
  8339. %nul% reg delete "HKLM\%specific_kms%" /f
  8340. )
  8341. echo:
  8342. %nul% reg query "HKLM\%specific_kms%" && (
  8343. call :dk_color %Red% "Removing Specific KMS Host [Failed]"
  8344. ) || (
  8345. echo Removing Specific KMS Host [Successful]
  8346. )
  8347. goto :dk_done
  8348. ::========================================================================================================================================
  8349. :: This code runs to protect/undo below registry key for KMS38 protection
  8350. :: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\55c92734-d682-4d71-983e-d6ec3f16059f
  8351. :: KMS38 protection stops 180 days KMS Activation from replacing KMS38 activation
  8352. :regdel:
  8353. param (
  8354. [switch]$protect
  8355. )
  8356. $SID = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544')
  8357. $Admin = ($SID.Translate([System.Security.Principal.NTAccount])).Value
  8358. if($protect) {
  8359. $ruleArgs = @("$Admin", "Delete, SetValue", "ContainerInherit", "None", "Deny")
  8360. } else {
  8361. $ruleArgs = @("$Admin", "FullControl", "Allow")
  8362. }
  8363. $path = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\55c92734-d682-4d71-983e-d6ec3f16059f'
  8364. $key = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64').OpenSubKey($path, 'ReadWriteSubTree', 'ChangePermissions')
  8365. $acl = $key.GetAccessControl()
  8366. $rule = [System.Security.AccessControl.RegistryAccessRule]::new.Invoke($ruleArgs)
  8367. $acl.ResetAccessRule($rule)
  8368. $key.SetAccessControl($acl)
  8369. :regdel:
  8370. ::========================================================================================================================================
  8371. :: Check KMS activation status
  8372. :k_actinfo
  8373. set xpr=
  8374. for /f "tokens=* delims=" %%# in ('%psc% "$([DateTime]::Now.addMinutes(%gpr%)).ToString('yyyy-MM-dd HH:mm:ss')" %nul6%') do set "xpr=%%#"
  8375. call :dk_color %Green% "%winos% is activated till !xpr!"
  8376. exit /b
  8377. :: Check remaining KMS activation grace period
  8378. :k_checkexp
  8379. set gpr=0
  8380. if %_wmic% EQU 1 for /f "tokens=2 delims==" %%# in ('"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' and Description like '%%KMSCLIENT%%' and PartialProductKey is not NULL AND LicenseDependsOn is NULL) get GracePeriodRemaining /VALUE" %nul6%') do set "gpr=%%#"
  8381. if %_wmic% EQU 0 for /f "tokens=2 delims==" %%# in ('%psc% "(([WMISEARCHER]'SELECT GracePeriodRemaining FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND Description like ''%%KMSCLIENT%%'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).GracePeriodRemaining | %% {echo ('GracePeriodRemaining='+$_)}" %nul6%') do set "gpr=%%#"
  8382. if %gpr% GTR 259200 (set _k38=1) else (set _k38=)
  8383. exit /b
  8384. :: Get Windows installed key channel
  8385. :k_channel
  8386. set _gvlk=
  8387. if %_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)
  8388. if %_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)
  8389. exit /b
  8390. ::========================================================================================================================================
  8391. :: Get Product Key from pkeyhelper.dll for future new editions
  8392. :: It works on Windows 10 1803 (17134) and later builds.
  8393. :k_pkey
  8394. call :dk_reflection
  8395. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SkuGetProductKeyForEdition', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [String], [String].MakeByRefType(), [String].MakeByRefType()), 1, 3);
  8396. set d1=%d1% $out = ''; [void]$TypeBuilder.CreateType()::SkuGetProductKeyForEdition(%1, %2, [ref]$out, [ref]$null); $out
  8397. set pkey=
  8398. for /f %%a in ('%psc% "%d1%"') do if not errorlevel 1 (set pkey=%%a)
  8399. exit /b
  8400. :: Get channel name for the key which was extracted from pkeyhelper.dll
  8401. :k_pkeychannel
  8402. set k=%1
  8403. set m=[Runtime.InteropServices.Marshal]
  8404. set p=%SysPath%\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms
  8405. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('PidGenX', 'pidgenx.dll', 'Public, Static', 1, [int], @([String], [String], [String], [int], [IntPtr], [IntPtr], [IntPtr]), 1, 3);
  8406. set d1=%d1% $r = [byte[]]::new(0x04F8); $r[0] = 0xF8; $r[1] = 0x04; $f = %m%::AllocHGlobal(0x04F8); %m%::Copy($r, 0, $f, 0x04F8);
  8407. set 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)
  8408. set pkeychannel=
  8409. for /f %%a in ('%psc% "%d1%"') do if not errorlevel 1 (set pkeychannel=%%a)
  8410. exit /b
  8411. :k_gvlk
  8412. for %%# in (pkeyhelper.dll) do @if "%%~$PATH:#"=="" exit /b
  8413. for %%# in (Volume:GVLK) do (
  8414. call :k_pkey %osSKU% '%%#'
  8415. if defined pkey call :k_pkeychannel !pkey!
  8416. if /i "!pkeychannel!"=="%%#" (
  8417. set key=!pkey!
  8418. exit /b
  8419. )
  8420. )
  8421. exit /b
  8422. ::========================================================================================================================================
  8423. :: 1st column = Activation ID
  8424. :: 2nd column = GVLK (Generic volume licensing key)
  8425. :: 3rd column = SKU ID
  8426. :: 4th column = WMI Edition ID (For reference only)
  8427. :: 5th column = Build Branch name incase same Edition ID is used in different OS versions with different key (For reference only)
  8428. :: Separator = "_"
  8429. :kms38data
  8430. set f=
  8431. for %%# in (
  8432. :: Windows 10/11
  8433. 73111121-5638-40f6-bc11-f1d7b0d64300_NPPR9-FWDCX-D2C8J-H872K-2Y%f%T43___4_Enterprise
  8434. e272e3e2-732f-4c65-a8f0-484747d0d947_DPH2V-TTNVB-4X9Q3-TJR4H-KH%f%JW4__27_EnterpriseN
  8435. 2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX__48_Professional
  8436. a80b5abf-76ad-428b-b05d-a47d2dffeebf_MH37W-N47XK-V7XM9-C7227-GC%f%QG9__49_ProfessionalN
  8437. 7b9e1751-a8da-4f75-9560-5fadfe3d8e38_3KHY7-WNT83-DGQKR-F7HPR-84%f%4BM__98_CoreN
  8438. a9107544-f4a0-4053-a96a-1479abdef912_PVMJN-6DFY6-9CCP6-7BKTT-D3%f%WVR__99_CoreCountrySpecific
  8439. cd918a57-a41b-4c82-8dce-1a538e221a83_7HNRX-D7KGG-3K4RQ-4WPJ4-YT%f%DFH_100_CoreSingleLanguage
  8440. 58e97c99-f377-4ef1-81d5-4ad5522b5fd8_TX9XD-98N7V-6WMQ6-BX7FG-H8%f%Q99_101_Core
  8441. e0c42288-980c-4788-a014-c080d2e1926e_NW6C2-QMPVW-D7KKK-3GKT6-VC%f%FB2_121_Education
  8442. 3c102355-d027-42c6-ad23-2e7ef8a02585_2WH4N-8QGBV-H22JP-CT43Q-MD%f%WWJ_122_EducationN
  8443. 32d2fab3-e4a8-42c2-923b-4bf4fd13e6ee_M7XTQ-FN8P6-TTKYV-9D4CC-J4%f%62D_125_EnterpriseS_RS5,VB,Ge
  8444. 2d5a5a60-3040-48bf-beb0-fcd770c20ce0_DCPHK-NFMTC-H88MJ-PFHPY-QJ%f%4BJ_125_EnterpriseS_RS1
  8445. 7b51a46c-0c04-4e8f-9af4-8496cca90d5e_WNMTR-4C88C-JK8YV-HQ7T2-76%f%DF9_125_EnterpriseS_TH1
  8446. 7103a333-b8c8-49cc-93ce-d37c09687f92_92NFX-8DJQP-P6BBQ-THF9C-7C%f%G2H_126_EnterpriseSN_RS5,VB,Ge
  8447. 9f776d83-7156-45b2-8a5c-359b9c9f22a3_QFFDN-GRT3P-VKWWX-X7T3R-8B%f%639_126_EnterpriseSN_RS1
  8448. 87b838b7-41b6-4590-8318-5797951d8529_2F77B-TNFGY-69QQF-B8YKP-D6%f%9TJ_126_EnterpriseSN_TH1
  8449. 82bbc092-bc50-4e16-8e18-b74fc486aec3_NRG8B-VKK3Q-CXVCJ-9G2XF-6Q%f%84J_161_ProfessionalWorkstation
  8450. 4b1571d3-bafb-4b40-8087-a961be2caf65_9FNHH-K3HBT-3W4TD-6383H-6X%f%YWF_162_ProfessionalWorkstationN
  8451. 3f1afc82-f8ac-4f6c-8005-1d233e606eee_6TP4R-GNPTD-KYYHQ-7B7DP-J4%f%47Y_164_ProfessionalEducation
  8452. 5300b18c-2e33-4dc2-8291-47ffcec746dd_YVWGF-BXNMC-HTQYQ-CPQ99-66%f%QFC_165_ProfessionalEducationN
  8453. e0b2d383-d112-413f-8a80-97f373a5820c_YYVX9-NTFWV-6MDM3-9PT4T-4M%f%68B_171_EnterpriseG
  8454. e38454fb-41a4-4f59-a5dc-25080e354730_44RPN-FTY23-9VTTB-MP9BX-T8%f%4FV_172_EnterpriseGN
  8455. ec868e65-fadf-4759-b23e-93fe37f2cc29_CPWHC-NT2C7-VYW78-DHDB2-PG%f%3GK_175_ServerRdsh_RS5
  8456. e4db50ea-bda1-4566-b047-0ca50abc6f07_7NBT4-WGBQX-MP4H7-QXFF8-YP%f%3KX_175_ServerRdsh_RS3
  8457. 0df4f814-3f57-4b8b-9a9d-fddadcd69fac_NBTWJ-3DR69-3C4V8-C26MC-GQ%f%9M6_183_CloudE
  8458. 59eb965c-9150-42b7-a0ec-22151b9897c5_KBN8V-HFGQ4-MGXVD-347P6-PD%f%QGT_191_IoTEnterpriseS_VB,NI
  8459. d30136fc-cb4b-416e-a23d-87207abc44a9_6XN7V-PCBDC-BDBRH-8DQY7-G6%f%R44_202_CloudEditionN
  8460. ca7df2e3-5ea0-47b8-9ac1-b1be4d8edd69_37D7F-N49CB-WQR8W-TBJ73-FM%f%8RX_203_CloudEdition
  8461. :: Windows 2016/19/22/25 LTSC/SAC
  8462. 7dc26449-db21-4e09-ba37-28f2958506a6_TVRH6-WHNXV-R9WG3-9XRFY-MY%f%832___7_ServerStandard_Ge
  8463. 9bd77860-9b31-4b7b-96ad-2564017315bf_VDYBN-27WPP-V4HQT-9VMD4-VM%f%K7H___7_ServerStandard_FE
  8464. de32eafd-aaee-4662-9444-c1befb41bde2_N69G4-B89J2-4G8F4-WWYCC-J4%f%64C___7_ServerStandard_RS5
  8465. 8c1c5410-9f39-4805-8c9d-63a07706358f_WC2BQ-8NRM3-FDDYY-2BFGV-KH%f%KQY___7_ServerStandard_RS1
  8466. c052f164-cdf6-409a-a0cb-853ba0f0f55a_D764K-2NDRG-47T6Q-P8T8W-YP%f%6DF___8_ServerDatacenter_Ge
  8467. ef6cfc9f-8c5d-44ac-9aad-de6a2ea0ae03_WX4NM-KYWYW-QJJR4-XV3QB-6V%f%M33___8_ServerDatacenter_FE
  8468. 34e1ae55-27f8-4950-8877-7a03be5fb181_WMDGN-G9PQG-XVVXX-R3X43-63%f%DFG___8_ServerDatacenter_RS5
  8469. 21c56779-b449-4d20-adfc-eece0e1ad74b_CB7KF-BWN84-R7R2Y-793K2-8X%f%DDG___8_ServerDatacenter_RS1
  8470. 034d3cbb-5d4b-4245-b3f8-f84571314078_WVDHN-86M7X-466P6-VHXV7-YY%f%726__50_ServerSolution_RS5
  8471. 2b5a1b0f-a5ab-4c54-ac2f-a6d94824a283_JCKRF-N37P4-C2D82-9YXRT-4M%f%63B__50_ServerSolution_RS1
  8472. 7b4433f4-b1e7-4788-895a-c45378d38253_QN4C6-GBJD2-FB422-GHWJK-GJ%f%G2R_110_ServerCloudStorage
  8473. 8de8eb62-bbe0-40ac-ac17-f75595071ea3_GRFBW-QNDC4-6QBHG-CCK3B-2P%f%R88_120_ServerARM64_RS5
  8474. 43d9af6e-5e86-4be8-a797-d072a046896c_K9FYF-G6NCK-73M32-XMVPY-F9%f%DRR_120_ServerARM64_RS4
  8475. 39e69c41-42b4-4a0a-abad-8e3c10a797cc_QFND9-D3Y9C-J3KKY-6RPVP-2D%f%PYV_145_ServerDatacenterACor_FE
  8476. 90c362e5-0da1-4bfd-b53b-b87d309ade43_6NMRW-2C8FM-D24W7-TQWMY-CW%f%H2D_145_ServerDatacenterACor_RS5
  8477. e49c08e7-da82-42f8-bde2-b570fbcae76c_2HXDN-KRXHB-GPYC7-YCKFJ-7F%f%VDG_145_ServerDatacenterACor_RS3
  8478. f5e9429c-f50b-4b98-b15c-ef92eb5cff39_67KN8-4FYJW-2487Q-MQ2J7-4C%f%4RG_146_ServerStandardACor_FE
  8479. 73e3957c-fc0c-400d-9184-5f7b6f2eb409_N2KJX-J94YW-TQVFB-DG9YT-72%f%4CC_146_ServerStandardACor_RS5
  8480. 61c5ef22-f14f-4553-a824-c4b31e84b100_PTXN8-JFHJM-4WC78-MPCBR-9W%f%4KR_146_ServerStandardACor_RS3
  8481. 45b5aff2-60a0-42f2-bc4b-ec6e5f7b527e_FCNV3-279Q9-BQB46-FTKXX-9H%f%PRH_168_ServerAzureCor_Ge
  8482. 8c8f0ad3-9a43-4e05-b840-93b8d1475cbc_6N379-GGTMK-23C6M-XVVTC-CK%f%FRQ_168_ServerAzureCor_FE
  8483. a99cc1f0-7719-4306-9645-294102fbff95_FDNH6-VW9RW-BXPJ7-4XTYG-23%f%9TB_168_ServerAzureCor_RS5
  8484. 3dbf341b-5f6c-4fa7-b936-699dce9e263f_VP34G-4NPPG-79JTQ-864T4-R3%f%MQX_168_ServerAzureCor_RS1
  8485. c2e946d1-cfa2-4523-8c87-30bc696ee584_XGN3F-F394H-FD2MY-PP6FD-8M%f%CRC_407_ServerTurbine_Ge
  8486. 19b5e0fb-4431-46bc-bac1-2f1873e4ae73_NTBV8-9K7Q8-V27C6-M2BTV-KH%f%MXV_407_ServerTurbine_RS5
  8487. ) do (
  8488. for /f "tokens=1-5 delims=_" %%A in ("%%#") do if %osSKU%==%%C (
  8489. if %1==key if not defined key echo "!allapps!" | find /i "%%A" %nul1% && set key=%%B
  8490. )
  8491. )
  8492. exit /b
  8493. ::========================================================================================================================================
  8494. :: Below code is used to get alternate edition name and key if current edition doesn't support KMS38 activation
  8495. :: 1st column = Current SKU ID
  8496. :: 2nd column = Current Edition Name
  8497. :: 3rd column = Current Edition Activation ID
  8498. :: 4th column = Alternate Edition Activation ID
  8499. :: 5th column = Alternate Edition GVLK
  8500. :: 6th column = Alternate Edition Name
  8501. :: Separator = _
  8502. :kms38fallback
  8503. set notfoundaltactID=
  8504. if %_NoEditionChange%==1 exit /b
  8505. for %%# in (
  8506. 188_IoTEnterprise__________________8ab9bdd1-1f67-4997-82d9-8878520837d9_73111121-5638-40f6-bc11-f1d7b0d64300_NPPR9-FWDCX-D2C8J-H872K-2Y%f%T43_Enterprise
  8507. 206_IoTEnterpriseK_________________80083eae-7031-4394-9e88-4901973d56fe_73111121-5638-40f6-bc11-f1d7b0d64300_NPPR9-FWDCX-D2C8J-H872K-2Y%f%T43_Enterprise
  8508. 191_IoTEnterpriseS-2021____________ed655016-a9e8-4434-95d9-4345352c2552_32d2fab3-e4a8-42c2-923b-4bf4fd13e6ee_M7XTQ-FN8P6-TTKYV-9D4CC-J4%f%62D_EnterpriseS-2021
  8509. 205_IoTEnterpriseSK________________d4f9b41f-205c-405e-8e08-3d16e88e02be_59eb965c-9150-42b7-a0ec-22151b9897c5_KBN8V-HFGQ4-MGXVD-347P6-PD%f%QGT_IoTEnterpriseS
  8510. 138_ProfessionalSingleLanguage_____a48938aa-62fa-4966-9d44-9f04da3f72f2_2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX_Professional
  8511. 139_ProfessionalCountrySpecific____f7af7d09-40e4-419c-a49b-eae366689ebd_2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX_Professional
  8512. 139_ProfessionalCountrySpecific-Zn_01eb852c-424d-4060-94b8-c10d799d7364_2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX_Professional
  8513. ) do (
  8514. for /f "tokens=1-6 delims=_" %%A in ("%%#") do if %osSKU%==%%A (
  8515. echo "!allapps!" | find /i "%%C" %nul1% && (
  8516. echo "!allapps!" | find /i "%%D" %nul1% && (
  8517. set altkey=%%E
  8518. set altedition=%%F
  8519. ) || (
  8520. set altedition=%%F
  8521. set notfoundaltactID=1
  8522. )
  8523. )
  8524. )
  8525. )
  8526. exit /b
  8527. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8528. :KMSActivation
  8529. :: To activate Windows with K-M-S activation, run the script with "/K-Windows" parameter or change 0 to 1 in below line
  8530. set _actwin=0
  8531. :: 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
  8532. set _actoff=0
  8533. :: 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
  8534. set _actprojvis=0
  8535. :: 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
  8536. set _actwinoff=0
  8537. :: 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
  8538. set _NoEditionChange=0
  8539. :: To NOT auto-install renewal task with activation, run the script with "/K-NoRenewalTask" parameter or change 0 to 1 in below line
  8540. set _norentsk=0
  8541. :: 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.
  8542. set _uni=0
  8543. :: Advanced options:
  8544. :: Don't use renewal task option if you are going to use a specific server name instead of public servers used in the script
  8545. :: To specify a server address for activation, run the script with "/K-Server-YOURKMSSERVERNAME" parameter or add it in below line after = sign
  8546. set _server=
  8547. :: To specify a port for activation, run the script with "/K-Port-YOURPORTNAME" parameter or add it in below line after = sign
  8548. set _port=
  8549. :: Script will run in unattended mode if parameters are used OR value is changed in above lines FOR activation or uninstall.
  8550. ::========================================================================================================================================
  8551. cls
  8552. color 07
  8553. set KS=K%blank%MS
  8554. title Online %KS% Activation %masver%
  8555. set _args=
  8556. set _elev=
  8557. set _unattended=0
  8558. set _args=%*
  8559. if defined _args set _args=%_args:"=%
  8560. if defined _args for %%A in (%_args%) do (
  8561. if /i "%%A"=="-el" (set _elev=1)
  8562. if /i "%%A"=="/K-Windows" (set _actwin=1)
  8563. if /i "%%A"=="/K-Office" (set _actoff=1)
  8564. if /i "%%A"=="/K-ProjectVisio" (set _actprojvis=1)
  8565. if /i "%%A"=="/K-WindowsOffice" (set _actwinoff=1)
  8566. if /i "%%A"=="/K-NoEditionChange" (set _NoEditionChange=1)
  8567. if /i "%%A"=="/K-NoRenewalTask" (set _norentsk=1)
  8568. if /i "%%A"=="/K-Uninstall" (set _uni=1)
  8569. echo "%%A" | find /i "/K-Port-" >nul && (set "_port=%%A" & call set "_port=%%_port:~8%%")
  8570. echo "%%A" | find /i "/K-Server-" >nul && (set "_server=%%A" & call set "_server=%%_server:~10%%")
  8571. )
  8572. for %%A in (%_actwin% %_actoff% %_actprojvis% %_actwinoff% %_uni%) do (if "%%A"=="1" set _unattended=1)
  8573. ::========================================================================================================================================
  8574. if %_uni%==1 goto :ks_uninstall
  8575. :ks_menu
  8576. if defined _server set _norentsk=1
  8577. if not defined _server set _port=
  8578. if %_unattended%==0 (
  8579. cls
  8580. if not defined terminal mode 76, 30
  8581. title Online %KS% Activation %masver%
  8582. echo:
  8583. echo:
  8584. echo:
  8585. echo:
  8586. if exist "%ProgramFiles%\Activation-Renewal\Activation_task.cmd" (
  8587. find /i "Ver:2.7" "%ProgramFiles%\Activation-Renewal\Activation_task.cmd" %nul% || (
  8588. call :dk_color %_Yellow% " Old renewal task found, run activation to update it."
  8589. )
  8590. )
  8591. echo ______________________________________________________________
  8592. echo:
  8593. echo [1] Activate - Windows
  8594. echo [2] Activate - Office [All]
  8595. echo [3] Activate - Office [Project/Visio]
  8596. echo [4] Activate - All
  8597. echo _______________________________________________
  8598. echo:
  8599. if %_norentsk%==0 (
  8600. echo [5] Renewal Task With Activation [Yes]
  8601. ) else (
  8602. call :dk_color2 %_White% " [5] Renewal Task With Activation " %_Yellow% "[No]"
  8603. )
  8604. if %_NoEditionChange%==0 (
  8605. echo [6] Change Edition If Needed [Yes]
  8606. ) else (
  8607. call :dk_color2 %_White% " [6] Change Edition If Needed " %_Yellow% "[No]"
  8608. )
  8609. echo [7] Uninstall Online %KS%
  8610. echo _______________________________________________
  8611. echo:
  8612. if defined _server (
  8613. echo [8] Set %KS% Server/Port [%_server%] [%_port%]
  8614. ) else (
  8615. echo [8] Set %KS% Server/Port
  8616. )
  8617. echo [9] Download Office
  8618. echo [0] %_exitmsg%
  8619. echo ______________________________________________________________
  8620. echo:
  8621. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,3,4,5,6,7,8,9,0]"
  8622. choice /C:1234567890 /N
  8623. set _el=!errorlevel!
  8624. if !_el!==10 exit /b
  8625. if !_el!==9 start %mas%genuine-installation-media & goto :ks_menu
  8626. if !_el!==8 goto :ks_ip
  8627. if !_el!==7 cls & call :ks_uninstall & cls & goto :ks_menu
  8628. if !_el!==6 (if %_NoEditionChange%==0 (set _NoEditionChange=1) else (set _NoEditionChange=0)) & goto :ks_menu
  8629. if !_el!==5 (if %_norentsk%==0 (set _norentsk=1) else (set _norentsk=0)) & goto :ks_menu
  8630. if !_el!==4 cls & setlocal & set "_actwin=1" & set "_actoff=1" & set "_actprojvis=0" & call :ks_start & endlocal & cls & goto :ks_menu
  8631. if !_el!==3 cls & setlocal & set "_actwin=0" & set "_actoff=0" & set "_actprojvis=1" & call :ks_start & endlocal & cls & goto :ks_menu
  8632. if !_el!==2 cls & setlocal & set "_actwin=0" & set "_actoff=1" & set "_actprojvis=0" & call :ks_start & endlocal & cls & goto :ks_menu
  8633. if !_el!==1 cls & setlocal & set "_actwin=1" & set "_actoff=0" & set "_actprojvis=0" & call :ks_start & endlocal & cls & goto :ks_menu
  8634. goto :ks_menu
  8635. )
  8636. ::========================================================================================================================================
  8637. :ks_start
  8638. cls
  8639. if not defined terminal (
  8640. mode 115, 32
  8641. if exist "%SysPath%\spp\store_test\" mode 135, 32
  8642. %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%
  8643. )
  8644. title Online %KS% Activation %masver%
  8645. echo:
  8646. echo Initializing...
  8647. call :dk_chkmal
  8648. if not exist %SysPath%\sppsvc.exe (
  8649. %eline%
  8650. echo [%SysPath%\sppsvc.exe] file is missing, aborting...
  8651. echo:
  8652. set fixes=%fixes% %mas%troubleshoot
  8653. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  8654. goto dk_done
  8655. )
  8656. ::========================================================================================================================================
  8657. if %_actprojvis%==1 (set "_actoff=1")
  8658. if %_actwinoff%==1 (set "_actwin=1" & set "_actoff=1")
  8659. set spp=SoftwareLicensingProduct
  8660. set sps=SoftwareLicensingService
  8661. call :dk_ckeckwmic
  8662. call :dk_checksku
  8663. call :dk_product
  8664. call :dk_sppissue
  8665. ::========================================================================================================================================
  8666. set error=
  8667. cls
  8668. echo:
  8669. call :dk_showosinfo
  8670. :: Check Internet connection
  8671. set _int=
  8672. for %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (
  8673. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
  8674. )
  8675. if not defined _int (
  8676. %psc% "If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}"
  8677. if !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)
  8678. )
  8679. if defined _int (
  8680. echo Checking Internet Connection [Connected%ping_f%]
  8681. ) else (
  8682. set error=1
  8683. call :dk_color %Red% "Checking Internet Connection [Not Connected]"
  8684. call :dk_color %Blue% "Internet is required for Online %KS% Activation."
  8685. )
  8686. ::========================================================================================================================================
  8687. echo Initiating Diagnostic Tests...
  8688. set "_serv=sppsvc Winmgmt"
  8689. :: Software Protection
  8690. :: Windows Management Instrumentation
  8691. if %_actwin%==0 set notwinact=1
  8692. call :dk_errorcheck
  8693. ::========================================================================================================================================
  8694. call :_taskclear-cache
  8695. call :_tasksetserv
  8696. if not %_actwin%==1 goto :ks_office
  8697. :: Process Windows
  8698. :: Check if system is permanently activated or not
  8699. echo:
  8700. echo Processing Windows...
  8701. call :dk_checkperm
  8702. if defined _perm (
  8703. call :dk_color %Gray% "Checking OS Activation [Windows is already permanently activated]"
  8704. goto :ks_office
  8705. )
  8706. :: Check Evaluation version
  8707. set _eval=
  8708. set _evalserv=
  8709. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" set _eval=1
  8710. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*EvalEdition~*.mum" set _evalserv=1
  8711. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*EvalCorEdition~*.mum" set _eval=1 & set _evalserv=1
  8712. if defined _eval (
  8713. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Eval" %nul1% && (
  8714. call :dk_color %Red% "Checking Evaluation Edition [Evaluation editions cannot be activated outside of evaluation period.]"
  8715. if defined _evalserv (
  8716. call :dk_color %Blue% "Go back to main menu and use [Change Edition] option."
  8717. ) else (
  8718. call :dk_color %Blue% "Use TSforge activation option from the main menu to reset evaluation period."
  8719. set fixes=%fixes% %mas%evaluation_editions
  8720. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%evaluation_editions"
  8721. )
  8722. goto :ks_office
  8723. )
  8724. )
  8725. ::========================================================================================================================================
  8726. :: Check if GVLK is already installed or not
  8727. call :k_channel
  8728. :: Detect Key
  8729. set key=
  8730. set pkey=
  8731. set altkey=
  8732. set changekey=
  8733. set altedition=
  8734. call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  8735. if defined allapps call :ksdata winkey
  8736. if not defined key call :k_gvlk %nul%
  8737. if defined allapps if not defined key call :kms38fallback
  8738. if defined altkey (set key=%altkey%&set changekey=1)
  8739. set /a UBR=0
  8740. if %osSKU%==191 if defined altkey if defined altedition (
  8741. for /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
  8742. if %winbuild% LSS 22598 if !UBR! LSS 2788 (
  8743. call :dk_color %Blue% "Windows must be updated to build 19044.2788 or higher for IotEnterpriseS %KS% activation."
  8744. )
  8745. )
  8746. if not defined key if defined notfoundaltactID (
  8747. call :dk_color %Red% "Checking Alternate Edition For %KS% [%altedition% Activation ID Not Found]"
  8748. )
  8749. if not defined key if not defined _gvlk (
  8750. echo [%winos% ^| %winbuild% ^| SKU:%osSKU%]
  8751. if %winbuild% GEQ 9200 if exist "%SysPath%\spp\tokens\skus\%osedition%\*GVLK*.xrm-ms" set sppks=1
  8752. if %winbuild% LSS 9200 if exist "%SysPath%\spp\tokens\skus\Security-SPP-Component-SKU-%osedition%\*VLKMS*.xrm-ms" set sppks=1
  8753. if %winbuild% LSS 9200 if exist "%SysPath%\spp\tokens\skus\Security-SPP-Component-SKU-%osedition%\*VL-BYPASS*.xrm-ms" set sppks=1
  8754. if defined skunotfound (
  8755. call :dk_color %Red% "Required license files not found in %SysPath%\spp\tokens\skus\"
  8756. set fixes=%fixes% %mas%troubleshoot
  8757. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  8758. )
  8759. if defined sppks (
  8760. call :dk_color %Red% "%KS% activation is supported but failed to find the %KS% key."
  8761. set fixes=%fixes% %mas%troubleshoot
  8762. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  8763. )
  8764. if not defined skunotfound if not defined sppks (
  8765. call :dk_color %Red% "This product does not support %KS% activation."
  8766. call :dk_color %Blue% "Use TSforge activation option from the main menu."
  8767. )
  8768. echo:
  8769. goto :ks_office
  8770. )
  8771. ::========================================================================================================================================
  8772. :: Install key
  8773. if defined changekey (
  8774. call :dk_color %Blue% "[%altedition%] edition product key will be used to enable %KS% activation."
  8775. echo:
  8776. )
  8777. if defined winsub (
  8778. call :dk_color %Blue% "Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%]."
  8779. echo:
  8780. )
  8781. set _partial=
  8782. if not defined key (
  8783. if %_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=%%#"
  8784. if %_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=%%#"
  8785. call echo Checking Installed Product Key [Partial Key - %%_partial%%] [Volume:GVLK]
  8786. )
  8787. if defined key (
  8788. call :dk_inskey "[%key%]"
  8789. )
  8790. ::========================================================================================================================================
  8791. :ks_office
  8792. if not %_actoff%==1 goto :ks_activate
  8793. call :ks_setspp
  8794. :: Check ohook install
  8795. set ohook=
  8796. for %%# in (15 16) do (
  8797. for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do (
  8798. if exist "%%~A\Microsoft Office\Office%%#\sppc*dll" set ohook=1
  8799. )
  8800. )
  8801. for %%# in (System SystemX86) do (
  8802. for %%G in ("Office 15" "Office") do (
  8803. for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do (
  8804. if exist "%%~A\Microsoft %%~G\root\vfs\%%#\sppc*dll" set ohook=1
  8805. )
  8806. )
  8807. )
  8808. if defined ohook (
  8809. echo:
  8810. call :dk_color %Gray% "Checking Ohook [Ohook activation is already installed for Office]"
  8811. )
  8812. :: Check unsupported office versions
  8813. set o14c2r=
  8814. set _68=HKLM\SOFTWARE\Microsoft\Office
  8815. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  8816. %nul% reg query %_68%\14.0\CVH /f Click2run /k && set o14c2r=Office 2010 C2R
  8817. %nul% reg query %_86%\14.0\CVH /f Click2run /k && set o14c2r=Office 2010 C2R
  8818. if not "%o14c2r%"=="" (
  8819. echo:
  8820. call :dk_color %Red% "Checking Unsupported Office Install [ %o14c2r%]"
  8821. )
  8822. if %winbuild% GEQ 10240 %psc% "Get-AppxPackage -name "Microsoft.MicrosoftOfficeHub"" | find /i "Office" %nul1% && (
  8823. set ohub=1
  8824. )
  8825. ::========================================================================================================================================
  8826. :: Check supported office versions
  8827. call :ks_getpath
  8828. set o16uwp=
  8829. set o16uwp_path=
  8830. if %winbuild% GEQ 10240 (
  8831. for /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"))
  8832. )
  8833. sc query ClickToRunSvc %nul%
  8834. set error1=%errorlevel%
  8835. if defined o16c2r if %error1% EQU 1060 (
  8836. echo:
  8837. call :dk_color %Red% "Checking ClickToRun Service [Not found, Office 16.0 files found]"
  8838. set o16c2r=
  8839. set error=1
  8840. )
  8841. sc query OfficeSvc %nul%
  8842. set error2=%errorlevel%
  8843. if defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (
  8844. echo:
  8845. call :dk_color %Red% "Checking ClickToRun Service [Not found, Office 15.0 files found]"
  8846. set o15c2r=
  8847. set error=1
  8848. )
  8849. if "%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%"=="" (
  8850. set error=1
  8851. echo:
  8852. if not "%o14c2r%"=="" (
  8853. call :dk_color %Red% "Checking Supported Office Install [Not Found]"
  8854. ) else (
  8855. call :dk_color %Red% "Checking Installed Office [Not Found]"
  8856. )
  8857. if defined ohub (
  8858. echo:
  8859. echo You have only Office dashboard app installed, you need to install full Office version.
  8860. )
  8861. call :dk_color %Blue% "Download and install Office from below URL and try again."
  8862. set fixes=%fixes% %mas%genuine-installation-media
  8863. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  8864. goto :ks_activate
  8865. )
  8866. set multioffice=
  8867. if not "%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%"=="1" set multioffice=1
  8868. if not "%o14c2r%"=="" set multioffice=1
  8869. if defined multioffice (
  8870. echo:
  8871. call :dk_color %Gray% "Checking Multiple Office Install [Found. Recommended to install one version only]"
  8872. )
  8873. ::========================================================================================================================================
  8874. :: Process Office UWP
  8875. if not defined o16uwp goto :ks_starto15c2r
  8876. call :ks_reset
  8877. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  8878. set oVer=16
  8879. set "_oLPath=%o16uwp_path%\Licenses16"
  8880. for /f "delims=" %%a in ('%psc% "(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty Dependencies) | Select-Object PackageFullName" %nul6%') do (set "o16uwpapplist=!o16uwpapplist! %%a")
  8881. echo "%o16uwpapplist%" | findstr /i "Access Excel OneNote Outlook PowerPoint Publisher SkypeForBusiness Word" %nul% && set "_oIds=O365HomePremRetail"
  8882. for %%# in (Project Visio) do (
  8883. echo "%o16uwpapplist%" | findstr /i "%%#" %nul% && (
  8884. set _lat=
  8885. if exist "%_oLPath%\%%#Pro2024VL*.xrm-ms" set "_oIds= !_oIds! %%#Pro2024Retail " & set _lat=1
  8886. if not defined _lat if exist "%_oLPath%\%%#Pro2021VL*.xrm-ms" set "_oIds= !_oIds! %%#Pro2021Retail " & set _lat=1
  8887. if not defined _lat if exist "%_oLPath%\%%#Pro2019VL*.xrm-ms" set "_oIds= !_oIds! %%#Pro2019Retail " & set _lat=1
  8888. if not defined _lat set "_oIds= !_oIds! %%#ProRetail "
  8889. )
  8890. )
  8891. set uwpinfo=%o16uwp_path:C:\Program Files\WindowsApps\Microsoft.Office.Desktop_=%
  8892. echo:
  8893. echo Processing Office... [UWP ^| %uwpinfo%]
  8894. if not defined _oIds (
  8895. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  8896. set error=1
  8897. goto :ks_starto15c2r
  8898. )
  8899. call :ks_process
  8900. ::========================================================================================================================================
  8901. :ks_starto15c2r
  8902. :: Process Office 15.0 C2R
  8903. if not defined o15c2r goto :ks_starto16c2r
  8904. call :ks_reset
  8905. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  8906. set oVer=15
  8907. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  8908. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  8909. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  8910. for /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")
  8911. if not defined _oArch for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v Platform" %nul6%') do (set "_oArch=%%b")
  8912. if not defined _version for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v version" %nul6%') do (set "_version=%%b")
  8913. if 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")
  8914. echo "%o15c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=10) || (set _tok=9)
  8915. for /f "tokens=%_tok% delims=\" %%a in ('reg query %o15c2r_reg%\ProductReleaseIDs\Active %nul6% ^| findstr /i "Retail Volume"') do (
  8916. echo "!_oIds!" | find /i " %%a " %nul1% || (set "_oIds= !_oIds! %%a ")
  8917. )
  8918. set "_oLPath=%_oRoot%\Licenses"
  8919. set "_oIntegrator=%_oRoot%\integration\integrator.exe"
  8920. echo:
  8921. echo Processing Office... [C2R ^| %_version% ^| %_oArch%]
  8922. if not defined _oIds (
  8923. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  8924. set error=1
  8925. goto :ks_starto16c2r
  8926. )
  8927. if "%_actprojvis%"=="0" call :oh_fixprids
  8928. call :ks_process
  8929. ::========================================================================================================================================
  8930. :ks_starto16c2r
  8931. :: Process Office 16.0 C2R
  8932. if not defined o16c2r goto :ks_startmsi
  8933. call :ks_reset
  8934. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  8935. set oVer=16
  8936. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  8937. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  8938. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  8939. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v AudienceData" %nul6%') do (set "_AudienceData=^| %%b ")
  8940. for /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")
  8941. echo "%o16c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=9) || (set _tok=8)
  8942. for /f "tokens=%_tok% delims=\" %%a in ('reg query "%o16c2r_reg%\ProductReleaseIDs" /s /f ".16" /k %nul6% ^| findstr /i "Retail Volume"') do (
  8943. echo "!_oIds!" | find /i " %%a " %nul1% || (set "_oIds= !_oIds! %%a ")
  8944. )
  8945. set _oIds=%_oIds:.16=%
  8946. set _o16c2rIds=%_oIds%
  8947. set "_oLPath=%_oRoot%\Licenses16"
  8948. set "_oIntegrator=%_oRoot%\integration\integrator.exe"
  8949. echo:
  8950. echo Processing Office... [C2R ^| %_version% %_AudienceData%^| %_oArch%]
  8951. if not defined _oIds (
  8952. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  8953. set error=1
  8954. goto :ks_startmsi
  8955. )
  8956. if "%_actprojvis%"=="0" call :oh_fixprids
  8957. call :ks_process
  8958. ::========================================================================================================================================
  8959. :ks_startmsi
  8960. if defined o14msi call :ks_setspp 14
  8961. if defined o14msi call :ks_processmsi 14 %o14msi_reg%
  8962. call :ks_setspp
  8963. if defined o15msi call :ks_processmsi 15 %o15msi_reg%
  8964. if defined o16msi call :ks_processmsi 16 %o16msi_reg%
  8965. ::========================================================================================================================================
  8966. echo:
  8967. call :oh_clearblock
  8968. if "%o16msi%%o15msi%"=="" if not "%o16uwp%%o16c2r%%o15c2r%"=="" if "%keyerror%"=="0" if %_NoEditionChange%==0 call :oh_uninstkey
  8969. call :oh_licrefresh
  8970. ::========================================================================================================================================
  8971. :ks_activate
  8972. :: Opt out of sending KMSclient activation data to Microsoft
  8973. :: https://learn.microsoft.com/windows/privacy/manage-connections-from-windows-operating-system-components-to-microsoft-services#19-software-protection-platform
  8974. if %winbuild% GEQ 9600 (
  8975. reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\Software Protection Platform" /v NoGenTicket /t REG_DWORD /d 1 /f %nul%
  8976. if %winbuild% EQU 14393 reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\Software Protection Platform" /v NoAcquireGT /t REG_DWORD /d 1 /f %nul%
  8977. echo Turn off %KS% AVS Validation [Successful]
  8978. )
  8979. set "slp=SoftwareLicensingProduct"
  8980. set "ospp=OfficeSoftwareProtectionProduct"
  8981. echo:
  8982. echo Activating Volume Products...
  8983. if %_actwin%==1 call :_taskgetids sppwid %slp% windows
  8984. if %_actoff%==1 call :_taskgetids sppoid %slp% office
  8985. if %_actoff%==1 call :_taskgetids osppid %ospp% office
  8986. if not defined sppwid if not defined sppoid if not defined osppid (
  8987. if not defined keyerror (
  8988. echo No installed Volume Windows / Office products found.
  8989. ) else (
  8990. call :dk_color %Red% "Failed to get installed Volume Windows / Office products."
  8991. )
  8992. call :_taskgetserv
  8993. call :_taskregserv
  8994. )
  8995. call :_taskact
  8996. if not defined showfix if defined _tserror (call :dk_color %Blue% "%_fixmsg%" & set showfix=1)
  8997. :: Don't create renewal task if Windows/Office volume IDs are not found, even if script is set to create it by default
  8998. :: 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
  8999. set _deltask=
  9000. if not %_norentsk%==0 set _deltask=1
  9001. if not defined _deltask (
  9002. if %_actwin%==0 call :_taskgetids sppwid %slp% windows
  9003. if %_actoff%==0 call :_taskgetids sppoid %slp% office
  9004. if %_actoff%==0 call :_taskgetids osppid %ospp% office
  9005. )
  9006. if not defined sppwid if not defined sppoid if not defined osppid (set _deltask=1)
  9007. if defined oemerr if not defined sppoid if not defined osppid (set _deltask=1)
  9008. if not defined _deltask (
  9009. call :ks_renewal
  9010. ) else (
  9011. if exist "%ProgramFiles%\Activation-Renewal\Activation_task.cmd" call :dk_color %Gray% "Deleting activation renewal task..."
  9012. call :dk_color %Gray% "Skipping creation of activation renewal task..."
  9013. call :ks_clearstuff %nul%
  9014. if not defined _server (
  9015. if %winbuild% GEQ 9200 (
  9016. for /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"
  9017. for /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"
  9018. if defined _C16R (
  9019. REM mass grave[.]dev/office-license-is-not-genuine
  9020. set _server=10.0.0.10
  9021. call :_taskregserv
  9022. echo Keeping the non-existent IP address 10.0.0.10 as %KS% Server.
  9023. )
  9024. )
  9025. if not defined _C16R (
  9026. call :_taskclear-cache
  9027. echo Cleared %KS% Server from the registry.
  9028. )
  9029. )
  9030. )
  9031. :: https://learn.microsoft.com/azure/virtual-desktop/windows-10-multisession-faq
  9032. if %_actwin%==1 for %%# in (407) do if %osSKU%==%%# (
  9033. call :dk_color %Red% "%winos% does not support activation on non-azure platforms."
  9034. )
  9035. if %_actoff%==1 if defined sppoid if not defined _tserror if %_NoEditionChange%==0 if defined ohub (
  9036. echo:
  9037. call :dk_color %Gray% "Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app."
  9038. )
  9039. :: Trigger reevaluation of SPP's Scheduled Tasks
  9040. call :dk_reeval %nul%
  9041. goto :dk_done
  9042. ::========================================================================================================================================
  9043. :ks_ip
  9044. cls
  9045. set _server=
  9046. echo:
  9047. echo Enter / Paste the %KS% Server address, or just press Enter to return:
  9048. echo:
  9049. set /p _server=
  9050. if not defined _server goto :ks_menu
  9051. set "_server=%_server: =%"
  9052. echo:
  9053. echo Enter / Paste the %KS% Port address, or just press Enter to use default:
  9054. echo:
  9055. set /p _port=
  9056. if not defined _port goto :ks_menu
  9057. set "_port=%_port: =%"
  9058. goto :ks_menu
  9059. ::========================================================================================================================================
  9060. :ks_reset
  9061. set key=
  9062. set _oRoot=
  9063. set _oArch=
  9064. set _oIds=
  9065. set _oLPath=
  9066. set _actid=
  9067. set _prod=
  9068. set _lic=
  9069. set _arr=
  9070. set _prids=
  9071. set _config=
  9072. set _version=
  9073. set _License=
  9074. set _oBranding=
  9075. exit /b
  9076. ::========================================================================================================================================
  9077. :ks_getpath
  9078. set o16c2r=
  9079. set o15c2r=
  9080. set o16msi=
  9081. set o15msi=
  9082. set o14msi=
  9083. set _68=HKLM\SOFTWARE\Microsoft\Office
  9084. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  9085. for /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)
  9086. for /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)
  9087. for /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)
  9088. for /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)
  9089. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o16msi=1&set o16msi_reg=%_86%\16.0)
  9090. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o16msi=1&set o16msi_reg=%_68%\16.0)
  9091. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o15msi=1&set o15msi_reg=%_86%\15.0)
  9092. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o15msi=1&set o15msi_reg=%_68%\15.0)
  9093. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o14msi=1&set o14msi_reg=%_86%\14.0)
  9094. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set o14msi=1&set o14msi_reg=%_68%\14.0)
  9095. exit /b
  9096. ::========================================================================================================================================
  9097. :: After retail to volume conversion, new product ID needs .OSPPReady key in registry, otherwise product info may not fully reflect
  9098. :ks_osppready
  9099. if not defined _config exit /b
  9100. echo: %_config% | find /i "propertyBag" %nul1% && (
  9101. set "_osppt=REG_DWORD"
  9102. set "_osppready=%o15c2r_reg%"
  9103. ) || (
  9104. set "_osppt=REG_SZ"
  9105. set "_osppready=%_config%"
  9106. )
  9107. reg add %_osppready% /f /v %_altoffid%.OSPPReady /t %_osppt% /d 1 %nul1%
  9108. :: Office builds before 16.0.10730.20102 need the Installed license product ID in ProductReleaseIds, otherwise product info may not fully reflect
  9109. if exist "%_oLPath%\Word2019VL_KMS_Client_AE*.xrm-ms" exit /b
  9110. reg query %_prids% | findstr /I "%_altoffid%" %nul1%
  9111. if %errorlevel% NEQ 0 (
  9112. for /f "skip=2 tokens=2*" %%a in ('reg query %_prids%') do reg add %_prids% /t REG_SZ /d "%%b,%_altoffid%" /f %nul1%
  9113. )
  9114. exit /b
  9115. ::========================================================================================================================================
  9116. :ks_setspp
  9117. if %winbuild% GEQ 9200 (
  9118. set spp=SoftwareLicensingProduct
  9119. set sps=SoftwareLicensingService
  9120. ) else (
  9121. set spp=OfficeSoftwareProtectionProduct
  9122. set sps=OfficeSoftwareProtectionService
  9123. )
  9124. if "%1"=="14" (
  9125. set spp=OfficeSoftwareProtectionProduct
  9126. set sps=OfficeSoftwareProtectionService
  9127. )
  9128. exit /b
  9129. ::========================================================================================================================================
  9130. :ks_process
  9131. for %%# in (%_oIds%) do (
  9132. set skipprocess=
  9133. if %_NoEditionChange%==1 if not defined _oBranding (
  9134. set foundprod=
  9135. call :ksdata chkprod %%#
  9136. if not defined foundprod (
  9137. set skipprocess=1
  9138. call :dk_color %Gray% "Skipping Because NoEditionChange Mode [%%#]"
  9139. )
  9140. )
  9141. if "%_actprojvis%"=="1" if not defined skipprocess (
  9142. echo %%# | findstr /i "Project Visio" %nul% || (
  9143. set skipprocess=1
  9144. call :dk_color %Gray% "Skipping Because Project/Visio Mode [%%#]"
  9145. )
  9146. )
  9147. if "%_actprojvis%"=="0" if not defined skipprocess echo %_oIds% | findstr /i "O365" %nul% && (
  9148. echo %%# | findstr /i "Project Visio" %nul% && (
  9149. set skipprocess=1
  9150. echo Skipping Because Mondo Is Available [%%#]
  9151. )
  9152. )
  9153. if not defined skipprocess (
  9154. set key=
  9155. set _actid=
  9156. set _preview=
  9157. set _License=%%#
  9158. set _altoffid=
  9159. echo %%# | find /i "2024" %nul% && (
  9160. if exist "!_oLPath!\ProPlus2024PreviewVL_*.xrm-ms" if not exist "!_oLPath!\ProPlus2024VL_*.xrm-ms" set _preview=-Preview
  9161. )
  9162. set _prod=%%#!_preview!
  9163. call :ksdata getinfo !_prod!
  9164. if defined _altoffid (
  9165. set _License=!_altoffid!
  9166. echo Converting Retail To Volume [!_prod! To !_altoffid!]
  9167. set _prod=!_altoffid!
  9168. call :ks_osppready
  9169. )
  9170. if not "!key!"=="" (
  9171. echo "!allapps!" | find /i "!_actid!" %nul1% || call :oh_installlic
  9172. call :dk_inskey "[!key!] [!_prod!]"
  9173. ) else (
  9174. if not defined _oBranding (
  9175. set error=1
  9176. call :dk_color %Red% "Checking Product In Script [Office %oVer%.0 !_prod! not found in script]"
  9177. call :dk_color %Blue% "Make sure you are using Latest MAS script."
  9178. ) else (
  9179. call :dk_color %Red% "Checking Product In Script [!_prod! MSI Retail is not supported]"
  9180. call :dk_color %Blue% "Uninstall this and Install C2R or MSI VL version of Office."
  9181. )
  9182. set fixes=%fixes% %mas%genuine-installation-media
  9183. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  9184. )
  9185. )
  9186. )
  9187. exit /b
  9188. ::========================================================================================================================================
  9189. :ks_processmsi
  9190. :: Process Office MSI Version
  9191. call :ks_reset
  9192. if "%1"=="14" (
  9193. call :dk_actids 59a52881-a989-479d-af46-f275c6370663
  9194. ) else (
  9195. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  9196. )
  9197. set oVer=%1
  9198. for /f "skip=2 tokens=2*" %%a in ('"reg query %2\Common\InstallRoot /v Path" %nul6%') do (set "_oRoot=%%b")
  9199. for /f "skip=2 tokens=2*" %%a in ('"reg query %2\Common\ProductVersion /v LastProduct" %nul6%') do (set "_version=%%b")
  9200. if "%_oRoot:~-1%"=="\" set "_oRoot=%_oRoot:~0,-1%"
  9201. echo "%2" | find /i "Wow6432Node" %nul1% && set _oArch=x86
  9202. if not "%osarch%"=="x86" if not defined _oArch set _oArch=x64
  9203. if "%osarch%"=="x86" set _oArch=x86
  9204. set "_common=%CommonProgramFiles%"
  9205. if defined PROCESSOR_ARCHITEW6432 set "_common=%CommonProgramW6432%"
  9206. set "_common2=%CommonProgramFiles(x86)%"
  9207. for /r "%_common%\Microsoft Shared\OFFICE%oVer%\" %%f in (BRANDING.XML) do if exist "%%f" set "_oBranding=%%f"
  9208. if not defined _oBranding for /r "%_common2%\Microsoft Shared\OFFICE%oVer%\" %%f in (BRANDING.XML) do if exist "%%f" set "_oBranding=%%f"
  9209. call :ksdata getmsiprod %2
  9210. call :ks_msiretaildata getmsiret %2
  9211. echo:
  9212. echo Processing Office... [MSI ^| %_version% ^| %_oArch%]
  9213. if not defined _oBranding (
  9214. set error=1
  9215. call :dk_color %Red% "Checking BRANDING.XML [Not Found. Aborting activation...]"
  9216. exit /b
  9217. )
  9218. if not defined _oIds (
  9219. set error=1
  9220. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  9221. exit /b
  9222. )
  9223. call :ks_process
  9224. exit /b
  9225. ::========================================================================================================================================
  9226. :ks_uninstall
  9227. cls
  9228. if not defined terminal mode 91, 30
  9229. title Online %KS% Complete Uninstall %masver%
  9230. set "uline=__________________________________________________________________________________________"
  9231. set "_C16R="
  9232. for /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"
  9233. for /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"
  9234. if %winbuild% GEQ 9200 if defined _C16R (
  9235. echo:
  9236. call :dk_color %Gray% "Notice-"
  9237. echo:
  9238. echo To make sure Office programs do not show a non-genuine banner,
  9239. echo please run the activation option once, and don't uninstall afterward.
  9240. echo %uline%
  9241. )
  9242. echo:
  9243. set error_=
  9244. call :_taskclear-cache
  9245. call :ks_clearstuff
  9246. :: check KMS38 lock
  9247. %nul% reg query "HKLM\%SPPk%\%_wApp%" && (
  9248. set error_=9
  9249. echo Failed to completely clear %KS% Cache.
  9250. reg query "HKLM\%SPPk%\%_wApp%" /s %nul2% | findstr /i "127.0.0.2" %nul1% && echo KMS38 activation is locked.
  9251. ) || (
  9252. echo Cleared %KS% Cache successfully.
  9253. )
  9254. if defined error_ (
  9255. if "%error_%"=="1" (
  9256. echo %uline%
  9257. %eline%
  9258. echo Try Again / Restart the System
  9259. echo %uline%
  9260. )
  9261. ) else (
  9262. echo %uline%
  9263. echo:
  9264. call :dk_color %Green% "Online %KS% has been successfully uninstalled."
  9265. echo %uline%
  9266. )
  9267. goto :dk_done
  9268. :ks_clearstuff
  9269. set "key=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\taskcache\tasks"
  9270. reg query "%key%" /f Path /s | find /i "\Activation-Renewal" %nul1% && (
  9271. echo Deleting [Task] Activation-Renewal
  9272. schtasks /delete /tn Activation-Renewal /f %nul%
  9273. )
  9274. reg query "%key%" /f Path /s | find /i "\Activation-Run_Once" %nul1% && (
  9275. echo Deleting [Task] Activation-Run_Once
  9276. schtasks /delete /tn Activation-Run_Once /f %nul%
  9277. )
  9278. If exist "%ProgramFiles%\Activation-Renewal\" (
  9279. echo Deleting [Folder] %ProgramFiles%\Activation-Renewal\
  9280. rmdir /s /q "%ProgramFiles%\Activation-Renewal\" %nul%
  9281. )
  9282. :: Stuff from old MAS versions
  9283. schtasks /delete /tn Online_%KS%_Activation_Script-Renewal /f %nul%
  9284. schtasks /delete /tn Online_%KS%_Activation_Script-Run_Once /f %nul%
  9285. del /f /q "%ProgramData%\Online_%KS%_Activation.cmd" %nul%
  9286. rmdir /s /q "%ProgramData%\Activation-Renewal\" %nul%
  9287. rmdir /s /q "%ProgramData%\Online_%KS%_Activation\" %nul%
  9288. rmdir /s /q "%windir%\Online_%KS%_Activation_Script\" %nul%
  9289. reg delete "HKCR\DesktopBackground\shell\Activate Windows - Office" /f %nul%
  9290. :: Check if all is removed
  9291. reg query "%key%" /f Path /s | find /i "\Activation-Renewal" %nul1% && (set error_=1)
  9292. reg query "%key%" /f Path /s | find /i "\Activation-Run_Once" %nul1% && (set error_=1)
  9293. reg query "%key%" /f Path /s | find /i "\Online_%KS%_Activation_Script" %nul1% && (set error_=1)
  9294. If exist "%windir%\Online_%KS%_Activation_Script\" (set error_=1)
  9295. reg query "HKCR\DesktopBackground\shell\Activate Windows - Office" %nul% && (set error_=1)
  9296. if exist "%ProgramData%\Online_%KS%_Activation.cmd" (set error_=1)
  9297. if exist "%ProgramData%\Online_%KS%_Activation\" (set error_=1)
  9298. if exist "%ProgramData%\Activation-Renewal\" (set error_=1)
  9299. if exist "%ProgramFiles%\Activation-Renewal\" (set error_=1)
  9300. exit /b
  9301. ::========================================================================================================================================
  9302. :_extracttask:
  9303. @echo off
  9304. :: Renew K-M-S activation with Online servers via scheduled task
  9305. ::============================================================================
  9306. ::
  9307. :: Homepage: mass grave[.]dev
  9308. :: Email: mas.help@outlook.com
  9309. ::
  9310. ::============================================================================
  9311. if not "%~1"=="Task" (
  9312. echo:
  9313. echo ====== Error ======
  9314. echo:
  9315. echo This file is supposed to be run only by the scheduled task.
  9316. echo:
  9317. echo Press any key to exit
  9318. pause >nul
  9319. exit /b
  9320. )
  9321. :: Set Environment variables, it helps if they are misconfigured in the system
  9322. setlocal EnableExtensions
  9323. setlocal DisableDelayedExpansion
  9324. set "PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
  9325. set "SysPath=%SystemRoot%\System32"
  9326. set "Path=%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\"
  9327. if exist "%SystemRoot%\Sysnative\reg.exe" (
  9328. set "SysPath=%SystemRoot%\Sysnative"
  9329. set "Path=%SystemRoot%\Sysnative;%SystemRoot%;%SystemRoot%\Sysnative\Wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%Path%"
  9330. )
  9331. set "ComSpec=%SysPath%\cmd.exe"
  9332. set "PSModulePath=%ProgramFiles%\WindowsPowerShell\Modules;%SysPath%\WindowsPowerShell\v1.0\Modules"
  9333. >nul fltmc || exit /b
  9334. ::========================================================================================================================================
  9335. set _tserror=
  9336. set winbuild=1
  9337. set "nul=>nul 2>&1"
  9338. for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
  9339. set psc=powershell.exe
  9340. set run_once=
  9341. set t_name=Renewal Task
  9342. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\taskcache\tasks" /f Path /s | find /i "\Activation-Run_Once" >nul && (
  9343. set run_once=1
  9344. set t_name=Run Once Task
  9345. )
  9346. set _wmic=0
  9347. for %%# in (wmic.exe) do @if not "%%~$PATH:#"=="" (
  9348. cmd /c "wmic path Win32_ComputerSystem get CreationClassName /value" 2>nul | find /i "computersystem" 1>nul && set _wmic=1
  9349. )
  9350. setlocal EnableDelayedExpansion
  9351. if exist "%ProgramFiles%\Activation-Renewal\" call :_taskstart>>"%ProgramFiles%\Activation-Renewal\Logs.txt"
  9352. exit
  9353. ::========================================================================================================================================
  9354. :_taskstart
  9355. echo:
  9356. echo %date%, %time%
  9357. set /a loop=1
  9358. set /a max_loop=4
  9359. call :_tasksetserv
  9360. :_intrepeat
  9361. :: Check Internet connection. Works even if ICMP echo is disabled.
  9362. for %%a in (%srvlist%) do (
  9363. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (
  9364. if not "%%#"=="" goto _taskIntConnected
  9365. )
  9366. )
  9367. nslookup dns.msftncsi.com 2>nul | find "131.107.255.255" 1>nul
  9368. if "%errorlevel%"=="0" goto _taskIntConnected
  9369. if %loop%==%max_loop% (
  9370. set _tserror=1
  9371. goto _taskend
  9372. )
  9373. echo:
  9374. echo Error: Internet is not connected
  9375. echo Waiting 30 seconds
  9376. timeout /t 30 >nul
  9377. set /a loop=%loop%+1
  9378. goto _intrepeat
  9379. :_taskIntConnected
  9380. ::========================================================================================================================================
  9381. call :_taskclear-cache
  9382. :: Check WMI and sppsvc Errors
  9383. set applist=
  9384. net start sppsvc /y %nul%
  9385. if %_wmic% EQU 1 set "chkapp=for /f "tokens=2 delims==" %%a in ('"wmic path %slp% where (ApplicationID='%_wApp%') get ID /VALUE" 2^>nul')"
  9386. if %_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')"
  9387. %chkapp% do (if defined applist (call set "applist=!applist! %%a") else (call set "applist=%%a"))
  9388. if not defined applist (
  9389. set _tserror=1
  9390. if %_wmic% EQU 1 wmic path Win32_ComputerSystem get CreationClassName /value 2>nul | find /i "computersystem" 1>nul
  9391. if %_wmic% EQU 0 %psc% "Get-CIMInstance -Class Win32_ComputerSystem | Select-Object -Property CreationClassName" 2>nul | find /i "computersystem" 1>nul
  9392. if !errorlevel! NEQ 0 (set e_wmispp=WMI, SPP) else (set e_wmispp=SPP)
  9393. echo:
  9394. echo Error: Not Respoding- !e_wmispp!
  9395. echo:
  9396. )
  9397. ::========================================================================================================================================
  9398. :: Check installed volume products activation ID's
  9399. call :_taskgetids sppwid %slp% windows
  9400. call :_taskgetids sppoid %slp% office
  9401. call :_taskgetids osppid %ospp% office
  9402. ::========================================================================================================================================
  9403. echo:
  9404. echo Renewing K-M-S activation for all installed Volume products
  9405. if not defined sppwid if not defined sppoid if not defined osppid (
  9406. echo:
  9407. echo No installed Volume Windows / Office product found
  9408. echo:
  9409. echo Renewing K-M-S server
  9410. call :_taskgetserv
  9411. call :_taskregserv
  9412. goto :_skipact
  9413. )
  9414. ::========================================================================================================================================
  9415. call :_taskact
  9416. :_skipact
  9417. ::========================================================================================================================================
  9418. if defined run_once (
  9419. echo:
  9420. echo Deleting Scheduled Task Activation-Run_Once
  9421. schtasks /delete /tn Activation-Run_Once /f %nul%
  9422. )
  9423. ::========================================================================================================================================
  9424. :_taskend
  9425. echo:
  9426. echo Exiting
  9427. echo ______________________________________________________________________
  9428. if defined _tserror (exit /b 123456789) else (exit /b 0)
  9429. ::========================================================================================================================================
  9430. :_act
  9431. set prodname=
  9432. if %_wmic% EQU 1 for /f "tokens=2 delims==" %%# in ('"wmic path !_path! where ID='!_actid!' get LicenseFamily /VALUE" 2^>nul') do (call set "prodname=%%#")
  9433. if %_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=%%#")
  9434. for /f "tokens=1 delims=-_" %%a in ("%prodname%") do set "prodname=%%a"
  9435. set _taskskip=
  9436. if "%_actprojvis%"=="1" (
  9437. echo: %prodname% | find /i "Office" %nul% && (
  9438. echo: %prodname% | findstr /i "Project Visio" %nul% || (set _taskskip=1& exit /b)
  9439. )
  9440. )
  9441. if defined t_name Activating: %prodname%
  9442. set errorcode=12345
  9443. set /a act_attempt=0
  9444. :_act2
  9445. if %act_attempt% GTR 4 exit /b
  9446. if not "%act_ok%"=="1" (
  9447. if not defined _server call :_taskgetserv
  9448. call :_taskregserv
  9449. )
  9450. if not !server_num! GTR %max_servers% (
  9451. if "%1"=="act_win" if %_kms38% EQU 1 (
  9452. set act_ok=1
  9453. exit /b
  9454. )
  9455. if %_wmic% EQU 1 wmic path !_path! where ID='!_actid!' call Activate %nul%
  9456. if %_wmic% EQU 0 %psc% "try {$null=(([WMISEARCHER]'SELECT ID FROM !_path! where ID=''!_actid!''').Get()).Activate(); exit 0} catch { exit $_.Exception.InnerException.HResult }"
  9457. call set errorcode=!errorlevel!
  9458. if !errorcode! EQU 0 (
  9459. set act_ok=1
  9460. exit /b
  9461. )
  9462. if "%1"=="act_win" if !errorcode! EQU -1073418187 if %winbuild% LSS 9200 (
  9463. set act_ok=1
  9464. exit /b
  9465. )
  9466. set act_ok=0
  9467. set /a act_attempt+=1
  9468. if not defined _server goto _act2
  9469. )
  9470. exit /b
  9471. ::========================================================================================================================================
  9472. :_actinfo
  9473. if "%1"=="act_win" if not defined t_name (set prodname=%winos%)
  9474. if "%1"=="act_win" if %_kms38% EQU 1 (
  9475. if defined t_name (
  9476. echo %prodname% is already activated with KMS38.
  9477. ) else (
  9478. call :dk_color %Green% "%prodname% is already activated with KMS38."
  9479. )
  9480. exit /b
  9481. )
  9482. if %errorcode% EQU 12345 (
  9483. if defined t_name (
  9484. echo %prodname% activation failed due to restricted or no Internet.
  9485. ) else (
  9486. call :dk_color %Red% "%prodname% activation failed due to restricted or no Internet."
  9487. )
  9488. set showfix=1
  9489. set _tserror=1
  9490. exit /b
  9491. )
  9492. if %errorcode% EQU -1073418187 if "%1"=="act_win" if %winbuild% LSS 9200 (
  9493. if defined t_name (
  9494. echo %prodname% cannot be KMS-activated on this computer due to unqualified OEM BIOS [0xC004F035].
  9495. ) else (
  9496. call :dk_color %Red% "%prodname% cannot be KMS-activated on this computer due to unqualified OEM BIOS [0xC004F035]."
  9497. call :dk_color %Blue% "Use TSforge activation option from the main menu."
  9498. )
  9499. set oemerr=1
  9500. set showfix=1
  9501. exit /b
  9502. )
  9503. if %errorcode% EQU -1073418124 (
  9504. if defined t_name (
  9505. echo %prodname% activation failed due to Internet issue [0xC004F074].
  9506. ) else (
  9507. call :dk_color %Red% "%prodname% activation failed due to Internet issue [0xC004F074]."
  9508. if not defined _tserror (
  9509. call :dk_color %Blue% "Make sure that system files are not blocked by firewall."
  9510. call :dk_color %Blue% "If the issue persists, try another Internet connection or VPN such as https://1.1.1.1"
  9511. )
  9512. )
  9513. set showfix=1
  9514. set _tserror=1
  9515. exit /b
  9516. )
  9517. set gpr=0
  9518. set gpr2=0
  9519. call :_taskgetgrace
  9520. set /a "gpr2=(%gpr%+1440-1)/1440"
  9521. if %errorcode% EQU 0 if %gpr% EQU 0 (
  9522. if defined t_name (
  9523. echo %prodname% activation succeeded, but Remaining Period failed to increase.
  9524. ) else (
  9525. call :dk_color %Red% "%prodname% activation succeeded, but Remaining Period failed to increase."
  9526. )
  9527. set _tserror=1
  9528. exit /b
  9529. )
  9530. set _actpass=1
  9531. if %gpr% EQU 43200 if "%1"=="act_win" if %winbuild% GEQ 9200 set _actpass=0
  9532. if %gpr% EQU 64800 set _actpass=0
  9533. if %gpr% GTR 259200 if "%1"=="act_win" call :_taskchkEnterpriseG _actpass
  9534. if %gpr% EQU 259200 set _actpass=0
  9535. if %errorcode% EQU 0 if %_actpass% EQU 0 (
  9536. if defined t_name (
  9537. echo %prodname% is successfully activated for %gpr2% days.
  9538. ) else (
  9539. call :dk_color %Green% "%prodname% is successfully activated for %gpr2% days."
  9540. )
  9541. exit /b
  9542. )
  9543. cmd /c exit /b %errorcode%
  9544. if defined t_name (
  9545. echo %prodname% has failed to activate [0x!=ExitCode!]. Remaining Period: %gpr2% days [%gpr% minutes].
  9546. ) else (
  9547. call :dk_color %Red% "%prodname% has failed to activate [0x!=ExitCode!]. Remaining Period: %gpr2% days [%gpr% minutes]."
  9548. )
  9549. set _tserror=1
  9550. exit /b
  9551. ::========================================================================================================================================
  9552. :_taskact
  9553. :: Check KMS38 activation
  9554. set gpr=0
  9555. set _kms38=0
  9556. if defined sppwid if %winbuild% GEQ 14393 (
  9557. set _path=%slp%
  9558. set _actid=%sppwid%
  9559. call :_taskgetgrace
  9560. )
  9561. if %gpr% NEQ 0 if %gpr% GTR 259200 (
  9562. set _kms38=1
  9563. call :_taskchkEnterpriseG _kms38
  9564. )
  9565. :: 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.
  9566. if %_kms38% EQU 1 (
  9567. %nul% reg add "HKLM\%SPPk%\%_wApp%\%sppwid%" /f /v KeyManagementServiceName /t REG_SZ /d "127.0.0.2"
  9568. %nul% reg add "HKLM\%SPPk%\%_wApp%\%sppwid%" /f /v KeyManagementServicePort /t REG_SZ /d "1688"
  9569. )
  9570. echo:
  9571. if defined sppwid (
  9572. set _path=%slp%
  9573. set _actid=%sppwid%
  9574. call :_act act_win
  9575. call :_actinfo act_win
  9576. ) else (
  9577. if defined t_name echo Checking: Volume version of Windows is not installed
  9578. )
  9579. if defined sppoid (
  9580. set _path=%slp%
  9581. for %%# in (%sppoid%) do (
  9582. set _actid=%%#
  9583. call :_act
  9584. if not defined _taskskip call :_actinfo
  9585. )
  9586. )
  9587. if defined osppid (
  9588. set _path=%ospp%
  9589. for %%# in (%osppid%) do (
  9590. set _actid=%%#
  9591. call :_act
  9592. if not defined _taskskip call :_actinfo
  9593. )
  9594. )
  9595. if not defined sppoid if not defined osppid if defined t_name (
  9596. echo:
  9597. echo Checking: Volume version of Office is not installed
  9598. )
  9599. exit /b
  9600. ::========================================================================================================================================
  9601. :_taskgetids
  9602. set %1=
  9603. if %_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')"
  9604. if %_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')"
  9605. %chkapp% do (if defined %1 (call set "%1=!%1! %%a") else (call set "%1=%%a"))
  9606. exit /b
  9607. :_taskgetgrace
  9608. set gpr=0
  9609. if %_wmic% EQU 1 for /f "tokens=2 delims==" %%# in ('"wmic path !_path! where ID='!_actid!' get GracePeriodRemaining /VALUE" 2^>nul') do call set "gpr=%%#"
  9610. if %_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=%%#"
  9611. exit /b
  9612. :_taskchkEnterpriseG
  9613. for %%# in (e0b2d383-d112-413f-8a80-97f373a5820c e38454fb-41a4-4f59-a5dc-25080e354730) do (if %sppwid%==%%# set %1=0)
  9614. exit /b
  9615. ::========================================================================================================================================
  9616. :: Clean existing K-M-S cache from the registry
  9617. :_taskclear-cache
  9618. set w=
  9619. for %%# in (SppE%w%xtComObj.exe sppsvc.exe) do (
  9620. reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ima%w%ge File Execu%w%tion Options\%%#" /f %nul%
  9621. )
  9622. set "OPPk=SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform"
  9623. set "SPPk=SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform"
  9624. set "slp=SoftwareLicensingProduct"
  9625. set "ospp=OfficeSoftwareProtectionProduct"
  9626. set "_wApp=55c92734-d682-4d71-983e-d6ec3f16059f"
  9627. set "_oApp=0ff1ce15-a989-479d-af46-f275c6370663"
  9628. set "_oA14=59a52881-a989-479d-af46-f275c6370663"
  9629. %nul% reg delete "HKLM\%SPPk%" /f /v KeyManagementServiceName
  9630. %nul% reg delete "HKLM\%SPPk%" /f /v KeyManagementServiceName /reg:32
  9631. %nul% reg delete "HKLM\%SPPk%" /f /v KeyManagementServicePort
  9632. %nul% reg delete "HKLM\%SPPk%" /f /v KeyManagementServicePort /reg:32
  9633. %nul% reg delete "HKLM\%SPPk%" /f /v DisableDnsPublishing
  9634. %nul% reg delete "HKLM\%SPPk%" /f /v DisableKeyManagementServiceHostCaching
  9635. %nul% reg delete "HKLM\%SPPk%\%_wApp%" /f
  9636. if %winbuild% GEQ 9200 (
  9637. %nul% reg delete "HKLM\%SPPk%\%_oApp%" /f
  9638. %nul% reg delete "HKLM\%SPPk%\%_oApp%" /f /reg:32
  9639. )
  9640. if %winbuild% GEQ 9600 (
  9641. %nul% reg delete "HKU\S-1-5-20\%SPPk%\%_wApp%" /f
  9642. %nul% reg delete "HKU\S-1-5-20\%SPPk%\%_oApp%" /f
  9643. )
  9644. %nul% reg delete "HKLM\%OPPk%" /f /v KeyManagementServiceName
  9645. %nul% reg delete "HKLM\%OPPk%" /f /v KeyManagementServicePort
  9646. %nul% reg delete "HKLM\%OPPk%" /f /v DisableDnsPublishing
  9647. %nul% reg delete "HKLM\%OPPk%" /f /v DisableKeyManagementServiceHostCaching
  9648. %nul% reg delete "HKLM\%OPPk%\%_oA14%" /f
  9649. %nul% reg delete "HKLM\%OPPk%\%_oApp%" /f
  9650. exit /b
  9651. ::========================================================================================================================================
  9652. :_taskregserv
  9653. if defined _server (set KMS_IP=%_server%)
  9654. if not defined _port set _port=1688
  9655. %nul% reg add "HKLM\%SPPk%" /f /v KeyManagementServiceName /t REG_SZ /d "%KMS_IP%"
  9656. %nul% reg add "HKLM\%SPPk%" /f /v KeyManagementServiceName /t REG_SZ /d "%KMS_IP%" /reg:32
  9657. %nul% reg add "HKLM\%SPPk%" /f /v KeyManagementServicePort /t REG_SZ /d "%_port%"
  9658. %nul% reg add "HKLM\%SPPk%" /f /v KeyManagementServicePort /t REG_SZ /d "%_port%" /reg:32
  9659. %nul% reg add "HKLM\%OPPk%" /f /v KeyManagementServiceName /t REG_SZ /d "%KMS_IP%"
  9660. %nul% reg add "HKLM\%OPPk%" /f /v KeyManagementServicePort /t REG_SZ /d "%_port%"
  9661. if %winbuild% GEQ 9200 (
  9662. %nul% reg add "HKLM\%SPPk%\%_oApp%" /f /v KeyManagementServiceName /t REG_SZ /d "%KMS_IP%"
  9663. %nul% reg add "HKLM\%SPPk%\%_oApp%" /f /v KeyManagementServiceName /t REG_SZ /d "%KMS_IP%" /reg:32
  9664. %nul% reg add "HKLM\%SPPk%\%_oApp%" /f /v KeyManagementServicePort /t REG_SZ /d "%_port%"
  9665. %nul% reg add "HKLM\%SPPk%\%_oApp%" /f /v KeyManagementServicePort /t REG_SZ /d "%_port%" /reg:32
  9666. )
  9667. exit /b
  9668. ::========================================================================================================================================
  9669. :_tasksetserv
  9670. :: Multi K-M-S servers integration and servers randomization
  9671. set srvlist=
  9672. set -=
  9673. set "srvlist=kms.03%-%k.org kms-default.cangs%-%hui.net kms.six%-%yin.com kms.moe%-%club.org kms.cgt%-%soft.com"
  9674. set "srvlist=%srvlist% kms.id%-%ina.cn kms.moe%-%yuuko.com xinch%-%eng213618.cn kms.lol%-%i.best kms.my%-%ds.cloud"
  9675. set "srvlist=%srvlist% kms.0%-%t.net.cn win.k%-%ms.pub kms.wx%-%lost.com kms.moe%-%yuuko.top kms.gh%-%pym.com"
  9676. set n=1
  9677. for %%a in (%srvlist%) do (set %%a=&set server!n!=%%a&set /a n+=1)
  9678. set max_servers=15
  9679. set /a server_num=0
  9680. exit /b
  9681. :_taskgetserv
  9682. if %server_num% geq %max_servers% (set /a server_num+=1&set KMS_IP=222.184.9.98&exit /b)
  9683. set /a rand=%Random%%%(15+1-1)+1
  9684. if defined !server%rand%! goto :_taskgetserv
  9685. set KMS_IP=!server%rand%!
  9686. set !server%rand%!=1
  9687. :: Get IPv4 address of K-M-S server to use for the activation, works even if ICMP echo is disabled.
  9688. :: Microsoft and Antivirus's may flag the issue if public K-M-S server host name is directly used for the activation.
  9689. set /a server_num+=1
  9690. (for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %KMS_IP% 2^>nul') do set "KMS_IP=%%a"
  9691. if "%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=%%#"
  9692. if not "%KMS_IP%"=="!KMS_IP!" exit /b
  9693. goto :_taskgetserv
  9694. )
  9695. ::Ver:2.7
  9696. :_extracttask:
  9697. ::========================================================================================================================================
  9698. :ks_renewal
  9699. set error_=
  9700. set "_dest=%ProgramFiles%\Activation-Renewal"
  9701. set "key=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\taskcache\tasks"
  9702. call :ks_clearstuff %nul%
  9703. if defined error_ (
  9704. set error=1
  9705. call :dk_color %Red% "Failed to remove previous Renewal Task. Restart system / Try again."
  9706. exit /b
  9707. )
  9708. if not exist "%_dest%\" md "%_dest%\" %nul%
  9709. for /f %%G in ('%psc% "[Guid]::NewGuid().Guid"') do set "randguid=%%G"
  9710. set "_temp=%SystemRoot%\Temp\%Random%%randguid%"
  9711. set nil=
  9712. if exist "%_temp%\.*" rmdir /s /q "%_temp%\" %nul%
  9713. md "%_temp%\" %nul%
  9714. call :ks_RenExport renewal "%_temp%\Renewal.xml" Unicode
  9715. if not defined _int (call :ks_RenExport run_once "%_temp%\Run_Once.xml" Unicode)
  9716. s%nil%cht%nil%asks /cre%nil%ate /tn "Activation-Renewal" /ru "SYS%nil%TEM" /xml "%_temp%\Renewal.xml" %nul%
  9717. if 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%)
  9718. if exist "%_temp%\.*" rmdir /s /q "%_temp%\" %nul%
  9719. call :ks_createInfo.txt
  9720. %psc% "$f=[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)"
  9721. ::========================================================================================================================================
  9722. reg query "%key%" /f Path /s | find /i "\Activation-Renewal" >nul || (set error_=1)
  9723. if not defined _int reg query "%key%" /f Path /s | find /i "\Activation-Run_Once" >nul || (set error_=1)
  9724. If not exist "%_dest%\Activation_task.cmd" (set error_=1)
  9725. If not exist "%_dest%\Info.txt" (set error_=1)
  9726. if defined error_ (
  9727. schtasks /delete /tn Activation-Renewal /f %nul%
  9728. schtasks /delete /tn Activation-Run_Once /f %nul%
  9729. rmdir /s /q "%_dest%\" %nul%
  9730. set error=1
  9731. call :dk_color %Red% "Failed to install Renewal Task. Restart system / Try again."
  9732. exit /b
  9733. )
  9734. if "%keyerror%"=="0" if not defined _tserror (
  9735. call :dk_color %Green% "Renewal Task for lifetime activation is successfully installed in %_dest%"
  9736. exit /b
  9737. )
  9738. echo Renewal Task for lifetime activation is successfully installed in %_dest%
  9739. exit /b
  9740. :: Extract the text from batch script without character and file encoding issue
  9741. :ks_RenExport
  9742. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split \":%~1\:.*`r`n\"; [io.file]::WriteAllText('%~2',$f[1].Trim(),[System.Text.Encoding]::%~3);"
  9743. exit /b
  9744. ::========================================================================================================================================
  9745. :ks_createInfo.txt
  9746. (
  9747. echo The use of this script is to renew your Windows/Office license using online K-M-S.
  9748. echo:
  9749. echo If renewal/activation Scheduled tasks were created then following would exist,
  9750. echo:
  9751. echo - Scheduled tasks
  9752. echo Activation-Renewal [Renewal / Weekly]
  9753. echo Activation-Run_Once [Activation Task - deletes itself once activated]
  9754. echo The scheduled tasks runs only if the system is connected to the Internet.
  9755. echo:
  9756. echo - Files
  9757. echo C:\Program Files\Activation-Renewal\Activation_task.cmd
  9758. echo C:\Program Files\Activation-Renewal\Info.txt
  9759. echo C:\Program Files\Activation-Renewal\Logs.txt
  9760. echo ______________________________________________________________________________________________
  9761. echo:
  9762. echo This Script is a part of MAS project.
  9763. echo:
  9764. echo Homepage: mass grave[.]dev
  9765. echo Email: mas.help@outlook.com
  9766. )>"%_dest%\Info.txt"
  9767. exit /b
  9768. ::========================================================================================================================================
  9769. :renewal:
  9770. <?xml version="1.0" encoding="UTF-16"?>
  9771. <Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  9772. <RegistrationInfo>
  9773. <Source>Microsoft Corporation</Source>
  9774. <Date>1999-01-01T12:00:00.34375</Date>
  9775. <Author>WindowsAddict</Author>
  9776. <Version>1.0</Version>
  9777. <Description>Online K-M-S Activation-Renewal - Weekly Task</Description>
  9778. <URI>\Activation-Renewal</URI>
  9779. <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>
  9780. </RegistrationInfo>
  9781. <Triggers>
  9782. <CalendarTrigger>
  9783. <StartBoundary>1999-01-01T12:00:00</StartBoundary>
  9784. <Enabled>true</Enabled>
  9785. <ScheduleByWeek>
  9786. <DaysOfWeek>
  9787. <Sunday />
  9788. </DaysOfWeek>
  9789. <WeeksInterval>1</WeeksInterval>
  9790. </ScheduleByWeek>
  9791. </CalendarTrigger>
  9792. </Triggers>
  9793. <Principals>
  9794. <Principal id="LocalSystem">
  9795. <UserId>S-1-5-18</UserId>
  9796. <RunLevel>HighestAvailable</RunLevel>
  9797. </Principal>
  9798. </Principals>
  9799. <Settings>
  9800. <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
  9801. <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
  9802. <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
  9803. <AllowHardTerminate>true</AllowHardTerminate>
  9804. <StartWhenAvailable>true</StartWhenAvailable>
  9805. <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>
  9806. <IdleSettings>
  9807. <StopOnIdleEnd>false</StopOnIdleEnd>
  9808. <RestartOnIdle>false</RestartOnIdle>
  9809. </IdleSettings>
  9810. <AllowStartOnDemand>true</AllowStartOnDemand>
  9811. <Enabled>true</Enabled>
  9812. <Hidden>true</Hidden>
  9813. <RunOnlyIfIdle>false</RunOnlyIfIdle>
  9814. <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
  9815. <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
  9816. <WakeToRun>false</WakeToRun>
  9817. <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>
  9818. <Priority>7</Priority>
  9819. <RestartOnFailure>
  9820. <Interval>PT2M</Interval>
  9821. <Count>3</Count>
  9822. </RestartOnFailure>
  9823. </Settings>
  9824. <Actions Context="LocalSystem">
  9825. <Exec>
  9826. <Command>%ProgramFiles%\Activation-Renewal\Activation_task.cmd</Command>
  9827. <Arguments>Task</Arguments>
  9828. </Exec>
  9829. </Actions>
  9830. </Task>
  9831. :renewal:
  9832. :run_once:
  9833. <?xml version="1.0" encoding="UTF-16"?>
  9834. <Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  9835. <RegistrationInfo>
  9836. <Source>Microsoft Corporation</Source>
  9837. <Date>1999-01-01T12:00:00.34375</Date>
  9838. <Author>WindowsAddict</Author>
  9839. <Version>1.0</Version>
  9840. <Description>Online K-M-S Activation Run Once - Run and Delete itself on first Internet Contact</Description>
  9841. <URI>\Activation-Run_Once</URI>
  9842. <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>
  9843. </RegistrationInfo>
  9844. <Triggers>
  9845. <LogonTrigger>
  9846. <Enabled>true</Enabled>
  9847. </LogonTrigger>
  9848. </Triggers>
  9849. <Principals>
  9850. <Principal id="LocalSystem">
  9851. <UserId>S-1-5-18</UserId>
  9852. <RunLevel>HighestAvailable</RunLevel>
  9853. </Principal>
  9854. </Principals>
  9855. <Settings>
  9856. <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
  9857. <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
  9858. <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
  9859. <AllowHardTerminate>true</AllowHardTerminate>
  9860. <StartWhenAvailable>true</StartWhenAvailable>
  9861. <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>
  9862. <IdleSettings>
  9863. <StopOnIdleEnd>false</StopOnIdleEnd>
  9864. <RestartOnIdle>false</RestartOnIdle>
  9865. </IdleSettings>
  9866. <AllowStartOnDemand>true</AllowStartOnDemand>
  9867. <Enabled>true</Enabled>
  9868. <Hidden>true</Hidden>
  9869. <RunOnlyIfIdle>false</RunOnlyIfIdle>
  9870. <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
  9871. <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
  9872. <WakeToRun>false</WakeToRun>
  9873. <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>
  9874. <Priority>7</Priority>
  9875. <RestartOnFailure>
  9876. <Interval>PT2M</Interval>
  9877. <Count>3</Count>
  9878. </RestartOnFailure>
  9879. </Settings>
  9880. <Actions Context="LocalSystem">
  9881. <Exec>
  9882. <Command>%ProgramFiles%\Activation-Renewal\Activation_task.cmd</Command>
  9883. <Arguments>Task</Arguments>
  9884. </Exec>
  9885. </Actions>
  9886. </Task>
  9887. :run_once:
  9888. ::========================================================================================================================================
  9889. :: 1st column = Office version number
  9890. :: 2nd column = Activation ID
  9891. :: 3rd column = Edition
  9892. :: 4th column = Other Edition IDs if they are part of the same primary product (For reference only)
  9893. :: Separator = "_"
  9894. :ks_msiretaildata
  9895. for %%# in (
  9896. :: Office 2010
  9897. 14_4d463c2c-0505-4626-8cdb-a4da82e2d8ed_AccessR
  9898. 14_745fb377-0a59-4ca9-b9a9-c359557a2c4e_AccessRuntimeR
  9899. 14_4eaff0d0-c6cb-4187-94f3-c7656d49a0aa_ExcelR
  9900. 14_7004b7f0-6407-4f45-8eac-966e5f868bde_GrooveR
  9901. 14_7b7d1f17-fdcb-4820-9789-9bec6e377821_HomeBusinessR_[HomeBusinessDemoR]
  9902. 14_19316117-30a8-4773-8fd9-7f7231f4e060_HomeBusinessSubR
  9903. 14_09e2d37e-474b-4121-8626-58ad9be5776f_HomeStudentR_[HomeStudentDemoR]
  9904. 14_c3ae020c-5a71-4cc5-a27a-2a97c2d46860_HSExcelR
  9905. 14_25fe4611-b44d-49cc-ae87-2143d299194e_HSOneNoteR
  9906. 14_d652ad8d-da5c-4358-b928-7fb1b4de7a7c_HSPowerPointR
  9907. 14_a963d7ae-7a88-41a7-94da-8bb5635a8af9_HSWordR
  9908. 14_ef1da464-01c8-43a6-91af-e4e5713744f9_InfoPathR
  9909. 14_14f5946a-debc-4716-babc-7e2c240fec08_MondoR
  9910. 14_c1ceda8b-c578-4d5d-a4aa-23626be4e234_OEM
  9911. 14_3f7aa693-9a7e-44fc-9309-bb3d8e604925_OneNoteR
  9912. 14_fbf4ac36-31c8-4340-8666-79873129cf40_OutlookR
  9913. 14_acb51361-c0db-4895-9497-1831c41f31a6_PersonalR_[PersonalDemoR,PersonalPrepaidR]
  9914. 14_133c8359-4e93-4241-8118-30bb18737ea0_PowerPointR
  9915. 14_8b559c37-0117-413e-921b-b853aeb6e210_ProfessionalR_[ProfessionalAcadR,ProfessionalDemoR]
  9916. 14_725714d7-d58f-4d12-9fa8-35873c6f7215_ProjectProR_[ProjectProMSDNR]
  9917. 14_4d06f72e-fd50-4bc2-a24b-d448d7f17ef2_ProjectProSubR
  9918. 14_688f6589-2bd9-424e-a152-b13f36aa6de1_ProjectStdR
  9919. 14_71af7e84-93e6-4363-9b69-699e04e74071_ProPlusR_[ProPlusAcadR,ProPlusMSDNR,Sub4R]
  9920. 14_e98ef0c0-71c4-42ce-8305-287d8721e26c_ProPlusSubR
  9921. 14_98677603-a668-4fa4-9980-3f1f05f78f69_PublisherR
  9922. 14_dbe3aee0-5183-4ff7-8142-66050173cb01_SmallBusBasicsR_[SmallBusBasicsMSDNR]
  9923. 14_b78df69e-0966-40b1-ae85-30a5134dedd0_SPDR
  9924. 14_d3422cfb-8d8b-4ead-99f9-eab0ccd990d7_StandardR
  9925. 14_2745e581-565a-4670-ae90-6bf7c57ffe43_StarterR
  9926. 14_66cad568-c2dc-459d-93ec-2f3cb967ee34_VisioSIR_Prem[Pro,Std]
  9927. 14_db3bbc9c-ce52-41d1-a46f-1a1d68059119_WordR
  9928. :: Office 2013
  9929. 15_ab4d047b-97cf-4126-a69f-34df08e2f254_AccessRetail
  9930. 15_259de5be-492b-44b3-9d78-9645f848f7b0_AccessRuntimeRetail
  9931. 15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_ExcelRetail
  9932. 15_cfaf5356-49e3-48a8-ab3c-e729ab791250_GrooveRetail
  9933. 15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_HomeBusinessPipcRetail
  9934. 15_a2b90e7a-a797-4713-af90-f0becf52a1dd_HomeBusinessRetail
  9935. 15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_HomeStudentARMRetail
  9936. 15_ebef9f05-5273-404a-9253-c5e252f50555_HomeStudentPlusARMRetail
  9937. 15_f2de350d-3028-410a-bfae-283e00b44d0e_HomeStudentRetail
  9938. 15_44984381-406e-4a35-b1c3-e54f499556e2_InfoPathRetail
  9939. 15_9103f3ce-1084-447a-827e-d6097f68c895_LyncAcademicRetail
  9940. 15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_LyncEntryRetail
  9941. 15_fada6658-bfc6-4c4e-825a-59a89822cda8_LyncRetail
  9942. 15_69ec9152-153b-471a-bf35-77ec88683eae_MondoRetail
  9943. 15_3391e125-f6e4-4b1e-899c-a25e6092d40d_OneNoteFreeRetail
  9944. 15_8b524bcc-67ea-4876-a509-45e46f6347e8_OneNoteRetail
  9945. 15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_OutlookRetail
  9946. 15_5aab8561-1686-43f7-9ff5-2c861da58d17_PersonalPipcRetail
  9947. 15_17e9df2d-ed91-4382-904b-4fed6a12caf0_PersonalRetail
  9948. 15_31743b82-bfbc-44b6-aa12-85d42e644d5b_PowerPointRetail
  9949. 15_064383fa-1538-491c-859b-0ecab169a0ab_ProPlusRetail
  9950. 15_4e26cac1-e15a-4467-9069-cb47b67fe191_ProfessionalPipcRetail
  9951. 15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_ProfessionalRetail
  9952. 15_2f72340c-b555-418d-8b46-355944fe66b8_ProjectProRetail
  9953. 15_58d95b09-6af6-453d-a976-8ef0ae0316b1_ProjectStdRetail
  9954. 15_c3a0814a-70a4-471f-af37-2313a6331111_PublisherRetail
  9955. 15_ba3e3833-6a7e-445a-89d0-7802a9a68588_SPDRetail
  9956. 15_32255c0a-16b4-4ce2-b388-8a4267e219eb_StandardRetail
  9957. 15_a56a3b37-3a35-4bbb-a036-eee5f1898eee_VisioProRetail
  9958. 15_980f9e3e-f5a8-41c8-8596-61404addf677_VisioStdRetail
  9959. 15_191509f2-6977-456f-ab30-cf0492b1e93a_WordRetail
  9960. :: Office 365 - 15.0 version
  9961. 15_6337137e-7c07-4197-8986-bece6a76fc33_O365BusinessRetail
  9962. 15_537ea5b5-7d50-4876-bd38-a53a77caca32_O365HomePremRetail
  9963. 15_149dbce7-a48e-44db-8364-a53386cd4580_O365ProPlusRetail
  9964. 15_bacd4614-5bef-4a5e-bafc-de4c788037a2_O365SmallBusPremRetail
  9965. :: Office 365 - 16.0 version
  9966. 16_6337137e-7c07-4197-8986-bece6a76fc33_O365BusinessRetail
  9967. 16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_O365EduCloudRetail
  9968. 16_537ea5b5-7d50-4876-bd38-a53a77caca32_O365HomePremRetail
  9969. 16_149dbce7-a48e-44db-8364-a53386cd4580_O365ProPlusRetail
  9970. 16_bacd4614-5bef-4a5e-bafc-de4c788037a2_O365SmallBusPremRetail
  9971. :: Office 2016
  9972. 16_bfa358b0-98f1-4125-842e-585fa13032e6_AccessRetail
  9973. 16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_AccessRuntimeRetail
  9974. 16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_ExcelRetail
  9975. 16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_HomeBusinessPipcRetail
  9976. 16_86834d00-7896-4a38-8fae-32f20b86fa2b_HomeBusinessRetail
  9977. 16_c28acdb8-d8b3-4199-baa4-024d09e97c99_HomeStudentRetail
  9978. 16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_HomeStudentARMRetail
  9979. 16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_HomeStudentPlusARMRetail
  9980. 16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_HomeStudentVNextRetail
  9981. 16_69ec9152-153b-471a-bf35-77ec88683eae_MondoRetail
  9982. 16_436366de-5579-4f24-96db-3893e4400030_OneNoteFreeRetail
  9983. 16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_OneNoteRetail
  9984. 16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_OutlookRetail
  9985. 16_5aab8561-1686-43f7-9ff5-2c861da58d17_PersonalPipcRetail
  9986. 16_a9f645a1-0d6a-4978-926a-abcb363b72a6_PersonalRetail
  9987. 16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_PowerPointRetail
  9988. 16_de52bd50-9564-4adc-8fcb-a345c17f84f9_ProPlusRetail
  9989. 16_4e26cac1-e15a-4467-9069-cb47b67fe191_ProfessionalPipcRetail
  9990. 16_d64edc00-7453-4301-8428-197343fafb16_ProfessionalRetail
  9991. 16_2f72340c-b555-418d-8b46-355944fe66b8_ProjectProRetail
  9992. 16_58d95b09-6af6-453d-a976-8ef0ae0316b1_ProjectStdRetail
  9993. 16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_PublisherRetail
  9994. 16_9103f3ce-1084-447a-827e-d6097f68c895_SkypeServiceBypassRetail
  9995. 16_971cd368-f2e1-49c1-aedd-330909ce18b6_SkypeforBusinessEntryRetail
  9996. 16_418d2b9f-b491-4d7f-84f1-49e27cc66597_SkypeforBusinessRetail
  9997. 16_4a31c291-3a12-4c64-b8ab-cd79212be45e_StandardRetail
  9998. 16_a56a3b37-3a35-4bbb-a036-eee5f1898eee_VisioProRetail
  9999. 16_980f9e3e-f5a8-41c8-8596-61404addf677_VisioStdRetail
  10000. 16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_WordRetail
  10001. ) do (
  10002. for /f "tokens=1-5 delims=_" %%A in ("%%#") do (
  10003. if %1==getmsiret if "%oVer%"=="%%A" (
  10004. for /f "tokens=*" %%x in ('findstr /i /c:"%%B" "%_oBranding%"') do set "prodId=%%x"
  10005. set prodId=!prodId:"/>=!
  10006. set prodId=!prodId:~-4!
  10007. if "%oVer%"=="14" (
  10008. REM Exception case for Visio because wrong primary product ID is mentioned in Branding.xml
  10009. echo %%C | find /i "Visio" %nul% && set prodId=0057
  10010. )
  10011. reg query "%2\Registration\{%%B}" /v ProductCode %nul2% | find /i "-!prodId!-" %nul% && (
  10012. reg query "%2\Common\InstalledPackages" %nul2% | find /i "-!prodId!-" %nul% && (
  10013. if defined _oIds (set _oIds=!_oIds! %%C) else (set _oIds=%%C)
  10014. )
  10015. )
  10016. )
  10017. )
  10018. )
  10019. exit /b
  10020. ::========================================================================================================================================
  10021. :: 1st column = Activation ID
  10022. :: 2nd column = GVLK / Free Office products keys
  10023. :: 3rd column = In case of Windows, its SKU ID. In case of Office, its Office version
  10024. :: 4th column = Edition ID
  10025. :: 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)
  10026. :: 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
  10027. :: 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
  10028. :: Separator = "_"
  10029. :ksdata
  10030. set f=
  10031. for %%# in (
  10032. :: Windows 10/11
  10033. 73111121-5638-40f6-bc11-f1d7b0d64300_NPPR9-FWDCX-D2C8J-H872K-2Y%f%T43___4_Enterprise
  10034. e272e3e2-732f-4c65-a8f0-484747d0d947_DPH2V-TTNVB-4X9Q3-TJR4H-KH%f%JW4__27_EnterpriseN
  10035. 2de67392-b7a7-462a-b1ca-108dd189f588_W269N-WFGWX-YVC9B-4J6C9-T8%f%3GX__48_Professional
  10036. a80b5abf-76ad-428b-b05d-a47d2dffeebf_MH37W-N47XK-V7XM9-C7227-GC%f%QG9__49_ProfessionalN
  10037. 7b9e1751-a8da-4f75-9560-5fadfe3d8e38_3KHY7-WNT83-DGQKR-F7HPR-84%f%4BM__98_CoreN
  10038. a9107544-f4a0-4053-a96a-1479abdef912_PVMJN-6DFY6-9CCP6-7BKTT-D3%f%WVR__99_CoreCountrySpecific
  10039. cd918a57-a41b-4c82-8dce-1a538e221a83_7HNRX-D7KGG-3K4RQ-4WPJ4-YT%f%DFH_100_CoreSingleLanguage
  10040. 58e97c99-f377-4ef1-81d5-4ad5522b5fd8_TX9XD-98N7V-6WMQ6-BX7FG-H8%f%Q99_101_Core
  10041. e0c42288-980c-4788-a014-c080d2e1926e_NW6C2-QMPVW-D7KKK-3GKT6-VC%f%FB2_121_Education
  10042. 3c102355-d027-42c6-ad23-2e7ef8a02585_2WH4N-8QGBV-H22JP-CT43Q-MD%f%WWJ_122_EducationN
  10043. 32d2fab3-e4a8-42c2-923b-4bf4fd13e6ee_M7XTQ-FN8P6-TTKYV-9D4CC-J4%f%62D_125_EnterpriseS_RS5,VB,Ge
  10044. 2d5a5a60-3040-48bf-beb0-fcd770c20ce0_DCPHK-NFMTC-H88MJ-PFHPY-QJ%f%4BJ_125_EnterpriseS_RS1
  10045. 7b51a46c-0c04-4e8f-9af4-8496cca90d5e_WNMTR-4C88C-JK8YV-HQ7T2-76%f%DF9_125_EnterpriseS_TH1
  10046. 7103a333-b8c8-49cc-93ce-d37c09687f92_92NFX-8DJQP-P6BBQ-THF9C-7C%f%G2H_126_EnterpriseSN_RS5,VB,Ge
  10047. 9f776d83-7156-45b2-8a5c-359b9c9f22a3_QFFDN-GRT3P-VKWWX-X7T3R-8B%f%639_126_EnterpriseSN_RS1
  10048. 87b838b7-41b6-4590-8318-5797951d8529_2F77B-TNFGY-69QQF-B8YKP-D6%f%9TJ_126_EnterpriseSN_TH1
  10049. 82bbc092-bc50-4e16-8e18-b74fc486aec3_NRG8B-VKK3Q-CXVCJ-9G2XF-6Q%f%84J_161_ProfessionalWorkstation
  10050. 4b1571d3-bafb-4b40-8087-a961be2caf65_9FNHH-K3HBT-3W4TD-6383H-6X%f%YWF_162_ProfessionalWorkstationN
  10051. 3f1afc82-f8ac-4f6c-8005-1d233e606eee_6TP4R-GNPTD-KYYHQ-7B7DP-J4%f%47Y_164_ProfessionalEducation
  10052. 5300b18c-2e33-4dc2-8291-47ffcec746dd_YVWGF-BXNMC-HTQYQ-CPQ99-66%f%QFC_165_ProfessionalEducationN
  10053. e0b2d383-d112-413f-8a80-97f373a5820c_YYVX9-NTFWV-6MDM3-9PT4T-4M%f%68B_171_EnterpriseG
  10054. e38454fb-41a4-4f59-a5dc-25080e354730_44RPN-FTY23-9VTTB-MP9BX-T8%f%4FV_172_EnterpriseGN
  10055. ec868e65-fadf-4759-b23e-93fe37f2cc29_CPWHC-NT2C7-VYW78-DHDB2-PG%f%3GK_175_ServerRdsh_RS5
  10056. e4db50ea-bda1-4566-b047-0ca50abc6f07_7NBT4-WGBQX-MP4H7-QXFF8-YP%f%3KX_175_ServerRdsh_RS3
  10057. 0df4f814-3f57-4b8b-9a9d-fddadcd69fac_NBTWJ-3DR69-3C4V8-C26MC-GQ%f%9M6_183_CloudE
  10058. 59eb965c-9150-42b7-a0ec-22151b9897c5_KBN8V-HFGQ4-MGXVD-347P6-PD%f%QGT_191_IoTEnterpriseS_VB,NI
  10059. d30136fc-cb4b-416e-a23d-87207abc44a9_6XN7V-PCBDC-BDBRH-8DQY7-G6%f%R44_202_CloudEditionN
  10060. ca7df2e3-5ea0-47b8-9ac1-b1be4d8edd69_37D7F-N49CB-WQR8W-TBJ73-FM%f%8RX_203_CloudEdition
  10061. :: Windows 2016/19/22/25 LTSC/SAC
  10062. 7dc26449-db21-4e09-ba37-28f2958506a6_TVRH6-WHNXV-R9WG3-9XRFY-MY%f%832___7_ServerStandard_Ge
  10063. 9bd77860-9b31-4b7b-96ad-2564017315bf_VDYBN-27WPP-V4HQT-9VMD4-VM%f%K7H___7_ServerStandard_FE
  10064. de32eafd-aaee-4662-9444-c1befb41bde2_N69G4-B89J2-4G8F4-WWYCC-J4%f%64C___7_ServerStandard_RS5
  10065. 8c1c5410-9f39-4805-8c9d-63a07706358f_WC2BQ-8NRM3-FDDYY-2BFGV-KH%f%KQY___7_ServerStandard_RS1
  10066. c052f164-cdf6-409a-a0cb-853ba0f0f55a_D764K-2NDRG-47T6Q-P8T8W-YP%f%6DF___8_ServerDatacenter_Ge
  10067. ef6cfc9f-8c5d-44ac-9aad-de6a2ea0ae03_WX4NM-KYWYW-QJJR4-XV3QB-6V%f%M33___8_ServerDatacenter_FE
  10068. 34e1ae55-27f8-4950-8877-7a03be5fb181_WMDGN-G9PQG-XVVXX-R3X43-63%f%DFG___8_ServerDatacenter_RS5
  10069. 21c56779-b449-4d20-adfc-eece0e1ad74b_CB7KF-BWN84-R7R2Y-793K2-8X%f%DDG___8_ServerDatacenter_RS1
  10070. 034d3cbb-5d4b-4245-b3f8-f84571314078_WVDHN-86M7X-466P6-VHXV7-YY%f%726__50_ServerSolution_RS5
  10071. 2b5a1b0f-a5ab-4c54-ac2f-a6d94824a283_JCKRF-N37P4-C2D82-9YXRT-4M%f%63B__50_ServerSolution_RS1
  10072. 7b4433f4-b1e7-4788-895a-c45378d38253_QN4C6-GBJD2-FB422-GHWJK-GJ%f%G2R_110_ServerCloudStorage
  10073. 8de8eb62-bbe0-40ac-ac17-f75595071ea3_GRFBW-QNDC4-6QBHG-CCK3B-2P%f%R88_120_ServerARM64_RS5
  10074. 43d9af6e-5e86-4be8-a797-d072a046896c_K9FYF-G6NCK-73M32-XMVPY-F9%f%DRR_120_ServerARM64_RS4
  10075. 39e69c41-42b4-4a0a-abad-8e3c10a797cc_QFND9-D3Y9C-J3KKY-6RPVP-2D%f%PYV_145_ServerDatacenterACor_FE
  10076. 90c362e5-0da1-4bfd-b53b-b87d309ade43_6NMRW-2C8FM-D24W7-TQWMY-CW%f%H2D_145_ServerDatacenterACor_RS5
  10077. e49c08e7-da82-42f8-bde2-b570fbcae76c_2HXDN-KRXHB-GPYC7-YCKFJ-7F%f%VDG_145_ServerDatacenterACor_RS3
  10078. f5e9429c-f50b-4b98-b15c-ef92eb5cff39_67KN8-4FYJW-2487Q-MQ2J7-4C%f%4RG_146_ServerStandardACor_FE
  10079. 73e3957c-fc0c-400d-9184-5f7b6f2eb409_N2KJX-J94YW-TQVFB-DG9YT-72%f%4CC_146_ServerStandardACor_RS5
  10080. 61c5ef22-f14f-4553-a824-c4b31e84b100_PTXN8-JFHJM-4WC78-MPCBR-9W%f%4KR_146_ServerStandardACor_RS3
  10081. 45b5aff2-60a0-42f2-bc4b-ec6e5f7b527e_FCNV3-279Q9-BQB46-FTKXX-9H%f%PRH_168_ServerAzureCor_Ge
  10082. 8c8f0ad3-9a43-4e05-b840-93b8d1475cbc_6N379-GGTMK-23C6M-XVVTC-CK%f%FRQ_168_ServerAzureCor_FE
  10083. a99cc1f0-7719-4306-9645-294102fbff95_FDNH6-VW9RW-BXPJ7-4XTYG-23%f%9TB_168_ServerAzureCor_RS5
  10084. 3dbf341b-5f6c-4fa7-b936-699dce9e263f_VP34G-4NPPG-79JTQ-864T4-R3%f%MQX_168_ServerAzureCor_RS1
  10085. c2e946d1-cfa2-4523-8c87-30bc696ee584_XGN3F-F394H-FD2MY-PP6FD-8M%f%CRC_407_ServerTurbine_Ge
  10086. 19b5e0fb-4431-46bc-bac1-2f1873e4ae73_NTBV8-9K7Q8-V27C6-M2BTV-KH%f%MXV_407_ServerTurbine_RS5
  10087. :: Windows 8.1
  10088. 81671aaf-79d1-4eb1-b004-8cbbe173afea_MHF9N-XY6XB-WVXMC-BTDCT-MK%f%KG7___4_Enterprise
  10089. 113e705c-fa49-48a4-beea-7dd879b46b14_TT4HM-HN7YT-62K67-RGRQJ-JF%f%FXW__27_EnterpriseN
  10090. c06b6981-d7fd-4a35-b7b4-054742b7af67_GCRJD-8NW9H-F2CDX-CCM8D-9D%f%6T9__48_Professional
  10091. 7476d79f-8e48-49b4-ab63-4d0b813a16e4_HMCNV-VVBFX-7HMBH-CTY9B-B4%f%FXY__49_ProfessionalN
  10092. f7e88590-dfc7-4c78-bccb-6f3865b99d1a_VHXM3-NR6FT-RY6RT-CK882-KW%f%2CJ__86_EmbeddedIndustryA
  10093. 0ab82d54-47f4-4acb-818c-cc5bf0ecb649_NMMPB-38DD4-R2823-62W8D-VX%f%KJB__89_EmbeddedIndustry
  10094. cd4e2d9f-5059-4a50-a92d-05d5bb1267c7_FNFKF-PWTVT-9RC8H-32HB2-JB%f%34X__91_EmbeddedIndustryE
  10095. ffee456a-cd87-4390-8e07-16146c672fd0_XYTND-K6QKT-K2MRH-66RTM-43%f%JKP__97_CoreARM
  10096. 78558a64-dc19-43fe-a0d0-8075b2a370a3_7B9N3-D94CG-YTVHR-QBPX3-RJ%f%P64__98_CoreN
  10097. db78b74f-ef1c-4892-abfe-1e66b8231df6_NCTT7-2RGK8-WMHRF-RY7YQ-JT%f%XG3__99_CoreCountrySpecific
  10098. c72c6a1d-f252-4e7e-bdd1-3fca342acb35_BB6NG-PQ82V-VRDPW-8XVD2-V8%f%P66_100_CoreSingleLanguage
  10099. fe1c3238-432a-43a1-8e25-97e7d1ef10f3_M9Q9P-WNJJT-6PXPY-DWX8H-6X%f%WKK_101_Core
  10100. 096ce63d-4fac-48a9-82a9-61ae9e800e5f_789NJ-TQK6T-6XTH8-J39CJ-J8%f%D3P_103_ProfessionalWMC
  10101. e9942b32-2e55-4197-b0bd-5ff58cba8860_3PY8R-QHNP9-W7XQD-G6DPH-3J%f%2C9_111_CoreConnected
  10102. c6ddecd6-2354-4c19-909b-306a3058484e_Q6HTR-N24GM-PMJFP-69CD8-2G%f%XKR_113_CoreConnectedN
  10103. b8f5e3a3-ed33-4608-81e1-37d6c9dcfd9c_KF37N-VDV38-GRRTV-XH8X6-6F%f%3BB_115_CoreConnectedSingleLanguage
  10104. ba998212-460a-44db-bfb5-71bf09d1c68b_R962J-37N87-9VVK2-WJ74P-XT%f%MHR_116_CoreConnectedCountrySpecific
  10105. e58d87b5-8126-4580-80fb-861b22f79296_MX3RK-9HNGX-K3QKC-6PJ3F-W8%f%D7B_112_ProfessionalStudent
  10106. cab491c7-a918-4f60-b502-dab75e334f40_TNFGH-2R6PB-8XM3K-QYHX2-J4%f%296_114_ProfessionalStudentN
  10107. :: Windows Server 2012 R2
  10108. b3ca044e-a358-4d68-9883-aaa2941aca99_D2N9P-3P6X9-2R39C-7RTCD-MD%f%VJX___7_ServerStandard
  10109. 00091344-1ea4-4f37-b789-01750ba6988c_W3GGN-FT8W3-Y4M27-J84CP-Q3%f%VJ9___8_ServerDatacenter
  10110. 21db6ba4-9a7b-4a14-9e29-64a60c59301d_KNC87-3J2TX-XB4WP-VCPJV-M4%f%FWM__50_ServerSolution
  10111. b743a2be-68d4-4dd3-af32-92425b7bb623_3NPTF-33KPT-GGBPR-YX76B-39%f%KDD_110_ServerCloudStorage
  10112. :: Windows 8
  10113. 458e1bec-837a-45f6-b9d5-925ed5d299de_32JNW-9KQ84-P47T8-D8GGY-CW%f%CK7___4_Enterprise
  10114. e14997e7-800a-4cf7-ad10-de4b45b578db_JMNMF-RHW7P-DMY6X-RF3DR-X2%f%BQT__27_EnterpriseN
  10115. a98bcd6d-5343-4603-8afe-5908e4611112_NG4HW-VH26C-733KW-K6F98-J8%f%CK4__48_Professional
  10116. ebf245c1-29a8-4daf-9cb1-38dfc608a8c8_XCVCF-2NXM9-723PB-MHCB7-2R%f%YQQ__49_ProfessionalN
  10117. 10018baf-ce21-4060-80bd-47fe74ed4dab_RYXVT-BNQG7-VD29F-DBMRY-HT%f%73M__89_EmbeddedIndustry
  10118. 18db1848-12e0-4167-b9d7-da7fcda507db_NKB3R-R2F8T-3XCDP-7Q2KW-XW%f%YQ2__91_EmbeddedIndustryE
  10119. af35d7b7-5035-4b63-8972-f0b747b9f4dc_DXHJF-N9KQX-MFPVR-GHGQK-Y7%f%RKV__97_CoreARM
  10120. 197390a0-65f6-4a95-bdc4-55d58a3b0253_8N2M2-HWPGY-7PGT9-HGDD8-GV%f%GGY__98_CoreN
  10121. 9d5584a2-2d85-419a-982c-a00888bb9ddf_4K36P-JN4VD-GDC6V-KDT89-DY%f%FKP__99_CoreCountrySpecific
  10122. 8860fcd4-a77b-4a20-9045-a150ff11d609_2WN2H-YGCQR-KFX6K-CD6TF-84%f%YXQ_100_CoreSingleLanguage
  10123. c04ed6bf-55c8-4b47-9f8e-5a1f31ceee60_BN3D2-R7TKB-3YPBD-8DRP2-27%f%GG4_101_Core
  10124. a00018a3-f20f-4632-bf7c-8daa5351c914_GNBB8-YVD74-QJHX6-27H4K-8Q%f%HDG_103_ProfessionalWMC
  10125. :: Windows Server 2012
  10126. f0f5ec41-0d55-4732-af02-440a44a3cf0f_XC9B7-NBPP2-83J2H-RHMBY-92%f%BT4___7_ServerStandard
  10127. d3643d60-0c42-412d-a7d6-52e6635327f6_48HP8-DN98B-MYWDG-T2DCC-8W%f%83P___8_ServerDatacenter
  10128. 8f365ba6-c1b9-4223-98fc-282a0756a3ed_HTDQM-NBMMG-KGYDT-2DTKT-J2%f%MPV__50_ServerSolution
  10129. 7d5486c7-e120-4771-b7f1-7b56c6d3170c_HM7DN-YVMH3-46JC3-XYTG7-CY%f%QJJ__76_ServerMultiPointStandard
  10130. 95fd1c83-7df5-494a-be8b-1300e1c9d1cd_XNH6W-2V9GX-RGJ4K-Y8X6F-QG%f%J2G__77_ServerMultiPointPremium
  10131. :: Windows 7
  10132. ae2ee509-1b34-41c0-acb7-6d4650168915_33PXH-7Y6KF-2VJC9-XBBR8-HV%f%THH___4_Enterprise
  10133. 1cb6d605-11b3-4e14-bb30-da91c8e3983a_YDRBP-3D83W-TY26F-D46B2-XC%f%KRJ__27_EnterpriseN
  10134. b92e9980-b9d5-4821-9c94-140f632f6312_FJ82H-XT6CR-J8D7P-XQJJ2-GP%f%DD4__48_Professional
  10135. 54a09a0d-d57b-4c10-8b69-a842d6590ad5_MRPKT-YTG23-K7D7T-X2JMM-QY%f%7MG__49_ProfessionalN
  10136. db537896-376f-48ae-a492-53d0547773d0_YBYF6-BHCR3-JPKRB-CDW7B-F9%f%BK4__65_Embedded_POSReady
  10137. aa6dd3aa-c2b4-40e2-a544-a6bbb3f5c395_73KQT-CD9G6-K7TQG-66MRP-CQ%f%22C__65_Embedded_ThinPC
  10138. 5a041529-fef8-4d07-b06f-b59b573b32d2_W82YF-2Q76Y-63HXB-FGJG9-GF%f%7QX__69_ProfessionalE
  10139. 46bbed08-9c7b-48fc-a614-95250573f4ea_C29WB-22CC8-VJ326-GHFJW-H9%f%DH4__70_EnterpriseE
  10140. :: Windows Server 2008 R2
  10141. 68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC___7_ServerStandard
  10142. 7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648___8_ServerDatacenter
  10143. 620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y__10_ServerEnterprise
  10144. 7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648__12_ServerDatacenterCore
  10145. 68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC__13_ServerStandardCore
  10146. 620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y__14_ServerEnterpriseCore
  10147. 8a26851c-1c7e-48d3-a687-fbca9b9ac16b_GT63C-RJFQ3-4GMB6-BRFB9-CB%f%83V__15_ServerEnterpriseIA64
  10148. a78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4__17_ServerWeb
  10149. cda18cf3-c196-46ad-b289-60c072869994_TT8MH-CG224-D3D7Q-498W2-9Q%f%CTX__18_ServerHPC
  10150. a78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4__29_ServerWebCore
  10151. f772515c-0e87-48d5-a676-e6962c3e1195_736RG-XDKJK-V34PF-BHK87-J6%f%X3K__56_ServerEmbeddedSolution
  10152. ::========================================================================================================================================
  10153. :: Office 2010
  10154. 8ce7e872-188c-4b98-9d90-f8f90b7aad02_V7Y44-9T38C-R2VJK-666HK-T7%f%DDX__14_AccessVL
  10155. cee5d470-6e3b-4fcc-8c2b-d17428568a9f_H62QG-HXVKF-PP4HP-66KMR-CW%f%9BM__14_ExcelVL
  10156. 8947d0b8-c33b-43e1-8c56-9b674c052832_QYYW6-QP4CB-MBV6G-HYMCJ-4T%f%3J4__14_GrooveVL
  10157. ca6b6639-4ad6-40ae-a575-14dee07f6430_K96W8-67RPQ-62T9Y-J8FQJ-BT%f%37T__14_InfoPathVL
  10158. 09ed9640-f020-400a-acd8-d7d867dfd9c2_YBJTT-JG6MD-V9Q7P-DBKXJ-38%f%W9R__14_MondoVL
  10159. ab586f5c-5256-4632-962f-fefd8b49e6f4_Q4Y4M-RHWJM-PY37F-MTKWH-D3%f%XHX__14_OneNoteVL
  10160. ecb7c192-73ab-4ded-acf4-2399b095d0cc_7YDC2-CWM8M-RRTJC-8MDVC-X3%f%DWQ__14_OutlookVL
  10161. 45593b1d-dfb1-4e91-bbfb-2d5d0ce2227a_RC8FX-88JRY-3PF7C-X8P67-P4%f%VTT__14_PowerPointVL
  10162. df133ff7-bf14-4f95-afe3-7b48e7e331ef_YGX6F-PGV49-PGW3J-9BTGG-VH%f%KC6__14_ProjectProVL
  10163. 5dc7bf61-5ec9-4996-9ccb-df806a2d0efe_4HP3K-88W3F-W2K3D-6677X-F9%f%PGB__14_ProjectStdVL
  10164. 6f327760-8c5c-417c-9b61-836a98287e0c_VYBBJ-TRJPB-QFQRF-QFT4D-H3%f%GVB__14_ProPlusVL
  10165. b50c4f75-599b-43e8-8dcd-1081a7967241_BFK7F-9MYHM-V68C7-DRQ66-83%f%YTP__14_PublisherVL
  10166. ea509e87-07a1-4a45-9edc-eba5a39f36af_D6QFG-VBYP2-XQHM7-J97RH-VV%f%RCK__14_SmallBusBasicsVL
  10167. 9da2a678-fb6b-4e67-ab84-60dd6a9c819a_V7QKV-4XVVR-XYV4D-F7DFM-8R%f%6BM__14_StandardVL
  10168. 92236105-bb67-494f-94c7-7f7a607929bd_D9DWC-HPYVV-JGF4P-BTWQB-WX%f%8BJ__14_VisioSIVL
  10169. 2d0882e7-a4e7-423b-8ccc-70d91e0158b1_HVHB3-C6FV7-KQX9W-YQG79-CR%f%Y7T__14_WordVL
  10170. :: Office 2013
  10171. 6ee7622c-18d8-4005-9fb7-92db644a279b_NG2JY-H4JBT-HQXYP-78QH9-4J%f%M2D__15_AccessVolume_-AccessRetail-
  10172. 259de5be-492b-44b3-9d78-9645f848f7b0_X3XNB-HJB7K-66THH-8DWQ3-XH%f%GJP__15_AccessRuntimeRetail_[Bypass]
  10173. f7461d52-7c2b-43b2-8744-ea958e0bd09a_VGPNG-Y7HQW-9RHP7-TKPV3-BG%f%7GB__15_ExcelVolume_-ExcelRetail-
  10174. fb4875ec-0c6b-450f-b82b-ab57d8d1677f_H7R7V-WPNXQ-WCYYC-76BGV-VT%f%7GH__15_GrooveVolume_-GrooveRetail-
  10175. a30b8040-d68a-423f-b0b5-9ce292ea5a8f_DKT8B-N7VXH-D963P-Q4PHY-F8%f%894__15_InfoPathVolume_-InfoPathRetail-
  10176. 9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY__15_LyncAcademicRetail_[PrepidBypass]
  10177. ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_N42BF-CBY9F-W2C7R-X397X-DY%f%FQW__15_LyncEntryRetail_[PrepidBypass]
  10178. 1b9f11e3-c85c-4e1b-bb29-879ad2c909e3_2MG3G-3BNTT-3MFW9-KDQW3-TC%f%K7R__15_LyncVolume_-LyncRetail-
  10179. 1dc00701-03af-4680-b2af-007ffc758a1f_CWH2Y-NPYJW-3C7HD-BJQWB-G2%f%8JJ__15_MondoRetail
  10180. dc981c6b-fc8e-420f-aa43-f8f33e5c0923_42QTK-RN8M7-J3C4G-BBGYM-88%f%CYV__15_MondoVolume_-O365BusinessRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-
  10181. 3391e125-f6e4-4b1e-899c-a25e6092d40d_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%FF4__15_OneNoteFreeRetail_[Bypass]
  10182. efe1f3e6-aea2-4144-a208-32aa872b6545_TGN6P-8MMBC-37P2F-XHXXK-P3%f%4VW__15_OneNoteVolume_-OneNoteRetail-
  10183. 771c3afa-50c5-443f-b151-ff2546d863a0_QPN8Q-BJBTJ-334K3-93TGY-2P%f%MBT__15_OutlookVolume_-OutlookRetail-
  10184. 8c762649-97d1-4953-ad27-b7e2c25b972e_4NT99-8RJFH-Q2VDH-KYG2C-4R%f%D4F__15_PowerPointVolume_-PowerPointRetail-
  10185. 4a5d124a-e620-44ba-b6ff-658961b33b9a_FN8TT-7WMH6-2D4X9-M337T-23%f%42K__15_ProjectProVolume_-ProjectProRetail-
  10186. 427a28d1-d17c-4abf-b717-32c780ba6f07_6NTH3-CW976-3G3Y2-JK3TX-8Q%f%HTT__15_ProjectStdVolume_-ProjectStdRetail-
  10187. b322da9c-a2e2-4058-9e4e-f59a6970bd69_YC7DK-G2NP3-2QQC3-J6H88-GV%f%GXT__15_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-
  10188. 00c79ff1-6850-443d-bf61-71cde0de305f_PN2WF-29XG2-T9HJ7-JQPJR-FC%f%XK4__15_PublisherVolume_-PublisherRetail-
  10189. ba3e3833-6a7e-445a-89d0-7802a9a68588_3NY6J-WHT3F-47BDV-JHF36-23%f%43W__15_SPDRetail_[PrepidBypass]
  10190. b13afb38-cd79-4ae5-9f7f-eed058d750ca_KBKQT-2NMXY-JJWGP-M62JB-92%f%CD4__15_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-PersonalPipcRetail-PersonalRetail-
  10191. e13ac10e-75d0-4aff-a0cd-764982cf541c_C2FG9-N6J68-H8BTJ-BW3QX-RM%f%3B3__15_VisioProVolume_-VisioProRetail-
  10192. ac4efaf0-f81f-4f61-bdf7-ea32b02ab117_J484Y-4NKBF-W2HMG-DBMJC-PG%f%WR7__15_VisioStdVolume_-VisioStdRetail-
  10193. d9f5b1c6-5386-495a-88f9-9ad6b41ac9b3_6Q7VD-NX8JD-WJ2VH-88V73-4G%f%BJ7__15_WordVolume_-WordRetail-
  10194. :: Office 2016
  10195. 9d9faf9e-d345-4b49-afce-68cb0a539c7c_RNB7V-P48F4-3FYY6-2P3R3-63%f%BQV__16_AccessRuntimeRetail_[PrepidBypass]
  10196. 67c0fc0c-deba-401b-bf8b-9c8ad8395804_GNH9Y-D2J4T-FJHGG-QRVH7-QP%f%FDW__16_AccessVolume_-AccessRetail-
  10197. c3e65d36-141f-4d2f-a303-a842ee756a29_9C2PK-NWTVB-JMPW8-BFT28-7F%f%TBF__16_ExcelVolume_-ExcelRetail-
  10198. e914ea6e-a5fa-4439-a394-a9bb3293ca09_DMTCJ-KNRKX-26982-JYCKT-P7%f%KB6__16_MondoRetail
  10199. 9caabccb-61b1-4b4b-8bec-d10a3c3ac2ce_HFTND-W9MK4-8B7MJ-B6C4G-XQ%f%BR2__16_MondoVolume_-O365BusinessRetail-O365EduCloudRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-
  10200. 436366de-5579-4f24-96db-3893e4400030_XYNTG-R96FY-369HX-YFPHY-F9%f%CPM__16_OneNoteFreeRetail_[Bypass]
  10201. d8cace59-33d2-4ac7-9b1b-9b72339c51c8_DR92N-9HTF2-97XKM-XW2WJ-XW%f%3J6__16_OneNoteVolume_-OneNoteRetail-OneNote2021Retail-
  10202. ec9d9265-9d1e-4ed0-838a-cdc20f2551a1_R69KK-NTPKF-7M3Q4-QYBHW-6M%f%T9B__16_OutlookVolume_-OutlookRetail-
  10203. d70b1bba-b893-4544-96e2-b7a318091c33_J7MQP-HNJ4Y-WJ7YM-PFYGF-BY%f%6C6__16_PowerPointVolume_-PowerPointRetail-
  10204. 4f414197-0fc2-4c01-b68a-86cbb9ac254c_YG9NW-3K39V-2T3HJ-93F3Q-G8%f%3KT__16_ProjectProVolume_-ProjectProRetail-
  10205. 829b8110-0e6f-4349-bca4-42803577788d_WGT24-HCNMF-FQ7XH-6M8K7-DR%f%TW9__16_ProjectProXVolume
  10206. da7ddabc-3fbe-4447-9e01-6ab7440b4cd4_GNFHQ-F6YQM-KQDGJ-327XX-KQ%f%BVC__16_ProjectStdVolume_-ProjectStdRetail-
  10207. cbbaca45-556a-4416-ad03-bda598eaa7c8_D8NRQ-JTYM3-7J2DX-646CT-68%f%36M__16_ProjectStdXVolume
  10208. d450596f-894d-49e0-966a-fd39ed4c4c64_XQNVK-8JYDB-WJ9W3-YJ8YR-WF%f%G99__16_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-
  10209. 041a06cb-c5b8-4772-809f-416d03d16654_F47MM-N3XJP-TQXJ9-BP99D-8K%f%837__16_PublisherVolume_-PublisherRetail-
  10210. 9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY__16_SkypeServiceBypassRetail_[PrepidBypass]
  10211. 971cd368-f2e1-49c1-aedd-330909ce18b6_4N4D8-3J7Y3-YYW7C-73HD2-V8%f%RHY__16_SkypeforBusinessEntryRetail_[PrepidBypass]
  10212. 83e04ee1-fa8d-436d-8994-d31a862cab77_869NQ-FJ69K-466HW-QYCP2-DD%f%BV6__16_SkypeforBusinessVolume_-SkypeforBusinessRetail-
  10213. dedfa23d-6ed1-45a6-85dc-63cae0546de6_JNRGM-WHDWX-FJJG3-K47QV-DR%f%TFM__16_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-HomeStudentVNextRetail-PersonalPipcRetail-PersonalRetail-
  10214. 6bf301c1-b94a-43e9-ba31-d494598c47fb_PD3PC-RHNGV-FXJ29-8JK7D-RJ%f%RJK__16_VisioProVolume_-VisioProRetail-
  10215. b234abe3-0857-4f9c-b05a-4dc314f85557_69WXN-MBYV6-22PQG-3WGHK-RM%f%6XC__16_VisioProXVolume
  10216. aa2a7821-1827-4c2c-8f1d-4513a34dda97_7WHWN-4T7MP-G96JF-G33KR-W8%f%GF4__16_VisioStdVolume_-VisioStdRetail-
  10217. 361fe620-64f4-41b5-ba77-84f8e079b1f7_NY48V-PPYYH-3F4PX-XJRKJ-W4%f%423__16_VisioStdXVolume
  10218. bb11badf-d8aa-470e-9311-20eaf80fe5cc_WXY84-JN2Q9-RBCCQ-3Q3J3-3P%f%FJ6__16_WordVolume_-WordRetail-
  10219. :: Office 2019
  10220. 22e6b96c-1011-4cd5-8b35-3c8fb6366b86_FGQNJ-JWJCG-7Q8MG-RMRGJ-9T%f%QVF__16_AccessRuntime2019Retail_[PrepidBypass]
  10221. 9e9bceeb-e736-4f26-88de-763f87dcc485_9N9PT-27V4Y-VJ2PD-YXFMF-YT%f%FQT__16_Access2019Volume_-Access2019Retail-
  10222. 237854e9-79fc-4497-a0c1-a70969691c6b_TMJWT-YYNMB-3BKTF-644FC-RV%f%XBD__16_Excel2019Volume_-Excel2019Retail-
  10223. c8f8a301-19f5-4132-96ce-2de9d4adbd33_7HD7K-N4PVK-BHBCQ-YWQRW-XW%f%4VK__16_Outlook2019Volume_-Outlook2019Retail-
  10224. 3131fd61-5e4f-4308-8d6d-62be1987c92c_RRNCX-C64HY-W2MM7-MCH9G-TJ%f%HMQ__16_PowerPoint2019Volume_-PowerPoint2019Retail-
  10225. 2ca2bf3f-949e-446a-82c7-e25a15ec78c4_B4NPR-3FKK7-T2MBV-FRQ4W-PK%f%D2B__16_ProjectPro2019Volume_-ProjectPro2019Retail-
  10226. 1777f0e3-7392-4198-97ea-8ae4de6f6381_C4F7P-NCP8C-6CQPT-MQHV9-JX%f%D2M__16_ProjectStd2019Volume_-ProjectStd2019Retail-
  10227. 85dd8b5f-eaa4-4af3-a628-cce9e77c9a03_NMMKJ-6RK4F-KMJVX-8D9MJ-6M%f%WKP__16_ProPlus2019Volume_-ProPlus2019Retail-Professional2019Retail-
  10228. 9d3e4cca-e172-46f1-a2f4-1d2107051444_G2KWX-3NW6P-PY93R-JXK2T-C9%f%Y9V__16_Publisher2019Volume_-Publisher2019Retail-
  10229. 734c6c6e-b0ba-4298-a891-671772b2bd1b_NCJ33-JHBBY-HTK98-MYCV8-HM%f%KHJ__16_SkypeforBusiness2019Volume_-SkypeforBusiness2019Retail-
  10230. f88cfdec-94ce-4463-a969-037be92bc0e7_N9722-BV9H6-WTJTT-FPB93-97%f%8MK__16_SkypeforBusinessEntry2019Retail_[PrepidBypass]
  10231. 6912a74b-a5fb-401a-bfdb-2e3ab46f4b02_6NWWJ-YQWMR-QKGCB-6TMB3-9D%f%9HK__16_Standard2019Volume_-Standard2019Retail-HomeBusiness2019Retail-HomeStudentARM2019Retail-HomeStudentPlusARM2019Retail-HomeStudent2019Retail-Personal2019Retail-
  10232. 5b5cf08f-b81a-431d-b080-3450d8620565_9BGNQ-K37YR-RQHF2-38RQ3-7V%f%CBB__16_VisioPro2019Volume_-VisioPro2019Retail-
  10233. e06d7df3-aad0-419d-8dfb-0ac37e2bdf39_7TQNQ-K3YQQ-3PFH7-CCPPM-X4%f%VQ2__16_VisioStd2019Volume_-VisioStd2019Retail-
  10234. 059834fe-a8ea-4bff-b67b-4d006b5447d3_PBX3G-NWMT6-Q7XBW-PYJGG-WX%f%D33__16_Word2019Volume_-Word2019Retail-
  10235. :: Office 2021
  10236. :: OneNote2021Volume KMS license is not available
  10237. 844c36cb-851c-49e7-9079-12e62a049e2a_MNX9D-PB834-VCGY2-K2RW2-2D%f%P3D__16_AccessRuntime2021Retail_[Bypass]
  10238. 1fe429d8-3fa7-4a39-b6f0-03dded42fe14_WM8YG-YNGDD-4JHDC-PG3F4-FC%f%4T4__16_Access2021Volume_-Access2021Retail-
  10239. ea71effc-69f1-4925-9991-2f5e319bbc24_NWG3X-87C9K-TC7YY-BC2G7-G6%f%RVC__16_Excel2021Volume_-Excel2021Retail-
  10240. a5799e4c-f83c-4c6e-9516-dfe9b696150b_C9FM6-3N72F-HFJXB-TM3V9-T8%f%6R9__16_Outlook2021Volume_-Outlook2021Retail-
  10241. 778ccb9a-2f6a-44e5-853c-eb22b7609643_CNM3W-V94GB-QJQHH-BDQ3J-33%f%Y8H__16_OneNoteFree2021Retail_[Bypass]
  10242. 6e166cc3-495d-438a-89e7-d7c9e6fd4dea_TY7XF-NFRBR-KJ44C-G83KF-GX%f%27K__16_PowerPoint2021Volume_-PowerPoint2021Retail-
  10243. 76881159-155c-43e0-9db7-2d70a9a3a4ca_FTNWT-C6WBT-8HMGF-K9PRX-QV%f%9H8__16_ProjectPro2021Volume_-ProjectPro2021Retail-
  10244. 6dd72704-f752-4b71-94c7-11cec6bfc355_J2JDC-NJCYY-9RGQ4-YXWMH-T3%f%D4T__16_ProjectStd2021Volume_-ProjectStd2021Retail-
  10245. fbdb3e18-a8ef-4fb3-9183-dffd60bd0984_FXYTK-NJJ8C-GB6DW-3DYQT-6F%f%7TH__16_ProPlus2021Volume_-ProPlus2021Retail-Professional2021Retail-
  10246. aa66521f-2370-4ad8-a2bb-c095e3e4338f_2MW9D-N4BXM-9VBPG-Q7W6M-KF%f%BGQ__16_Publisher2021Volume_-Publisher2021Retail-
  10247. 1f32a9af-1274-48bd-ba1e-1ab7508a23e8_HWCXN-K3WBT-WJBKY-R8BD9-XK%f%29P__16_SkypeforBusiness2021Volume_-SkypeforBusiness2021Retail-
  10248. 080a45c5-9f9f-49eb-b4b0-c3c610a5ebd3_KDX7X-BNVR8-TXXGX-4Q7Y8-78%f%VT3__16_Standard2021Volume_-Standard2021Retail-HomeBusiness2021Retail-HomeStudent2021Retail-Personal2021Retail-
  10249. fb61ac9a-1688-45d2-8f6b-0674dbffa33c_KNH8D-FGHT4-T8RK3-CTDYJ-K2%f%HT4__16_VisioPro2021Volume_-VisioPro2021Retail-
  10250. 72fce797-1884-48dd-a860-b2f6a5efd3ca_MJVNY-BYWPY-CWV6J-2RKRT-4M%f%8QG__16_VisioStd2021Volume_-VisioStd2021Retail-
  10251. abe28aea-625a-43b1-8e30-225eb8fbd9e5_TN8H9-M34D3-Y64V9-TR72V-X7%f%9KV__16_Word2021Volume_-Word2021Retail-
  10252. :: Office 2024
  10253. fceda083-1203-402a-8ec4-3d7ed9f3648c_2TDPW-NDQ7G-FMG99-DXQ7M-TX%f%3T2__16_ProPlus2024Volume-Preview
  10254. aaea0dc8-78e1-4343-9f25-b69b83dd1bce_D9GTG-NP7DV-T6JP3-B6B62-JB%f%89R__16_ProjectPro2024Volume-Preview
  10255. 4ab4d849-aabc-43fb-87ee-3aed02518891_YW66X-NH62M-G6YFP-B7KCT-WX%f%GKQ__16_VisioPro2024Volume-Preview
  10256. 72e9faa7-ead1-4f3d-9f6e-3abc090a81d7_82FTR-NCHR7-W3944-MGRHM-JM%f%CWD__16_Access2024Volume_-Access2024Retail-
  10257. cbbba2c3-0ff5-4558-846a-043ef9d78559_F4DYN-89BP2-WQTWJ-GR8YC-CK%f%GJG__16_Excel2024Volume_-Excel2024Retail-
  10258. bef3152a-8a04-40f2-a065-340c3f23516d_D2F8D-N3Q3B-J28PV-X27HD-RJ%f%WB9__16_Outlook2024Volume_-Outlook2024Retail-
  10259. b63626a4-5f05-4ced-9639-31ba730a127e_CW94N-K6GJH-9CTXY-MG2VC-FY%f%CWP__16_PowerPoint2024Volume_-PowerPoint2024Retail-
  10260. f510af75-8ab7-4426-a236-1bfb95c34ff8_FQQ23-N4YCY-73HQ3-FM9WC-76%f%HF4__16_ProjectPro2024Volume_-ProjectPro2024Retail-
  10261. 9f144f27-2ac5-40b9-899d-898c2b8b4f81_PD3TT-NTHQQ-VC7CY-MFXK3-G8%f%7F8__16_ProjectStd2024Volume_-ProjectStd2024Retail-
  10262. 8d368fc1-9470-4be2-8d66-90e836cbb051_XJ2XN-FW8RK-P4HMP-DKDBV-GC%f%VGB__16_ProPlus2024Volume_-ProPlus2024Retail-
  10263. 0002290a-2091-4324-9e53-3cfe28884cde_4NKHF-9HBQF-Q3B6C-7YV34-F6%f%4P3__16_SkypeforBusiness2024Volume
  10264. bbac904f-6a7e-418a-bb4b-24c85da06187_V28N4-JG22K-W66P8-VTMGK-H6%f%HGR__16_Standard2024Volume_-Home2024Retail-HomeBusiness2024Retail-
  10265. fa187091-8246-47b1-964f-80a0b1e5d69a_B7TN8-FJ8V3-7QYCP-HQPMV-YY%f%89G__16_VisioPro2024Volume_-VisioPro2024Retail-
  10266. 923fa470-aa71-4b8b-b35c-36b79bf9f44b_JMMVY-XFNQC-KK4HK-9H7R3-WQ%f%QTV__16_VisioStd2024Volume_-VisioStd2024Retail-
  10267. d0eded01-0881-4b37-9738-190400095098_MQ84N-7VYDM-FXV7C-6K7CC-VF%f%W9J__16_Word2024Volume_-Word2024Retail-
  10268. ) do (
  10269. for /f "tokens=1-5 delims=_" %%A in ("%%#") do (
  10270. if %1==winkey if %osSKU%==%%C if not defined key (
  10271. echo "!allapps!" | find /i "%%A" %nul1% && set key=%%B
  10272. )
  10273. if %1==chkprod if "%oVer%"=="%%C" if not defined foundprod (
  10274. echo "%%D" | findstr /I "\<%2.*" %nul% && set foundprod=1
  10275. )
  10276. if %1==getinfo if not defined key if "%oVer%"=="%%C" (
  10277. if /i "%2"=="%%D" (
  10278. set key=%%B
  10279. set _actid=%%A
  10280. set _allactid=!_allactid! %%A
  10281. ) else if not defined _oBranding if %_NoEditionChange%==0 (
  10282. echo: %%E | find /i "-%2-" %nul% && (
  10283. set key=%%B
  10284. set _altoffid=%%D
  10285. set _actid=%%A
  10286. set _allactid=!_allactid! %%A
  10287. )
  10288. )
  10289. )
  10290. if %1==getmsiprod if "%oVer%"=="%%C" (
  10291. for /f "tokens=*" %%x in ('findstr /i /c:"%%A" "%_oBranding%"') do set "prodId=%%x"
  10292. set prodId=!prodId:"/>=!
  10293. set prodId=!prodId:~-4!
  10294. if "%oVer%"=="14" (
  10295. REM Exception case for Visio because wrong primary product ID is mentioned in Branding.xml
  10296. echo %%D | find /i "Visio" %nul% && set prodId=0057
  10297. )
  10298. reg query "%2\Registration\{%%A}" /v ProductCode %nul2% | find /i "-!prodId!-" %nul% && (
  10299. reg query "%2\Common\InstalledPackages" %nul2% | find /i "-!prodId!-" %nul% && (
  10300. if defined _oIds (set _oIds=!_oIds! %%D) else (set _oIds=%%D)
  10301. )
  10302. )
  10303. )
  10304. )
  10305. )
  10306. exit /b
  10307. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  10308. :check_actstatus
  10309. cls
  10310. if not defined terminal (
  10311. mode 100, 36
  10312. %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%
  10313. )
  10314. %psc% "$f=[IO.File]::ReadAllText('!_batp!') -split ':sppmgr\:.*';iex ($f[1])"
  10315. goto dk_done
  10316. :sppmgr:
  10317. param (
  10318. [Parameter()]
  10319. [switch]
  10320. $All,
  10321. [Parameter()]
  10322. [switch]
  10323. $Dlv,
  10324. [Parameter()]
  10325. [switch]
  10326. $IID,
  10327. [Parameter()]
  10328. [switch]
  10329. $Pass
  10330. )
  10331. function CONOUT($strObj)
  10332. {
  10333. Out-Host -Input $strObj
  10334. }
  10335. function ExitScript($ExitCode = 0)
  10336. {
  10337. Exit $ExitCode
  10338. }
  10339. if (-Not $PSVersionTable) {
  10340. "==== ERROR ====`r`n"
  10341. "Windows PowerShell 1.0 is not supported by this script."
  10342. ExitScript 1
  10343. }
  10344. if ($ExecutionContext.SessionState.LanguageMode.value__ -NE 0) {
  10345. "==== ERROR ====`r`n"
  10346. "Windows PowerShell is not running in Full Language Mode."
  10347. ExitScript 1
  10348. }
  10349. $winbuild = 1
  10350. try {
  10351. $winbuild = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("$env:SystemRoot\System32\kernel32.dll").FileBuildPart
  10352. } catch {
  10353. $winbuild = [int]([wmi]'Win32_OperatingSystem=@').BuildNumber
  10354. }
  10355. if ($winbuild -EQ 1) {
  10356. "==== ERROR ====`r`n"
  10357. "Could not detect Windows build."
  10358. ExitScript 1
  10359. }
  10360. if ($winbuild -LT 2600) {
  10361. "==== ERROR ====`r`n"
  10362. "This build of Windows is not supported by this script."
  10363. ExitScript 1
  10364. }
  10365. if ($All.IsPresent)
  10366. {
  10367. $isAll = {CONOUT "`r"}
  10368. $noAll = {$null}
  10369. }
  10370. else
  10371. {
  10372. $isAll = {$null}
  10373. $noAll = {CONOUT "`r"}
  10374. }
  10375. $Dlv = $Dlv.IsPresent
  10376. $IID = $IID.IsPresent -Or $Dlv.IsPresent
  10377. $NT6 = $winbuild -GE 6000
  10378. $NT7 = $winbuild -GE 7600
  10379. $NT9 = $winbuild -GE 9600
  10380. $Admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
  10381. $line2 = "============================================================"
  10382. $line3 = "____________________________________________________________"
  10383. function echoWindows
  10384. {
  10385. CONOUT "$line2"
  10386. CONOUT "=== Windows Status ==="
  10387. CONOUT "$line2"
  10388. & $noAll
  10389. }
  10390. function echoOffice
  10391. {
  10392. if ($doMSG -EQ 0) {
  10393. return
  10394. }
  10395. & $isAll
  10396. CONOUT "$line2"
  10397. CONOUT "=== Office Status ==="
  10398. CONOUT "$line2"
  10399. & $noAll
  10400. $script:doMSG = 0
  10401. }
  10402. function strGetRegistry($strKey, $strName)
  10403. {
  10404. try {
  10405. return [Microsoft.Win32.Registry]::GetValue($strKey, $strName, $null)
  10406. } catch {
  10407. return $null
  10408. }
  10409. }
  10410. function CheckOhook
  10411. {
  10412. $ohook = 0
  10413. $paths = "${env:ProgramFiles}", "${env:ProgramW6432}", "${env:ProgramFiles(x86)}"
  10414. 15, 16 | foreach `
  10415. {
  10416. $A = $_; $paths | foreach `
  10417. {
  10418. if (Test-Path "$($_)$('\Microsoft Office\Office')$($A)$('\sppc*dll')") {$ohook = 1}
  10419. }
  10420. }
  10421. "System", "SystemX86" | foreach `
  10422. {
  10423. $A = $_; "Office 15", "Office" | foreach `
  10424. {
  10425. $B = $_; $paths | foreach `
  10426. {
  10427. if (Test-Path "$($_)$('\Microsoft ')$($B)$('\root\vfs\')$($A)$('\sppc*dll')") {$ohook = 1}
  10428. }
  10429. }
  10430. }
  10431. if ($ohook -EQ 0) {
  10432. return
  10433. }
  10434. & $isAll
  10435. CONOUT "$line2"
  10436. CONOUT "=== Office Ohook Status ==="
  10437. CONOUT "$line2"
  10438. $host.UI.WriteLine('Yellow', 'Black', "`r`nOhook for permanent Office activation is installed.`r`nYou can ignore the below mentioned Office activation status.")
  10439. & $noAll
  10440. }
  10441. #region WMI
  10442. function DetectID($strSLP, $strAppId)
  10443. {
  10444. $ppk = (" AND PartialProductKey <> NULL)", ")")[$All.IsPresent]
  10445. $fltr = "SELECT ID FROM $strSLP WHERE (ApplicationID='$strAppId'"
  10446. $clause = $fltr + $ppk
  10447. $sWmi = [wmisearcher]$clause
  10448. $sWmi.Options.Rewindable = $false
  10449. return ($sWmi.Get().Count -GT 0)
  10450. }
  10451. function GetID($strSLP, $strAppId)
  10452. {
  10453. $NT5 = ($strSLP -EQ $wslp -And $winbuild -LT 6001)
  10454. $IDs = [Collections.ArrayList]@()
  10455. $isAdd = (" AND LicenseDependsOn <> NULL)", ")")[$NT5]
  10456. $noAdd = " AND LicenseDependsOn IS NULL)"
  10457. $query = "SELECT ID FROM $strSLP WHERE (ApplicationID='$strAppId' AND PartialProductKey"
  10458. if ($All.IsPresent) {
  10459. $fltr = $query + " IS NULL"
  10460. $clause = $fltr + $isAdd
  10461. $sWmi = [wmisearcher]$clause
  10462. $sWmi.Options.Rewindable = $false
  10463. try {$sWmi.Get() | select -Expand Properties -EA 0 | foreach {$IDs += $_.Value}} catch {}
  10464. if (-Not $NT5) {
  10465. $clause = $fltr + $noAdd
  10466. $sWmi = [wmisearcher]$clause
  10467. $sWmi.Options.Rewindable = $false
  10468. try {$sWmi.Get() | select -Expand Properties -EA 0 | foreach {$IDs += $_.Value}} catch {}
  10469. }
  10470. }
  10471. $fltr = $query + " <> NULL"
  10472. $clause = $fltr + $isAdd
  10473. $sWmi = [wmisearcher]$clause
  10474. $sWmi.Options.Rewindable = $false
  10475. try {$sWmi.Get() | select -Expand Properties -EA 0 | foreach {$IDs += $_.Value}} catch {}
  10476. if (-Not $NT5) {
  10477. $clause = $fltr + $noAdd
  10478. $sWmi = [wmisearcher]$clause
  10479. $sWmi.Options.Rewindable = $false
  10480. try {$sWmi.Get() | select -Expand Properties -EA 0 | foreach {$IDs += $_.Value}} catch {}
  10481. }
  10482. return $IDs
  10483. }
  10484. function DetectSubscription {
  10485. if ($null -EQ $objSvc.SubscriptionType -Or $objSvc.SubscriptionType -EQ 120) {
  10486. return
  10487. }
  10488. if ($objSvc.SubscriptionType -EQ 1) {
  10489. $SubMsgType = "Device based"
  10490. } else {
  10491. $SubMsgType = "User based"
  10492. }
  10493. if ($objSvc.SubscriptionStatus -EQ 120) {
  10494. $SubMsgStatus = "Expired"
  10495. } elseif ($objSvc.SubscriptionStatus -EQ 100) {
  10496. $SubMsgStatus = "Disabled"
  10497. } elseif ($objSvc.SubscriptionStatus -EQ 1) {
  10498. $SubMsgStatus = "Active"
  10499. } else {
  10500. $SubMsgStatus = "Not active"
  10501. }
  10502. $SubMsgExpiry = "Unknown"
  10503. if ($objSvc.SubscriptionExpiry) {
  10504. if ($objSvc.SubscriptionExpiry.Contains("unspecified") -EQ $false) {$SubMsgExpiry = $objSvc.SubscriptionExpiry}
  10505. }
  10506. $SubMsgEdition = "Unknown"
  10507. if ($objSvc.SubscriptionEdition) {
  10508. if ($objSvc.SubscriptionEdition.Contains("UNKNOWN") -EQ $false) {$SubMsgEdition = $objSvc.SubscriptionEdition}
  10509. }
  10510. CONOUT "`nSubscription information:"
  10511. CONOUT " Edition: $SubMsgEdition"
  10512. CONOUT " Type : $SubMsgType"
  10513. CONOUT " Status : $SubMsgStatus"
  10514. CONOUT " Expiry : $SubMsgExpiry"
  10515. }
  10516. function DetectAdbaClient
  10517. {
  10518. CONOUT "`nAD Activation client information:"
  10519. CONOUT " Object Name: $ADActivationObjectName"
  10520. CONOUT " Domain Name: $ADActivationObjectDN"
  10521. CONOUT " CSVLK Extended PID: $ADActivationCsvlkPid"
  10522. CONOUT " CSVLK Activation ID: $ADActivationCsvlkSkuId"
  10523. }
  10524. function DetectAvmClient
  10525. {
  10526. CONOUT "`nAutomatic VM Activation client information:"
  10527. if (-Not [String]::IsNullOrEmpty($IAID)) {
  10528. CONOUT " Guest IAID: $IAID"
  10529. } else {
  10530. CONOUT " Guest IAID: Not Available"
  10531. }
  10532. if (-Not [String]::IsNullOrEmpty($AutomaticVMActivationHostMachineName)) {
  10533. CONOUT " Host machine name: $AutomaticVMActivationHostMachineName"
  10534. } else {
  10535. CONOUT " Host machine name: Not Available"
  10536. }
  10537. if ($AutomaticVMActivationLastActivationTime.Substring(0,4) -NE "1601") {
  10538. $EED = [DateTime]::Parse([Management.ManagementDateTimeConverter]::ToDateTime($AutomaticVMActivationLastActivationTime),$null,48).ToString('yyyy-MM-dd hh:mm:ss tt')
  10539. CONOUT " Activation time: $EED UTC"
  10540. } else {
  10541. CONOUT " Activation time: Not Available"
  10542. }
  10543. if (-Not [String]::IsNullOrEmpty($AutomaticVMActivationHostDigitalPid2)) {
  10544. CONOUT " Host Digital PID2: $AutomaticVMActivationHostDigitalPid2"
  10545. } else {
  10546. CONOUT " Host Digital PID2: Not Available"
  10547. }
  10548. }
  10549. function DetectKmsHost
  10550. {
  10551. if ($Vista -Or $NT5) {
  10552. $KeyManagementServiceListeningPort = strGetRegistry $SLKeyPath "KeyManagementServiceListeningPort"
  10553. $KeyManagementServiceDnsPublishing = strGetRegistry $SLKeyPath "DisableDnsPublishing"
  10554. $KeyManagementServiceLowPriority = strGetRegistry $SLKeyPath "EnableKmsLowPriority"
  10555. if (-Not $KeyManagementServiceDnsPublishing) {$KeyManagementServiceDnsPublishing = "TRUE"}
  10556. if (-Not $KeyManagementServiceLowPriority) {$KeyManagementServiceLowPriority = "FALSE"}
  10557. } else {
  10558. $KeyManagementServiceListeningPort = $objSvc.KeyManagementServiceListeningPort
  10559. $KeyManagementServiceDnsPublishing = $objSvc.KeyManagementServiceDnsPublishing
  10560. $KeyManagementServiceLowPriority = $objSvc.KeyManagementServiceLowPriority
  10561. }
  10562. if (-Not $KeyManagementServiceListeningPort) {$KeyManagementServiceListeningPort = 1688}
  10563. if ($KeyManagementServiceDnsPublishing -EQ "TRUE") {
  10564. $KeyManagementServiceDnsPublishing = "Enabled"
  10565. } else {
  10566. $KeyManagementServiceDnsPublishing = "Disabled"
  10567. }
  10568. if ($KeyManagementServiceLowPriority -EQ "TRUE") {
  10569. $KeyManagementServiceLowPriority = "Low"
  10570. } else {
  10571. $KeyManagementServiceLowPriority = "Normal"
  10572. }
  10573. CONOUT "`nKey Management Service host information:"
  10574. CONOUT " Current count: $KeyManagementServiceCurrentCount"
  10575. CONOUT " Listening on Port: $KeyManagementServiceListeningPort"
  10576. CONOUT " DNS publishing: $KeyManagementServiceDnsPublishing"
  10577. CONOUT " KMS priority: $KeyManagementServiceLowPriority"
  10578. if (-Not [String]::IsNullOrEmpty($KeyManagementServiceTotalRequests)) {
  10579. CONOUT "`nKey Management Service cumulative requests received from clients:"
  10580. CONOUT " Total: $KeyManagementServiceTotalRequests"
  10581. CONOUT " Failed: $KeyManagementServiceFailedRequests"
  10582. CONOUT " Unlicensed: $KeyManagementServiceUnlicensedRequests"
  10583. CONOUT " Licensed: $KeyManagementServiceLicensedRequests"
  10584. CONOUT " Initial grace period: $KeyManagementServiceOOBGraceRequests"
  10585. CONOUT " Expired or Hardware out of tolerance: $KeyManagementServiceOOTGraceRequests"
  10586. CONOUT " Non-genuine grace period: $KeyManagementServiceNonGenuineGraceRequests"
  10587. if ($null -NE $KeyManagementServiceNotificationRequests) {CONOUT " Notification: $KeyManagementServiceNotificationRequests"}
  10588. }
  10589. }
  10590. function DetectKmsClient
  10591. {
  10592. if ($null -NE $VLActivationTypeEnabled) {CONOUT "Configured Activation Type: $($VLActTypes[$VLActivationTypeEnabled])"}
  10593. CONOUT "`r"
  10594. if ($LicenseStatus -NE 1) {
  10595. CONOUT "Please activate the product in order to update KMS client information values."
  10596. return
  10597. }
  10598. if ($Vista) {
  10599. $KeyManagementServicePort = strGetRegistry $SLKeyPath "KeyManagementServicePort"
  10600. $DiscoveredKeyManagementServiceMachineName = strGetRegistry $NSKeyPath "DiscoveredKeyManagementServiceName"
  10601. $DiscoveredKeyManagementServiceMachinePort = strGetRegistry $NSKeyPath "DiscoveredKeyManagementServicePort"
  10602. }
  10603. if ([String]::IsNullOrEmpty($KeyManagementServiceMachine)) {
  10604. $KmsReg = $null
  10605. } else {
  10606. if (-Not $KeyManagementServicePort) {$KeyManagementServicePort = 1688}
  10607. $KmsReg = "Registered KMS machine name: ${KeyManagementServiceMachine}:${KeyManagementServicePort}"
  10608. }
  10609. if ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceMachineName)) {
  10610. $KmsDns = "DNS auto-discovery: KMS name not available"
  10611. if ($Vista -And -Not $Admin) {$KmsDns = "DNS auto-discovery: Run the script as administrator to retrieve info"}
  10612. } else {
  10613. if (-Not $DiscoveredKeyManagementServiceMachinePort) {$DiscoveredKeyManagementServiceMachinePort = 1688}
  10614. $KmsDns = "KMS machine name from DNS: ${DiscoveredKeyManagementServiceMachineName}:${DiscoveredKeyManagementServiceMachinePort}"
  10615. }
  10616. if ($null -NE $objSvc.KeyManagementServiceHostCaching) {
  10617. if ($objSvc.KeyManagementServiceHostCaching -EQ "TRUE") {
  10618. $KeyManagementServiceHostCaching = "Enabled"
  10619. } else {
  10620. $KeyManagementServiceHostCaching = "Disabled"
  10621. }
  10622. }
  10623. CONOUT "Key Management Service client information:"
  10624. CONOUT " Client Machine ID (CMID): $($objSvc.ClientMachineID)"
  10625. if ($null -EQ $KmsReg) {
  10626. CONOUT " $KmsDns"
  10627. CONOUT " Registered KMS machine name: KMS name not available"
  10628. } else {
  10629. CONOUT " $KmsReg"
  10630. }
  10631. if ($null -NE $DiscoveredKeyManagementServiceMachineIpAddress) {CONOUT " KMS machine IP address: $DiscoveredKeyManagementServiceMachineIpAddress"}
  10632. CONOUT " KMS machine extended PID: $KeyManagementServiceProductKeyID"
  10633. CONOUT " Activation interval: $VLActivationInterval minutes"
  10634. CONOUT " Renewal interval: $VLRenewalInterval minutes"
  10635. if ($null -NE $KeyManagementServiceHostCaching) {CONOUT " KMS host caching: $KeyManagementServiceHostCaching"}
  10636. if (-Not [String]::IsNullOrEmpty($KeyManagementServiceLookupDomain)) {CONOUT " KMS SRV record lookup domain: $KeyManagementServiceLookupDomain"}
  10637. }
  10638. function GetResult($strSLP, $strSLS, $strID)
  10639. {
  10640. try
  10641. {
  10642. $objPrd = [wmisearcher]"SELECT * FROM $strSLP WHERE ID='$strID'"
  10643. $objPrd.Options.Rewindable = $false
  10644. $objPrd.Get() | select -Expand Properties -EA 0 | foreach { if (-Not [String]::IsNullOrEmpty($_.Value)) {set $_.Name $_.Value} }
  10645. $objPrd.Dispose()
  10646. }
  10647. catch
  10648. {
  10649. return
  10650. }
  10651. $winID = ($ApplicationID -EQ $winApp)
  10652. $winPR = ($winID -And -Not $LicenseIsAddon)
  10653. $Vista = ($winID -And $NT6 -And -Not $NT7)
  10654. $NT5 = ($strSLP -EQ $wslp -And $winbuild -LT 6001)
  10655. $reapp = ("Windows", "App")[!$winID]
  10656. $prmnt = ("machine", "product")[!$winPR]
  10657. if ($Description | Select-String "VOLUME_KMSCLIENT") {$cKmsClient = 1; $_mTag = "Volume"}
  10658. if ($Description | Select-String "TIMEBASED_") {$cTblClient = 1; $_mTag = "Timebased"}
  10659. if ($Description | Select-String "VIRTUAL_MACHINE_ACTIVATION") {$cAvmClient = 1; $_mTag = "Automatic VM"}
  10660. if ($null -EQ $cKmsClient) {
  10661. if ($Description | Select-String "VOLUME_KMS") {$cKmsHost = 1}
  10662. }
  10663. $_gpr = [Math]::Round($GracePeriodRemaining/1440)
  10664. if ($_gpr -GT 0) {
  10665. $_xpr = [DateTime]::Now.addMinutes($GracePeriodRemaining).ToString('yyyy-MM-dd hh:mm:ss tt')
  10666. }
  10667. if ($null -EQ $LicenseStatusReason) {$LicenseStatusReason = -1}
  10668. $LicenseReason = '0x{0:X}' -f $LicenseStatusReason
  10669. $LicenseMsg = "Time remaining: $GracePeriodRemaining minute(s) ($_gpr day(s))"
  10670. if ($LicenseStatus -EQ 0) {
  10671. $LicenseInf = "Unlicensed"
  10672. $LicenseMsg = $null
  10673. }
  10674. if ($LicenseStatus -EQ 1) {
  10675. $LicenseInf = "Licensed"
  10676. $LicenseMsg = $null
  10677. if ($GracePeriodRemaining -EQ 0) {
  10678. $ExpireMsg = "The $prmnt is permanently activated."
  10679. } else {
  10680. $LicenseMsg = "$_mTag activation expiration: $GracePeriodRemaining minute(s) ($_gpr day(s))"
  10681. if ($null -NE $_xpr) {$ExpireMsg = "$_mTag activation will expire $_xpr"}
  10682. }
  10683. }
  10684. if ($LicenseStatus -EQ 2) {
  10685. $LicenseInf = "Initial grace period"
  10686. if ($null -NE $_xpr) {$ExpireMsg = "Initial grace period ends $_xpr"}
  10687. }
  10688. if ($LicenseStatus -EQ 3) {
  10689. $LicenseInf = "Additional grace period (KMS license expired or hardware out of tolerance)"
  10690. if ($null -NE $_xpr) {$ExpireMsg = "Additional grace period ends $_xpr"}
  10691. }
  10692. if ($LicenseStatus -EQ 4) {
  10693. $LicenseInf = "Non-genuine grace period"
  10694. if ($null -NE $_xpr) {$ExpireMsg = "Non-genuine grace period ends $_xpr"}
  10695. }
  10696. if ($LicenseStatus -EQ 5 -And -Not $NT5) {
  10697. $LicenseInf = "Notification"
  10698. $LicenseMsg = "Notification Reason: $LicenseReason"
  10699. if ($LicenseReason -EQ "0xC004F00F") {if ($null -NE $cKmsClient) {$LicenseMsg = $LicenseMsg + " (KMS license expired)."} else {$LicenseMsg = $LicenseMsg + " (hardware out of tolerance)."}}
  10700. if ($LicenseReason -EQ "0xC004F200") {$LicenseMsg = $LicenseMsg + " (non-genuine)."}
  10701. if ($LicenseReason -EQ "0xC004F009" -Or $LicenseReason -EQ "0xC004F064") {$LicenseMsg = $LicenseMsg + " (grace time expired)."}
  10702. }
  10703. if ($LicenseStatus -GT 5 -Or ($LicenseStatus -GT 4 -And $NT5)) {
  10704. $LicenseInf = "Unknown"
  10705. $LicenseMsg = $null
  10706. }
  10707. if ($LicenseStatus -EQ 6 -And -Not $Vista -And -Not $NT5) {
  10708. $LicenseInf = "Extended grace period"
  10709. if ($null -NE $_xpr) {$ExpireMsg = "Extended grace period ends $_xpr"}
  10710. }
  10711. if ($winPR -And $PartialProductKey -And -Not $NT9) {
  10712. $dp4 = strGetRegistry "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" "DigitalProductId4"
  10713. if ($null -NE $dp4) {
  10714. $ProductKeyChannel = ([System.Text.Encoding]::Unicode.GetString($dp4, 1016, 128)).Trim([char]$null)
  10715. }
  10716. }
  10717. if ($winPR -And $Dlv -And $NT7 -And $null -EQ $RemainingAppReArmCount) {
  10718. try
  10719. {
  10720. $tmp = [wmisearcher]"SELECT RemainingWindowsReArmCount FROM $strSLS"
  10721. $tmp.Options.Rewindable = $false
  10722. $tmp.Get() | select -Expand Properties -EA 0 | foreach {set $_.Name $_.Value}
  10723. $tmp.Dispose()
  10724. }
  10725. catch
  10726. {
  10727. }
  10728. }
  10729. $add_on = $Name.IndexOf("add-on for", 5)
  10730. & $isAll
  10731. if ($add_on -EQ -1) {CONOUT "Name: $Name"} else {CONOUT "Name: $($Name.Substring(0, $add_on + 7))"}
  10732. CONOUT "Description: $Description"
  10733. CONOUT "Activation ID: $ID"
  10734. if ($null -NE $ProductKeyID) {CONOUT "Extended PID: $ProductKeyID"}
  10735. if ($null -NE $ProductKeyID2 -And $Dlv) {CONOUT "Product ID: $ProductKeyID2"}
  10736. if ($null -NE $OfflineInstallationId -And $IID) {CONOUT "Installation ID: $OfflineInstallationId"}
  10737. if ($null -NE $ProductKeyChannel) {CONOUT "Product Key Channel: $ProductKeyChannel"}
  10738. if ($null -NE $PartialProductKey) {CONOUT "Partial Product Key: $PartialProductKey"}
  10739. CONOUT "License Status: $LicenseInf"
  10740. if ($null -NE $LicenseMsg) {CONOUT "$LicenseMsg"}
  10741. if ($LicenseStatus -NE 0 -And $EvaluationEndDate.Substring(0,4) -NE "1601") {
  10742. $EED = [DateTime]::Parse([Management.ManagementDateTimeConverter]::ToDateTime($EvaluationEndDate),$null,48).ToString('yyyy-MM-dd hh:mm:ss tt')
  10743. CONOUT "Evaluation End Date: $EED UTC"
  10744. }
  10745. if ($Dlv) {
  10746. if ($null -NE $RemainingWindowsReArmCount) {
  10747. CONOUT "Remaining Windows rearm count: $RemainingWindowsReArmCount"
  10748. }
  10749. if ($null -NE $RemainingSkuReArmCount -And $RemainingSkuReArmCount -NE 4294967295) {
  10750. CONOUT "Remaining $reapp rearm count: $RemainingAppReArmCount"
  10751. CONOUT "Remaining SKU rearm count: $RemainingSkuReArmCount"
  10752. }
  10753. if ($null -NE $TrustedTime -And $LicenseStatus -NE 0) {
  10754. $TTD = [DateTime]::Parse([Management.ManagementDateTimeConverter]::ToDateTime($TrustedTime),$null,32).ToString('yyyy-MM-dd hh:mm:ss tt')
  10755. CONOUT "Trusted time: $TTD"
  10756. }
  10757. }
  10758. if ($LicenseStatus -EQ 0) {
  10759. return
  10760. }
  10761. if ($strSLP -EQ $wslp -And $null -NE $PartialProductKey -And $null -NE $ADActivationObjectName -And $VLActivationType -EQ 1) {
  10762. DetectAdbaClient
  10763. }
  10764. if ($winID -And $null -NE $cAvmClient -And $null -NE $PartialProductKey) {
  10765. DetectAvmClient
  10766. }
  10767. $chkSub = ($winPR -And $cSub)
  10768. $chkSLS = ($null -NE $PartialProductKey) -And ($null -NE $cKmsClient -Or $null -NE $cKmsHost -Or $chkSub)
  10769. if (!$chkSLS) {
  10770. if ($null -NE $ExpireMsg) {CONOUT "`n $ExpireMsg"}
  10771. return
  10772. }
  10773. try
  10774. {
  10775. $objSvc = New-Object PSObject
  10776. $wmiSvc = [wmisearcher]"SELECT * FROM $strSLS"
  10777. $wmiSvc.Options.Rewindable = $false
  10778. $wmiSvc.Get() | select -Expand Properties -EA 0 | foreach { if (-Not [String]::IsNullOrEmpty($_.Value)) {$objSvc | Add-Member 8 $_.Name $_.Value} }
  10779. $wmiSvc.Dispose()
  10780. if ($null -EQ $IsKeyManagementServiceMachine) {$objSvc.PSObject.Properties | foreach {set $_.Name $_.Value}}
  10781. }
  10782. catch
  10783. {
  10784. return
  10785. }
  10786. if ($strSLS -EQ $wsls -And $NT9) {
  10787. if ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceMachineIpAddress)) {
  10788. $DiscoveredKeyManagementServiceMachineIpAddress = "not available"
  10789. }
  10790. }
  10791. if ($null -NE $cKmsHost -And $IsKeyManagementServiceMachine -GT 0) {
  10792. if ($null -NE $ExpireMsg) {CONOUT "`n $ExpireMsg"}
  10793. DetectKmsHost
  10794. }
  10795. if ($null -NE $cKmsClient) {
  10796. DetectKmsClient
  10797. }
  10798. if ($null -EQ $cKmsHost) {
  10799. if ($null -NE $ExpireMsg) {CONOUT "`n $ExpireMsg"}
  10800. }
  10801. if ($chkSub) {
  10802. DetectSubscription
  10803. }
  10804. }
  10805. #endregion
  10806. #region vNextDiag
  10807. if ($PSVersionTable.PSVersion.Major -Lt 3)
  10808. {
  10809. function ConvertFrom-Json
  10810. {
  10811. [CmdletBinding()]
  10812. Param(
  10813. [Parameter(ValueFromPipeline=$true)][Object]$item
  10814. )
  10815. [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
  10816. $psjs = New-Object System.Web.Script.Serialization.JavaScriptSerializer
  10817. Return ,$psjs.DeserializeObject($item)
  10818. }
  10819. function ConvertTo-Json
  10820. {
  10821. [CmdletBinding()]
  10822. Param(
  10823. [Parameter(ValueFromPipeline=$true)][Object]$item
  10824. )
  10825. [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
  10826. $psjs = New-Object System.Web.Script.Serialization.JavaScriptSerializer
  10827. Return $psjs.Serialize($item)
  10828. }
  10829. }
  10830. function PrintModePerPridFromRegistry
  10831. {
  10832. $vNextRegkey = "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing\LicensingNext"
  10833. $vNextPrids = Get-Item -Path $vNextRegkey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty 'property' -ErrorAction SilentlyContinue | Where-Object -FilterScript {$_.ToLower() -like "*retail" -or $_.ToLower() -like "*volume"}
  10834. If ($null -Eq $vNextPrids)
  10835. {
  10836. CONOUT "`nNo registry keys found."
  10837. Return
  10838. }
  10839. CONOUT "`r"
  10840. $vNextPrids | ForEach `
  10841. {
  10842. $mode = (Get-ItemProperty -Path $vNextRegkey -Name $_).$_
  10843. Switch ($mode)
  10844. {
  10845. 2 { $mode = "vNext"; Break }
  10846. 3 { $mode = "Device"; Break }
  10847. Default { $mode = "Legacy"; Break }
  10848. }
  10849. CONOUT "$_ = $mode"
  10850. }
  10851. }
  10852. function PrintSharedComputerLicensing
  10853. {
  10854. $scaRegKey = "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration"
  10855. $scaValue = Get-ItemProperty -Path $scaRegKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty "SharedComputerLicensing" -ErrorAction SilentlyContinue
  10856. $scaRegKey2 = "HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing"
  10857. $scaValue2 = Get-ItemProperty -Path $scaRegKey2 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty "SharedComputerLicensing" -ErrorAction SilentlyContinue
  10858. $scaPolicyKey = "HKLM:\SOFTWARE\Policies\Microsoft\Office\16.0\Common\Licensing"
  10859. $scaPolicyValue = Get-ItemProperty -Path $scaPolicyKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty "SharedComputerLicensing" -ErrorAction SilentlyContinue
  10860. If ($null -Eq $scaValue -And $null -Eq $scaValue2 -And $null -Eq $scaPolicyValue)
  10861. {
  10862. CONOUT "`nNo registry keys found."
  10863. Return
  10864. }
  10865. $scaModeValue = $scaValue -Or $scaValue2 -Or $scaPolicyValue
  10866. If ($scaModeValue -Eq 0)
  10867. {
  10868. $scaMode = "Disabled"
  10869. }
  10870. If ($scaModeValue -Eq 1)
  10871. {
  10872. $scaMode = "Enabled"
  10873. }
  10874. CONOUT "`nStatus: $scaMode"
  10875. CONOUT "`r"
  10876. $tokenFiles = $null
  10877. $tokenPath = "${env:LOCALAPPDATA}\Microsoft\Office\16.0\Licensing"
  10878. If (Test-Path $tokenPath)
  10879. {
  10880. $tokenFiles = Get-ChildItem -Path $tokenPath -Filter "*authString*" -Recurse | Where-Object { !$_.PSIsContainer }
  10881. }
  10882. If ($null -Eq $tokenFiles -Or $tokenFiles.Length -Eq 0)
  10883. {
  10884. CONOUT "No tokens found."
  10885. Return
  10886. }
  10887. $tokenFiles | ForEach `
  10888. {
  10889. $tokenParts = (Get-Content -Encoding Unicode -Path $_.FullName).Split('_')
  10890. $output = New-Object PSObject
  10891. $output | Add-Member 8 'ACID' $tokenParts[0];
  10892. $output | Add-Member 8 'User' $tokenParts[3];
  10893. $output | Add-Member 8 'NotBefore' $tokenParts[4];
  10894. $output | Add-Member 8 'NotAfter' $tokenParts[5];
  10895. Write-Output $output
  10896. }
  10897. }
  10898. function PrintLicensesInformation
  10899. {
  10900. Param(
  10901. [ValidateSet("NUL", "Device")]
  10902. [String]$mode
  10903. )
  10904. If ($mode -Eq "NUL")
  10905. {
  10906. $licensePath = "${env:LOCALAPPDATA}\Microsoft\Office\Licenses"
  10907. }
  10908. ElseIf ($mode -Eq "Device")
  10909. {
  10910. $licensePath = "${env:PROGRAMDATA}\Microsoft\Office\Licenses"
  10911. }
  10912. $licenseFiles = $null
  10913. If (Test-Path $licensePath)
  10914. {
  10915. $licenseFiles = Get-ChildItem -Path $licensePath -Recurse | Where-Object { !$_.PSIsContainer }
  10916. }
  10917. If ($null -Eq $licenseFiles -Or $licenseFiles.Length -Eq 0)
  10918. {
  10919. CONOUT "`nNo licenses found."
  10920. Return
  10921. }
  10922. $licenseFiles | ForEach `
  10923. {
  10924. $license = (Get-Content -Encoding Unicode $_.FullName | ConvertFrom-Json).License
  10925. $decodedLicense = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($license)) | ConvertFrom-Json
  10926. $licenseType = $decodedLicense.LicenseType
  10927. If ($null -Ne $decodedLicense.ExpiresOn)
  10928. {
  10929. $expiry = [System.DateTime]::Parse($decodedLicense.ExpiresOn, $null, 'AdjustToUniversal')
  10930. }
  10931. Else
  10932. {
  10933. $expiry = New-Object System.DateTime
  10934. }
  10935. $licenseState = "Grace"
  10936. If ((Get-Date) -Gt (Get-Date $decodedLicense.Metadata.NotAfter))
  10937. {
  10938. $licenseState = "RFM"
  10939. }
  10940. ElseIf ((Get-Date) -Lt (Get-Date $expiry))
  10941. {
  10942. $licenseState = "Licensed"
  10943. }
  10944. $output = New-Object PSObject
  10945. $output | Add-Member 8 'File' $_.PSChildName;
  10946. $output | Add-Member 8 'Version' $_.Directory.Name;
  10947. $output | Add-Member 8 'Type' "User|${licenseType}";
  10948. $output | Add-Member 8 'Product' $decodedLicense.ProductReleaseId;
  10949. $output | Add-Member 8 'Acid' $decodedLicense.Acid;
  10950. If ($mode -Eq "Device") { $output | Add-Member 8 'DeviceId' $decodedLicense.Metadata.DeviceId; }
  10951. $output | Add-Member 8 'LicenseState' $licenseState;
  10952. $output | Add-Member 8 'EntitlementStatus' $decodedLicense.Status;
  10953. $output | Add-Member 8 'EntitlementExpiration' ("N/A", $decodedLicense.ExpiresOn)[!($null -eq $decodedLicense.ExpiresOn)];
  10954. $output | Add-Member 8 'ReasonCode' ("N/A", $decodedLicense.ReasonCode)[!($null -eq $decodedLicense.ReasonCode)];
  10955. $output | Add-Member 8 'NotBefore' $decodedLicense.Metadata.NotBefore;
  10956. $output | Add-Member 8 'NotAfter' $decodedLicense.Metadata.NotAfter;
  10957. $output | Add-Member 8 'NextRenewal' $decodedLicense.Metadata.RenewAfter;
  10958. $output | Add-Member 8 'TenantId' ("N/A", $decodedLicense.Metadata.TenantId)[!($null -eq $decodedLicense.Metadata.TenantId)];
  10959. #$output.PSObject.Properties | foreach { $ht = @{} } { $ht[$_.Name] = $_.Value } { $output = $ht | ConvertTo-Json }
  10960. Write-Output $output
  10961. }
  10962. }
  10963. function vNextDiagRun
  10964. {
  10965. $fNUL = ([IO.Directory]::Exists("${env:LOCALAPPDATA}\Microsoft\Office\Licenses")) -and ([IO.Directory]::GetFiles("${env:LOCALAPPDATA}\Microsoft\Office\Licenses", "*", 1).Length -GE 0)
  10966. $fDev = ([IO.Directory]::Exists("${env:PROGRAMDATA}\Microsoft\Office\Licenses")) -and ([IO.Directory]::GetFiles("${env:PROGRAMDATA}\Microsoft\Office\Licenses", "*", 1).Length -GE 0)
  10967. $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"})
  10968. $rSCA = $null -NE (GP "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration" -EA 0 | select -Expand "SharedComputerLicensing" -EA 0)
  10969. $rSCL = $null -NE (GP "HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing" -EA 0 | select -Expand "SharedComputerLicensing" -EA 0)
  10970. if (($fNUL -Or $fDev -Or $rPID -Or $rSCA -Or $rSCL) -EQ $false) {
  10971. Return
  10972. }
  10973. & $isAll
  10974. CONOUT "$line2"
  10975. CONOUT "=== Office vNext Status ==="
  10976. CONOUT "$line2"
  10977. CONOUT "`n========== Mode per ProductReleaseId =========="
  10978. PrintModePerPridFromRegistry
  10979. CONOUT "`n========== Shared Computer Licensing =========="
  10980. PrintSharedComputerLicensing
  10981. CONOUT "`n========== vNext licenses ==========="
  10982. PrintLicensesInformation -Mode "NUL"
  10983. CONOUT "`n========== Device licenses =========="
  10984. PrintLicensesInformation -Mode "Device"
  10985. CONOUT "$line3"
  10986. CONOUT "`r"
  10987. }
  10988. #endregion
  10989. #region clic
  10990. <#
  10991. ;;; Source: https://github.com/asdcorp/clic
  10992. ;;; Powershell port: abbodi1406
  10993. Copyright 2023 asdcorp
  10994. Permission is hereby granted, free of charge, to any person obtaining a copy of
  10995. this software and associated documentation files (the "Software"), to deal in
  10996. the Software without restriction, including without limitation the rights to
  10997. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10998. the Software, and to permit persons to whom the Software is furnished to do so,
  10999. subject to the following conditions:
  11000. The above copyright notice and this permission notice shall be included in all
  11001. copies or substantial portions of the Software.
  11002. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11003. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  11004. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  11005. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  11006. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  11007. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  11008. #>
  11009. function BoolToWStr($bVal) {
  11010. ("TRUE", "FALSE")[!$bVal]
  11011. }
  11012. function InitializePInvoke {
  11013. $Marshal = [System.Runtime.InteropServices.Marshal]
  11014. $Module = [AppDomain]::CurrentDomain.DefineDynamicAssembly((Get-Random), 'Run').DefineDynamicModule((Get-Random))
  11015. $Class = $Module.DefineType('NativeMethods', 'Public, Abstract, Sealed, BeforeFieldInit', [Object], 0)
  11016. $Class.DefinePInvokeMethod('SLIsWindowsGenuineLocal', 'slc.dll', 'Public, Static', 'Standard', [Int32], @([UInt32].MakeByRefType()), 'Winapi', 'Unicode').SetImplementationFlags('PreserveSig')
  11017. $Class.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 22, 1, [Int32], @([String], [UInt32].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  11018. $Class.DefinePInvokeMethod('SLGetWindowsInformation', 'slc.dll', 22, 1, [Int32], @([String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  11019. if ($DllSubscription) {
  11020. $Class.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  11021. $Struct = $Class.DefineNestedType('SubStatus', 'NestedPublic, SequentialLayout, Sealed, BeforeFieldInit', [ValueType], 0)
  11022. [void]$Struct.DefineField('dwEnabled', [UInt32], 'Public')
  11023. [void]$Struct.DefineField('dwSku', [UInt32], 6)
  11024. [void]$Struct.DefineField('dwState', [UInt32], 6)
  11025. $SubStatus = $Struct.CreateType()
  11026. }
  11027. $Win32 = $Class.CreateType()
  11028. }
  11029. function InitializeDigitalLicenseCheck {
  11030. $CAB = [System.Reflection.Emit.CustomAttributeBuilder]
  11031. $ICom = $Module.DefineType('EUM.IEUM', 'Public, Interface, Abstract, Import')
  11032. $ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.ComImportAttribute].GetConstructor(@()), @()))
  11033. $ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.GuidAttribute].GetConstructor(@([String])), @('F2DCB80D-0670-44BC-9002-CD18688730AF')))
  11034. $ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.InterfaceTypeAttribute].GetConstructor(@([Int16])), @([Int16]1)))
  11035. 1..4 | % { [void]$ICom.DefineMethod('VF'+$_, 'Public, Virtual, HideBySig, NewSlot, Abstract', 'Standard, HasThis', [Void], @()) }
  11036. [void]$ICom.DefineMethod('AcquireModernLicenseForWindows', 1478, 33, [Int32], @([Int32], [Int32].MakeByRefType()))
  11037. $IEUM = $ICom.CreateType()
  11038. }
  11039. function PrintStateData {
  11040. $pwszStateData = 0
  11041. $cbSize = 0
  11042. if ($Win32::SLGetWindowsInformation(
  11043. "Security-SPP-Action-StateData",
  11044. [ref]$null,
  11045. [ref]$cbSize,
  11046. [ref]$pwszStateData
  11047. )) {
  11048. return $FALSE
  11049. }
  11050. [string[]]$pwszStateString = $Marshal::PtrToStringUni($pwszStateData) -replace ";", "`n "
  11051. CONOUT (" $pwszStateString")
  11052. $Marshal::FreeHGlobal($pwszStateData)
  11053. return $TRUE
  11054. }
  11055. function PrintLastActivationHResult {
  11056. $pdwLastHResult = 0
  11057. $cbSize = 0
  11058. if ($Win32::SLGetWindowsInformation(
  11059. "Security-SPP-LastWindowsActivationHResult",
  11060. [ref]$null,
  11061. [ref]$cbSize,
  11062. [ref]$pdwLastHResult
  11063. )) {
  11064. return $FALSE
  11065. }
  11066. CONOUT (" LastActivationHResult=0x{0:x8}" -f $Marshal::ReadInt32($pdwLastHResult))
  11067. $Marshal::FreeHGlobal($pdwLastHResult)
  11068. return $TRUE
  11069. }
  11070. function PrintLastActivationTime {
  11071. $pdwLastTime = 0
  11072. $cbSize = 0
  11073. if ($Win32::SLGetWindowsInformation(
  11074. "Security-SPP-LastWindowsActivationTime",
  11075. [ref]$null,
  11076. [ref]$cbSize,
  11077. [ref]$pdwLastTime
  11078. )) {
  11079. return $FALSE
  11080. }
  11081. $actTime = $Marshal::ReadInt64($pdwLastTime)
  11082. if ($actTime -ne 0) {
  11083. CONOUT (" LastActivationTime={0}" -f [DateTime]::FromFileTimeUtc($actTime).ToString("yyyy/MM/dd:HH:mm:ss"))
  11084. }
  11085. $Marshal::FreeHGlobal($pdwLastTime)
  11086. return $TRUE
  11087. }
  11088. function PrintIsWindowsGenuine {
  11089. $dwGenuine = 0
  11090. $ppwszGenuineStates = @(
  11091. "SL_GEN_STATE_IS_GENUINE",
  11092. "SL_GEN_STATE_INVALID_LICENSE",
  11093. "SL_GEN_STATE_TAMPERED",
  11094. "SL_GEN_STATE_OFFLINE",
  11095. "SL_GEN_STATE_LAST"
  11096. )
  11097. if ($Win32::SLIsWindowsGenuineLocal([ref]$dwGenuine)) {
  11098. return $FALSE
  11099. }
  11100. if ($dwGenuine -lt 5) {
  11101. CONOUT (" IsWindowsGenuine={0}" -f $ppwszGenuineStates[$dwGenuine])
  11102. } else {
  11103. CONOUT (" IsWindowsGenuine={0}" -f $dwGenuine)
  11104. }
  11105. return $TRUE
  11106. }
  11107. function PrintDigitalLicenseStatus {
  11108. try {
  11109. . InitializeDigitalLicenseCheck
  11110. $ComObj = New-Object -Com EditionUpgradeManagerObj.EditionUpgradeManager
  11111. } catch {
  11112. return $FALSE
  11113. }
  11114. $parameters = 1, $null
  11115. if ([EUM.IEUM].GetMethod("AcquireModernLicenseForWindows").Invoke($ComObj, $parameters)) {
  11116. return $FALSE
  11117. }
  11118. $dwReturnCode = $parameters[1]
  11119. [bool]$bDigitalLicense = $FALSE
  11120. $bDigitalLicense = (($dwReturnCode -ge 0) -and ($dwReturnCode -ne 1))
  11121. CONOUT (" IsDigitalLicense={0}" -f (BoolToWStr $bDigitalLicense))
  11122. return $TRUE
  11123. }
  11124. function PrintSubscriptionStatus {
  11125. $dwSupported = 0
  11126. if ($winbuild -ge 15063) {
  11127. $pwszPolicy = "ConsumeAddonPolicySet"
  11128. } else {
  11129. $pwszPolicy = "Allow-WindowsSubscription"
  11130. }
  11131. if ($Win32::SLGetWindowsInformationDWORD($pwszPolicy, [ref]$dwSupported)) {
  11132. return $FALSE
  11133. }
  11134. CONOUT (" SubscriptionSupportedEdition={0}" -f (BoolToWStr $dwSupported))
  11135. $pStatus = $Marshal::AllocHGlobal($Marshal::SizeOf([Type]$SubStatus))
  11136. if ($Win32::ClipGetSubscriptionStatus([ref]$pStatus)) {
  11137. return $FALSE
  11138. }
  11139. $sStatus = [Activator]::CreateInstance($SubStatus)
  11140. $sStatus = $Marshal::PtrToStructure($pStatus, [Type]$SubStatus)
  11141. $Marshal::FreeHGlobal($pStatus)
  11142. CONOUT (" SubscriptionEnabled={0}" -f (BoolToWStr $sStatus.dwEnabled))
  11143. if ($sStatus.dwEnabled -eq 0) {
  11144. return $TRUE
  11145. }
  11146. CONOUT (" SubscriptionSku={0}" -f $sStatus.dwSku)
  11147. CONOUT (" SubscriptionState={0}" -f $sStatus.dwState)
  11148. return $TRUE
  11149. }
  11150. function ClicRun
  11151. {
  11152. & $isAll
  11153. CONOUT "Client Licensing Check information:"
  11154. $null = PrintStateData
  11155. $null = PrintLastActivationHResult
  11156. $null = PrintLastActivationTime
  11157. $null = PrintIsWindowsGenuine
  11158. if ($DllDigital) {
  11159. $null = PrintDigitalLicenseStatus
  11160. }
  11161. if ($DllSubscription) {
  11162. $null = PrintSubscriptionStatus
  11163. }
  11164. CONOUT "$line3"
  11165. & $noAll
  11166. }
  11167. #endregion
  11168. $Host.UI.RawUI.WindowTitle = "Check Activation Status"
  11169. if ($All.IsPresent) {
  11170. $B=$Host.UI.RawUI.BufferSize;$B.Height=3000;$Host.UI.RawUI.BufferSize=$B;
  11171. if (!$Pass.IsPresent) {clear;}
  11172. }
  11173. $SysPath = "$env:SystemRoot\System32"
  11174. if (Test-Path "$env:SystemRoot\Sysnative\reg.exe") {
  11175. $SysPath = "$env:SystemRoot\Sysnative"
  11176. }
  11177. $wslp = "SoftwareLicensingProduct"
  11178. $wsls = "SoftwareLicensingService"
  11179. $oslp = "OfficeSoftwareProtectionProduct"
  11180. $osls = "OfficeSoftwareProtectionService"
  11181. $winApp = "55c92734-d682-4d71-983e-d6ec3f16059f"
  11182. $o14App = "59a52881-a989-479d-af46-f275c6370663"
  11183. $o15App = "0ff1ce15-a989-479d-af46-f275c6370663"
  11184. $cSub = ($winbuild -GE 19041) -And (Select-String -Path "$SysPath\wbem\sppwmi.mof" -Encoding unicode -Pattern "SubscriptionType")
  11185. $DllDigital = ($winbuild -GE 14393) -And (Test-Path "$SysPath\EditionUpgradeManagerObj.dll")
  11186. $DllSubscription = ($winbuild -GE 14393) -And (Test-Path "$SysPath\Clipc.dll")
  11187. $VLActTypes = @("All", "AD", "KMS", "Token")
  11188. $SLKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SL"
  11189. $NSKeyPath = "HKEY_USERS\S-1-5-20\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SL"
  11190. 'cW1nd0ws', 'c0ff1ce15', 'c0ff1ce14', 'ospp14', 'ospp15' | foreach {set $_ $false}
  11191. $offsvc = "osppsvc"
  11192. if ($NT7 -Or -Not $NT6) {$winsvc = "sppsvc"} else {$winsvc = "slsvc"}
  11193. try {gsv $winsvc -EA 1 | Out-Null; $WsppHook = 1} catch {$WsppHook = 0}
  11194. try {gsv $offsvc -EA 1 | Out-Null; $OsppHook = 1} catch {$OsppHook = 0}
  11195. if ($WsppHook -NE 0) {
  11196. try {sasv $winsvc -EA 1} catch {}
  11197. $cW1nd0ws = DetectID $wslp $winApp
  11198. $c0ff1ce15 = DetectID $wslp $o15App
  11199. $c0ff1ce14 = DetectID $wslp $o14App
  11200. }
  11201. if ($OsppHook -NE 0) {
  11202. try {sasv $offsvc -EA 1} catch {}
  11203. $ospp15 = DetectID $oslp $o15App
  11204. $ospp14 = DetectID $oslp $o14App
  11205. }
  11206. if ($cW1nd0ws)
  11207. {
  11208. echoWindows
  11209. GetID $wslp $winApp | foreach -EA 1 {
  11210. GetResult $wslp $wsls $_
  11211. CONOUT "$line3"
  11212. & $noAll
  11213. }
  11214. }
  11215. elseif ($NT6)
  11216. {
  11217. echoWindows
  11218. CONOUT "`nError: product key not found."
  11219. }
  11220. if ($winbuild -GE 9200) {
  11221. . InitializePInvoke
  11222. ClicRun
  11223. }
  11224. if ($c0ff1ce15 -Or $ospp15) {
  11225. CheckOhook
  11226. }
  11227. $doMSG = 1
  11228. if ($c0ff1ce15)
  11229. {
  11230. echoOffice
  11231. GetID $wslp $o15App | foreach -EA 1 {
  11232. GetResult $wslp $wsls $_
  11233. CONOUT "$line3"
  11234. & $noAll
  11235. }
  11236. }
  11237. if ($c0ff1ce14)
  11238. {
  11239. echoOffice
  11240. GetID $wslp $o14App | foreach -EA 1 {
  11241. GetResult $wslp $wsls $_
  11242. CONOUT "$line3"
  11243. & $noAll
  11244. }
  11245. }
  11246. if ($ospp15)
  11247. {
  11248. echoOffice
  11249. GetID $oslp $o15App | foreach -EA 1 {
  11250. GetResult $oslp $osls $_
  11251. CONOUT "$line3"
  11252. & $noAll
  11253. }
  11254. }
  11255. if ($ospp14)
  11256. {
  11257. echoOffice
  11258. GetID $oslp $o14App | foreach -EA 1 {
  11259. GetResult $oslp $osls $_
  11260. CONOUT "$line3"
  11261. & $noAll
  11262. }
  11263. }
  11264. if ($NT7) {
  11265. vNextDiagRun
  11266. }
  11267. ExitScript 0
  11268. :sppmgr:
  11269. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  11270. :troubleshoot
  11271. set "line=_________________________________________________________________________________________________"
  11272. :at_menu
  11273. cls
  11274. title Troubleshoot %masver%
  11275. if not defined terminal mode 77, 30
  11276. echo:
  11277. echo:
  11278. echo:
  11279. echo:
  11280. echo: _______________________________________________________________
  11281. echo:
  11282. call :dk_color2 %_White% " [1] " %_Green% "Help"
  11283. echo: ___________________________________________________
  11284. echo:
  11285. echo: [2] Dism RestoreHealth
  11286. echo: [3] SFC Scannow
  11287. echo:
  11288. echo: [4] Fix WMI
  11289. echo: [5] Fix Licensing
  11290. echo: [6] Fix WPA Registry
  11291. echo: ___________________________________________________
  11292. echo:
  11293. echo: [0] %_exitmsg%
  11294. echo: _______________________________________________________________
  11295. echo:
  11296. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard :"
  11297. choice /C:1234560 /N
  11298. set _erl=%errorlevel%
  11299. if %_erl%==7 exit /b
  11300. if %_erl%==6 start %mas%fix-wpa-registry &goto at_menu
  11301. if %_erl%==5 goto:retokens
  11302. if %_erl%==4 goto:fixwmi
  11303. if %_erl%==3 goto:sfcscan
  11304. if %_erl%==2 goto:dism_rest
  11305. if %_erl%==1 start %mas%troubleshoot.html &goto at_menu
  11306. goto :at_menu
  11307. ::========================================================================================================================================
  11308. :dism_rest
  11309. cls
  11310. if not defined terminal mode 98, 30
  11311. title Dism /English /Online /Cleanup-Image /RestoreHealth
  11312. if %winbuild% LSS 9200 (
  11313. %eline%
  11314. echo Unsupported OS version detected.
  11315. echo This command only works on Windows 8/8.1/10/11 and their Server equivalents.
  11316. goto :at_back
  11317. )
  11318. set _int=
  11319. for %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (
  11320. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
  11321. )
  11322. echo:
  11323. if defined _int (
  11324. echo Checking Internet Connection [Connected]
  11325. ) else (
  11326. call :dk_color2 %_White% " " %Red% "Checking Internet Connection [Not connected]"
  11327. )
  11328. echo %line%
  11329. echo:
  11330. echo DISM uses Windows Update to provide replacement files required to fix corruption.
  11331. echo This will take 5-15 minutes or more..
  11332. echo %line%
  11333. echo:
  11334. echo Notes:
  11335. echo:
  11336. call :dk_color2 %_White% " - " %Gray% "Make sure the internet is connected."
  11337. call :dk_color2 %_White% " - " %Gray% "Make sure that Windows update is properly working."
  11338. echo:
  11339. echo %line%
  11340. echo:
  11341. choice /C:09 /N /M "> [9] Continue [0] Go back : "
  11342. if %errorlevel%==1 goto at_menu
  11343. cls
  11344. if not defined terminal mode 110, 30
  11345. for /f %%a in ('%psc% "(Get-Date).ToString('yyyyMMdd-HHmmssfff')"') do set _time=%%a
  11346. %psc% Stop-Service TrustedInstaller -force %nul%
  11347. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\backup_cbs_%_time%.log" %nul%
  11348. copy /y /b "%SystemRoot%\logs\DISM\dism.log" "%SystemRoot%\logs\DISM\backup_dism_%_time%.log" %nul%
  11349. del /f /q "%SystemRoot%\logs\cbs\cbs.log" %nul%
  11350. del /f /q "%SystemRoot%\logs\DISM\dism.log" %nul%
  11351. echo:
  11352. echo Applying the command...
  11353. echo dism /english /online /cleanup-image /restorehealth
  11354. dism /english /online /cleanup-image /restorehealth
  11355. timeout /t 5 %nul1%
  11356. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\cbs_%_time%.log" %nul%
  11357. copy /y /b "%SystemRoot%\logs\DISM\dism.log" "%SystemRoot%\logs\DISM\dism_%_time%.log" %nul%
  11358. if not exist "!desktop!\AT_Logs\" md "!desktop!\AT_Logs\" %nul%
  11359. call :compresslog cbs\cbs_%_time%.log AT_Logs\RHealth_CBS %nul%
  11360. call :compresslog DISM\dism_%_time%.log AT_Logs\RHealth_DISM %nul%
  11361. if not exist "!desktop!\AT_Logs\RHealth_CBS_%_time%.cab" (
  11362. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "!desktop!\AT_Logs\RHealth_CBS_%_time%.log" %nul%
  11363. )
  11364. if not exist "!desktop!\AT_Logs\RHealth_DISM_%_time%.cab" (
  11365. copy /y /b "%SystemRoot%\logs\DISM\dism.log" "!desktop!\AT_Logs\RHealth_DISM_%_time%.log" %nul%
  11366. )
  11367. echo:
  11368. call :dk_color %Gray% "CBS and DISM logs are copied to the AT_Logs folder on your desktop."
  11369. goto :at_back
  11370. ::========================================================================================================================================
  11371. :sfcscan
  11372. cls
  11373. if not defined terminal mode 98, 30
  11374. title sfc /scannow
  11375. echo:
  11376. echo %line%
  11377. echo:
  11378. echo SFC will repair missing or corrupted system files.
  11379. echo It is recommended you run the DISM option first before this one.
  11380. echo This will take 10-15 minutes or more..
  11381. echo:
  11382. echo If SFC could not fix something, then run the command again to see if it may be able
  11383. echo to the next time. Sometimes it may take running the sfc /scannow command 3 times
  11384. echo restarting the PC after each time to completely fix everything that it's able to.
  11385. echo:
  11386. echo %line%
  11387. echo:
  11388. choice /C:09 /N /M "> [9] Continue [0] Go back : "
  11389. if %errorlevel%==1 goto at_menu
  11390. cls
  11391. for /f %%a in ('%psc% "(Get-Date).ToString('yyyyMMdd-HHmmssfff')"') do set _time=%%a
  11392. %psc% Stop-Service TrustedInstaller -force %nul%
  11393. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\backup_cbs_%_time%.log" %nul%
  11394. del /f /q "%SystemRoot%\logs\cbs\cbs.log" %nul%
  11395. echo:
  11396. echo Applying the command...
  11397. echo sfc /scannow
  11398. sfc /scannow
  11399. timeout /t 5 %nul1%
  11400. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\cbs_%_time%.log" %nul%
  11401. if not exist "!desktop!\AT_Logs\" md "!desktop!\AT_Logs\" %nul%
  11402. call :compresslog cbs\cbs_%_time%.log AT_Logs\SFC_CBS %nul%
  11403. if not exist "!desktop!\AT_Logs\SFC_CBS_%_time%.cab" (
  11404. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "!desktop!\AT_Logs\SFC_CBS_%_time%.log" %nul%
  11405. )
  11406. echo:
  11407. call :dk_color %Gray% "The CBS log was copied to the AT_Logs folder on your Desktop."
  11408. goto :at_back
  11409. ::========================================================================================================================================
  11410. :retokens
  11411. cls
  11412. if not defined terminal (
  11413. mode 125, 32
  11414. %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%
  11415. )
  11416. title Fix Licensing ^(ClipSVC ^+ SPP ^+ OSPP^)
  11417. echo:
  11418. echo %line%
  11419. echo:
  11420. echo Notes:
  11421. echo:
  11422. echo - This option helps in troubleshooting activation issues.
  11423. echo:
  11424. echo - This option will:
  11425. echo - Deactivate Windows and Office, you may need to reactivate.
  11426. echo If Windows is activated with motherboard / OEM / Digital license
  11427. echo then Windows will activate itself again.
  11428. echo:
  11429. echo - Clear ClipSVC, SPP and OSPP licenses.
  11430. echo - Fix permissions of SPP tokens folder and registries.
  11431. echo - Trigger the repair option for Office.
  11432. echo:
  11433. call :dk_color2 %_White% " - " %Red% "Apply this option only when it is necessary."
  11434. echo:
  11435. echo %line%
  11436. echo:
  11437. choice /C:09 /N /M "> [9] Continue [0] Go back : "
  11438. if %errorlevel%==1 goto at_menu
  11439. ::========================================================================================================================================
  11440. :: Rebuild ClipSVC Licences
  11441. cls
  11442. :cleanlicensing
  11443. echo:
  11444. echo %line%
  11445. echo:
  11446. call :dk_color %Blue% "Rebuilding ClipSVC Licenses..."
  11447. echo:
  11448. if %winbuild% LSS 10240 (
  11449. echo ClipSVC license rebuilding is supported only on Windows 10/11 and their Server equivalents.
  11450. echo Skipping...
  11451. goto :rebuildspptok
  11452. )
  11453. %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% && (
  11454. echo Windows is permanently activated.
  11455. echo Skipping...
  11456. goto :rebuildspptok
  11457. )
  11458. echo Stopping ClipSVC service...
  11459. %psc% Stop-Service ClipSVC -force %nul%
  11460. timeout /t 2 %nul%
  11461. echo:
  11462. echo Applying the command to clean ClipSVC Licenses...
  11463. echo rundll32 clipc.dll,ClipCleanUpState
  11464. rundll32 clipc.dll,ClipCleanUpState
  11465. if %winbuild% LEQ 10240 (
  11466. echo [Successful]
  11467. ) else (
  11468. if exist "%ProgramData%\Microsoft\Windows\ClipSVC\tokens.dat" (
  11469. call :dk_color %Red% "[Failed]"
  11470. ) else (
  11471. echo [Successful]
  11472. )
  11473. )
  11474. :: Below registry key (Volatile & Protected) gets created after the ClipSVC License cleanup command, and gets automatically deleted after
  11475. :: system restart. It needs to be deleted to activate the system without restart.
  11476. set "RegKey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ClipSVC\Volatile\PersistedSystemState"
  11477. set "_ident=HKU\S-1-5-19\SOFTWARE\Microsoft\IdentityCRL"
  11478. reg query "%RegKey%" %nul% && %nul% call :regownstart
  11479. reg delete "%RegKey%" /f %nul%
  11480. echo:
  11481. echo Deleting a Volatile ^& Protected Registry Key...
  11482. echo [%RegKey%]
  11483. reg query "%RegKey%" %nul% && (
  11484. call :dk_color %Red% "[Failed]"
  11485. echo Reboot your machine using the restart option, that will delete this registry key automatically.
  11486. ) || (
  11487. echo [Successful]
  11488. )
  11489. :: Clear HWID token related registry to fix activation incase there is any corruption
  11490. echo:
  11491. echo Deleting IdentityCRL Registry Key...
  11492. echo [%_ident%]
  11493. reg delete "%_ident%" /f %nul%
  11494. reg query "%_ident%" %nul% && (
  11495. call :dk_color %Red% "[Failed]"
  11496. ) || (
  11497. echo [Successful]
  11498. )
  11499. %psc% Stop-Service ClipSVC -force %nul%
  11500. :: Rebuild ClipSVC folder to fix permission issues
  11501. echo:
  11502. if %winbuild% GTR 10240 (
  11503. echo Deleting folder %ProgramData%\Microsoft\Windows\ClipSVC\
  11504. rmdir /s /q "C:\ProgramData\Microsoft\Windows\ClipSvc" %nul%
  11505. if exist "%ProgramData%\Microsoft\Windows\ClipSVC\" (
  11506. call :dk_color %Red% "[Failed]"
  11507. ) else (
  11508. echo [Successful]
  11509. )
  11510. echo:
  11511. echo Rebuilding the %ProgramData%\Microsoft\Windows\ClipSVC\ folder...
  11512. %psc% Start-Service ClipSVC %nul%
  11513. timeout /t 3 %nul%
  11514. if not exist "%ProgramData%\Microsoft\Windows\ClipSVC\" timeout /t 5 %nul%
  11515. if not exist "%ProgramData%\Microsoft\Windows\ClipSVC\" (
  11516. call :dk_color %Red% "[Failed]"
  11517. ) else (
  11518. echo [Successful]
  11519. )
  11520. )
  11521. echo:
  11522. echo Restarting wlidsvc ^& LicenseManager services...
  11523. for %%# in (wlidsvc LicenseManager) do (%psc% "Start-Job { Restart-Service %%# } | Wait-Job -Timeout 20 | Out-Null")
  11524. ::========================================================================================================================================
  11525. :: Rebuild SPP Tokens
  11526. :rebuildspptok
  11527. echo:
  11528. echo %line%
  11529. echo:
  11530. call :dk_color %Blue% "Rebuilding SPP licensing tokens..."
  11531. echo:
  11532. call :scandat check
  11533. if not defined token (
  11534. call :dk_color %Red% "tokens.dat file not found."
  11535. ) else (
  11536. echo tokens.dat file: [%token%]
  11537. )
  11538. set tokenstore=
  11539. set badregistry=
  11540. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v TokenStore %nul6%') do call set "tokenstore=%%b"
  11541. if %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" (
  11542. set badregistry=1
  11543. echo:
  11544. call :dk_color %Red% "Correct path not found in TokenStore Registry [%tokenstore%]"
  11545. )
  11546. :: Check sppsvc permissions and apply fixes
  11547. if %winbuild% GEQ 9200 if not defined badregistry (
  11548. echo:
  11549. echo Checking SPP permission related issues...
  11550. call :checkperms
  11551. if defined permerror (
  11552. call :dk_color %Red% "[!permerror!]"
  11553. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':fixsppperms\:.*';iex ($f[1])" %nul%
  11554. call :checkperms
  11555. if defined permerror (
  11556. call :dk_color %Red% "[!permerror!] [Failed To Fix]"
  11557. ) else (
  11558. call :dk_color %Green% "[Successfully Fixed]"
  11559. )
  11560. ) else (
  11561. echo [No Error Found]
  11562. )
  11563. )
  11564. echo:
  11565. echo Stopping sppsvc service...
  11566. %psc% Stop-Service sppsvc -force %nul%
  11567. set w=
  11568. set _sppint=
  11569. for %%# in (SppEx%w%tComObj.exe sppsvc.exe) do (reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ima%w%ge File Execu%w%tion Options\%%#" %nul% && (set _sppint=1))
  11570. if defined _sppint (
  11571. echo:
  11572. echo Removing SPP IFEO registry keys...
  11573. for %%# in (SppE%w%xtComObj.exe sppsvc.exe) do (reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ima%w%ge File Execu%w%tion Options\%%#" /f %nul%)
  11574. )
  11575. if %winbuild% LSS 9200 (
  11576. REM Fix issues caused by Update KB971033 in Windows 7
  11577. REM https://support.microsoft.com/help/4487266
  11578. echo:
  11579. echo Checking Update KB971033...
  11580. %psc% "if (Get-Hotfix -Id KB971033 -ErrorAction SilentlyContinue) {Exit 3}" %nul%
  11581. if !errorlevel!==3 (
  11582. echo Found, uninstalling it...
  11583. wusa /uninstall /quiet /norestart /kb:971033
  11584. ) else (
  11585. echo [Not Found]
  11586. )
  11587. %psc% Stop-Service sppuinotify -force %nul%
  11588. sc config sppuinotify start= disabled
  11589. del /f /q %SysPath%\7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0 /ah
  11590. )
  11591. :: Delete registry keys that are not deleted by activation scripts
  11592. echo:
  11593. echo Cleaning some licensing-related registry keys...
  11594. %nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "ServiceSessionId" /f
  11595. %nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "LicStatusArray" /f
  11596. %nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "PolicyValuesArray" /f
  11597. %nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "actionlist" /f
  11598. %nul% reg delete "HKLM\SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform\data" /f
  11599. echo:
  11600. call :scandat delete
  11601. call :scandat check
  11602. if defined token (
  11603. echo:
  11604. call :dk_color %Red% "Failed to delete .dat files."
  11605. echo:
  11606. )
  11607. echo:
  11608. echo Reinstalling system licenses...
  11609. %psc% "Stop-Service sppsvc -force; $sls = Get-WmiObject SoftwareLicensingService; $f=[io.file]::ReadAllText('!_batp!') -split ':xrm\:.*';iex ($f[1]); ReinstallLicenses" %nul%
  11610. if %errorlevel% NEQ 0 %psc% "$sls = Get-WmiObject SoftwareLicensingService; $f=[io.file]::ReadAllText('!_batp!') -split ':xrm\:.*';iex ($f[1]); ReinstallLicenses" %nul%
  11611. if %errorlevel% EQU 0 (
  11612. echo [Successful]
  11613. ) else (
  11614. call :dk_color %Red% "[Failed]"
  11615. )
  11616. call :scandat check
  11617. echo:
  11618. if not defined token (
  11619. call :dk_color %Red% "Failed to rebuild tokens.dat file."
  11620. ) else (
  11621. echo tokens.dat file was rebuilt successfully.
  11622. )
  11623. if %winbuild% LSS 9200 (
  11624. sc config sppuinotify start= demand
  11625. )
  11626. ::========================================================================================================================================
  11627. :: Rebuild OSPP Tokens
  11628. echo:
  11629. echo %line%
  11630. echo:
  11631. call :dk_color %Blue% "Rebuilding OSPP licensing tokens..."
  11632. echo:
  11633. sc qc osppsvc %nul% || (
  11634. echo OSPP-based Office is not installed.
  11635. echo Skipping rebuilding OSPP tokens...
  11636. goto :repairoffice
  11637. )
  11638. call :scandatospp check
  11639. if not defined token (
  11640. call :dk_color %Red% "tokens.dat file not found."
  11641. ) else (
  11642. echo tokens.dat file: [%token%]
  11643. )
  11644. echo:
  11645. echo Stopping osppsvc service...
  11646. %psc% Stop-Service osppsvc -force %nul%
  11647. echo:
  11648. call :scandatospp delete
  11649. call :scandatospp check
  11650. if defined token (
  11651. echo:
  11652. call :dk_color %Red% "Failed to delete .dat files."
  11653. echo:
  11654. )
  11655. echo:
  11656. echo Starting osppsvc service to generate tokens.dat...
  11657. %psc% Start-Service osppsvc %nul%
  11658. call :scandatospp check
  11659. if not defined token (
  11660. %psc% Stop-Service osppsvc -force %nul%
  11661. %psc% Start-Service osppsvc %nul%
  11662. timeout /t 3 %nul%
  11663. )
  11664. call :scandatospp check
  11665. echo:
  11666. if not defined token (
  11667. call :dk_color %Red% "Failed to rebuild tokens.dat file."
  11668. ) else (
  11669. echo tokens.dat file was rebuilt successfully.
  11670. )
  11671. ::========================================================================================================================================
  11672. :repairoffice
  11673. echo:
  11674. echo %line%
  11675. echo:
  11676. call :dk_color %Blue% "Repairing Office licenses..."
  11677. echo:
  11678. for %%# in (68 86) do (
  11679. for %%A in (msi14 msi15 msi16 c2r14 c2r15 c2r16) do (set %%A_%%#=&set %%Arepair%%#=)
  11680. )
  11681. set _68=HKLM\SOFTWARE\Microsoft\Office
  11682. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  11683. reg query %_68%\14.0\CVH /f Click2run /k %nul% && (set "c2r14_68=Office 14.0 C2R x86/x64" & set "c2r14repair68=")
  11684. reg query %_86%\14.0\CVH /f Click2run /k %nul% && (set "c2r14_86=Office 14.0 C2R x86" & set "c2r14repair86=")
  11685. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi14_86=Office 14.0 MSI x86" & call :getrepairsetup msi14repair86 14)
  11686. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi14_68=Office 14.0 MSI x86/x64" & call :getrepairsetup msi14repair68 14)
  11687. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi15_86=Office 15.0 MSI x86" & call :getrepairsetup msi15repair86 15)
  11688. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi15_68=Office 15.0 MSI x86/x64" & call :getrepairsetup msi15repair68 15)
  11689. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi16_86=Office 16.0 MSI x86" & call :getrepairsetup msi16repair86 16)
  11690. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi16_68=Office 16.0 MSI x86/x64" & call :getrepairsetup msi16repair68 16)
  11691. for /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)
  11692. for /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)
  11693. for /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 :getc2rrepair c2r16repair86 OfficeClickToRun.exe)
  11694. for /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 :getc2rrepair c2r16repair68 OfficeClickToRun.exe)
  11695. set uwp16=
  11696. if %winbuild% GEQ 10240 (
  11697. %psc% "Get-AppxPackage -name "Microsoft.Office.Desktop"" | find /i "Office" %nul1% && set uwp16=Office 16.0 UWP
  11698. )
  11699. set /a counter=0
  11700. echo Checking installed Office versions...
  11701. echo:
  11702. for %%# in (
  11703. "%msi14_68%"
  11704. "%msi14_86%"
  11705. "%msi15_68%"
  11706. "%msi15_86%"
  11707. "%msi16_68%"
  11708. "%msi16_86%"
  11709. "%c2r14_68%"
  11710. "%c2r14_86%"
  11711. "%c2r15_68%"
  11712. "%c2r15_86%"
  11713. "%c2r16_68%"
  11714. "%c2r16_86%"
  11715. "%uwp16%"
  11716. ) do (
  11717. if not "%%#"=="""" (
  11718. set insoff=%%#
  11719. set insoff=!insoff:"=!
  11720. echo [!insoff!]
  11721. set /a counter+=1
  11722. )
  11723. )
  11724. if %counter% GTR 1 (
  11725. %eline%
  11726. echo Multiple Office versions found.
  11727. echo It is recommended to only install one version of Office.
  11728. echo ________________________________________________________________
  11729. echo:
  11730. )
  11731. if %counter% EQU 0 (
  11732. echo:
  11733. echo Office ^(2010 and later^) is not installed.
  11734. goto :repairend
  11735. echo:
  11736. ) else (
  11737. echo:
  11738. call :dk_color %_Yellow% "A new window will appear, in that window you need to select [Quick Repair] option."
  11739. if defined terminal (
  11740. call :dk_color %_Yellow% "Press [0] to continue..."
  11741. choice /c 0 /n
  11742. ) else (
  11743. call :dk_color %_Yellow% "Press any key to continue..."
  11744. pause %nul1%
  11745. )
  11746. )
  11747. if defined uwp16 (
  11748. echo:
  11749. echo Skipping repair for Office 16.0 UWP...
  11750. echo:
  11751. )
  11752. set c2r14=
  11753. if defined c2r14_68 set c2r14=1
  11754. if defined c2r14_86 set c2r14=1
  11755. if defined c2r14 (
  11756. echo:
  11757. echo Skipping repair for Office 14.0 C2R...
  11758. echo:
  11759. )
  11760. if defined msi14_68 if exist "%msi14repair68%" echo Running - "%msi14repair68%" & "%msi14repair68%"
  11761. if defined msi14_86 if exist "%msi14repair86%" echo Running - "%msi14repair86%" & "%msi14repair86%"
  11762. if defined msi15_68 if exist "%msi15repair68%" echo Running - "%msi15repair68%" & "%msi15repair68%"
  11763. if defined msi15_86 if exist "%msi15repair86%" echo Running - "%msi15repair86%" & "%msi15repair86%"
  11764. if defined msi16_68 if exist "%msi16repair68%" echo Running - "%msi16repair68%" & "%msi16repair68%"
  11765. if defined msi16_86 if exist "%msi16repair86%" echo Running - "%msi16repair86%" & "%msi16repair86%"
  11766. if defined c2r15_68 if exist "%c2r15repair68%" echo Running - "%c2r15repair68%" REPAIRUI RERUNMODE & "%c2r15repair68%" REPAIRUI RERUNMODE
  11767. if defined c2r15_86 if exist "%c2r15repair86%" echo Running - "%c2r15repair86%" REPAIRUI RERUNMODE & "%c2r15repair86%" REPAIRUI RERUNMODE
  11768. if defined c2r16_68 if exist "%c2r16repair68%" echo Running - "%c2r16repair68%" scenario=Repair & "%c2r16repair68%" scenario=Repair
  11769. if defined c2r16_86 if exist "%c2r16repair86%" echo Running - "%c2r16repair86%" scenario=Repair & "%c2r16repair86%" scenario=Repair
  11770. :repairend
  11771. echo:
  11772. echo %line%
  11773. echo:
  11774. echo:
  11775. call :dk_color %Green% "Finished"
  11776. goto :at_back
  11777. :getc2rrepair
  11778. for %%# in (X86 X64) do (
  11779. if exist "%systemdrive%\Program Files\Microsoft Office 15\Client%%#\%2" (
  11780. set "%1=%systemdrive%\Program Files\Microsoft Office 15\Client%%#\%2"
  11781. )
  11782. )
  11783. exit /b
  11784. :getrepairsetup
  11785. set "_common86=%systemdrive%\Program Files (x86)\Common Files\Microsoft Shared\OFFICE%2\Office Setup Controller\setup.exe"
  11786. set "_common68=%systemdrive%\Program Files\Common Files\Microsoft Shared\OFFICE%2\Office Setup Controller\setup.exe"
  11787. if exist "%_common86%" set "%1=%_common86%"
  11788. if exist "%_common68%" set "%1=%_common68%"
  11789. exit /b
  11790. ::========================================================================================================================================
  11791. :fixwmi
  11792. cls
  11793. if not defined terminal mode 98, 34
  11794. title Fix WMI
  11795. :: https://techcommunity.microsoft.com/t5/ask-the-performance-team/wmi-repository-corruption-or-not/ba-p/375484
  11796. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
  11797. %eline%
  11798. echo Rebuilding WMI is not recommended on Windows Server, aborting...
  11799. goto :at_back
  11800. )
  11801. echo:
  11802. echo Checking WMI
  11803. call :checkwmi
  11804. :: Apply basic fix first and check
  11805. if defined error (
  11806. %psc% Stop-Service Winmgmt -force %nul%
  11807. winmgmt /salvagerepository %nul%
  11808. call :checkwmi
  11809. )
  11810. if not defined error (
  11811. echo [Working]
  11812. echo No need to apply this option, aborting...
  11813. goto :at_back
  11814. )
  11815. call :dk_color %Red% "[Not Responding]"
  11816. set _corrupt=
  11817. sc start Winmgmt %nul%
  11818. if %errorlevel% EQU 1060 set _corrupt=1
  11819. sc query Winmgmt %nul% || set _corrupt=1
  11820. for %%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)
  11821. echo:
  11822. if defined _corrupt (
  11823. %eline%
  11824. echo Winmgmt service is corrupted, aborting...
  11825. goto :at_back
  11826. )
  11827. echo Disabling Winmgmt service
  11828. sc config Winmgmt start= disabled %nul%
  11829. if %errorlevel% EQU 0 (
  11830. echo [Successful]
  11831. ) else (
  11832. call :dk_color %Red% "[Failed] Aborting..."
  11833. sc config Winmgmt start= auto %nul%
  11834. goto :at_back
  11835. )
  11836. echo:
  11837. echo Stopping Winmgmt service
  11838. %psc% Stop-Service Winmgmt -force %nul%
  11839. %psc% Stop-Service Winmgmt -force %nul%
  11840. %psc% Stop-Service Winmgmt -force %nul%
  11841. sc query Winmgmt | find /i "STOPPED" %nul% && (
  11842. echo [Successful]
  11843. ) || (
  11844. call :dk_color %Red% "[Failed]"
  11845. echo:
  11846. call :dk_color %Blue% "Its recommended to select [Restart] option and then apply Fix WMI option again."
  11847. echo %line%
  11848. echo:
  11849. choice /C:21 /N /M "> [1] Restart [2] Revert Back Changes :"
  11850. if !errorlevel!==1 (sc config Winmgmt start= auto %nul%&goto :at_back)
  11851. echo:
  11852. echo Restarting...
  11853. shutdown -t 5 -r
  11854. exit
  11855. )
  11856. echo:
  11857. echo Deleting WMI repository
  11858. rmdir /s /q "%SysPath%\wbem\repository\" %nul%
  11859. if exist "%SysPath%\wbem\repository\" (
  11860. call :dk_color %Red% "[Failed]"
  11861. ) else (
  11862. echo [Successful]
  11863. )
  11864. echo:
  11865. echo Enabling Winmgmt service
  11866. sc config Winmgmt start= auto %nul%
  11867. if %errorlevel% EQU 0 (
  11868. echo [Successful]
  11869. ) else (
  11870. call :dk_color %Red% "[Failed]"
  11871. )
  11872. call :checkwmi
  11873. if not defined error (
  11874. echo:
  11875. echo Checking WMI
  11876. call :dk_color %Green% "[Working]"
  11877. goto :at_back
  11878. )
  11879. echo:
  11880. echo Registering .dll's and Compiling .mof's, .mfl's
  11881. call :registerobj %nul%
  11882. echo:
  11883. echo Checking WMI
  11884. call :checkwmi
  11885. if defined error (
  11886. call :dk_color %Red% "[Not Responding]"
  11887. echo:
  11888. echo Run [Dism RestoreHealth] and [SFC Scannow] options and make sure there are no errors.
  11889. ) else (
  11890. call :dk_color %Green% "[Working]"
  11891. )
  11892. goto :at_back
  11893. :registerobj
  11894. :: https://eskonr.com/2012/01/how-to-fix-wmi-issues-automatically/
  11895. %psc% Stop-Service Winmgmt -force %nul%
  11896. cd /d %SysPath%\wbem\
  11897. regsvr32 /s %SysPath%\scecli.dll
  11898. regsvr32 /s %SysPath%\userenv.dll
  11899. mofcomp cimwin32.mof
  11900. mofcomp cimwin32.mfl
  11901. mofcomp rsop.mof
  11902. mofcomp rsop.mfl
  11903. for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s
  11904. for /f %%s in ('dir /b *.mof') do mofcomp %%s
  11905. for /f %%s in ('dir /b *.mfl') do mofcomp %%s
  11906. winmgmt /salvagerepository
  11907. winmgmt /resetrepository
  11908. exit /b
  11909. :checkwmi
  11910. :: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants
  11911. set error=
  11912. %psc% "Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName" %nul2% | find /i "computersystem" %nul1%
  11913. if %errorlevel% NEQ 0 (set error=1& exit /b)
  11914. winmgmt /verifyrepository %nul%
  11915. if %errorlevel% NEQ 0 (set error=1& exit /b)
  11916. %psc% "try { $null=([WMISEARCHER]'SELECT * FROM SoftwareLicensingService').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
  11917. cmd /c exit /b %errorlevel%
  11918. echo "0x%=ExitCode%" | findstr /i "0x800410 0x800440 0x80131501" %nul1%
  11919. if %errorlevel% EQU 0 set error=1
  11920. exit /b
  11921. ::========================================================================================================================================
  11922. :at_back
  11923. echo:
  11924. echo %line%
  11925. echo:
  11926. if defined terminal (
  11927. call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
  11928. choice /c 0 /n
  11929. ) else (
  11930. call :dk_color %_Yellow% "Press any key to %_exitmsg%..."
  11931. pause %nul1%
  11932. )
  11933. goto :at_menu
  11934. ::========================================================================================================================================
  11935. :compresslog
  11936. :: https://stackoverflow.com/a/46268232
  11937. set "ddf="%SystemRoot%\Temp\ddf""
  11938. %nul% del /q /f %ddf%
  11939. echo/.New Cabinet>%ddf%
  11940. echo/.set Cabinet=ON>>%ddf%
  11941. echo/.set CabinetFileCountThreshold=0;>>%ddf%
  11942. echo/.set Compress=ON>>%ddf%
  11943. echo/.set CompressionType=LZX>>%ddf%
  11944. echo/.set CompressionLevel=7;>>%ddf%
  11945. echo/.set CompressionMemory=21;>>%ddf%
  11946. echo/.set FolderFileCountThreshold=0;>>%ddf%
  11947. echo/.set FolderSizeThreshold=0;>>%ddf%
  11948. echo/.set GenerateInf=OFF>>%ddf%
  11949. echo/.set InfFileName=nul>>%ddf%
  11950. echo/.set MaxCabinetSize=0;>>%ddf%
  11951. echo/.set MaxDiskFileCount=0;>>%ddf%
  11952. echo/.set MaxDiskSize=0;>>%ddf%
  11953. echo/.set MaxErrors=1;>>%ddf%
  11954. echo/.set RptFileName=nul>>%ddf%
  11955. echo/.set UniqueFiles=ON>>%ddf%
  11956. for /f "tokens=* delims=" %%D in ('dir /a:-D/b/s "%SystemRoot%\logs\%1"') do (
  11957. echo/"%%~fD" /inf=no;>>%ddf%
  11958. )
  11959. makecab /F %ddf% /D DiskDirectory1="" /D CabinetNameTemplate="!desktop!\%2_%_time%.cab"
  11960. del /q /f %ddf%
  11961. exit /b
  11962. ::========================================================================================================================================
  11963. :checkperms
  11964. :: This code checks if SPP has permission access to tokens folder and required registry keys. Incorrect permissions are often set by gaming spoofers.
  11965. set permerror=
  11966. if not exist "%tokenstore%\" set "permerror=Error Found In Token Folder"
  11967. if defined ps32onArm exit /b
  11968. for %%# in (
  11969. "%tokenstore%+FullControl"
  11970. "HKLM:\SYSTEM\WPA+QueryValues, EnumerateSubKeys, WriteKey"
  11971. "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform+SetValue"
  11972. ) do for /f "tokens=1,2 delims=+" %%A in (%%#) do if not defined permerror (
  11973. %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%
  11974. if !errorlevel!==2 (
  11975. if "%%A"=="%tokenstore%" (
  11976. set "permerror=Error Found In Token Folder"
  11977. ) else (
  11978. set "permerror=Error Found In SPP Registries"
  11979. )
  11980. )
  11981. )
  11982. REM https://learn.microsoft.com/office/troubleshoot/activation/license-issue-when-start-office-application
  11983. if not defined permerror (
  11984. reg query "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion" %nul% && (
  11985. set "pol=HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Policies"
  11986. reg query "!pol!" %nul% || reg add "!pol!" %nul%
  11987. %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%
  11988. if !errorlevel!==3 set "permerror=Error Found In S-1-5-20 SPP"
  11989. )
  11990. )
  11991. exit /b
  11992. ::========================================================================================================================================
  11993. :: Fix SPP related registry and folder permissions
  11994. :fixsppperms:
  11995. # Fix perms for Token Folder
  11996. if ($env:permerror -eq 'Error Found In Token Folder') {
  11997. New-Item -Path $env:tokenstore -ItemType Directory -Force
  11998. $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)'
  11999. $AclObject = New-Object System.Security.AccessControl.DirectorySecurity
  12000. $AclObject.SetSecurityDescriptorSddlForm($sddl)
  12001. Set-Acl -Path $env:tokenstore -AclObject $AclObject
  12002. exit
  12003. }
  12004. # Fix perms for SPP registries
  12005. if ($env:permerror -eq 'Error Found In SPP Registries') {
  12006. $acl = Get-Acl 'HKLM:\SYSTEM\WPA'
  12007. $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\sppsvc', 'QueryValues, EnumerateSubKeys, WriteKey', 'ContainerInherit, ObjectInherit', 'None', 'Allow')
  12008. $acl.ResetAccessRule($rule)
  12009. $acl.SetAccessRule($rule)
  12010. Set-Acl -Path 'HKLM:\SYSTEM\WPA' -AclObject $acl
  12011. $acl = Get-Acl 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform'
  12012. $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\sppsvc', 'SetValue', 'ContainerInherit, ObjectInherit', 'None', 'Allow')
  12013. $acl.ResetAccessRule($rule)
  12014. $acl.SetAccessRule($rule)
  12015. Set-Acl -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform' -AclObject $acl
  12016. exit
  12017. }
  12018. # Fix perms for SPP in HKU\S-1-5-20
  12019. # https://learn.microsoft.com/office/troubleshoot/activation/license-issue-when-start-office-application
  12020. if ($env:permerror -ne 'Error Found In S-1-5-20 SPP') {
  12021. exit
  12022. }
  12023. if (-not (Test-Path 'Registry::HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform')) {
  12024. exit
  12025. }
  12026. # https://stackoverflow.com/a/35843420
  12027. function Take-Permissions {
  12028. param($rootKey, $key, [System.Security.Principal.SecurityIdentifier]$sid = 'S-1-5-32-545', $recurse = $true)
  12029. switch -regex ($rootKey) {
  12030. 'HKCU|HKEY_CURRENT_USER' { $rootKey = 'CurrentUser' }
  12031. 'HKLM|HKEY_LOCAL_MACHINE' { $rootKey = 'LocalMachine' }
  12032. 'HKCR|HKEY_CLASSES_ROOT' { $rootKey = 'ClassesRoot' }
  12033. 'HKCC|HKEY_CURRENT_CONFIG' { $rootKey = 'CurrentConfig' }
  12034. 'HKU|HKEY_USERS' { $rootKey = 'Users' }
  12035. }
  12036. ### Step 1 - escalate current process's privilege
  12037. # get SeTakeOwnership, SeBackup and SeRestore privileges before executes next lines, script needs Admin privilege
  12038. $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)
  12039. $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)
  12040. $TypeBuilder = $ModuleBuilder.DefineType(0)
  12041. $TypeBuilder.DefinePInvokeMethod('RtlAdjustPrivilege', 'ntdll.dll', 'Public, Static', 1, [int], @([int], [bool], [bool], [bool].MakeByRefType()), 1, 3) | Out-Null
  12042. 9, 17, 18 | ForEach-Object { $TypeBuilder.CreateType()::RtlAdjustPrivilege($_, $true, $false, [ref]$false) | Out-Null }
  12043. function Take-KeyPermissions {
  12044. param($rootKey, $key, $sid, $recurse, $recurseLevel = 0)
  12045. ### Step 2 - get ownerships of key - it works only for current key
  12046. $regKey = [Microsoft.Win32.Registry]::$rootKey.OpenSubKey($key, 'ReadWriteSubTree', 'TakeOwnership')
  12047. $acl = New-Object System.Security.AccessControl.RegistrySecurity
  12048. $acl.SetOwner($sid)
  12049. $regKey.SetAccessControl($acl)
  12050. ### Step 3 - enable inheritance of permissions (not ownership) for current key from parent
  12051. $acl.SetAccessRuleProtection($false, $false)
  12052. $regKey.SetAccessControl($acl)
  12053. ### Step 4 - only for top-level key, change permissions for current key and propagate it for subkeys
  12054. # to enable propagations for subkeys, it needs to execute Steps 2-3 for each subkey (Step 5)
  12055. if ($recurseLevel -eq 0) {
  12056. $regKey = $regKey.OpenSubKey('', 'ReadWriteSubTree', 'ChangePermissions')
  12057. $rule = New-Object System.Security.AccessControl.RegistryAccessRule($sid, 'FullControl', 'ContainerInherit', 'None', 'Allow')
  12058. $acl.ResetAccessRule($rule)
  12059. $regKey.SetAccessControl($acl)
  12060. }
  12061. ### Step 5 - recursively repeat steps 2-5 for subkeys
  12062. if ($recurse) {
  12063. foreach ($subKey in $regKey.OpenSubKey('').GetSubKeyNames()) {
  12064. Take-KeyPermissions $rootKey ($key + '\' + $subKey) $sid $recurse ($recurseLevel + 1)
  12065. }
  12066. }
  12067. }
  12068. Take-KeyPermissions $rootKey $key $sid $recurse
  12069. }
  12070. Take-Permissions "Users" "S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" "S-1-5-20"
  12071. :fixsppperms:
  12072. ::========================================================================================================================================
  12073. :scandat
  12074. set token=
  12075. for %%# in (
  12076. %SysPath%\spp\store_test\2.0\
  12077. %SysPath%\spp\store\
  12078. %SysPath%\spp\store\2.0\
  12079. %Systemdrive%\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\
  12080. ) do (
  12081. if %1==check (
  12082. if exist %%#tokens.dat set token=%%#tokens.dat
  12083. )
  12084. if %1==delete (
  12085. if exist %%# (
  12086. %nul% dir /a-d /s "%%#*.dat" && (
  12087. attrib -r -s -h "%%#*.dat" /S
  12088. del /S /F /Q "%%#*.dat"
  12089. )
  12090. )
  12091. )
  12092. )
  12093. exit /b
  12094. :scandatospp
  12095. set token=
  12096. for %%# in (
  12097. %ProgramData%\Microsoft\OfficeSoftwareProtectionPlatform\
  12098. ) do (
  12099. if %1==check (
  12100. if exist %%#tokens.dat set token=%%#tokens.dat
  12101. )
  12102. if %1==delete (
  12103. if exist %%# (
  12104. %nul% dir /a-d /s "%%#*.dat" && (
  12105. attrib -r -s -h "%%#*.dat" /S
  12106. del /S /F /Q "%%#*.dat"
  12107. )
  12108. )
  12109. )
  12110. )
  12111. exit /b
  12112. ::========================================================================================================================================
  12113. :regownstart
  12114. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':regown\:.*';iex ($f[1]);"
  12115. exit /b
  12116. :: Below code takes ownership of a volatile registry key and deletes it
  12117. :: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ClipSVC\Volatile\PersistedSystemState
  12118. :regown:
  12119. $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)
  12120. $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)
  12121. $TypeBuilder = $ModuleBuilder.DefineType(0)
  12122. $TypeBuilder.DefinePInvokeMethod('RtlAdjustPrivilege', 'ntdll.dll', 'Public, Static', 1, [int], @([int], [bool], [bool], [bool].MakeByRefType()), 1, 3) | Out-Null
  12123. $TypeBuilder.CreateType()::RtlAdjustPrivilege(9, $true, $false, [ref]$false) | Out-Null
  12124. $SID = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544')
  12125. $IDN = ($SID.Translate([System.Security.Principal.NTAccount])).Value
  12126. $Admin = New-Object System.Security.Principal.NTAccount($IDN)
  12127. $path = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\ClipSVC\Volatile\PersistedSystemState'
  12128. $key = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64').OpenSubKey($path, 'ReadWriteSubTree', 'takeownership')
  12129. $acl = $key.GetAccessControl()
  12130. $acl.SetOwner($Admin)
  12131. $key.SetAccessControl($acl)
  12132. $rule = New-Object System.Security.AccessControl.RegistryAccessRule($Admin,"FullControl","Allow")
  12133. $acl.SetAccessRule($rule)
  12134. $key.SetAccessControl($acl)
  12135. :regown:
  12136. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12137. :change_winedition
  12138. :: To stage current edition while changing edition with CBS Upgrade Method, change 0 to 1 in below line
  12139. set _stg=0
  12140. set "line=echo ___________________________________________________________________________________________"
  12141. cls
  12142. if not defined terminal mode 98, 30
  12143. title Change Windows Edition %masver%
  12144. echo:
  12145. echo Initializing...
  12146. echo:
  12147. for %%# in (
  12148. sppsvc.exe
  12149. dism.exe
  12150. ) do (
  12151. if not exist %SysPath%\%%# (
  12152. %eline%
  12153. echo [%SysPath%\%%#] file is missing, aborting...
  12154. echo:
  12155. set fixes=%fixes% %mas%troubleshoot
  12156. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  12157. goto dk_done
  12158. )
  12159. )
  12160. ::========================================================================================================================================
  12161. set spp=SoftwareLicensingProduct
  12162. set sps=SoftwareLicensingService
  12163. call :dk_reflection
  12164. call :dk_ckeckwmic
  12165. call :dk_sppissue
  12166. for /f "tokens=6-7 delims=[]. " %%i in ('ver') do if not "%%j"=="" (
  12167. set fullbuild=%%i.%%j
  12168. ) else (
  12169. for /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"
  12170. for /f "skip=2 tokens=3,4 delims=. " %%G in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildLabEx') do (
  12171. if defined UBR (set "fullbuild=%%G.!UBR!") else (set "fullbuild=%%G.%%H")
  12172. )
  12173. )
  12174. ::========================================================================================================================================
  12175. :: Check Activation IDs
  12176. call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  12177. if not defined allapps (
  12178. %eline%
  12179. echo Failed to find activation IDs. Aborting...
  12180. echo:
  12181. set fixes=%fixes% %mas%troubleshoot
  12182. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  12183. goto dk_done
  12184. )
  12185. ::========================================================================================================================================
  12186. :: Check Windows Edition and branch
  12187. set osedition=
  12188. set dismnotworking=
  12189. for /f "tokens=3 delims=: " %%a in ('DISM /English /Online /Get-CurrentEdition %nul6% ^| find /i "Current Edition :"') do set "osedition=%%a"
  12190. if not defined osedition set dismnotworking=1
  12191. if %_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%')"
  12192. if %_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%')"
  12193. if not defined osedition %chkedi% do if not errorlevel 1 (call set "osedition=%%a")
  12194. if not defined osedition (
  12195. %eline%
  12196. echo Failed to detect OS edition, aborting...
  12197. echo:
  12198. set fixes=%fixes% %mas%troubleshoot
  12199. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  12200. goto dk_done
  12201. )
  12202. for /f "skip=2 tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul6%') do set "regedition=%%a"
  12203. if /i not "%osedition%"=="%regedition%" (
  12204. set "showeditionerror=call :dk_color %_Yellow% "[%osedition%] [Reg-%regedition%].""
  12205. )
  12206. set branch=
  12207. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildBranch %nul6%') do set "branch=%%b"
  12208. ::========================================================================================================================================
  12209. :: Get target editions list
  12210. set _target=
  12211. set _dtarget=
  12212. set _ptarget=
  12213. set _ntarget=
  12214. set _wtarget=
  12215. if %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 "))
  12216. if %winbuild% LSS 10240 for /f "tokens=4" %%a in ('%psc% "$f=[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 "))
  12217. if %winbuild% GEQ 10240 if not exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
  12218. if %winbuild% GEQ 17063 call :ced_edilist
  12219. if /i "%osedition:~0,4%"=="Core" set _pro=Professional
  12220. if /i "%osedition%"=="CoreN" set _pro=ProfessionalN
  12221. set "_dtarget= %_dtarget% !_wtarget! !_pro! "
  12222. )
  12223. ::========================================================================================================================================
  12224. for %%# in (CloudEdition CloudEditionN ServerRdsh) do if /i %osedition%==%%# (
  12225. cls
  12226. echo:
  12227. call :dk_color %Red% "==== Note ===="
  12228. echo:
  12229. echo [EditionID:%osedition% ^| %fullbuild%]
  12230. echo:
  12231. echo Changing this edition may not remove "%osedition%"-specific features.
  12232. echo:
  12233. call :dk_color %_Yellow% "Press [7] to continue anyway..."
  12234. choice /c 7 /n
  12235. cls
  12236. )
  12237. for %%# in ( %_dtarget% %_ptarget% ) do if /i not "%%#"=="%osedition%" (
  12238. echo "!_target!" | find /i " %%# " %nul1% || set "_target= !_target! %%# "
  12239. )
  12240. if defined _target (
  12241. for %%# in (%_target%) do (
  12242. echo %%# | findstr /i "CountrySpecific CloudEdition" %nul% || (set "_ntarget=!_ntarget! %%#")
  12243. )
  12244. )
  12245. if not defined _ntarget (
  12246. %line%
  12247. echo:
  12248. if defined dismnotworking call :dk_color %Red% "DISM.exe is not working."
  12249. call :dk_color %Gray% "Target editions not found."
  12250. echo Current Edition [%osedition% ^| %winbuild%] can not be changed to any other Edition.
  12251. %line%
  12252. goto dk_done
  12253. )
  12254. ::========================================================================================================================================
  12255. :cedmenu2
  12256. cls
  12257. if not defined terminal mode 98, 30
  12258. set inpt=
  12259. set counter=0
  12260. set verified=0
  12261. set targetedition=
  12262. %line%
  12263. echo:
  12264. call :dk_color %Gray% "You can change the edition [%osedition%] [%fullbuild%] to one of the following."
  12265. %showeditionerror%
  12266. if defined dismnotworking (
  12267. call :dk_color %_Yellow% "Note - DISM.exe is not working."
  12268. if /i "%osedition:~0,4%"=="Core" call :dk_color %_Yellow% " - You will see more edition options to choose once its changed to Pro."
  12269. )
  12270. %line%
  12271. echo:
  12272. for %%A in (%_ntarget%) do (
  12273. set /a counter+=1
  12274. echo [!counter!] %%A
  12275. set targetedition!counter!=%%A
  12276. )
  12277. %line%
  12278. echo:
  12279. echo [0] %_exitmsg%
  12280. echo:
  12281. call :dk_color %_Green% "Enter an option number using your keyboard and press Enter to confirm:"
  12282. set /p inpt=
  12283. if "%inpt%"=="" goto cedmenu2
  12284. if "%inpt%"=="0" exit /b
  12285. for /l %%i in (1,1,%counter%) do (if "%inpt%"=="%%i" set verified=1)
  12286. set targetedition=!targetedition%inpt%!
  12287. if %verified%==0 goto cedmenu2
  12288. ::========================================================================================================================================
  12289. if %winbuild% LSS 10240 goto :cbsmethod
  12290. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" goto :ced_change_server
  12291. cls
  12292. if not defined terminal mode con cols=105 lines=32
  12293. if /i "%targetedition%"=="ServerRdsh" (
  12294. echo:
  12295. call :dk_color %Red% "==== Note ===="
  12296. echo:
  12297. echo Once the edition is changed to "%targetedition%",
  12298. echo the system may not be able to properly change edition later.
  12299. echo:
  12300. echo [1] Continue Anyway
  12301. echo [0] Go Back
  12302. echo:
  12303. call :dk_color %_Green% "Choose a menu option using your keyboard [1,0] :"
  12304. choice /C:10 /N
  12305. if !errorlevel!==2 goto cedmenu2
  12306. if !errorlevel!==1 rem
  12307. )
  12308. cls
  12309. set key=
  12310. set _chan=
  12311. set _dismapi=0
  12312. :: Check if DISM API or slmgr.vbs is required for edition upgrade
  12313. if not exist "%SysPath%\spp\tokens\skus\%targetedition%\%targetedition%*.xrm-ms" (
  12314. echo %_wtarget% | find /i " %targetedition% " || (
  12315. set _dismapi=1
  12316. )
  12317. )
  12318. set "keyflow=Retail Volume:GVLK Volume:MAK OEM:NONSLP OEM:DM PGS:TB Retail:TB:Eval"
  12319. call :ced_targetSKU %targetedition%
  12320. if defined targetSKU call :ced_windowskey
  12321. if defined key if defined pkeychannel set _chan=%pkeychannel%
  12322. if not defined key call :changeeditiondata
  12323. if not defined key if %_dismapi%==1 if /i "%targetedition%"=="Professional" (
  12324. set key=VK7JG-NPHTM-C97JM-9MPGT-3V66T
  12325. set _chan=Retail
  12326. )
  12327. if not defined key (
  12328. %eline%
  12329. echo [%targetedition% ^| %winbuild%]
  12330. echo Failed to get product key from pkeyhelper.dll.
  12331. echo:
  12332. set fixes=%fixes% %mas%troubleshoot
  12333. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  12334. goto dk_done
  12335. )
  12336. ::========================================================================================================================================
  12337. :: Changing from Core to Non-Core & Changing editions in Windows build older than 17134 requires "changepk /productkey" or DISM Api method and restart
  12338. :: In other cases, editions can be changed instantly with "slmgr /ipk"
  12339. if %_dismapi%==1 (
  12340. if not defined terminal mode con cols=105 lines=40
  12341. call :ced_rebootflag
  12342. if defined rebootreq goto dk_done
  12343. )
  12344. cls
  12345. %line%
  12346. echo:
  12347. %showeditionerror%
  12348. if defined dismnotworking call :dk_color %_Yellow% "DISM.exe is not working."
  12349. echo Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...
  12350. echo:
  12351. if %_dismapi%==1 (
  12352. call :dk_color %Green% "Notes -"
  12353. echo:
  12354. echo - Save your work before continuing, the system will auto-restart.
  12355. echo:
  12356. echo - You will need to activate with HWID option once the edition is changed.
  12357. %line%
  12358. echo:
  12359. choice /C:21 /N /M "[1] Continue [2] %_exitmsg% : "
  12360. if !errorlevel!==1 exit /b
  12361. )
  12362. ::========================================================================================================================================
  12363. if %_dismapi%==0 (
  12364. echo Installing %_chan% key [%key%]
  12365. echo:
  12366. if %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey="%key%" %nul%
  12367. if %_wmic% EQU 0 %psc% "try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
  12368. set keyerror=!errorlevel!
  12369. cmd /c exit /b !keyerror!
  12370. if !keyerror! NEQ 0 set "keyerror=[0x!=ExitCode!]"
  12371. if !keyerror! EQU 0 (
  12372. call :dk_refresh
  12373. call :dk_color %Green% "[Successful]"
  12374. echo:
  12375. call :dk_color %Gray% "Reboot is required to fully change the edition."
  12376. ) else (
  12377. call :dk_color %Red% "[Unsuccessful] [Error Code: !keyerror!]"
  12378. echo:
  12379. set fixes=%fixes% %mas%troubleshoot
  12380. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  12381. )
  12382. )
  12383. if %_dismapi%==1 (
  12384. echo:
  12385. echo Applying the DISM API method with %_chan% key %key%. Please wait...
  12386. echo:
  12387. call :ced_prep
  12388. if defined preperror goto dk_done
  12389. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':dismapi\:.*';& ([ScriptBlock]::Create($f[1])) %targetedition% %key%"
  12390. call :ced_postprep
  12391. )
  12392. %line%
  12393. goto dk_done
  12394. ::========================================================================================================================================
  12395. :cbsmethod
  12396. cls
  12397. if not defined terminal (
  12398. mode con cols=105 lines=32
  12399. %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%
  12400. )
  12401. call :ced_rebootflag
  12402. if defined rebootreq goto dk_done
  12403. echo:
  12404. %showeditionerror%
  12405. if defined dismnotworking call :dk_color %_Yellow% "Note - DISM.exe is not working."
  12406. echo Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...
  12407. echo:
  12408. call :dk_color %Blue% "Important - Save your work before continuing, the system will auto-restart."
  12409. echo:
  12410. choice /C:01 /N /M "[1] Continue [0] %_exitmsg% : "
  12411. if %errorlevel%==1 exit /b
  12412. echo:
  12413. echo Initializing...
  12414. echo:
  12415. call :ced_prep
  12416. if defined preperror goto dk_done
  12417. if %_stg%==0 (set stage=) else (set stage=-StageCurrent)
  12418. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':cbsxml\:.*';& ([ScriptBlock]::Create($f[1])) -SetEdition %targetedition% %stage%"
  12419. call :ced_postprep
  12420. %line%
  12421. goto dk_done
  12422. ::========================================================================================================================================
  12423. :ced_change_server
  12424. cls
  12425. if not defined terminal (
  12426. mode con cols=105 lines=32
  12427. %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%
  12428. )
  12429. set key=
  12430. set _chan=
  12431. set "keyflow=Volume:GVLK Retail Volume:MAK OEM:NONSLP OEM:DM PGS:TB Retail:TB:Eval"
  12432. call :ced_targetSKU %targetedition%
  12433. if defined targetSKU call :ced_windowskey
  12434. if defined key if defined pkeychannel set _chan=%pkeychannel%
  12435. if not defined key call :changeeditiondata
  12436. if not defined key (
  12437. %eline%
  12438. echo [%targetedition% ^| %winbuild%]
  12439. echo Failed to get product key from pkeyhelper.dll.
  12440. echo:
  12441. set fixes=%fixes% %mas%troubleshoot
  12442. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  12443. goto dk_done
  12444. )
  12445. call :ced_rebootflag
  12446. if defined rebootreq goto dk_done
  12447. cls
  12448. echo:
  12449. %showeditionerror%
  12450. if defined dismnotworking call :dk_color %_Yellow% "Note - DISM.exe is not working."
  12451. echo Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...
  12452. echo:
  12453. call :ced_prep
  12454. if defined preperror goto dk_done
  12455. echo Applying the command with %_chan% key...
  12456. echo DISM /online /Set-Edition:%targetedition% /ProductKey:%key% /AcceptEula
  12457. DISM /online /Set-Edition:%targetedition% /ProductKey:%key% /AcceptEula
  12458. call :ced_postprep
  12459. %line%
  12460. goto dk_done
  12461. ::========================================================================================================================================
  12462. :ced_prep
  12463. set _time=
  12464. set preperror=
  12465. for /f %%a in ('%psc% "(Get-Date).ToString('yyyyMMdd-HHmmssfff')"') do set _time=%%a
  12466. %psc% Stop-Service TrustedInstaller -force %nul%
  12467. sc query TrustedInstaller | find /i "RUNNING" %nul% && (
  12468. %eline%
  12469. echo Failed to stop the TrustedInstaller service.
  12470. echo Reboot your machine using the restart option and try again.
  12471. set preperror=1
  12472. exit /b
  12473. )
  12474. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\backup_cbs_%_time%.log" %nul%
  12475. copy /y /b "%SystemRoot%\logs\DISM\dism.log" "%SystemRoot%\logs\DISM\backup_dism_%_time%.log" %nul%
  12476. del /f /q "%SystemRoot%\logs\cbs\cbs.log" %nul%
  12477. del /f /q "%SystemRoot%\logs\DISM\dism.log" %nul%
  12478. :: Initiate this to appear in fresh logs
  12479. dism /online /english /Get-CurrentEdition %nul%
  12480. dism /online /english /Get-TargetEditions %nul%
  12481. exit /b
  12482. ::========================================================================================================================================
  12483. :ced_postprep
  12484. timeout /t 5 %nul1%
  12485. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\cbs_%_time%.log" %nul%
  12486. copy /y /b "%SystemRoot%\logs\DISM\dism.log" "%SystemRoot%\logs\DISM\dism_%_time%.log" %nul%
  12487. if not exist "!desktop!\ChangeEdition_Logs\" md "!desktop!\ChangeEdition_Logs\" %nul%
  12488. call :compresslog cbs\cbs_%_time%.log ChangeEdition_Logs\CBS %nul%
  12489. call :compresslog DISM\dism_%_time%.log ChangeEdition_Logs\DISM %nul%
  12490. echo:
  12491. if %winbuild% GEQ 9200 %psc% "if ((Get-WindowsOptionalFeature -Online -FeatureName NetFx3).State -eq 'Enabled') {Write-Host 'Checking .NET Framework 3.5 Status - Enabled'}"
  12492. echo Log files are copied to the ChangeEdition_Logs folder on your desktop.
  12493. echo:
  12494. call :dk_color %Blue% "In case there are errors, you should restart the system before trying again."
  12495. echo:
  12496. set fixes=%fixes% %mas%change_edition_issues
  12497. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%change_edition_issues"
  12498. exit /b
  12499. ::========================================================================================================================================
  12500. :: Get Edition list
  12501. :ced_edilist
  12502. if %_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%')"
  12503. if %_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%')"
  12504. %chkedi% do call set "_wtarget= !_wtarget! %%a "
  12505. exit /b
  12506. ::========================================================================================================================================
  12507. :: Check pending reboot flags
  12508. :ced_rebootflag
  12509. set rebootreq=
  12510. reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" %nul% && set rebootreq=1
  12511. reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" %nul% && set rebootreq=1
  12512. if defined rebootreq (
  12513. %eline%
  12514. echo Pending reboot flags found.
  12515. echo:
  12516. echo Make sure Windows is fully updated, restart the system and try again.
  12517. )
  12518. exit /b
  12519. ::========================================================================================================================================
  12520. :ced_windowskey
  12521. for %%# in (pkeyhelper.dll) do @if "%%~$PATH:#"=="" exit /b
  12522. for %%# in (%keyflow%) do (
  12523. call :k_pkey %targetSKU% '%%#'
  12524. if defined pkey call :k_pkeychannel !pkey!
  12525. if /i "!pkeychannel!"=="%%#" (
  12526. set key=!pkey!
  12527. exit /b
  12528. )
  12529. )
  12530. exit /b
  12531. ::========================================================================================================================================
  12532. :ced_targetSKU
  12533. set k=%1
  12534. set targetSKU=
  12535. for %%# in (pkeyhelper.dll) do @if "%%~$PATH:#"=="" exit /b
  12536. call :dk_reflection
  12537. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionIdFromName', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3);
  12538. set d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionIdFromName('%k%', [ref]$out); $out
  12539. for /f %%a in ('%psc% "%d1%"') do if not errorlevel 1 (set targetSKU=%%a)
  12540. if "%targetSKU%"=="0" set targetSKU=
  12541. exit /b
  12542. ::========================================================================================================================================
  12543. :: https://github.com/asdcorp/Set-WindowsCbsEdition
  12544. :cbsxml:[
  12545. param (
  12546. [Parameter()]
  12547. [String]$SetEdition,
  12548. [Parameter()]
  12549. [Switch]$GetTargetEditions,
  12550. [Parameter()]
  12551. [Switch]$StageCurrent
  12552. )
  12553. function Get-AssemblyIdentity {
  12554. param (
  12555. [String]$PackageName
  12556. )
  12557. $PackageName = [String]$PackageName
  12558. $packageData = ($PackageName -split '~')
  12559. if($packageData[3] -eq '') {
  12560. $packageData[3] = 'neutral'
  12561. }
  12562. return "<assemblyIdentity name=`"$($packageData[0])`" version=`"$($packageData[4])`" processorArchitecture=`"$($packageData[2])`" publicKeyToken=`"$($packageData[1])`" language=`"$($packageData[3])`" />"
  12563. }
  12564. function Get-SxsName {
  12565. param (
  12566. [String]$PackageName
  12567. )
  12568. $name = ($PackageName -replace '[^A-z0-9\-\._]', '')
  12569. if($name.Length -gt 40) {
  12570. $name = ($name[0..18] -join '') + '\.\.' + ($name[-19..-1] -join '')
  12571. }
  12572. return $name.ToLower()
  12573. }
  12574. function Find-EditionXmlInSxs {
  12575. param (
  12576. [String]$Edition
  12577. )
  12578. $candidates = @($Edition, 'Client', 'Server')
  12579. $winSxs = $Env:SystemRoot + '\WinSxS'
  12580. $allInSxs = Get-ChildItem -Path $winSxs | select Name
  12581. foreach($candidate in $candidates) {
  12582. $name = Get-SxsName -PackageName "Microsoft-Windows-Editions-$candidate"
  12583. $packages = $allInSxs | where name -Match ('^.*_'+$name+'_31bf3856ad364e35')
  12584. if($packages.Length -eq 0) {
  12585. continue
  12586. }
  12587. $package = $packages[-1].Name
  12588. $testPath = $winSxs + "\$package\" + $Edition + 'Edition.xml'
  12589. if(Test-Path -Path $testPath -PathType Leaf) {
  12590. return $testPath
  12591. }
  12592. }
  12593. return $null
  12594. }
  12595. function Find-EditionXml {
  12596. param (
  12597. [String]$Edition
  12598. )
  12599. $servicingEditions = $Env:SystemRoot + '\servicing\Editions'
  12600. $editionXml = $Edition + 'Edition.xml'
  12601. $editionXmlInServicing = $servicingEditions + '\' + $editionXml
  12602. if(Test-Path -Path $editionXmlInServicing -PathType Leaf) {
  12603. return $editionXmlInServicing
  12604. }
  12605. return Find-EditionXmlInSxs -Edition $Edition
  12606. }
  12607. function Write-UpgradeCandidates {
  12608. param (
  12609. [HashTable]$InstallCandidates
  12610. )
  12611. $editionCount = 0
  12612. Write-Host 'Editions that can be upgraded to:'
  12613. foreach($candidate in $InstallCandidates.Keys) {
  12614. Write-Host "Target Edition : $candidate"
  12615. $editionCount++
  12616. }
  12617. if($editionCount -eq 0) {
  12618. Write-Host '(no editions are available)'
  12619. }
  12620. }
  12621. function Write-UpgradeXml {
  12622. param (
  12623. [Array]$RemovalCandidates,
  12624. [Array]$InstallCandidates,
  12625. [Boolean]$Stage
  12626. )
  12627. $removeAction = 'remove'
  12628. if($Stage) {
  12629. $removeAction = 'stage'
  12630. }
  12631. Write-Output '<?xml version="1.0"?>'
  12632. Write-Output '<unattend xmlns="urn:schemas-microsoft-com:unattend">'
  12633. Write-Output '<servicing>'
  12634. foreach($package in $InstallCandidates) {
  12635. Write-Output '<package action="install">'
  12636. Write-Output (Get-AssemblyIdentity -PackageName $package)
  12637. Write-Output '</package>'
  12638. }
  12639. foreach($package in $RemovalCandidates) {
  12640. Write-Output "<package action=`"$removeAction`">"
  12641. Write-Output (Get-AssemblyIdentity -PackageName $package)
  12642. Write-Output '</package>'
  12643. }
  12644. Write-Output '</servicing>'
  12645. Write-Output '</unattend>'
  12646. }
  12647. function Write-Usage {
  12648. Get-Help $script:MyInvocation.MyCommand.Path -detailed
  12649. }
  12650. $version = '1.0'
  12651. $getTargetsParam = $GetTargetEditions.IsPresent
  12652. $stageCurrentParam = $StageCurrent.IsPresent
  12653. if($SetEdition -eq '' -and ($false -eq $getTargetsParam)) {
  12654. Write-Usage
  12655. Exit 1
  12656. }
  12657. $removalCandidates = @();
  12658. $installCandidates = @{};
  12659. $packages = Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages' | select Name | where { $_.name -match '^.*\\Microsoft-Windows-.*Edition~' }
  12660. foreach($package in $packages) {
  12661. $state = (Get-ItemProperty -Path "Registry::$($package.Name)").CurrentState
  12662. $packageName = ($package.Name -split '\\')[-1]
  12663. $packageEdition = (($packageName -split 'Edition~')[0] -split 'Microsoft-Windows-')[-1]
  12664. if($state -eq 0x40) {
  12665. if($null -eq $installCandidates[$packageEdition]) {
  12666. $installCandidates[$packageEdition] = @()
  12667. }
  12668. if($false -eq ($installCandidates[$packageEdition] -contains $packageName)) {
  12669. $installCandidates[$packageEdition] = $installCandidates[$packageEdition] + @($packageName)
  12670. }
  12671. }
  12672. if((($state -eq 0x50) -or ($state -eq 0x70)) -and ($false -eq ($removalCandidates -contains $packageName))) {
  12673. $removalCandidates = $removalCandidates + @($packageName)
  12674. }
  12675. }
  12676. if($getTargetsParam) {
  12677. Write-UpgradeCandidates -InstallCandidates $installCandidates
  12678. Exit
  12679. }
  12680. if($false -eq ($installCandidates.Keys -contains $SetEdition)) {
  12681. Write-Error "The system cannot be upgraded to `"$SetEdition`""
  12682. Exit 1
  12683. }
  12684. $xmlPath = $Env:SystemRoot + '\Temp' + '\CbsUpgrade.xml'
  12685. Write-UpgradeXml -RemovalCandidates $removalCandidates `
  12686. -InstallCandidates $installCandidates[$SetEdition] `
  12687. -Stage $stageCurrentParam >$xmlPath
  12688. $editionXml = Find-EditionXml -Edition $SetEdition
  12689. if($null -eq $editionXml) {
  12690. Write-Warning 'Unable to find edition specific settings XML. Proceeding without it...'
  12691. }
  12692. Write-Host 'Starting the upgrade process. This may take a while...'
  12693. DISM.EXE /English /NoRestart /Online /Apply-Unattend:$xmlPath
  12694. $dismError = $LASTEXITCODE
  12695. Remove-Item -Path $xmlPath -Force
  12696. if(($dismError -ne 0) -and ($dismError -ne 3010)) {
  12697. Write-Error 'Failed to upgrade to the target edition'
  12698. Exit $dismError
  12699. }
  12700. if($null -ne $editionXml) {
  12701. $destination = $Env:SystemRoot + '\' + $SetEdition + '.xml'
  12702. Copy-Item -Path $editionXml -Destination $destination
  12703. DISM.EXE /English /NoRestart /Online /Apply-Unattend:$editionXml
  12704. $dismError = $LASTEXITCODE
  12705. if(($dismError -ne 0) -and ($dismError -ne 3010)) {
  12706. Write-Error 'Failed to apply edition specific settings'
  12707. Exit $dismError
  12708. }
  12709. }
  12710. Restart-Computer
  12711. :cbsxml:]
  12712. ::========================================================================================================================================
  12713. :: Change edition using DISM API
  12714. :: Thanks to Alex (aka may, ave9858)
  12715. :dismapi:[
  12716. param (
  12717. [Parameter()]
  12718. [String]$TargetEdition,
  12719. [Parameter()]
  12720. [String]$Key
  12721. )
  12722. $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)
  12723. $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)
  12724. $TB = $ModuleBuilder.DefineType(0)
  12725. [void]$TB.DefinePInvokeMethod('DismInitialize', 'DismApi.dll', 22, 1, [int], @([int], [IntPtr], [IntPtr]), 1, 3)
  12726. [void]$TB.DefinePInvokeMethod('DismOpenSession', 'DismApi.dll', 22, 1, [int], @([String], [IntPtr], [IntPtr], [UInt32].MakeByRefType()), 1, 3)
  12727. [void]$TB.DefinePInvokeMethod('_DismSetEdition', 'DismApi.dll', 22, 1, [int], @([UInt32], [String], [String], [IntPtr], [IntPtr], [IntPtr]), 1, 3)
  12728. $Dism = $TB.CreateType()
  12729. [void]$Dism::DismInitialize(2, 0, 0)
  12730. $Session = 0
  12731. [void]$Dism::DismOpenSession('DISM_{53BFAE52-B167-4E2F-A258-0A37B57FF845}', 0, 0, [ref]$Session)
  12732. if (!$Dism::_DismSetEdition($Session, "$TargetEdition", "$Key", 0, 0, 0)) {
  12733. Restart-Computer
  12734. }
  12735. :dismapi:]
  12736. ::========================================================================================================================================
  12737. :: 1st column = Generic Retail/OEM/MAK/GVLK Key
  12738. :: 2nd column = Key Type
  12739. :: 3rd column = WMI Edition ID
  12740. :: 4th column = Version name incase same Edition ID is used in different OS versions with different key
  12741. :: Separator = _
  12742. :: For Windows 10/11 editions, HWID key is listed where ever possible, in Server versions, KMS key is listed where ever possible.
  12743. :: 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
  12744. :changeeditiondata
  12745. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
  12746. if %winbuild% GTR 17763 exit /b
  12747. ) else (
  12748. if %winbuild% GEQ 22000 exit /b
  12749. )
  12750. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*CorEdition~*.mum" (set Cor=Cor) else (set Cor=)
  12751. set h=
  12752. for %%# in (
  12753. XGVPP-NMH47-7TTHJ-W3FW7-8HV%h%2C__OEM:NONSLP_Enterprise
  12754. D6RD9-D4N8T-RT9QX-YW6YT-FCW%h%WJ______Retail_Starter
  12755. 3V6Q6-NQXCX-V8YXR-9QCYV-QPF%h%CT__Volume:MAK_EnterpriseN
  12756. 3NFXW-2T27M-2BDW6-4GHRV-68X%h%RX______Retail_StarterN
  12757. VK7JG-NPHTM-C97JM-9MPGT-3V6%h%6T______Retail_Professional
  12758. 2B87N-8KFHP-DKV6R-Y2C8J-PKC%h%KT______Retail_ProfessionalN
  12759. 4CPRK-NM3K3-X6XXQ-RXX86-WXC%h%HW______Retail_CoreN
  12760. N2434-X9D7W-8PF6X-8DV9T-8TY%h%MD______Retail_CoreCountrySpecific
  12761. BT79Q-G7N6G-PGBYW-4YWX6-6F4%h%BT______Retail_CoreSingleLanguage
  12762. YTMG3-N6DKC-DKB77-7M9GH-8HV%h%X7______Retail_Core
  12763. XKCNC-J26Q9-KFHD2-FKTHY-KD7%h%2Y__OEM:NONSLP_PPIPro
  12764. YNMGQ-8RYV3-4PGQ3-C8XTP-7CF%h%BY______Retail_Education
  12765. 84NGF-MHBT6-FXBX8-QWJK7-DRR%h%8H______Retail_EducationN
  12766. KCNVH-YKWX8-GJJB9-H9FDT-6F7%h%W2__Volume:MAK_EnterpriseS_VB
  12767. 43TBQ-NH92J-XKTM7-KT3KK-P39%h%PB__OEM:NONSLP_EnterpriseS_RS5
  12768. NK96Y-D9CD8-W44CQ-R8YTK-DYJ%h%WX__OEM:NONSLP_EnterpriseS_RS1
  12769. FWN7H-PF93Q-4GGP8-M8RF3-MDW%h%WW__OEM:NONSLP_EnterpriseS_TH
  12770. RQFNW-9TPM3-JQ73T-QV4VQ-DV9%h%PT__Volume:MAK_EnterpriseSN_VB
  12771. M33WV-NHY3C-R7FPM-BQGPT-239%h%PG__Volume:MAK_EnterpriseSN_RS5
  12772. 2DBW3-N2PJG-MVHW3-G7TDK-9HK%h%R4__Volume:MAK_EnterpriseSN_RS1
  12773. NTX6B-BRYC2-K6786-F6MVQ-M7V%h%2X__Volume:MAK_EnterpriseSN_TH
  12774. G3KNM-CHG6T-R36X3-9QDG6-8M8%h%K9______Retail_ProfessionalSingleLanguage
  12775. HNGCC-Y38KG-QVK8D-WMWRK-X86%h%VK______Retail_ProfessionalCountrySpecific
  12776. DXG7C-N36C4-C4HTG-X4T3X-2YV%h%77______Retail_ProfessionalWorkstation
  12777. WYPNQ-8C467-V2W6J-TX4WX-WT2%h%RQ______Retail_ProfessionalWorkstationN
  12778. 8PTT6-RNW4C-6V7J2-C2D3X-MHB%h%PB______Retail_ProfessionalEducation
  12779. GJTYN-HDMQY-FRR76-HVGC7-QPF%h%8P______Retail_ProfessionalEducationN
  12780. C4NTJ-CX6Q2-VXDMR-XVKGM-F9D%h%JC__Volume:MAK_EnterpriseG
  12781. 46PN6-R9BK9-CVHKB-HWQ9V-MBJ%h%Y8__Volume:MAK_EnterpriseGN
  12782. NJCF7-PW8QT-3324D-688JX-2YV%h%66______Retail_ServerRdsh
  12783. XQQYW-NFFMW-XJPBH-K8732-CKF%h%FD______OEM:DM_IoTEnterprise
  12784. QPM6N-7J2WJ-P88HH-P3YRH-YY7%h%4H__OEM:NONSLP_IoTEnterpriseS
  12785. K9VKN-3BGWV-Y624W-MCRMQ-BHD%h%CD______Retail_CloudEditionN
  12786. KY7PN-VR6RX-83W6Y-6DDYQ-T6R%h%4W______Retail_CloudEdition
  12787. V3WVW-N2PV2-CGWC3-34QGF-VMJ%h%2C______Retail_Cloud
  12788. NH9J3-68WK7-6FB93-4K3DF-DJ4%h%F6______Retail_CloudN
  12789. 2HN6V-HGTM8-6C97C-RK67V-JQP%h%FD______Retail_CloudE
  12790. WC2BQ-8NRM3-FDDYY-2BFGV-KHK%h%QY_Volume:GVLK_ServerStandard%Cor%_RS1
  12791. CB7KF-BWN84-R7R2Y-793K2-8XD%h%DG_Volume:GVLK_ServerDatacenter%Cor%_RS1
  12792. JCKRF-N37P4-C2D82-9YXRT-4M6%h%3B_Volume:GVLK_ServerSolution_RS1
  12793. QN4C6-GBJD2-FB422-GHWJK-GJG%h%2R_Volume:GVLK_ServerCloudStorage_RS1
  12794. VP34G-4NPPG-79JTQ-864T4-R3M%h%QX_Volume:GVLK_ServerAzureCor_RS1
  12795. 9JQNQ-V8HQ6-PKB8H-GGHRY-R62%h%H6______Retail_ServerAzureNano_RS1
  12796. VN8D3-PR82H-DB6BJ-J9P4M-92F%h%6J______Retail_ServerStorageStandard_RS1
  12797. 48TQX-NVK3R-D8QR3-GTHHM-8FH%h%XC______Retail_ServerStorageWorkgroup_RS1
  12798. 2HXDN-KRXHB-GPYC7-YCKFJ-7FV%h%DG_Volume:GVLK_ServerDatacenterACor_RS3
  12799. PTXN8-JFHJM-4WC78-MPCBR-9W4%h%KR_Volume:GVLK_ServerStandardACor_RS3
  12800. ) do (
  12801. for /f "tokens=1-4 delims=_" %%A in ("%%#") do if /i %targetedition%==%%C (
  12802. if not defined key (
  12803. set 4th=%%D
  12804. if not defined 4th (
  12805. set "key=%%A" & set "_chan=%%B"
  12806. ) else (
  12807. echo "%branch%" | find /i "%%D" %nul1% && (set "key=%%A" & set "_chan=%%B")
  12808. )
  12809. )
  12810. )
  12811. )
  12812. exit /b
  12813. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12814. :change_offedition
  12815. set "line=echo ___________________________________________________________________________________________"
  12816. cls
  12817. if not defined terminal mode 98, 30
  12818. title Change Office Edition %masver%
  12819. echo:
  12820. echo Initializing...
  12821. echo:
  12822. if not exist %SysPath%\sppsvc.exe (
  12823. %eline%
  12824. echo [%SysPath%\sppsvc.exe] file is missing. Aborting...
  12825. echo:
  12826. set fixes=%fixes% %mas%troubleshoot
  12827. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  12828. goto dk_done
  12829. )
  12830. ::========================================================================================================================================
  12831. set spp=SoftwareLicensingProduct
  12832. set sps=SoftwareLicensingService
  12833. call :dk_reflection
  12834. call :dk_ckeckwmic
  12835. call :dk_sppissue
  12836. for /f "tokens=6-7 delims=[]. " %%i in ('ver') do if not "%%j"=="" (
  12837. set fullbuild=%%i.%%j
  12838. ) else (
  12839. for /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"
  12840. for /f "skip=2 tokens=3,4 delims=. " %%G in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildLabEx') do (
  12841. if defined UBR (set "fullbuild=%%G.!UBR!") else (set "fullbuild=%%G.%%H")
  12842. )
  12843. )
  12844. ::========================================================================================================================================
  12845. :: Check Windows Edition
  12846. :: This is just to ensure that SPP/WMI are functional
  12847. cls
  12848. set osedition=0
  12849. if %_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%')"
  12850. if %_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%')"
  12851. %chkedi% do if not errorlevel 1 (call set "osedition=%%a")
  12852. if %osedition%==0 (
  12853. %eline%
  12854. echo Failed to detect OS Edition. Aborting...
  12855. echo:
  12856. set fixes=%fixes% %mas%troubleshoot
  12857. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  12858. goto dk_done
  12859. )
  12860. ::========================================================================================================================================
  12861. :: Check installed Office 16.0 C2R
  12862. set o16c2r=
  12863. set _68=HKLM\SOFTWARE\Microsoft\Office
  12864. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  12865. for /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)
  12866. for /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)
  12867. if not defined o16c2r_reg (
  12868. %eline%
  12869. echo Office C2R 2016 or later is not installed, which is required for this script.
  12870. echo Download and install Office from below URL and try again.
  12871. echo:
  12872. set fixes=%fixes% %mas%genuine-installation-media
  12873. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  12874. goto dk_done
  12875. )
  12876. call :ch_getinfo
  12877. ::========================================================================================================================================
  12878. :: Check minimum required details
  12879. if %verchk% LSS 9029 (
  12880. %eline%
  12881. echo Installed Office version is %_version%.
  12882. echo Minimum required version is 16.0.9029.2167
  12883. echo Aborting...
  12884. echo:
  12885. call :dk_color %Blue% "Download and install latest Office from below URL and try again."
  12886. set fixes=%fixes% %mas%genuine-installation-media
  12887. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  12888. goto dk_done
  12889. )
  12890. for %%A in (
  12891. _oArch
  12892. _updch
  12893. _lang
  12894. _clversion
  12895. _version
  12896. _oIds
  12897. _c2rXml
  12898. _c2rExe
  12899. _c2rCexe
  12900. _masterxml
  12901. ) do (
  12902. if not defined %%A (
  12903. %eline%
  12904. echo Failed to find %%A. Aborting...
  12905. echo:
  12906. call :dk_color %Blue% "Download and install Office from below URL and try again."
  12907. set fixes=%fixes% %mas%genuine-installation-media
  12908. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  12909. goto dk_done
  12910. )
  12911. )
  12912. if %winbuild% LSS 10240 if defined ltscfound (
  12913. %eline%
  12914. echo Installed Office appears to be from the Volume channel %ltsc19%%ltsc21%%ltsc24%,
  12915. echo which is not officially supported on your Windows build version %winbuild%.
  12916. echo Aborting...
  12917. echo:
  12918. set fixes=%fixes% %mas%troubleshoot
  12919. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  12920. goto dk_done
  12921. )
  12922. set unsupbuild=
  12923. if %winbuild% LSS 10240 if %winbuild% GEQ 9200 if %verchk% GTR 16026 set unsupbuild=1
  12924. if %winbuild% LSS 9200 if %verchk% GTR 12527 set unsupbuild=1
  12925. if defined unsupbuild (
  12926. %eline%
  12927. echo Unsupported Office %verchk% is installed on your Windows build version %winbuild%.
  12928. echo Aborting...
  12929. echo:
  12930. set fixes=%fixes% %mas%troubleshoot
  12931. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  12932. goto dk_done
  12933. )
  12934. ::========================================================================================================================================
  12935. :oemenu
  12936. cls
  12937. set fixes=
  12938. if not defined terminal mode 76, 25
  12939. title Change Office Edition %masver%
  12940. echo:
  12941. echo:
  12942. echo:
  12943. echo:
  12944. echo ____________________________________________________________
  12945. echo:
  12946. echo [1] Change all editions
  12947. echo [2] Add edition
  12948. echo [3] Remove edition
  12949. echo:
  12950. echo [4] Add/Remove apps
  12951. echo ____________________________________________
  12952. echo:
  12953. echo [5] Change Office Update Channel
  12954. echo [0] %_exitmsg%
  12955. echo ____________________________________________________________
  12956. echo:
  12957. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,3,4,5,0]"
  12958. choice /C:123450 /N
  12959. set _el=!errorlevel!
  12960. if !_el!==6 exit /b
  12961. if !_el!==5 goto :oe_changeupdchnl
  12962. if !_el!==4 goto :oe_editedition
  12963. if !_el!==3 goto :oe_removeedition
  12964. if !_el!==2 set change=0& goto :oe_edition
  12965. if !_el!==1 set change=1& goto :oe_edition
  12966. goto :oemenu
  12967. ::========================================================================================================================================
  12968. :oe_edition
  12969. cls
  12970. call :oe_chkinternet
  12971. if not defined _int (
  12972. goto :oe_goback
  12973. )
  12974. cls
  12975. if not defined terminal mode 76, 25
  12976. if %change%==1 (
  12977. title Change all editions %masver%
  12978. ) else (
  12979. title Add edition %masver%
  12980. )
  12981. echo:
  12982. echo:
  12983. echo:
  12984. echo:
  12985. echo O365/Mondo editions have the latest features.
  12986. echo ____________________________________________________________
  12987. echo:
  12988. echo [1] Office Suites - Retail
  12989. echo [2] Office Suites - Volume
  12990. echo [3] Office SingleApps - Retail
  12991. echo [4] Office SingleApps - Volume
  12992. echo ____________________________________________
  12993. echo:
  12994. echo [0] Go Back
  12995. echo ____________________________________________________________
  12996. echo:
  12997. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,3,4,0]"
  12998. choice /C:12340 /N
  12999. set _el=!errorlevel!
  13000. if !_el!==5 goto :oemenu
  13001. if !_el!==4 set list=SingleApps_Volume&goto :oe_editionchangepre
  13002. if !_el!==3 set list=SingleApps_Retail&goto :oe_editionchangepre
  13003. if !_el!==2 set list=Suites_Volume&goto :oe_editionchangepre
  13004. if !_el!==1 set list=Suites_Retail&goto :oe_editionchangepre
  13005. goto :oe_edition
  13006. ::========================================================================================================================================
  13007. :oe_editionchangepre
  13008. cls
  13009. call :ch_getinfo
  13010. call :oe_tempcleanup
  13011. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':getlist\:.*';iex ($f[1])"
  13012. :oe_editionchange
  13013. cls
  13014. if not defined terminal (
  13015. mode 98, 45
  13016. %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%
  13017. )
  13018. if not exist %SystemRoot%\Temp\%list%.txt (
  13019. %eline%
  13020. echo Failed to generate available editions list.
  13021. echo:
  13022. set fixes=%fixes% %mas%troubleshoot
  13023. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  13024. goto :oe_goback
  13025. )
  13026. set inpt=
  13027. set counter=0
  13028. set verified=0
  13029. set _notfound=
  13030. set targetedition=
  13031. %line%
  13032. echo:
  13033. call :dk_color %Gray% "Installed Office editions: %_oIds%"
  13034. call :dk_color %Gray% "You can select one of the following Office Editions."
  13035. if %winbuild% LSS 10240 (
  13036. echo Unsupported products such as 2019/2021/2024 are excluded from this list.
  13037. ) else (
  13038. for %%# in (2019 2021 2024) do (
  13039. find /i "%%#" "%SystemRoot%\Temp\%list%.txt" %nul1% || (
  13040. if defined _notfound (set _notfound=%%#, !_notfound!) else (set _notfound=%%#)
  13041. )
  13042. )
  13043. if defined _notfound call :dk_color %Gray% "Office !_notfound! is not in this list because old version [%_version%] of Office is installed."
  13044. )
  13045. %line%
  13046. echo:
  13047. for /f "usebackq delims=" %%A in (%SystemRoot%\Temp\%list%.txt) do (
  13048. set /a counter+=1
  13049. if !counter! LSS 10 (
  13050. echo [!counter!] %%A
  13051. ) else (
  13052. echo [!counter!] %%A
  13053. )
  13054. set targetedition!counter!=%%A
  13055. )
  13056. %line%
  13057. echo:
  13058. echo [0] Go Back
  13059. echo:
  13060. call :dk_color %_Green% "Enter an option number using your keyboard and press Enter to confirm:"
  13061. set /p inpt=
  13062. if "%inpt%"=="" goto :oe_editionchange
  13063. if "%inpt%"=="0" (call :oe_tempcleanup & goto :oe_edition)
  13064. for /l %%i in (1,1,%counter%) do (if "%inpt%"=="%%i" set verified=1)
  13065. set targetedition=!targetedition%inpt%!
  13066. if %verified%==0 goto :oe_editionchange
  13067. ::========================================================================================================================================
  13068. :: Set app exclusions
  13069. :oe_excludeappspre
  13070. cls
  13071. set suites=
  13072. echo %list% | find /i "Suites" %nul1% && (
  13073. set suites=1
  13074. %psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':getappnames\:.*';iex ($f[1])"
  13075. if not exist %SystemRoot%\Temp\getAppIds.txt (
  13076. %eline%
  13077. echo Failed to generate available apps list.
  13078. echo:
  13079. set fixes=%fixes% %mas%troubleshoot
  13080. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  13081. goto :oe_goback
  13082. )
  13083. )
  13084. for %%# in (
  13085. Access
  13086. Excel
  13087. Lync
  13088. OneNote
  13089. Outlook
  13090. PowerPoint
  13091. Project
  13092. Publisher
  13093. Visio
  13094. Word
  13095. ) do (
  13096. if defined suites (
  13097. find /i "%%#" "%SystemRoot%\Temp\getAppIds.txt" %nul1% && (set %%#_st=On) || (set %%#_st=)
  13098. ) else (
  13099. set %%#_st=
  13100. )
  13101. )
  13102. if defined Lync_st set Lync_st=Off
  13103. set OneDrive_st=Off
  13104. if defined suites (set Teams_st=Off) else (set Teams_st=)
  13105. :oe_excludeapps
  13106. cls
  13107. if not defined terminal mode 98, 32
  13108. %line%
  13109. echo:
  13110. call :dk_color %Gray% "Target edition: %targetedition%"
  13111. call :dk_color %Gray% "You can exclude the below apps from installation."
  13112. %line%
  13113. if defined suites echo:
  13114. if defined Access_st echo [A] Access : %Access_st%
  13115. if defined Excel_st echo [E] Excel : %Excel_st%
  13116. if defined OneNote_st echo [N] OneNote : %OneNote_st%
  13117. if defined Outlook_st echo [O] Outlook : %Outlook_st%
  13118. if defined PowerPoint_st echo [P] PowerPoint : %PowerPoint_st%
  13119. if defined Project_st echo [J] Project : %Project_st%
  13120. if defined Publisher_st echo [R] Publisher : %Publisher_st%
  13121. if defined Visio_st echo [V] Visio : %Visio_st%
  13122. if defined Word_st echo [W] Word : %Word_st%
  13123. echo:
  13124. if defined Lync_st echo [L] SkypeForBusiness : %Lync_st%
  13125. if defined OneDrive_st echo [D] OneDrive : %OneDrive_st%
  13126. if defined Teams_st echo [T] Teams : %Teams_st%
  13127. %line%
  13128. echo:
  13129. echo [1] Continue
  13130. echo [0] Go Back
  13131. %line%
  13132. echo:
  13133. call :dk_color %_Green% "Choose a menu option using your keyboard:"
  13134. choice /C:AENOPJRVWLDT10 /N
  13135. set _el=!errorlevel!
  13136. if !_el!==14 goto :oemenu
  13137. if !_el!==13 call :excludelist & goto :oe_editionchangefinal
  13138. if !_el!==12 if defined Teams_st (if "%Teams_st%"=="Off" (set Teams_st=ON) else (set Teams_st=Off))
  13139. if !_el!==11 if defined OneDrive_st (if "%OneDrive_st%"=="Off" (set OneDrive_st=ON) else (set OneDrive_st=Off))
  13140. if !_el!==10 if defined Lync_st (if "%Lync_st%"=="Off" (set Lync_st=ON) else (set Lync_st=Off))
  13141. if !_el!==9 if defined Word_st (if "%Word_st%"=="Off" (set Word_st=ON) else (set Word_st=Off))
  13142. if !_el!==8 if defined Visio_st (if "%Visio_st%"=="Off" (set Visio_st=ON) else (set Visio_st=Off))
  13143. if !_el!==7 if defined Publisher_st (if "%Publisher_st%"=="Off" (set Publisher_st=ON) else (set Publisher_st=Off))
  13144. if !_el!==6 if defined Project_st (if "%Project_st%"=="Off" (set Project_st=ON) else (set Project_st=Off))
  13145. if !_el!==5 if defined PowerPoint_st (if "%PowerPoint_st%"=="Off" (set PowerPoint_st=ON) else (set PowerPoint_st=Off))
  13146. if !_el!==4 if defined Outlook_st (if "%Outlook_st%"=="Off" (set Outlook_st=ON) else (set Outlook_st=Off))
  13147. if !_el!==3 if defined OneNote_st (if "%OneNote_st%"=="Off" (set OneNote_st=ON) else (set OneNote_st=Off))
  13148. if !_el!==2 if defined Excel_st (if "%Excel_st%"=="Off" (set Excel_st=ON) else (set Excel_st=Off))
  13149. if !_el!==1 if defined Access_st (if "%Access_st%"=="Off" (set Access_st=ON) else (set Access_st=Off))
  13150. goto :oe_excludeapps
  13151. :excludelist
  13152. set excludelist=
  13153. for %%# in (
  13154. access
  13155. excel
  13156. onenote
  13157. outlook
  13158. powerpoint
  13159. project
  13160. publisher
  13161. visio
  13162. word
  13163. lync
  13164. onedrive
  13165. teams
  13166. ) do (
  13167. if /i "!%%#_st!"=="Off" if defined excludelist (set excludelist=!excludelist!,%%#) else (set excludelist=,%%#)
  13168. )
  13169. exit /b
  13170. ::========================================================================================================================================
  13171. :: Final command to change/add edition
  13172. :oe_editionchangefinal
  13173. cls
  13174. if not defined terminal mode 105, 32
  13175. :: Check for Project and Visio with unsupported language
  13176. set projvis=
  13177. set langmatched=
  13178. echo: %Project_st% %Visio_st% | find /i "ON" %nul% && set projvis=1
  13179. echo: %targetedition% | findstr /i "Project Visio" %nul% && set projvis=1
  13180. if defined projvis (
  13181. for %%# in (
  13182. ar-sa
  13183. cs-cz
  13184. da-dk
  13185. de-de
  13186. el-gr
  13187. en-us
  13188. es-es
  13189. fi-fi
  13190. fr-fr
  13191. he-il
  13192. hu-hu
  13193. it-it
  13194. ja-jp
  13195. ko-kr
  13196. nb-no
  13197. nl-nl
  13198. pl-pl
  13199. pt-br
  13200. pt-pt
  13201. ro-ro
  13202. ru-ru
  13203. sk-sk
  13204. sl-si
  13205. sv-se
  13206. tr-tr
  13207. uk-ua
  13208. zh-cn
  13209. zh-tw
  13210. ) do (
  13211. if /i "%_lang%"=="%%#" set langmatched=1
  13212. )
  13213. if not defined langmatched (
  13214. %eline%
  13215. echo %_lang% language is not available for Project/Visio apps.
  13216. echo:
  13217. call :dk_color %Blue% "Install Office in the supported language for Project/Visio from the below URL."
  13218. set fixes=%fixes% %mas%genuine-installation-media
  13219. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  13220. goto :oe_goback
  13221. )
  13222. )
  13223. :: Thanks to @abbodi1406 for first discovering OfficeClickToRun.exe uses
  13224. :: Thanks to @may for the suggestion to use it to change edition with CDN as a source
  13225. :: OfficeClickToRun.exe with productstoadd method is used here to add editions
  13226. :: It uses delta updates, meaning that since it's using same installed build, it will consume very less Internet
  13227. set "c2rcommand="%_c2rExe%" platform=%_oArch% culture=%_lang% productstoadd=%targetedition%.16_%_lang%_x-none 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"
  13228. if %change%==1 (
  13229. set "c2rcommand=!c2rcommand! productstoremove=AllProducts"
  13230. )
  13231. echo:
  13232. echo Running the below command, please wait...
  13233. echo:
  13234. echo %c2rcommand%
  13235. %c2rcommand%
  13236. set errorcode=%errorlevel%
  13237. timeout /t 10 %nul%
  13238. echo:
  13239. if %errorcode% EQU 0 (
  13240. call :dk_color %Gray% "Now run the Office activation option from the main menu."
  13241. ) else (
  13242. set fixes=%fixes% %mas%troubleshoot
  13243. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  13244. )
  13245. call :oe_tempcleanup
  13246. goto :oe_goback
  13247. ::========================================================================================================================================
  13248. :: Edit Office edition
  13249. :oe_editedition
  13250. cls
  13251. title Add/Remove Apps %masver%
  13252. call :oe_chkinternet
  13253. if not defined _int (
  13254. goto :oe_goback
  13255. )
  13256. set change=0
  13257. call :ch_getinfo
  13258. cls
  13259. if not defined terminal (
  13260. mode 98, 35
  13261. )
  13262. set inpt=
  13263. set counter=0
  13264. set verified=0
  13265. set targetedition=
  13266. %line%
  13267. echo:
  13268. call :dk_color %Gray% "You can edit [add/remove apps] one of the following Office editions."
  13269. %line%
  13270. echo:
  13271. for %%A in (%_oIds%) do (
  13272. set /a counter+=1
  13273. echo [!counter!] %%A
  13274. set targetedition!counter!=%%A
  13275. )
  13276. %line%
  13277. echo:
  13278. echo [0] Go Back
  13279. echo:
  13280. call :dk_color %_Green% "Enter an option number using your keyboard and press Enter to confirm:"
  13281. set /p inpt=
  13282. if "%inpt%"=="" goto :oe_editedition
  13283. if "%inpt%"=="0" goto :oemenu
  13284. for /l %%i in (1,1,%counter%) do (if "%inpt%"=="%%i" set verified=1)
  13285. set targetedition=!targetedition%inpt%!
  13286. if %verified%==0 goto :oe_editedition
  13287. ::===============
  13288. cls
  13289. if not defined terminal mode 98, 32
  13290. echo %targetedition% | findstr /i "Access Excel OneNote Outlook PowerPoint Project Publisher Skype Visio Word" %nul% && (set list=SingleApps) || (set list=Suites)
  13291. goto :oe_excludeappspre
  13292. ::========================================================================================================================================
  13293. :: Remove Office editions
  13294. :oe_removeedition
  13295. title Remove Office editions %masver%
  13296. call :ch_getinfo
  13297. cls
  13298. if not defined terminal (
  13299. mode 98, 35
  13300. )
  13301. set counter=0
  13302. for %%A in (%_oIds%) do (set /a counter+=1)
  13303. if !counter! LEQ 1 (
  13304. echo:
  13305. echo Only "%_oIds%" product is installed.
  13306. echo This option is available only when multiple products are installed.
  13307. goto :oe_goback
  13308. )
  13309. ::===============
  13310. set inpt=
  13311. set counter=0
  13312. set verified=0
  13313. set targetedition=
  13314. %line%
  13315. echo:
  13316. call :dk_color %Gray% "You can uninstall one of the following Office editions."
  13317. %line%
  13318. echo:
  13319. for %%A in (%_oIds%) do (
  13320. set /a counter+=1
  13321. echo [!counter!] %%A
  13322. set targetedition!counter!=%%A
  13323. )
  13324. %line%
  13325. echo:
  13326. echo [0] Go Back
  13327. echo:
  13328. call :dk_color %_Green% "Enter an option number using your keyboard and press Enter to confirm:"
  13329. set /p inpt=
  13330. if "%inpt%"=="" goto :oe_removeedition
  13331. if "%inpt%"=="0" goto :oemenu
  13332. for /l %%i in (1,1,%counter%) do (if "%inpt%"=="%%i" set verified=1)
  13333. set targetedition=!targetedition%inpt%!
  13334. if %verified%==0 goto :oe_removeedition
  13335. ::===============
  13336. cls
  13337. if not defined terminal mode 105, 32
  13338. set _lang=
  13339. echo "%o16c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=10) || (set _tok=9)
  13340. for /f "tokens=%_tok% delims=\" %%a in ('reg query "%o16c2r_reg%\ProductReleaseIDs\%_actconfig%\%targetedition%.16" /f "-" /k ^| findstr /i ".*16\\.*-.*"') do (
  13341. if defined _lang (set "_lang=!_lang!_%%a") else (set "_lang=_%%a")
  13342. )
  13343. set "c2rcommand="%_c2rExe%" platform=%_oArch% productstoremove=%targetedition%.16%_lang%"
  13344. echo:
  13345. echo Running the below command, please wait...
  13346. echo:
  13347. echo %c2rcommand%
  13348. %c2rcommand%
  13349. if %errorlevel% NEQ 0 (
  13350. echo:
  13351. set fixes=%fixes% %mas%troubleshoot
  13352. call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
  13353. )
  13354. goto :oe_goback
  13355. ::========================================================================================================================================
  13356. :: Change Office update channel
  13357. :oe_changeupdchnl
  13358. title Change Office update channel %masver%
  13359. call :ch_getinfo
  13360. cls
  13361. if not defined terminal (
  13362. mode 98, 33
  13363. )
  13364. call :oe_chkinternet
  13365. if not defined _int (
  13366. goto :oe_goback
  13367. )
  13368. if %winbuild% LSS 10240 (
  13369. echo %_oIds% | findstr "2019 2021 2024" %nul% && (
  13370. %eline%
  13371. echo Installed Office editions: %_oIds%
  13372. echo Unsupported Office edition is installed on your Windows build version %winbuild%.
  13373. goto :oe_goback
  13374. )
  13375. )
  13376. ::===============
  13377. set inpt=
  13378. set counter=0
  13379. set verified=0
  13380. set targetFFN=
  13381. set targetchannel=
  13382. %line%
  13383. echo:
  13384. call :dk_color %Gray% "Installed update channel: %_AudienceData%, %_version%, Client: %_clversion%"
  13385. call :dk_color %Gray% "Unsupported update channels are excluded from this list."
  13386. %line%
  13387. echo:
  13388. for %%# in (
  13389. "5440FD1F-7ECB-4221-8110-145EFAA6372F_Insider Fast [Beta] - Insiders::DevMain"
  13390. "64256AFE-F5D9-4F86-8936-8840A6A4F5BE_Monthly Preview - Insiders::CC"
  13391. "492350F6-3A01-4F97-B9C0-C7C6DDF67D60_Monthly [Current] - Production::CC"
  13392. "55336B82-A18D-4DD6-B5F6-9E5095C314A6_Monthly Enterprise - Production::MEC"
  13393. "B8F9B850-328D-4355-9145-C59439A0C4CF_Semi Annual Preview - Insiders::FRDC"
  13394. "7FFBC6BF-BC32-4F92-8982-F9DD17FD3114_Semi Annual - Production::DC"
  13395. "EA4A4090-DE26-49D7-93C1-91BFF9E53FC3_DevMain Channel - Dogfood::DevMain"
  13396. "B61285DD-D9F7-41F2-9757-8F61CBA4E9C8_Microsoft Elite - Microsoft::DevMain"
  13397. "F2E724C1-748F-4B47-8FB8-8E0D210E9208_Perpetual2019 VL - Production::LTSC"
  13398. "1D2D2EA6-1680-4C56-AC58-A441C8C24FF9_Microsoft2019 VL - Microsoft::LTSC"
  13399. "5030841D-C919-4594-8D2D-84AE4F96E58E_Perpetual2021 VL - Production::LTSC2021"
  13400. "86752282-5841-4120-AC80-DB03AE6B5FDB_Microsoft2021 VL - Microsoft::LTSC2021"
  13401. "7983BAC0-E531-40CF-BE00-FD24FE66619C_Perpetual2024 VL - Production::LTSC2024"
  13402. "C02D8FE6-5242-4DA8-972F-82EE55E00671_Microsoft2024 VL - Microsoft::LTSC2024"
  13403. ) do (
  13404. for /f "tokens=1-2 delims=_" %%A in ("%%~#") do (
  13405. set supported=
  13406. if %winbuild% LSS 10240 (echo %%B | findstr /i "LTSC DevMain" %nul% || set supported=1) else (set supported=1)
  13407. if %winbuild% GEQ 10240 (
  13408. if defined ltsc19 echo %%B | find /i "2019 VL" %nul% || set supported=
  13409. if defined ltsc21 echo %%B | find /i "2021 VL" %nul% || set supported=
  13410. if defined ltsc24 echo %%B | find /i "2024 VL" %nul% || set supported=
  13411. if not defined ltscfound echo %%B | find /i "LTSC" %nul% && set supported=
  13412. )
  13413. if defined supported (
  13414. set /a counter+=1
  13415. if !counter! LSS 10 (
  13416. echo [!counter!] %%B
  13417. ) else (
  13418. echo [!counter!] %%B
  13419. )
  13420. set targetFFN!counter!=%%A
  13421. set targetchannel!counter!=%%B
  13422. )
  13423. )
  13424. )
  13425. %line%
  13426. echo:
  13427. echo [R] Learn about update channels
  13428. echo [0] Go back
  13429. echo:
  13430. call :dk_color %_Green% "Enter an option number using your keyboard and press Enter to confirm:"
  13431. set /p inpt=
  13432. if "%inpt%"=="" goto :oe_changeupdchnl
  13433. if "%inpt%"=="0" goto :oemenu
  13434. if /i "%inpt%"=="R" start https://learn.microsoft.com/microsoft-365-apps/updates/overview-update-channels & goto :oe_changeupdchnl
  13435. for /l %%i in (1,1,%counter%) do (if "%inpt%"=="%%i" set verified=1)
  13436. set targetFFN=!targetFFN%inpt%!
  13437. set targetchannel=!targetchannel%inpt%!
  13438. if %verified%==0 goto :oe_changeupdchnl
  13439. ::=======================
  13440. cls
  13441. if not defined terminal mode 105, 32
  13442. :: Get build number for the target FFN, using build number with OfficeC2RClient.exe command to trigger updates provides accurate results
  13443. set build=
  13444. for /f "delims=" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':getbuild\:.*';iex ($f[1])" %nul6%') do (set build=%%a)
  13445. echo "%build%" | find /i "16." %nul% || set build=
  13446. :: Cleanup Office update related registries, thanks to @abbodi1406
  13447. :: https://techcommunity.microsoft.com/t5/office-365-blog/how-to-manage-office-365-proplus-channels-for-it-pros/ba-p/795813
  13448. :: https://learn.microsoft.com/en-us/microsoft-365-apps/updates/change-update-channels#considerations-when-changing-channels
  13449. echo:
  13450. for /f "tokens=1 delims=-" %%A in ("%targetchannel%") do (echo Target update channel: %%A)
  13451. echo:
  13452. echo Cleaning Office update registry keys...
  13453. echo Adding new update channel to registry keys...
  13454. %nul% reg add %o16c2r_reg%\Configuration /v CDNBaseUrl /t REG_SZ /d "https://officecdn.microsoft.com/pr/%targetFFN%" /f
  13455. %nul% reg add %o16c2r_reg%\Configuration /v UpdateChannel /t REG_SZ /d "https://officecdn.microsoft.com/pr/%targetFFN%" /f
  13456. %nul% reg add %o16c2r_reg%\Configuration /v UpdateChannelChanged /t REG_SZ /d "True" /f
  13457. %nul% reg delete %o16c2r_reg%\Configuration /v UnmanagedUpdateURL /f
  13458. %nul% reg delete %o16c2r_reg%\Configuration /v UpdateUrl /f
  13459. %nul% reg delete %o16c2r_reg%\Configuration /v UpdatePath /f
  13460. %nul% reg delete %o16c2r_reg%\Configuration /v UpdateToVersion /f
  13461. %nul% reg delete %o16c2r_reg%\Updates /v UpdateToVersion /f
  13462. %nul% reg delete HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\officeupdate /f
  13463. %nul% reg delete HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\officeupdate /f /reg:32
  13464. %nul% reg delete HKCU\SOFTWARE\Policies\Microsoft\office\16.0\common\officeupdate /f
  13465. %nul% reg delete HKLM\SOFTWARE\Policies\Microsoft\cloud\office\16.0\Common\officeupdate /f
  13466. %nul% reg delete HKLM\SOFTWARE\Policies\Microsoft\cloud\office\16.0\Common\officeupdate /f /reg:32
  13467. %nul% reg delete HKCU\Software\Policies\Microsoft\cloud\office\16.0\Common\officeupdate /f
  13468. if not defined build (
  13469. if %winbuild% GEQ 9200 call :dk_color %Gray% "Failed to detect build number for the target FFN."
  13470. set "updcommand="%_c2rCexe%" /update user"
  13471. ) else (
  13472. set "updcommand="%_c2rCexe%" /update user updatetoversion=%build%"
  13473. )
  13474. echo Running the below command to trigger updates...
  13475. echo:
  13476. echo %updcommand%
  13477. %updcommand%
  13478. echo:
  13479. echo Help - %mas%troubleshoot
  13480. goto :oe_goback
  13481. ::========================================================================================================================================
  13482. :oe_goback
  13483. call :oe_tempcleanup
  13484. echo:
  13485. if defined fixes (
  13486. call :dk_color %White% "Follow ALL the ABOVE blue lines. "
  13487. call :dk_color2 %Blue% "Press [1] to Open Support Webpage " %Gray% " Press [0] to Ignore"
  13488. choice /C:10 /N
  13489. if !errorlevel!==1 (for %%# in (%fixes%) do (start %%#))
  13490. )
  13491. if defined terminal (
  13492. call :dk_color %_Yellow% "Press [0] key to go back..."
  13493. choice /c 0 /n
  13494. ) else (
  13495. call :dk_color %_Yellow% "Press any key to go back..."
  13496. pause %nul1%
  13497. )
  13498. goto :oemenu
  13499. ::========================================================================================================================================
  13500. :oe_tempcleanup
  13501. del /f /q %SystemRoot%\Temp\SingleApps_Volume.txt %nul%
  13502. del /f /q %SystemRoot%\Temp\SingleApps_Retail.txt %nul%
  13503. del /f /q %SystemRoot%\Temp\Suites_Volume.txt %nul%
  13504. del /f /q %SystemRoot%\Temp\Suites_Retail.txt %nul%
  13505. del /f /q %SystemRoot%\Temp\getAppIds.txt %nul%
  13506. exit /b
  13507. ::========================================================================================================================================
  13508. :: Fetch required info
  13509. :ch_getinfo
  13510. set _oRoot=
  13511. set _oArch=
  13512. set _updch=
  13513. set _oIds=
  13514. set _lang=
  13515. set _cfolder=
  13516. set _version=
  13517. set _clversion=
  13518. set _AudienceData=
  13519. set _actconfig=
  13520. set _c2rXml=
  13521. set _c2rExe=
  13522. set _c2rCexe=
  13523. set _masterxml=
  13524. set ltsc19=
  13525. set ltsc21=
  13526. set ltsc24=
  13527. set ltscfound=
  13528. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  13529. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  13530. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v ClientFolder" %nul6%') do (set "_cfolder=%%b")
  13531. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v AudienceId" %nul6%') do (set "_updch=%%b")
  13532. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v ClientCulture" %nul6%') do (set "_lang=%%b")
  13533. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v ClientVersionToReport" %nul6%') do (set "_clversion=%%b")
  13534. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  13535. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v AudienceData" %nul6%') do (set "_AudienceData=%%b")
  13536. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\ProductReleaseIDs /v ActiveConfiguration" %nul6%') do (set "_actconfig=%%b")
  13537. echo "%o16c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=9) || (set _tok=8)
  13538. for /f "tokens=%_tok% delims=\" %%a in ('reg query "%o16c2r_reg%\ProductReleaseIDs\%_actconfig%" /f ".16" /k %nul6% ^| findstr /i "Retail Volume"') do (
  13539. if defined _oIds (set "_oIds=!_oIds! %%a") else (set "_oIds=%%a")
  13540. )
  13541. set _oIds=%_oIds:.16=%
  13542. set verchk=0
  13543. for /f "tokens=3 delims=." %%a in ("%_version%") do set "verchk=%%a"
  13544. if exist "%_oRoot%\Licenses16\c2rpridslicensefiles_auto.xml" set "_c2rXml=%_oRoot%\Licenses16\c2rpridslicensefiles_auto.xml"
  13545. if exist "%ProgramData%\Microsoft\ClickToRun\ProductReleases\%_actconfig%\x-none.16\MasterDescriptor.x-none.xml" (
  13546. set "_masterxml=%ProgramData%\Microsoft\ClickToRun\ProductReleases\%_actconfig%\x-none.16\MasterDescriptor.x-none.xml"
  13547. )
  13548. if exist "%_cfolder%\OfficeClickToRun.exe" (
  13549. set "_c2rExe=%_cfolder%\OfficeClickToRun.exe"
  13550. )
  13551. if exist "%_cfolder%\OfficeC2RClient.exe" (
  13552. set "_c2rCexe=%_cfolder%\OfficeC2RClient.exe"
  13553. )
  13554. set "audidata4=%_AudienceData:~-4%"
  13555. if /i "%audidata4%"=="LTSC" set ltsc19=LTSC
  13556. echo %_clversion% %_version% | findstr "16.0.103 16.0.104 16.0.105" %nul% && set ltsc19=LTSC
  13557. if /i "%audidata4%"=="2021" set ltsc21=LTSC2021
  13558. echo %_clversion% %_version% | findstr "16.0.14332" %nul% && set ltsc21=LTSC2021
  13559. if /i "%audidata4%"=="2024" set ltsc24=LTSC2024
  13560. :: LTSC 2024 build is not fixed yet
  13561. if not "%ltsc19%%ltsc21%%ltsc24%"=="" set ltscfound=1
  13562. exit /b
  13563. ::========================================================================================================================================
  13564. :: Check Internet connection
  13565. :oe_chkinternet
  13566. set _int=
  13567. for %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (
  13568. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
  13569. )
  13570. if not defined _int (
  13571. %psc% "If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}"
  13572. if !errorlevel!==0 (set _int=1)
  13573. )
  13574. if not defined _int (
  13575. %eline%
  13576. call :dk_color %Red% "Internet is not connected."
  13577. call :dk_color %Blue% "Internet is required for this operation."
  13578. )
  13579. exit /b
  13580. ::========================================================================================================================================
  13581. :: Get available build number for a FFN
  13582. :getbuild:
  13583. $Tls12 = [Enum]::ToObject([System.Net.SecurityProtocolType], 3072)
  13584. [System.Net.ServicePointManager]::SecurityProtocol = $Tls12
  13585. $FFN = $env:targetFFN
  13586. $windowsBuild = [System.Environment]::OSVersion.Version.Build
  13587. $baseUrl = "https://mrodevicemgr.officeapps.live.com/mrodevicemgrsvc/api/v2/C2RReleaseData?audienceFFN=$FFN"
  13588. $url = if ($windowsBuild -lt 9200) { "$baseUrl&osver=Client|6.1" } elseif ($windowsBuild -lt 10240) { "$baseUrl&osver=Client|6.3" } else { $baseUrl }
  13589. $response = if ($windowsBuild -ge 9200) { irm -Uri $url -Method Get } else { (New-Object System.Net.WebClient).DownloadString($url) }
  13590. if ($windowsBuild -lt 9200) {
  13591. if ($response -match '"AvailableBuild"\s*:\s*"([^"]+)"') { Write-Host $matches[1] }
  13592. } else {
  13593. Write-Host $response.AvailableBuild
  13594. }
  13595. :getbuild:
  13596. ::========================================================================================================================================
  13597. :: Get available edition list from c2rpridslicensefiles_auto.xml
  13598. :: and filter the list using MasterDescriptor.x-none.xml
  13599. :: and exclude unsupported products on Windows 7/8/8.1
  13600. :getlist:
  13601. $xmlPath1 = $env:_c2rXml
  13602. $xmlPath2 = $env:_masterxml
  13603. $outputDir = $env:SystemRoot + "\Temp\"
  13604. $buildNumber = [System.Environment]::OSVersion.Version.Build
  13605. $excludedKeywords = @("2019", "2021", "2024")
  13606. $productReleaseIds = @()
  13607. if (Test-Path $xmlPath1) {
  13608. $xml1 = New-Object -TypeName System.Xml.XmlDocument
  13609. $xml1.Load($xmlPath1)
  13610. foreach ($node in $xml1.SelectNodes("//ProductReleaseId")) {
  13611. $id = $node.GetAttribute("id")
  13612. $exclude = $false
  13613. if ($buildNumber -lt 10240) {
  13614. foreach ($keyword in $excludedKeywords) {
  13615. if ($id -match $keyword) { $exclude = $true; break }
  13616. }
  13617. }
  13618. if ($id -ne "CommonLicenseFiles" -and -not $exclude) { $productReleaseIds += $id }
  13619. }
  13620. }
  13621. $categories = @{
  13622. "Suites_Retail" = @(); "Suites_Volume" = @()
  13623. "SingleApps_Retail" = @(); "SingleApps_Volume" = @()
  13624. }
  13625. foreach ($id in $productReleaseIds) {
  13626. $category = if ($id -match "Retail") { "Retail" } else { "Volume" }
  13627. $categories["SingleApps_$category"] += $id
  13628. }
  13629. if (Test-Path $xmlPath2) {
  13630. $xml2 = New-Object -TypeName System.Xml.XmlDocument
  13631. $xml2.Load($xmlPath2)
  13632. foreach ($sku in $xml2.SelectNodes("//SKU")) {
  13633. $skuId = $sku.GetAttribute("ID")
  13634. if ($productReleaseIds -contains $skuId) {
  13635. $appIds = $sku.SelectNodes("Apps/App") | ForEach-Object { $_.GetAttribute("id") }
  13636. if ($appIds -contains "Excel" -and $appIds -contains "Word") {
  13637. $category = if ($skuId -match "Retail") { "Retail" } else { "Volume" }
  13638. $categories["Suites_$category"] += $skuId
  13639. $categories["SingleApps_$category"] = $categories["SingleApps_$category"] | Where-Object { $_ -ne $skuId }
  13640. }
  13641. }
  13642. }
  13643. }
  13644. foreach ($section in $categories.Keys) {
  13645. $filePath = Join-Path -Path $outputDir -ChildPath "$section.txt"
  13646. $ids = $categories[$section]
  13647. if ($ids.Count -gt 0) { $ids | Out-File -FilePath $filePath -Encoding ASCII }
  13648. }
  13649. :getlist:
  13650. ::========================================================================================================================================
  13651. :: Get App list for a specific product ID using MasterDescriptor.x-none.xml
  13652. :getappnames:
  13653. $xmlPath = $env:_masterxml
  13654. $targetSkuId = $env:targetedition
  13655. $outputDir = $env:SystemRoot + "\Temp\"
  13656. $outputFile = Join-Path -Path $outputDir -ChildPath "getAppIds.txt"
  13657. $excludeIds = @("shared", "PowerPivot", "PowerView", "MondoOnly", "OSM", "OSMUX", "Groove", "DCF")
  13658. $xml = New-Object -TypeName System.Xml.XmlDocument
  13659. $xml.Load($xmlPath)
  13660. $appIdsList = @()
  13661. $skuNodes = $xml.SelectNodes("//SKU[@ID='$targetSkuId']")
  13662. foreach ($skuNode in $skuNodes) {
  13663. foreach ($app in $skuNode.SelectNodes("Apps/App")) {
  13664. $appId = $app.GetAttribute("id")
  13665. if ($excludeIds -notcontains $appId) {
  13666. $appIdsList += $appId
  13667. }
  13668. }
  13669. }
  13670. if ($appIdsList.Count -gt 0) {
  13671. $appIdsList | Out-File -FilePath $outputFile -Encoding ASCII
  13672. }
  13673. :getappnames:
  13674. ::========================================================================================================================================
  13675. ::
  13676. :: Leave empty line below