JclSysInfo.pas 238 KB

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