JclSysInfo.pas 220 KB

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