JclSysInfo.pas 238 KB

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