JclSysInfo.pas 218 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083
  1. {**************************************************************************************************}
  2. { }
  3. { Project JEDI Code Library (JCL) }
  4. { }
  5. { The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
  6. { you may not use this file except in compliance with the License. You may obtain a copy of the }
  7. { License at http://www.mozilla.org/MPL/ }
  8. { }
  9. { Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
  10. { ANY KIND, either express or implied. See the License for the specific language governing rights }
  11. { and limitations under the License. }
  12. { }
  13. { The Original Code is JclSysInfo.pas. }
  14. { }
  15. { The Initial Developer of the Original Code is Marcel van Brakel. }
  16. { Portions created by Marcel van Brakel are Copyright (C) Marcel van Brakel. All rights reserved. }
  17. { }
  18. { Contributors: }
  19. { Alexander Radchenko }
  20. { Andre Snepvangers (asnepvangers) }
  21. { Azret Botash }
  22. { Bryan Coutch }
  23. { Carl Clark }
  24. { Eric S. Fisher }
  25. { Florent Ouchet (outchy) }
  26. { Heiko Adams }
  27. { James Azarja }
  28. { Jean-Fabien Connault (cycocrew) }
  29. { John C Molyneux }
  30. { Marcel van Brakel }
  31. { Matthias Thoma (mthoma) }
  32. { Mike Lischke }
  33. { Nick Hodges }
  34. { Olivier Sannier (obones) }
  35. { Peter Friese }
  36. { Peter Thornquist (peter3) }
  37. { Petr Vones (pvones) }
  38. { Rik Barker }
  39. { Robert Marquardt (marquardt) }
  40. { Robert Rossmair (rrossmair) }
  41. { Scott Price }
  42. { Tom Hahn (tomhahn) }
  43. { Wim de Cleen }
  44. { }
  45. {**************************************************************************************************}
  46. { }
  47. { This unit contains routines and classes to retrieve various pieces of system information. }
  48. { Examples are the location of standard folders, settings of environment variables, processor }
  49. { details and the Windows version. }
  50. { }
  51. {**************************************************************************************************}
  52. { }
  53. { Last modified: $Date:: $ }
  54. { Revision: $Rev:: $ }
  55. { Author: $Author:: $ }
  56. { }
  57. {**************************************************************************************************}
  58. // Windows NT 4 and earlier do not support GetSystemPowerStatus (while introduced
  59. // in NT4 - it is a stub there - implemented in Windows 2000 and later.
  60. unit JclSysInfo;
  61. {$I jcl.inc}
  62. interface
  63. uses
  64. {$IFDEF UNITVERSIONING}
  65. JclUnitVersioning,
  66. {$ENDIF UNITVERSIONING}
  67. {$IFDEF HAS_UNIT_LIBC}
  68. Libc,
  69. {$ENDIF HAS_UNIT_LIBC}
  70. {$IFDEF HAS_UNITSCOPE}
  71. {$IFDEF MSWINDOWS}
  72. Winapi.Windows, WinApi.ActiveX, Winapi.ShlObj,
  73. {$ENDIF MSWINDOWS}
  74. System.Classes,
  75. {$ELSE ~HAS_UNITSCOPE}
  76. {$IFDEF MSWINDOWS}
  77. Windows, ActiveX, ShlObj,
  78. {$ENDIF MSWINDOWS}
  79. Classes,
  80. {$ENDIF ~HAS_UNITSCOPE}
  81. JclBase, JclResources;
  82. // Environment Variables
  83. {$IFDEF MSWINDOWS}
  84. type
  85. TEnvironmentOption = (eoLocalMachine, eoCurrentUser, eoAdditional);
  86. TEnvironmentOptions = set of TEnvironmentOption;
  87. {$ENDIF MSWINDOWS}
  88. function DelEnvironmentVar(const Name: string): Boolean;
  89. function ExpandEnvironmentVar(var Value: string): Boolean;
  90. function ExpandEnvironmentVarCustom(var Value: string; Vars: TStrings): Boolean;
  91. function GetEnvironmentVar(const Name: string; out Value: string): Boolean; overload;
  92. function GetEnvironmentVar(const Name: string; out Value: string; Expand: Boolean): Boolean; overload;
  93. function GetEnvironmentVars(const Vars: TStrings): Boolean; overload;
  94. function GetEnvironmentVars(const Vars: TStrings; Expand: Boolean): Boolean; overload;
  95. function SetEnvironmentVar(const Name, Value: string): Boolean;
  96. {$IFDEF MSWINDOWS}
  97. function CreateEnvironmentBlock(const Options: TEnvironmentOptions; const AdditionalVars: TStrings): PChar;
  98. procedure DestroyEnvironmentBlock(var Env: PChar);
  99. procedure SetGlobalEnvironmentVariable(VariableName, VariableContent: string);
  100. {$ENDIF MSWINDOWS}
  101. // Common Folder Locations
  102. {$IFDEF MSWINDOWS}
  103. function GetCommonFilesFolder: string;
  104. {$ENDIF MSWINDOWS}
  105. function GetCurrentFolder: string;
  106. {$IFDEF MSWINDOWS}
  107. function GetProgramFilesFolder: string;
  108. function GetWindowsFolder: string;
  109. function GetWindowsSystemFolder: string;
  110. function GetWindowsTempFolder: string;
  111. function GetDesktopFolder: string;
  112. function GetProgramsFolder: string;
  113. {$ENDIF MSWINDOWS}
  114. function GetPersonalFolder: string;
  115. {$IFDEF MSWINDOWS}
  116. function GetFavoritesFolder: string;
  117. function GetStartupFolder: string;
  118. function GetRecentFolder: string;
  119. function GetSendToFolder: string;
  120. function GetStartmenuFolder: string;
  121. function GetDesktopDirectoryFolder: string;
  122. function GetCommonDocumentsFolder: string;
  123. function GetNethoodFolder: string;
  124. function GetFontsFolder: string;
  125. function GetCommonStartmenuFolder: string;
  126. function GetCommonStartupFolder: string;
  127. function GetPrinthoodFolder: string;
  128. function GetProfileFolder: string;
  129. function GetCommonProgramsFolder: string;
  130. function GetCommonDesktopdirectoryFolder: string;
  131. function GetCommonAppdataFolder: string;
  132. function GetAppdataFolder: string;
  133. function GetLocalAppData: string;
  134. function GetCommonFavoritesFolder: string;
  135. function GetTemplatesFolder: string;
  136. function GetInternetCacheFolder: string;
  137. function GetCookiesFolder: string;
  138. function GetHistoryFolder: string;
  139. // Advanced Power Management (APM)
  140. type
  141. TAPMLineStatus = (alsOffline, alsOnline, alsUnknown);
  142. TAPMBatteryFlag = (abfHigh, abfLow, abfCritical, abfCharging, abfNoBattery, abfUnknown);
  143. TAPMBatteryFlags = set of TAPMBatteryFlag;
  144. function GetAPMLineStatus: TAPMLineStatus;
  145. function GetAPMBatteryFlag: TAPMBatteryFlag;
  146. function GetAPMBatteryFlags: TAPMBatteryFlags;
  147. function GetAPMBatteryLifePercent: Integer;
  148. function GetAPMBatteryLifeTime: DWORD;
  149. function GetAPMBatteryFullLifeTime: DWORD;
  150. // Identification
  151. type
  152. TFileSystemFlag =
  153. (
  154. fsCaseSensitive, // The file system supports case-sensitive file names.
  155. fsCasePreservedNames, // The file system preserves the case of file names when it places a name on disk.
  156. fsSupportsUnicodeOnDisk, // The file system supports Unicode in file names as they appear on disk.
  157. fsPersistentACLs, // The file system preserves and enforces ACLs. For example, NTFS preserves and enforces ACLs, and FAT does not.
  158. fsSupportsFileCompression, // The file system supports file-based compression.
  159. fsSupportsVolumeQuotas, // The file system supports disk quotas.
  160. fsSupportsSparseFiles, // The file system supports sparse files.
  161. fsSupportsReparsePoints, // The file system supports reparse points.
  162. fsSupportsRemoteStorage, // ?
  163. fsVolumeIsCompressed, // The specified volume is a compressed volume; for example, a DoubleSpace volume.
  164. fsSupportsObjectIds, // The file system supports object identifiers.
  165. fsSupportsEncryption, // The file system supports the Encrypted File System (EFS).
  166. fsSupportsNamedStreams, // The file system supports named streams.
  167. fsVolumeIsReadOnly // The specified volume is read-only.
  168. // Windows 2000/NT and Windows Me/98/95: This value is not supported.
  169. );
  170. TFileSystemFlags = set of TFileSystemFlag;
  171. function GetVolumeName(const Drive: string): string;
  172. function GetVolumeSerialNumber(const Drive: string): string;
  173. function GetVolumeFileSystem(const Drive: string): string;
  174. function GetVolumeFileSystemFlags(const Volume: string): TFileSystemFlags;
  175. {$ENDIF MSWINDOWS}
  176. function GetIPAddress(const HostName: string): string;
  177. {$IFDEF MSWINDOWS}
  178. procedure GetIpAddresses(Results: TStrings; const HostName: AnsiString); overload;
  179. {$ENDIF MSWINDOWS}
  180. procedure GetIpAddresses(Results: TStrings); overload;
  181. function GetLocalComputerName: string;
  182. function GetLocalUserName: string;
  183. {$IFDEF MSWINDOWS}
  184. function GetUserDomainName(const CurUser: string): string;
  185. function GetWorkGroupName: WideString;
  186. {$ENDIF MSWINDOWS}
  187. function GetDomainName: string;
  188. {$IFDEF MSWINDOWS}
  189. function GetRegisteredCompany: string;
  190. function GetRegisteredOwner: string;
  191. function GetBIOSName: string;
  192. function GetBIOSCopyright: string;
  193. function GetBIOSExtendedInfo: string;
  194. function GetBIOSDate: TDateTime;
  195. {$ENDIF MSWINDOWS}
  196. // Processes, Tasks and Modules
  197. type
  198. TJclTerminateAppResult = (taError, taClean, taKill);
  199. function RunningProcessesList(const List: TStrings; FullPath: Boolean = True): Boolean;
  200. {$IFDEF MSWINDOWS}
  201. function LoadedModulesList(const List: TStrings; ProcessID: DWORD; HandlesOnly: Boolean = False): Boolean;
  202. function GetTasksList(const List: TStrings): Boolean;
  203. function ModuleFromAddr(const Addr: Pointer): HMODULE;
  204. function IsSystemModule(const Module: HMODULE): Boolean;
  205. function IsMainAppWindow(Wnd: THandle): Boolean;
  206. function IsWindowResponding(Wnd: THandle; Timeout: Integer): Boolean;
  207. function GetWindowIcon(Wnd: THandle; LargeIcon: Boolean): HICON;
  208. function GetWindowCaption(Wnd: THandle): string;
  209. function TerminateTask(Wnd: THandle; Timeout: Integer): TJclTerminateAppResult;
  210. function TerminateApp(ProcessID: DWORD; Timeout: Integer): TJclTerminateAppResult;
  211. {$ENDIF MSWINDOWS}
  212. {$IFDEF MSWINDOWS}
  213. {.$IFNDEF FPC}
  214. function GetPidFromProcessName(const ProcessName: string): THandle;
  215. function GetProcessNameFromWnd(Wnd: THandle): string;
  216. function GetProcessNameFromPid(PID: DWORD): string;
  217. function GetMainAppWndFromPid(PID: DWORD): THandle;
  218. function GetWndFromPid(PID: DWORD; const WindowClassName: string): HWND;
  219. {.$ENDIF ~FPC}
  220. function GetShellProcessName: string;
  221. {.$IFNDEF FPC}
  222. function GetShellProcessHandle: THandle;
  223. {.$ENDIF ~FPC}
  224. // Version Information
  225. type
  226. TWindowsVersion =
  227. (wvUnknown, wvWin95, wvWin95OSR2, wvWin98, wvWin98SE, wvWinME,
  228. wvWinNT31, wvWinNT35, wvWinNT351, wvWinNT4, wvWin2000, wvWinXP,
  229. wvWin2003, wvWinXP64, wvWin2003R2, wvWinVista, wvWinServer2008,
  230. wvWin7, wvWinServer2008R2, wvWin8, wvWin8RT, wvWinServer2012,
  231. wvWin81, wvWin81RT, wvWinServer2012R2, wvWin10, wvWinServer2016);
  232. TWindowsEdition =
  233. (weUnknown, weWinXPHome, weWinXPPro, weWinXPHomeN, weWinXPProN, weWinXPHomeK,
  234. weWinXPProK, weWinXPHomeKN, weWinXPProKN, weWinXPStarter, weWinXPMediaCenter,
  235. weWinXPTablet, weWinVistaStarter, weWinVistaHomeBasic, weWinVistaHomeBasicN,
  236. weWinVistaHomePremium, weWinVistaBusiness, weWinVistaBusinessN,
  237. weWinVistaEnterprise, weWinVistaUltimate, weWin7Starter, weWin7HomeBasic,
  238. weWin7HomePremium, weWin7Professional, weWin7Enterprise, weWin7Ultimate,
  239. weWin8, weWin8Pro, weWin8Enterprise, weWin8RT, weWin81, weWin81Pro,
  240. weWin81Enterprise, weWin81RT, weWin10, weWin10Home, weWin10Pro,
  241. weWin10Enterprise, weWin10Education);
  242. TNtProductType =
  243. (ptUnknown, ptWorkStation, ptServer, ptAdvancedServer,
  244. ptPersonal, ptProfessional, ptDatacenterServer, ptEnterprise, ptWebEdition);
  245. TProcessorArchitecture =
  246. (paUnknown, // unknown processor
  247. pax8632, // x86 32 bit processors (some P4, Celeron, Athlon and older)
  248. pax8664, // x86 64 bit processors (latest P4, Celeron and Athlon64)
  249. paIA64); // Itanium processors
  250. var
  251. { in case of additions, don't forget to update initialization section! }
  252. IsWin95: Boolean = False;
  253. IsWin95OSR2: Boolean = False;
  254. IsWin98: Boolean = False;
  255. IsWin98SE: Boolean = False;
  256. IsWinME: Boolean = False;
  257. IsWinNT: Boolean = False;
  258. IsWinNT3: Boolean = False;
  259. IsWinNT31: Boolean = False;
  260. IsWinNT35: Boolean = False;
  261. IsWinNT351: Boolean = False;
  262. IsWinNT4: Boolean = False;
  263. IsWin2K: Boolean = False;
  264. IsWinXP: Boolean = False;
  265. IsWin2003: Boolean = False;
  266. IsWinXP64: Boolean = False;
  267. IsWin2003R2: Boolean = False;
  268. IsWinVista: Boolean = False;
  269. IsWinServer2008: Boolean = False;
  270. IsWin7: Boolean = False;
  271. IsWinServer2008R2: Boolean = False;
  272. IsWin8: Boolean = False;
  273. IsWin8RT: Boolean = False;
  274. IsWinServer2012: Boolean = False;
  275. IsWin81: Boolean = False;
  276. IsWin81RT: Boolean = False;
  277. IsWinServer2012R2: Boolean = False;
  278. IsWin10: Boolean = False;
  279. IsWinServer2016: Boolean = False;
  280. const
  281. PROCESSOR_ARCHITECTURE_INTEL = 0;
  282. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_INTEL}
  283. PROCESSOR_ARCHITECTURE_AMD64 = 9;
  284. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_AMD64}
  285. PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 = 10;
  286. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_IA32_ON_WIN64}
  287. PROCESSOR_ARCHITECTURE_IA64 = 6;
  288. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_IA64}
  289. function GetWindowsVersion: TWindowsVersion;
  290. function GetWindowsEdition: TWindowsEdition;
  291. function NtProductType: TNtProductType;
  292. function GetWindowsVersionString: string;
  293. function GetWindowsEditionString: string;
  294. function GetWindowsProductString: string;
  295. function NtProductTypeString: string;
  296. function GetWindowsBuildNumber: Integer;
  297. function GetWindowsMajorVersionNumber: Integer;
  298. function GetWindowsMinorVersionNumber: Integer;
  299. function GetWindowsVersionNumber: string;
  300. function GetWindowsServicePackVersion: Integer;
  301. function GetWindowsServicePackVersionString: string;
  302. function GetOpenGLVersion(const Win: THandle; out Version, Vendor: AnsiString): Boolean;
  303. function GetNativeSystemInfo(var SystemInfo: TSystemInfo): Boolean;
  304. function GetProcessorArchitecture: TProcessorArchitecture;
  305. function IsWindows64: Boolean;
  306. function JclCheckWinVersion(Major, Minor: Integer): Boolean;
  307. {$ENDIF MSWINDOWS}
  308. function GetOSVersionString: string;
  309. // Hardware
  310. {$IFDEF MSWINDOWS}
  311. function GetMacAddresses(const Machine: string; const Addresses: TStrings): Integer;
  312. {$ENDIF MSWINDOWS}
  313. function ReadTimeStampCounter: Int64;
  314. {$IFDEF WIN64}
  315. {$EXTERNALSYM ReadTimeStampCounter}
  316. {$ENDIF WIN64}
  317. type
  318. TTLBInformation = (tiEntries, tiAssociativity);
  319. TCacheInformation = (ciLineSize {in Bytes}, ciLinesPerTag, ciAssociativity, ciSize);
  320. TIntelSpecific = record
  321. L2Cache: Cardinal;
  322. CacheDescriptors: array [0..15] of Byte;
  323. BrandID: Byte;
  324. FlushLineSize: Byte;
  325. APICID: Byte;
  326. ExFeatures: Cardinal;
  327. Ex64Features: Cardinal;
  328. Ex64Features2: Cardinal;
  329. PowerManagementFeatures: Cardinal;
  330. PhysicalAddressBits: Byte;
  331. VirtualAddressBits: Byte;
  332. end;
  333. TCyrixSpecific = record
  334. L1CacheInfo: array [0..3] of Byte;
  335. TLBInfo: array [0..3] of Byte;
  336. end;
  337. TAMDSpecific = packed record
  338. ExFeatures: Cardinal;
  339. ExFeatures2: Cardinal;
  340. Features2: Cardinal;
  341. BrandID: Byte;
  342. FlushLineSize: Byte;
  343. APICID: Byte;
  344. ExBrandID: Word;
  345. // do not split L1 MByte TLB
  346. L1MByteInstructionTLB: array [TTLBInformation] of Byte;
  347. L1MByteDataTLB: array [TTLBInformation] of Byte;
  348. // do not split L1 KByte TLB
  349. L1KByteInstructionTLB: array [TTLBInformation] of Byte;
  350. L1KByteDataTLB: array [TTLBInformation] of Byte;
  351. L1DataCache: array [TCacheInformation] of Byte;
  352. L1InstructionCache: array [TCacheInformation] of Byte;
  353. // do not split L2 MByte TLB
  354. L2MByteInstructionTLB: array [TTLBInformation] of Byte; // L2 TLB for 2-MByte and 4-MByte pages
  355. L2MByteDataTLB: array [TTLBInformation] of Byte; // L2 TLB for 2-MByte and 4-MByte pages
  356. // do not split L2 KByte TLB
  357. L2KByteDataTLB: array [TTLBInformation] of Byte; // L2 TLB for 4-KByte pages
  358. L2KByteInstructionTLB: array [TTLBInformation] of Byte; // L2 TLB for 4-KByte pages
  359. L2Cache: Cardinal;
  360. L3Cache: Cardinal;
  361. AdvancedPowerManagement: Cardinal;
  362. PhysicalAddressSize: Byte;
  363. VirtualAddressSize: Byte;
  364. end;
  365. TVIASpecific = record
  366. ExFeatures: Cardinal;
  367. DataTLB: array [TTLBInformation] of Byte;
  368. InstructionTLB: array [TTLBInformation] of Byte;
  369. L1DataCache: array [TCacheInformation] of Byte;
  370. L1InstructionCache: array [TCacheInformation] of Byte;
  371. L2DataCache: Cardinal;
  372. end;
  373. TTransmetaSpecific = record
  374. ExFeatures: Cardinal;
  375. DataTLB: array [TTLBInformation] of Byte;
  376. CodeTLB: array [TTLBInformation] of Byte;
  377. L1DataCache: array [TCacheInformation] of Byte;
  378. L1CodeCache: array [TCacheInformation] of Byte;
  379. L2Cache: Cardinal;
  380. RevisionABCD: Cardinal;
  381. RevisionXXXX: Cardinal;
  382. Frequency: Cardinal;
  383. CodeMorphingABCD: Cardinal;
  384. CodeMorphingXXXX: Cardinal;
  385. TransmetaFeatures: Cardinal;
  386. TransmetaInformations: array [0..64] of Char;
  387. CurrentVoltage: Cardinal;
  388. CurrentFrequency: Cardinal;
  389. CurrentPerformance: Cardinal;
  390. end;
  391. TCacheFamily = (
  392. cfInstructionTLB, cfDataTLB,
  393. cfL1InstructionCache, cfL1DataCache,
  394. cfL2Cache, cfL2TLB, cfL3Cache, cfTrace, cfOther);
  395. TCacheInfo = record
  396. D: Byte;
  397. Family: TCacheFamily;
  398. Size: Cardinal;
  399. WaysOfAssoc: Byte;
  400. LineSize: Byte; // for Normal Cache
  401. LinePerSector: Byte; // for L3 Normal Cache
  402. Entries: Cardinal; // for TLB
  403. I: PResStringRec;
  404. end;
  405. TFreqInfo = record
  406. RawFreq: Int64;
  407. NormFreq: Int64;
  408. InCycles: Int64;
  409. ExTicks: Int64;
  410. end;
  411. const
  412. CPU_TYPE_INTEL = 1;
  413. CPU_TYPE_CYRIX = 2;
  414. CPU_TYPE_AMD = 3;
  415. CPU_TYPE_TRANSMETA = 4;
  416. CPU_TYPE_VIA = 5;
  417. type
  418. TSSESupport = (sse, sse2, sse3, ssse3, sse41, sse42, sse4A, sse5, avx);
  419. TSSESupports = set of TSSESupport;
  420. TCpuInfo = record
  421. HasInstruction: Boolean;
  422. AES: Boolean;
  423. MMX: Boolean;
  424. ExMMX: Boolean;
  425. _3DNow: Boolean;
  426. Ex3DNow: Boolean;
  427. SSE: TSSESupports;
  428. IsFDIVOK: Boolean;
  429. Is64Bits: Boolean;
  430. DEPCapable: Boolean;
  431. HasCacheInfo: Boolean;
  432. HasExtendedInfo: Boolean;
  433. PType: Byte;
  434. Family: Byte;
  435. ExtendedFamily: Byte;
  436. Model: Byte;
  437. ExtendedModel: Byte;
  438. Stepping: Byte;
  439. Features: Cardinal;
  440. FrequencyInfo: TFreqInfo;
  441. VendorIDString: array [0..11] of AnsiChar;
  442. Manufacturer: array [0..9] of AnsiChar;
  443. CpuName: array [0..47] of AnsiChar;
  444. L1DataCacheSize: Cardinal; // in kByte
  445. L1DataCacheLineSize: Byte; // in Byte
  446. L1DataCacheAssociativity: Byte;
  447. L1InstructionCacheSize: Cardinal; // in kByte
  448. L1InstructionCacheLineSize: Byte; // in Byte
  449. L1InstructionCacheAssociativity: Byte;
  450. L2CacheSize: Cardinal; // in kByte
  451. L2CacheLineSize: Byte; // in Byte
  452. L2CacheAssociativity: Byte;
  453. L3CacheSize: Cardinal; // in kByte
  454. L3CacheLineSize: Byte; // in Byte
  455. L3CacheAssociativity: Byte;
  456. L3LinesPerSector: Byte;
  457. LogicalCore: Byte;
  458. PhysicalCore: Byte;
  459. HyperThreadingTechnology: Boolean;
  460. HardwareHyperThreadingTechnology: Boolean;
  461. // todo: TLB
  462. case CpuType: Byte of
  463. CPU_TYPE_INTEL: (IntelSpecific: TIntelSpecific;);
  464. CPU_TYPE_CYRIX: (CyrixSpecific: TCyrixSpecific;);
  465. CPU_TYPE_AMD: (AMDSpecific: TAMDSpecific;);
  466. CPU_TYPE_TRANSMETA: (TransmetaSpecific: TTransmetaSpecific;);
  467. CPU_TYPE_VIA: (ViaSpecific: TViaSpecific;);
  468. end;
  469. const
  470. VendorIDIntel: array [0..11] of AnsiChar = 'GenuineIntel';
  471. VendorIDCyrix: array [0..11] of AnsiChar = 'CyrixInstead';
  472. VendorIDAMD: array [0..11] of AnsiChar = 'AuthenticAMD';
  473. VendorIDTransmeta: array [0..11] of AnsiChar = 'GenuineTMx86';
  474. VendorIDVIA: array [0..11] of AnsiChar = 'CentaurHauls';
  475. // Constants to be used with Feature Flag set of a CPU
  476. // eg. IF (Features and FPU_FLAG = FPU_FLAG) THEN CPU has Floating-Point unit on
  477. // chip. However, Intel claims that in future models, a zero in the feature
  478. // flags will mean that the chip has that feature, however, the following flags
  479. // will work for any production 80x86 chip or clone.
  480. // eg. IF (Features and FPU_FLAG = 0) then CPU has Floating-Point unit on chip.
  481. const
  482. { 32 bits in a DWord Value }
  483. BIT_0 = $00000001;
  484. BIT_1 = $00000002;
  485. BIT_2 = $00000004;
  486. BIT_3 = $00000008;
  487. BIT_4 = $00000010;
  488. BIT_5 = $00000020;
  489. BIT_6 = $00000040;
  490. BIT_7 = $00000080;
  491. BIT_8 = $00000100;
  492. BIT_9 = $00000200;
  493. BIT_10 = $00000400;
  494. BIT_11 = $00000800;
  495. BIT_12 = $00001000;
  496. BIT_13 = $00002000;
  497. BIT_14 = $00004000;
  498. BIT_15 = $00008000;
  499. BIT_16 = $00010000;
  500. BIT_17 = $00020000;
  501. BIT_18 = $00040000;
  502. BIT_19 = $00080000;
  503. BIT_20 = $00100000;
  504. BIT_21 = $00200000;
  505. BIT_22 = $00400000;
  506. BIT_23 = $00800000;
  507. BIT_24 = $01000000;
  508. BIT_25 = $02000000;
  509. BIT_26 = $04000000;
  510. BIT_27 = $08000000;
  511. BIT_28 = $10000000;
  512. BIT_29 = $20000000;
  513. BIT_30 = $40000000;
  514. BIT_31 = DWORD($80000000);
  515. { Standard Feature Flags }
  516. FPU_FLAG = BIT_0; // Floating-Point unit on chip
  517. VME_FLAG = BIT_1; // Virtual Mode Extention
  518. DE_FLAG = BIT_2; // Debugging Extention
  519. PSE_FLAG = BIT_3; // Page Size Extention
  520. TSC_FLAG = BIT_4; // Time Stamp Counter
  521. MSR_FLAG = BIT_5; // Model Specific Registers
  522. PAE_FLAG = BIT_6; // Physical Address Extention
  523. MCE_FLAG = BIT_7; // Machine Check Exception
  524. CX8_FLAG = BIT_8; // CMPXCHG8 Instruction
  525. APIC_FLAG = BIT_9; // Software-accessible local APIC on Chip
  526. BIT_10_FLAG = BIT_10; // Reserved, do not count on value
  527. SEP_FLAG = BIT_11; // Fast System Call
  528. MTRR_FLAG = BIT_12; // Memory Type Range Registers
  529. PGE_FLAG = BIT_13; // Page Global Enable
  530. MCA_FLAG = BIT_14; // Machine Check Architecture
  531. CMOV_FLAG = BIT_15; // Conditional Move Instruction
  532. PAT_FLAG = BIT_16; // Page Attribute Table
  533. PSE36_FLAG = BIT_17; // 36-bit Page Size Extention
  534. PSN_FLAG = BIT_18; // Processor serial number is present and enabled
  535. CLFLSH_FLAG = BIT_19; // CLFLUSH intruction
  536. BIT_20_FLAG = BIT_20; // Reserved, do not count on value
  537. DS_FLAG = BIT_21; // Debug store
  538. ACPI_FLAG = BIT_22; // Thermal monitor and clock control
  539. MMX_FLAG = BIT_23; // MMX technology
  540. FXSR_FLAG = BIT_24; // Fast Floating Point Save and Restore
  541. SSE_FLAG = BIT_25; // Streaming SIMD Extensions
  542. SSE2_FLAG = BIT_26; // Streaming SIMD Extensions 2
  543. SS_FLAG = BIT_27; // Self snoop
  544. HTT_FLAG = BIT_28; // Hyper-threading technology
  545. TM_FLAG = BIT_29; // Thermal monitor
  546. BIT_30_FLAG = BIT_30; // Reserved, do not count on value
  547. PBE_FLAG = BIT_31; // Pending Break Enable
  548. { Standard Intel Feature Flags }
  549. INTEL_FPU = BIT_0; // Floating-Point unit on chip
  550. INTEL_VME = BIT_1; // Virtual Mode Extention
  551. INTEL_DE = BIT_2; // Debugging Extention
  552. INTEL_PSE = BIT_3; // Page Size Extention
  553. INTEL_TSC = BIT_4; // Time Stamp Counter
  554. INTEL_MSR = BIT_5; // Model Specific Registers
  555. INTEL_PAE = BIT_6; // Physical Address Extention
  556. INTEL_MCE = BIT_7; // Machine Check Exception
  557. INTEL_CX8 = BIT_8; // CMPXCHG8 Instruction
  558. INTEL_APIC = BIT_9; // Software-accessible local APIC on Chip
  559. INTEL_BIT_10 = BIT_10; // Reserved, do not count on value
  560. INTEL_SEP = BIT_11; // Fast System Call
  561. INTEL_MTRR = BIT_12; // Memory Type Range Registers
  562. INTEL_PGE = BIT_13; // Page Global Enable
  563. INTEL_MCA = BIT_14; // Machine Check Architecture
  564. INTEL_CMOV = BIT_15; // Conditional Move Instruction
  565. INTEL_PAT = BIT_16; // Page Attribute Table
  566. INTEL_PSE36 = BIT_17; // 36-bit Page Size Extention
  567. INTEL_PSN = BIT_18; // Processor serial number is present and enabled
  568. INTEL_CLFLSH = BIT_19; // CLFLUSH intruction
  569. INTEL_BIT_20 = BIT_20; // Reserved, do not count on value
  570. INTEL_DS = BIT_21; // Debug store
  571. INTEL_ACPI = BIT_22; // Thermal monitor and clock control
  572. INTEL_MMX = BIT_23; // MMX technology
  573. INTEL_FXSR = BIT_24; // Fast Floating Point Save and Restore
  574. INTEL_SSE = BIT_25; // Streaming SIMD Extensions
  575. INTEL_SSE2 = BIT_26; // Streaming SIMD Extensions 2
  576. INTEL_SS = BIT_27; // Self snoop
  577. INTEL_HTT = BIT_28; // Hyper-threading technology
  578. INTEL_TM = BIT_29; // Thermal monitor
  579. INTEL_IA64 = BIT_30; // IA32 emulation mode on Itanium processors (IA64)
  580. INTEL_PBE = BIT_31; // Pending Break Enable
  581. { Extended Intel Feature Flags }
  582. EINTEL_SSE3 = BIT_0; // Streaming SIMD Extensions 3
  583. EINTEL_PCLMULQDQ = BIT_1; // the processor supports the PCLMULQDQ instruction
  584. EINTEL_DTES64 = BIT_2; // the processor supports DS area using 64-bit layout
  585. EINTEL_MONITOR = BIT_3; // Monitor/MWAIT
  586. EINTEL_DSCPL = BIT_4; // CPL Qualified debug Store
  587. EINTEL_VMX = BIT_5; // Virtual Machine Technology
  588. EINTEL_SMX = BIT_6; // Safer Mode Extensions
  589. EINTEL_EST = BIT_7; // Enhanced Intel Speedstep technology
  590. EINTEL_TM2 = BIT_8; // Thermal monitor 2
  591. EINTEL_SSSE3 = BIT_9; // SSSE 3 extensions
  592. EINTEL_CNXTID = BIT_10; // L1 Context ID
  593. EINTEL_BIT_11 = BIT_11; // Reserved, do not count on value
  594. EINTEL_FMA = BIT_12; // Fused Multiply Add
  595. EINTEL_CX16 = BIT_13; // CMPXCHG16B instruction
  596. EINTEL_XTPR = BIT_14; // Send Task Priority messages
  597. EINTEL_PDCM = BIT_15; // Perf/Debug Capability MSR
  598. EINTEL_BIT_16 = BIT_16; // Reserved, do not count on value
  599. EINTEL_PCID = BIT_17; // Process-context Identifiers
  600. EINTEL_DCA = BIT_18; // Direct Cache Access
  601. EINTEL_SSE4_1 = BIT_19; // Streaming SIMD Extensions 4.1
  602. EINTEL_SSE4_2 = BIT_20; // Streaming SIMD Extensions 4.2
  603. EINTEL_X2APIC = BIT_21; // x2APIC feature
  604. EINTEL_MOVBE = BIT_22; // MOVBE instruction
  605. EINTEL_POPCNT = BIT_23; // A value of 1 indicates the processor supports the POPCNT instruction.
  606. EINTEL_TSC_DL = BIT_24; // TSC-Deadline
  607. EINTEL_AES = BIT_25; // the processor supports the AES instruction extensions
  608. EINTEL_XSAVE = BIT_26; // XSAVE/XRSTOR processor extended states feature, XSETBV/XGETBV instructions and XFEATURE_ENABLED_MASK (XCR0) register
  609. EINTEL_OSXSAVE = BIT_27; // OS has enabled features present in EINTEL_XSAVE
  610. EINTEL_AVX = BIT_28; // Advanced Vector Extensions
  611. EINTEL_BIT_29 = BIT_29; // Reserved, do not count on value
  612. EINTEL_RDRAND = BIT_30; // the processor supports the RDRAND instruction.
  613. EINTEL_BIT_31 = BIT_31; // Always return 0
  614. { Extended Intel 64 Bits Feature Flags }
  615. EINTEL64_BIT_0 = BIT_0; // Reserved, do not count on value
  616. EINTEL64_BIT_1 = BIT_1; // Reserved, do not count on value
  617. EINTEL64_BIT_2 = BIT_2; // Reserved, do not count on value
  618. EINTEL64_BIT_3 = BIT_3; // Reserved, do not count on value
  619. EINTEL64_BIT_4 = BIT_4; // Reserved, do not count on value
  620. EINTEL64_BIT_5 = BIT_5; // Reserved, do not count on value
  621. EINTEL64_BIT_6 = BIT_6; // Reserved, do not count on value
  622. EINTEL64_BIT_7 = BIT_7; // Reserved, do not count on value
  623. EINTEL64_BIT_8 = BIT_8; // Reserved, do not count on value
  624. EINTEL64_BIT_9 = BIT_9; // Reserved, do not count on value
  625. EINTEL64_BIT_10 = BIT_10; // Reserved, do not count on value
  626. EINTEL64_SYS = BIT_11; // 64 Bit - SYSCALL SYSRET
  627. EINTEL64_BIT_12 = BIT_12; // Reserved, do not count on value
  628. EINTEL64_BIT_13 = BIT_13; // Reserved, do not count on value
  629. EINTEL64_BIT_14 = BIT_14; // Reserved, do not count on value
  630. EINTEL64_BIT_15 = BIT_15; // Reserved, do not count on value
  631. EINTEL64_BIT_16 = BIT_16; // Reserved, do not count on value
  632. EINTEL64_BIT_17 = BIT_17; // Reserved, do not count on value
  633. EINTEL64_BIT_18 = BIT_18; // Reserved, do not count on value
  634. EINTEL64_BIT_19 = BIT_19; // Reserved, do not count on value
  635. EINTEL64_XD = BIT_20; // Execution Disable Bit
  636. EINTEL64_BIT_21 = BIT_21; // Reserved, do not count on value
  637. EINTEL64_BIT_22 = BIT_22; // Reserved, do not count on value
  638. EINTEL64_BIT_23 = BIT_23; // Reserved, do not count on value
  639. EINTEL64_BIT_24 = BIT_24; // Reserved, do not count on value
  640. EINTEL64_BIT_25 = BIT_25; // Reserved, do not count on value
  641. EINTEL64_1GBYTE = BIT_26; // 1G-Byte pages are available
  642. EINTEL64_RDTSCP = BIT_27; // RDTSCP and IA32_TSC_AUX are available
  643. EINTEL64_BIT_28 = BIT_28; // Reserved, do not count on value
  644. EINTEL64_EM64T = BIT_29; // Intel Extended Memory 64 Technology
  645. EINTEL64_BIT_30 = BIT_30; // Reserved, do not count on value
  646. EINTEL64_BIT_31 = BIT_31; // Reserved, do not count on value
  647. { Extended Intel 64 Bits Feature Flags continued }
  648. EINTEL64_2_LAHF = BIT_0; // LAHF/SAHF available in 64 bit mode
  649. EINTEL64_2_BIT_1 = BIT_1; // Reserved, do not count on value
  650. EINTEL64_2_BIT_2 = BIT_2; // Reserved, do not count on value
  651. EINTEL64_2_BIT_3 = BIT_3; // Reserved, do not count on value
  652. EINTEL64_2_BIT_4 = BIT_4; // Reserved, do not count on value
  653. EINTEL64_2_BIT_5 = BIT_5; // Reserved, do not count on value
  654. EINTEL64_2_BIT_6 = BIT_6; // Reserved, do not count on value
  655. EINTEL64_2_BIT_7 = BIT_7; // Reserved, do not count on value
  656. EINTEL64_2_BIT_8 = BIT_8; // Reserved, do not count on value
  657. EINTEL64_2_BIT_9 = BIT_9; // Reserved, do not count on value
  658. EINTEL64_2_BIT_10 = BIT_10; // Reserved, do not count on value
  659. EINTEL64_2_BIT_11 = BIT_11; // Reserved, do not count on value
  660. EINTEL64_2_BIT_12 = BIT_12; // Reserved, do not count on value
  661. EINTEL64_2_BIT_13 = BIT_13; // Reserved, do not count on value
  662. EINTEL64_2_BIT_14 = BIT_14; // Reserved, do not count on value
  663. EINTEL64_2_BIT_15 = BIT_15; // Reserved, do not count on value
  664. EINTEL64_2_BIT_16 = BIT_16; // Reserved, do not count on value
  665. EINTEL64_2_BIT_17 = BIT_17; // Reserved, do not count on value
  666. EINTEL64_2_BIT_18 = BIT_18; // Reserved, do not count on value
  667. EINTEL64_2_BIT_19 = BIT_19; // Reserved, do not count on value
  668. EINTEL64_2_BIT_20 = BIT_20; // Reserved, do not count on value
  669. EINTEL64_2_BIT_21 = BIT_21; // Reserved, do not count on value
  670. EINTEL64_2_BIT_22 = BIT_22; // Reserved, do not count on value
  671. EINTEL64_2_BIT_23 = BIT_23; // Reserved, do not count on value
  672. EINTEL64_2_BIT_24 = BIT_24; // Reserved, do not count on value
  673. EINTEL64_2_BIT_25 = BIT_25; // Reserved, do not count on value
  674. EINTEL64_2_BIT_26 = BIT_26; // Reserved, do not count on value
  675. EINTEL64_2_BIT_27 = BIT_27; // Reserved, do not count on value
  676. EINTEL64_2_BIT_28 = BIT_28; // Reserved, do not count on value
  677. EINTEL64_2_BIT_29 = BIT_29; // Reserved, do not count on value
  678. EINTEL64_2_BIT_30 = BIT_30; // Reserved, do not count on value
  679. EINTEL64_2_BIT_31 = BIT_31; // Reserved, do not count on value
  680. { INTEL Power Management Flags }
  681. PINTEL_TEMPSENSOR = BIT_0; // Digital temperature sensor
  682. PINTEL_TURBOBOOST = BIT_1; // Intel Turbo Boost Technology Available
  683. PINTEL_ARAT = BIT_2; // APIC-Timer-always-running feature
  684. PINTEL_BIT_3 = BIT_3; // Reverved, do not count on value
  685. PINTEL_PLN = BIT_4; // Power Limit Notification constrols
  686. PINTEL_ECMD = BIT_5; // Clock Modulation duty cycle extension
  687. PINTEL_PTM = BIT_6; // Package Thermal Management
  688. PINTEL_BIT_7 = BIT_7; // Reserved, do not count on value
  689. PINTEL_BIT_8 = BIT_8; // Reserved, do not count on value
  690. PINTEL_BIT_9 = BIT_9; // Reserved, do not count on value
  691. PINTEL_BIT_10 = BIT_10; // Reserved, do not count on value
  692. PINTEL_BIT_11 = BIT_11; // Reserved, do not count on value
  693. PINTEL_BIT_12 = BIT_12; // Reserved, do not count on value
  694. PINTEL_BIT_13 = BIT_13; // Reserved, do not count on value
  695. PINTEL_BIT_14 = BIT_14; // Reserved, do not count on value
  696. PINTEL_BIT_15 = BIT_15; // Reserved, do not count on value
  697. PINTEL_BIT_16 = BIT_16; // Reserved, do not count on value
  698. PINTEL_BIT_17 = BIT_17; // Reserved, do not count on value
  699. PINTEL_BIT_18 = BIT_18; // Reserved, do not count on value
  700. PINTEL_BIT_19 = BIT_19; // Reserved, do not count on value
  701. PINTEL_BIT_20 = BIT_20; // Reserved, do not count on value
  702. PINTEL_BIT_21 = BIT_21; // Reserved, do not count on value
  703. PINTEL_BIT_22 = BIT_22; // Reserved, do not count on value
  704. PINTEL_BIT_23 = BIT_23; // Reserved, do not count on value
  705. PINTEL_BIT_24 = BIT_24; // Reserved, do not count on value
  706. PINTEL_BIT_25 = BIT_25; // Reserved, do not count on value
  707. PINTEL_BIT_26 = BIT_26; // Reserved, do not count on value
  708. PINTEL_BIT_27 = BIT_27; // Reserved, do not count on value
  709. PINTEL_BIT_28 = BIT_28; // Reserved, do not count on value
  710. PINTEL_BIT_29 = BIT_29; // Reserved, do not count on value
  711. PINTEL_BIT_30 = BIT_30; // Reserved, do not count on value
  712. PINTEL_BIT_31 = BIT_31; // Reserved, do not count on value
  713. { AMD Standard Feature Flags }
  714. AMD_FPU = BIT_0; // Floating-Point unit on chip
  715. AMD_VME = BIT_1; // Virtual Mode Extention
  716. AMD_DE = BIT_2; // Debugging Extention
  717. AMD_PSE = BIT_3; // Page Size Extention
  718. AMD_TSC = BIT_4; // Time Stamp Counter
  719. AMD_MSR = BIT_5; // Model Specific Registers
  720. AMD_PAE = BIT_6; // Physical address Extensions
  721. AMD_MCE = BIT_7; // Machine Check Exception
  722. AMD_CX8 = BIT_8; // CMPXCHG8 Instruction
  723. AMD_APIC = BIT_9; // Software-accessible local APIC on Chip
  724. AMD_BIT_10 = BIT_10; // Reserved, do not count on value
  725. AMD_SEP_BIT = BIT_11; // SYSENTER and SYSEXIT instructions
  726. AMD_MTRR = BIT_12; // Memory Type Range Registers
  727. AMD_PGE = BIT_13; // Page Global Enable
  728. AMD_MCA = BIT_14; // Machine Check Architecture
  729. AMD_CMOV = BIT_15; // Conditional Move Instruction
  730. AMD_PAT = BIT_16; // Page Attribute Table
  731. AMD_PSE36 = BIT_17; // Page Size Extensions
  732. AMD_BIT_18 = BIT_18; // Reserved, do not count on value
  733. AMD_CLFLSH = BIT_19; // CLFLUSH instruction
  734. AMD_BIT_20 = BIT_20; // Reserved, do not count on value
  735. AMD_BIT_21 = BIT_21; // Reserved, do not count on value
  736. AMD_BIT_22 = BIT_22; // Reserved, do not count on value
  737. AMD_MMX = BIT_23; // MMX technology
  738. AMD_FXSR = BIT_24; // FXSAVE and FXSTORE instructions
  739. AMD_SSE = BIT_25; // SSE Extensions
  740. AMD_SSE2 = BIT_26; // SSE2 Extensions
  741. AMD_BIT_27 = BIT_27; // Reserved, do not count on value
  742. AMD_HTT = BIT_28; // Hyper-Threading Technology
  743. AMD_BIT_29 = BIT_29; // Reserved, do not count on value
  744. AMD_BIT_30 = BIT_30; // Reserved, do not count on value
  745. AMD_BIT_31 = BIT_31; // Reserved, do not count on value
  746. { AMD Standard Feature Flags continued }
  747. AMD2_SSE3 = BIT_0; // SSE3 extensions
  748. AMD2_PCLMULQDQ = BIT_1; // PCLMULQDQ instruction support
  749. AMD2_BIT_2 = BIT_2; // Reserved, do not count on value
  750. AMD2_MONITOR = BIT_3; // MONITOR/MWAIT instructions. See "MONITOR" and "MWAIT" in APM3.
  751. AMD2_BIT_4 = BIT_4; // Reserved, do not count on value
  752. AMD2_BIT_5 = BIT_5; // Reserved, do not count on value
  753. AMD2_BIT_6 = BIT_6; // Reserved, do not count on value
  754. AMD2_BIT_7 = BIT_7; // Reserved, do not count on value
  755. AMD2_BIT_8 = BIT_8; // Reserved, do not count on value
  756. AMD2_SSSE3 = BIT_9; // supplemental SSE3 extensions
  757. AMD2_BIT_10 = BIT_10; // Reserved, do not count on value
  758. AMD2_BIT_11 = BIT_11; // Reserved, do not count on value
  759. AMD2_FMA = BIT_12; // FMA instruction support
  760. AMD2_CMPXCHG16B = BIT_13; // CMPXCHG16B available
  761. AMD2_BIT_14 = BIT_14; // Reserved, do not count on value
  762. AMD2_BIT_15 = BIT_15; // Reserved, do not count on value
  763. AMD2_BIT_16 = BIT_16; // Reserved, do not count on value
  764. AMD2_BIT_17 = BIT_17; // Reserved, do not count on value
  765. AMD2_BIT_18 = BIT_18; // Reserved, do not count on value
  766. AMD2_SSE41 = BIT_19; // SSE4.1 instruction support
  767. AMD2_SSE42 = BIT_20; // SSE4.2 instruction support
  768. AMD2_BIT_21 = BIT_21; // Reserved, do not count on value
  769. AMD2_BIT_22 = BIT_22; // Reserved, do not count on value
  770. AMD2_POPCNT = BIT_23; // POPCNT instruction. See "POPCNT" in APM3.
  771. AMD2_BIT_24 = BIT_24; // Reserved, do not count on value
  772. AMD2_AES = BIT_25; // AES instruction support
  773. AMD2_XSAVE = BIT_26; // XSAVE (and related) instructions are supported by hardware
  774. AMD2_OSXSAVE = BIT_27; // XSAVE (and related) instructions are enabled
  775. AMD2_AVX = BIT_28; // AVX instruction support
  776. AMD2_F16C = BIT_29; // half-precision convert instruction support
  777. AMD2_BIT_30 = BIT_30; // Reserved, do not count on value
  778. AMD2_RAZ = BIT_31; // Reserved for use by hypervisor to indicate guest status
  779. { AMD Enhanced Feature Flags }
  780. EAMD_FPU = BIT_0; // Floating-Point unit on chip
  781. EAMD_VME = BIT_1; // Virtual Mode Extention
  782. EAMD_DE = BIT_2; // Debugging Extention
  783. EAMD_PSE = BIT_3; // Page Size Extention
  784. EAMD_TSC = BIT_4; // Time Stamp Counter
  785. EAMD_MSR = BIT_5; // Model Specific Registers
  786. EAMD_PAE = BIT_6; // Physical-address extensions
  787. EAMD_MCE = BIT_7; // Machine Check Exception
  788. EAMD_CX8 = BIT_8; // CMPXCHG8 Instruction
  789. EAMD_APIC = BIT_9; // Advanced Programmable Interrupt Controler
  790. EAMD_BIT_10 = BIT_10; // Reserved, do not count on value
  791. EAMD_SEP = BIT_11; // Fast System Call
  792. EAMD_MTRR = BIT_12; // Memory-Type Range Registers
  793. EAMD_PGE = BIT_13; // Page Global Enable
  794. EAMD_MCA = BIT_14; // Machine Check Architecture
  795. EAMD_CMOV = BIT_15; // Conditional Move Intructions
  796. EAMD_PAT = BIT_16; // Page Attributes Table
  797. EAMD_PSE2 = BIT_17; // Page Size Extensions
  798. EAMD_BIT_18 = BIT_18; // Reserved, do not count on value
  799. EAMD_BIT_19 = BIT_19; // Reserved, do not count on value
  800. EAMD_NX = BIT_20; // No-Execute Page Protection
  801. EAMD_BIT_21 = BIT_21; // Reserved, do not count on value
  802. EAMD_EXMMX = BIT_22; // AMD Extensions to MMX technology
  803. EAMD_MMX = BIT_23; // MMX technology
  804. EAMD_FX = BIT_24; // FXSAVE and FXSTORE instructions
  805. EAMD_FFX = BIT_25; // Fast FXSAVE and FXSTORE instructions
  806. EAMD_1GBPAGE = BIT_26; // 1-GB large page support.
  807. EAMD_RDTSCP = BIT_27; // RDTSCP instruction.
  808. EAMD_BIT_28 = BIT_28; // Reserved, do not count on value
  809. EAMD_LONG = BIT_29; // Long Mode (64-bit Core)
  810. EAMD_EX3DNOW = BIT_30; // AMD Extensions to 3DNow! intructions
  811. EAMD_3DNOW = BIT_31; // AMD 3DNOW! Technology
  812. { AMD Extended Feature Flags continued }
  813. EAMD2_LAHF = BIT_0; // LAHF/SAHF available in 64-bit mode
  814. EAMD2_CMPLEGACY = BIT_1; // core multi-processing legacy mode
  815. EAMD2_SVM = BIT_2; // Secure Virtual Machine
  816. EAMD2_EXTAPICSPACE = BIT_3; // This bit indicates the presence of extended APIC register space starting at offset 400h from the “APIC Base Address Register,” as specified in the BKDG.
  817. EAMD2_ALTMOVCR8 = BIT_4; // LOCK MOV CR0 means MOV CR8
  818. EAMD2_ABM = BIT_5; // ABM: Advanced bit manipulation. LZCNT instruction support.
  819. EAMD2_SSE4A = BIT_6; // EXTRQ, INSERTQ, MOVNTSS, and MOVNTSD instruction support.
  820. EAMD2_MISALIGNSSE = BIT_7; // Misaligned SSE mode.
  821. EAMD2_3DNOWPREFETCH = BIT_8; // PREFETCH and PREFETCHW instruction support.
  822. EAMD2_OSVW = BIT_9; // OS visible workaround.
  823. EAMD2_IBS = BIT_10; // Instruction based sampling
  824. EAMD2_XOP = BIT_11; // extended operation support
  825. EAMD2_SKINIT = BIT_12; // SKINIT, STGI, and DEV support.
  826. EAMD2_WDT = BIT_13; // Watchdog timer support.
  827. EAMD2_BIT_14 = BIT_14; // Reserved, do not count on value
  828. EAMD2_LWP = BIT_15; // lightweight profiling support
  829. EAMD2_FMA4 = BIT_16; // 4-operand FMA instruction support.
  830. EAMD2_BIT_17 = BIT_17; // Reserved, do not count on value
  831. EAMD2_BIT_18 = BIT_18; // Reserved, do not count on value
  832. EAMD2_NODEID = BIT_19; // Support for MSRC001_100C[NodeId, NodesPerProcessor]
  833. EAMD2_BIT_20 = BIT_20; // Reserved, do not count on value
  834. EAMD2_TBM = BIT_21; // trailing bit manipulation instruction support
  835. EAMD2_TOPOLOGYEXT = BIT_22; // topology extensions support
  836. EAMD2_BIT_23 = BIT_23; // Reserved, do not count on value
  837. EAMD2_BIT_24 = BIT_24; // Reserved, do not count on value
  838. EAMD2_BIT_25 = BIT_25; // Reserved, do not count on value
  839. EAMD2_BIT_26 = BIT_26; // Reserved, do not count on value
  840. EAMD2_BIT_27 = BIT_27; // Reserved, do not count on value
  841. EAMD2_BIT_28 = BIT_28; // Reserved, do not count on value
  842. EAMD2_BIT_29 = BIT_29; // Reserved, do not count on value
  843. EAMD2_BIT_30 = BIT_30; // Reserved, do not count on value
  844. EAMD2_BIT_31 = BIT_31; // Reserved, do not count on value
  845. { AMD Power Management Features Flags }
  846. PAMD_TEMPSENSOR = BIT_0; // Temperature Sensor
  847. PAMD_FREQUENCYID = BIT_1; // Frequency ID Control
  848. PAMD_VOLTAGEID = BIT_2; // Voltage ID Control
  849. PAMD_THERMALTRIP = BIT_3; // Thermal Trip
  850. PAMD_THERMALMONITOR = BIT_4; // Thermal Monitoring
  851. PAMD_BIT_5 = BIT_5; // Reserved, do not count on value
  852. PAMD_100MHZSTEP = BIT_6; // 100 Mhz multiplier control.
  853. PAMD_HWPSTATE = BIT_7; // Hardware P-State control.
  854. PAMD_TSC_INVARIANT = BIT_8; // TSC rate is invariant
  855. PAMD_CPB = BIT_9; // core performance boost
  856. PAMD_EFFFREQRO = BIT_10; // read-only effective frequency interface
  857. PAMD_BIT_11 = BIT_11; // Reserved, do not count on value
  858. PAMD_BIT_12 = BIT_12; // Reserved, do not count on value
  859. PAMD_BIT_13 = BIT_13; // Reserved, do not count on value
  860. PAMD_BIT_14 = BIT_14; // Reserved, do not count on value
  861. PAMD_BIT_15 = BIT_15; // Reserved, do not count on value
  862. PAMD_BIT_16 = BIT_16; // Reserved, do not count on value
  863. PAMD_BIT_17 = BIT_17; // Reserved, do not count on value
  864. PAMD_BIT_18 = BIT_18; // Reserved, do not count on value
  865. PAMD_BIT_19 = BIT_19; // Reserved, do not count on value
  866. PAMD_BIT_20 = BIT_20; // Reserved, do not count on value
  867. PAMD_BIT_21 = BIT_21; // Reserved, do not count on value
  868. PAMD_BIT_22 = BIT_22; // Reserved, do not count on value
  869. PAMD_BIT_23 = BIT_23; // Reserved, do not count on value
  870. PAMD_BIT_24 = BIT_24; // Reserved, do not count on value
  871. PAMD_BIT_25 = BIT_25; // Reserved, do not count on value
  872. PAMD_BIT_26 = BIT_26; // Reserved, do not count on value
  873. PAMD_BIT_27 = BIT_27; // Reserved, do not count on value
  874. PAMD_BIT_28 = BIT_28; // Reserved, do not count on value
  875. PAMD_BIT_29 = BIT_29; // Reserved, do not count on value
  876. PAMD_BIT_30 = BIT_30; // Reserved, do not count on value
  877. PAMD_BIT_31 = BIT_31; // Reserved, do not count on value
  878. { AMD TLB and L1 Associativity constants }
  879. AMD_ASSOC_RESERVED = 0;
  880. AMD_ASSOC_DIRECT = 1;
  881. // 2 to 254 = direct value to the associativity
  882. AMD_ASSOC_FULLY = 255;
  883. { AMD L2 Cache Associativity constants }
  884. AMD_L2_ASSOC_DISABLED = 0;
  885. AMD_L2_ASSOC_DIRECT = 1;
  886. AMD_L2_ASSOC_2WAY = 2;
  887. AMD_L2_ASSOC_4WAY = 4;
  888. AMD_L2_ASSOC_8WAY = 6;
  889. AMD_L2_ASSOC_16WAY = 8;
  890. AMD_L2_ASSOC_32WAY = 10;
  891. AMD_L2_ASSOC_48WAY = 11;
  892. AMD_L2_ASSOC_64WAY = 12;
  893. AMD_L2_ASSOC_96WAY = 13;
  894. AMD_L2_ASSOC_128WAY = 14;
  895. AMD_L2_ASSOC_FULLY = 15;
  896. // TODO AMD SVM and LWP bits
  897. { VIA Standard Feature Flags }
  898. VIA_FPU = BIT_0; // FPU present
  899. VIA_VME = BIT_1; // Virtual Mode Extension
  900. VIA_DE = BIT_2; // Debugging extensions
  901. VIA_PSE = BIT_3; // Page Size Extensions (4MB)
  902. VIA_TSC = BIT_4; // Time Stamp Counter
  903. VIA_MSR = BIT_5; // Model Specific Registers
  904. VIA_PAE = BIT_6; // Physical Address Extension
  905. VIA_MCE = BIT_7; // Machine Check Exception
  906. VIA_CX8 = BIT_8; // CMPXCHG8B instruction
  907. VIA_APIC = BIT_9; // APIC supported
  908. VIA_BIT_10 = BIT_10; // Reserved, do not count on value
  909. VIA_SEP = BIT_11; // Fast System Call
  910. VIA_MTRR = BIT_12; // Memory Range Registers
  911. VIA_PTE = BIT_13; // PTE Global Bit
  912. VIA_MCA = BIT_14; // Machine Check Architecture
  913. VIA_CMOVE = BIT_15; // Conditional Move
  914. VIA_PAT = BIT_16; // Page Attribute Table
  915. VIA_PSE2 = BIT_17; // 36-bit Page Size Extension
  916. VIA_SNUM = BIT_18; // Processor serial number
  917. VIA_BIT_19 = BIT_19; // Reserved, do not count on value
  918. VIA_BIT_20 = BIT_20; // Reserved, do not count on value
  919. VIA_BIT_21 = BIT_21; // Reserved, do not count on value
  920. VIA_BIT_22 = BIT_22; // Reserved, do not count on value
  921. VIA_MMX = BIT_23; // MMX
  922. VIA_FX = BIT_24; // FXSAVE and FXSTORE instructions
  923. VIA_SSE = BIT_25; // Streaming SIMD Extension
  924. VIA_BIT_26 = BIT_26; // Reserved, do not count on value
  925. VIA_BIT_27 = BIT_27; // Reserved, do not count on value
  926. VIA_BIT_28 = BIT_28; // Reserved, do not count on value
  927. VIA_BIT_29 = BIT_29; // Reserved, do not count on value
  928. VIA_BIT_30 = BIT_30; // Reserved, do not count on value
  929. VIA_3DNOW = BIT_31; // 3DNow! Technology
  930. { VIA Extended Feature Flags }
  931. EVIA_AIS = BIT_0; // Alternate Instruction Set
  932. EVIA_AISE = BIT_1; // Alternate Instruction Set Enabled
  933. EVIA_NO_RNG = BIT_2; // NO Random Number Generator
  934. EVIA_RNGE = BIT_3; // Random Number Generator Enabled
  935. EVIA_MSR = BIT_4; // Longhaul MSR 0x110A available
  936. EVIA_FEMMS = BIT_5; // FEMMS instruction Present
  937. EVIA_NO_ACE = BIT_6; // Advanced Cryptography Engine NOT Present
  938. EVIA_ACEE = BIT_7; // ACE Enabled
  939. EVIA_BIT_8 = BIT_8; // Reserved, do not count on value
  940. EVIA_BIT_9 = BIT_9; // Reserved, do not count on value
  941. EVIA_BIT_10 = BIT_10; // Reserved, do not count on value
  942. EVIA_BIT_11 = BIT_11; // Reserved, do not count on value
  943. EVIA_BIT_12 = BIT_12; // Reserved, do not count on value
  944. EVIA_BIT_13 = BIT_13; // Reserved, do not count on value
  945. EVIA_BIT_14 = BIT_14; // Reserved, do not count on value
  946. EVIA_BIT_15 = BIT_15; // Reserved, do not count on value
  947. EVIA_BIT_16 = BIT_16; // Reserved, do not count on value
  948. EVIA_BIT_17 = BIT_17; // Reserved, do not count on value
  949. EVIA_BIT_18 = BIT_18; // Reserved, do not count on value
  950. EVIA_BIT_19 = BIT_19; // Reserved, do not count on value
  951. EVIA_BIT_20 = BIT_20; // Reserved, do not count on value
  952. EVIA_BIT_21 = BIT_21; // Reserved, do not count on value
  953. EVIA_BIT_22 = BIT_22; // Reserved, do not count on value
  954. EVIA_BIT_23 = BIT_23; // Reserved, do not count on value
  955. EVIA_BIT_24 = BIT_24; // Reserved, do not count on value
  956. EVIA_BIT_25 = BIT_25; // Reserved, do not count on value
  957. EVIA_BIT_26 = BIT_26; // Reserved, do not count on value
  958. EVIA_BIT_27 = BIT_27; // Reserved, do not count on value
  959. EVIA_BIT_28 = BIT_28; // Reserved, do not count on value
  960. EVIA_BIT_29 = BIT_29; // Reserved, do not count on value
  961. EVIA_BIT_30 = BIT_30; // Reserved, do not count on value
  962. EVIA_BIT_31 = BIT_31; // Reserved, do not count on value
  963. { Cyrix Standard Feature Flags }
  964. CYRIX_FPU = BIT_0; // Floating-Point unit on chip
  965. CYRIX_VME = BIT_1; // Virtual Mode Extention
  966. CYRIX_DE = BIT_2; // Debugging Extention
  967. CYRIX_PSE = BIT_3; // Page Size Extention
  968. CYRIX_TSC = BIT_4; // Time Stamp Counter
  969. CYRIX_MSR = BIT_5; // Model Specific Registers
  970. CYRIX_PAE = BIT_6; // Physical Address Extention
  971. CYRIX_MCE = BIT_7; // Machine Check Exception
  972. CYRIX_CX8 = BIT_8; // CMPXCHG8 Instruction
  973. CYRIX_APIC = BIT_9; // Software-accessible local APIC on Chip
  974. CYRIX_BIT_10 = BIT_10; // Reserved, do not count on value
  975. CYRIX_BIT_11 = BIT_11; // Reserved, do not count on value
  976. CYRIX_MTRR = BIT_12; // Memory Type Range Registers
  977. CYRIX_PGE = BIT_13; // Page Global Enable
  978. CYRIX_MCA = BIT_14; // Machine Check Architecture
  979. CYRIX_CMOV = BIT_15; // Conditional Move Instruction
  980. CYRIX_BIT_16 = BIT_16; // Reserved, do not count on value
  981. CYRIX_BIT_17 = BIT_17; // Reserved, do not count on value
  982. CYRIX_BIT_18 = BIT_18; // Reserved, do not count on value
  983. CYRIX_BIT_19 = BIT_19; // Reserved, do not count on value
  984. CYRIX_BIT_20 = BIT_20; // Reserved, do not count on value
  985. CYRIX_BIT_21 = BIT_21; // Reserved, do not count on value
  986. CYRIX_BIT_22 = BIT_22; // Reserved, do not count on value
  987. CYRIX_MMX = BIT_23; // MMX technology
  988. CYRIX_BIT_24 = BIT_24; // Reserved, do not count on value
  989. CYRIX_BIT_25 = BIT_25; // Reserved, do not count on value
  990. CYRIX_BIT_26 = BIT_26; // Reserved, do not count on value
  991. CYRIX_BIT_27 = BIT_27; // Reserved, do not count on value
  992. CYRIX_BIT_28 = BIT_28; // Reserved, do not count on value
  993. CYRIX_BIT_29 = BIT_29; // Reserved, do not count on value
  994. CYRIX_BIT_30 = BIT_30; // Reserved, do not count on value
  995. CYRIX_BIT_31 = BIT_31; // Reserved, do not count on value
  996. { Cyrix Enhanced Feature Flags }
  997. ECYRIX_FPU = BIT_0; // Floating-Point unit on chip
  998. ECYRIX_VME = BIT_1; // Virtual Mode Extention
  999. ECYRIX_DE = BIT_2; // Debugging Extention
  1000. ECYRIX_PSE = BIT_3; // Page Size Extention
  1001. ECYRIX_TSC = BIT_4; // Time Stamp Counter
  1002. ECYRIX_MSR = BIT_5; // Model Specific Registers
  1003. ECYRIX_PAE = BIT_6; // Physical Address Extention
  1004. ECYRIX_MCE = BIT_7; // Machine Check Exception
  1005. ECYRIX_CX8 = BIT_8; // CMPXCHG8 Instruction
  1006. ECYRIX_APIC = BIT_9; // Software-accessible local APIC on Chip
  1007. ECYRIX_SEP = BIT_10; // Fast System Call
  1008. ECYRIX_BIT_11 = BIT_11; // Reserved, do not count on value
  1009. ECYRIX_MTRR = BIT_12; // Memory Type Range Registers
  1010. ECYRIX_PGE = BIT_13; // Page Global Enable
  1011. ECYRIX_MCA = BIT_14; // Machine Check Architecture
  1012. ECYRIX_ICMOV = BIT_15; // Integer Conditional Move Instruction
  1013. ECYRIX_FCMOV = BIT_16; // Floating Point Conditional Move Instruction
  1014. ECYRIX_BIT_17 = BIT_17; // Reserved, do not count on value
  1015. ECYRIX_BIT_18 = BIT_18; // Reserved, do not count on value
  1016. ECYRIX_BIT_19 = BIT_19; // Reserved, do not count on value
  1017. ECYRIX_BIT_20 = BIT_20; // Reserved, do not count on value
  1018. ECYRIX_BIT_21 = BIT_21; // Reserved, do not count on value
  1019. ECYRIX_BIT_22 = BIT_22; // Reserved, do not count on value
  1020. ECYRIX_MMX = BIT_23; // MMX technology
  1021. ECYRIX_EMMX = BIT_24; // Extended MMX Technology
  1022. ECYRIX_BIT_25 = BIT_25; // Reserved, do not count on value
  1023. ECYRIX_BIT_26 = BIT_26; // Reserved, do not count on value
  1024. ECYRIX_BIT_27 = BIT_27; // Reserved, do not count on value
  1025. ECYRIX_BIT_28 = BIT_28; // Reserved, do not count on value
  1026. ECYRIX_BIT_29 = BIT_29; // Reserved, do not count on value
  1027. ECYRIX_BIT_30 = BIT_30; // Reserved, do not count on value
  1028. ECYRIX_BIT_31 = BIT_31; // Reserved, do not count on value
  1029. { Transmeta Features }
  1030. TRANSMETA_FPU = BIT_0; // Floating-Point unit on chip
  1031. TRANSMETA_VME = BIT_1; // Virtual Mode Extention
  1032. TRANSMETA_DE = BIT_2; // Debugging Extention
  1033. TRANSMETA_PSE = BIT_3; // Page Size Extention
  1034. TRANSMETA_TSC = BIT_4; // Time Stamp Counter
  1035. TRANSMETA_MSR = BIT_5; // Model Specific Registers
  1036. TRANSMETA_BIT_6 = BIT_6; // Reserved, do not count on value
  1037. TRANSMETA_BIT_7 = BIT_7; // Reserved, do not count on value
  1038. TRANSMETA_CX8 = BIT_8; // CMPXCHG8 Instruction
  1039. TRANSMETA_BIT_9 = BIT_9; // Reserved, do not count on value
  1040. TRANSMETA_BIT_10 = BIT_10; // Reserved, do not count on value
  1041. TRANSMETA_SEP = BIT_11; // Fast system Call Extensions
  1042. TRANSMETA_BIT_12 = BIT_12; // Reserved, do not count on value
  1043. TRANSMETA_BIT_13 = BIT_13; // Reserved, do not count on value
  1044. TRANSMETA_BIT_14 = BIT_14; // Reserved, do not count on value
  1045. TRANSMETA_CMOV = BIT_15; // Conditional Move Instruction
  1046. TRANSMETA_BIT_16 = BIT_16; // Reserved, do not count on value
  1047. TRANSMETA_BIT_17 = BIT_17; // Reserved, do not count on value
  1048. TRANSMETA_PSN = BIT_18; // Processor Serial Number
  1049. TRANSMETA_BIT_19 = BIT_19; // Reserved, do not count on value
  1050. TRANSMETA_BIT_20 = BIT_20; // Reserved, do not count on value
  1051. TRANSMETA_BIT_21 = BIT_21; // Reserved, do not count on value
  1052. TRANSMETA_BIT_22 = BIT_22; // Reserved, do not count on value
  1053. TRANSMETA_MMX = BIT_23; // MMX technology
  1054. TRANSMETA_BIT_24 = BIT_24; // Reserved, do not count on value
  1055. TRANSMETA_BIT_25 = BIT_25; // Reserved, do not count on value
  1056. TRANSMETA_BIT_26 = BIT_26; // Reserved, do not count on value
  1057. TRANSMETA_BIT_27 = BIT_27; // Reserved, do not count on value
  1058. TRANSMETA_BIT_28 = BIT_28; // Reserved, do not count on value
  1059. TRANSMETA_BIT_29 = BIT_29; // Reserved, do not count on value
  1060. TRANSMETA_BIT_30 = BIT_30; // Reserved, do not count on value
  1061. TRANSMETA_BIT_31 = BIT_31; // Reserved, do not count on value
  1062. { Extended Transmeta Features }
  1063. ETRANSMETA_FPU = BIT_0; // Floating-Point unit on chip
  1064. ETRANSMETA_VME = BIT_1; // Virtual Mode Extention
  1065. ETRANSMETA_DE = BIT_2; // Debugging Extention
  1066. ETRANSMETA_PSE = BIT_3; // Page Size Extention
  1067. ETRANSMETA_TSC = BIT_4; // Time Stamp Counter
  1068. ETRANSMETA_MSR = BIT_5; // Model Specific Registers
  1069. ETRANSMETA_BIT_6 = BIT_6; // Reserved, do not count on value
  1070. ETRANSMETA_BIT_7 = BIT_7; // Reserved, do not count on value
  1071. ETRANSMETA_CX8 = BIT_8; // CMPXCHG8 Instruction
  1072. ETRANSMETA_BIT_9 = BIT_9; // Reserved, do not count on value
  1073. ETRANSMETA_BIT_10 = BIT_10; // Reserved, do not count on value
  1074. ETRANSMETA_BIT_11 = BIT_11; // Reserved, do not count on value
  1075. ETRANSMETA_BIT_12 = BIT_12; // Reserved, do not count on value
  1076. ETRANSMETA_BIT_13 = BIT_13; // Reserved, do not count on value
  1077. ETRANSMETA_BIT_14 = BIT_14; // Reserved, do not count on value
  1078. ETRANSMETA_CMOV = BIT_15; // Conditional Move Instruction
  1079. ETRANSMETA_FCMOV = BIT_16; // Float Conditional Move Instruction
  1080. ETRANSMETA_BIT_17 = BIT_17; // Reserved, do not count on value
  1081. ETRANSMETA_BIT_18 = BIT_18; // Reserved, do not count on value
  1082. ETRANSMETA_BIT_19 = BIT_19; // Reserved, do not count on value
  1083. ETRANSMETA_BIT_20 = BIT_20; // Reserved, do not count on value
  1084. ETRANSMETA_BIT_21 = BIT_21; // Reserved, do not count on value
  1085. ETRANSMETA_BIT_22 = BIT_22; // Reserved, do not count on value
  1086. ETRANSMETA_MMX = BIT_23; // MMX technology
  1087. ETRANSMETA_BIT_24 = BIT_24; // Reserved, do not count on value
  1088. ETRANSMETA_BIT_25 = BIT_25; // Reserved, do not count on value
  1089. ETRANSMETA_BIT_26 = BIT_26; // Reserved, do not count on value
  1090. ETRANSMETA_BIT_27 = BIT_27; // Reserved, do not count on value
  1091. ETRANSMETA_BIT_28 = BIT_28; // Reserved, do not count on value
  1092. ETRANSMETA_BIT_29 = BIT_29; // Reserved, do not count on value
  1093. ETRANSMETA_BIT_30 = BIT_30; // Reserved, do not count on value
  1094. ETRANSMETA_BIT_31 = BIT_31; // Reserved, do not count on value
  1095. { Transmeta Specific Features }
  1096. STRANSMETA_RECOVERY = BIT_0; // Recovery Mode
  1097. STRANSMETA_LONGRUN = BIT_1; // Long Run
  1098. STRANSMETA_BIT_2 = BIT_2; // Debugging Extention
  1099. STRANSMETA_LRTI = BIT_3; // Long Run Table Interface
  1100. STRANSMETA_BIT_4 = BIT_4; // Reserved, do not count on value
  1101. STRANSMETA_BIT_5 = BIT_5; // Reserved, do not count on value
  1102. STRANSMETA_BIT_6 = BIT_6; // Reserved, do not count on value
  1103. STRANSMETA_PTTI1 = BIT_7; // Persistent Translation Technology 1.x
  1104. STRANSMETA_PTTI2 = BIT_8; // Persistent Translation Technology 2.0
  1105. STRANSMETA_BIT_9 = BIT_9; // Reserved, do not count on value
  1106. STRANSMETA_BIT_10 = BIT_10; // Reserved, do not count on value
  1107. STRANSMETA_BIT_11 = BIT_11; // Reserved, do not count on value
  1108. STRANSMETA_BIT_12 = BIT_12; // Reserved, do not count on value
  1109. STRANSMETA_BIT_13 = BIT_13; // Reserved, do not count on value
  1110. STRANSMETA_BIT_14 = BIT_14; // Reserved, do not count on value
  1111. STRANSMETA_BIT_15 = BIT_15; // Reserved, do not count on value
  1112. STRANSMETA_BIT_16 = BIT_16; // Reserved, do not count on value
  1113. STRANSMETA_BIT_17 = BIT_17; // Reserved, do not count on value
  1114. STRANSMETA_BIT_18 = BIT_18; // Reserved, do not count on value
  1115. STRANSMETA_BIT_19 = BIT_19; // Reserved, do not count on value
  1116. STRANSMETA_BIT_20 = BIT_20; // Reserved, do not count on value
  1117. STRANSMETA_BIT_21 = BIT_21; // Reserved, do not count on value
  1118. STRANSMETA_BIT_22 = BIT_22; // Reserved, do not count on value
  1119. STRANSMETA_BIT_23 = BIT_23; // Reserved, do not count on value
  1120. STRANSMETA_BIT_24 = BIT_24; // Reserved, do not count on value
  1121. STRANSMETA_BIT_25 = BIT_25; // Reserved, do not count on value
  1122. STRANSMETA_BIT_26 = BIT_26; // Reserved, do not count on value
  1123. STRANSMETA_BIT_27 = BIT_27; // Reserved, do not count on value
  1124. STRANSMETA_BIT_28 = BIT_28; // Reserved, do not count on value
  1125. STRANSMETA_BIT_29 = BIT_29; // Reserved, do not count on value
  1126. STRANSMETA_BIT_30 = BIT_30; // Reserved, do not count on value
  1127. STRANSMETA_BIT_31 = BIT_31; // Reserved, do not count on value
  1128. { Constants of bits of the MXCSR register - Intel and AMD processors that support SSE instructions}
  1129. MXCSR_IE = BIT_0; // Invalid Operation flag
  1130. MXCSR_DE = BIT_1; // Denormal flag
  1131. MXCSR_ZE = BIT_2; // Divide by Zero flag
  1132. MXCSR_OE = BIT_3; // Overflow flag
  1133. MXCSR_UE = BIT_4; // Underflow flag
  1134. MXCSR_PE = BIT_5; // Precision flag
  1135. MXCSR_DAZ = BIT_6; // Denormal are Zero flag
  1136. MXCSR_IM = BIT_7; // Invalid Operation mask
  1137. MXCSR_DM = BIT_8; // Denormal mask
  1138. MXCSR_ZM = BIT_9; // Divide by Zero mask
  1139. MXCSR_OM = BIT_10; // Overflow mask
  1140. MXCSR_UM = BIT_11; // Underflow mask
  1141. MXCSR_PM = BIT_12; // Precision mask
  1142. MXCSR_RC1 = BIT_13; // Rounding control, bit 1
  1143. MXCSR_RC2 = BIT_14; // Rounding control, bit 2
  1144. MXCSR_RC = MXCSR_RC1 or MXCSR_RC2; // Rounding control
  1145. MXCSR_FZ = BIT_15; // Flush to Zero
  1146. const
  1147. IntelCacheDescription: array [0..102] of TCacheInfo = (
  1148. (D: $00; Family: cfOther; Size: 0; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr00),
  1149. (D: $01; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 32; I: @RsIntelCacheDescr01),
  1150. (D: $02; Family: cfInstructionTLB; Size: 4096; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 2; I: @RsIntelCacheDescr02),
  1151. (D: $03; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 64; I: @RsIntelCacheDescr03),
  1152. (D: $04; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 8; I: @RsIntelCacheDescr04),
  1153. (D: $05; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 32; I: @RsIntelCacheDescr05),
  1154. (D: $06; Family: cfL1InstructionCache; Size: 8; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr06),
  1155. (D: $08; Family: cfL1InstructionCache; Size: 16; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr08),
  1156. (D: $09; Family: cfL1InstructionCache; Size: 32; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr09),
  1157. (D: $0A; Family: cfL1DataCache; Size: 8; WaysOfAssoc: 2; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr0A),
  1158. (D: $0B; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 4; I: @RsIntelCacheDescr0B),
  1159. (D: $0C; Family: cfL1DataCache; Size: 16; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr0C),
  1160. (D: $0D; Family: cfL1DataCache; Size: 16; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr0D),
  1161. (D: $0E; Family: cfL1DataCache; Size: 24; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr0E),
  1162. (D: $21; Family: cfL2Cache; Size: 256; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr21),
  1163. (D: $22; Family: cfL3Cache; Size: 512; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr22),
  1164. (D: $23; Family: cfL3Cache; Size: 1024; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr23),
  1165. (D: $25; Family: cfL3Cache; Size: 2048; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr25),
  1166. (D: $29; Family: cfL3Cache; Size: 4096; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr29),
  1167. (D: $2C; Family: cfL1DataCache; Size: 32; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr2C),
  1168. (D: $30; Family: cfL1InstructionCache; Size: 32; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr30),
  1169. (D: $39; Family: cfL2Cache; Size: 128; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr39),
  1170. (D: $3A; Family: cfL2Cache; Size: 192; WaysOfAssoc: 6; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr3A),
  1171. (D: $3B; Family: cfL2Cache; Size: 128; WaysOfAssoc: 2; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr3B),
  1172. (D: $3C; Family: cfL2Cache; Size: 256; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr3C),
  1173. (D: $3D; Family: cfL2Cache; Size: 384; WaysOfAssoc: 6; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr3D),
  1174. (D: $3E; Family: cfL2Cache; Size: 512; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr3E),
  1175. (D: $40; Family: cfOther; Size: 0; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr40),
  1176. (D: $41; Family: cfL2Cache; Size: 128; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr41),
  1177. (D: $42; Family: cfL2Cache; Size: 256; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr42),
  1178. (D: $43; Family: cfL2Cache; Size: 512; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr43),
  1179. (D: $44; Family: cfL2Cache; Size: 1024; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr44),
  1180. (D: $45; Family: cfL2Cache; Size: 2048; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr45),
  1181. (D: $46; Family: cfL3Cache; Size: 4096; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr46),
  1182. (D: $47; Family: cfL3Cache; Size: 8192; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr47),
  1183. (D: $48; Family: cfL2Cache; Size: 3072; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr48),
  1184. (D: $49; Family: cfL2Cache; Size: 4096; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr49),
  1185. (D: $4A; Family: cfL3Cache; Size: 6144; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr4A),
  1186. (D: $4B; Family: cfL3Cache; Size: 8192; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr4B),
  1187. (D: $4C; Family: cfL3Cache; Size: 12288; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr4C),
  1188. (D: $4D; Family: cfL3Cache; Size: 16384; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr4D),
  1189. (D: $4E; Family: cfL3Cache; Size: 6144; WaysOfAssoc: 24; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr4E),
  1190. (D: $4F; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 32; I: @RsIntelCacheDescr4F),
  1191. (D: $50; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 64; I: @RsIntelCacheDescr50),
  1192. (D: $51; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 128; I: @RsIntelCacheDescr51),
  1193. (D: $52; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 256; I: @RsIntelCacheDescr52),
  1194. (D: $55; Family: cfInstructionTLB; Size: 2048; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 7; I: @RsIntelCacheDescr55),
  1195. (D: $56; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 16; I: @RsIntelCacheDescr56),
  1196. (D: $57; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 16; I: @RsIntelCacheDescr57),
  1197. (D: $59; Family: cfDataTLB; Size: 4; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 16; I: @RsIntelCacheDescr59),
  1198. (D: $5A; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 32; I: @RsIntelCacheDescr5A),
  1199. (D: $5B; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 64; I: @RsIntelCacheDescr5B),
  1200. (D: $5C; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 128; I: @RsIntelCacheDescr5C),
  1201. (D: $5D; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 256; I: @RsIntelCacheDescr5D),
  1202. (D: $60; Family: cfL1DataCache; Size: 16; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr60),
  1203. (D: $66; Family: cfL1DataCache; Size: 8; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr66),
  1204. (D: $67; Family: cfL1DataCache; Size: 16; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr67),
  1205. (D: $68; Family: cfL1DataCache; Size: 32; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr68),
  1206. (D: $70; Family: cfTrace; Size: 12; WaysOfAssoc: 8; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr70),
  1207. (D: $71; Family: cfTrace; Size: 16; WaysOfAssoc: 8; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr71),
  1208. (D: $72; Family: cfTrace; Size: 32; WaysOfAssoc: 8; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr72),
  1209. (D: $73; Family: cfTrace; Size: 64; WaysOfAssoc: 8; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr73),
  1210. (D: $76; Family: cfInstructionTLB; Size: 2048; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 8; I: @RsIntelCacheDescr76),
  1211. (D: $78; Family: cfL2Cache; Size: 1024; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr78),
  1212. (D: $79; Family: cfL2Cache; Size: 128; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr79),
  1213. (D: $7A; Family: cfL2Cache; Size: 256; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr7A),
  1214. (D: $7B; Family: cfL2Cache; Size: 512; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr7B),
  1215. (D: $7C; Family: cfL2Cache; Size: 1024; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr7C),
  1216. (D: $7D; Family: cfL2Cache; Size: 2048; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr7D),
  1217. (D: $7F; Family: cfL2Cache; Size: 512; WaysOfAssoc: 2; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr7F),
  1218. (D: $80; Family: cfL2Cache; Size: 512; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr80),
  1219. (D: $82; Family: cfL2Cache; Size: 256; WaysOfAssoc: 8; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr82),
  1220. (D: $83; Family: cfL2Cache; Size: 512; WaysOfAssoc: 8; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr83),
  1221. (D: $84; Family: cfL2Cache; Size: 1024; WaysOfAssoc: 8; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr84),
  1222. (D: $85; Family: cfL2Cache; Size: 2048; WaysOfAssoc: 8; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr85),
  1223. (D: $86; Family: cfL2Cache; Size: 512; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr86),
  1224. (D: $87; Family: cfL2Cache; Size: 1024; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr87),
  1225. (D: $B0; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 128; I: @RsIntelCacheDescrB0),
  1226. (D: $B1; Family: cfInstructionTLB; Size: 2048; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 8; I: @RsIntelCacheDescrB1),
  1227. (D: $B2; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 64; I: @RsIntelCacheDescrB2),
  1228. (D: $B3; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 128; I: @RsIntelCacheDescrB3),
  1229. (D: $B4; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 256; I: @RsIntelCacheDescrB4),
  1230. (D: $BA; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 64; I: @RsIntelCacheDescrBA),
  1231. (D: $C0; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 8; I: @RsIntelCacheDescrC0),
  1232. (D: $CA; Family: cfL2TLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 512; I: @RsIntelCacheDescrCA),
  1233. (D: $D0; Family: cfL3Cache; Size: 512; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD0),
  1234. (D: $D1; Family: cfL3Cache; Size: 1024; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD1),
  1235. (D: $D2; Family: cfL3Cache; Size: 2048; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD2),
  1236. (D: $D6; Family: cfL3Cache; Size: 1024; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD6),
  1237. (D: $D7; Family: cfL3Cache; Size: 2048; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD7),
  1238. (D: $D8; Family: cfL3Cache; Size: 4096; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD8),
  1239. (D: $DC; Family: cfL3Cache; Size: 1536; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrDC),
  1240. (D: $DD; Family: cfL3Cache; Size: 3072; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrDD),
  1241. (D: $DE; Family: cfL3Cache; Size: 6144; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrDE),
  1242. (D: $E2; Family: cfL3Cache; Size: 2048; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrE2),
  1243. (D: $E3; Family: cfL3Cache; Size: 4096; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrE3),
  1244. (D: $E4; Family: cfL3Cache; Size: 8192; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrE4),
  1245. (D: $EA; Family: cfL3Cache; Size: 12288; WaysOfAssoc: 24; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrEA),
  1246. (D: $EB; Family: cfL3Cache; Size: 18432; WaysOfAssoc: 24; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrEB),
  1247. (D: $EC; Family: cfL3Cache; Size: 24576; WaysOfAssoc: 24; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrEC),
  1248. (D: $F0; Family: cfOther; Size: 0; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrF0),
  1249. (D: $F1; Family: cfOther; Size: 0; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrF1),
  1250. (D: $FF; Family: cfOther; Size: 0; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrFF)
  1251. );
  1252. procedure GetCpuInfo(var CpuInfo: TCpuInfo);
  1253. function GetIntelCacheDescription(const D: Byte): string;
  1254. function RoundFrequency(const Frequency: Integer): Integer;
  1255. {$IFDEF MSWINDOWS}
  1256. function GetCPUSpeed(var CpuSpeed: TFreqInfo): Boolean;
  1257. type
  1258. TOSEnabledFeature = (oefFPU, oefSSE, oefAVX);
  1259. TOSEnabledFeatures = set of TOSEnabledFeature;
  1260. function GetOSEnabledFeatures: TOSEnabledFeatures;
  1261. {$ENDIF MSWINDOWS}
  1262. function CPUID: TCpuInfo;
  1263. function TestFDIVInstruction: Boolean;
  1264. // Memory Information
  1265. {$IFDEF MSWINDOWS}
  1266. function GetMaxAppAddress: TJclAddr;
  1267. function GetMinAppAddress: TJclAddr;
  1268. {$ENDIF MSWINDOWS}
  1269. function GetMemoryLoad: Byte;
  1270. function GetSwapFileSize: Int64;
  1271. function GetSwapFileUsage: Byte;
  1272. function GetTotalPhysicalMemory: Int64;
  1273. function GetFreePhysicalMemory: Int64;
  1274. {$IFDEF MSWINDOWS}
  1275. function GetTotalPageFileMemory: Int64;
  1276. function GetFreePageFileMemory: Int64;
  1277. function GetTotalVirtualMemory: Int64;
  1278. function GetFreeVirtualMemory: Int64;
  1279. {$ENDIF MSWINDOWS}
  1280. // Alloc granularity
  1281. procedure RoundToAllocGranularity64(var Value: Int64; Up: Boolean);
  1282. procedure RoundToAllocGranularityPtr(var Value: Pointer; Up: Boolean);
  1283. {$IFDEF MSWINDOWS}
  1284. // Keyboard Information
  1285. function GetKeyState(const VirtualKey: Cardinal): Boolean;
  1286. function GetNumLockKeyState: Boolean;
  1287. function GetScrollLockKeyState: Boolean;
  1288. function GetCapsLockKeyState: Boolean;
  1289. // Windows 95/98/Me system resources information
  1290. type
  1291. TFreeSysResKind = (rtSystem, rtGdi, rtUser);
  1292. TFreeSystemResources = record
  1293. SystemRes: Integer;
  1294. GdiRes: Integer;
  1295. UserRes: Integer;
  1296. end;
  1297. function IsSystemResourcesMeterPresent: Boolean;
  1298. function GetFreeSystemResources(const ResourceType: TFreeSysResKind): Integer; overload;
  1299. function GetFreeSystemResources: TFreeSystemResources; overload;
  1300. function GetBPP: Cardinal;
  1301. // Installed programs information
  1302. function ProgIDExists(const ProgID: string): Boolean;
  1303. function IsWordInstalled: Boolean;
  1304. function IsExcelInstalled: Boolean;
  1305. function IsAccessInstalled: Boolean;
  1306. function IsPowerPointInstalled: Boolean;
  1307. function IsFrontPageInstalled: Boolean;
  1308. function IsOutlookInstalled: Boolean;
  1309. function IsInternetExplorerInstalled: Boolean;
  1310. function IsMSProjectInstalled: Boolean;
  1311. function IsOpenOfficeInstalled: Boolean;
  1312. function IsLibreOfficeInstalled: Boolean;
  1313. {$ENDIF MSWINDOWS}
  1314. // Public global variables
  1315. var
  1316. ProcessorCount: Cardinal = 0;
  1317. AllocGranularity: Cardinal = 0;
  1318. PageSize: Cardinal = 0;
  1319. {$IFDEF UNITVERSIONING}
  1320. const
  1321. UnitVersioning: TUnitVersionInfo = (
  1322. RCSfile: '$URL$';
  1323. Revision: '$Revision$';
  1324. Date: '$Date$';
  1325. LogPath: 'JCL\source\common';
  1326. Extra: '';
  1327. Data: nil
  1328. );
  1329. {$ENDIF UNITVERSIONING}
  1330. implementation
  1331. uses
  1332. {$IFDEF HAS_UNITSCOPE}
  1333. System.SysUtils, System.Math,
  1334. {$IFDEF MSWINDOWS}
  1335. Winapi.Messages, Winapi.Winsock, Snmp,
  1336. {$IFDEF FPC}
  1337. JwaTlHelp32, JwaPsApi,
  1338. {$ELSE ~FPC}
  1339. Winapi.TLHelp32, Winapi.PsApi,
  1340. JclShell,
  1341. {$ENDIF ~FPC}
  1342. JclRegistry, JclWin32,
  1343. {$ENDIF MSWINDOWS}
  1344. {$ELSE ~HAS_UNITSCOPE}
  1345. SysUtils,
  1346. Math,
  1347. {$IFDEF MSWINDOWS}
  1348. Messages, Winsock, Snmp,
  1349. {$IFDEF FPC}
  1350. JwaTlHelp32, JwaPsApi,
  1351. {$ELSE ~FPC}
  1352. TLHelp32, PsApi,
  1353. JclShell,
  1354. {$ENDIF ~FPC}
  1355. JclRegistry, JclWin32,
  1356. {$ENDIF MSWINDOWS}
  1357. {$ENDIF ~HAS_UNITSCOPE}
  1358. Jcl8087, JclIniFiles,
  1359. JclSysUtils, JclFileUtils, JclAnsiStrings, JclStrings;
  1360. {$IFDEF FPC}
  1361. {$IFDEF MSWINDOWS}
  1362. function PidlToPath(IdList: PItemIdList): string;
  1363. begin
  1364. SetLength(Result, MAX_PATH);
  1365. if SHGetPathFromIdList(IdList, PChar(Result)) then
  1366. StrResetLength(Result)
  1367. else
  1368. Result := '';
  1369. end;
  1370. //----------------------------------------------------------------------------
  1371. function GetSpecialFolderLocation(const Folder: Integer): string;
  1372. var
  1373. FolderPidl: PItemIdList;
  1374. begin
  1375. FolderPidl := nil;
  1376. if Succeeded(SHGetSpecialFolderLocation(0, Folder, FolderPidl)) then
  1377. begin
  1378. try
  1379. Result := PidlToPath(FolderPidl);
  1380. finally
  1381. CoTaskMemFree(FolderPidl);
  1382. end;
  1383. end
  1384. else
  1385. Result := '';
  1386. end;
  1387. //----------------------------------------------------------------------------
  1388. {$ENDIF MSWINDOWS}
  1389. {$ENDIF FPC}
  1390. //=== Environment ============================================================
  1391. function DelEnvironmentVar(const Name: string): Boolean;
  1392. begin
  1393. {$IFDEF UNIX}
  1394. UnSetEnv(PChar(Name));
  1395. Result := True;
  1396. {$ENDIF UNIX}
  1397. {$IFDEF MSWINDOWS}
  1398. Result := SetEnvironmentVariable(PChar(Name), nil);
  1399. {$ENDIF MSWINDOWS}
  1400. end;
  1401. function ExpandEnvironmentVar(var Value: string): Boolean;
  1402. {$IFDEF UNIX}
  1403. begin
  1404. Result := True;
  1405. end;
  1406. {$ENDIF UNIX}
  1407. {$IFDEF MSWINDOWS}
  1408. var
  1409. R: Integer;
  1410. Expanded: string;
  1411. begin
  1412. SetLength(Expanded, 1);
  1413. R := ExpandEnvironmentStrings(PChar(Value), PChar(Expanded), 0);
  1414. SetLength(Expanded, R);
  1415. Result := ExpandEnvironmentStrings(PChar(Value), PChar(Expanded), R) <> 0;
  1416. if Result then
  1417. begin
  1418. StrResetLength(Expanded);
  1419. Value := Expanded;
  1420. end;
  1421. end;
  1422. {$ENDIF MSWINDOWS}
  1423. function ExpandEnvironmentVarCustom(var Value: string; Vars: TStrings): Boolean;
  1424. function FindClosingBrace(const R: string; var Position: Integer): Boolean;
  1425. var
  1426. Index, Len, BraceCount: Integer;
  1427. Quotes: string;
  1428. begin
  1429. Len := Length(R);
  1430. BraceCount := 0;
  1431. Quotes := '';
  1432. while (Position <= Len) do
  1433. begin
  1434. // handle quotes first
  1435. if (R[Position] = NativeSingleQuote) then
  1436. begin
  1437. Index := JclStrings.CharPos(Quotes, NativeSingleQuote);
  1438. if Index >= 0 then
  1439. SetLength(Quotes, Index - 1)
  1440. else
  1441. Quotes := Quotes + NativeSingleQuote;
  1442. end;
  1443. if (R[Position] = NativeDoubleQuote) then
  1444. begin
  1445. Index := JclStrings.CharPos(Quotes, NativeDoubleQuote);
  1446. if Index >= 0 then
  1447. SetLength(Quotes, Index - 1)
  1448. else
  1449. Quotes := Quotes + NativeDoubleQuote;
  1450. end;
  1451. if (R[Position] = '`') then
  1452. begin
  1453. Index := JclStrings.CharPos(Quotes, '`');
  1454. if Index >= 0 then
  1455. SetLength(Quotes, Index - 1)
  1456. else
  1457. Quotes := Quotes + '`';
  1458. end;
  1459. if Quotes = '' then
  1460. begin
  1461. if R[Position] = ')' then
  1462. begin
  1463. Dec(BraceCount);
  1464. if BraceCount = 0 then
  1465. Break;
  1466. end
  1467. else
  1468. if R[Position] = '(' then
  1469. Inc(BraceCount);
  1470. end;
  1471. Inc(Position);
  1472. end;
  1473. Result := Position <= Len;
  1474. // Delphi XE's CodeGear.Delphi.Targets has a bug where the closing paran is missing
  1475. // "'$(DelphiWin32DebugDCUPath'!=''". But it is still a valid string and not worth
  1476. // an exception.
  1477. //
  1478. // if Position > Len then
  1479. // raise EJclMsBuildError.CreateResFmt(@RsEEndOfString, [S]);
  1480. end;
  1481. var
  1482. Start, Position: Integer;
  1483. PropertyName, PropertyValue: string;
  1484. begin
  1485. Result := True;
  1486. repeat
  1487. // start with the last match in order to convert $(some$(other))
  1488. // evaluate properties
  1489. Start := StrLastPos('$(', Value);
  1490. if Start > 0 then
  1491. begin
  1492. Position := Start;
  1493. if not FindClosingBrace(Value, Position) then
  1494. Break;
  1495. PropertyName := Copy(Value, Start + 2, Position - Start - 2);
  1496. PropertyValue := Vars.Values[PropertyName];
  1497. if PropertyValue <> '' then
  1498. StrReplace(Value,
  1499. Copy(Value, Start, Position - Start + 1), // $(PropertyName)
  1500. PropertyValue,
  1501. [rfReplaceAll, rfIgnoreCase])
  1502. else
  1503. begin
  1504. Result := False;
  1505. Start := 0;
  1506. end;
  1507. end;
  1508. until Start = 0;
  1509. end;
  1510. {$IFDEF UNIX}
  1511. function GetEnvironmentVar(const Name: string; var Value: string): Boolean;
  1512. begin
  1513. Value := getenv(PChar(Name));
  1514. Result := Value <> '';
  1515. end;
  1516. function GetEnvironmentVar(const Name: string; var Value: string; Expand: Boolean): Boolean;
  1517. begin
  1518. Result := GetEnvironmentVar(Name, Value); // Expand is there just for x-platform compatibility
  1519. end;
  1520. {$ENDIF UNIX}
  1521. {$IFDEF MSWINDOWS}
  1522. function GetEnvironmentVar(const Name: string; out Value: string): Boolean;
  1523. begin
  1524. Result := GetEnvironmentVar(Name, Value, True);
  1525. end;
  1526. function GetEnvironmentVar(const Name: string; out Value: string; Expand: Boolean): Boolean;
  1527. var
  1528. R: DWORD;
  1529. begin
  1530. R := {$IFDEF HAS_UNITSCOPE}Winapi.{$ENDIF}Windows.GetEnvironmentVariable(PChar(Name), nil, 0);
  1531. SetLength(Value, R);
  1532. R := {$IFDEF HAS_UNITSCOPE}Winapi.{$ENDIF}Windows.GetEnvironmentVariable(PChar(Name), PChar(Value), R);
  1533. Result := R <> 0;
  1534. if not Result then
  1535. Value := ''
  1536. else
  1537. begin
  1538. SetLength(Value, R);
  1539. if Expand then
  1540. ExpandEnvironmentVar(Value);
  1541. end;
  1542. end;
  1543. {$ENDIF MSWINDOWS}
  1544. {$IFDEF LINUX}
  1545. function GetEnvironmentVars(const Vars: TStrings): Boolean;
  1546. var
  1547. P: PPChar;
  1548. begin
  1549. Vars.BeginUpdate;
  1550. try
  1551. Vars.Clear;
  1552. P := System.envp;
  1553. Result := P <> nil;
  1554. while (P <> nil) and (P^ <> nil) do
  1555. begin
  1556. Vars.Add(P^);
  1557. Inc(P);
  1558. end;
  1559. finally
  1560. Vars.EndUpdate;
  1561. end;
  1562. end;
  1563. function GetEnvironmentVars(const Vars: TStrings; Expand: Boolean): Boolean;
  1564. begin
  1565. Result := GetEnvironmentVars(Vars); // Expand is there just for x-platform compatibility
  1566. end;
  1567. {$ENDIF LINUX}
  1568. {$IFDEF MSWINDOWS}
  1569. function GetEnvironmentVars(const Vars: TStrings): Boolean;
  1570. begin
  1571. Result := GetEnvironmentVars(Vars, True);
  1572. end;
  1573. function GetEnvironmentVars(const Vars: TStrings; Expand: Boolean): Boolean;
  1574. var
  1575. Raw: PChar;
  1576. Expanded: string;
  1577. I: Integer;
  1578. begin
  1579. Vars.BeginUpdate;
  1580. try
  1581. Vars.Clear;
  1582. Raw := GetEnvironmentStrings;
  1583. try
  1584. MultiSzToStrings(Vars, Raw);
  1585. Result := True;
  1586. finally
  1587. FreeEnvironmentStrings(Raw);
  1588. end;
  1589. if Expand then
  1590. begin
  1591. for I := 0 to Vars.Count - 1 do
  1592. begin
  1593. Expanded := Vars[I];
  1594. if ExpandEnvironmentVar(Expanded) then
  1595. Vars[I] := Expanded;
  1596. end;
  1597. end;
  1598. finally
  1599. Vars.EndUpdate;
  1600. end;
  1601. end;
  1602. {$ENDIF MSWINDOWS}
  1603. function SetEnvironmentVar(const Name, Value: string): Boolean;
  1604. begin
  1605. {$IFDEF UNIX}
  1606. SetEnv(PChar(Name), PChar(Value), 1);
  1607. Result := True;
  1608. {$ENDIF UNIX}
  1609. {$IFDEF MSWINDOWS}
  1610. Result := SetEnvironmentVariable(PChar(Name), PChar(Value));
  1611. {$ENDIF MSWINDOWS}
  1612. end;
  1613. {$IFDEF MSWINDOWS}
  1614. function CreateEnvironmentBlock(const Options: TEnvironmentOptions; const AdditionalVars: TStrings): PChar;
  1615. const
  1616. RegLocalEnvironment = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
  1617. RegUserEnvironment = '\Environment\';
  1618. var
  1619. KeyNames, TempList: TStrings;
  1620. Temp, Name, Value: string;
  1621. I: Integer;
  1622. begin
  1623. TempList := TStringList.Create;
  1624. try
  1625. // add additional environment variables
  1626. if eoAdditional in Options then
  1627. for I := 0 to AdditionalVars.Count - 1 do
  1628. begin
  1629. Temp := AdditionalVars[I];
  1630. ExpandEnvironmentVar(Temp);
  1631. TempList.Add(Temp);
  1632. end;
  1633. // get environment strings from local machine
  1634. if eoLocalMachine in Options then
  1635. begin
  1636. KeyNames := TStringList.Create;
  1637. try
  1638. if RegGetValueNames(HKEY_LOCAL_MACHINE, RegLocalEnvironment, KeyNames) then
  1639. begin
  1640. for I := 0 to KeyNames.Count - 1 do
  1641. begin
  1642. Name := KeyNames[I];
  1643. Value := RegReadString(HKEY_LOCAL_MACHINE, RegLocalEnvironment, Name);
  1644. ExpandEnvironmentVar(Value);
  1645. TempList.Add(Name + '=' + Value);
  1646. end;
  1647. end;
  1648. finally
  1649. FreeAndNil(KeyNames);
  1650. end;
  1651. end;
  1652. // get environment strings from current user
  1653. if eoCurrentUser in Options then
  1654. begin
  1655. KeyNames := TStringLIst.Create;
  1656. try
  1657. if RegGetValueNames(HKEY_CURRENT_USER, RegUserEnvironment, KeyNames) then
  1658. begin
  1659. for I := 0 to KeyNames.Count - 1 do
  1660. begin
  1661. Name := KeyNames[I];
  1662. Value := RegReadString(HKEY_CURRENT_USER, RegUserEnvironment, Name);
  1663. ExpandEnvironmentVar(Value);
  1664. TempList.Add(Name + '=' + Value);
  1665. end;
  1666. end;
  1667. finally
  1668. KeyNames.Free;
  1669. end;
  1670. end;
  1671. // transform stringlist into multi-PChar
  1672. Result := nil;
  1673. StringsToMultiSz(Result, TempList);
  1674. finally
  1675. FreeAndNil(TempList);
  1676. end;
  1677. end;
  1678. // frees an environment block allocated by CreateEnvironmentBlock and
  1679. // sets Env to nil
  1680. procedure DestroyEnvironmentBlock(var Env: PChar);
  1681. begin
  1682. FreeMultiSz(Env);
  1683. end;
  1684. procedure SetGlobalEnvironmentVariable(VariableName, VariableContent: string);
  1685. const
  1686. cEnvironment = 'Environment';
  1687. begin
  1688. if VariableName = '' then
  1689. Exit;
  1690. if VariableContent = '' then
  1691. begin
  1692. RegDeleteEntry(HKEY_CURRENT_USER, cEnvironment, VariableName);
  1693. SetEnvironmentVariable(PChar(VariableName), nil);
  1694. end
  1695. else
  1696. begin
  1697. RegWriteString(HKEY_CURRENT_USER, cEnvironment, VariableName, VariableContent);
  1698. SetEnvironmentVariable(PChar(VariableName), PChar(VariableContent));
  1699. end;
  1700. SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, LPARAM(PChar(cEnvironment)));
  1701. end;
  1702. //=== Common Folders =========================================================
  1703. // Utility function which returns the Windows independent CurrentVersion key
  1704. // inside HKEY_LOCAL_MACHINE
  1705. const
  1706. HKLM_CURRENT_VERSION_WINDOWS = 'SOFTWARE\Microsoft\Windows\CurrentVersion';
  1707. HKLM_CURRENT_VERSION_NT = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion';
  1708. function REG_CURRENT_VERSION: string;
  1709. begin
  1710. if IsWinNT then
  1711. Result := HKLM_CURRENT_VERSION_NT
  1712. else
  1713. Result := HKLM_CURRENT_VERSION_WINDOWS;
  1714. end;
  1715. { TODO : Check for documented solution }
  1716. function GetCommonFilesFolder: string;
  1717. begin
  1718. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, HKLM_CURRENT_VERSION_WINDOWS,
  1719. 'CommonFilesDir', '');
  1720. end;
  1721. {$ENDIF MSWINDOWS}
  1722. function GetCurrentFolder: string;
  1723. {$IFDEF UNIX}
  1724. const
  1725. InitialSize = 64;
  1726. var
  1727. Size: Integer;
  1728. begin
  1729. Size := InitialSize;
  1730. while True do
  1731. begin
  1732. SetLength(Result, Size);
  1733. if getcwd(PChar(Result), Size) <> nil then
  1734. begin
  1735. StrResetLength(Result);
  1736. Exit;
  1737. end;
  1738. {$IFDEF FPC}
  1739. if GetLastOSError <> ERANGE then
  1740. {$ELSE ~FPC}
  1741. if GetLastError <> ERANGE then
  1742. {$ENDIF ~FPC}
  1743. RaiseLastOSError;
  1744. Size := Size * 2;
  1745. end;
  1746. end;
  1747. {$ENDIF UNIX}
  1748. {$IFDEF MSWINDOWS}
  1749. var
  1750. Required: Cardinal;
  1751. begin
  1752. Result := '';
  1753. Required := GetCurrentDirectory(0, nil);
  1754. if Required <> 0 then
  1755. begin
  1756. SetLength(Result, Required);
  1757. GetCurrentDirectory(Required, PChar(Result));
  1758. StrResetLength(Result);
  1759. end;
  1760. end;
  1761. {$ENDIF MSWINDOWS}
  1762. {$IFDEF MSWINDOWS}
  1763. { TODO : Check for documented solution }
  1764. function GetProgramFilesFolder: string;
  1765. begin
  1766. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, HKLM_CURRENT_VERSION_WINDOWS, 'ProgramFilesDir', '');
  1767. end;
  1768. { TODO : Check for documented solution }
  1769. function GetWindowsFolder: string;
  1770. var
  1771. Required: Cardinal;
  1772. begin
  1773. Result := '';
  1774. Required := GetWindowsDirectory(nil, 0);
  1775. if Required <> 0 then
  1776. begin
  1777. SetLength(Result, Required);
  1778. GetWindowsDirectory(PChar(Result), Required);
  1779. StrResetLength(Result);
  1780. end;
  1781. end;
  1782. { TODO : Check for documented solution }
  1783. function GetWindowsSystemFolder: string;
  1784. var
  1785. Required: Cardinal;
  1786. begin
  1787. Result := '';
  1788. Required := GetSystemDirectory(nil, 0);
  1789. if Required <> 0 then
  1790. begin
  1791. SetLength(Result, Required);
  1792. GetSystemDirectory(PChar(Result), Required);
  1793. StrResetLength(Result);
  1794. end;
  1795. end;
  1796. function GetWindowsTempFolder: string;
  1797. begin
  1798. Result := PathRemoveSeparator(PathGetTempPath);
  1799. end;
  1800. function GetDesktopFolder: string;
  1801. begin
  1802. Result := GetSpecialFolderLocation(CSIDL_DESKTOP);
  1803. end;
  1804. { TODO : Check GetProgramsFolder = GetProgramFilesFolder }
  1805. function GetProgramsFolder: string;
  1806. begin
  1807. Result := GetSpecialFolderLocation(CSIDL_PROGRAMS);
  1808. end;
  1809. {$ENDIF MSWINDOWS}
  1810. function GetPersonalFolder: string;
  1811. begin
  1812. {$IFDEF UNIX}
  1813. Result := GetEnvironmentVariable('HOME');
  1814. {$ENDIF UNIX}
  1815. {$IFDEF MSWINDOWS}
  1816. Result := GetSpecialFolderLocation(CSIDL_PERSONAL);
  1817. {$ENDIF MSWINDOWS}
  1818. end;
  1819. {$IFDEF MSWINDOWS}
  1820. function GetFavoritesFolder: string;
  1821. begin
  1822. Result := GetSpecialFolderLocation(CSIDL_FAVORITES);
  1823. end;
  1824. function GetStartupFolder: string;
  1825. begin
  1826. Result := GetSpecialFolderLocation(CSIDL_STARTUP);
  1827. end;
  1828. function GetRecentFolder: string;
  1829. begin
  1830. Result := GetSpecialFolderLocation(CSIDL_RECENT);
  1831. end;
  1832. function GetSendToFolder: string;
  1833. begin
  1834. Result := GetSpecialFolderLocation(CSIDL_SENDTO);
  1835. end;
  1836. function GetStartmenuFolder: string;
  1837. begin
  1838. Result := GetSpecialFolderLocation(CSIDL_STARTMENU);
  1839. end;
  1840. function GetDesktopDirectoryFolder: string;
  1841. begin
  1842. Result := GetSpecialFolderLocation(CSIDL_DESKTOPDIRECTORY);
  1843. end;
  1844. function GetCommonDocumentsFolder: string;
  1845. begin
  1846. Result := GetSpecialFolderLocation(CSIDL_COMMON_DOCUMENTS);
  1847. end;
  1848. function GetNethoodFolder: string;
  1849. begin
  1850. Result := GetSpecialFolderLocation(CSIDL_NETHOOD);
  1851. end;
  1852. function GetFontsFolder: string;
  1853. begin
  1854. Result := GetSpecialFolderLocation(CSIDL_FONTS);
  1855. end;
  1856. function GetCommonStartmenuFolder: string;
  1857. begin
  1858. Result := GetSpecialFolderLocation(CSIDL_COMMON_STARTMENU);
  1859. end;
  1860. function GetCommonProgramsFolder: string;
  1861. begin
  1862. Result := GetSpecialFolderLocation(CSIDL_COMMON_PROGRAMS);
  1863. end;
  1864. function GetCommonStartupFolder: string;
  1865. begin
  1866. Result := GetSpecialFolderLocation(CSIDL_COMMON_STARTUP);
  1867. end;
  1868. function GetCommonDesktopdirectoryFolder: string;
  1869. begin
  1870. Result := GetSpecialFolderLocation(CSIDL_COMMON_DESKTOPDIRECTORY);
  1871. end;
  1872. function GetCommonAppdataFolder: string;
  1873. begin
  1874. Result := GetSpecialFolderLocation(CSIDL_COMMON_APPDATA);
  1875. end;
  1876. function GetAppdataFolder: string;
  1877. begin
  1878. Result := GetSpecialFolderLocation(CSIDL_APPDATA);
  1879. end;
  1880. function GetLocalAppData: string;
  1881. begin
  1882. Result := GetSpecialFolderLocation(CSIDL_LOCAL_APPDATA);
  1883. end;
  1884. function GetPrinthoodFolder: string;
  1885. begin
  1886. Result := GetSpecialFolderLocation(CSIDL_PRINTHOOD);
  1887. end;
  1888. function GetCommonFavoritesFolder: string;
  1889. begin
  1890. Result := GetSpecialFolderLocation(CSIDL_COMMON_FAVORITES);
  1891. end;
  1892. function GetTemplatesFolder: string;
  1893. begin
  1894. Result := GetSpecialFolderLocation(CSIDL_TEMPLATES);
  1895. end;
  1896. function GetInternetCacheFolder: string;
  1897. begin
  1898. Result := GetSpecialFolderLocation(CSIDL_INTERNET_CACHE);
  1899. end;
  1900. function GetCookiesFolder: string;
  1901. begin
  1902. Result := GetSpecialFolderLocation(CSIDL_COOKIES);
  1903. end;
  1904. function GetHistoryFolder: string;
  1905. begin
  1906. Result := GetSpecialFolderLocation(CSIDL_HISTORY);
  1907. end;
  1908. function GetProfileFolder: string;
  1909. begin
  1910. Result := GetSpecialFolderLocation(CSIDL_PROFILE);
  1911. end;
  1912. // the following special folders are pure virtual and cannot be
  1913. // mapped to a directory path:
  1914. // CSIDL_INTERNET
  1915. // CSIDL_CONTROLS
  1916. // CSIDL_PRINTERS
  1917. // CSIDL_BITBUCKET
  1918. // CSIDL_DRIVES
  1919. // CSIDL_NETWORK
  1920. // CSIDL_ALTSTARTUP
  1921. // CSIDL_COMMON_ALTSTARTUP
  1922. // Identification
  1923. type
  1924. TVolumeInfoKind = (vikName, vikSerial, vikFileSystem);
  1925. function GetVolumeInfoHelper(const Drive: string; InfoKind: TVolumeInfoKind): string;
  1926. var
  1927. VolumeSerialNumber: DWORD;
  1928. MaximumComponentLength: DWORD;
  1929. Flags: DWORD;
  1930. Name: array [0..MAX_PATH] of Char;
  1931. FileSystem: array [0..15] of Char;
  1932. ErrorMode: Cardinal;
  1933. DriveStr: string;
  1934. begin
  1935. { TODO : Change to RootPath }
  1936. { TODO : Perform better checking of Drive param or document that no checking
  1937. is performed. RM Suggested:
  1938. DriveStr := Drive;
  1939. if (Length(Drive) < 2) or (Drive[2] <> ':') then
  1940. DriveStr := GetCurrentFolder;
  1941. DriveStr := DriveStr[1] + ':\'; }
  1942. Result := '';
  1943. DriveStr := Drive + ':\';
  1944. ErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  1945. try
  1946. Flags := 0;
  1947. MaximumComponentLength := 0;
  1948. if GetVolumeInformation(PChar(DriveStr), Name, SizeOf(Name), @VolumeSerialNumber,
  1949. MaximumComponentLength, Flags, FileSystem, SizeOf(FileSystem)) then
  1950. case InfoKind of
  1951. vikName:
  1952. Result := StrPas(Name);
  1953. vikSerial:
  1954. begin
  1955. Result := IntToHex(HiWord(VolumeSerialNumber), 4) + '-' +
  1956. IntToHex(LoWord(VolumeSerialNumber), 4);
  1957. end;
  1958. vikFileSystem:
  1959. Result := StrPas(FileSystem);
  1960. end;
  1961. finally
  1962. SetErrorMode(ErrorMode);
  1963. end;
  1964. end;
  1965. function GetVolumeName(const Drive: string): string;
  1966. begin
  1967. Result := GetVolumeInfoHelper(Drive, vikName);
  1968. end;
  1969. function GetVolumeSerialNumber(const Drive: string): string;
  1970. begin
  1971. Result := GetVolumeInfoHelper(Drive, vikSerial);
  1972. end;
  1973. function GetVolumeFileSystem(const Drive: string): string;
  1974. begin
  1975. Result := GetVolumeInfoHelper(Drive, vikFileSystem);
  1976. end;
  1977. { TODO -cHelp : Donator (incl. TFileSystemFlag[s]): Robert Rossmair }
  1978. function GetVolumeFileSystemFlags(const Volume: string): TFileSystemFlags;
  1979. const
  1980. FileSystemFlags: array [TFileSystemFlag] of DWORD =
  1981. ( FILE_CASE_SENSITIVE_SEARCH, // fsCaseSensitive
  1982. FILE_CASE_PRESERVED_NAMES, // fsCasePreservedNames
  1983. FILE_UNICODE_ON_DISK, // fsSupportsUnicodeOnDisk
  1984. FILE_PERSISTENT_ACLS, // fsPersistentACLs
  1985. FILE_FILE_COMPRESSION, // fsSupportsFileCompression
  1986. FILE_VOLUME_QUOTAS, // fsSupportsVolumeQuotas
  1987. FILE_SUPPORTS_SPARSE_FILES, // fsSupportsSparseFiles
  1988. FILE_SUPPORTS_REPARSE_POINTS, // fsSupportsReparsePoints
  1989. FILE_SUPPORTS_REMOTE_STORAGE, // fsSupportsRemoteStorage
  1990. FILE_VOLUME_IS_COMPRESSED, // fsVolumeIsCompressed
  1991. FILE_SUPPORTS_OBJECT_IDS, // fsSupportsObjectIds
  1992. FILE_SUPPORTS_ENCRYPTION, // fsSupportsEncryption
  1993. FILE_NAMED_STREAMS, // fsSupportsNamedStreams
  1994. FILE_READ_ONLY_VOLUME // fsVolumeIsReadOnly
  1995. );
  1996. var
  1997. MaximumComponentLength, Flags: Cardinal;
  1998. Flag: TFileSystemFlag;
  1999. begin
  2000. Flags := 0;
  2001. MaximumComponentLength := 0;
  2002. if not GetVolumeInformation(PChar(PathAddSeparator(Volume)), nil, 0, nil,
  2003. MaximumComponentLength, Flags, nil, 0) then
  2004. RaiseLastOSError;
  2005. Result := [];
  2006. for Flag := Low(TFileSystemFlag) to High(TFileSystemFlag) do
  2007. if (Flags and FileSystemFlags[Flag]) <> 0 then
  2008. Include(Result, Flag);
  2009. end;
  2010. {$ENDIF MSWINDOWS}
  2011. { TODO -cDoc: Contributor: twm }
  2012. function GetIPAddress(const HostName: string): string;
  2013. var
  2014. {$IFDEF MSWINDOWS}
  2015. R: Integer;
  2016. WSAData: TWSAData;
  2017. {$ENDIF MSWINDOWS}
  2018. HostEnt: PHostEnt;
  2019. Host: AnsiString;
  2020. SockAddr: TSockAddrIn;
  2021. begin
  2022. Result := '';
  2023. {$IFDEF MSWINDOWS}
  2024. WSAData.wVersion := 0;
  2025. R := WSAStartup(MakeWord(1, 1), WSAData);
  2026. if R = 0 then
  2027. try
  2028. {$ENDIF MSWINDOWS}
  2029. Host := AnsiString(HostName);
  2030. if Host = '' then
  2031. begin
  2032. SetLength(Host, MAX_PATH);
  2033. GetHostName(PAnsiChar(Host), MAX_PATH);
  2034. end;
  2035. HostEnt := GetHostByName(PAnsiChar(Host));
  2036. if HostEnt <> nil then
  2037. begin
  2038. SockAddr.sin_addr.S_addr := Longint(PLongint(HostEnt^.h_addr_list^)^);
  2039. Result := string(AnsiString(inet_ntoa(SockAddr.sin_addr)));
  2040. end;
  2041. {$IFDEF MSWINDOWS}
  2042. finally
  2043. WSACleanup;
  2044. end;
  2045. {$ENDIF MSWINDOWS}
  2046. end;
  2047. { TODO -cDoc: Donator: twm }
  2048. {$IFDEF MSWINDOWS}
  2049. procedure GetIpAddresses(Results: TStrings);
  2050. begin
  2051. GetIpAddresses(Results, '');
  2052. end;
  2053. procedure GetIpAddresses(Results: TStrings; const HostName: AnsiString);
  2054. type
  2055. TaPInAddr = array[0..10] of PInAddr;
  2056. PaPInAddr = ^TaPInAddr;
  2057. var
  2058. R: Integer;
  2059. HostEnt: PHostEnt;
  2060. pptr: PaPInAddr;
  2061. Host: AnsiString;
  2062. i: Integer;
  2063. WSAData: TWSAData;
  2064. begin
  2065. //need a socket for ioctl()
  2066. WSAData.wVersion := 0;
  2067. R := WSAStartup(MakeWord(1, 1), WSAData);
  2068. if R = 0 then begin
  2069. try
  2070. if HostName = '' then
  2071. begin
  2072. SetLength(Host, MAX_PATH);
  2073. GetHostName(PAnsiChar(Host), MAX_PATH);
  2074. end
  2075. else
  2076. Host := HostName;
  2077. HostEnt := GetHostByName(PAnsiChar(Host));
  2078. if HostEnt <> nil then
  2079. begin
  2080. pPtr := PaPInAddr(HostEnt^.h_addr_list);
  2081. i := 0;
  2082. while pPtr^[I] <> nil do begin
  2083. Results.Add(string(AnsiString(inet_ntoa(pptr^[i]^)))); // OF AnsiString to TStrings
  2084. Inc(i);
  2085. end;
  2086. end;
  2087. finally
  2088. WSACleanup;
  2089. end;
  2090. end;
  2091. end;
  2092. {$ENDIF MSWINDOWS}
  2093. {$IFDEF UNIX}
  2094. { TODO -cDoc: Donator: twm, Contributor rrossmair }
  2095. // Returns all IP addresses of the local machine in the form
  2096. // <interface>=<IP-Address> (which allows for access to the interface names
  2097. // by means of Results.Names and the addresses through Results.Values)
  2098. //
  2099. // Example:
  2100. //
  2101. // lo=127.0.0.1
  2102. // eth0=10.10.10.1
  2103. // ppp0=217.82.187.130
  2104. //
  2105. // note that this will append to Results!
  2106. //
  2107. procedure GetIpAddresses(Results: TStrings);
  2108. var
  2109. Sock: Integer;
  2110. IfReq: TIfReq;
  2111. SockAddrPtr: PSockAddrIn;
  2112. ListSave, IfList: PIfNameIndex;
  2113. begin
  2114. //need a socket for ioctl()
  2115. Sock := socket(AF_INET, SOCK_STREAM, 0);
  2116. if Sock < 0 then
  2117. RaiseLastOSError;
  2118. try
  2119. //returns pointer to dynamically allocated list of structs
  2120. ListSave := if_nameindex();
  2121. try
  2122. IfList := ListSave;
  2123. //walk thru the array returned and query for each
  2124. //interface's address
  2125. while IfList^.if_index <> 0 do
  2126. begin
  2127. //copy in the interface name to look up address of
  2128. {$IFDEF FPC}
  2129. strncpy(IfReq.ifr_ifrn.ifrn_name, IfList^.if_name, IFNAMSIZ);
  2130. {$ELSE ~FPC}
  2131. strncpy(IfReq.ifrn_name, IfList^.if_name, IFNAMSIZ);
  2132. {$ENDIF ~FPC}
  2133. //get the address for this interface
  2134. if ioctl(Sock, SIOCGIFADDR, @IfReq) <> 0 then
  2135. RaiseLastOSError;
  2136. //print out the address
  2137. {$IFDEF FPC}
  2138. SockAddrPtr := PSockAddrIn(@IfReq.ifr_ifru.ifru_addr);
  2139. Results.Add(Format('%s=%s', [IfReq.ifr_ifrn.ifrn_name, inet_ntoa(SockAddrPtr^.sin_addr)]));
  2140. {$ELSE ~FPC}
  2141. SockAddrPtr := PSockAddrIn(@IfReq.ifru_addr);
  2142. Results.Add(Format('%s=%s', [IfReq.ifrn_name, inet_ntoa(SockAddrPtr^.sin_addr)]));
  2143. {$ENDIF ~FPC}
  2144. Inc(IfList);
  2145. end;
  2146. finally
  2147. //free the dynamic memory kernel allocated for us
  2148. if_freenameindex(ListSave);
  2149. end;
  2150. finally
  2151. Libc.__close(Sock)
  2152. end;
  2153. end;
  2154. {$ENDIF UNIX}
  2155. function GetLocalComputerName: string;
  2156. // (rom) UNIX or LINUX?
  2157. {$IFDEF LINUX}
  2158. var
  2159. MachineInfo: utsname;
  2160. begin
  2161. uname(MachineInfo);
  2162. Result := MachineInfo.nodename;
  2163. end;
  2164. {$ENDIF LINUX}
  2165. {$IFDEF MSWINDOWS}
  2166. var
  2167. Count: DWORD;
  2168. begin
  2169. Count := MAX_COMPUTERNAME_LENGTH + 1;
  2170. // set buffer size to MAX_COMPUTERNAME_LENGTH + 2 characters for safety
  2171. { TODO : Win2k solution }
  2172. SetLength(Result, Count);
  2173. if GetComputerName(PChar(Result), Count) then
  2174. StrResetLength(Result)
  2175. else
  2176. Result := '';
  2177. end;
  2178. {$ENDIF MSWINDOWS}
  2179. function GetLocalUserName: string;
  2180. {$IFDEF UNIX}
  2181. begin
  2182. Result := GetEnv('USER');
  2183. end;
  2184. {$ENDIF UNIX}
  2185. {$IFDEF MSWINDOWS}
  2186. var
  2187. Count: DWORD;
  2188. begin
  2189. Count := 256 + 1; // UNLEN + 1
  2190. // set buffer size to 256 + 2 characters
  2191. { TODO : Win2k solution }
  2192. SetLength(Result, Count);
  2193. if GetUserName(PChar(Result), Count) then
  2194. StrResetLength(Result)
  2195. else
  2196. Result := '';
  2197. end;
  2198. {$ENDIF MSWINDOWS}
  2199. {$IFDEF MSWINDOWS}
  2200. function GetRegisteredCompany: string;
  2201. begin
  2202. { TODO : check for MSDN documentation }
  2203. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, REG_CURRENT_VERSION, 'RegisteredOrganization', '');
  2204. end;
  2205. function GetRegisteredOwner: string;
  2206. begin
  2207. { TODO : check for MSDN documentation }
  2208. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, REG_CURRENT_VERSION, 'RegisteredOwner', '');
  2209. end;
  2210. { TODO: Check supported platforms, maybe complete rewrite }
  2211. function GetUserDomainName(const CurUser: string): string;
  2212. var
  2213. Count1, Count2: DWORD;
  2214. Sd: PSID; // PSecurityDescriptor; // FPC requires PSID
  2215. Snu: SID_Name_Use;
  2216. begin
  2217. Count1 := 0;
  2218. Count2 := 0;
  2219. Sd := nil;
  2220. Snu := SIDTypeUser;
  2221. Result := '';
  2222. LookUpAccountName(nil, PChar(CurUser), Sd, Count1, PChar(Result), Count2, Snu);
  2223. // set buffer size to Count2 + 2 characters for safety
  2224. SetLength(Result, Count2 + 1);
  2225. Sd := AllocMem(Count1);
  2226. try
  2227. if LookUpAccountName(nil, PChar(CurUser), Sd, Count1, PChar(Result), Count2, Snu) then
  2228. StrResetLength(Result)
  2229. else
  2230. Result := EmptyStr;
  2231. finally
  2232. FreeMem(Sd);
  2233. end;
  2234. end;
  2235. function GetWorkGroupName: WideString;
  2236. var
  2237. WkstaInfo: PByte;
  2238. WkstaInfo100: PWKSTA_INFO_100;
  2239. begin
  2240. if NetWkstaGetInfo(nil, 100, WkstaInfo) <> NERR_Success then
  2241. raise EJclWin32Error.CreateRes(@RsENetWkstaGetInfo);
  2242. WkstaInfo100 := PWKSTA_INFO_100(WkstaInfo);
  2243. Result := WideString(PWideChar(WkstaInfo100^.wki100_langroup));
  2244. NetApiBufferFree(Pointer(WkstaInfo));
  2245. end;
  2246. {$ENDIF MSWINDOWS}
  2247. function GetDomainName: string;
  2248. {$IFDEF UNIX}
  2249. var
  2250. MachineInfo: utsname;
  2251. begin
  2252. uname(MachineInfo);
  2253. Result := MachineInfo.domainname;
  2254. end;
  2255. {$ENDIF UNIX}
  2256. {$IFDEF MSWINDOWS}
  2257. //091123 HA Use LookupAccountSid to fetch the current users domain ...
  2258. //begin
  2259. // Result := GetUserDomainName(GetLocalUserName);
  2260. //end;
  2261. var
  2262. hProcess, hAccessToken: THandle;
  2263. InfoBuffer: PChar;
  2264. AccountName: array [0..UNLEN] of Char;
  2265. DomainName: array [0..UNLEN] of Char;
  2266. InfoBufferSize: Cardinal;
  2267. AccountSize: Cardinal;
  2268. DomainSize: Cardinal;
  2269. snu: SID_NAME_USE;
  2270. begin
  2271. InfoBufferSize := 1000;
  2272. AccountSize := SizeOf(AccountName);
  2273. DomainSize := SizeOf(DomainName);
  2274. hProcess := GetCurrentProcess;
  2275. if OpenProcessToken(hProcess, TOKEN_READ, hAccessToken) then
  2276. try
  2277. GetMem(InfoBuffer, InfoBufferSize);
  2278. try
  2279. if GetTokenInformation(hAccessToken, TokenUser, InfoBuffer, InfoBufferSize, InfoBufferSize) then
  2280. LookupAccountSid(nil, PSIDAndAttributes(InfoBuffer)^.sid, AccountName, AccountSize,
  2281. DomainName, DomainSize, snu)
  2282. else
  2283. RaiseLastOSError;
  2284. finally
  2285. FreeMem(InfoBuffer)
  2286. end;
  2287. Result := DomainName;
  2288. finally
  2289. CloseHandle(hAccessToken);
  2290. end
  2291. end;
  2292. {$ENDIF MSWINDOWS}
  2293. {$IFDEF MSWINDOWS}
  2294. // Reference: How to Obtain BIOS Information from the Registry
  2295. // http://support.microsoft.com/default.aspx?scid=kb;en-us;q195268
  2296. function GetBIOSName: string;
  2297. const
  2298. Win9xBIOSInfoKey = 'Enum\Root\*PNP0C01\0000';
  2299. begin
  2300. if IsWinNT then
  2301. Result := ''
  2302. else
  2303. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, Win9xBIOSInfoKey, 'BIOSName', '');
  2304. end;
  2305. function GetBIOSCopyright: string;
  2306. const
  2307. ADR_BIOSCOPYRIGHT = $FE091;
  2308. begin
  2309. Result := '';
  2310. if not IsWinNT and not IsBadReadPtr(Pointer(ADR_BIOSCOPYRIGHT), 2) then
  2311. try
  2312. Result := string(AnsiString(PAnsiChar(ADR_BIOSCOPYRIGHT)));
  2313. except
  2314. Result := '';
  2315. end;
  2316. end;
  2317. function GetBIOSExtendedInfo: string;
  2318. const
  2319. ADR_BIOSEXTENDEDINFO = $FEC71;
  2320. begin
  2321. Result := '';
  2322. if not IsWinNT and not IsBadReadPtr(Pointer(ADR_BIOSEXTENDEDINFO), 2) then
  2323. try
  2324. Result := string(AnsiString(PAnsiChar(ADR_BIOSEXTENDEDINFO)));
  2325. except
  2326. Result := '';
  2327. end;
  2328. end;
  2329. // Reference: How to Obtain BIOS Information from the Registry
  2330. // http://support.microsoft.com/default.aspx?scid=kb;en-us;q195268
  2331. { TODO : the date string can be e.g. 00/00/00 }
  2332. function GetBIOSDate: TDateTime;
  2333. const
  2334. WinNT_REG_PATH = 'HARDWARE\DESCRIPTION\System';
  2335. WinNT_REG_KEY = 'SystemBiosDate';
  2336. Win9x_REG_PATH = 'Enum\Root\*PNP0C01\0000';
  2337. Win9x_REG_KEY = 'BiosDate';
  2338. var
  2339. RegStr: string;
  2340. {$IFDEF RTL150_UP}
  2341. FormatSettings: TFormatSettings;
  2342. {$ELSE ~RTL150_UP}
  2343. RegFormat: string;
  2344. RegSeparator: Char;
  2345. {$ENDIF ~RTL150_UP}
  2346. begin
  2347. if IsWinNT then
  2348. RegStr := RegReadString(HKEY_LOCAL_MACHINE, WinNT_REG_PATH, WinNT_REG_KEY)
  2349. else
  2350. RegStr := RegReadString(HKEY_LOCAL_MACHINE, Win9x_REG_PATH, Win9x_REG_KEY);
  2351. {$IFDEF RTL150_UP}
  2352. FillChar(FormatSettings, SizeOf(FormatSettings), 0);
  2353. FormatSettings.DateSeparator := '/';
  2354. FormatSettings.ShortDateFormat := 'm/d/y';
  2355. if not TryStrToDate(RegStr, Result, FormatSettings) then
  2356. begin
  2357. FormatSettings.ShortDateFormat := 'y/m/d';
  2358. if not TryStrToDate(RegStr, Result, FormatSettings) then
  2359. Result := 0;
  2360. end;
  2361. {$ELSE ~RTL150_UP}
  2362. Result := 0;
  2363. { TODO : change to a threadsafe solution }
  2364. RegFormat := ShortDateFormat;
  2365. RegSeparator := DateSeparator;
  2366. try
  2367. DateSeparator := '/';
  2368. try
  2369. ShortDateFormat := 'm/d/y';
  2370. Result := StrToDate(RegStr);
  2371. except
  2372. try
  2373. ShortDateFormat := 'y/m/d';
  2374. Result := StrToDate(RegStr);
  2375. except
  2376. end;
  2377. end;
  2378. finally
  2379. ShortDateFormat := RegFormat;
  2380. DateSeparator := RegSeparator;
  2381. end;
  2382. {$ENDIF ~RTL150_UP}
  2383. end;
  2384. {$ENDIF MSWINDOWS}
  2385. //=== Processes, Tasks and Modules ===========================================
  2386. {$IFDEF UNIX}
  2387. const
  2388. CommLen = 16; // synchronize with size of comm in struct task_struct in
  2389. // /usr/include/linux/sched.h
  2390. SProcDirectory = '/proc';
  2391. function RunningProcessesList(const List: TStrings; FullPath: Boolean): Boolean;
  2392. var
  2393. ProcDir: PDirectoryStream;
  2394. PtrDirEnt: PDirEnt;
  2395. Scratch: TDirEnt;
  2396. ProcID: __pid_t;
  2397. E: Integer;
  2398. FileName: string;
  2399. F: PIOFile;
  2400. begin
  2401. Result := False;
  2402. ProcDir := opendir(SProcDirectory);
  2403. if ProcDir <> nil then
  2404. begin
  2405. PtrDirEnt := nil;
  2406. {$IFDEF FPC}
  2407. if readdir_r(ProcDir, @Scratch, @PtrDirEnt) <> 0 then
  2408. Exit;
  2409. {$ELSE ~FPC}
  2410. if readdir_r(ProcDir, @Scratch, PtrDirEnt) <> 0 then
  2411. Exit;
  2412. {$ENDIF ~FPC}
  2413. List.BeginUpdate;
  2414. try
  2415. while PtrDirEnt <> nil do
  2416. begin
  2417. Val(PtrDirEnt^.d_name, ProcID, E);
  2418. if E = 0 then // name was process id
  2419. begin
  2420. FileName := '';
  2421. if FullPath then
  2422. FileName := SymbolicLinkTarget(Format('/proc/%s/exe', [PtrDirEnt^.d_name]));
  2423. if FileName = '' then // usually due to insufficient access rights
  2424. begin
  2425. // read stat
  2426. FileName := Format('/proc/%s/stat', [PtrDirEnt^.d_name]);
  2427. F := fopen(PChar(FileName), 'r');
  2428. if F = nil then
  2429. raise EJclError.CreateResFmt(@RsInvalidProcessID, [ProcID]);
  2430. try
  2431. SetLength(FileName, CommLen);
  2432. if fscanf(F, PChar(Format('%%*d (%%%d[^)])', [CommLen])), PChar(FileName)) <> 1 then
  2433. RaiseLastOSError;
  2434. StrResetLength(FileName);
  2435. finally
  2436. fclose(F);
  2437. end;
  2438. end;
  2439. List.AddObject(FileName, Pointer(ProcID));
  2440. end;
  2441. {$IFDEF FPC}
  2442. if readdir_r(ProcDir, @Scratch, @PtrDirEnt) <> 0 then
  2443. Break;
  2444. {$ELSE ~FPC}
  2445. if readdir_r(ProcDir, @Scratch, PtrDirEnt) <> 0 then
  2446. Break;
  2447. {$ENDIF ~FPC}
  2448. end;
  2449. finally
  2450. List.EndUpdate;
  2451. end;
  2452. end;
  2453. end;
  2454. {$ENDIF UNIX}
  2455. {$IFDEF MSWINDOWS}
  2456. function RunningProcessesList(const List: TStrings; FullPath: Boolean): Boolean;
  2457. // This function always returns an empty string on Win9x
  2458. function ProcessFileName(PID: DWORD): string;
  2459. var
  2460. Handle: THandle;
  2461. begin
  2462. Result := '';
  2463. Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
  2464. if Handle <> 0 then
  2465. try
  2466. SetLength(Result, MAX_PATH);
  2467. if FullPath then
  2468. begin
  2469. if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
  2470. StrResetLength(Result)
  2471. else
  2472. Result := '';
  2473. end
  2474. else
  2475. begin
  2476. if GetModuleBaseName(Handle, 0, PChar(Result), MAX_PATH) > 0 then
  2477. StrResetLength(Result)
  2478. else
  2479. Result := '';
  2480. end;
  2481. finally
  2482. CloseHandle(Handle);
  2483. end;
  2484. end;
  2485. { TODO: Check return value of CreateToolhelp32Snapshot on Windows NT (0?) }
  2486. function BuildListTH: Boolean;
  2487. var
  2488. SnapProcHandle: THandle;
  2489. ProcEntry: TProcessEntry32;
  2490. NextProc: Boolean;
  2491. FileName: string;
  2492. Win2kOrNewer: Boolean;
  2493. begin
  2494. SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  2495. Result := (SnapProcHandle <> INVALID_HANDLE_VALUE);
  2496. if Result then
  2497. try
  2498. Win2kOrNewer := JclCheckWinVersion(5, 0); // Win2k or newer
  2499. ProcEntry.dwSize := SizeOf(ProcEntry);
  2500. NextProc := Process32First(SnapProcHandle, ProcEntry);
  2501. while NextProc do
  2502. begin
  2503. if ProcEntry.th32ProcessID = 0 then
  2504. begin
  2505. // PID 0 is always the "System Idle Process" but this name cannot be
  2506. // retrieved from the system and has to be fabricated.
  2507. FileName := LoadResString(@RsSystemIdleProcess);
  2508. end
  2509. else
  2510. begin
  2511. if Win2kOrNewer then
  2512. begin
  2513. FileName := ProcessFileName(ProcEntry.th32ProcessID);
  2514. if FileName = '' then
  2515. FileName := ProcEntry.szExeFile;
  2516. end
  2517. else
  2518. begin
  2519. FileName := ProcEntry.szExeFile;
  2520. if not FullPath then
  2521. FileName := ExtractFileName(FileName);
  2522. end;
  2523. end;
  2524. List.AddObject(FileName, Pointer(ProcEntry.th32ProcessID));
  2525. NextProc := Process32Next(SnapProcHandle, ProcEntry);
  2526. end;
  2527. finally
  2528. CloseHandle(SnapProcHandle);
  2529. end;
  2530. end;
  2531. function BuildListPS: Boolean;
  2532. var
  2533. PIDs: array [0..1024] of DWORD;
  2534. Needed: DWORD;
  2535. I: Integer;
  2536. FileName: string;
  2537. begin
  2538. Needed := 0;
  2539. Result := EnumProcesses(@PIDs, SizeOf(PIDs), Needed);
  2540. if Result then
  2541. begin
  2542. for I := 0 to (Needed div SizeOf(DWORD)) - 1 do
  2543. begin
  2544. case PIDs[I] of
  2545. 0:
  2546. // PID 0 is always the "System Idle Process" but this name cannot be
  2547. // retrieved from the system and has to be fabricated.
  2548. FileName := LoadResString(@RsSystemIdleProcess);
  2549. 2:
  2550. // On NT 4 PID 2 is the "System Process" but this name cannot be
  2551. // retrieved from the system and has to be fabricated.
  2552. if IsWinNT4 then
  2553. FileName := LoadResString(@RsSystemProcess)
  2554. else
  2555. FileName := ProcessFileName(PIDs[I]);
  2556. 8:
  2557. // On Win2K PID 8 is the "System Process" but this name cannot be
  2558. // retrieved from the system and has to be fabricated.
  2559. if IsWin2k or IsWinXP then
  2560. FileName := LoadResString(@RsSystemProcess)
  2561. else
  2562. FileName := ProcessFileName(PIDs[I]);
  2563. else
  2564. FileName := ProcessFileName(PIDs[I]);
  2565. end;
  2566. if FileName <> '' then
  2567. List.AddObject(FileName, Pointer(PIDs[I]));
  2568. end;
  2569. end;
  2570. end;
  2571. begin
  2572. { TODO : safer solution? }
  2573. List.BeginUpdate;
  2574. try
  2575. if GetWindowsVersion in [wvWinNT31, wvWinNT35, wvWinNT351, wvWinNT4] then
  2576. Result := BuildListPS
  2577. else
  2578. Result := BuildListTH;
  2579. finally
  2580. List.EndUpdate;
  2581. end;
  2582. end;
  2583. { TODO Windows 9x ? }
  2584. function LoadedModulesList(const List: TStrings; ProcessID: DWORD; HandlesOnly: Boolean): Boolean;
  2585. procedure AddToList(ProcessHandle: THandle; Module: HMODULE);
  2586. var
  2587. FileName: array [0..MAX_PATH] of Char;
  2588. ModuleInfo: TModuleInfo;
  2589. begin
  2590. ModuleInfo.EntryPoint := nil;
  2591. {$IFDEF FPC}
  2592. if GetModuleInformation(ProcessHandle, Module, ModuleInfo, SizeOf(ModuleInfo)) then
  2593. {$ELSE ~FPC}
  2594. if GetModuleInformation(ProcessHandle, Module, @ModuleInfo, SizeOf(ModuleInfo)) then
  2595. {$ENDIF ~FPC}
  2596. begin
  2597. if HandlesOnly then
  2598. List.AddObject('', Pointer(ModuleInfo.lpBaseOfDll))
  2599. else
  2600. if GetModuleFileNameEx(ProcessHandle, Module, Filename, SizeOf(Filename)) > 0 then
  2601. List.AddObject(FileName, Pointer(ModuleInfo.lpBaseOfDll));
  2602. end;
  2603. end;
  2604. function EnumModulesVQ(ProcessHandle: THandle): Boolean;
  2605. var
  2606. MemInfo: TMemoryBasicInformation;
  2607. Base: PChar;
  2608. LastAllocBase: Pointer;
  2609. Res: DWORD;
  2610. begin
  2611. Base := nil;
  2612. LastAllocBase := nil;
  2613. ResetMemory(MemInfo, SizeOf(MemInfo));
  2614. Res := VirtualQueryEx(ProcessHandle, Base, MemInfo, SizeOf(MemInfo));
  2615. Result := (Res = SizeOf(MemInfo));
  2616. while Res = SizeOf(MemInfo) do
  2617. begin
  2618. if MemInfo.AllocationBase <> LastAllocBase then
  2619. begin
  2620. {$IFDEF FPC}
  2621. if MemInfo._Type = MEM_IMAGE then
  2622. {$ELSE ~FPC}
  2623. if MemInfo.Type_9 = MEM_IMAGE then
  2624. {$ENDIF ~FPC}
  2625. AddToList(ProcessHandle, HMODULE(MemInfo.AllocationBase));
  2626. LastAllocBase := MemInfo.AllocationBase;
  2627. end;
  2628. Inc(Base, MemInfo.RegionSize);
  2629. Res := VirtualQueryEx(ProcessHandle, Base, MemInfo, SizeOf(MemInfo));
  2630. end;
  2631. end;
  2632. function EnumModulesPS: Boolean;
  2633. var
  2634. ProcessHandle: THandle;
  2635. Needed: DWORD;
  2636. Modules: array of THandle;
  2637. I, Cnt: Integer;
  2638. begin
  2639. Result := False;
  2640. ProcessHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, ProcessID);
  2641. if ProcessHandle <> 0 then
  2642. try
  2643. Needed := 0;
  2644. Result := EnumProcessModules(ProcessHandle, nil, 0, Needed);
  2645. if Result then
  2646. begin
  2647. Cnt := Needed div SizeOf(HMODULE);
  2648. SetLength(Modules, Cnt);
  2649. if EnumProcessModules(ProcessHandle, @Modules[0], Needed, Needed) then
  2650. for I := 0 to Cnt - 1 do
  2651. AddToList(ProcessHandle, Modules[I]);
  2652. end
  2653. else
  2654. Result := EnumModulesVQ(ProcessHandle);
  2655. finally
  2656. CloseHandle(ProcessHandle);
  2657. end;
  2658. end;
  2659. { TODO: Check return value of CreateToolhelp32Snapshot on Windows NT (0?) }
  2660. function EnumModulesTH: Boolean;
  2661. var
  2662. SnapProcHandle: THandle;
  2663. Module: TModuleEntry32;
  2664. Next: Boolean;
  2665. begin
  2666. SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcessID);
  2667. Result := (SnapProcHandle <> INVALID_HANDLE_VALUE);
  2668. if Result then
  2669. try
  2670. ResetMemory(Module, SizeOf(Module));
  2671. Module.dwSize := SizeOf(Module);
  2672. Next := Module32First(SnapProcHandle, Module);
  2673. while Next do
  2674. begin
  2675. if HandlesOnly then
  2676. List.AddObject('', Pointer(Module.hModule))
  2677. else
  2678. List.AddObject(Module.szExePath, Pointer(Module.hModule));
  2679. Next := Module32Next(SnapProcHandle, Module);
  2680. end;
  2681. finally
  2682. CloseHandle(SnapProcHandle);
  2683. end;
  2684. end;
  2685. begin
  2686. List.BeginUpdate;
  2687. try
  2688. if IsWinNT then
  2689. Result := EnumModulesPS
  2690. else
  2691. Result := EnumModulesTH;
  2692. finally
  2693. List.EndUpdate;
  2694. end;
  2695. end;
  2696. function EnumTaskWindowsProc(Wnd: THandle; List: TStrings): Boolean; stdcall;
  2697. var
  2698. Caption: array [0..1024] of Char;
  2699. begin
  2700. if IsMainAppWindow(Wnd) and (GetWindowText(Wnd, Caption, SizeOf(Caption)) > 0) then
  2701. List.AddObject(Caption, Pointer(Wnd));
  2702. Result := True;
  2703. end;
  2704. function GetTasksList(const List: TStrings): Boolean;
  2705. begin
  2706. List.BeginUpdate;
  2707. try
  2708. Result := EnumWindows(@EnumTaskWindowsProc, LPARAM(List));
  2709. finally
  2710. List.EndUpdate;
  2711. end;
  2712. end;
  2713. function ModuleFromAddr(const Addr: Pointer): HMODULE;
  2714. var
  2715. MI: TMemoryBasicInformation;
  2716. begin
  2717. MI.AllocationBase := nil;
  2718. VirtualQuery(Addr, MI, SizeOf(MI));
  2719. if MI.State <> MEM_COMMIT then
  2720. Result := 0
  2721. else
  2722. Result := HMODULE(MI.AllocationBase);
  2723. end;
  2724. function IsSystemModule(const Module: HMODULE): Boolean;
  2725. var
  2726. CurModule: PLibModule;
  2727. begin
  2728. Result := False;
  2729. if Module <> 0 then
  2730. begin
  2731. CurModule := LibModuleList;
  2732. while CurModule <> nil do
  2733. begin
  2734. if CurModule.Instance = Module then
  2735. begin
  2736. Result := True;
  2737. Break;
  2738. end;
  2739. CurModule := CurModule.Next;
  2740. end;
  2741. end;
  2742. end;
  2743. // Reference: http://msdn.microsoft.com/library/periodic/period97/win321197.htm
  2744. { TODO : wrong link }
  2745. function IsMainAppWindow(Wnd: THandle): Boolean;
  2746. var
  2747. ParentWnd: THandle;
  2748. ExStyle: DWORD;
  2749. begin
  2750. if IsWindowVisible(Wnd) then
  2751. begin
  2752. ParentWnd := THandle(GetWindowLongPtr(Wnd, GWLP_HWNDPARENT));
  2753. ExStyle := GetWindowLongPtr(Wnd, GWL_EXSTYLE);
  2754. Result := ((ParentWnd = 0) or (ParentWnd = GetDesktopWindow)) and
  2755. ((ExStyle and WS_EX_TOOLWINDOW = 0) or (ExStyle and WS_EX_APPWINDOW <> 0));
  2756. end
  2757. else
  2758. Result := False;
  2759. end;
  2760. function IsWindowResponding(Wnd: THandle; Timeout: Integer): Boolean;
  2761. var
  2762. Res: DWORD;
  2763. begin
  2764. Res := 0;
  2765. Result := SendMessageTimeout(Wnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, Timeout, {$IFDEF RTL230_UP}@{$ENDIF}Res) <> 0;
  2766. end;
  2767. function GetWindowIcon(Wnd: THandle; LargeIcon: Boolean): HICON;
  2768. var
  2769. Width, Height: Integer;
  2770. TempIcon: HICON;
  2771. IconType: DWORD;
  2772. begin
  2773. if LargeIcon then
  2774. begin
  2775. Width := GetSystemMetrics(SM_CXICON);
  2776. Height := GetSystemMetrics(SM_CYICON);
  2777. IconType := ICON_BIG;
  2778. TempIcon := GetClassLong(Wnd, GCL_HICON);
  2779. end
  2780. else
  2781. begin
  2782. Width := GetSystemMetrics(SM_CXSMICON);
  2783. Height := GetSystemMetrics(SM_CYSMICON);
  2784. IconType := ICON_SMALL;
  2785. TempIcon := GetClassLong(Wnd, GCL_HICONSM);
  2786. end;
  2787. if TempIcon = 0 then
  2788. TempIcon := SendMessage(Wnd, WM_GETICON, IconType, 0);
  2789. if (TempIcon = 0) and not LargeIcon then
  2790. TempIcon := SendMessage(Wnd, WM_GETICON, ICON_BIG, 0);
  2791. Result := CopyImage(TempIcon, IMAGE_ICON, Width, Height, 0);
  2792. end;
  2793. function GetWindowCaption(Wnd: THandle): string;
  2794. var
  2795. Buffer: string;
  2796. Size: Integer;
  2797. begin
  2798. Size := GetWindowTextLength(Wnd);
  2799. if Size = 0 then
  2800. Size := 1; // always allocate at least one byte, otherwise PChar(Buffer) returns nil
  2801. SetLength(Buffer, Size);
  2802. // strings always have an additional null character
  2803. Size := GetWindowText(Wnd, PChar(Buffer), Size + 1);
  2804. Result := Copy(Buffer, 1, Size);
  2805. end;
  2806. // Q178893
  2807. // http://support.microsoft.com/default.aspx?scid=kb;en-us;178893
  2808. function EnumTerminateAppWindowsProc(Wnd: THandle; ProcessID: DWORD): Boolean; stdcall;
  2809. var
  2810. PID: DWORD;
  2811. begin
  2812. GetWindowThreadProcessId(Wnd, @PID);
  2813. if ProcessID = PID then
  2814. PostMessage(Wnd, WM_CLOSE, 0, 0);
  2815. Result := True;
  2816. end;
  2817. function TerminateApp(ProcessID: DWORD; Timeout: Integer): TJclTerminateAppResult;
  2818. var
  2819. ProcessHandle: THandle;
  2820. begin
  2821. Result := taError;
  2822. if ProcessID <> GetCurrentProcessId then
  2823. begin
  2824. ProcessHandle := OpenProcess(SYNCHRONIZE or PROCESS_TERMINATE, False, ProcessID);
  2825. if ProcessHandle <> 0 then
  2826. try
  2827. EnumWindows(@EnumTerminateAppWindowsProc, LPARAM(ProcessID));
  2828. if WaitForSingleObject(ProcessHandle, Timeout) = WAIT_OBJECT_0 then
  2829. Result := taClean
  2830. else
  2831. if TerminateProcess(ProcessHandle, 0) then
  2832. Result := taKill;
  2833. finally
  2834. CloseHandle(ProcessHandle);
  2835. end;
  2836. end;
  2837. end;
  2838. function TerminateTask(Wnd: THandle; Timeout: Integer): TJclTerminateAppResult;
  2839. var
  2840. PID: DWORD;
  2841. begin
  2842. if GetWindowThreadProcessId(Wnd, @PID) <> 0 then
  2843. Result := TerminateApp(PID, Timeout)
  2844. else
  2845. Result := taError;
  2846. end;
  2847. function GetProcessNameFromWnd(Wnd: THandle): string;
  2848. var
  2849. List: TStringList;
  2850. PID: THandle;
  2851. I: Integer;
  2852. begin
  2853. Result := '';
  2854. if IsWindow(Wnd) then
  2855. begin
  2856. PID := INVALID_HANDLE_VALUE;
  2857. GetWindowThreadProcessId(Wnd, @PID);
  2858. List := TStringList.Create;
  2859. try
  2860. if RunningProcessesList(List, True) then
  2861. begin
  2862. I := List.IndexOfObject(Pointer(PID));
  2863. if I > -1 then
  2864. Result := List[I];
  2865. end;
  2866. finally
  2867. List.Free;
  2868. end;
  2869. end;
  2870. end;
  2871. function GetPidFromProcessName(const ProcessName: string): THandle;
  2872. var
  2873. List: TStringList;
  2874. I: Integer;
  2875. HasFullPath: Boolean;
  2876. begin
  2877. Result := INVALID_HANDLE_VALUE;
  2878. List := TStringList.Create;
  2879. try
  2880. HasFullPath := ExtractFilePath(ProcessName) <> '';
  2881. if RunningProcessesList(List, HasFullPath) then
  2882. begin
  2883. I := List.IndexOf(ProcessName);
  2884. if I > -1 then
  2885. Result := DWORD(List.Objects[I]);
  2886. end;
  2887. finally
  2888. List.Free;
  2889. end;
  2890. end;
  2891. function GetProcessNameFromPid(PID: DWORD): string;
  2892. var
  2893. List: TStringList;
  2894. I: Integer;
  2895. begin
  2896. // Note: there are other ways to retrieve the name of the process given it's
  2897. // PID but this implementation seems to work best without making assumptions
  2898. // although it may not be the most efficient implementation.
  2899. Result := '';
  2900. List := TStringList.Create;
  2901. try
  2902. if RunningProcessesList(List, True) then
  2903. begin
  2904. I := List.IndexOfObject(Pointer(PID));
  2905. if I > -1 then
  2906. Result := List[I];
  2907. end;
  2908. finally
  2909. List.Free;
  2910. end;
  2911. end;
  2912. type
  2913. PSearch = ^TSearch;
  2914. TSearch = record
  2915. PID: DWORD;
  2916. Wnd: THandle;
  2917. end;
  2918. function EnumMainAppWindowsProc(Wnd: THandle; Res: PSearch): Boolean; stdcall;
  2919. var
  2920. WindowPid: DWORD;
  2921. begin
  2922. WindowPid := 0;
  2923. GetWindowThreadProcessId(Wnd, @WindowPid);
  2924. if (WindowPid = Res^.PID) and IsMainAppWindow(Wnd) then
  2925. begin
  2926. Res^.Wnd := Wnd;
  2927. Result := False;
  2928. end
  2929. else
  2930. Result := True;
  2931. end;
  2932. function GetMainAppWndFromPid(PID: DWORD): THandle;
  2933. var
  2934. SearchRec: TSearch;
  2935. begin
  2936. SearchRec.PID := PID;
  2937. SearchRec.Wnd := 0;
  2938. EnumWindows(@EnumMainAppWindowsProc, LPARAM(@SearchRec));
  2939. Result := SearchRec.Wnd;
  2940. end;
  2941. type
  2942. PEnumWndStruct = ^TEnumWndStruct;
  2943. TEnumWndStruct = record
  2944. PID: DWORD;
  2945. WndClassName: string;
  2946. ResultWnd: HWND;
  2947. end;
  2948. function EnumPidWinProc(Wnd: HWND; Enum: PEnumWndStruct): BOOL; stdcall;
  2949. var
  2950. PID: DWORD;
  2951. C: PChar;
  2952. CLen: Integer;
  2953. begin
  2954. Result := True;
  2955. GetWindowThreadProcessId(Wnd, @PID);
  2956. if (PID = Enum.PID) then
  2957. begin
  2958. CLen := Length(Enum.WndClassName)+1;
  2959. C := StrAlloc(CLen);
  2960. if (GetClassName(Wnd, C, CLen) > 0) then
  2961. if (C = Enum.WndClassName) then
  2962. begin
  2963. Result := False;
  2964. Enum.ResultWnd := Wnd;
  2965. end;
  2966. StrDispose(C);
  2967. end;
  2968. end;
  2969. function GetWndFromPid(PID: DWORD; const WindowClassName: string): HWND;
  2970. var
  2971. EnumWndStruct: TEnumWndStruct;
  2972. begin
  2973. EnumWndStruct.PID := PID;
  2974. EnumWndStruct.WndClassName := WindowClassName;
  2975. EnumWndStruct.ResultWnd := 0;
  2976. EnumWindows(@EnumPidWinProc, LPARAM(@EnumWndStruct));
  2977. Result := EnumWndStruct.ResultWnd;
  2978. end;
  2979. function GetShellProcessName: string;
  2980. const
  2981. cShellKey = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon';
  2982. cShellValue = 'Shell';
  2983. cShellDefault = 'explorer.exe';
  2984. cShellSystemIniFileName = 'system.ini';
  2985. cShellBootSection = 'boot';
  2986. begin
  2987. if IsWinNT then
  2988. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, cShellKey, cShellValue, '')
  2989. else
  2990. Result := IniReadString(PathAddSeparator(GetWindowsFolder) + cShellSystemIniFileName, cShellBootSection, cShellValue);
  2991. if Result = '' then
  2992. Result := cShellDefault;
  2993. end;
  2994. function GetShellProcessHandle: THandle;
  2995. var
  2996. Pid: Longword;
  2997. begin
  2998. Pid := GetPidFromProcessName(GetShellProcessName);
  2999. Result := OpenProcess(PROCESS_ALL_ACCESS, False, Pid);
  3000. if Result = 0 then
  3001. RaiseLastOSError;
  3002. end;
  3003. //=== Version Information ====================================================
  3004. { Q159/238
  3005. Windows 95 retail, OEM 4.00.950 7/11/95
  3006. Windows 95 retail SP1 4.00.950A 7/11/95-12/31/95
  3007. OEM Service Release 2 4.00.1111* (4.00.950B) 8/24/96
  3008. OEM Service Release 2.1 4.03.1212-1214* (4.00.950B) 8/24/96-8/27/97
  3009. OEM Service Release 2.5 4.03.1214* (4.00.950C) 8/24/96-11/18/97
  3010. Windows 98 retail, OEM 4.10.1998 5/11/98
  3011. Windows 98 Second Edition 4.10.2222A 4/23/99
  3012. Windows Millennium 4.90.3000
  3013. }
  3014. { TODO : Distinquish between all these different releases? }
  3015. var
  3016. KernelVersionHi: DWORD;
  3017. function GetWindowsVersion: TWindowsVersion;
  3018. var
  3019. TrimmedWin32CSDVersion: string;
  3020. SystemInfo: TSystemInfo;
  3021. OSVersionInfoEx: TOSVersionInfoEx;
  3022. Win32MajorVersionEx, Win32MinorVersionEx: integer;
  3023. ProductName: string;
  3024. const
  3025. SM_SERVERR2 = 89;
  3026. begin
  3027. Win32MajorVersionEx := -1;
  3028. Result := wvUnknown;
  3029. TrimmedWin32CSDVersion := Trim(Win32CSDVersion);
  3030. case Win32Platform of
  3031. VER_PLATFORM_WIN32_WINDOWS:
  3032. case Win32MinorVersion of
  3033. 0..9:
  3034. if (TrimmedWin32CSDVersion = 'B') or (TrimmedWin32CSDVersion = 'C') then
  3035. Result := wvWin95OSR2
  3036. else
  3037. Result := wvWin95;
  3038. 10..89:
  3039. // On Windows ME Win32MinorVersion can be 10 (indicating Windows 98
  3040. // under certain circumstances (image name is setup.exe). Checking
  3041. // the kernel version is one way of working around that.
  3042. if KernelVersionHi = $0004005A then // 4.90.x.x
  3043. Result := wvWinME
  3044. else
  3045. if (TrimmedWin32CSDVersion = 'A') or (TrimmedWin32CSDVersion = 'B') then
  3046. Result := wvWin98SE
  3047. else
  3048. Result := wvWin98;
  3049. 90:
  3050. Result := wvWinME;
  3051. end;
  3052. VER_PLATFORM_WIN32_NT:
  3053. case Win32MajorVersion of
  3054. 3:
  3055. case Win32MinorVersion of
  3056. 1:
  3057. Result := wvWinNT31;
  3058. 5:
  3059. Result := wvWinNT35;
  3060. 51:
  3061. Result := wvWinNT351;
  3062. end;
  3063. 4:
  3064. Result := wvWinNT4;
  3065. 5:
  3066. case Win32MinorVersion of
  3067. 0:
  3068. Result := wvWin2000;
  3069. 1:
  3070. Result := wvWinXP;
  3071. 2:
  3072. begin
  3073. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3074. SystemInfo.dwOemId := 0;
  3075. GetNativeSystemInfo(SystemInfo);
  3076. if GetSystemMetrics(SM_SERVERR2) <> 0 then
  3077. Result := wvWin2003R2
  3078. else
  3079. if (SystemInfo.wProcessorArchitecture <> PROCESSOR_ARCHITECTURE_INTEL) and
  3080. GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3081. Result := wvWinXP64
  3082. else
  3083. Result := wvWin2003;
  3084. end;
  3085. end;
  3086. 6:
  3087. begin
  3088. // Starting with Windows 8.1, the GetVersion(Ex) API is deprecated and will detect the
  3089. // application as Windows 8 (kernel version 6.2) until an application manifest is included
  3090. // See https://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
  3091. if Win32MinorVersion = 2 then
  3092. begin
  3093. ProductName := RegReadStringDef(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ProductName', '');
  3094. if (pos(RsOSVersionWin81, ProductName) = 1) or (pos(RsOSVersionWinServer2012R2, ProductName) = 1) then
  3095. Win32MinorVersionEx := 3 // Windows 8.1 and Windows Server 2012R2
  3096. else
  3097. if (pos(RsOSVersionWin8, ProductName) = 1) or (pos(RsOSVersionWinServer2012, ProductName) = 1) then
  3098. Win32MinorVersionEx := 2 // Windows 8 and Windows Server 2012
  3099. else
  3100. begin
  3101. Win32MajorVersionEx := GetWindowsMajorVersionNumber;
  3102. if Win32MajorVersionEx = 6 then
  3103. Win32MinorVersionEx := 4 // Windows 10 (builds < 9926) and Windows Server 2016 (builds < 10074)
  3104. else
  3105. if Win32MajorVersionEx = 10 then
  3106. Win32MinorVersionEx := -1 // Windows 10 (builds >= 9926) and Windows Server 2016 (builds >= 10074), set to -1 to escape case block
  3107. else
  3108. Win32MinorVersionEx := Win32MinorVersion;
  3109. end;
  3110. end
  3111. else
  3112. Win32MinorVersionEx := Win32MinorVersion;
  3113. case Win32MinorVersionEx of
  3114. 0:
  3115. begin
  3116. // Windows Vista and Windows Server 2008
  3117. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3118. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3119. Result := wvWinVista
  3120. else
  3121. Result := wvWinServer2008;
  3122. end;
  3123. 1:
  3124. begin
  3125. // Windows 7 and Windows Server 2008 R2
  3126. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3127. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3128. Result := wvWin7
  3129. else
  3130. Result := wvWinServer2008R2;
  3131. end;
  3132. 2:
  3133. begin
  3134. // Windows 8 and Windows Server 2012
  3135. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3136. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3137. Result := wvWin8
  3138. else
  3139. Result := wvWinServer2012;
  3140. end;
  3141. 3:
  3142. begin
  3143. // Windows 8.1 and Windows Server 2012 R2
  3144. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3145. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3146. Result := wvWin81
  3147. else
  3148. Result := wvWinServer2012R2;
  3149. end;
  3150. 4:
  3151. begin
  3152. // Windows 10 (builds < 9926) and Windows Server 2016 (builds < 10074)
  3153. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3154. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3155. Result := wvWin10
  3156. else
  3157. Result := wvWinServer2016;
  3158. end;
  3159. end;
  3160. end;
  3161. 10:
  3162. Win32MajorVersionEx := Win32MajorVersion;
  3163. end;
  3164. end;
  3165. // This part will only be hit with Windows 10 and Windows Server 2016 (and newer) where an application manifest is not included
  3166. if (Win32MajorVersionEx >= 10) then
  3167. begin
  3168. case Win32MajorVersionEx of
  3169. 10:
  3170. begin
  3171. Win32MinorVersionEx := GetWindowsMinorVersionNumber;
  3172. case Win32MinorVersionEx of
  3173. 0:
  3174. begin
  3175. // Windows 10 (builds >= 9926) and Windows Server 2016 (builds >= 10074)
  3176. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3177. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3178. Result := wvWin10
  3179. else
  3180. Result := wvWinServer2016;
  3181. end;
  3182. end;
  3183. end;
  3184. end;
  3185. end;
  3186. end;
  3187. function GetWindowsEdition: TWindowsEdition;
  3188. const
  3189. ProductName = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion';
  3190. var
  3191. Edition: string;
  3192. begin
  3193. Result := weUnknown;
  3194. Edition := RegReadStringDef(HKEY_LOCAL_MACHINE, ProductName, 'ProductName', '');
  3195. // Remove (tm) in 'Windows (TM) Vista Ultimate'
  3196. Edition := StringReplace(Edition, '(TM) ', '', [rfReplaceAll, rfIgnoreCase]);
  3197. if Pos('Windows XP', Edition) = 1 then
  3198. begin
  3199. // Windows XP Editions
  3200. if Pos('Home Edition N', Edition) > 0 then
  3201. Result := weWinXPHomeN
  3202. else
  3203. if Pos('Professional N', Edition) > 0 then
  3204. Result := weWinXPProN
  3205. else
  3206. if Pos('Home Edition K', Edition) > 0 then
  3207. Result := weWinXPHomeK
  3208. else
  3209. if Pos('Professional K', Edition) > 0 then
  3210. Result := weWinXPProK
  3211. else
  3212. if Pos('Home Edition KN', Edition) > 0 then
  3213. Result := weWinXPHomeKN
  3214. else
  3215. if Pos('Professional KN', Edition) > 0 then
  3216. Result := weWinXPProKN
  3217. else
  3218. if Pos('Home', Edition) > 0 then
  3219. Result := weWinXPHome
  3220. else
  3221. if Pos('Professional', Edition) > 0 then
  3222. Result := weWinXPPro
  3223. else
  3224. if Pos('Starter', Edition) > 0 then
  3225. Result := weWinXPStarter
  3226. else
  3227. if Pos('Media Center', Edition) > 0 then
  3228. Result := weWinXPMediaCenter
  3229. else
  3230. if Pos('Tablet', Edition) > 0 then
  3231. Result := weWinXPTablet;
  3232. end
  3233. else
  3234. if (Pos('Windows Vista', Edition) = 1) then
  3235. begin
  3236. // Windows Vista Editions
  3237. if Pos('Starter', Edition) > 0 then
  3238. Result := weWinVistaStarter
  3239. else
  3240. if Pos('Home Basic N', Edition) > 0 then
  3241. Result := weWinVistaHomeBasicN
  3242. else
  3243. if Pos('Home Basic', Edition) > 0 then
  3244. Result := weWinVistaHomeBasic
  3245. else
  3246. if Pos('Home Premium', Edition) > 0 then
  3247. Result := weWinVistaHomePremium
  3248. else
  3249. if Pos('Business N', Edition) > 0 then
  3250. Result := weWinVistaBusinessN
  3251. else
  3252. if Pos('Business', Edition) > 0 then
  3253. Result := weWinVistaBusiness
  3254. else
  3255. if Pos('Enterprise', Edition) > 0 then
  3256. Result := weWinVistaEnterprise
  3257. else
  3258. if Pos('Ultimate', Edition) > 0 then
  3259. Result := weWinVistaUltimate;
  3260. end
  3261. else
  3262. if Pos('Windows 7', Edition) = 1 then
  3263. begin
  3264. // Windows 7 Editions
  3265. if Pos('Starter', Edition) > 0 then
  3266. Result := weWin7Starter
  3267. else
  3268. if Pos('Home Basic', Edition) > 0 then
  3269. Result := weWin7HomeBasic
  3270. else
  3271. if Pos('Home Premium', Edition) > 0 then
  3272. Result := weWin7HomePremium
  3273. else
  3274. if Pos('Professional', Edition) > 0 then
  3275. Result := weWin7Professional
  3276. else
  3277. if Pos('Enterprise', Edition) > 0 then
  3278. Result := weWin7Enterprise
  3279. else
  3280. if Pos('Ultimate', Edition) > 0 then
  3281. Result := weWin7Ultimate;
  3282. end
  3283. else
  3284. if Pos('Windows 8.1', Edition) = 1 then
  3285. begin
  3286. // Windows 8.1 Editions
  3287. if Pos('Pro', Edition) > 0 then
  3288. Result := weWin81Pro
  3289. else
  3290. if Pos('Enterprise', Edition) > 0 then
  3291. Result := weWin81Enterprise
  3292. else
  3293. Result := weWin81;
  3294. end
  3295. else
  3296. if Pos('Windows 8', Edition) = 1 then
  3297. begin
  3298. // Windows 8 Editions
  3299. if Pos('Pro', Edition) > 0 then
  3300. Result := weWin8Pro
  3301. else
  3302. if Pos('Enterprise', Edition) > 0 then
  3303. Result := weWin8Enterprise
  3304. else
  3305. Result := weWin8;
  3306. end
  3307. else
  3308. if Pos('Windows RT 8.1', Edition) = 1 then
  3309. Result := weWin81RT
  3310. else
  3311. if Pos('Windows RT', Edition) = 1 then
  3312. Result := weWin8RT
  3313. else
  3314. if Pos('Windows 10', Edition) = 1 then
  3315. begin
  3316. // Windows 10 Editions
  3317. if Pos('Home', Edition) > 0 then
  3318. Result := weWin10Home
  3319. else
  3320. if Pos('Pro', Edition) > 0 then
  3321. Result := weWin10Pro
  3322. else
  3323. if Pos('Enterprise', Edition) > 0 then
  3324. Result := weWin10Enterprise
  3325. else
  3326. if Pos('Education', Edition) > 0 then
  3327. Result := weWin10Education
  3328. else
  3329. Result := weWin10;
  3330. end
  3331. end;
  3332. function NtProductType: TNtProductType;
  3333. const
  3334. ProductType = 'SYSTEM\CurrentControlSet\Control\ProductOptions';
  3335. var
  3336. Product: string;
  3337. OSVersionInfo: TOSVersionInfoEx;
  3338. SystemInfo: TSystemInfo;
  3339. begin
  3340. Result := ptUnknown;
  3341. ResetMemory(OSVersionInfo, SizeOf(OSVersionInfo));
  3342. ResetMemory(SystemInfo, SizeOf(SystemInfo));
  3343. OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo);
  3344. GetNativeSystemInfo(SystemInfo);
  3345. // Favor documented API over registry
  3346. if IsWinNT4 and (GetWindowsServicePackVersion >= 6) then
  3347. begin
  3348. if GetVersionEx(OSVersionInfo) then
  3349. begin
  3350. if (OSVersionInfo.wProductType = VER_NT_WORKSTATION) then
  3351. Result := ptWorkstation
  3352. else
  3353. if (OSVersionInfo.wSuiteMask and VER_SUITE_ENTERPRISE) = VER_SUITE_ENTERPRISE then
  3354. Result := ptEnterprise
  3355. else
  3356. Result := ptServer;
  3357. end;
  3358. end
  3359. else
  3360. if IsWin2K then
  3361. begin
  3362. if GetVersionEx(OSVersionInfo) then
  3363. begin
  3364. if OSVersionInfo.wProductType in [VER_NT_SERVER, VER_NT_DOMAIN_CONTROLLER] then
  3365. begin
  3366. if (OSVersionInfo.wSuiteMask and VER_SUITE_DATACENTER) <> 0 then
  3367. Result := ptDatacenterServer
  3368. else
  3369. if (OSVersionInfo.wSuiteMask and VER_SUITE_ENTERPRISE) <> 0 then
  3370. Result := ptAdvancedServer
  3371. else
  3372. Result := ptServer;
  3373. end
  3374. else
  3375. Result := ptProfessional;
  3376. end;
  3377. end
  3378. else
  3379. if IsWinXP64 or IsWin2003 or IsWin2003R2 then // all (5.2)
  3380. begin
  3381. if GetVersionEx(OSVersionInfo) then
  3382. begin
  3383. if OSVersionInfo.wProductType in [VER_NT_SERVER, VER_NT_DOMAIN_CONTROLLER] then
  3384. begin
  3385. if (OSVersionInfo.wSuiteMask and VER_SUITE_DATACENTER) = VER_SUITE_DATACENTER then
  3386. Result := ptDatacenterServer
  3387. else
  3388. if (OSVersionInfo.wSuiteMask and VER_SUITE_ENTERPRISE) = VER_SUITE_ENTERPRISE then
  3389. Result := ptEnterprise
  3390. else
  3391. if (OSVersionInfo.wSuiteMask = VER_SUITE_BLADE) then
  3392. Result := ptWebEdition
  3393. else
  3394. Result := ptServer;
  3395. end
  3396. else
  3397. if (OSVersionInfo.wProductType = VER_NT_WORKSTATION) then
  3398. Result := ptProfessional;
  3399. end;
  3400. end
  3401. else
  3402. if JclCheckWinVersion(5, 1) then // Windows XP or newer
  3403. begin
  3404. if GetVersionEx(OSVersionInfo) then
  3405. begin
  3406. //if IsWinXP or IsWinVista or IsWin7 or IsWin8 or IsWin81 or IsWin10 then
  3407. if OSVersionInfo.wProductType = VER_NT_WORKSTATION then // workstation
  3408. begin
  3409. if (OSVersionInfo.wSuiteMask and VER_SUITE_PERSONAL) = VER_SUITE_PERSONAL then
  3410. Result := ptPersonal
  3411. else
  3412. Result := ptProfessional;
  3413. end
  3414. else
  3415. //if IsWinServer2008 or IsWinServer2008R2 or IsWinServer2012 or IsWinServer2012R2 then
  3416. if OSVersionInfo.wProductType in [VER_NT_SERVER, VER_NT_DOMAIN_CONTROLLER] then // server
  3417. begin
  3418. if (OSVersionInfo.wSuiteMask and VER_SUITE_DATACENTER) = VER_SUITE_DATACENTER then
  3419. Result := ptDatacenterServer
  3420. else
  3421. if (OSVersionInfo.wSuiteMask and VER_SUITE_ENTERPRISE) = VER_SUITE_ENTERPRISE then
  3422. Result := ptEnterprise
  3423. else
  3424. Result := ptServer;
  3425. end;
  3426. end;
  3427. end;
  3428. if Result = ptUnknown then
  3429. begin
  3430. // Non Windows 2000/XP system or the above method failed, try registry
  3431. Product := RegReadStringDef(HKEY_LOCAL_MACHINE, ProductType, 'ProductType', '');
  3432. if CompareText(Product, 'WINNT') = 0 then
  3433. Result := ptWorkStation
  3434. else
  3435. if CompareText(Product, 'SERVERNT') = 0 then
  3436. Result := {ptServer} ptAdvancedServer
  3437. else
  3438. if CompareText(Product, 'LANMANNT') = 0 then
  3439. Result := {ptAdvancedServer} ptServer
  3440. else
  3441. Result := ptUnknown;
  3442. end;
  3443. end;
  3444. function GetWindowsVersionString: string;
  3445. begin
  3446. case GetWindowsVersion of
  3447. wvWin95:
  3448. Result := LoadResString(@RsOSVersionWin95);
  3449. wvWin95OSR2:
  3450. Result := LoadResString(@RsOSVersionWin95OSR2);
  3451. wvWin98:
  3452. Result := LoadResString(@RsOSVersionWin98);
  3453. wvWin98SE:
  3454. Result := LoadResString(@RsOSVersionWin98SE);
  3455. wvWinME:
  3456. Result := LoadResString(@RsOSVersionWinME);
  3457. wvWinNT31, wvWinNT35, wvWinNT351:
  3458. Result := Format(LoadResString(@RsOSVersionWinNT3), [Win32MinorVersion]);
  3459. wvWinNT4:
  3460. Result := Format(LoadResString(@RsOSVersionWinNT4), [Win32MinorVersion]);
  3461. wvWin2000:
  3462. Result := LoadResString(@RsOSVersionWin2000);
  3463. wvWinXP:
  3464. Result := LoadResString(@RsOSVersionWinXP);
  3465. wvWin2003:
  3466. Result := LoadResString(@RsOSVersionWin2003);
  3467. wvWin2003R2:
  3468. Result := LoadResString(@RsOSVersionWin2003R2);
  3469. wvWinXP64:
  3470. Result := LoadResString(@RsOSVersionWinXP64);
  3471. wvWinVista:
  3472. Result := LoadResString(@RsOSVersionWinVista);
  3473. wvWinServer2008:
  3474. Result := LoadResString(@RsOSVersionWinServer2008);
  3475. wvWin7:
  3476. Result := LoadResString(@RsOSVersionWin7);
  3477. wvWinServer2008R2:
  3478. Result := LoadResString(@RsOSVersionWinServer2008R2);
  3479. wvWin8:
  3480. Result := LoadResString(@RsOSVersionWin8);
  3481. wvWin8RT:
  3482. Result := LoadResString(@RsOSVersionWin8RT);
  3483. wvWinServer2012:
  3484. Result := LoadResString(@RsOSVersionWinServer2012);
  3485. wvWin81:
  3486. Result := LoadResString(@RsOSVersionWin81);
  3487. wvWin81RT:
  3488. Result := LoadResString(@RsOSVersionWin81RT);
  3489. wvWinServer2012R2:
  3490. Result := LoadResString(@RsOSVersionWinServer2012R2);
  3491. wvWin10:
  3492. Result := LoadResString(@RsOSVersionWin10);
  3493. wvWinServer2016:
  3494. Result := LoadResString(@RsOSVersionWinServer2016);
  3495. else
  3496. Result := '';
  3497. end;
  3498. end;
  3499. function GetWindowsEditionString: string;
  3500. begin
  3501. case GetWindowsEdition of
  3502. weWinXPHome:
  3503. Result := LoadResString(@RsEditionWinXPHome);
  3504. weWinXPPro:
  3505. Result := LoadResString(@RsEditionWinXPPro);
  3506. weWinXPHomeN:
  3507. Result := LoadResString(@RsEditionWinXPHomeN);
  3508. weWinXPProN:
  3509. Result := LoadResString(@RsEditionWinXPProN);
  3510. weWinXPHomeK:
  3511. Result := LoadResString(@RsEditionWinXPHomeK);
  3512. weWinXPProK:
  3513. Result := LoadResString(@RsEditionWinXPProK);
  3514. weWinXPHomeKN:
  3515. Result := LoadResString(@RsEditionWinXPHomeKN);
  3516. weWinXPProKN:
  3517. Result := LoadResString(@RsEditionWinXPProKN);
  3518. weWinXPStarter:
  3519. Result := LoadResString(@RsEditionWinXPStarter);
  3520. weWinXPMediaCenter:
  3521. Result := LoadResString(@RsEditionWinXPMediaCenter);
  3522. weWinXPTablet:
  3523. Result := LoadResString(@RsEditionWinXPTablet);
  3524. weWinVistaStarter:
  3525. Result := LoadResString(@RsEditionWinVistaStarter);
  3526. weWinVistaHomeBasic:
  3527. Result := LoadResString(@RsEditionWinVistaHomeBasic);
  3528. weWinVistaHomeBasicN:
  3529. Result := LoadResString(@RsEditionWinVistaHomeBasicN);
  3530. weWinVistaHomePremium:
  3531. Result := LoadResString(@RsEditionWinVistaHomePremium);
  3532. weWinVistaBusiness:
  3533. Result := LoadResString(@RsEditionWinVistaBusiness);
  3534. weWinVistaBusinessN:
  3535. Result := LoadResString(@RsEditionWinVistaBusinessN);
  3536. weWinVistaEnterprise:
  3537. Result := LoadResString(@RsEditionWinVistaEnterprise);
  3538. weWinVistaUltimate:
  3539. Result := LoadResString(@RsEditionWinVistaUltimate);
  3540. weWin7Starter:
  3541. Result := LoadResString(@RsEditionWin7Starter);
  3542. weWin7HomeBasic:
  3543. Result := LoadResString(@RsEditionWin7HomeBasic);
  3544. weWin7HomePremium:
  3545. Result := LoadResString(@RsEditionWin7HomePremium);
  3546. weWin7Professional:
  3547. Result := LoadResString(@RsEditionWin7Professional);
  3548. weWin7Enterprise:
  3549. Result := LoadResString(@RsEditionWin7Enterprise);
  3550. weWin7Ultimate:
  3551. Result := LoadResString(@RsEditionWin7Ultimate);
  3552. weWin8Pro:
  3553. Result := LoadResString(@RsEditionWin8Pro);
  3554. weWin8Enterprise:
  3555. Result := LoadResString(@RsEditionWin8Enterprise);
  3556. weWin8RT:
  3557. Result := LoadResString(@RsEditionWin8RT);
  3558. weWin81Pro:
  3559. Result := LoadResString(@RsEditionWin81Pro);
  3560. weWin81Enterprise:
  3561. Result := LoadResString(@RsEditionWin81Enterprise);
  3562. weWin81RT:
  3563. Result := LoadResString(@RsEditionWin81RT);
  3564. weWin10Home:
  3565. Result := LoadResString(@RsEditionWin10Home);
  3566. weWin10Pro:
  3567. Result := LoadResString(@RsEditionWin10Pro);
  3568. weWin10Enterprise:
  3569. Result := LoadResString(@RsEditionWin10Enterprise);
  3570. weWin10Education:
  3571. Result := LoadResString(@RsEditionWin10Education);
  3572. else
  3573. Result := '';
  3574. end;
  3575. end;
  3576. function GetWindowsProductString: string;
  3577. begin
  3578. Result := GetWindowsVersionString;
  3579. if GetWindowsEditionString <> '' then
  3580. Result := Result + ' ' + GetWindowsEditionString;
  3581. end;
  3582. function NtProductTypeString: string;
  3583. begin
  3584. case NtProductType of
  3585. ptWorkStation:
  3586. Result := LoadResString(@RsProductTypeWorkStation);
  3587. ptServer:
  3588. Result := LoadResString(@RsProductTypeServer);
  3589. ptAdvancedServer:
  3590. Result := LoadResString(@RsProductTypeAdvancedServer);
  3591. ptPersonal:
  3592. Result := LoadResString(@RsProductTypePersonal);
  3593. ptProfessional:
  3594. Result := LoadResString(@RsProductTypeProfessional);
  3595. ptDatacenterServer:
  3596. Result := LoadResString(@RsProductTypeDatacenterServer);
  3597. ptEnterprise:
  3598. Result := LoadResString(@RsProductTypeEnterprise);
  3599. ptWebEdition:
  3600. Result := LoadResString(@RsProductTypeWebEdition);
  3601. else
  3602. Result := '';
  3603. end;
  3604. end;
  3605. function GetWindowsBuildNumber: Integer;
  3606. begin
  3607. // Starting with Windows 8.1, the GetVersion(Ex) API is deprecated and will detect the
  3608. // application as Windows 8 (kernel version 6.2) until an application manifest is included
  3609. // See https://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
  3610. if (Win32MajorVersion = 6) and (Win32MinorVersion = 2) then
  3611. Result := strToInt(RegReadStringDef(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentBuildNumber', intToStr(Win32BuildNumber)))
  3612. else
  3613. Result := Win32BuildNumber;
  3614. end;
  3615. function GetWindowsMajorVersionNumber: Integer;
  3616. begin
  3617. // Starting with Windows 8.1, the GetVersion(Ex) API is deprecated and will detect the
  3618. // application as Windows 8 (kernel version 6.2) until an application manifest is included
  3619. // See https://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
  3620. if (Win32MajorVersion = 6) and (Win32MinorVersion = 2) then
  3621. begin
  3622. // CurrentMajorVersionNumber present in registry starting with Windows 10
  3623. // If CurrentMajorVersionNumber not present in registry then use CurrentVersion
  3624. Result := RegReadIntegerDef(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentMajorVersionNumber', -1);
  3625. if Result = -1 then
  3626. Result := strToInt(StrBefore('.', RegReadStringDef(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentVersion', intToStr(Win32MajorVersion) + '.' + intToStr(Win32MinorVersion))));
  3627. end
  3628. else
  3629. Result := Win32MajorVersion;
  3630. end;
  3631. function GetWindowsMinorVersionNumber: Integer;
  3632. begin
  3633. // Starting with Windows 8.1, the GetVersion(Ex) API is deprecated and will detect the
  3634. // application as Windows 8 (kernel version 6.2) until an application manifest is included
  3635. // See https://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
  3636. if (Win32MajorVersion = 6) and (Win32MinorVersion = 2) then
  3637. begin
  3638. // CurrentMinorVersionNumber present in registry starting with Windows 10
  3639. // If CurrentMinorVersionNumber not present then use CurrentVersion
  3640. Result := RegReadIntegerDef(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentMinorVersionNumber', -1);
  3641. if Result = -1 then
  3642. Result := strToInt(StrAfter('.', RegReadStringDef(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentVersion', intToStr(Win32MajorVersion) + '.' + intToStr(Win32MinorVersion))));
  3643. end
  3644. else
  3645. Result := Win32MajorVersion;
  3646. end;
  3647. function GetWindowsVersionNumber: string;
  3648. begin
  3649. // Returns version number as MajorVersionNumber.MinorVersionNumber (string type)
  3650. Result := intToStr(GetWindowsMajorVersionNumber) + '.' + intToStr(GetWindowsMinorVersionNumber);
  3651. end;
  3652. function GetWindowsServicePackVersion: Integer;
  3653. const
  3654. RegWindowsControl = 'SYSTEM\CurrentControlSet\Control\Windows';
  3655. var
  3656. SP: Integer;
  3657. VersionInfo: TOSVersionInfoEx;
  3658. begin
  3659. Result := 0;
  3660. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion >= 5) then
  3661. begin
  3662. ResetMemory(VersionInfo, SizeOf(VersionInfo));
  3663. VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
  3664. if GetVersionEx(VersionInfo) then
  3665. Result := VersionInfo.wServicePackMajor;
  3666. end
  3667. else
  3668. begin
  3669. SP := RegReadIntegerDef(HKEY_LOCAL_MACHINE, RegWindowsControl, 'CSDVersion', 0);
  3670. Result := StrToInt(IntToHex(SP, 4)) div 100;
  3671. end;
  3672. end;
  3673. function GetWindowsServicePackVersionString: string;
  3674. var
  3675. SP: Integer;
  3676. begin
  3677. SP := GetWindowsServicePackVersion;
  3678. if SP > 0 then
  3679. Result := Format(LoadResString(@RsSPInfo), [SP])
  3680. else
  3681. Result := '';
  3682. end;
  3683. // Imports copied from OpenGL unit. Direct using of OpenGL unit might cause unexpected problems due
  3684. // setting 8087CW in the intialization section
  3685. {
  3686. function glGetString(name: Cardinal): PChar; stdcall; external opengl32;
  3687. function glGetError: Cardinal; stdcall; external opengl32;
  3688. function gluErrorString(errCode: Cardinal): PChar; stdcall; external 'glu32.dll';
  3689. }
  3690. type
  3691. TglGetStringFunc = function(name: Cardinal): PAnsiChar; stdcall;
  3692. TglGetErrorFunc = function: Cardinal; stdcall;
  3693. TgluErrorStringFunc = function(errCode: Cardinal): PAnsiChar; stdcall;
  3694. TwglCreateContextFunc = function(DC: HDC): HGLRC; stdcall;
  3695. TwglDeleteContextFunc = function(p1: HGLRC): BOOL; stdcall;
  3696. TwglMakeCurrentFunc = function(DC: HDC; p2: HGLRC): BOOL; stdcall;
  3697. const
  3698. glu32 = 'glu32.dll'; // do not localize
  3699. glGetStringName = 'glGetString'; // do not localize
  3700. glGetErrorName = 'glGetError'; // do not localize
  3701. gluErrorStringName = 'gluErrorString'; // do not localize
  3702. wglCreateContextName = 'wglCreateContext'; // do not localize
  3703. wglDeleteContextName = 'wglDeleteContext'; // do not localize
  3704. wglMakeCurrentName = 'wglMakeCurrent'; // do not localize
  3705. ChoosePixelFormatName = 'ChoosePixelFormat'; // do not localize
  3706. SetPixelFormatName = 'SetPixelFormat'; // do not localize
  3707. function GetOpenGLVersion(const Win: THandle; out Version, Vendor: AnsiString): Boolean;
  3708. const
  3709. GL_NO_ERROR = 0;
  3710. GL_VENDOR = $1F00;
  3711. GL_VERSION = $1F02;
  3712. var
  3713. OpenGlLib, Glu32Lib: HModule;
  3714. glGetStringFunc: TglGetStringFunc;
  3715. glGetErrorFunc: TglGetErrorFunc;
  3716. gluErrorStringFunc: TgluErrorStringFunc;
  3717. wglCreateContextFunc: TwglCreateContextFunc;
  3718. wglDeleteContextFunc: TwglDeleteContextFunc;
  3719. wglMakeCurrentFunc: TwglMakeCurrentFunc;
  3720. pfd: TPixelFormatDescriptor;
  3721. iFormatIndex: Integer;
  3722. hGLContext: HGLRC;
  3723. hGLDC: HDC;
  3724. pcTemp: PAnsiChar;
  3725. glErr: Cardinal;
  3726. bError: Boolean;
  3727. sOpenGLVersion, sOpenGLVendor: AnsiString;
  3728. Save8087CW: Word;
  3729. procedure FunctionFailedError(Name: string);
  3730. begin
  3731. raise EJclError.CreateResFmt(@RsEOpenGLInfo, [Name]);
  3732. end;
  3733. begin
  3734. @glGetStringFunc := nil;
  3735. @glGetErrorFunc := nil;
  3736. @gluErrorStringFunc := nil;
  3737. @wglCreateContextFunc := nil;
  3738. @wglDeleteContextFunc := nil;
  3739. @wglMakeCurrentFunc := nil;
  3740. Glu32Lib := 0;
  3741. OpenGlLib := SafeLoadLibrary(opengl32);
  3742. try
  3743. if OpenGlLib <> 0 then
  3744. begin
  3745. Glu32Lib := SafeLoadLibrary(glu32); // do not localize
  3746. if (OpenGlLib <> 0) and (Glu32Lib <> 0) then
  3747. begin
  3748. glGetStringFunc := GetProcAddress(OpenGlLib, glGetStringName);
  3749. glGetErrorFunc := GetProcAddress(OpenGlLib, glGetErrorName);
  3750. gluErrorStringFunc := GetProcAddress(Glu32Lib, gluErrorStringName);
  3751. wglCreateContextFunc := GetProcAddress(OpenGlLib, wglCreateContextName);
  3752. wglDeleteContextFunc := GetProcAddress(OpenGlLib, wglDeleteContextName);
  3753. wglMakeCurrentFunc := GetProcAddress(OpenGlLib, wglMakeCurrentName);
  3754. end;
  3755. end;
  3756. if not (Assigned(glGetStringFunc) and Assigned(glGetErrorFunc) and Assigned(gluErrorStringFunc) and
  3757. Assigned(wglCreateContextFunc) and Assigned(wglDeleteContextFunc) and Assigned(wglMakeCurrentFunc)) then
  3758. begin
  3759. @glGetStringFunc := nil;
  3760. Result := False;
  3761. Vendor := AnsiString(LoadResString(@RsOpenGLInfoError));
  3762. Version := AnsiString(LoadResString(@RsOpenGLInfoError));
  3763. Exit;
  3764. end;
  3765. { To call for the version information string we must first have an active
  3766. context established for use. We can, of course, close this after use }
  3767. Save8087CW := Get8087ControlWord;
  3768. try
  3769. Set8087CW($133F);
  3770. hGLContext := 0;
  3771. Result := False;
  3772. bError := False;
  3773. if Win = 0 then
  3774. begin
  3775. Result := False;
  3776. Vendor := AnsiString(LoadResString(@RsOpenGLInfoError));
  3777. Version := AnsiString(LoadResString(@RsOpenGLInfoError));
  3778. Exit;
  3779. end;
  3780. ResetMemory(pfd, SizeOf(pfd));
  3781. with pfd do
  3782. begin
  3783. nSize := SizeOf(pfd);
  3784. nVersion := 1; { The Current Version of the descriptor is 1 }
  3785. dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
  3786. iPixelType := PFD_TYPE_RGBA;
  3787. cColorBits := 24; { support 24-bit colour }
  3788. cDepthBits := 32; { Depth of the z-buffer }
  3789. iLayerType := PFD_MAIN_PLANE;
  3790. end;
  3791. hGLDC := GetDC(Win);
  3792. try
  3793. iFormatIndex := ChoosePixelFormat(hGLDC, @pfd);
  3794. if iFormatIndex = 0 then
  3795. FunctionFailedError(ChoosePixelFormatName);
  3796. if not SetPixelFormat(hGLDC, iFormatIndex, @pfd) then
  3797. FunctionFailedError(SetPixelFormatName);
  3798. hGLContext := wglCreateContextFunc(hGLDC);
  3799. if hGLContext = 0 then
  3800. FunctionFailedError(wglCreateContextName);
  3801. if not wglMakeCurrentFunc(hGLDC, hGLContext) then
  3802. FunctionFailedError(wglMakeCurrentName);
  3803. { TODO : Review the following. Not sure I am 100% happy with this code
  3804. in its current structure. }
  3805. pcTemp := glGetStringFunc(GL_VERSION);
  3806. if pcTemp <> nil then
  3807. begin
  3808. { TODO : Store this information in a Global Variable, and return that??
  3809. This would save this work being performed again with later calls }
  3810. sOpenGLVersion := StrPasA(pcTemp);
  3811. end
  3812. else
  3813. begin
  3814. bError := True;
  3815. glErr := glGetErrorFunc;
  3816. if glErr <> GL_NO_ERROR then
  3817. begin
  3818. sOpenGLVersion := gluErrorStringFunc(glErr);
  3819. sOpenGLVendor := '';
  3820. end;
  3821. end;
  3822. pcTemp := glGetStringFunc(GL_VENDOR);
  3823. if pcTemp <> nil then
  3824. begin
  3825. { TODO : Store this information in a Global Variable, and return that??
  3826. This would save this work being performed again with later calls }
  3827. sOpenGLVendor := StrPasA(pcTemp);
  3828. end
  3829. else
  3830. begin
  3831. bError := True;
  3832. glErr := glGetErrorFunc;
  3833. if glErr <> GL_NO_ERROR then
  3834. begin
  3835. sOpenGLVendor := gluErrorStringFunc(glErr);
  3836. Exit;
  3837. end;
  3838. end;
  3839. Result := (not bError);
  3840. Version := sOpenGLVersion;
  3841. Vendor := sOpenGLVendor;
  3842. finally
  3843. { Close all resources }
  3844. wglMakeCurrentFunc(hGLDC, 0);
  3845. if hGLContext <> 0 then
  3846. wglDeleteContextFunc(hGLContext);
  3847. end;
  3848. finally
  3849. Set8087CW(Save8087CW);
  3850. end;
  3851. finally
  3852. if (OpenGlLib <> 0) then
  3853. FreeLibrary(OpenGlLib);
  3854. if (Glu32Lib <> 0) then
  3855. FreeLibrary(Glu32Lib);
  3856. end;
  3857. end;
  3858. function GetNativeSystemInfo(var SystemInfo: TSystemInfo): Boolean;
  3859. type
  3860. TGetNativeSystemInfo = procedure (var SystemInfo: TSystemInfo); stdcall;
  3861. var
  3862. LibraryHandle: HMODULE;
  3863. _GetNativeSystemInfo: TGetNativeSystemInfo;
  3864. begin
  3865. Result := False;
  3866. LibraryHandle := GetModuleHandle(kernel32);
  3867. if LibraryHandle <> 0 then
  3868. begin
  3869. _GetNativeSystemInfo := GetProcAddress(LibraryHandle, PAnsiChar('GetNativeSystemInfo'));
  3870. if Assigned(_GetNativeSystemInfo) then
  3871. begin
  3872. _GetNativeSystemInfo(SystemInfo);
  3873. Result := True;
  3874. end
  3875. else
  3876. GetSystemInfo(SystemInfo);
  3877. end
  3878. else
  3879. GetSystemInfo(SystemInfo);
  3880. end;
  3881. function GetProcessorArchitecture: TProcessorArchitecture;
  3882. var
  3883. ASystemInfo: TSystemInfo;
  3884. begin
  3885. ASystemInfo.dwOemId := 0;
  3886. GetNativeSystemInfo(ASystemInfo);
  3887. case ASystemInfo.wProcessorArchitecture of
  3888. PROCESSOR_ARCHITECTURE_INTEL:
  3889. Result := pax8632;
  3890. PROCESSOR_ARCHITECTURE_IA64:
  3891. Result := paIA64;
  3892. PROCESSOR_ARCHITECTURE_AMD64:
  3893. Result := pax8664;
  3894. else
  3895. Result := paUnknown;
  3896. end;
  3897. end;
  3898. function IsWindows64: Boolean;
  3899. var
  3900. ASystemInfo: TSystemInfo;
  3901. begin
  3902. ASystemInfo.dwOemId := 0;
  3903. GetNativeSystemInfo(ASystemInfo);
  3904. Result := ASystemInfo.wProcessorArchitecture in [PROCESSOR_ARCHITECTURE_IA64,PROCESSOR_ARCHITECTURE_AMD64];
  3905. end;
  3906. function JclCheckWinVersion(Major, Minor: Integer): Boolean;
  3907. begin
  3908. {$IFDEF RTL150_UP}
  3909. Result := CheckWin32Version(Major, Minor);
  3910. {$ELSE}
  3911. // Delphi 6 and older have a wrong implementation
  3912. Result := (Win32MajorVersion > Major) or
  3913. ((Win32MajorVersion = Major) and (Win32MinorVersion >= Minor));
  3914. {$ENDIF RTL150_UP}
  3915. end;
  3916. {$ENDIF MSWINDOWS}
  3917. function GetOSVersionString: string;
  3918. {$IFDEF UNIX}
  3919. var
  3920. MachineInfo: utsname;
  3921. begin
  3922. uname(MachineInfo);
  3923. Result := Format('%s %s', [MachineInfo.sysname, MachineInfo.release]);
  3924. end;
  3925. {$ENDIF UNIX}
  3926. {$IFDEF MSWINDOWS}
  3927. begin
  3928. Result := Format('%s %s', [GetWindowsVersionString, GetWindowsServicePackVersionString]);
  3929. end;
  3930. {$ENDIF MSWINDOWS}
  3931. //=== Hardware ===============================================================
  3932. // Helper function for GetMacAddress()
  3933. // Converts the adapter_address array to a string
  3934. function AdapterToString(Adapter: PJclByteArray): string;
  3935. begin
  3936. Result := Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',
  3937. [Integer(Adapter[0]), Integer(Adapter[1]),
  3938. Integer(Adapter[2]), Integer(Adapter[3]),
  3939. Integer(Adapter[4]), Integer(Adapter[5])]);
  3940. end;
  3941. { TODO: RTLD version of NetBios }
  3942. {$IFDEF MSWINDOWS}
  3943. type
  3944. TNetBios = function(P: PNCB): Byte; stdcall;
  3945. var
  3946. NetBiosLib: HINST = 0;
  3947. _NetBios: TNetBios;
  3948. {$IFDEF FPC}
  3949. NullAdapterAddress: array [0..5] of Byte = ($00, $00, $00, $00, $00, $00);
  3950. OID_ipMACEntAddr: array [0..9] of UINT = (1, 3, 6, 1, 2, 1, 2, 2, 1, 6);
  3951. OID_ifEntryType: array [0..9] of UINT = (1, 3, 6, 1, 2, 1, 2, 2, 1, 3);
  3952. OID_ifEntryNum: array [0..7] of UINT = (1, 3, 6, 1, 2, 1, 2, 1);
  3953. {$ENDIF FPC}
  3954. function GetMacAddresses(const Machine: string; const Addresses: TStrings): Integer;
  3955. procedure ExitNetbios;
  3956. begin
  3957. if NetBiosLib <> 0 then
  3958. begin
  3959. FreeLibrary(NetBiosLib);
  3960. NetBiosLib := 0;
  3961. end;
  3962. end;
  3963. function InitNetbios: Boolean;
  3964. begin
  3965. Result := True;
  3966. if NetBiosLib = 0 then
  3967. begin
  3968. NetBiosLib := SafeLoadLibrary('netapi32.dll');
  3969. Result := NetBiosLib <> 0;
  3970. if Result then
  3971. begin
  3972. @_NetBios := GetProcAddress(NetBiosLib, PAnsiChar('Netbios'));
  3973. Result := @_NetBios <> nil;
  3974. if not Result then
  3975. ExitNetbios;
  3976. end;
  3977. end;
  3978. end;
  3979. function NetBios(P: PNCB): Byte;
  3980. begin
  3981. if InitNetbios then
  3982. Result := _NetBios(P)
  3983. else
  3984. Result := 1; // anything other than NRC_GOODRET will do
  3985. end;
  3986. procedure GetMacAddressesNetBios;
  3987. // Platform SDK
  3988. // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netbios/netbios_1l82.asp
  3989. // Microsoft Knowledge Base Article - 118623
  3990. // HOWTO: Get the MAC Address for an Ethernet Adapter
  3991. // http://support.microsoft.com/default.aspx?scid=kb;en-us;118623
  3992. type
  3993. AStat = packed record
  3994. adapt: TAdapterStatus;
  3995. NameBuff: array [0..29] of TNameBuffer;
  3996. end;
  3997. var
  3998. NCB: TNCB;
  3999. Enum: TLanaEnum;
  4000. I, L, NameLen: Integer;
  4001. Adapter: AStat;
  4002. MachineName: AnsiString;
  4003. begin
  4004. MachineName := AnsiString(UpperCase(Machine));
  4005. if MachineName = '' then
  4006. MachineName := '*';
  4007. NameLen := Length(MachineName);
  4008. L := NCBNAMSZ - NameLen;
  4009. if L > 0 then
  4010. begin
  4011. SetLength(MachineName, NCBNAMSZ);
  4012. FillChar(MachineName[NameLen + 1], L, ' ');
  4013. end;
  4014. // From Junior/RO in NG: Microsoft's implementation limits NETBIOS names to 15 characters
  4015. MachineName[NCBNAMSZ] := #0;
  4016. ResetMemory(NCB, SizeOf(NCB));
  4017. NCB.ncb_command := NCBENUM;
  4018. NCB.ncb_buffer := Pointer(@Enum);
  4019. NCB.ncb_length := SizeOf(Enum);
  4020. if NetBios(@NCB) = NRC_GOODRET then
  4021. begin
  4022. Result := Enum.Length;
  4023. for I := 0 to Ord(Enum.Length) - 1 do
  4024. begin
  4025. ResetMemory(NCB, SizeOf(NCB));
  4026. NCB.ncb_command := NCBRESET;
  4027. NCB.ncb_lana_num := Enum.lana[I];
  4028. if NetBios(@NCB) = NRC_GOODRET then
  4029. begin
  4030. ResetMemory(NCB, SizeOf(NCB));
  4031. NCB.ncb_command := NCBASTAT;
  4032. NCB.ncb_lana_num := Enum.lana[I];
  4033. Move(MachineName[1], NCB.ncb_callname, SizeOf(NCB.ncb_callname));
  4034. NCB.ncb_buffer := PUCHAR(@Adapter);
  4035. NCB.ncb_length := SizeOf(Adapter);
  4036. if NetBios(@NCB) = NRC_GOODRET then
  4037. Addresses.Add(AdapterToString(@Adapter.adapt));
  4038. end;
  4039. end;
  4040. end;
  4041. end;
  4042. procedure GetMacAddressesSnmp;
  4043. const
  4044. InetMib1 = 'inetmib1.dll';
  4045. {$IFNDEF FPC // can't resolve address of const }
  4046. NullAdapterAddress: array [0..5] of Byte = ($00, $00, $00, $00, $00, $00);
  4047. OID_ipMACEntAddr: array [0..9] of UINT = (1, 3, 6, 1, 2, 1, 2, 2, 1, 6);
  4048. OID_ifEntryType: array [0..9] of UINT = (1, 3, 6, 1, 2, 1, 2, 2, 1, 3);
  4049. OID_ifEntryNum: array [0..7] of UINT = (1, 3, 6, 1, 2, 1, 2, 1);
  4050. {$ENDIF ~FPC}
  4051. var
  4052. PollForTrapEvent: THandle;
  4053. SupportedView: PAsnObjectIdentifier;
  4054. MIB_ifMACEntAddr: TAsnObjectIdentifier;
  4055. MIB_ifEntryType: TAsnObjectIdentifier;
  4056. MIB_ifEntryNum: TAsnObjectIdentifier;
  4057. VarBindList: TSnmpVarBindList;
  4058. VarBind: array [0..1] of TSnmpVarBind;
  4059. ErrorStatus, ErrorIndex: TAsnInteger32;
  4060. DTmp: Integer;
  4061. Ret: Boolean;
  4062. MAC: PJclByteArray;
  4063. begin
  4064. if LoadSnmp then
  4065. try
  4066. if LoadSnmpExtension(InetMib1) then
  4067. try
  4068. MIB_ifMACEntAddr.idLength := Length(OID_ipMACEntAddr);
  4069. MIB_ifMACEntAddr.ids := @OID_ipMACEntAddr;
  4070. MIB_ifEntryType.idLength := Length(OID_ifEntryType);
  4071. MIB_ifEntryType.ids := @OID_ifEntryType;
  4072. MIB_ifEntryNum.idLength := Length(OID_ifEntryNum);
  4073. MIB_ifEntryNum.ids := @OID_ifEntryNum;
  4074. PollForTrapEvent := 0;
  4075. SupportedView := nil;
  4076. if SnmpExtensionInit(GetTickCount, PollForTrapEvent, SupportedView) then
  4077. begin
  4078. VarBindList.list := @VarBind[0];
  4079. VarBind[0].name := DEFINE_NULLOID;
  4080. VarBind[1].name := DEFINE_NULLOID;
  4081. VarBindList.len := 1;
  4082. SnmpUtilOidCpy(@VarBind[0].name, @MIB_ifEntryNum);
  4083. ErrorIndex := 0;
  4084. ErrorStatus := 0;
  4085. Ret := SnmpExtensionQuery(SNMP_PDU_GETNEXT, VarBindList, ErrorStatus, ErrorIndex);
  4086. if Ret then
  4087. begin
  4088. Result := VarBind[0].value.number;
  4089. VarBindList.len := 2;
  4090. SnmpUtilOidCpy(@VarBind[0].name, @MIB_ifEntryType);
  4091. SnmpUtilOidCpy(@VarBind[1].name, @MIB_ifMACEntAddr);
  4092. while Ret do
  4093. begin
  4094. Ret := SnmpExtensionQuery(SNMP_PDU_GETNEXT, VarBindList, ErrorStatus, ErrorIndex);
  4095. if Ret then
  4096. begin
  4097. Ret := SnmpUtilOidNCmp(@VarBind[0].name, @MIB_ifEntryType, MIB_ifEntryType.idLength) = SNMP_ERRORSTATUS_NOERROR;
  4098. if Ret then
  4099. begin
  4100. DTmp := VarBind[0].value.number;
  4101. if DTmp = 6 then
  4102. begin
  4103. Ret := SnmpUtilOidNCmp(@VarBind[1].name, @MIB_ifMACEntAddr, MIB_ifMACEntAddr.idLength) = SNMP_ERRORSTATUS_NOERROR;
  4104. if Ret and (VarBind[1].value.address.stream <> nil) then
  4105. begin
  4106. MAC := PJclByteArray(VarBind[1].value.address.stream);
  4107. if not CompareMem(MAC, @NullAdapterAddress, SizeOf(NullAdapterAddress)) then
  4108. Addresses.Add(AdapterToString(MAC));
  4109. end;
  4110. end;
  4111. end;
  4112. end;
  4113. end;
  4114. end;
  4115. SnmpUtilVarBindFree(@VarBind[0]);
  4116. SnmpUtilVarBindFree(@VarBind[1]);
  4117. end;
  4118. finally
  4119. UnloadSnmpExtension;
  4120. end;
  4121. finally
  4122. UnloadSnmp;
  4123. end;
  4124. end;
  4125. begin
  4126. Result := -1;
  4127. Addresses.BeginUpdate;
  4128. try
  4129. Addresses.Clear;
  4130. GetMacAddressesNetBios;
  4131. if (Result <= 0) and (Machine = '') then
  4132. GetMacAddressesSnmp;
  4133. finally
  4134. Addresses.EndUpdate;
  4135. end;
  4136. end;
  4137. {$ENDIF MSWINDOWS}
  4138. function ReadTimeStampCounter: Int64; assembler;
  4139. asm
  4140. DW $310F
  4141. // TSC in EDX:EAX
  4142. {$IFDEF CPU64}
  4143. SHL RDX, 32
  4144. OR RAX, RDX
  4145. // Result in RAX
  4146. {$ENDIF CPU64}
  4147. end;
  4148. function GetIntelCacheDescription(const D: Byte): string;
  4149. var
  4150. I: Integer;
  4151. begin
  4152. Result := '';
  4153. if D <> 0 then
  4154. for I := Low(IntelCacheDescription) to High(IntelCacheDescription) do
  4155. if IntelCacheDescription[I].D = D then
  4156. begin
  4157. Result := LoadResString(IntelCacheDescription[I].I);
  4158. Break;
  4159. end;
  4160. // (outchy) added a return value for unknow D value
  4161. if Result = '' then
  4162. Result := Format(LoadResString(@RsIntelUnknownCache),[D]);
  4163. end;
  4164. procedure GetCpuInfo(var CpuInfo: TCpuInfo);
  4165. begin
  4166. CpuInfo := CPUID;
  4167. CpuInfo.IsFDIVOK := TestFDIVInstruction;
  4168. if CpuInfo.HasInstruction then
  4169. begin
  4170. {$IFDEF MSWINDOWS}
  4171. if (CpuInfo.Features and TSC_FLAG) = TSC_FLAG then
  4172. GetCpuSpeed(CpuInfo.FrequencyInfo);
  4173. {$ENDIF MSWINDOWS}
  4174. end;
  4175. end;
  4176. function RoundFrequency(const Frequency: Integer): Integer;
  4177. const
  4178. NF: array [0..8] of Integer = (0, 20, 33, 50, 60, 66, 80, 90, 100);
  4179. var
  4180. Freq, RF: Integer;
  4181. I: Byte;
  4182. Hi, Lo: Byte;
  4183. begin
  4184. RF := 0;
  4185. Freq := Frequency mod 100;
  4186. for I := 0 to 8 do
  4187. begin
  4188. if Freq < NF[I] then
  4189. begin
  4190. Hi := I;
  4191. Lo := I - 1;
  4192. if (NF[Hi] - Freq) > (Freq - NF[Lo]) then
  4193. RF := NF[Lo] - Freq
  4194. else
  4195. RF := NF[Hi] - Freq;
  4196. Break;
  4197. end;
  4198. end;
  4199. Result := Frequency + RF;
  4200. end;
  4201. function GetCPUSpeed(var CpuSpeed: TFreqInfo): Boolean;
  4202. {$IFDEF UNIX}
  4203. begin
  4204. { TODO : GetCPUSpeed: Solution for Linux }
  4205. Result := False;
  4206. end;
  4207. {$ENDIF UNIX}
  4208. {$IFDEF MSWINDOWS}
  4209. var
  4210. T0, T1: Int64;
  4211. CountFreq: Int64;
  4212. Freq, Freq2, Freq3, Total: Int64;
  4213. TotalCycles, Cycles: Int64;
  4214. Stamp0, Stamp1: Int64;
  4215. TotalTicks, Ticks: Double;
  4216. Tries, Priority: Integer;
  4217. Thread: THandle;
  4218. begin
  4219. Stamp0 := 0;
  4220. Stamp1 := 0;
  4221. Freq := 0;
  4222. Freq2 := 0;
  4223. Freq3 := 0;
  4224. Tries := 0;
  4225. TotalCycles := 0;
  4226. TotalTicks := 0;
  4227. Total := 0;
  4228. Thread := GetCurrentThread();
  4229. CountFreq := 0;
  4230. Result := QueryPerformanceFrequency(CountFreq);
  4231. if Result then
  4232. begin
  4233. while ((Tries < 3) or ((Tries < 20) and ((Abs(3 * Freq - Total) > 3) or
  4234. (Abs(3 * Freq2 - Total) > 3) or (Abs(3 * Freq3 - Total) > 3)))) do
  4235. begin
  4236. Inc(Tries);
  4237. Freq3 := Freq2;
  4238. Freq2 := Freq;
  4239. T0 := 0;
  4240. QueryPerformanceCounter(T0);
  4241. T1 := T0;
  4242. Priority := GetThreadPriority(Thread);
  4243. if Priority <> THREAD_PRIORITY_ERROR_RETURN then
  4244. SetThreadPriority(Thread, THREAD_PRIORITY_TIME_CRITICAL);
  4245. try
  4246. while T1 - T0 < 50 do
  4247. begin
  4248. QueryPerformanceCounter(T1);
  4249. Stamp0 := ReadTimeStampCounter;
  4250. end;
  4251. T0 := T1;
  4252. while T1 - T0 < 1000 do
  4253. begin
  4254. QueryPerformanceCounter(T1);
  4255. Stamp1 := ReadTimeStampCounter;
  4256. end;
  4257. finally
  4258. if Priority <> THREAD_PRIORITY_ERROR_RETURN then
  4259. SetThreadPriority(Thread, Priority);
  4260. end;
  4261. Cycles := Stamp1 - Stamp0;
  4262. Ticks := T1 - T0;
  4263. Ticks := Ticks * 100000;
  4264. // avoid division by zero
  4265. if CountFreq = 0 then
  4266. Ticks := High(Int64)
  4267. else
  4268. Ticks := Ticks / (CountFreq / 10);
  4269. TotalTicks := TotalTicks + Ticks;
  4270. TotalCycles := TotalCycles + Cycles;
  4271. // avoid division by zero
  4272. if IsZero(Ticks) then
  4273. Freq := High(Freq)
  4274. else
  4275. Freq := Round(Cycles / Ticks);
  4276. Total := Freq + Freq2 + Freq3;
  4277. end;
  4278. // avoid division by zero
  4279. if IsZero(TotalTicks) then
  4280. begin
  4281. Freq3 := High(Freq3);
  4282. Freq2 := High(Freq2);
  4283. CpuSpeed.RawFreq := High(CpuSpeed.RawFreq);
  4284. end
  4285. else
  4286. begin
  4287. Freq3 := Round((TotalCycles * 10) / TotalTicks); // freq. in multiples of 10^5 Hz
  4288. Freq2 := Round((TotalCycles * 100) / TotalTicks); // freq. in multiples of 10^4 Hz
  4289. CpuSpeed.RawFreq := Round(TotalCycles / TotalTicks);
  4290. end;
  4291. CpuSpeed.NormFreq := CpuSpeed.RawFreq;
  4292. if Freq2 - (Freq3 * 10) >= 6 then
  4293. Inc(Freq3);
  4294. Freq := CpuSpeed.RawFreq * 10;
  4295. if (Freq3 - Freq) >= 6 then
  4296. Inc(CpuSpeed.NormFreq);
  4297. CpuSpeed.ExTicks := Round(TotalTicks);
  4298. CpuSpeed.InCycles := TotalCycles;
  4299. CpuSpeed.NormFreq := RoundFrequency(CpuSpeed.NormFreq);
  4300. Result := True;
  4301. end;
  4302. end;
  4303. function GetOSEnabledFeatures: TOSEnabledFeatures;
  4304. var
  4305. EnabledFeatures: Int64;
  4306. begin
  4307. // Windows 7 or newer
  4308. if JclCheckWinVersion(6, 1) then
  4309. begin
  4310. EnabledFeatures := $FFFFFFFF;
  4311. EnabledFeatures := EnabledFeatures shl 32;
  4312. EnabledFeatures := EnabledFeatures or $FFFFFFFF;
  4313. EnabledFeatures := GetEnabledExtendedFeatures(EnabledFeatures);
  4314. Result := [];
  4315. if (EnabledFeatures and XSTATE_MASK_LEGACY_FLOATING_POINT) <> 0 then
  4316. Include(Result, oefFPU);
  4317. if (EnabledFeatures and XSTATE_MASK_LEGACY_SSE) <> 0 then
  4318. Include(Result, oefSSE);
  4319. if (EnabledFeatures and XSTATE_MASK_GSSE) <> 0 then
  4320. Include(Result, oefAVX);
  4321. end
  4322. else
  4323. Result := [];
  4324. end;
  4325. {$ENDIF MSWINDOWS}
  4326. function CPUID: TCpuInfo;
  4327. function HasCPUIDInstruction: Boolean;
  4328. const
  4329. ID_FLAG = $200000;
  4330. {$IFNDEF DELPHI64_TEMPORARY}
  4331. begin
  4332. {$ENDIF ~DELPHI64_TEMPORARY}
  4333. asm
  4334. {$IFDEF CPU32}
  4335. PUSHFD
  4336. POP EAX
  4337. MOV ECX, EAX
  4338. XOR EAX, ID_FLAG
  4339. AND ECX, ID_FLAG
  4340. PUSH EAX
  4341. POPFD
  4342. PUSHFD
  4343. POP EAX
  4344. AND EAX, ID_FLAG
  4345. XOR EAX, ECX
  4346. SETNZ Result
  4347. {$ENDIF CPU32}
  4348. {$IFDEF CPU64}
  4349. {$IFDEF FPC}
  4350. {$DEFINE DELPHI64_TEMPORARY}
  4351. {$ENDIF FPC}
  4352. {$IFDEF DELPHI64_TEMPORARY}
  4353. PUSHFQ
  4354. {$ELSE ~DELPHI64_TEMPORARY}
  4355. PUSHFD
  4356. {$ENDIF ~DELPHI64_TEMPORARY}
  4357. POP RAX
  4358. MOV RCX, RAX
  4359. XOR RAX, ID_FLAG
  4360. AND RCX, ID_FLAG
  4361. PUSH RAX
  4362. {$IFDEF DELPHI64_TEMPORARY}
  4363. POPFQ
  4364. {$ELSE ~DELPHI64_TEMPORARY}
  4365. POPFD
  4366. {$ENDIF ~DELPHI64_TEMPORARY}
  4367. {$IFDEF DELPHI64_TEMPORARY}
  4368. PUSHFQ
  4369. {$ELSE ~DELPHI64_TEMPORARY}
  4370. PUSHFD
  4371. {$ENDIF ~DELPHI64_TEMPORARY}
  4372. POP RAX
  4373. AND RAX, ID_FLAG
  4374. XOR RAX, RCX
  4375. SETNZ Result
  4376. {$IFDEF FPC}
  4377. {$UNDEF DELPHI64_TEMPORARY}
  4378. {$ENDIF FPC}
  4379. {$ENDIF CPU64}
  4380. end;
  4381. {$IFNDEF DELPHI64_TEMPORARY}
  4382. end;
  4383. {$ENDIF ~DELPHI64_TEMPORARY}
  4384. procedure CallCPUID(ValueEAX, ValueECX: Cardinal; out ReturnedEAX, ReturnedEBX, ReturnedECX, ReturnedEDX);
  4385. {$IFNDEF DELPHI64_TEMPORARY}
  4386. begin
  4387. {$ENDIF ~DELPHI64_TEMPORARY}
  4388. asm
  4389. {$IFDEF CPU32}
  4390. // save context
  4391. PUSH EDI
  4392. PUSH EBX
  4393. // init parameters
  4394. MOV EAX, ValueEAX
  4395. MOV ECX, ValueECX
  4396. // CPUID
  4397. DB 0FH
  4398. DB 0A2H
  4399. // store results
  4400. MOV EDI, ReturnedEAX
  4401. MOV Cardinal PTR [EDI], EAX
  4402. MOV EAX, ReturnedEBX
  4403. MOV EDI, ReturnedECX
  4404. MOV Cardinal PTR [EAX], EBX
  4405. MOV Cardinal PTR [EDI], ECX
  4406. MOV EAX, ReturnedEDX
  4407. MOV Cardinal PTR [EAX], EDX
  4408. // restore context
  4409. POP EBX
  4410. POP EDI
  4411. {$ENDIF CPU32}
  4412. {$IFDEF CPU64}
  4413. // save context
  4414. PUSH RBX
  4415. // init parameters
  4416. MOV EAX, ValueEAX
  4417. MOV ECX, ValueECX
  4418. // CPUID
  4419. CPUID
  4420. // store results
  4421. MOV R8, ReturnedEAX
  4422. MOV R9, ReturnedEBX
  4423. MOV R10, ReturnedECX
  4424. MOV R11, ReturnedEDX
  4425. MOV Cardinal PTR [R8], EAX
  4426. MOV Cardinal PTR [R9], EBX
  4427. MOV Cardinal PTR [R10], ECX
  4428. MOV Cardinal PTR [R11], EDX
  4429. // restore context
  4430. POP RBX
  4431. {$ENDIF CPU64}
  4432. end;
  4433. {$IFNDEF DELPHI64_TEMPORARY}
  4434. end;
  4435. {$ENDIF ~DELPHI64_TEMPORARY}
  4436. procedure ProcessStandard(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  4437. var
  4438. VersionInfo, AdditionalInfo, ExFeatures: Cardinal;
  4439. begin
  4440. if HiVal >= 1 then
  4441. begin
  4442. CallCPUID(1, 0, VersionInfo, AdditionalInfo, ExFeatures, CPUInfo.Features);
  4443. CPUInfo.PType := (VersionInfo and $00003000) shr 12;
  4444. CPUInfo.Family := (VersionInfo and $00000F00) shr 8;
  4445. CPUInfo.Model := (VersionInfo and $000000F0) shr 4;
  4446. CPUInfo.Stepping := (VersionInfo and $0000000F);
  4447. CPUInfo.ExtendedModel := (VersionInfo and $000F0000) shr 16;
  4448. CPUInfo.ExtendedFamily := (VersionInfo and $0FF00000) shr 20;
  4449. if CPUInfo.CpuType = CPU_TYPE_INTEL then
  4450. begin
  4451. CPUInfo.IntelSpecific.ExFeatures := ExFeatures;
  4452. CPUInfo.IntelSpecific.BrandID := AdditionalInfo and $000000FF;
  4453. CPUInfo.IntelSpecific.FlushLineSize := (AdditionalInfo and $0000FF00) shr 8;
  4454. CPUInfo.IntelSpecific.APICID := (AdditionalInfo and $FF000000) shr 24;
  4455. CPUInfo.HyperThreadingTechnology := (CPUInfo.Features and INTEL_HTT) <> 0;
  4456. if CPUInfo.HyperThreadingTechnology then
  4457. begin
  4458. CPUInfo.LogicalCore := (AdditionalInfo and $00FF0000) shr 16;
  4459. if CPUInfo.LogicalCore = 0 then
  4460. CPUInfo.LogicalCore := 1;
  4461. end;
  4462. if HiVal >= 2 then
  4463. begin
  4464. CPUInfo.HasCacheInfo := True;
  4465. // TODO: multiple loops
  4466. CallCPUID(2, 0, CPUInfo.IntelSpecific.CacheDescriptors[0], CPUInfo.IntelSpecific.CacheDescriptors[4],
  4467. CPUInfo.IntelSpecific.CacheDescriptors[8], CPUInfo.IntelSpecific.CacheDescriptors[12]);
  4468. end;
  4469. end;
  4470. end;
  4471. end;
  4472. procedure ProcessIntel(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  4473. var
  4474. ExHiVal, Unused, AddressSize, CoreInfo: Cardinal;
  4475. I, J: Integer;
  4476. begin
  4477. CPUInfo.CpuType := CPU_TYPE_INTEL;
  4478. CPUInfo.Manufacturer := 'Intel';
  4479. ProcessStandard(CPUInfo, HiVal);
  4480. if HiVal >= 4 then
  4481. begin
  4482. CallCPUID(4, 0, CoreInfo, Unused, Unused, Unused);
  4483. CPUInfo.PhysicalCore := ((CoreInfo and $FC000000) shr 26) + 1;
  4484. end;
  4485. if HiVal >= 6 then
  4486. CallCPUID(6, 0, CPUInfo.IntelSpecific.PowerManagementFeatures, Unused, Unused, Unused);
  4487. // check Intel extended
  4488. CallCPUID($80000000, 0, ExHiVal, Unused, Unused, Unused);
  4489. if ExHiVal >= $80000001 then
  4490. begin
  4491. CPUInfo.HasExtendedInfo := True;
  4492. CallCPUID($80000001, 0, Unused, Unused, CPUInfo.IntelSpecific.Ex64Features2,
  4493. CPUInfo.IntelSpecific.Ex64Features);
  4494. end;
  4495. if ExHiVal >= $80000002 then
  4496. CallCPUID($80000002, 0, CPUInfo.CpuName[0], CPUInfo.CpuName[4], CPUInfo.CpuName[8], CPUInfo.CpuName[12]);
  4497. if ExHiVal >= $80000003 then
  4498. CallCPUID($80000003, 0, CPUInfo.CpuName[16], CPUInfo.CpuName[20], CPUInfo.CpuName[24], CPUInfo.CpuName[28]);
  4499. if ExHiVal >= $80000004 then
  4500. CallCPUID($80000004, 0, CPUInfo.CpuName[32], CPUInfo.CpuName[36], CPUInfo.CpuName[40], CPUInfo.CpuName[44]);
  4501. if ExHiVal >= $80000006 then
  4502. CallCPUID($80000006, 0, Unused, Unused, CPUInfo.IntelSpecific.L2Cache, Unused);
  4503. if ExHiVal >= $80000008 then
  4504. begin
  4505. CallCPUID($80000008, 0, AddressSize, Unused, Unused, Unused);
  4506. CPUInfo.IntelSpecific.PhysicalAddressBits := AddressSize and $000000FF;
  4507. CPUInfo.IntelSpecific.VirtualAddressBits := (AddressSize and $0000FF00) shr 8;
  4508. end;
  4509. if CPUInfo.HasCacheInfo then
  4510. begin
  4511. if (CPUInfo.IntelSpecific.L2Cache <> 0) then
  4512. begin
  4513. CPUInfo.L2CacheSize := CPUInfo.IntelSpecific.L2Cache shr 16;
  4514. CPUInfo.L2CacheLineSize := CPUInfo.IntelSpecific.L2Cache and $FF;
  4515. CPUInfo.L2CacheAssociativity := (CPUInfo.IntelSpecific.L2Cache shr 12) and $F;
  4516. end;
  4517. for I := Low(CPUInfo.IntelSpecific.CacheDescriptors) to High(CPUInfo.IntelSpecific.CacheDescriptors) do
  4518. if CPUInfo.IntelSpecific.CacheDescriptors[I]<>0 then
  4519. for J := Low(IntelCacheDescription) to High(IntelCacheDescription) do
  4520. if IntelCacheDescription[J].D = CPUInfo.IntelSpecific.CacheDescriptors[I] then
  4521. with IntelCacheDescription[J] do
  4522. case Family of
  4523. //cfInstructionTLB:
  4524. //cfDataTLB:
  4525. cfL1InstructionCache:
  4526. begin
  4527. Inc(CPUInfo.L1InstructionCacheSize,Size);
  4528. CPUInfo.L1InstructionCacheLineSize := LineSize;
  4529. CPUInfo.L1InstructionCacheAssociativity := WaysOfAssoc;
  4530. end;
  4531. cfL1DataCache:
  4532. begin
  4533. Inc(CPUInfo.L1DataCacheSize,Size);
  4534. CPUInfo.L1DataCacheLineSize := LineSize;
  4535. CPUInfo.L1DataCacheAssociativity := WaysOfAssoc;
  4536. end;
  4537. cfL2Cache:
  4538. if (CPUInfo.IntelSpecific.L2Cache = 0) then
  4539. begin
  4540. Inc(CPUInfo.L2CacheSize,Size);
  4541. CPUInfo.L2CacheLineSize := LineSize;
  4542. CPUInfo.L2CacheAssociativity := WaysOfAssoc;
  4543. end;
  4544. cfL3Cache:
  4545. begin
  4546. Inc(CPUInfo.L3CacheSize,Size);
  4547. CPUInfo.L3CacheLineSize := LineSize;
  4548. CPUInfo.L3CacheAssociativity := WaysOfAssoc;
  4549. CPUInfo.L3LinesPerSector := LinePerSector;
  4550. end;
  4551. //cfTrace: // no numeric informations
  4552. //cfOther:
  4553. end;
  4554. end;
  4555. if not CPUInfo.HasExtendedInfo then
  4556. begin
  4557. case CPUInfo.Family of
  4558. 4:
  4559. case CPUInfo.Model of
  4560. 1:
  4561. CPUInfo.CpuName := 'Intel 486DX Processor';
  4562. 2:
  4563. CPUInfo.CpuName := 'Intel 486SX Processor';
  4564. 3:
  4565. CPUInfo.CpuName := 'Intel DX2 Processor';
  4566. 4:
  4567. CPUInfo.CpuName := 'Intel 486 Processor';
  4568. 5:
  4569. CPUInfo.CpuName := 'Intel SX2 Processor';
  4570. 7:
  4571. CPUInfo.CpuName := 'Write-Back Enhanced Intel DX2 Processor';
  4572. 8:
  4573. CPUInfo.CpuName := 'Intel DX4 Processor';
  4574. else
  4575. CPUInfo.CpuName := 'Intel 486 Processor';
  4576. end;
  4577. 5:
  4578. CPUInfo.CpuName := 'Pentium';
  4579. 6:
  4580. case CPUInfo.Model of
  4581. 1:
  4582. CPUInfo.CpuName := 'Pentium Pro';
  4583. 3:
  4584. CPUInfo.CpuName := 'Pentium II';
  4585. 5:
  4586. case CPUInfo.L2CacheSize of
  4587. 0:
  4588. CPUInfo.CpuName := 'Celeron';
  4589. 1024:
  4590. CPUInfo.CpuName := 'Pentium II Xeon';
  4591. 2048:
  4592. CPUInfo.CpuName := 'Pentium II Xeon';
  4593. else
  4594. CPUInfo.CpuName := 'Pentium II';
  4595. end;
  4596. 6:
  4597. case CPUInfo.L2CacheSize of
  4598. 0:
  4599. CPUInfo.CpuName := 'Celeron';
  4600. 128:
  4601. CPUInfo.CpuName := 'Celeron';
  4602. else
  4603. CPUInfo.CpuName := 'Pentium II';
  4604. end;
  4605. 7:
  4606. case CPUInfo.L2CacheSize of
  4607. 1024:
  4608. CPUInfo.CpuName := 'Pentium III Xeon';
  4609. 2048:
  4610. CPUInfo.CpuName := 'Pentium III Xeon';
  4611. else
  4612. CPUInfo.CpuName := 'Pentium III';
  4613. end;
  4614. 8:
  4615. case CPUInfo.IntelSpecific.BrandID of
  4616. 1:
  4617. CPUInfo.CpuName := 'Celeron';
  4618. 2:
  4619. CPUInfo.CpuName := 'Pentium III';
  4620. 3:
  4621. CPUInfo.CpuName := 'Pentium III Xeon';
  4622. 4:
  4623. CPUInfo.CpuName := 'Pentium III';
  4624. else
  4625. CPUInfo.CpuName := 'Pentium III';
  4626. end;
  4627. 10:
  4628. CPUInfo.CpuName := 'Pentium III Xeon';
  4629. 11:
  4630. CPUInfo.CpuName := 'Pentium III';
  4631. else
  4632. StrPCopyA(CPUInfo.CpuName, AnsiString(Format('P6 (Model %d)', [CPUInfo.Model])));
  4633. end;
  4634. 15:
  4635. case CPUInfo.IntelSpecific.BrandID of
  4636. 1:
  4637. CPUInfo.CpuName := 'Celeron';
  4638. 8:
  4639. CPUInfo.CpuName := 'Pentium 4';
  4640. 14:
  4641. CPUInfo.CpuName := 'Xeon';
  4642. else
  4643. CPUInfo.CpuName := 'Pentium 4';
  4644. end;
  4645. else
  4646. StrPCopyA(CPUInfo.CpuName, AnsiString(Format('P%d', [CPUInfo.Family])));
  4647. end;
  4648. end;
  4649. CPUInfo.HardwareHyperThreadingTechnology := CPUInfo.LogicalCore <> CPUInfo.PhysicalCore;
  4650. CPUInfo.AES := (CPUInfo.IntelSpecific.ExFeatures and EINTEL_AES) <> 0;
  4651. CPUInfo.MMX := (CPUInfo.Features and MMX_FLAG) <> 0;
  4652. CPUInfo.SSE := [];
  4653. if (CPUInfo.Features and SSE_FLAG) <> 0 then
  4654. Include(CPUInfo.SSE, sse);
  4655. if (CPUInfo.Features and SSE2_FLAG) <> 0 then
  4656. Include(CPUInfo.SSE, sse2);
  4657. if (CPUInfo.IntelSpecific.ExFeatures and EINTEL_SSE3) <> 0 then
  4658. Include(CPUInfo.SSE, sse3);
  4659. if (CPUInfo.IntelSpecific.ExFeatures and EINTEL_SSSE3) <> 0 then
  4660. Include(CPUInfo.SSE, ssse3);
  4661. if (CPUInfo.IntelSpecific.ExFeatures and EINTEL_SSE4_1) <> 0 then
  4662. Include(CPUInfo.SSE, sse41);
  4663. if (CPUInfo.IntelSpecific.ExFeatures and EINTEL_SSE4_2) <> 0 then
  4664. Include(CPUInfo.SSE, sse42);
  4665. if (CPUInfo.IntelSpecific.ExFeatures and EINTEL_AVX) <> 0 then
  4666. Include(CPUInfo.SSE, avx);
  4667. CPUInfo.Is64Bits := CPUInfo.HasExtendedInfo and ((CPUInfo.IntelSpecific.Ex64Features and EINTEL64_EM64T)<>0);
  4668. CPUInfo.DepCapable := CPUInfo.HasExtendedInfo and ((CPUInfo.IntelSpecific.Ex64Features and EINTEL64_XD) <> 0);
  4669. end;
  4670. procedure ProcessAMD(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  4671. var
  4672. ExHiVal, Unused, VersionInfo, AdditionalInfo: Cardinal;
  4673. begin
  4674. CPUInfo.CpuType := CPU_TYPE_AMD;
  4675. CPUInfo.Manufacturer := 'AMD';
  4676. // check AMD extended
  4677. if HiVal >= 1 then
  4678. begin
  4679. CallCPUID(1, 0, VersionInfo, AdditionalInfo, CPUInfo.AMDSpecific.Features2, CPUInfo.Features);
  4680. CPUInfo.AMDSpecific.BrandID := AdditionalInfo and $000000FF;
  4681. CPUInfo.AMDSpecific.FlushLineSize := (AdditionalInfo and $0000FF00) shr 8;
  4682. CPUInfo.AMDSpecific.APICID := (AdditionalInfo and $FF000000) shr 24;
  4683. CPUInfo.HyperThreadingTechnology := (CPUInfo.Features and AMD_HTT) <> 0;
  4684. if CPUInfo.HyperThreadingTechnology then
  4685. begin
  4686. CPUInfo.LogicalCore := (AdditionalInfo and $00FF0000) shr 16;
  4687. if CPUInfo.LogicalCore = 0 then
  4688. CPUInfo.LogicalCore := 1;
  4689. end;
  4690. end;
  4691. CallCPUID($80000000, 0, ExHiVal, Unused, Unused, Unused);
  4692. if ExHiVal <> 0 then
  4693. begin
  4694. // AMD only
  4695. CPUInfo.HasExtendedInfo := True;
  4696. if ExHiVal >= $80000001 then
  4697. begin
  4698. CallCPUID($80000001, 0, VersionInfo, AdditionalInfo, CPUInfo.AMDSpecific.ExFeatures2, CPUInfo.AMDSpecific.ExFeatures);
  4699. CPUInfo.Family := (VersionInfo and $00000F00) shr 8;
  4700. CPUInfo.Model := (VersionInfo and $000000F0) shr 4;
  4701. CPUInfo.Stepping := (VersionInfo and $0000000F);
  4702. CPUInfo.ExtendedModel := (VersionInfo and $000F0000) shr 16;
  4703. CPUInfo.ExtendedFamily := (VersionInfo and $0FF00000) shr 20;
  4704. CPUInfo.AMDSpecific.ExBrandID := AdditionalInfo and $0000FFFF;
  4705. end;
  4706. if ExHiVal >= $80000002 then
  4707. CallCPUID($80000002, 0, CPUInfo.CpuName[0], CPUInfo.CpuName[4], CPUInfo.CpuName[8], CPUInfo.CpuName[12]);
  4708. if ExHiVal >= $80000003 then
  4709. CallCPUID($80000003, 0, CPUInfo.CpuName[16], CPUInfo.CpuName[20], CPUInfo.CpuName[24], CPUInfo.CpuName[28]);
  4710. if ExHiVal >= $80000004 then
  4711. CallCPUID($80000004, 0, CPUInfo.CpuName[32], CPUInfo.CpuName[36], CPUInfo.CpuName[40], CPUInfo.CpuName[44]);
  4712. if ExHiVal >= $80000005 then
  4713. begin
  4714. CPUInfo.HasCacheInfo := True;
  4715. CallCPUID($80000005, 0, CPUInfo.AMDSpecific.L1MByteInstructionTLB, CPUInfo.AMDSpecific.L1KByteInstructionTLB,
  4716. CPUInfo.AMDSpecific.L1DataCache, CPUInfo.AMDSpecific.L1InstructionCache);
  4717. end;
  4718. if ExHiVal >= $80000006 then
  4719. CallCPUID($80000006, 0, CPUInfo.AMDSpecific.L2MByteInstructionTLB, CPUInfo.AMDSpecific.L2KByteInstructionTLB,
  4720. CPUInfo.AMDSpecific.L2Cache, CPUInfo.AMDSpecific.L3Cache);
  4721. if CPUInfo.HasCacheInfo then
  4722. begin
  4723. CPUInfo.L1DataCacheSize := CPUInfo.AMDSpecific.L1DataCache[ciSize];
  4724. CPUInfo.L1DataCacheLineSize := CPUInfo.AMDSpecific.L1DataCache[ciLineSize];
  4725. CPUInfo.L1DataCacheAssociativity := CPUInfo.AMDSpecific.L1DataCache[ciAssociativity];
  4726. CPUInfo.L1InstructionCacheSize := CPUInfo.AMDSpecific.L1InstructionCache[ciSize];
  4727. CPUInfo.L1InstructionCacheLineSize := CPUInfo.AMDSpecific.L1InstructionCache[ciLineSize];
  4728. CPUInfo.L1InstructionCacheAssociativity := CPUInfo.AMDSpecific.L1InstructionCache[ciAssociativity];
  4729. CPUInfo.L2CacheLineSize := CPUInfo.AMDSpecific.L2Cache and $FF;
  4730. CPUInfo.L2CacheAssociativity := (CPUInfo.AMDSpecific.L2Cache shr 12) and $F;
  4731. CPUInfo.L2CacheSize := CPUInfo.AMDSpecific.L2Cache shr 16;
  4732. CPUInfo.L3CacheLineSize := CPUInfo.AMDSpecific.L3Cache and $FF;
  4733. CPUInfo.L3CacheAssociativity := (CPUInfo.AMDSpecific.L3Cache shr 12) and $F;
  4734. CPUInfo.L3CacheSize := CPUInfo.AMDSpecific.L3Cache shr 19 {MB}; //(CPUInfo.AMDSpecific.L3Cache shr 18) * 512 {kB};
  4735. end;
  4736. if ExHiVal >= $80000007 then
  4737. CallCPUID($80000007, 0, Unused, Unused, Unused, CPUInfo.AMDSpecific.AdvancedPowerManagement);
  4738. if ExHiVal >= $80000008 then
  4739. begin
  4740. CallCPUID($80000008, 0, Unused, VersionInfo, AdditionalInfo, Unused);
  4741. CPUInfo.AMDSpecific.PhysicalAddressSize := VersionInfo and $000000FF;
  4742. CPUInfo.AMDSpecific.VirtualAddressSize := (VersionInfo and $0000FF00) shr 8;
  4743. CPUInfo.PhysicalCore := (AdditionalInfo and $000000FF) + 1;
  4744. end;
  4745. end
  4746. else
  4747. begin
  4748. ProcessStandard(CPUInfo, HiVal);
  4749. case CPUInfo.Family of
  4750. 4:
  4751. CPUInfo.CpuName := 'Am486(R) or Am5x86';
  4752. 5:
  4753. case CPUInfo.Model of
  4754. 0:
  4755. CPUInfo.CpuName := 'AMD-K5 (Model 0)';
  4756. 1:
  4757. CPUInfo.CpuName := 'AMD-K5 (Model 1)';
  4758. 2:
  4759. CPUInfo.CpuName := 'AMD-K5 (Model 2)';
  4760. 3:
  4761. CPUInfo.CpuName := 'AMD-K5 (Model 3)';
  4762. 6:
  4763. CPUInfo.CpuName := 'AMD-K6® (Model 6)';
  4764. 7:
  4765. CPUInfo.CpuName := 'AMD-K6® (Model 7)';
  4766. 8:
  4767. CPUInfo.CpuName := 'AMD-K6®-2 (Model 8)';
  4768. 9:
  4769. CPUInfo.CpuName := 'AMD-K6®-III (Model 9)';
  4770. else
  4771. StrFmtA(CPUInfo.CpuName, PAnsiChar(AnsiString(LoadResString(@RsUnknownAMDModel))), [CPUInfo.Model]);
  4772. end;
  4773. 6:
  4774. case CPUInfo.Model of
  4775. 1:
  4776. CPUInfo.CpuName := 'AMD Athlon™ (Model 1)';
  4777. 2:
  4778. CPUInfo.CpuName := 'AMD Athlon™ (Model 2)';
  4779. 3:
  4780. CPUInfo.CpuName := 'AMD Duron™ (Model 3)';
  4781. 4:
  4782. CPUInfo.CpuName := 'AMD Athlon™ (Model 4)';
  4783. 6:
  4784. CPUInfo.CpuName := 'AMD Athlon™ XP (Model 6)';
  4785. 7:
  4786. CPUInfo.CpuName := 'AMD Duron™ (Model 7)';
  4787. 8:
  4788. CPUInfo.CpuName := 'AMD Athlon™ XP (Model 8)';
  4789. 10:
  4790. CPUInfo.CpuName := 'AMD Athlon™ XP (Model 10)';
  4791. else
  4792. StrFmtA(CPUInfo.CpuName, PAnsiChar(AnsiString(LoadResString(@RsUnknownAMDModel))), [CPUInfo.Model]);
  4793. end;
  4794. 8:
  4795. else
  4796. CPUInfo.CpuName := 'Unknown AMD Chip';
  4797. end;
  4798. end;
  4799. CPUInfo.HardwareHyperThreadingTechnology := CPUInfo.LogicalCore <> CPUInfo.PhysicalCore;
  4800. CPUInfo.AES := (CPUInfo.AMDSpecific.Features2 and AMD2_AES) <> 0;
  4801. CPUInfo.MMX := (CPUInfo.Features and AMD_MMX) <> 0;
  4802. CPUInfo.ExMMX := CPUInfo.HasExtendedInfo and ((CPUInfo.AMDSpecific.ExFeatures and EAMD_EXMMX) <> 0);
  4803. CPUInfo._3DNow := CPUInfo.HasExtendedInfo and ((CPUInfo.AMDSpecific.ExFeatures and EAMD_3DNOW) <> 0);
  4804. CPUInfo.Ex3DNow := CPUInfo.HasExtendedInfo and ((CPUInfo.AMDSpecific.ExFeatures and EAMD_EX3DNOW) <> 0);
  4805. CPUInfo.SSE := [];
  4806. if (CPUInfo.Features and AMD_SSE) <> 0 then
  4807. Include(CPUInfo.SSE, sse);
  4808. if (CPUInfo.Features and AMD_SSE2) <> 0 then
  4809. Include(CPUInfo.SSE, sse2);
  4810. if (CPUInfo.AMDSpecific.Features2 and AMD2_SSE3) <> 0 then
  4811. Include(CPUInfo.SSE, sse3);
  4812. if CPUInfo.HasExtendedInfo then
  4813. begin
  4814. if (CPUInfo.AMDSpecific.ExFeatures2 and EAMD2_SSE4A) <> 0 then
  4815. Include(CPUInfo.SSE, sse4A);
  4816. if (CPUInfo.AMDSpecific.Features2 and AMD2_SSE41) <> 0 then
  4817. Include(CPUInfo.SSE, sse41);
  4818. if (CPUInfo.AMDSpecific.Features2 and AMD2_SSE42) <> 0 then
  4819. Include(CPUInfo.SSE, sse42);
  4820. end;
  4821. CPUInfo.Is64Bits := CPUInfo.HasExtendedInfo and ((CPUInfo.AMDSpecific.ExFeatures and EAMD_LONG) <> 0);
  4822. CPUInfo.DEPCapable := CPUInfo.HasExtendedInfo and ((CPUInfo.AMDSpecific.ExFeatures and EAMD_NX) <> 0);
  4823. end;
  4824. procedure ProcessCyrix(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  4825. var
  4826. ExHiVal, Unused, VersionInfo, AdditionalInfo: Cardinal;
  4827. begin
  4828. CPUInfo.CpuType := CPU_TYPE_CYRIX;
  4829. CPUInfo.Manufacturer := 'Cyrix';
  4830. // check Cyrix extended
  4831. CallCPUID($80000000, 0, ExHiVal, Unused, Unused, Unused);
  4832. if ExHiVal <> 0 then
  4833. begin
  4834. // Cyrix only
  4835. CPUInfo.HasExtendedInfo := True;
  4836. if ExHiVal >= $80000001 then
  4837. begin
  4838. CallCPUID($80000001, 0, VersionInfo, AdditionalInfo, Unused, CPUInfo.Features);
  4839. CPUInfo.PType := (VersionInfo and $0000F000) shr 12;
  4840. CPUInfo.Family := (VersionInfo and $00000F00) shr 8;
  4841. CPUInfo.Model := (VersionInfo and $000000F0) shr 4;
  4842. CPUInfo.Stepping := (VersionInfo and $0000000F);
  4843. end;
  4844. if ExHiVal >= $80000002 then
  4845. CallCPUID($80000002, 0, CPUInfo.CpuName[0], CPUInfo.CpuName[4], CPUInfo.CpuName[8], CPUInfo.CpuName[12]);
  4846. if ExHiVal >= $80000003 then
  4847. CallCPUID($80000003, 0, CPUInfo.CpuName[16], CPUInfo.CpuName[20], CPUInfo.CpuName[24], CPUInfo.CpuName[28]);
  4848. if ExHiVal >= $80000004 then
  4849. CallCPUID($80000004, 0, CPUInfo.CpuName[32], CPUInfo.CpuName[36], CPUInfo.CpuName[40], CPUInfo.CpuName[44]);
  4850. if ExHiVal >= $80000005 then
  4851. begin
  4852. CPUInfo.HasCacheInfo := True;
  4853. CallCPUID($80000005, 0, Unused, CPUInfo.CyrixSpecific.TLBInfo, CPUInfo.CyrixSpecific.L1CacheInfo, Unused);
  4854. end;
  4855. end
  4856. else
  4857. begin
  4858. ProcessStandard(CPUInfo, HiVal);
  4859. case CPUInfo.Family of
  4860. 4:
  4861. CPUInfo.CpuName := 'Cyrix MediaGX';
  4862. 5:
  4863. case CPUInfo.Model of
  4864. 2:
  4865. CPUInfo.CpuName := 'Cyrix 6x86';
  4866. 4:
  4867. CPUInfo.CpuName := 'Cyrix GXm';
  4868. end;
  4869. 6:
  4870. CPUInfo.CpuName := '6x86MX';
  4871. else
  4872. StrPCopyA(CPUInfo.CpuName, AnsiString(Format('%dx86', [CPUInfo.Family])));
  4873. end;
  4874. end;
  4875. end;
  4876. procedure ProcessVIA(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  4877. var
  4878. ExHiVal, Unused, VersionInfo: Cardinal;
  4879. begin
  4880. CPUInfo.CpuType := CPU_TYPE_VIA;
  4881. CPUInfo.Manufacturer := 'Via';
  4882. // check VIA extended
  4883. CallCPUID($80000000, 0, ExHiVal, Unused, Unused, Unused);
  4884. if ExHiVal <> 0 then
  4885. begin
  4886. if ExHiVal >= $80000001 then
  4887. begin
  4888. CPUInfo.HasExtendedInfo := True;
  4889. CallCPUID($80000001, 0, VersionInfo, Unused, Unused, CPUInfo.ViaSpecific.ExFeatures);
  4890. CPUInfo.PType := (VersionInfo and $00003000) shr 12;
  4891. CPUInfo.Family := (VersionInfo and $00000F00) shr 8;
  4892. CPUInfo.Model := (VersionInfo and $000000F0) shr 4;
  4893. CPUInfo.Stepping := (VersionInfo and $0000000F);
  4894. end;
  4895. if ExHiVal >= $80000002 then
  4896. CallCPUID($80000002, 0, CPUInfo.CpuName[0], CPUInfo.CpuName[4], CPUInfo.CpuName[8], CPUInfo.CpuName[12]);
  4897. if ExHiVal >= $80000003 then
  4898. CallCPUID($80000003, 0, CPUInfo.CpuName[16], CPUInfo.CpuName[20], CPUInfo.CpuName[24], CPUInfo.CpuName[28]);
  4899. if ExHiVal >= $80000004 then
  4900. CallCPUID($80000004, 0, CPUInfo.CpuName[32], CPUInfo.CpuName[36], CPUInfo.CpuName[40], CPUInfo.CpuName[44]);
  4901. if ExHiVal >= $80000005 then
  4902. begin
  4903. CPUInfo.HasCacheInfo := True;
  4904. CallCPUID($80000005, 0, Unused, CPUInfo.ViaSpecific.InstructionTLB, CPUInfo.ViaSpecific.L1DataCache,
  4905. CPUInfo.ViaSpecific.L1InstructionCache);
  4906. end;
  4907. if ExHiVal >= $80000006 then
  4908. CallCPUID($80000006, 0, Unused, Unused, CPUInfo.ViaSpecific.L2DataCache, Unused);
  4909. if CPUInfo.HasCacheInfo then
  4910. begin
  4911. CPUInfo.L1DataCacheSize := CPUInfo.VIASpecific.L1DataCache[ciSize];
  4912. CPUInfo.L1DataCacheLineSize := CPUInfo.VIASpecific.L1DataCache[ciLineSize];
  4913. CPUInfo.L1DataCacheAssociativity := CPUInfo.VIASpecific.L1DataCache[ciAssociativity];
  4914. CPUInfo.L1InstructionCacheSize := CPUInfo.VIASpecific.L1InstructionCache[ciSize];
  4915. CPUInfo.L1InstructionCacheLineSize := CPUInfo.VIASpecific.L1InstructionCache[ciLineSize];
  4916. CPUInfo.L1InstructionCacheAssociativity := CPUInfo.VIASpecific.L1InstructionCache[ciAssociativity];
  4917. CPUInfo.L2CacheLineSize := CPUInfo.VIASpecific.L2DataCache and $FF;
  4918. CPUInfo.L2CacheAssociativity := (CPUInfo.VIASpecific.L2DataCache shr 12) and $F;
  4919. CPUInfo.L2CacheSize := CPUInfo.VIASpecific.L2DataCache shr 16;
  4920. end;
  4921. CallCPUID($C0000000, 0, ExHiVal, Unused, Unused, Unused);
  4922. if ExHiVal >= $C0000001 then
  4923. CallCPUID($C0000001, 0, Unused, Unused, Unused, CPUInfo.ViaSpecific.ExFeatures);
  4924. end
  4925. else
  4926. ProcessStandard(CPUInfo, HiVal);
  4927. if not CPUInfo.HasExtendedInfo then
  4928. CPUInfo.CpuName := 'C3';
  4929. CPUInfo.MMX := (CPUInfo.Features and VIA_MMX) <> 0;
  4930. CPUInfo.SSE := [];
  4931. if (CPUInfo.Features and VIA_SSE) <> 0 then
  4932. Include(CPUInfo.SSE, sse);
  4933. CPUInfo._3DNow := (CPUInfo.Features and VIA_3DNOW) <> 0;
  4934. end;
  4935. procedure ProcessTransmeta(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  4936. var
  4937. ExHiVal, Unused, VersionInfo: Cardinal;
  4938. begin
  4939. CPUInfo.CpuType := CPU_TYPE_TRANSMETA;
  4940. CPUInfo.Manufacturer := 'Transmeta';
  4941. if (HiVal >= 1) then
  4942. begin
  4943. CallCPUID(1, 0, VersionInfo, Unused, Unused, CPUInfo.Features);
  4944. CPUInfo.PType := (VersionInfo and $00003000) shr 12;
  4945. CPUInfo.Family := (VersionInfo and $00000F00) shr 8;
  4946. CPUInfo.Model := (VersionInfo and $000000F0) shr 4;
  4947. CPUInfo.Stepping := (VersionInfo and $0000000F);
  4948. end;
  4949. // no information when eax is 2
  4950. // eax is 3 means Serial Number, not detected there
  4951. // small CPU description, overriden if ExHiVal >= 80000002
  4952. CallCPUID($80000000, 0, ExHiVal, CPUInfo.CpuName[0], CPUInfo.CpuName[8], CPUInfo.CpuName[4]);
  4953. if ExHiVal <> 0 then
  4954. begin
  4955. CPUInfo.HasExtendedInfo := True;
  4956. if ExHiVal >= $80000001 then
  4957. CallCPUID($80000001, 0, Unused, Unused, Unused, CPUInfo.TransmetaSpecific.ExFeatures);
  4958. if ExHiVal >= $80000002 then
  4959. CallCPUID($80000002, 0, CPUInfo.CpuName[0], CPUInfo.CpuName[4], CPUInfo.CpuName[8], CPUInfo.CpuName[12]);
  4960. if ExHiVal >= $80000003 then
  4961. CallCPUID($80000003, 0, CPUInfo.CpuName[16], CPUInfo.CpuName[20], CPUInfo.CpuName[24], CPUInfo.CpuName[28]);
  4962. if ExHiVal >= $80000004 then
  4963. CallCPUID($80000004, 0, CPUInfo.CpuName[32], CPUInfo.CpuName[36], CPUInfo.CpuName[40], CPUInfo.CpuName[44]);
  4964. if ExHiVal >= $80000005 then
  4965. begin
  4966. CPUInfo.HasCacheInfo := True;
  4967. CallCPUID($80000005, 0, Unused, CPUInfo.TransmetaSpecific.CodeTLB, CPUInfo.TransmetaSpecific.L1DataCache,
  4968. CPUInfo.TransmetaSpecific.L1CodeCache);
  4969. end;
  4970. if CPUInfo.HasCacheInfo then
  4971. begin
  4972. CPUInfo.L1DataCacheSize := CPUInfo.TransmetaSpecific.L1DataCache[ciSize];
  4973. CPUInfo.L1DataCacheLineSize := CPUInfo.TransmetaSpecific.L1DataCache[ciLineSize];
  4974. CPUInfo.L1DataCacheAssociativity := CPUInfo.TransmetaSpecific.L1DataCache[ciAssociativity];
  4975. CPUInfo.L1InstructionCacheSize := CPUInfo.TransmetaSpecific.L1CodeCache[ciSize];
  4976. CPUInfo.L1InstructionCacheLineSize := CPUInfo.TransmetaSpecific.L1CodeCache[ciLineSize];
  4977. CPUInfo.L1InstructionCacheAssociativity := CPUInfo.TransmetaSpecific.L1CodeCache[ciAssociativity];
  4978. CPUInfo.L2CacheLineSize := CPUInfo.TransmetaSpecific.L2Cache and $FF;
  4979. CPUInfo.L2CacheAssociativity := (CPUInfo.TransmetaSpecific.L2Cache shr 12) and $F;
  4980. CPUInfo.L2CacheSize := CPUInfo.TransmetaSpecific.L2Cache shr 16;
  4981. end;
  4982. if ExHiVal >= $80000006 then
  4983. CallCPUID($80000006, 0, Unused, Unused, CPUInfo.TransmetaSpecific.L2Cache, Unused);
  4984. end
  4985. else
  4986. CPUInfo.CpuName := 'Crusoe';
  4987. CallCPUID($80860000, 0, ExHiVal, Unused, Unused, Unused);
  4988. if ExHiVal <> 0 then
  4989. begin
  4990. if ExHiVal >= $80860001 then
  4991. CallCPUID($80860001, 0, Unused, CPUInfo.TransmetaSpecific.RevisionABCD, CPUInfo.TransmetaSpecific.RevisionXXXX,
  4992. CPUInfo.TransmetaSpecific.TransmetaFeatures);
  4993. if ExHiVal >= $80860002 then
  4994. CallCPUID($80860002, 0, Unused, CPUInfo.TransmetaSpecific.CodeMorphingABCD, CPUInfo.TransmetaSpecific.CodeMorphingXXXX, Unused);
  4995. if ExHiVal >= $80860003 then
  4996. CallCPUID($80860003, 0, CPUInfo.TransmetaSpecific.TransmetaInformations[0], CPUInfo.TransmetaSpecific.TransmetaInformations[4],
  4997. CPUInfo.TransmetaSpecific.TransmetaInformations[8], CPUInfo.TransmetaSpecific.TransmetaInformations[12]);
  4998. if ExHiVal >= $80860004 then
  4999. CallCPUID($80860004, 0, CPUInfo.TransmetaSpecific.TransmetaInformations[16], CPUInfo.TransmetaSpecific.TransmetaInformations[20],
  5000. CPUInfo.TransmetaSpecific.TransmetaInformations[24], CPUInfo.TransmetaSpecific.TransmetaInformations[28]);
  5001. if ExHiVal >= $80860005 then
  5002. CallCPUID($80860005, 0, CPUInfo.TransmetaSpecific.TransmetaInformations[32], CPUInfo.TransmetaSpecific.TransmetaInformations[36],
  5003. CPUInfo.TransmetaSpecific.TransmetaInformations[40], CPUInfo.TransmetaSpecific.TransmetaInformations[44]);
  5004. if ExHiVal >= $80860006 then
  5005. CallCPUID($80860006, 0, CPUInfo.TransmetaSpecific.TransmetaInformations[48], CPUInfo.TransmetaSpecific.TransmetaInformations[52],
  5006. CPUInfo.TransmetaSpecific.TransmetaInformations[56], CPUInfo.TransmetaSpecific.TransmetaInformations[60]);
  5007. if (ExHiVal >= $80860007) and ((CPUInfo.TransmetaSpecific.TransmetaFeatures and STRANSMETA_LONGRUN) <> 0) then
  5008. CallCPUID($80860007, 0, CPUInfo.TransmetaSpecific.CurrentFrequency, CPUInfo.TransmetaSpecific.CurrentVoltage,
  5009. CPUInfo.TransmetaSpecific.CurrentPerformance, Unused);
  5010. end;
  5011. CPUInfo.MMX := (CPUInfo.Features and TRANSMETA_MMX) <> 0;
  5012. end;
  5013. var
  5014. HiVal: Cardinal;
  5015. begin
  5016. ResetMemory(Result, sizeof(Result));
  5017. Result.LogicalCore := 1;
  5018. Result.PhysicalCore := 1;
  5019. if HasCPUIDInstruction then
  5020. begin
  5021. Result.HasInstruction := True;
  5022. CallCPUID(0, 0, HiVal, Result.VendorIDString[0], Result.VendorIDString[8],
  5023. Result.VendorIDString[4]);
  5024. if Result.VendorIDString = VendorIDIntel then
  5025. ProcessIntel(Result, HiVal)
  5026. else if Result.VendorIDString = VendorIDAMD then
  5027. ProcessAMD(Result, HiVal)
  5028. else if Result.VendorIDString = VendorIDCyrix then
  5029. ProcessCyrix(Result, HiVal)
  5030. else if Result.VendorIDString = VendorIDVIA then
  5031. ProcessVIA(Result, HiVal)
  5032. else if Result.VendorIDString = VendorIDTransmeta then
  5033. ProcessTransmeta(Result, HiVal)
  5034. else
  5035. ProcessStandard(Result, HiVal);
  5036. end
  5037. else
  5038. Result.Family := 4;
  5039. if Result.CpuType = 0 then
  5040. begin
  5041. Result.Manufacturer := 'Unknown';
  5042. Result.CpuName := 'Unknown';
  5043. end;
  5044. end;
  5045. function TestFDIVInstruction: Boolean;
  5046. {$IFDEF CPU32}
  5047. var
  5048. TopNum: Double;
  5049. BottomNum: Double;
  5050. One: Double;
  5051. ISOK: Boolean;
  5052. begin
  5053. // The following code was found in Borlands fdiv.asm file in the
  5054. // Delphi 3\Source\RTL\SYS directory, (I made some minor modifications)
  5055. // therefore I cannot take credit for it.
  5056. TopNum := 2658955;
  5057. BottomNum := PI;
  5058. One := 1;
  5059. asm
  5060. PUSH EAX
  5061. FLD [TopNum]
  5062. FDIV [BottomNum]
  5063. FMUL [BottomNum]
  5064. FSUBR [TopNum]
  5065. FCOMP [One]
  5066. FSTSW AX
  5067. SHR EAX, 8
  5068. AND EAX, 01H
  5069. MOV ISOK, AL
  5070. POP EAX
  5071. end;
  5072. Result := ISOK;
  5073. end;
  5074. {$ENDIF CPU32}
  5075. {$IFDEF CPU64}
  5076. begin
  5077. Result := True;
  5078. end;
  5079. {$ENDIF CPU64}
  5080. //=== Alloc granularity ======================================================
  5081. procedure RoundToAllocGranularity64(var Value: Int64; Up: Boolean);
  5082. begin
  5083. if (Value mod AllocGranularity) <> 0 then
  5084. if Up then
  5085. Value := ((Value div AllocGranularity) + 1) * AllocGranularity
  5086. else
  5087. Value := (Value div AllocGranularity) * AllocGranularity;
  5088. end;
  5089. procedure RoundToAllocGranularityPtr(var Value: Pointer; Up: Boolean);
  5090. var
  5091. Addr: TJclAddr;
  5092. begin
  5093. Addr := TJclAddr(Value);
  5094. if (Addr mod AllocGranularity) <> 0 then
  5095. begin
  5096. if Up then
  5097. Addr := ((Addr div AllocGranularity) + 1) * AllocGranularity
  5098. else
  5099. Addr := (Addr div AllocGranularity) * AllocGranularity;
  5100. Value := Pointer(Addr);
  5101. end;
  5102. end;
  5103. //=== Advanced Power Management (APM) ========================================
  5104. {$IFDEF MSWINDOWS}
  5105. function GetAPMLineStatus: TAPMLineStatus;
  5106. var
  5107. SystemPowerStatus: TSystemPowerStatus;
  5108. begin
  5109. Result := alsUnknown;
  5110. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5111. Exit; // so we return alsUnknown
  5112. SystemPowerStatus.ACLineStatus := 0;
  5113. if not GetSystemPowerStatus(SystemPowerStatus) then
  5114. RaiseLastOSError
  5115. else
  5116. begin
  5117. case SystemPowerStatus.ACLineStatus of
  5118. 0:
  5119. Result := alsOffline;
  5120. 1:
  5121. Result := alsOnline;
  5122. 255:
  5123. Result := alsUnknown;
  5124. end;
  5125. end;
  5126. end;
  5127. function GetAPMBatteryFlag: TAPMBatteryFlag;
  5128. var
  5129. SystemPowerStatus: TSystemPowerStatus;
  5130. begin
  5131. Result := abfUnknown;
  5132. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5133. Exit; // so we return abfUnknown
  5134. SystemPowerStatus.ACLineStatus := 0;
  5135. if not GetSystemPowerStatus(SystemPowerStatus) then
  5136. RaiseLastOSError
  5137. else
  5138. begin
  5139. case SystemPowerStatus.BatteryFlag of
  5140. 1:
  5141. Result := abfHigh;
  5142. 2:
  5143. Result := abfLow;
  5144. 4:
  5145. Result := abfCritical;
  5146. 8:
  5147. Result := abfCharging;
  5148. 128:
  5149. Result := abfNoBattery;
  5150. 255:
  5151. Result := abfUnknown;
  5152. end;
  5153. end;
  5154. end;
  5155. function GetAPMBatteryFlags: TAPMBatteryFlags;
  5156. var
  5157. SystemPowerStatus: TSystemPowerStatus;
  5158. begin
  5159. Result := [];
  5160. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5161. begin
  5162. Result := [abfUnknown];
  5163. Exit; // so we return [abfUnknown]
  5164. end;
  5165. SystemPowerStatus.ACLineStatus := 0;
  5166. if not GetSystemPowerStatus(SystemPowerStatus) then
  5167. RaiseLastOSError
  5168. else
  5169. begin
  5170. if (SystemPowerStatus.BatteryFlag and 1) <> 0 then
  5171. Result := Result + [abfHigh];
  5172. if (SystemPowerStatus.BatteryFlag and 2) <> 0 then
  5173. Result := Result + [abfLow];
  5174. if (SystemPowerStatus.BatteryFlag and 4) <> 0 then
  5175. Result := Result + [abfCritical];
  5176. if (SystemPowerStatus.BatteryFlag and 8) <> 0 then
  5177. Result := Result + [abfCharging];
  5178. if (SystemPowerStatus.BatteryFlag and 128) <> 0 then
  5179. Result := Result + [abfNoBattery];
  5180. if SystemPowerStatus.BatteryFlag = 255 then
  5181. Result := Result + [abfUnknown];
  5182. end;
  5183. end;
  5184. function GetAPMBatteryLifePercent: Integer;
  5185. var
  5186. SystemPowerStatus: TSystemPowerStatus;
  5187. begin
  5188. Result := 0;
  5189. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5190. Exit;
  5191. SystemPowerStatus.ACLineStatus := 0;
  5192. if not GetSystemPowerStatus(SystemPowerStatus) then
  5193. RaiseLastOSError
  5194. else
  5195. Result := SystemPowerStatus.BatteryLifePercent;
  5196. end;
  5197. function GetAPMBatteryLifeTime: DWORD;
  5198. var
  5199. SystemPowerStatus: TSystemPowerStatus;
  5200. begin
  5201. Result := 0;
  5202. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5203. Exit;
  5204. SystemPowerStatus.ACLineStatus := 0;
  5205. if not GetSystemPowerStatus(SystemPowerStatus) then
  5206. RaiseLastOSError
  5207. else
  5208. Result := SystemPowerStatus.BatteryLifeTime;
  5209. end;
  5210. function GetAPMBatteryFullLifeTime: DWORD;
  5211. var
  5212. SystemPowerStatus: TSystemPowerStatus;
  5213. begin
  5214. Result := 0;
  5215. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5216. Exit;
  5217. SystemPowerStatus.ACLineStatus := 0;
  5218. if not GetSystemPowerStatus(SystemPowerStatus) then
  5219. RaiseLastOSError
  5220. else
  5221. Result := SystemPowerStatus.BatteryFullLifeTime;
  5222. end;
  5223. //=== Memory Information =====================================================
  5224. function GetMaxAppAddress: TJclAddr;
  5225. var
  5226. SystemInfo: TSystemInfo;
  5227. begin
  5228. ResetMemory(SystemInfo, SizeOf(SystemInfo));
  5229. GetSystemInfo(SystemInfo);
  5230. Result := TJclAddr(SystemInfo.lpMaximumApplicationAddress);
  5231. end;
  5232. function GetMinAppAddress: TJclAddr;
  5233. var
  5234. SystemInfo: TSystemInfo;
  5235. begin
  5236. ResetMemory(SystemInfo, SizeOf(SystemInfo));
  5237. GetSystemInfo(SystemInfo);
  5238. Result := TJclAddr(SystemInfo.lpMinimumApplicationAddress);
  5239. end;
  5240. {$ENDIF MSWINDOWS}
  5241. function GetMemoryLoad: Byte;
  5242. {$IFDEF UNIX}
  5243. var
  5244. SystemInf: TSysInfo;
  5245. begin
  5246. {$IFDEF FPC}
  5247. SysInfo(@SystemInf);
  5248. {$ELSE ~FPC}
  5249. SysInfo(SystemInf);
  5250. {$ENDIF ~FPC}
  5251. with SystemInf do
  5252. Result := 100 - Round(100 * freeram / totalram);
  5253. end;
  5254. {$ENDIF UNIX}
  5255. {$IFDEF MSWINDOWS}
  5256. var
  5257. MemoryStatusEx: TMemoryStatusEx;
  5258. begin
  5259. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5260. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5261. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5262. RaiseLastOSError;
  5263. Result := MemoryStatusEx.dwMemoryLoad;
  5264. end;
  5265. {$ENDIF MSWINDOWS}
  5266. function GetSwapFileSize: Int64;
  5267. {$IFDEF UNIX}
  5268. var
  5269. SystemInf: TSysInfo;
  5270. begin
  5271. {$IFDEF FPC}
  5272. SysInfo(@SystemInf);
  5273. {$ELSE ~FPC}
  5274. SysInfo(SystemInf);
  5275. {$ENDIF ~FPC}
  5276. Result := SystemInf.totalswap;
  5277. end;
  5278. {$ENDIF UNIX}
  5279. {$IFDEF MSWINDOWS}
  5280. var
  5281. MemoryStatusEx: TMemoryStatusEx;
  5282. begin
  5283. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5284. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5285. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5286. RaiseLastOSError;
  5287. Result := MemoryStatusEx.ullTotalPageFile - MemoryStatusEx.ullAvailPageFile;
  5288. end;
  5289. {$ENDIF MSWINDOWS}
  5290. function GetSwapFileUsage: Byte;
  5291. {$IFDEF UNIX}
  5292. var
  5293. SystemInf: TSysInfo;
  5294. begin
  5295. {$IFDEF FPC}
  5296. SysInfo(@SystemInf);
  5297. {$ELSE ~FPC}
  5298. SysInfo(SystemInf);
  5299. {$ENDIF ~FPC}
  5300. with SystemInf do
  5301. Result := 100 - Trunc(100 * FreeSwap / TotalSwap);
  5302. end;
  5303. {$ENDIF UNIX}
  5304. {$IFDEF MSWINDOWS}
  5305. var
  5306. MemoryStatusEx: TMemoryStatusEx;
  5307. begin
  5308. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5309. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5310. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5311. RaiseLastOSError;
  5312. if MemoryStatusEx.ullTotalPageFile > 0 then
  5313. Result := 100 - Trunc(MemoryStatusEx.ullAvailPageFile / MemoryStatusEx.ullTotalPageFile * 100)
  5314. else
  5315. Result := 0;
  5316. end;
  5317. {$ENDIF MSWINDOWS}
  5318. function GetTotalPhysicalMemory: Int64;
  5319. {$IFDEF UNIX}
  5320. var
  5321. SystemInf: TSysInfo;
  5322. begin
  5323. {$IFDEF FPC}
  5324. SysInfo(@SystemInf);
  5325. {$ELSE ~FPC}
  5326. SysInfo(SystemInf);
  5327. {$ENDIF ~FPC}
  5328. Result := SystemInf.totalram;
  5329. end;
  5330. {$ENDIF UNIX}
  5331. {$IFDEF MSWINDOWS}
  5332. var
  5333. MemoryStatusEx: TMemoryStatusEx;
  5334. begin
  5335. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5336. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5337. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5338. RaiseLastOSError;
  5339. Result := MemoryStatusEx.ullTotalPhys;
  5340. end;
  5341. {$ENDIF MSWINDOWS}
  5342. function GetFreePhysicalMemory: Int64;
  5343. {$IFDEF UNIX}
  5344. var
  5345. SystemInf: TSysInfo;
  5346. begin
  5347. {$IFDEF FPC}
  5348. SysInfo(@SystemInf);
  5349. {$ELSE ~FPC}
  5350. SysInfo(SystemInf);
  5351. {$ENDIF ~FPC}
  5352. Result := SystemInf.freeram;
  5353. end;
  5354. {$ENDIF UNIX}
  5355. {$IFDEF MSWINDOWS}
  5356. var
  5357. MemoryStatusEx: TMemoryStatusEx;
  5358. begin
  5359. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5360. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5361. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5362. RaiseLastOSError;
  5363. Result := MemoryStatusEx.ullAvailPhys;
  5364. end;
  5365. function GetTotalPageFileMemory: Int64;
  5366. var
  5367. MemoryStatusEx: TMemoryStatusEx;
  5368. begin
  5369. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5370. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5371. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5372. RaiseLastOSError;
  5373. Result := MemoryStatusEx.ullTotalPageFile;
  5374. end;
  5375. function GetFreePageFileMemory: Int64;
  5376. var
  5377. MemoryStatusEx: TMemoryStatusEx;
  5378. begin
  5379. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5380. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5381. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5382. RaiseLastOSError;
  5383. Result := MemoryStatusEx.ullAvailPageFile;
  5384. end;
  5385. function GetTotalVirtualMemory: Int64;
  5386. var
  5387. MemoryStatusEx: TMemoryStatusEx;
  5388. begin
  5389. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5390. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5391. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5392. RaiseLastOSError;
  5393. Result := MemoryStatusEx.ullTotalVirtual;
  5394. end;
  5395. function GetFreeVirtualMemory: Int64;
  5396. var
  5397. MemoryStatusEx: TMemoryStatusEx;
  5398. begin
  5399. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5400. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5401. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5402. RaiseLastOSError;
  5403. Result := MemoryStatusEx.ullAvailVirtual;
  5404. end;
  5405. //=== Keyboard Information ===================================================
  5406. function GetKeybStateHelper(VirtualKey: Cardinal; Mask: Byte): Boolean;
  5407. var
  5408. Keys: TKeyboardState;
  5409. begin
  5410. Keys[0] := 0;
  5411. Result := GetKeyBoardState(Keys) and (Keys[VirtualKey] and Mask <> 0);
  5412. end;
  5413. function GetKeyState(const VirtualKey: Cardinal): Boolean;
  5414. begin
  5415. Result := GetKeybStateHelper(VirtualKey, $80);
  5416. end;
  5417. function GetNumLockKeyState: Boolean;
  5418. begin
  5419. Result := GetKeybStateHelper(VK_NUMLOCK, $01);
  5420. end;
  5421. function GetScrollLockKeyState: Boolean;
  5422. begin
  5423. Result := GetKeybStateHelper(VK_SCROLL, $01);
  5424. end;
  5425. function GetCapsLockKeyState: Boolean;
  5426. begin
  5427. Result := GetKeybStateHelper(VK_CAPITAL, $01);
  5428. end;
  5429. //=== Windows 95/98/ME system resources information ==========================
  5430. { TODO -oPJH : compare to Win9xFreeSysResources }
  5431. var
  5432. ResmeterLibHandle: THandle;
  5433. MyGetFreeSystemResources: function(ResType: UINT): UINT; stdcall;
  5434. procedure UnloadSystemResourcesMeterLib;
  5435. begin
  5436. if ResmeterLibHandle <> 0 then
  5437. begin
  5438. FreeLibrary(ResmeterLibHandle);
  5439. ResmeterLibHandle := 0;
  5440. @MyGetFreeSystemResources := nil;
  5441. end;
  5442. end;
  5443. function IsSystemResourcesMeterPresent: Boolean;
  5444. procedure LoadResmeter;
  5445. begin
  5446. ResmeterLibHandle := SafeLoadLibrary('rsrc32.dll', SEM_FAILCRITICALERRORS);
  5447. if ResmeterLibHandle <> 0 then
  5448. begin
  5449. @MyGetFreeSystemResources := GetProcAddress(ResmeterLibHandle, PAnsiChar('_MyGetFreeSystemResources32@4'));
  5450. if not Assigned(MyGetFreeSystemResources) then
  5451. UnloadSystemResourcesMeterLib;
  5452. end;
  5453. end;
  5454. begin
  5455. if not IsWinNT and (ResmeterLibHandle = 0) then
  5456. LoadResmeter;
  5457. Result := (ResmeterLibHandle <> 0);
  5458. end;
  5459. function GetFreeSystemResources(const ResourceType: TFreeSysResKind): Integer;
  5460. const
  5461. ParamValues: array [TFreeSysResKind] of UINT = (0, 1, 2);
  5462. begin
  5463. if IsSystemResourcesMeterPresent then
  5464. Result := MyGetFreeSystemResources(ParamValues[ResourceType])
  5465. else
  5466. Result := -1;
  5467. end;
  5468. function GetFreeSystemResources: TFreeSystemResources;
  5469. begin
  5470. with Result do
  5471. begin
  5472. SystemRes := GetFreeSystemResources(rtSystem);
  5473. GdiRes := GetFreeSystemResources(rtGdi);
  5474. UserRes := GetFreeSystemResources(rtUser);
  5475. end;
  5476. end;
  5477. function GetBPP: Cardinal;
  5478. var
  5479. DC: HDC;
  5480. begin
  5481. DC := GetDC(HWND_DESKTOP);
  5482. if DC <> 0 then
  5483. begin
  5484. Result := GetDeviceCaps(DC, BITSPIXEL) * GetDeviceCaps(DC, PLANES);
  5485. ReleaseDC(HWND_DESKTOP, DC);
  5486. end
  5487. else
  5488. Result := 0;
  5489. end;
  5490. //=== Installed programs =====================================================
  5491. function ProgIDExists(const ProgID: string): Boolean;
  5492. var
  5493. Tmp: TGUID;
  5494. WideProgID: WideString;
  5495. begin
  5496. WideProgID := ProgID;
  5497. Result := Succeeded(CLSIDFromProgID(PWideChar(WideProgID), Tmp));
  5498. end;
  5499. function IsWordInstalled: Boolean;
  5500. begin
  5501. Result := ProgIDExists('Word.Application');
  5502. end;
  5503. function IsExcelInstalled: Boolean;
  5504. begin
  5505. Result := ProgIDExists('Excel.Application');
  5506. end;
  5507. function IsAccessInstalled: Boolean;
  5508. begin
  5509. Result := ProgIDExists('Access.Application');
  5510. end;
  5511. function IsPowerPointInstalled: Boolean;
  5512. begin
  5513. Result := ProgIDExists('PowerPoint.Application');
  5514. end;
  5515. function IsFrontPageInstalled: Boolean;
  5516. begin
  5517. Result := ProgIDExists('FrontPage.Application');
  5518. end;
  5519. function IsOutlookInstalled: Boolean;
  5520. begin
  5521. Result := ProgIDExists('Outlook.Application');
  5522. end;
  5523. function IsInternetExplorerInstalled: Boolean;
  5524. begin
  5525. Result := ProgIDExists('InternetExplorer.Application');
  5526. end;
  5527. function IsMSProjectInstalled: Boolean;
  5528. begin
  5529. Result := ProgIDExists('MSProject.Application');
  5530. end;
  5531. function IsOpenOfficeInstalled: Boolean;
  5532. begin
  5533. Result := ProgIDExists('com.sun.star.ServiceManager');
  5534. end;
  5535. function IsLibreOfficeInstalled: Boolean;
  5536. begin
  5537. Result := ProgIDExists('com.sun.star.ServiceManager.1');
  5538. end;
  5539. //=== Initialization/Finalization ============================================
  5540. procedure InitSysInfo;
  5541. var
  5542. SystemInfo: TSystemInfo;
  5543. Kernel32FileName: string;
  5544. VerFixedFileInfo: TVSFixedFileInfo;
  5545. begin
  5546. { processor information related initialization }
  5547. ResetMemory(SystemInfo, SizeOf(SystemInfo));
  5548. GetSystemInfo(SystemInfo);
  5549. ProcessorCount := SystemInfo.dwNumberOfProcessors;
  5550. AllocGranularity := SystemInfo.dwAllocationGranularity;
  5551. PageSize := SystemInfo.dwPageSize;
  5552. { Windows version information }
  5553. IsWinNT := Win32Platform = VER_PLATFORM_WIN32_NT;
  5554. Kernel32FileName := GetModulePath(GetModuleHandle(kernel32));
  5555. VerFixedFileInfo.dwFileDateLS := 0;
  5556. if (not IsWinNT) and VersionFixedFileInfo(Kernel32FileName, VerFixedFileInfo) then
  5557. KernelVersionHi := VerFixedFileInfo.dwProductVersionMS
  5558. else
  5559. KernelVersionHi := 0;
  5560. case GetWindowsVersion of
  5561. wvUnknown:
  5562. ;
  5563. wvWin95:
  5564. IsWin95 := True;
  5565. wvWin95OSR2:
  5566. IsWin95OSR2 := True;
  5567. wvWin98:
  5568. IsWin98 := True;
  5569. wvWin98SE:
  5570. IsWin98SE := True;
  5571. wvWinME:
  5572. IsWinME := True;
  5573. wvWinNT31:
  5574. begin
  5575. IsWinNT3 := True;
  5576. IsWinNT31 := True;
  5577. end;
  5578. wvWinNT35:
  5579. begin
  5580. IsWinNT3 := True;
  5581. IsWinNT35 := True;
  5582. end;
  5583. wvWinNT351:
  5584. begin
  5585. IsWinNT3 := True;
  5586. IsWinNT35 := True;
  5587. IsWinNT351 := True;
  5588. end;
  5589. wvWinNT4:
  5590. IsWinNT4 := True;
  5591. wvWin2000:
  5592. IsWin2K := True;
  5593. wvWinXP:
  5594. IsWinXP := True;
  5595. wvWin2003:
  5596. IsWin2003 := True;
  5597. wvWinXP64:
  5598. IsWinXP64 := True;
  5599. wvWin2003R2:
  5600. IsWin2003R2 := True;
  5601. wvWinVista:
  5602. IsWinVista := True;
  5603. wvWinServer2008:
  5604. IsWinServer2008 := True;
  5605. wvWin7:
  5606. IsWin7 := True;
  5607. wvWinServer2008R2:
  5608. IsWinServer2008R2 := True;
  5609. wvWin8:
  5610. IsWin8 := True;
  5611. wvWin8RT:
  5612. IsWin8RT := True;
  5613. wvWinServer2012:
  5614. IsWinServer2012 := True;
  5615. wvWin81:
  5616. IsWin81 := True;
  5617. wvWin81RT:
  5618. IsWin81RT := True;
  5619. wvWinServer2012R2:
  5620. IsWinServer2012R2 := True;
  5621. wvWin10:
  5622. IsWin10 := True;
  5623. wvWinServer2016:
  5624. IsWinServer2016 := True;
  5625. end;
  5626. end;
  5627. procedure FinalizeSysInfo;
  5628. begin
  5629. UnloadSystemResourcesMeterLib;
  5630. end;
  5631. initialization
  5632. InitSysInfo;
  5633. {$IFDEF UNITVERSIONING}
  5634. RegisterUnitVersion(HInstance, UnitVersioning);
  5635. {$ENDIF UNITVERSIONING}
  5636. finalization
  5637. {$IFDEF UNITVERSIONING}
  5638. UnregisterUnitVersion(HInstance);
  5639. {$ENDIF UNITVERSIONING}
  5640. FinalizeSysInfo;
  5641. {$ENDIF MSWINDOWS}
  5642. end.