-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJclRegistry.pas
More file actions
2156 lines (1969 loc) · 75 KB
/
Copy pathJclRegistry.pas
File metadata and controls
2156 lines (1969 loc) · 75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{**************************************************************************************************}
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the }
{ License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
{ ANY KIND, either express or implied. See the License for the specific language governing rights }
{ and limitations under the License. }
{ }
{ The Original Code is JclRegistry.pas. }
{ }
{ The Initial Developers of the Original Code are John C Molyneux, Marcel van Brakel and }
{ Charlie Calvert. Portions created by these individuals are Copyright (C) of these individuals. }
{ All Rights Reserved. }
{ }
{ Contributors: }
{ Marcel van Brakel }
{ Stephane Fillon }
{ Eric S.Fisher }
{ Peter Friese }
{ Andreas Hausladen (ahuser) }
{ Manlio Laschena (manlio) }
{ Robert Marquardt (marquardt) }
{ Robert Rossmair (rrossmair) }
{ Olivier Sannier (obones) }
{ Petr Vones (pvones) }
{ kogerbnz }
{ }
{**************************************************************************************************}
{ }
{ Contains various utility routines to read and write registry values. Using these routines }
{ prevents you from having to instantiate temporary TRegistry objects and since the routines }
{ directly call the registry API they do not suffer from the resource overhead as TRegistry does. }
{ }
{**************************************************************************************************}
{ }
{ Last modified: $Date:: $ }
{ Revision: $Rev:: $ }
{ Author: $Author:: $ }
{ }
{**************************************************************************************************}
unit JclRegistry;
{$I jcl.inc}
{$I windowsonly.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$IFDEF HAS_UNITSCOPE}
Winapi.Windows, System.Classes,
{$ELSE ~HAS_UNITSCOPE}
Windows, Classes,
{$ENDIF ~HAS_UNITSCOPE}
JclBase, JclStrings;
type
DelphiHKEY = {$IFDEF CPUX64}type Winapi.Windows.HKEY{$ELSE}Longword{$ENDIF CPUX64};
{$HPPEMIT '// BCB users must typecast the HKEY values to DelphiHKEY or use the HK-values below.'}
TExecKind = (ekMachineRun, ekMachineRunOnce, ekUserRun, ekUserRunOnce,
ekServiceRun, ekServiceRunOnce);
EJclRegistryError = class(EJclError);
{$IFDEF FPC}
const
HKCR = DelphiHKEY($80000000);
HKCU = DelphiHKEY($80000001);
HKLM = DelphiHKEY($80000002);
HKUS = DelphiHKEY($80000003);
HKPD = DelphiHKEY($80000004);
HKCC = DelphiHKEY($80000005);
HKDD = DelphiHKEY($80000006);
{$ELSE ~FPC}
const
HKCR = DelphiHKEY(HKEY_CLASSES_ROOT);
HKCU = DelphiHKEY(HKEY_CURRENT_USER);
HKLM = DelphiHKEY(HKEY_LOCAL_MACHINE);
HKUS = DelphiHKEY(HKEY_USERS);
HKPD = DelphiHKEY(HKEY_PERFORMANCE_DATA);
HKCC = DelphiHKEY(HKEY_CURRENT_CONFIG);
HKDD = DelphiHKEY(HKEY_DYN_DATA);
{$IFDEF CPU64}
{$NODEFINE DelphiHKEY}
{$NODEFINE HKCR}
{$NODEFINE HKCU}
{$NODEFINE HKLM}
{$NODEFINE HKUS}
{$NODEFINE HKPD}
{$NODEFINE HKCC}
{$NODEFINE HKDD}
{$HPPEMIT 'typedef HKEY DelphiHKEY;'}
{$HPPEMIT 'static const DelphiHKEY HKCR = HKEY_CLASSES_ROOT;'}
{$HPPEMIT 'static const DelphiHKEY HKCU = HKEY_CURRENT_USER;'}
{$HPPEMIT 'static const DelphiHKEY HKLM = HKEY_LOCAL_MACHINE;'}
{$HPPEMIT 'static const DelphiHKEY HKUS = HKEY_USERS;'}
{$HPPEMIT 'static const DelphiHKEY HKPD = HKEY_PERFORMANCE_DATA;'}
{$HPPEMIT 'static const DelphiHKEY HKCC = HKEY_CURRENT_CONFIG;'}
{$HPPEMIT 'static const DelphiHKEY HKDD = HKEY_DYN_DATA;'}
{$ENDIF CPU64}
{$ENDIF FPC}
function RootKeyName(const RootKey: THandle): string;
function RootKeyValue(const Name: string): THandle;
const
RegKeyDelimiter = '\';
function RegCreateKey(const RootKey: DelphiHKEY; const Key: string): Longint; overload;
function RegCreateKey(const RootKey: DelphiHKEY; const Key, Value: string): Longint; overload;
function RegDeleteEntry(const RootKey: DelphiHKEY; const Key, Name: string): Boolean;
function RegDeleteKeyTree(const RootKey: DelphiHKEY; const Key: string): Boolean;
function RegGetDataSize(const RootKey: DelphiHKEY; const Key, Name: string;
out DataSize: Cardinal): Boolean;
function RegGetDataType(const RootKey: DelphiHKEY; const Key, Name: string;
out DataType: Cardinal): Boolean;
function RegReadBool(const RootKey: DelphiHKEY; const Key, Name: string): Boolean;
function RegReadBoolDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: Boolean): Boolean;
function RegReadIntegerEx(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: Integer; RaiseException: Boolean = False): Boolean;
function RegReadInteger(const RootKey: DelphiHKEY; const Key, Name: string): Integer;
function RegReadIntegerDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: Integer): Integer;
function RegReadCardinalEx(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: Cardinal; RaiseException: Boolean = False): Boolean;
function RegReadCardinal(const RootKey: DelphiHKEY; const Key, Name: string): Cardinal;
function RegReadCardinalDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: Cardinal): Cardinal;
function RegReadDWORDEx(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: DWORD; RaiseException: Boolean = False): Boolean;
function RegReadDWORD(const RootKey: DelphiHKEY; const Key, Name: string): DWORD;
function RegReadDWORDDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: DWORD): DWORD;
function RegReadInt64Ex(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: Int64; RaiseException: Boolean = False): Boolean;
function RegReadInt64(const RootKey: DelphiHKEY; const Key, Name: string): Int64;
function RegReadInt64Def(const RootKey: DelphiHKEY; const Key, Name: string; Def: Int64): Int64;
function RegReadUInt64Ex(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: UInt64; RaiseException: Boolean = False): Boolean;
function RegReadUInt64(const RootKey: DelphiHKEY; const Key, Name: string): UInt64;
function RegReadUInt64Def(const RootKey: DelphiHKEY; const Key, Name: string; Def: UInt64): UInt64;
function RegReadSingleEx(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: Single; RaiseException: Boolean = False): Boolean;
function RegReadSingle(const RootKey: DelphiHKEY; const Key, Name: string): Single;
function RegReadSingleDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: Single): Single;
function RegReadDoubleEx(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: Double; RaiseException: Boolean = False): Boolean;
function RegReadDouble(const RootKey: DelphiHKEY; const Key, Name: string): Double;
function RegReadDoubleDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: Double): Double;
function RegReadExtendedEx(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: Extended; RaiseException: Boolean = False): Boolean;
function RegReadExtended(const RootKey: DelphiHKEY; const Key, Name: string): Extended;
function RegReadExtendedDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: Extended): Extended;
function RegReadStringEx(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: string; RaiseException: Boolean = False): Boolean;
function RegReadString(const RootKey: DelphiHKEY; const Key, Name: string): string;
function RegReadStringDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: string): string;
function RegReadAnsiStringEx(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: AnsiString; RaiseException: Boolean = False): Boolean;
function RegReadAnsiString(const RootKey: DelphiHKEY; const Key, Name: string): AnsiString;
function RegReadAnsiStringDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: AnsiString): AnsiString;
function RegReadWideStringEx(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: WideString; RaiseException: Boolean = False): Boolean;
function RegReadWideString(const RootKey: DelphiHKEY; const Key, Name: string): WideString;
function RegReadWideStringDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: WideString): WideString;
function RegReadMultiSzEx(const RootKey: DelphiHKEY; const Key, Name: string; Value: TStrings;
RaiseException: Boolean = False): Boolean; overload;
function RegReadMultiSzEx(const RootKey: DelphiHKEY; const Key, Name: string; out RetValue: PMultiSz;
RaiseException: Boolean = False): Boolean; overload;
procedure RegReadMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; Value: TStrings); overload;
function RegReadMultiSz(const RootKey: DelphiHKEY; const Key, Name: string): PMultiSz; overload;
procedure RegReadMultiSzDef(const RootKey: DelphiHKEY; const Key, Name: string; Value, Def: TStrings); overload;
function RegReadMultiSzDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: PMultiSz): PMultiSz; overload;
function RegReadAnsiMultiSzEx(const RootKey: DelphiHKEY; const Key, Name: string; Value: TAnsiStrings;
RaiseException: Boolean = False): Boolean; overload;
function RegReadAnsiMultiSzEx(const RootKey: DelphiHKEY; const Key, Name: string; out RetValue: PAnsiMultiSz;
RaiseException: Boolean = False): Boolean; overload;
procedure RegReadAnsiMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; Value: TAnsiStrings); overload;
function RegReadAnsiMultiSz(const RootKey: DelphiHKEY; const Key, Name: string): PAnsiMultiSz; overload;
procedure RegReadAnsiMultiSzDef(const RootKey: DelphiHKEY; const Key, Name: string;
Value, Def: TAnsiStrings); overload;
function RegReadAnsiMultiSzDef(const RootKey: DelphiHKEY; const Key, Name: string;
Def: PAnsiMultiSz): PAnsiMultiSz; overload;
function RegReadWideMultiSzEx(const RootKey: DelphiHKEY; const Key, Name: string; Value: TWideStrings;
RaiseException: Boolean = False): Boolean; overload;
function RegReadWideMultiSzEx(const RootKey: DelphiHKEY; const Key, Name: string; out RetValue: PWideMultiSz;
RaiseException: Boolean = False): Boolean; overload;
procedure RegReadWideMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; Value: TWideStrings); overload;
function RegReadWideMultiSz(const RootKey: DelphiHKEY; const Key, Name: string): PWideMultiSz; overload;
procedure RegReadWideMultiSzDef(const RootKey: DelphiHKEY; const Key, Name: string;
Value, Def: TWideStrings); overload;
function RegReadWideMultiSzDef(const RootKey: DelphiHKEY; const Key, Name: string;
Def: PWideMultiSz): PWideMultiSz; overload;
function RegReadBinaryEx(const RootKey: DelphiHKEY; const Key, Name: string; var Value; const ValueSize: Cardinal;
out DataSize: Cardinal; RaiseException: Boolean = False): Boolean;
function RegReadBinary(const RootKey: DelphiHKEY; const Key, Name: string;
var Value; const ValueSize: Cardinal): Cardinal;
function RegReadBinaryDef(const RootKey: DelphiHKEY; const Key, Name: string;
var Value; const ValueSize: Cardinal; const Def: Byte): Cardinal;
procedure RegWriteBool(const RootKey: DelphiHKEY; const Key, Name: string; Value: Boolean); overload;
procedure RegWriteBool(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: Boolean); overload;
procedure RegWriteInteger(const RootKey: DelphiHKEY; const Key, Name: string; Value: Integer); overload;
procedure RegWriteInteger(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: Integer); overload;
procedure RegWriteCardinal(const RootKey: DelphiHKEY; const Key, Name: string; Value: Cardinal); overload;
procedure RegWriteCardinal(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: Cardinal); overload;
procedure RegWriteDWORD(const RootKey: DelphiHKEY; const Key, Name: string; Value: DWORD); overload;
procedure RegWriteDWORD(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: DWORD); overload;
procedure RegWriteInt64(const RootKey: DelphiHKEY; const Key, Name: string; Value: Int64); overload;
procedure RegWriteInt64(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: Int64); overload;
procedure RegWriteUInt64(const RootKey: DelphiHKEY; const Key, Name: string; Value: UInt64); overload;
procedure RegWriteUInt64(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: UInt64); overload;
procedure RegWriteSingle(const RootKey: DelphiHKEY; const Key, Name: string; Value: Single); overload;
procedure RegWriteSingle(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: Single); overload;
procedure RegWriteDouble(const RootKey: DelphiHKEY; const Key, Name: string; Value: Double); overload;
procedure RegWriteDouble(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: Double); overload;
procedure RegWriteExtended(const RootKey: DelphiHKEY; const Key, Name: string; Value: Extended); overload;
procedure RegWriteExtended(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: Extended); overload;
procedure RegWriteString(const RootKey: DelphiHKEY; const Key, Name, Value: string); overload;
procedure RegWriteString(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
const Value: string); overload;
procedure RegWriteAnsiString(const RootKey: DelphiHKEY; const Key, Name: string; const Value: AnsiString); overload;
procedure RegWriteAnsiString(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
const Value: AnsiString); overload;
procedure RegWriteWideString(const RootKey: DelphiHKEY; const Key, Name: string; const Value: WideString); overload;
procedure RegWriteWideString(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
const Value: WideString); overload;
procedure RegWriteMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; Value: PMultiSz); overload;
procedure RegWriteMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; const Value: TStrings); overload;
procedure RegWriteMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: PMultiSz); overload;
procedure RegWriteMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
const Value: TStrings); overload;
procedure RegWriteAnsiMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; Value: PAnsiMultiSz); overload;
procedure RegWriteAnsiMultiSz(const RootKey: DelphiHKEY; const Key, Name: string;
const Value: TAnsiStrings); overload;
procedure RegWriteAnsiMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: PAnsiMultiSz); overload;
procedure RegWriteAnsiMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
const Value: TAnsiStrings); overload;
procedure RegWriteWideMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; Value: PWideMultiSz); overload;
procedure RegWriteWideMultiSz(const RootKey: DelphiHKEY; const Key, Name: string;
const Value: TWideStrings); overload;
procedure RegWriteWideMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
Value: PWideMultiSz); overload;
procedure RegWriteWideMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal;
const Value: TWideStrings); overload;
procedure RegWriteBinary(const RootKey: DelphiHKEY; const Key, Name: string; const Value; const ValueSize: Cardinal);
function RegGetValueNames(const RootKey: DelphiHKEY; const Key: string; const List: TStrings): Boolean;
function RegGetKeyNames(const RootKey: DelphiHKEY; const Key: string; const List: TStrings): Boolean;
function RegGetValueNamesAndValues(const RootKey: HKEY; const Key: string; const List: TStrings): Boolean;
function RegHasSubKeys(const RootKey: DelphiHKEY; const Key: string): Boolean;
function AllowRegKeyForEveryone(const RootKey: DelphiHKEY; Path: string): Boolean;
function RegAutoExecEnabled(const ExecKind: TExecKind; const Name: string; out CmdLine: string): Boolean;
{
From: Jean-Fabien Connault [cycocrew att worldnet dott fr]
Descr: Test whether a registry key exists as a subkey of RootKey
Used test cases:
procedure TForm1.Button1Click(Sender: TObject);
var
RegKey: HKEY;
begin
if RegOpenKeyEx(HKEY_CURRENT_USER, 'Software', 0, KEY_READ, RegKey) = ERROR_SUCCESS then
begin
Assert(not RegKeyExists(RegKey, 'Microsoft\_Windows'));
RegCloseKey(RegKey);
end;
if RegOpenKeyEx(HKEY_CURRENT_USER, 'Software', 0, KEY_READ, RegKey) = ERROR_SUCCESS then
begin
Assert(RegKeyExists(RegKey, 'Microsoft\Windows'));;
RegCloseKey(RegKey);
end;
Assert(RegKeyExists(HKEY_CURRENT_USER, ''));
Assert(RegKeyExists(HKEY_CURRENT_USER, 'Software'));
Assert(RegKeyExists(HKEY_CURRENT_USER, 'Software\Microsoft'));
Assert(RegKeyExists(HKEY_CURRENT_USER, 'Software\Microsoft\Windows'));
Assert(RegKeyExists(HKEY_CURRENT_USER, '\Software\Microsoft\Windows'));
Assert(not RegKeyExists(HKEY_CURRENT_USER, '\Software\Microsoft2\Windows'));
end;
}
function RegKeyExists(const RootKey: DelphiHKEY; const Key: string): Boolean;
function RegValueExists(const RootKey: DelphiHKEY; const Key, Name: string): Boolean;
function UnregisterAutoExec(ExecKind: TExecKind; const Name: string): Boolean;
function RegisterAutoExec(ExecKind: TExecKind; const Name, Cmdline: string): Boolean;
function RegSaveList(const RootKey: DelphiHKEY; const Key: string; const ListName: string;
const Items: TStrings): Boolean;
function RegLoadList(const RootKey: DelphiHKEY; const Key: string; const ListName: string;
const SaveTo: TStrings): Boolean;
function RegDelList(const RootKey: DelphiHKEY; const Key: string; const ListName: string): Boolean;
const
HKCRLongName = 'HKEY_CLASSES_ROOT';
HKCULongName = 'HKEY_CURRENT_USER';
HKLMLongName = 'HKEY_LOCAL_MACHINE';
HKUSLongName = 'HKEY_USERS';
HKPDLongName = 'HKEY_PERFORMANCE_DATA';
HKCCLongName = 'HKEY_CURRENT_CONFIG';
HKDDLongName = 'HKEY_DYN_DATA';
HKCRShortName = 'HKCR';
HKCUShortName = 'HKCU';
HKLMShortName = 'HKLM';
HKUSShortName = 'HKUS';
HKPDShortName = 'HKPD';
HKCCShortName = 'HKCC';
HKDDShortName = 'HKDD';
type
TRootKey = record
Key: DelphiHKEY;
AnsiName: AnsiString;
WideName: TUTF16String;
end;
const
RootKeys: array [0..13] of TRootKey =
(
(Key: HKCR; AnsiName: HKCRLongName; WideName: HKCRLongName),
(Key: HKCU; AnsiName: HKCULongName; WideName: HKCULongName),
(Key: HKLM; AnsiName: HKLMLongName; WideName: HKLMLongName),
(Key: HKUS; AnsiName: HKUSLongName; WideName: HKUSLongName),
(Key: HKPD; AnsiName: HKPDLongName; WideName: HKPDLongName),
(Key: HKCC; AnsiName: HKCCLongName; WideName: HKCCLongName),
(Key: HKDD; AnsiName: HKDDLongName; WideName: HKDDLongName),
(Key: HKCR; AnsiName: HKCRShortName; WideName: HKCRShortName),
(Key: HKCU; AnsiName: HKCUShortName; WideName: HKCUShortName),
(Key: HKLM; AnsiName: HKLMShortName; WideName: HKLMShortName),
(Key: HKUS; AnsiName: HKUSShortName; WideName: HKUSShortName),
(Key: HKPD; AnsiName: HKPDShortName; WideName: HKPDShortName),
(Key: HKCC; AnsiName: HKCCShortName; WideName: HKCCShortName),
(Key: HKDD; AnsiName: HKDDShortName; WideName: HKDDShortName)
);
type
{ clRegWOW64Access allows the user to switch all registry functions to the 64 bit registry
key on a 64bit system.
OS/Application 32bit/32bit 64bit/32bit 64bit/64bit
raDefault Software Wow6432Node Software
raNative Software Software Software
ra32Key Software Wow6432Node Wow6432Node
ra64Key Software Software Software
}
TJclRegWOW64Access = (raDefault, raNative, ra32Key, ra64Key);
// cannot access variable JclRegWOW64Access from outside package
// so these helper functions can be used.
function RegGetWOW64AccessMode: TJclRegWOW64Access;
procedure RegSetWOW64AccessMode(Access: TJclRegWOW64Access);
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$URL$';
Revision: '$Revision$';
Date: '$Date$';
LogPath: 'JCL\source\windows';
Extra: '';
Data: nil
);
{$ENDIF UNITVERSIONING}
implementation
uses
{$IFDEF HAS_UNITSCOPE}
System.SysUtils,
Winapi.AccCtrl,
{$ELSE ~HAS_UNITSCOPE}
SysUtils,
AccCtrl,
{$ENDIF ~HAS_UNITSCOPE}
{$IFDEF FPC}
// JwaAccCtrl,
{$ELSE ~FPC}
JclSysUtils,
{$ENDIF ~FPC}
JclResources, JclWin32, JclSysInfo,
JclAnsiStrings, JclWideStrings;
type
TRegKind = REG_NONE..REG_QWORD;
TRegKinds = set of TRegKind;
const
cItems = 'Items';
cRegBinKinds = [REG_SZ..REG_QWORD]; // all types
var
CachedIsWindows64: Integer = -1;
threadvar
JclRegWOW64Access: TJclRegWOW64Access {= raDefault};
function RegGetWOW64AccessMode: TJclRegWOW64Access;
begin
Result := JclRegWOW64Access;
end;
procedure RegSetWOW64AccessMode(Access: TJclRegWOW64Access);
begin
JclRegWOW64Access := Access;
end;
//=== Internal helper routines ===============================================
function GetWOW64AccessMode(samDesired: REGSAM): REGSAM;
const
KEY_WOW64_32KEY = $0200;
KEY_WOW64_64KEY = $0100;
KEY_WOW64_RES = $0300;
RegWOW64Accesses: array[Boolean, TJclRegWOW64Access] of HKEY = (
(HKEY(0), HKEY(0), HKEY(0), HKEY(0)),
(HKEY(0), KEY_WOW64_64KEY, KEY_WOW64_32KEY, KEY_WOW64_64KEY)
);
begin
Result := samDesired;
if (Win32Platform = VER_PLATFORM_WIN32_NT) and (samDesired and KEY_WOW64_RES = 0) then
begin
if CachedIsWindows64 = -1 then
if IsWindows64 then
CachedIsWindows64 := 1
else
CachedIsWindows64 := 0;
Result := Result or RegWOW64Accesses[CachedIsWindows64 = 1, JclRegWOW64Access];
end;
end;
function RootKeyName(const RootKey: THandle): string;
begin
case RootKey of
{$IFDEF DELPHI64_TEMPORARY}
Integer(HKCR) : Result := HKCRLongName;
Integer(HKCU) : Result := HKCULongName;
Integer(HKLM) : Result := HKLMLongName;
Integer(HKUS) : Result := HKUSLongName;
Integer(HKPD) : Result := HKPDLongName;
Integer(HKCC) : Result := HKCCLongName;
Integer(HKDD) : Result := HKDDLongName;
{$ELSE ~DELPHI64_TEMPORARY}
HKCR : Result := HKCRLongName;
HKCU : Result := HKCULongName;
HKLM : Result := HKLMLongName;
HKUS : Result := HKUSLongName;
HKPD : Result := HKPDLongName;
HKCC : Result := HKCCLongName;
HKDD : Result := HKDDLongName;
{$ENDIF ~DELPHI64_TEMPORARY}
else
Result := Format(HexFmt, [RootKey]);
end;
end;
function RootKeyValue(const Name: string): THandle;
var
Index: Integer;
begin
for Index := Low(RootKeys) to High(RootKeys) do
if string(RootKeys[Index].AnsiName) = Name then
begin
Result := RootKeys[Index].Key;
Exit;
end;
raise EJclRegistryError.CreateResFmt(@RsInconsistentPath, [Name]);
end;
procedure ReadError(const RootKey: THandle; const Key: string);
begin
raise EJclRegistryError.CreateResFmt(@RsUnableToOpenKeyRead, [RootKeyName(RootKey), Key]);
end;
procedure WriteError(const RootKey: THandle; const Key: string);
begin
raise EJclRegistryError.CreateResFmt(@RsUnableToOpenKeyWrite, [RootKeyName(RootKey), Key]);
end;
procedure ValueError(const RootKey: THandle; const Key, Name: string);
begin
raise EJclRegistryError.CreateResFmt(@RsUnableToAccessValue, [RootKeyName(RootKey), Key, Name]);
end;
procedure DataError(const RootKey: THandle; const Key, Name: string);
begin
raise EJclRegistryError.CreateResFmt(@RsWrongDataType, [RootKeyName(RootKey), Key, Name]);
end;
function GetKeyAndPath(ExecKind: TExecKind; out Key: HKEY; out RegPath: string): Boolean;
begin
Result := False;
if (ExecKind in [ekServiceRun, ekServiceRunOnce]) and (Win32Platform = VER_PLATFORM_WIN32_NT) then
Exit;
if ExecKind in [ekMachineRun, ekMachineRunOnce, ekServiceRun, ekServiceRunOnce] then
Key := HKEY_LOCAL_MACHINE
else
Key := HKEY_CURRENT_USER;
RegPath := 'Software\Microsoft\Windows\CurrentVersion\';
case ExecKind of
ekMachineRun, ekUserRun:
RegPath := RegPath + 'Run';
ekMachineRunOnce, ekUserRunOnce:
RegPath := RegPath + 'RunOnce';
ekServiceRun:
RegPath := RegPath + 'RunServices';
ekServiceRunOnce:
RegPath := RegPath + 'RunServicesOnce';
end;
Result := True;
end;
function RelativeKey(const RootKey: DelphiHKEY; Key: PAnsiChar): PAnsiChar; overload;
var
I: Integer;
begin
Result := Key;
if Result^ = RegKeyDelimiter then
Inc(Result);
for I := Low(RootKeys) to High(RootKeys) do
if StrPosA(Key, PAnsiChar(RootKeys[I].AnsiName + RegKeyDelimiter)) = Result then
begin
if RootKey <> RootKeys[I].Key then
raise EJclRegistryError.CreateResFmt(@RsInconsistentPath, [Key])
else
Inc(Result, Length(RootKeys[I].AnsiName));
Break;
end;
end;
function RelativeKey(const RootKey: DelphiHKEY; Key: PWideChar): PWideChar; overload;
var
I: Integer;
begin
Result := Key;
if Result^ = RegKeyDelimiter then
Inc(Result);
for I := Low(RootKeys) to High(RootKeys) do
if StrPosW(Key, PWideChar(RootKeys[I].WideName + RegKeyDelimiter)) = Result then
begin
if RootKey <> RootKeys[I].Key then
raise EJclRegistryError.CreateResFmt(@RsInconsistentPath, [Key])
else
Inc(Result, Length(RootKeys[I].WideName));
Break;
end;
end;
function InternalRegOpenKeyEx(Key: HKEY; SubKey: PWideChar;
ulOptions: DWORD; samDesired: REGSAM; var RegKey: HKEY): Longint; overload;
var
RelKey: AnsiString;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
Result := RegOpenKeyExW(Key, RelativeKey(Key, SubKey), ulOptions, GetWOW64AccessMode(samDesired), RegKey)
else
begin
RelKey := AnsiString(WideString(RelativeKey(Key, SubKey)));
Result := RegOpenKeyExA(Key, PAnsiChar(RelKey), ulOptions, samDesired, RegKey);
end;
end;
function InternalRegOpenKeyEx(Key: HKEY; SubKey: PAnsiChar;
ulOptions: DWORD; samDesired: REGSAM; var RegKey: HKEY): Longint; overload;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
Result := RegOpenKeyExA(Key, RelativeKey(Key, SubKey), ulOptions, GetWOW64AccessMode(samDesired), RegKey)
else
Result := RegOpenKeyExA(Key, RelativeKey(Key, SubKey), ulOptions, samDesired, RegKey);
end;
function InternalRegQueryValueEx(Key: HKEY; ValueName: PWideChar;
lpReserved: Pointer; lpType: PDWORD; lpData: Pointer; lpcbData: PDWORD): Longint;
var
ValName: AnsiString;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
Result := RegQueryValueExW(Key, ValueName, lpReserved, lpType, lpData, lpcbData)
else
begin
ValName := AnsiString(WideString(ValueName));
Result := RegQueryValueExA(Key, PAnsiChar(ValName), lpReserved, lpType, lpData, lpcbData);
end;
end;
function InternalRegSetValueEx(Key: HKEY; ValueName: PWideChar;
Reserved: DWORD; dwType: DWORD; lpData: Pointer; cbData: DWORD): Longint; stdcall;
var
ValName: AnsiString;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
Result := RegSetValueExW(Key, ValueName, Reserved, dwType, lpData, cbData)
else
begin
ValName := AnsiString(WideString(ValueName));
Result := RegSetValueExA(Key, PAnsiChar(ValName), Reserved, dwType, lpData, cbData);
end;
end;
function InternalGetData(const RootKey: DelphiHKEY; const Key, Name: TUTF16String;
RegKinds: TRegKinds; ExpectedSize: DWORD;
out DataType: DWORD; Data: Pointer; out DataSize: DWORD; RaiseException: Boolean): Boolean;
var
RegKey: HKEY;
begin
Result := True;
DataType := REG_NONE;
DataSize := 0;
RegKey := 0;
if InternalRegOpenKeyEx(RootKey, PWideChar(Key), 0, KEY_READ, RegKey) = ERROR_SUCCESS then
try
if InternalRegQueryValueEx(RegKey, PWideChar(Name), nil, @DataType, nil, @DataSize) = ERROR_SUCCESS then
begin
if not (DataType in RegKinds) or (DataSize > ExpectedSize) then
if RaiseException then
DataError(RootKey, Key, Name)
else
Result := False;
if InternalRegQueryValueEx(RegKey, PWideChar(Name), nil, nil, Data, @DataSize) <> ERROR_SUCCESS then
if RaiseException then
ValueError(RootKey, Key, Name)
else
Result := False;
end
else
if RaiseException then
ValueError(RootKey, Key, Name)
else
Result := False;
finally
RegCloseKey(RegKey);
end
else
if RaiseException then
ReadError(RootKey, Key)
else
Result := False;
end;
function InternalGetAnsiString(const RootKey: DelphiHKEY; const Key, Name: WideString; MultiFlag: Boolean;
out RetValue: AnsiString; RaiseException: Boolean): Boolean;
var
RegKey: HKEY;
DataType, DataSize: DWORD;
TmpRet: WideString;
DataLength: Integer;
RegKinds: TRegKinds;
begin
Result := True;
DataType := REG_NONE;
DataSize := 0;
RetValue := '';
RegKey := 0;
if InternalRegOpenKeyEx(RootKey, PWideChar(Key), 0, KEY_READ, RegKey) = ERROR_SUCCESS then
try
if InternalRegQueryValueEx(RegKey, PWideChar(Name), nil, @DataType, nil, @DataSize) = ERROR_SUCCESS then
begin
if MultiFlag then
RegKinds := [REG_BINARY, REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ]
else
RegKinds := [REG_BINARY, REG_SZ, REG_EXPAND_SZ];
if DataType in RegKinds then
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
DataLength := DataSize div SizeOf(WideChar);
SetLength(TmpRet, DataLength);
Result := InternalRegQueryValueEx(RegKey, PWideChar(Name), nil, nil, PWideChar(TmpRet), @DataSize) = ERROR_SUCCESS;
if Result then
RetValue := AnsiString(Copy(TmpRet, 1, DataLength - 1));
end
else
begin
DataLength := DataSize div SizeOf(AnsiChar);
SetLength(RetValue, DataLength);
Result := InternalRegQueryValueEx(RegKey, PWideChar(Name), nil, nil, PAnsiChar(RetValue), @DataSize) = ERROR_SUCCESS;
if Result then
SetLength(RetValue, DataLength - 1);
end;
if not Result then
begin
RetValue := '';
if RaiseException then
ValueError(RootKey, Key, Name)
else
Result := False;
end;
end
else
begin
RetValue := '';
if RaiseException then
DataError(RootKey, Key, Name)
else
Result := False;
end;
end
else
if RaiseException then
ValueError(RootKey, Key, Name)
else
Result := False;
finally
RegCloseKey(RegKey);
end
else
if RaiseException then
ReadError(RootKey, Key)
else
Result := False;
end;
function InternalGetWideString(const RootKey: DelphiHKEY; const Key, Name: WideString; MultiFlag: Boolean;
out RetValue: WideString; RaiseException: Boolean): Boolean;
var
RegKey: HKEY;
DataType, DataSize: DWORD;
RegKinds: TRegKinds;
DataLength: Integer;
begin
Result := True;
DataType := REG_NONE;
DataSize := 0;
RetValue := '';
RegKey := 0;
if InternalRegOpenKeyEx(RootKey, PWideChar(Key), 0, KEY_READ, RegKey) = ERROR_SUCCESS then
try
if InternalRegQueryValueEx(RegKey, PWideChar(Name), nil, @DataType, nil, @DataSize) = ERROR_SUCCESS then
begin
if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
RegKinds := [REG_BINARY]
else
if MultiFlag then
RegKinds := [REG_BINARY, REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ]
else
RegKinds := [REG_BINARY, REG_SZ, REG_EXPAND_SZ];
if DataType in RegKinds then
begin
DataLength := DataSize div SizeOf(WideChar);
SetLength(RetValue, DataLength);
if InternalRegQueryValueEx(RegKey, PWideChar(Name), nil, nil, PWideChar(RetValue), @DataSize) = ERROR_SUCCESS then
SetLength(RetValue, DataLength - 1)
else
begin
RetValue := '';
if RaiseException then
ValueError(RootKey, Key, Name)
else
Result := False;
end;
end
else
begin
RetValue := '';
if RaiseException then
DataError(RootKey, Key, Name)
else
Result := False;
end;
end
else
if RaiseException then
ValueError(RootKey, Key, Name)
else
Result := False;
finally
RegCloseKey(RegKey);
end
else
if RaiseException then
ReadError(RootKey, Key)
else
Result := False;
end;
function InternalStrToFloat(const RootKey: DelphiHKEY; const Key, Name: string; out Success: Boolean;
RaiseException: Boolean): Extended;
var
{$IFDEF RTL150_UP}
FS: TFormatSettings;
{$ELSE ~RTL150_UP}
OldSep: Char;
{$ENDIF ~RTL150_UP}
begin
{$IFDEF RTL150_UP}
FS.ThousandSeparator := ',';
FS.DecimalSeparator := '.';
{$ELSE ~RTL150_UP}
OldSep := DecimalSeparator;
try
DecimalSeparator := '.';
{$ENDIF ~RTL150_UP}
if RaiseException then
begin
Result := StrToFloat(RegReadString(RootKey, Key, Name){$IFDEF RTL150_UP}, FS{$ENDIF});
Success := True;
end
else
Success := TryStrToFloat(RegReadString(RootKey, Key, Name), Result{$IFDEF RTL150_UP}, FS{$ENDIF});
{$IFNDEF RTL150_UP}
finally
DecimalSeparator := OldSep;
end;
{$ENDIF ~RTL150_UP}
end;
procedure InternalSetData(const RootKey: DelphiHKEY; const Key, Name: WideString;
RegKind: TRegKind; Value: Pointer; ValueSize: Cardinal);
var
RegKey: HKEY;
begin
if not RegKeyExists(RootKey, Key) then
RegCreateKey(RootKey, Key);
RegKey := 0;
if InternalRegOpenKeyEx(RootKey, RelativeKey(RootKey, PWideChar(Key)), 0, KEY_WRITE, RegKey) = ERROR_SUCCESS then
try
if InternalRegSetValueEx(RegKey, PWideChar(Name), 0, RegKind, Value, ValueSize) <> ERROR_SUCCESS then
WriteError(RootKey, Key);
finally
RegCloseKey(RegKey);
end
else
WriteError(RootKey, Key);
end;
procedure InternalSetAnsiData(const RootKey: DelphiHKEY; const Key, Name: WideString;
RegKind: TRegKind; Value: Pointer; ValueSize: Cardinal);
var
Source: AnsiString;
Dest: WideString;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
// destination must be wide data
SetLength(Source, ValueSize div SizeOf(AnsiChar));
Move(Value^,Source[1],ValueSize * SizeOf(AnsiChar));
Dest := WideString(Source);
InternalSetData(RootKey, Key, Name, RegKind, PWideChar(Dest), SizeOf(WideChar) * ValueSize);
end
else
InternalSetData(RootKey, Key, Name, RegKind, Value, ValueSize);
end;
procedure InternalSetWideData(const RootKey: DelphiHKEY; const Key, Name: string;
RegKind: TRegKind; Value: Pointer; ValueSize: Cardinal);
begin
if (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and (RegKind in [REG_SZ, REG_MULTI_SZ, REG_EXPAND_SZ]) then
RegKind := REG_BINARY;
InternalSetData(RootKey, Key, Name, RegKind, Value, ValueSize);
end;
//=== Registry ===============================================================
function RegCreateKey(const RootKey: DelphiHKEY; const Key: string): Longint;
var
RegKey: HKEY;
begin
RegKey := 0;
Result := {$IFDEF HAS_UNITSCOPE}Winapi.{$ENDIF}Windows.RegCreateKeyEx(RootKey, RelativeKey(RootKey, PChar(Key)), 0, nil, 0,
GetWOW64AccessMode(KEY_ALL_ACCESS), nil, RegKey, nil);
if Result = ERROR_SUCCESS then
RegCloseKey(RegKey);
end;
function RegCreateKey(const RootKey: DelphiHKEY; const Key, Value: string): Longint;
begin
Result := RegSetValue(RootKey, RelativeKey(RootKey, PChar(Key)), REG_SZ, PChar(Value), Length(Value));
end;
function RegDeleteEntry(const RootKey: DelphiHKEY; const Key, Name: string): Boolean;
var
RegKey: HKEY;
begin
Result := False;
RegKey := 0;
if InternalRegOpenKeyEx(RootKey, RelativeKey(RootKey, PChar(Key)), 0, KEY_SET_VALUE, RegKey) = ERROR_SUCCESS then
begin
Result := RegDeleteValue(RegKey, PChar(Name)) = ERROR_SUCCESS;
RegCloseKey(RegKey);
if not Result then
ValueError(RootKey, Key, Name);
end
else
WriteError(RootKey, Key);
end;
function RegDeleteKeyTree(const RootKey: DelphiHKEY; const Key: string): Boolean;
var
RegKey: HKEY;
I: DWORD;
Size: DWORD;
NumSubKeys: DWORD;
MaxSubKeyLen: DWORD;
KeyName: string;
begin
RegKey := 0;
Result := InternalRegOpenKeyEx(RootKey, RelativeKey(RootKey, PChar(Key)), 0, KEY_ALL_ACCESS, RegKey) = ERROR_SUCCESS;
if Result then
begin
RegQueryInfoKey(RegKey, nil, nil, nil, @NumSubKeys, @MaxSubKeyLen, nil, nil, nil, nil, nil, nil);
if NumSubKeys <> 0 then
for I := NumSubKeys - 1 downto 0 do
begin
Size := MaxSubKeyLen+1;
SetLength(KeyName, Size);
RegEnumKeyEx(RegKey, I, PChar(KeyName), Size, nil, nil, nil, nil);
SetLength(KeyName, StrLen(PChar(KeyName)));
Result := RegDeleteKeyTree(RootKey, Key + RegKeyDelimiter + KeyName);
if not Result then
Break;
end;
RegCloseKey(RegKey);
if Result then
Result := {$IFDEF HAS_UNITSCOPE}Winapi.{$ENDIF}Windows.RegDeleteKey(RootKey, RelativeKey(RootKey, PChar(Key))) = ERROR_SUCCESS;
end
else
WriteError(RootKey, Key);
end;
function RegGetDataSize(const RootKey: DelphiHKEY; const Key, Name: string;
out DataSize: Cardinal): Boolean;
var
RegKey: HKEY;
begin
DataSize := 0;
RegKey := 0;
Result := InternalRegOpenKeyEx(RootKey, RelativeKey(RootKey, PChar(Key)), 0, KEY_READ, RegKey) = ERROR_SUCCESS;
if Result then
begin
Result := RegQueryValueEx(RegKey, PChar(Name), nil, nil, nil, @DataSize) = ERROR_SUCCESS;
RegCloseKey(RegKey);
end;
end;
function RegGetDataType(const RootKey: DelphiHKEY; const Key, Name: string;
out DataType: DWORD): Boolean;
var
RegKey: HKEY;
begin
DataType := REG_NONE;
RegKey := 0;
Result := InternalRegOpenKeyEx(RootKey, RelativeKey(RootKey, PChar(Key)), 0, KEY_READ, RegKey) = ERROR_SUCCESS;
if Result then
begin
Result := RegQueryValueEx(RegKey, PChar(Name), nil, @DataType, nil, nil) = ERROR_SUCCESS;
RegCloseKey(RegKey);
end;
end;
function RegReadBool(const RootKey: DelphiHKEY; const Key, Name: string): Boolean;
begin
Result := RegReadInteger(RootKey, Key, Name) <> 0;
end;
function RegReadBoolDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: Boolean): Boolean;
begin
Result := RegReadIntegerDef(RootKey, Key, Name, Ord(Def)) <> 0;
end;
function RegReadIntegerEx(const RootKey: DelphiHKEY; const Key, Name: string;
out RetValue: Integer; RaiseException: Boolean): Boolean;
var
DataType, DataSize: DWORD;
Ret: Int64;
begin
Ret := 0;
RegGetDataType(RootKey, Key, Name, DataType);
if DataType in [REG_SZ, REG_EXPAND_SZ] then
if RaiseException then
begin
Ret := StrToInt64(RegReadString(RootKey, Key, Name));
Result := True;