-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSiWin32.pas
7614 lines (7095 loc) · 269 KB
/
DSiWin32.pas
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
(*:Collection of Win32 wrappers and helper functions.
@desc <pre>
Free for personal and commercial use. No rights reserved.
Maintainer : gabr
Contributors : ales, aoven, gabr, Lee_Nover, _MeSSiah_, Miha-R, Odisej, xtreme,
Brdaws, Gre-Gor, krho, Cavlji, radicalb, fora, M.C, MP002, Mitja,
Christian Wimmer, Tommi Prami
Creation date : 2002-10-09
Last modification : 2010-12-04
Version : 1.60
</pre>*)(*
History:
1.60: 2010-12-04
- When compiled with D2007 or newer, unit FileCtrl is not included.
1.59b: 2010-10-28
- Call UniqueString before calling CreateProcessW.
1.59a: 2010-09-25
- [Tommi Prami] Added types missing in Delphi 7.
1.59: 2010-09-24
- Added function DSiDisableStandby that will try to disable standby and hibernate
on Windows XP SP 2 and newer.
1.58a: 2010-09-19
- Define TStartupInfoW in Delphi 7 and earlier.
1.58: 2010-07-27
- DSiAddApplicationToFirewallExceptionList[Advanced|XP] got a new parameter
TDSiFwResolveConflict (default rcDuplicate) where the caller can specify
behaviour if the rule with the same name already exists.
[rcDuplicate = add new rule with the same name, rcOverwrite = remove all rules
with the same name and then add the new rule, rcSkip = leave existing rules
intact and don't add the new rule]
- Implemented DSiFindApplicationInFirewallExceptionList[Advanced|XP].
1.57a: 2010-07-20
- Bug fix in DSiAddApplicationToFirewallExceptionListAdvanced: setting
rule.ServiceName to '' caused fwPolicy2.Rules.Add(rule) to raise exception.
1.57: 2010-06-18
- DSiExecuteAsUser now calls CreateProcessWithLogonW if CreateProcessAsUser fails
with ERROR_PRIVILEGE_NOT_HELD (1314). Windows error code is now returned in a
parameter. Window station and desktop process-specific ACEs are removed in a
background thread when child process exits (thanks to Christian Wimmer to pointing
out this problem). If the username is not set, DSiExecuteAsUser still sets up
ACEs for window station/desktop access but ends calling CreateProcess and does
not remove ACEs at the end.
- Two overloaded versions of DSiExecuteAsUser are implemented. One is backwards
compatible and another introduces two parameters -
out processInfo: TProcessInformation and startInfo: PStartupInfo (default: nil).
If the latter is assigned, it will be used instead of the internally generated
TStartupInfo. This version does not close process and thread handle returned
in the TProcessInformation if 'wait' is False.
- Implemented DSiRemoveAceFromWindowStation and DSiRemoveAceFromDesktop.
- Added dynamically loaded API forwarders DSiCreateProcessWithLogonW,
DSiCreateEnvironmentBlock, DSiDestroyEnvironmentBlock and
DSiGetUserProfileDirectoryW.
- DSiAddAceTo[WindowStation|Desktop] will not add SID if it already exists in the
ACL.
1.56: 2010-06-10
- [Mitja] Clear the last error if CreateProcess succeeds in DSiExecuteAndCapture
(found a test case where CreateProcess succeeded but last error was 126).
- [Christian Wimmer] In Unicode Delphis, DSiOpenSCManager, DSiGetLongPathName,
DSiGetModuleFileNameEx, DSiGetProcessImageFileName, DSiSetDllDirectory, and
DSiSHEmptyRecycleBin were linking to the wrong verison of the API.
- [Christian Wimmer] DSiCreateProcessAsUser must make a local copy of the
commandLine parameter when using Unicode API because the API may modify the
contents of this parameter.
- Implemented DSiGetLogonSID, DSiAddAceToWindowStation and DSiAddAceToDesktop.
- Redesigned DSiExecuteAsUser.
1.55: 2010-04-12
- Implemented DSiHasElapsed64 and DSiElapsedTime64.
1.54: 2010-04-08
- Implemented DSiLogonAs and DSiVerifyPassword.
1.53c: 2010-02-01
- DSiGetProcAddress made public.
1.53b: 2009-12-15
- Fixed Delphi 5 compilation.
1.53a: 2009-11-24
- Fixed TDSiRegistry.ReadVariant and WriteVariant to work with varUString
(also fixes all sorts of TDSiRegistry problems in Delphi 2010.)
1.53: 2009-11-13
- Implemented DSiDeleteRegistryValue.
- Added parameter 'access' to the DSiKillRegistry.
1.52a: 2009-11-04
- [Mitja] Fixed allocation in DSiGetUserName.
- [Mitja] Also catch 'error' output in DSiExecuteAndCapture.
1.52: 2009-10-28
- DSiAddApplicationToFirewallExceptionList renamed to
DSiAddApplicationToFirewallExceptionListXP.
- Added DSiAddApplicationToFirewallExceptionListAdvanced which uses Advanced
Firewall interface, available on Vista+.
- DSiAddApplicationToFirewallExceptionList now calls either
DSiAddApplicationToFirewallExceptionListXP or
DSiAddApplicationToFirewallExceptionListAdvanced, depending on OS version.
- Implemented functions to remove application from the firewall exception list:
DSiRemoveApplicationFromFirewallExceptionList,
DSiRemoveApplicationFromFirewallExceptionListAdvanced,
DSiRemoveApplicationFromFirewallExceptionListXP.
1.51a: 2009-10-27
- Convert non-EOleSysError exceptions in DSiAddApplicationToFirewallExceptionList
into ERROR_INVALID_FUNCTION error.
1.51: 2009-10-22
- Added 'onNewLine' callback to the DSiExecuteAndCapture. This event reports
program output line-by-line in real time and it can extend total time allowed
for program execution.
1.50: 2009-10-20
- [Mitja] Updated DSiExecuteAndCapture: settable timeout, Unicode Delphi support,
LastError is set if CreateProcess fails.
- Implemented functions DSiGetSubstDrive and DSiGetSubstPath.
1.49: 2009-10-12
- Added 'access' parameter to the DSiWriteRegistry methods so that user can
request writing to the non-virtualized key when running on 64-bit system
(KEY_WOW64_64KEY).
1.48: 2009-10-09
- Defined TOSVersionInfoEx record and corresponding constants.
- Extended DSiGetWindowsVersion to return wvWinServer2008, wvWin7 and
wvWinServer2008R2.
- Extended DSiGetTrueWindowsVersion to return wvWinServer2008OrVistaSP1 and
wvWin7OrServer2008R2.
1.47a: 2009-09-03
- Added parameter connectionIsAvailable to the DSiGetNetworkResource.
1.47: 2009-05-22
- Added dynamically loaded API forwarder DSiGetTickCount64.
1.46: 2009-03-17
- Added dynamically loaded API forwarders DSiWow64DisableWow64FsRedirection and
DSiWow64RevertWow64FsRedirection.
- Implemented function DSiDisableWow64FsRedirection and DSiRevertWow64FsRedirection.
1.45: 2009-03-16
- Implemented DSiGetCurrentThreadHandle and DSiGetCurrentProcessHandle.
1.44a: 2009-02-28
- Added D2009 compatibility fixes to DSiGetFolderLocation, DSiGetNetworkResource,
DSiGetComputerName, DSiGetWindowsFolder.
- Fixed DSiGetTempFileName, DSiGetUserName.
1.44: 2009-02-05
- Added functions DSiAddApplicationToFirewallExceptionList and
DSiAddPortToFirewallExceptionList.
1.43: 2009-01-28
- Added functions DSiGetNetworkResource, DSiDisconnectFromNetworkResource.
1.42: 2009-01-23
- Added functions DSiGetGlobalMemoryStatus, DSiGlobalMemoryStatusEx.
1.41: 2008-08-20
- Delphi 2009 compatibility.
1.40c: 2008-07-14
- Bug fixed: It was not possible to use DSiTimeGetTime64 in parallel from multiple
threads
1.40b: 2008-07-11
- Forced {$T-} as the code doesn't compile in {$T+} state.
1.40a: 2008-06-23
- Added constants FILE_LIST_DIRECTORY, FILE_SHARE_FULL, FILE_ACTION_ADDED,
FILE_ACTION_REMOVED, FILE_ACTION_MODIFIED, FILE_ACTION_RENAMED_OLD_NAME,
FILE_ACTION_RENAMED_NEW_NAME.
1.40: 2008-05-30
- Added function DSiCopyFileAnimated.
1.39: 2008-05-05
- Added function DSiConnectToNetworkResource.
1.38: 2008-04-29
- Added functions to copy HTML format to and from the clipboard:
DSiIsHtmlFormatOnClipboard, DSiGetHtmlFormatFromClipboard,
DSiCopyHtmlFormatToClipboard.
1.37: 2008-03-27
- Created DSiInterlocked*64 family of functions by copying the code from
http://qc.borland.com/wc/qcmain.aspx?d=6212. Functions were written by
Will DeWitt Jr [[email protected]] and are included with permission.
- Implemented DSiYield.
1.36a: 2008-01-16
- Changed DSiIsAdmin to use big enough buffer for token data.
- Changed DSiIsAdmin to ignore SE_GROUP_ENABLED attribute because function was
sometimes incorrectly returning False.
1.36: 2007-12-29
- Added procedures DSiCenterRectInRect and DSiMakeRectFullyVisibleOnRect.
1.35: 2007-12-17
- Added DSiTerminateProcessById procedure.
1.34: 2007-12-03
- Added three performance counter helpers DSiPerfCounterToMS, DSiPerfCounterToUS,
and DSiQueryPerfCounterAsUS.
1.33: 2007-11-26
- Added function DSiTimeGetTime64.
1.32: 2007-11-13
- Added parameter 'parameters' to DSiCreateShortcut and DSiGetShortcutInfo.
- Added function DSiEditShortcut.
- Added function DSiInitFontToSystemDefault.
1.31: 2007-11-06
- Added SHGetSpecialFolderLocation folder constants: CSIDL_ALTSTARTUP,
CSIDL_CDBURN_AREA, CSIDL_COMMON_ALTSTARTUP, CSIDL_COMMON_DESKTOPDIRECTORY,
CSIDL_COMMON_FAVORITES, CSIDL_COMMON_MUSIC, CSIDL_COMMON_PICTURES,
CSIDL_COMMON_PROGRAMS, CSIDL_COMMON_STARTMENU, CSIDL_COMMON_STARTUP,
CSIDL_COMMON_TEMPLATES, CSIDL_COMMON_VIDEO, CSIDL_COMPUTERSNEARME,
CSIDL_CONNECTIONS, CSIDL_COOKIES, CSIDL_INTERNET, CSIDL_INTERNET_CACHE,
CSIDL_MYDOCUMENTS, CSIDL_MYMUSIC, CSIDL_MYVIDEO, CSIDL_PHOTOALBUMS,
CSIDL_PLAYLISTS, CSIDL_PRINTHOOD, CSIDL_PROFILE, CSIDL_RESOURCES,
CSIDL_SAMPLE_MUSIC, CSIDL_SAMPLE_PLAYLISTS, CSIDL_SAMPLE_PICTURES,
CSIDL_SAMPLE_VIDEOS.
- Added ShGetSpecialFolderLocation flags CSIDL_FLAG_DONT_UNEXPAND and
CSIDL_FLAG_DONT_VERIFY.
- Added dynamically loaded API forwarder DSiSetSuspendState.
- Added dynamically loaded API forwarders DSiEnumProcessModules,
DSiGetModuleFileNameEx, and DSiGetProcessImageFileName.
- Added function DSiGetProcessFileName.
- More stringent checking in DSiGetProcessWindow.
- Fixed DSiLoadLibrary so that it can be called before initialization section is
executed. Somehow, D2007 doesn't always call initialization sectins in correct
order >:-(
1.30: 2007-10-25
- Added dynamically loaded API forwarders DSiDwmEnableComposition and
DsiDwmIsCompositionEnabled.
- Added Aero group with functions DSiAeroDisable, DSiAeroEnable, and
DSiAeroIsEnabled.
1.29: 2007-10-03
- Added function DSiIsAdmin.
1.28a: 2007-09-12
- TDSiTimer properties changed from published to public.
1.28: 2007-07-25
- Added function DSiMoveFile.
- Small changes in DSiMoveOnReboot.
1.27: 2007-07-11
- Added two overloaded functions DSiGetThreadTimes.
1.26: 2007-06-13
- Added two overloaded function DSiFileExtensionIs.
1.25: 2007-05-30
- Added thread-safe alternative to (De)AllocateHwnd - DSi(De)AllocateHwnd.
- Added TDSiTimer - a TTimer clone that uses DSi(De)AllocateHwnd internally.
- New function DSiGetFolderSize.
- Bug fixed: GetProcAddress result was not checked in DSiRegisterActiveX.
1.24: 2007-03-21
- Added support for search depth limitation to DSiEnumFilesEx and
DSiEnumFilesToSL.
1.23: 2007-02-14
- New functions: DSiGetProcessTimes (two overloaded versions), DSiGetFileTimes,
DSiFileTimeToDateTime (two overloaded versions), DSiFileTimeToMicroSeconds,
DSiGetProcessMemoryInfo, DSiGetProcessMemory (two overloaded versions),
DSiIsWow64, DSiGetAppCompatFlags, DSiGetTrueWindowsVersion.
- New dynamically loaded API forwarder: DSiIsWow64Process.
- Added parameter 'access' to DSiReadRegistry, DSiRegistryKeyExists, and
DSiRegistryValueExists functions.
1.22: 2006-12-07
- New function: DSiGetFileTime.
- Added Windows Vista detection to DSiGetWindowsVersion.
1.21: 2006-08-14
- New functions: DSiFileExistsW, DSiDirectoryExistsW, DSiFileSizeW,
DSiCompressFile, DSiUncompressFile, DSiIsFileCompressed, DSiIsFileCompressedW.
1.20: 2006-06-20
- New function: DSiGetShortcutInfo.
1.19: 2006-05-15
- New functions: DSiEnumFilesToSL, DSiGetLongPathName.
1.18: 2006-04-11
- New function: DSiSetDllDirectory.
1.17a: 2006-04-05
- Exit DSiProcessMessages when WM_QUIT is received.
1.17: 2006-03-14
- New function: DSiRegistryValueExists.
- Added 'working dir' parameter to the DSiCreateShortcut function.
1.16: 2006-01-23
- New DSiExecuteAndCapture implementation, contributed by matej.
1.15b: 2005-12-19
- TDSiRegistry.ReadInteger can now also read 4-byte binary values.
1.15a: 2005-08-09
- Removed StrNew from DSiGetComputerName because it caused the result never to
be released.
1.15: 2005-07-11
- New function: DSiWin32CheckNullHandle.
1.14: 2005-06-09
- New function: DSiGetEnvironmentVariable.
- DSiExecuteAndCapture modified to return exit code in a (newly added) parameter
and fixed to work on fast computers.
1.13a: 2005-03-15
- Make DSiGetTempFileName return empty string when GetTempFileName fails.
1.13: 2005-02-12
- New functions: DSiExitWindows, DSiGetSystemLanguage, DSiGetKeyboardLayouts.
- New methods: TDSiRegistry.ReadBinary (two overloaded versions),
TDSiRegistry.WriteBinary (two overloaded versions).
- Added OLE string processing to TDSiRegistry.ReadVariant and
TDSiRegistry.WriteVariant.
- Exported helper functions UTF8Encode and UTF8Decode for old Delphis (D5 and
below).
- Added Windows 2003 detection to DSiGetWindowsVersion.
- Modified DSiEnablePrivilege to return True without doint anything on 9x platform.
- Fixed handle leak in DSiSetProcessPriorityClass.
- Removed some dead code.
- Documented the Information segment.
1.12: 2004-09-21
- Added function DSiIncrementWorkingSet.
1.11: 2004-02-12
- Added functions DSiSetProcessPriorityClass, DSiGetProcessOwnerInfo (two
overloaded versions), DSiEnablePrivilege.
1.10: 2003-12-18
- Updated TDSiRegistry.ReadString to handle DWORD registry values too.
- Updated TDSiRegistry.ReadInteger to handle string registry values too.
1.09: 2003-11-14
- Added functions DSiValidateProcessAffinity, DSiValidateThreadAffinity,
DSiValidateProcessAffinityMask, DSiValidateThreadAffinityMask,
DSiGetSystemAffinityMask, DSiGetProcessAffinityMask,
DSiGetThreadAffinityMask, DSiAffinityMaskToString, and
DSiStringToAffinityMask.
1.08: 2003-11-12
- Added functions DSiCloseHandleAndInvalidate, DSiWin32CheckHandle,
DSiGetSystemAffinity, DSiGetProcessAffinity, DSiSetProcessAffinity,
DSiGetThreadAffinity, DSiSetThreadAffinity.
- Added types TDSiFileHandle, TDSiPipeHandle, TDSiMutexHandle, TDSiEventHandle,
TDSiSemaphoreHandle; all equivaled to THandle.
1.07a: 2003-10-18
- DSiuSecDelay was broken. Fixed.
1.07: 2003-10-09
- Added functions DSiGetUserNameEx, DSiIsDiskInDrive, DSiGetDiskLabel,
DSiGetMyDocumentsFolder, DSiGetSystemVersion, DSiRefreshDesktop,
DSiGetWindowsVersion, DSiRebuildDesktopIcons.
- Added TDSiRegistry methods ReadStrings and WriteStrings dealing with MULTI_SZ
registry format.
1.06a: 2003-09-03
- Typo fixed in DSiMsgWaitForTwoObjectsEx.
1.06: 2003-09-02
- New functions: DSiMsgWaitForTwoObjectsEx, DSiMsgWaitForThreeObjectsEx.
- Documented 'Handles' and 'Registry' sections.
- Bug fixed in DSiLoadLibrary.
1.05: 2003-09-02
- New functions: DSiMonitorOn, DSiMonitorOff, DSiMonitorStandby, DSiGetBootType,
DSiShareFolder, DSiUnshareFolder, DSiFileSize, DSiEnumFiles, DSiEnumFilesEx,
DSiGetDomain, DSiProcessMessages, DSiProcessThreadMessages, DSiLoadLibrary,
DSiGetProcAddress, DSiDisableX, DSiEnableX.
- Added dynamically loaded API forwarders: DSiNetApiBufferFree, DSiNetWkstaGetInfo,
DSiSHEmptyRecycleBin, DSiCreateProcessAsUser, DSiLogonUser,
DSiImpersonateLoggedOnUser, DSiRevertToSelf, DSiCloseServiceHandle,
DSiOpenSCManager, DSi9xNetShareAdd, DSi9xNetShareDel, DSiNTNetShareAdd,
DSiNTNetShareDel.
- DSiGetUserName could fail on Win9x. Fixed.
- Declared constants WAIT_OBJECT_1 (= WAIT_OBJECT_0+1) to WAIT_OBJECT_9
(=WAIT_OBJECT_0+9).
- All dynamically loaded functions are now available to the public (see new
{ DynaLoad } section).
- All functions using dynamically loaded API calls were modified to use new
DynaLoad methods.
- All string parameters turned into 'const' parameters.
- Various constants and type declarations moved to the 'interface' section.
1.04: 2003-05-27
- New functions: DSiLoadMedia, DSiEjectMedia.
1.03: 2003-05-24
- New functions: DSiExecuteAndCapture, DSiFreeMemAndNil.
1.02a: 2003-05-05
- Refuses to compile with Kylix.
- Removed platform-related warnings on Delphi 6&7.
1.02: 2002-12-29
- New function: DSiElapsedSince.
1.01: 2002-12-19
- Compiles with Delphi 6 and Delphi 7.
- New functions:
Files:
procedure DSiDeleteFiles(folder: string; fileMask: string);
procedure DSiDeleteTree(folder: string; removeSubdirsOnly: boolean);
procedure DSiEmptyFolder(folder: string);
procedure DSiEmptyRecycleBin;
procedure DSiRemoveFolder(folder: string);
procedure DSiuSecDelay(delay: word);
Processes:
function DSiExecuteAsUser(const commandLine, username, password: string;
const domain: string = '.'; visibility: integer = SW_SHOWDEFAULT;
workDir: string = ''; wait: boolean = false): cardinal;
function DSiImpersonateUser(const username, password, domain: string): boolean;
procedure DSiStopImpersonatingUser;
1.0: 2002-11-25
- Released.
*)
unit DSiWin32;
{$J+,T-} // required!
interface
{$IFDEF Linux}{$MESSAGE FATAL 'This unit is for Windows only'}{$ENDIF Linux}
{$IFDEF MSWindows}{$WARN SYMBOL_PLATFORM OFF}{$WARN UNIT_PLATFORM OFF}{$ENDIF MSWindows}
{$DEFINE NeedUTF}{$UNDEF NeedVariants}{$DEFINE NeedStartupInfo}
{$DEFINE NeedFileCtrl}
{$IFDEF ConditionalExpressions}
{$UNDEF NeedUTF}{$DEFINE NeedVariants}{$UNDEF NeedStartupInfo}
{$IF RTLVersion >= 18}{$UNDEF NeedFileCtrl}{$IFEND}
{$ENDIF}
uses
Windows,
Messages,
Consts,
{$IFDEF NeedVariants}
Variants,
{$ENDIF}
{$IFDEF NeedFileCtrl}
FileCtrl, // use before SysUtils so deprecated functions from FileCtrl can be reintroduced
{$ENDIF NeedFileCtrl}
SysUtils,
ShellAPI,
ShlObj,
Classes,
Graphics,
Registry;
const
// pretty wrappers
WAIT_OBJECT_1 = WAIT_OBJECT_0+1;
WAIT_OBJECT_2 = WAIT_OBJECT_0+2;
WAIT_OBJECT_3 = WAIT_OBJECT_0+3;
WAIT_OBJECT_4 = WAIT_OBJECT_0+4;
WAIT_OBJECT_5 = WAIT_OBJECT_0+5;
WAIT_OBJECT_6 = WAIT_OBJECT_0+6;
WAIT_OBJECT_7 = WAIT_OBJECT_0+7;
WAIT_OBJECT_8 = WAIT_OBJECT_0+8;
WAIT_OBJECT_9 = WAIT_OBJECT_0+9;
// folder constants missing from ShellObj
CSIDL_ADMINTOOLS = $0030; //v5.0; <user name>\Start Menu\Programs\Administrative Tools
CSIDL_ALTSTARTUP = $001D; //The file system directory that corresponds to the user's nonlocalized Startup program group.
CSIDL_APPDATA = $001A; //v4.71; Application Data, new for NT4
CSIDL_CDBURN_AREA = $003B; //v6.0; The file system directory acting as a staging area for files waiting to be written to CD.
CSIDL_COMMON_ADMINTOOLS = $002F; //v5.0; All Users\Start Menu\Programs\Administrative Tools
CSIDL_COMMON_ALTSTARTUP = $001E; //The file system directory that corresponds to the nonlocalized Startup program group for all users.
CSIDL_COMMON_APPDATA = $0023; //v5.0; All Users\Application Data
CSIDL_COMMON_DESKTOPDIRECTORY = $0019; //The file system directory that contains files and folders that appear on the desktop for all users.
CSIDL_COMMON_DOCUMENTS = $002E; //All Users\Documents
CSIDL_COMMON_FAVORITES = $001F; //The file system directory that serves as a common repository for favorite items common to all users.
CSIDL_COMMON_MUSIC = $0035; //v6.0; The file system directory that serves as a repository for music files common to all users.
CSIDL_COMMON_PICTURES = $0036; //v6.0; The file system directory that serves as a repository for image files common to all users.
CSIDL_COMMON_PROGRAMS = $0017; //The file system directory that contains the directories for the common program groups that appear on the Start menu for all users.
CSIDL_COMMON_STARTMENU = $0016; //The file system directory that contains the programs and folders that appear on the Start menu for all users.
CSIDL_COMMON_STARTUP = $0018; //The file system directory that contains the programs that appear in the Startup folder for all users.
CSIDL_COMMON_TEMPLATES = $002D; //The file system directory that contains the templates that are available to all users.
CSIDL_COMMON_VIDEO = $0037; //v6.0; The file system directory that serves as a repository for video files common to all users.
CSIDL_COMPUTERSNEARME = $003D; //The folder representing other machines in your workgroup.
CSIDL_CONNECTIONS = $0031; //The virtual folder representing Network Connections, containing network and dial-up connections.
CSIDL_COOKIES = $0021; //The file system directory that serves as a common repository for Internet cookies.
CSIDL_HISTORY = $0022; //The file system directory that serves as a common repository for Internet history items.
CSIDL_INTERNET = $0001; //A viritual folder for Internet Explorer (icon on desktop).
CSIDL_INTERNET_CACHE = $0020; //v4.72; The file system directory that serves as a common repository for temporary Internet files.
CSIDL_LOCAL_APPDATA = $001C; //v5.0; non roaming, user\Local Settings\Application Data
CSIDL_MYDOCUMENTS = $000C; //v6.0; The virtual folder representing the My Documents desktop item.
CSIDL_MYMUSIC = $000D; //The file system directory that serves as a common repository for music files.
CSIDL_MYPICTURES = $0027; //v5.0; My Pictures, new for Win2K
CSIDL_MYVIDEO = $000E; //v6.0; The file system directory that serves as a common repository for video files.
CSIDL_PHOTOALBUMS = $0045; //Vista; The virtual folder used to store photo albums.
CSIDL_PLAYLISTS = $003F; //Vista; The virtual folder used to store play albums.
CSIDL_PRINTHOOD = $001B; //The file system directory that contains the link objects that can exist in the Printers virtual folder.
CSIDL_PROFILE = $0028; //v5.0; The user's profile folder.
CSIDL_PROGRAM_FILES = $0026; //v5.0; C:\Program Files
CSIDL_PROGRAM_FILES_COMMON = $002B; //v5.0; C:\Program Files\Common
CSIDL_RESOURCES = $0038; //Vista; The file system directory that contains resource data.
CSIDL_SAMPLE_MUSIC = $0040; //Vista; The file system directory that contains sample music.
CSIDL_SAMPLE_PICTURES = $0042; //Vista; The file system directory that contains sample pictures.
CSIDL_SAMPLE_PLAYLISTS = $0041; //Vista; The file system directory that contains sample playlists.
CSIDL_SAMPLE_VIDEOS = $0043; //Vista; The file system directory that contains sample videos.
CSIDL_SYSTEM = $0025; //v5.0; GetSystemDirectory()
CSIDL_WINDOWS = $0024; //GetWindowsDirectory()
CSIDL_FLAG_DONT_UNEXPAND = $2000; //Combine with another CSIDL constant to ensure expanding of environment variables.
CSIDL_FLAG_DONT_VERIFY = $4000; //Combine with another CSIDL constant, except for CSIDL_FLAG_CREATE, to return an unverified folder path-with no attempt to create or initialize the folder.
CSIDL_FLAG_CREATE = $8000; // new for Win2K, OR this in to force creation of folder
FILE_DEVICE_FILE_SYSTEM = 9;
FILE_DEVICE_MASS_STORAGE = $2D;
METHOD_BUFFERED = 0;
FILE_ANY_ACCESS = 0;
FILE_READ_ACCESS = 1;
FILE_WRITE_ACCESS = 2;
IOCTL_STORAGE_EJECT_MEDIA = (FILE_DEVICE_MASS_STORAGE shl 16) OR
(FILE_READ_ACCESS shl 14) OR
($202 shl 2) OR
(METHOD_BUFFERED);
IOCTL_STORAGE_LOAD_MEDIA = (FILE_DEVICE_MASS_STORAGE shl 16) OR
(FILE_READ_ACCESS shl 14) OR
($203 shl 2) OR
(METHOD_BUFFERED);
FSCTL_SET_COMPRESSION = (FILE_DEVICE_FILE_SYSTEM shl 16) OR
((FILE_READ_ACCESS OR FILE_WRITE_ACCESS) shl 14) OR
(16 shl 2) OR
(METHOD_BUFFERED);
COMPRESSION_FORMAT_NONE = 0;
COMPRESSION_FORMAT_DEFAULT = 1;
SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
STYPE_DISKTREE = 0;
SHI50F_RDONLY = $0001;
SHI50F_FULL = $0002;
SHI50F_DEPENDSON = SHI50F_RDONLY or SHI50F_FULL;
SHI50F_ACCESSMASK = SHI50F_RDONLY or SHI50F_FULL;
// IPersisteFile GUID
IID_IPersistFile: TGUID = (
D1: $0000010B; D2: $0000; D3: $0000; D4: ($C0, $00, $00, $00, $00, $00, $00, $46));
// Extension for shortcut files
CLinkExt = '.lnk';
// ShEmptyRecycleBinA flags
SHERB_NOCONFIRMATION = $00000001;
SHERB_NOPROGRESSUI = $00000002;
SHERB_NOSOUND = $00000004;
// CurrentVersion registry key
DSiWinVerKey9x = '\Software\Microsoft\Windows\CurrentVersion';
DSiWinVerKeyNT = '\Software\Microsoft\Windows NT\CurrentVersion';
DSiWinVerKeys: array [boolean] of string = (DSiWinVerKey9x, DSiWinVerKeyNT);
// CPU IDs for the Affinity familiy of functions
DSiCPUIDs = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
// security constants needed in DSiIsAdmin
SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
DOMAIN_ALIAS_RID_ADMINS = $00000220;
DOMAIN_ALIAS_RID_USERS : DWORD = $00000221;
DOMAIN_ALIAS_RID_GUESTS: DWORD = $00000222;
DOMAIN_ALIAS_RID_POWER_: DWORD = $00000223;
SE_GROUP_ENABLED = $00000004;
type
// API types not defined in Delphi 5
PWkstaInfo100 = ^TWkstaInfo100;
_WKSTA_INFO_100 = record
wki100_platform_id: DWORD;
wki100_computername: LPWSTR;
wki100_langroup: LPWSTR;
wki100_ver_major: DWORD;
wki100_ver_minor: DWORD;
end;
{$EXTERNALSYM _WKSTA_INFO_100}
TWkstaInfo100 = _WKSTA_INFO_100;
WKSTA_INFO_100 = _WKSTA_INFO_100;
{$EXTERNALSYM WKSTA_INFO_100}
SHARE_INFO_2_NT = record
shi2_netname: PWideChar;
shi2_type: Integer;
shi2_remark: PWideChar;
shi2_permissions: Integer;
shi2_max_uses: Integer;
shi2_current_uses: Integer;
shi2_path: PWideChar;
shi2_passwd: PWideChar;
end;
SHARE_INFO_50_9x = record
shi50_netname: array[1..13] of char;
shi50_type: byte;
shi50_flags: short;
shi50_remark: pchar;
shi50_path: pchar;
shi50_rw_password: array[1..9] of char;
shi50_ro_password: array[1..9] of char;
szWhatever: array[1..256] of char;
end;
_PROCESS_MEMORY_COUNTERS = packed record
cb: DWORD;
PageFaultCount: DWORD;
PeakWorkingSetSize: DWORD;
WorkingSetSize: DWORD;
QuotaPeakPagedPoolUsage: DWORD;
QuotaPagedPoolUsage: DWORD;
QuotaPeakNonPagedPoolUsage: DWORD;
QuotaNonPagedPoolUsage: DWORD;
PagefileUsage: DWORD;
PeakPagefileUsage: DWORD;
end;
PROCESS_MEMORY_COUNTERS = _PROCESS_MEMORY_COUNTERS;
PPROCESS_MEMORY_COUNTERS = ^_PROCESS_MEMORY_COUNTERS;
TProcessMemoryCounters = _PROCESS_MEMORY_COUNTERS;
PProcessMemoryCounters = ^_PROCESS_MEMORY_COUNTERS;
DWORDLONG = int64;
PMemoryStatusEx = ^TMemoryStatusEx;
_MEMORYSTATUSEX = record
dwLength: DWORD;
dwMemoryLoad: DWORD;
ullTotalPhys: DWORDLONG;
ullAvailPhys: DWORDLONG;
ullTotalPageFile: DWORDLONG;
ullAvailPageFile: DWORDLONG;
ullTotalVirtual: DWORDLONG;
ullAvailVirtual: DWORDLONG;
ullAvailExtendedVirtual: DWORDLONG;
end;
TMemoryStatusEx = _MEMORYSTATUSEX;
MEMORYSTATUSEX = _MEMORYSTATUSEX;
// Service Controller handle
SC_HANDLE = THandle;
// DSiEnumFiles callback
TDSiEnumFilesCallback = procedure(const longFileName: string) of object;
// DSiEnumFilesEx callback
TDSiEnumFilesExCallback = procedure(const folder: string; S: TSearchRec;
isAFolder: boolean; var stopEnum: boolean) of object;
// DSiExecuteAndCapture callback
TDSiOnNewLineCallback = procedure(const line: string; var runningTimeLeft_sec: integer)
of object;
TDSiFileTime = (ftCreation, ftLastAccess, ftLastModification);
{ Handles }
// Pretty-print aliases
TDSiFileHandle = THandle;
TDSiPipeHandle = THandle;
TDSiMutexHandle = THandle;
TDSiEventHandle = THandle;
TDSiSemaphoreHandle = THandle;
procedure DSiCloseHandleAndInvalidate(var handle: THandle);
procedure DSiCloseHandleAndNull(var handle: THandle);
function DSiMsgWaitForThreeObjectsEx(obj0, obj1, obj2: THandle;
timeout: DWORD; wakeMask: DWORD; flags: DWORD): DWORD;
function DSiMsgWaitForTwoObjectsEx(obj0, obj1: THandle; timeout: DWORD;
wakeMask: DWORD; flags: DWORD): DWORD;
function DSiWaitForThreeObjects(obj0, obj1, obj2: THandle; waitAll: boolean;
timeout: DWORD): DWORD;
function DSiWaitForThreeObjectsEx(obj0, obj1, obj2: THandle; waitAll: boolean;
timeout: DWORD; alertable: boolean): DWORD;
function DSiWaitForTwoObjects(obj0, obj1: THandle; waitAll: boolean;
timeout: DWORD): DWORD;
function DSiWaitForTwoObjectsEx(obj0, obj1: THandle; waitAll: boolean;
timeout: DWORD; alertable: boolean): DWORD;
function DSiWin32CheckHandle(handle: THandle): THandle;
function DSiWin32CheckNullHandle(handle: THandle): THandle;
{ Registry }
const
KEY_WOW64_64KEY = $0100;
type
TDSiRegistry = class(TRegistry)
function ReadBinary(const name, defval: string): string; overload;
function ReadBinary(const name: string; dataStream: TStream): boolean; overload;
function ReadBool(const name: string; defval: boolean): boolean;
function ReadDate(const name: string; defval: TDateTime): TDateTime;
function ReadFont(const name: string; font: TFont): boolean;
function ReadInt64(const name: string; defval: int64): int64;
function ReadInteger(const name: string; defval: integer): integer;
function ReadString(const name, defval: string): string;
procedure ReadStrings(const name: string; strings: TStrings);
function ReadVariant(const name: string; defval: variant): variant;
procedure WriteBinary(const name, data: string); overload;
procedure WriteBinary(const name: string; data: TStream); overload;
procedure WriteFont(const name: string; font: TFont);
procedure WriteInt64(const name: string; value: int64);
procedure WriteStrings(const name: string; strings: TStrings);
procedure WriteVariant(const name: string; value: variant);
end; { TDSiRegistry }
function DSiCreateRegistryKey(const registryKey: string;
root: HKEY = HKEY_CURRENT_USER): boolean;
function DSiDeleteRegistryValue(const registryKey, name: string; root: HKEY =
HKEY_CURRENT_USER; access: longword = KEY_SET_VALUE): boolean;
function DSiKillRegistry(const registryKey: string;
root: HKEY = HKEY_CURRENT_USER; access: longword = KEY_SET_VALUE): boolean;
function DSiReadRegistry(const registryKey, name: string;
defaultValue: Variant; root: HKEY = HKEY_CURRENT_USER;
access: longword = KEY_QUERY_VALUE): Variant; overload;
function DSiReadRegistry(const registryKey, name: string;
defaultValue: int64; root: HKEY = HKEY_CURRENT_USER;
access: longword = KEY_QUERY_VALUE): int64; overload;
function DSiRegistryKeyExists(const registryKey: string;
root: HKEY = HKEY_CURRENT_USER; access: longword = KEY_QUERY_VALUE): boolean;
function DSiRegistryValueExists(const registryKey, name: string;
root: HKEY = HKEY_CURRENT_USER; access: longword = KEY_QUERY_VALUE): boolean;
function DSiWriteRegistry(const registryKey, name: string; value: int64;
root: HKEY = HKEY_CURRENT_USER; access: longword = KEY_SET_VALUE): boolean; overload;
function DSiWriteRegistry(const registryKey, name: string; value: Variant;
root: HKEY = HKEY_CURRENT_USER; access: longword = KEY_SET_VALUE): boolean; overload;
{ Files }
type
TShFileOpFlag = (fofAllowUndo, fofFilesOnly, fofMultiDestFiles, fofNoConfirmation,
fofNoConfirmMkDir, fofNoConnectedElements, fofNoErrorUI, fofNoRecursion,
fofNoRecurseReparse, fofRenameOnCollision, fofSilent, fofSimpleProgress,
fofWantMappingHandle, fofWantNukeWarning, fofNoUI);
TShFileOpFlags = set of TShFileOpFlag;
const
FILE_LIST_DIRECTORY = $0001;
FILE_SHARE_FULL = FILE_SHARE_DELETE OR FILE_SHARE_READ OR FILE_SHARE_WRITE;
FILE_ACTION_ADDED = $00000001;
FILE_ACTION_REMOVED = $00000002;
FILE_ACTION_MODIFIED = $00000003;
FILE_ACTION_RENAMED_OLD_NAME = $00000004;
FILE_ACTION_RENAMED_NEW_NAME = $00000005;
FOF_NOCONNECTEDELEMENTS = $2000;
FOF_NORECURSION = $1000;
FOF_NORECURSEREPARSE = $8000;
FOF_WANTNUKEWARNING = $4000;
FOF_NO_UI = FOF_SILENT OR FOF_NOCONFIRMATION OR FOF_NOERRORUI OR FOF_NOCONFIRMMKDIR;
CShFileOpFlagMappings: array [TShFileOpFlag] of FILEOP_FLAGS = (FOF_ALLOWUNDO,
FOF_FILESONLY, FOF_MULTIDESTFILES, FOF_NOCONFIRMATION, FOF_NOCONFIRMMKDIR,
FOF_NOCONNECTEDELEMENTS, FOF_NOERRORUI, FOF_NORECURSION, FOF_NORECURSEREPARSE,
FOF_RENAMEONCOLLISION, FOF_SILENT, FOF_SIMPLEPROGRESS, FOF_WANTMAPPINGHANDLE,
FOF_WANTNUKEWARNING, FOF_NO_UI);
function DSiCanWriteToFolder(const folderName: string): boolean;
function DSiCompressFile(fileHandle: THandle): boolean;
function DSiConnectToNetworkResource(const networkResource: string; const mappedLetter:
string = ''; const username: string = ''; const password: string = ''): boolean;
function DSiCopyFileAnimated(ownerWindowHandle: THandle; sourceFile, destinationFile:
string; var aborted: boolean; flags: TShFileOpFlags = [fofNoConfirmMkDir]): boolean;
function DSiCreateTempFolder: string;
procedure DSiDeleteFiles(const folder, fileMask: string);
function DSiDeleteOnReboot(const fileName: string): boolean;
procedure DSiDeleteTree(const folder: string; removeSubdirsOnly: boolean);
function DSiDeleteWithBatch(const fileName: string; rmDir: boolean = false): boolean;
function DSiDirectoryExistsW(const directory: WideString): boolean;
function DSiDisableWow64FsRedirection(var oldStatus: pointer): boolean;
function DSiDisconnectFromNetworkResource(mappedLetter: char; updateProfile: boolean =
false): boolean;
function DSiEjectMedia(deviceLetter: char): boolean;
procedure DSiEmptyFolder(const folder: string);
function DSiEmptyRecycleBin: boolean;
function DSiEnumFiles(const fileMask: string; attr: integer;
enumCallback: TDSiEnumFilesCallback): integer;
function DSiEnumFilesEx(const fileMask: string; attr: integer;
enumSubfolders: boolean; enumCallback: TDSiEnumFilesExCallback;
maxEnumDepth: integer = 0): integer;
procedure DSiEnumFilesToSL(const fileMask: string; attr: integer; fileList: TStrings;
storeFullPath: boolean = false; enumSubfolders: boolean = false;
maxEnumDepth: integer = 0);
function DSiFileExistsW(const fileName: WideString): boolean;
function DSiFileExtensionIs(const fileName, extension: string): boolean; overload;
function DSiFileExtensionIs(const fileName: string; extension: array of string):
boolean; overload;
function DSiFileSize(const fileName: string): int64;
function DSiFileSizeW(const fileName: WideString): int64;
function DSiGetFolderSize(const folder: string; includeSubfolders: boolean): int64;
function DSiGetFileTime(const fileName: string; whatTime: TDSiFileTime): TDateTime;
function DSiGetFileTimes(const fileName: string; var creationTime, lastAccessTime,
lastModificationTime: TDateTime): boolean;
function DSiGetLongPathName(const fileName: string): string;
function DSiGetNetworkResource(mappedLetter: char; var networkResource: string; var
connectionIsAvailable: boolean): boolean;
function DSiGetSubstDrive(mappedLetter: char): string;
function DSiGetSubstPath(const path: string): string;
function DSiGetTempFileName(const prefix: string; const tempPath: string = ''): string;
function DSiGetTempPath: string;
function DSiGetUniqueFileName(const extension: string): string;
function DSiIsFileCompressed(const fileName: string): boolean;
function DSiIsFileCompressedW(const fileName: WideString): boolean;
function DSiKillFile(const fileName: string): boolean;
function DSiLoadMedia(deviceLetter: char): boolean;
function DSiMoveFile(const srcName, destName: string; overwrite: boolean = true): boolean;
function DSiMoveOnReboot(const srcName, destName: string): boolean;
procedure DSiRemoveFolder(const folder: string);
function DSiRevertWow64FsRedirection(const oldStatus: pointer): boolean;
function DSiShareFolder(const folder, shareName, comment: string): boolean;
function DSiUncompressFile(fileHandle: THandle): boolean;
function DSiUnShareFolder(const shareName: string): boolean;
{ Processes }
function DSiAddAceToDesktop(desktop: HDESK; sid: PSID): boolean;
function DSiAddAceToWindowStation(station: HWINSTA; sid: PSID): boolean;
function DSiAffinityMaskToString(affinityMask: DWORD): string;
function DSiGetCurrentProcessHandle: THandle;
function DSiGetCurrentThreadHandle: THandle;
function DSiEnablePrivilege(const privilegeName: string): boolean;
function DSiExecute(const commandLine: string;
visibility: integer = SW_SHOWDEFAULT; const workDir: string = '';
wait: boolean = false): cardinal;
function DSiExecuteAndCapture(const app: string; output: TStrings; const workDir: string;
var exitCode: longword; waitTimeout_sec: integer = 15; onNewLine: TDSiOnNewLineCallback
= nil): cardinal;
function DSiExecuteAsUser(const commandLine, username, password: string;
var winErrorCode: cardinal; const domain: string = '.';
visibility: integer = SW_SHOWDEFAULT; const workDir: string = '';
wait: boolean = false): cardinal; overload;
function DSiExecuteAsUser(const commandLine, username, password: string;
var winErrorCode: cardinal; var processInfo: TProcessInformation;
const domain: string = '.'; visibility: integer = SW_SHOWDEFAULT;
const workDir: string = ''; wait: boolean = false;
startInfo: PStartupInfo = nil): cardinal; overload;
function DSiGetProcessAffinity: string;
function DSiGetProcessAffinityMask: DWORD;
function DSiGetProcessID(const processName: string; var processID: DWORD): boolean;
function DSiGetProcessMemory(var memoryCounters: TProcessMemoryCounters): boolean;
overload;
function DSiGetProcessMemory(process: THandle; var memoryCounters:
TProcessMemoryCounters): boolean; overload;
function DSiGetProcessFileName(process: THandle; var processName: string): boolean;
function DSiGetProcessOwnerInfo(const processName: string; var user,
domain: string): boolean; overload;
function DSiGetProcessOwnerInfo(processID: DWORD; var user,
domain: string): boolean; overload;
function DSiGetProcessTimes(var creationTime: TDateTime; var userTime,
kernelTime: int64): boolean; overload;
function DSiGetProcessTimes(process: THandle; var creationTime, exitTime: TDateTime;
var userTime, kernelTime: int64): boolean; overload;
function DSiGetSystemAffinity: string;
function DSiGetSystemAffinityMask: DWORD;
function DSiGetThreadAffinity: string;
function DSiGetThreadAffinityMask: DWORD;
function DSiGetThreadTimes(var creationTime: TDateTime; var userTime,
kernelTime: int64): boolean; overload;
function DSiGetThreadTimes(thread: THandle; var creationTime, exitTime: TDateTime;
var userTime, kernelTime: int64): boolean; overload;
function DSiImpersonateUser(const username, password: string;
const domain: string = '.'): boolean;
function DSiIncrementWorkingSet(incMinSize, incMaxSize: integer): boolean;
function DSiIsDebugged: boolean;
function DSiLogonAs(const username, password: string;
var logonHandle: THandle): boolean; overload;
function DSiLogonAs(const username, password, domain: string;
var logonHandle: THandle): boolean; overload;
function DSiOpenURL(const URL: string; newBrowser: boolean = false): boolean;
procedure DSiProcessThreadMessages;
function DSiRealModuleName: string;
function DSiRemoveAceFromDesktop(desktop: HDESK; sid: PSID): boolean;
function DSiRemoveAceFromWindowStation(station: HWINSTA; sid: PSID): boolean;
function DSiSetProcessAffinity(affinity: string): string;
function DSiSetProcessPriorityClass(const processName: string;
priority: DWORD): boolean;
function DSiSetThreadAffinity(affinity: string): string;
procedure DSiStopImpersonatingUser;
function DSiStringToAffinityMask(affinity: string): DWORD;
function DSiTerminateProcessById(processID: DWORD; closeWindowsFirst: boolean = true;
maxWait_sec: integer = 10): boolean;
procedure DSiTrimWorkingSet;
function DSiValidateProcessAffinity(affinity: string): string;
function DSiValidateProcessAffinityMask(affinityMask: DWORD): DWORD;
function DSiValidateThreadAffinity(affinity: string): string;
function DSiValidateThreadAffinityMask(affinityMask: DWORD): DWORD;
procedure DSiYield;
{ Memory }
procedure DSiFreePidl(pidl: PItemIDList);
procedure DSiFreeMemAndNil(var mem: pointer);
function DSiGetGlobalMemoryStatus(var memoryStatus: TMemoryStatusEx): boolean;
{ Windows }
type
TDSiExitWindows = (ewLogOff, ewForcedLogOff, ewPowerOff, ewForcedPowerOff, ewReboot,
ewForcedReboot, ewShutdown, ewForcedShutdown);
function DSiAllocateHWnd(wndProcMethod: TWndMethod): HWND;
procedure DSiDeallocateHWnd(wnd: HWND);
function DSiDisableStandby: boolean;
procedure DSiDisableX(hwnd: THandle);
procedure DSiEnableX(hwnd: THandle);
function DSiExitWindows(exitType: TDSiExitWindows): boolean;
function DSiForceForegroundWindow(hwnd: THandle;
restoreFirst: boolean = true): boolean;
function DSiGetClassName(hwnd: THandle): string;
function DSiGetProcessWindow(targetProcessID: cardinal): HWND;
function DSiGetWindowText(hwnd: THandle): string;
procedure DSiProcessMessages(hwnd: THandle; waitForWMQuit: boolean = false);
procedure DSiRebuildDesktopIcons;
procedure DSiRefreshDesktop;
procedure DSiSetTopMost(hwnd: THandle; onTop: boolean = true;
activate: boolean = false);
{ Aero }
function DSiAeroDisable: boolean;
function DSiAeroEnable: boolean;
function DSiAeroIsEnabled: boolean;
{ Taskbar }
function DSiGetTaskBarPosition: integer;
{ Menus }
function DSiGetHotkey(const item: string): char;
function DSiGetMenuItem(menu: HMENU; item: integer): string;
{ Screen }
procedure DSiDisableScreenSaver(out currentlyActive: boolean);
procedure DSiEnableScreenSaver;
function DSiGetBitsPerPixel: integer;
function DSiGetBPP: integer;
function DSiGetDesktopSize: TRect;
function DSiIsFullScreen: boolean;
procedure DSiMonitorOff;
procedure DSiMonitorOn;
procedure DSiMonitorStandby;
function DSiSetScreenResolution(width, height: integer): longint;
{ Rectangles }
procedure DSiCenterRectInRect(const ownerRect: TRect; var clientRect: TRect);
procedure DSiMakeRectFullyVisibleOnRect(const ownerRect: TRect; var clientRect: TRect);
{ Clipboard }
function DSiIsHtmlFormatOnClipboard: boolean;
function DSiGetHtmlFormatFromClipboard: string;
procedure DSiCopyHtmlFormatToClipboard(const sHtml: string; const sText: string = '');
{ Information }
type
TDSiBootType = (btNormal, btFailSafe, btFailSafeWithNetwork, btUnknown);
TDSiWindowsVersion = (wvUnknown, wvWin31, wvWin95, wvWin95OSR2, wvWin98,
wvWin98SE, wvWinME, wvWin9x, wvWinNT3, wvWinNT4, wvWin2000, wvWinXP,
wvWinNT, wvWinServer2003, wvWinVista, wvWinServer2008, wvWinServer2008OrVistaSP1,
wvWin7, wvWinServer2008R2, wvWin7OrServer2008R2);
TDSiUIElement = (ueMenu, ueMessage, ueWindowCaption, ueStatus);
const
CDSiWindowsVersionStr: array [TDSiWindowsVersion] of string = ('Unknown',
'Windows 3.1', 'Windows 95', 'Windows 95 OSR 2', 'Windows 98',
'Windows 98 SE', 'Windows Me', 'Windows 9x', 'Windows NT 3.5',
'Windows NT 4', 'Windows 2000', 'Windows XP', 'Windows NT', 'Windows Server 2003',
'Windows Vista', 'Windows Server 2008', 'Windows Server 2008 or Windows Vista SP1',
'Windows 7', 'Windows Server 2008 R2', 'Windows 7 or Windows Server 2008 R2');
VER_SUITE_BACKOFFICE = $00000004; // Microsoft BackOffice components are installed.
VER_SUITE_BLADE = $00000400; // Windows Server 2003, Web Edition is installed.
VER_SUITE_COMPUTE_SERVER = $00004000; // Windows Server 2003, Compute Cluster Edition is installed.
VER_SUITE_DATACENTER = $00000080; // Windows Server 2008 Datacenter, Windows Server 2003, Datacenter Edition, or Windows 2000 Datacenter Server is installed.
VER_SUITE_ENTERPRISE = $00000002; // Windows Server 2008 Enterprise, Windows Server 2003, Enterprise Edition, or Windows 2000 Advanced Server is installed. Refer to the Remarks section for more information about this bit flag.
VER_SUITE_EMBEDDEDNT = $00000040; // Windows XP Embedded is installed.
VER_SUITE_PERSONAL = $00000200; // Windows Vista Home Premium, Windows Vista Home Basic, or Windows XP Home Edition is installed.
VER_SUITE_SINGLEUSERTS = $00000100; // Remote Desktop is supported, but only one interactive session is supported. This value is set unless the system is running in application server mode.
VER_SUITE_SMALLBUSINESS = $00000001; // Microsoft Small Business Server was once installed on the system, but may have been upgraded to another version of Windows. Refer to the Remarks section for more information about this bit flag.
VER_SUITE_SMALLBUSINESS_RESTRICTED
= $00000020; // Microsoft Small Business Server is installed with the restrictive client license in force. Refer to the Remarks section for more information about this bit flag.
VER_SUITE_STORAGE_SERVER = $00002000; // Windows Storage Server 2003 R2 or Windows Storage Server 2003is installed.
VER_SUITE_TERMINAL = $00000010; // Terminal Services is installed. This value is always set.
VER_SUITE_WH_SERVER = $00008000; // Windows Home Server is installed.
VER_NT_DOMAIN_CONTROLLER = $0000002; // The system is a domain controller and the operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
VER_NT_SERVER = $0000003; // The operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
// Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER.
VER_NT_WORKSTATION = $0000001; // The operating system is Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional.
type
_OSVERSIONINFOEXA = record
dwOSVersionInfoSize: DWORD;
dwMajorVersion: DWORD;
dwMinorVersion: DWORD;
dwBuildNumber: DWORD;
dwPlatformId: DWORD;
szCSDVersion: array[0..127] of AnsiChar; { Maintenance AnsiString for PSS usage }
wServicePackMajor: WORD;
wServicePackMinor: WORD;
wSuiteMask: WORD;
wProductType: BYTE;
wReserved: BYTE;
end;
{$EXTERNALSYM _OSVERSIONINFOEXA}
_OSVERSIONINFOEXW = record
dwOSVersionInfoSize: DWORD;
dwMajorVersion: DWORD;
dwMinorVersion: DWORD;
dwBuildNumber: DWORD;
dwPlatformId: DWORD;
szCSDVersion: array[0..127] of WideChar; { Maintenance WideString for PSS usage }
wServicePackMajor: WORD;
wServicePackMinor: WORD;
wSuiteMask: WORD;
wProductType: BYTE;
wReserved: BYTE;
end;
{$EXTERNALSYM _OSVERSIONINFOExW}
_OSVERSIONINFEXO = _OSVERSIONINFOEXA;
TOSVersionInfoExA = _OSVERSIONINFOEXA;
TOSVersionInfoExW = _OSVERSIONINFOEXW;
TOSVersionInfoEx = TOSVersionInfoExA;
OSVERSIONINFOEXA = _OSVERSIONINFOEXA;
{$EXTERNALSYM OSVERSIONINFOEXA}
{$EXTERNALSYM OSVERSIONINFOEX}
OSVERSIONINFOEXW = _OSVERSIONINFOEXW;
{$EXTERNALSYM OSVERSIONINFOEXW}
{$EXTERNALSYM OSVERSIONINFOEX}
OSVERSIONINFOEX = OSVERSIONINFOEXA;
{$IFNDEF NeedStartupInfo}
_STARTUPINFOW = record
cb: DWORD;
lpReserved: PWideChar;
lpDesktop: PWideChar;
lpTitle: PWideChar;
dwX: DWORD;
dwY: DWORD;
dwXSize: DWORD;
dwYSize: DWORD;
dwXCountChars: DWORD;
dwYCountChars: DWORD;
dwFillAttribute: DWORD;
dwFlags: DWORD;
wShowWindow: Word;
cbReserved2: Word;
lpReserved2: PByte;
hStdInput: THandle;
hStdOutput: THandle;
hStdError: THandle;
end;
TStartupInfoW = _STARTUPINFOW;