summaryrefslogtreecommitdiff
path: root/support/dktools/dkwt.ctr
blob: 37855f391a612b76482e51b5b4e45c2823b7ab26 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
%%	options

copyright owner	=	Dirk Krause
copyright year	=	2011-xxxx
SPDX-License-Identifier:	BSD-3-Clause



%%	module

#include "dk3all.h"
#if 0
#include "dkt-version.h"
#endif
#include "dk4vers.h"
#include "dkt.h"
#include "dkwt.h"



$!trace-include



/**	File name for string table file.
*/
static dkChar const dkwt_string_table_file_name[] = { dkT("dkwt.str") };



/**	Version number string.
*/
static dkChar const dkwt_version[] = {
dkT("dkwt ") DKT_VERSION_DK
};



/**	License terms.
*/
static dkChar const * const dkwt_license[] = {
$!text macro=dkT

Copyright (c) 2011-2016, Dirk Krause
All rights reserved.

Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.
* Redistributions in binary form must reproduce the above 
  copyright notice, this list of conditions and the following
  disclaimer in the documentation and/or other materials
  provided with the distribution.
* Neither the name of the copyright holder(s) nor the names of
  contributors may be used to endorse or promote
  products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

$!end
};



/**	Message texts used by the program, localized.
*/
static dkChar const * const	dkwt_message_texts[] = {
$!string-table	macro=dkT
#
#   0: Attribute label: FUll user name
#
Full name:     
#
#   1: Attribute label: Comment for user
#
Comment:       
#
#   2: Attribute label: User comment
#
User comment:  
#
#   3: Attribute label: HOme directory
#
Home directory:
#
#   4: Attribute label: User profile directory
#
User profile:  
#
#   5: Attribute label: User SID
#
SID:           
#
#   6: Attribute label: User type
#
Type:          
#
#   7: User type: guest
#
Guest
#
#   8: User type: Normal user
#
User
#
#   9: User type: Administrator
#
Administrator
#
#  10: Attribute label: User flags.
#
Flags:         
#
#  11: Account attribute: Login script executed
#
Login script executed.
#
#  12: Account attribute: Account disabled
#
Account disabled.
#
#  13: Account attribute: Home directory required
#
Home directory required.
#
#  14: Account attribute: No password required
#
No password required.
#
#  15: Account attribute: Password can not be changed
#
Password can not be changed.
#
#  16: Account attribute: Locked out
#
Account locked out.
#
#  17: Account attribute: Password does not expire
#
Password does not expire.
#
#  18: Account attribute: Encrypted text password allowd
#
Encrypted text password allowed.
#
#  19: Account attribute: Account is sensitive, no delegation
#
Sensitive account, no delegation.
#
#  20: Account attribute: Smartcard required
#
Smartcard required.
#
#  21: Account attribute: DES keys are allowed only
#
DES keys only.
#
#  22: Account attribute: No Kerberos pre-auth required
#
No Kerberos pre-authentication required.
#
#  23: Account attribute: Account is trusted for delegation
#
Trusted for delegation.
#
#  24: Account attribute: Password is expired
#
Password expired.
#
#  25: Account attribute: Trusted to authenticate for delegation
#
Trusted to authenticate for delegation.
#
#  26: Account type: Normal user account
#
Normal user account.
#
#  27: Account type: Duplicated account for user from other domain
#
Duplicated account for user from another domain.
#
#  28: Account type: Workstation trust account
#
Workstation trust account.
#
#  29: Account type: Server trust account
#
Server trust account.
#
#  30: Account type: Interdomain trust account
#
Interdomain trust account.
#
#  31: Empty string
#

#
#  32: Operator privileges label
#
Operator:      
#
#  33: Operator type: Accounts operator
#
Accounts operator.
#
#  34: Operator type: Server operator
#
Server operator.
#
#  35: Operator type: Communications operator
#
Communications operator.
#
#  36: Operator type: Print operator
#
Print operator.
#
#  37: Attribute label: Country code
#
Country code:  
#
#  38: Attribute label: Code page number
#
Code page no.: 
#
#  39: Attribute label: Source
#
Source:  
#
#  40: Attribute label: Comment
#
Comment: 
#
#  41: Source type: Net
#
Net
#
#  42: Source type: Local
#
Local
#
#  43: Attribute label: SID
#
SID:     
#
#  44: Attribute label: Comment
#
Comment:         
#
#  45: Attribute label: Description
#
Description:     
#
#  46: Attribute label: Location
#
Location:        
#
#  47: Attribute label: Server
#
Server:          
#
#  48: Attribute label: Share name
#
Share name:      
#
#  49: Attribute label: Port
#
Port:            
#
#  50: Attribute label: Driver
#
Driver:          
#
#  51: Attribute label: Device
#
Device:          
#
#  52: Attribute label: Separator file
#
Separator file:  
#
#  53: Attribute label: Print processor
#
Print processor: 
#
#  54: Attribute label: Data type
#
Data type:       
#
#  55: Attribute label: Parameters
#
Parameters:      
#
#  56/57: Error message: Failed to create print file "..."!
#
Failed to create print file "
"!
#
#  58: Error message: Failed to schedule print job!
#
Failed to schedule print job!
#
#  59: Error message: Failed to add print job!
#
Failed to add print job!
#
#  60/61: Error message: Failed to open printer "..."!
#
Failed to open printer "
"!
#
#  62: Error message: Printer name too long!
#
Printer name too long!
#
#  63/64: Error message: No printer found for device "..."!
#
No printer found for device "
"!
#
#  65: Error message: Failed to find default printer!
#
Failed to find default printer!
#
#  66: Error message: Redefinition of profile base directory!
#
Redefinition of profile base directory!
#
#  67: Error message: No profile base directory specified!
#
No profile base directory specified!
#
#  68: Error message: Syntax - Unknown section type!
#
Syntax error - Unknown section type!
#
#  69: Error message: Syntax - Incomplete section header!
#
Syntax error - Incomplete section header!
#
#  70: Error message: Syntax - Missing section header!
#
Syntax error - Missing section header!
#
#  71: Error message: Syntax - Redefinition of system user!
#
Syntax error - Redefinition of system user!
#
#  72: Error message: Syntax - Redefinition of everyone user!
#
Syntax error - Redefinition of everyone user!
#
#  73: Error message: Syntax - Unknown option!
#
Syntax error - Unknown option!
#
#  74: Error message: Syntax - Not a key/value pair!
#
Syntax error - Not a key/value pair!
#
#  75: Error message: Options -l and -s are exclusive!
#
Options -l and -s are exclusive!
#
#  76: Error message: Arguments are ignored!
#
Arguments are ignored!
#
#  77: Error message: Failed to set keep-data flag.
#
FAILED TO SET KEEP-DATA FLAG!
#
#  78: Notice: Keep-data flag was set successfully.
#
Keep-data flag was set successfully.
#
#  79/80: Execution of "..." indicated an error!
#
Exit status code indicates an error, program:\n"

#
#  81/82: Error: Failed to find name for SID "..."!
#
Failed to find name for SID "
"!
#
#  83/84: Progress: Cleaning up local print queue ... .
#
Cleaning up local print queue "
".
#
#  85/86/87: Progress: Successfully deleted job ...: "...".
#
Successfully deleted job 
: "
".
#
#  88: Unnamed print job
#
Unnamed print job
#
#  89/90/91: Error: Failed to delete job ...: "..."!
#
Failed to delete job 
: "
"!
#
#  92/93: Error: Failed to open printer ...!
#
Failed to open printer "
"!
#
#  94: Error: Failed to enumerate local printers!
#
Failed to enumerate local printers!
#
#  95: Error: Missing user name!
#
Missing user name!
#
#  96: Progress: Print queue cleaned up successfully.
#
Print queue cleaned up successfully.
#
#  97: ERROR: Failed to send request!
#
Failed to send request!
#
#  98: ERROR: Failed to connect to remote host!
#
Failed to connect to remote host!
#
#  99: ERROR: Failed to create network socket!
#
Failed to create network socket!
#
#  100: ERROR: Failed to find IP address!
#
Failed to find IP address for remote host!
#
#  101/102: Progress: Cleaning up remote print queue ...
#
Cleaning up remote print queue "
".
#
#  103: ERROR: Request too long for buffer!
#
Request too long for buffer!
#
#  104/105: ERROR: Empty queue name in "..."!
#
Empty queue name in "
"!
#
# 106/107: ERROR: Empty host name in "..."!
#
Empty host name in "
"!
#
# 108/109: ERROR: Not a queue@host name: "..."!
#
Not a queue@host name: "
"!
#
# 110/111: ERROR: Queue name "..." too long!
#
Queue name "
" too long!
#
# 112: ERROR: Failed to initialize Windows sockets!
#
Failed to initialize Windows sockets!
#
# 113/114: Error: Error code: ...
#
Error code: 
.
#
# 115/116: IP address: ...
#
IP address: 
.
#
# 117: Warning: User profile cleanup is disabled on Windows Vista and above!
#
User profile cleanup is disabled on Windows Vista and above!
#
# 118/119: Progress: Executing command: ...
#
Executing command:\n

#
# 120/121: Progress: Remove directory: ...
#
Remove directory:\n

#
# 122/123: Progress: Remove file: ...
#
Remove file:\n

#
#  124/125/126: Progress: Delete Registry key ...
#
Delete registry key:\n
\\

#
#  127/128: DEBUG: Registry key "..." deleted.
#
Registry key "
" deleted.
#
#  129/130/131: ERROR: Failed to remove registry key:
#
Failed to remove registry key:\n
\\

#
#  132/133
#
Failed to open registry key:\n

#
#  134
#
Cleaning up profiles (start).
#
#  135
#
Internal error while retrieving directory entry name!
#
#  136/137
#
Failed to expand string\n"
",\nresult would become too long for buffer!
#
#  138/139
#
Subkey name too long:\n

#
#  140
#
Skipping profile cleanup due to previous errors!
#
#  141
#
Cleaning up profiles (finished).
#
#  142
#
Options -u, -i, -a, and -d are mutually exlusive!
#
#  143
#
At least one argument required!
#
#  144
#
Missing file/directory name!
#
#  145
#
Administrative privileges are required!
#
#  146
#
Administrative privileges are required to modify system environment!
$!end
};



/**	Keywords used by the program, not localized.
*/
static dkChar const * const	dkwt_no_loc[] = {
$!string-table	macro=dkT
#
#  0
#

#
#  1
#
dkwt.conf
#
#  2
#
System
#
#  3
#
Jeder
#
#  4
#
RD  /S /Q "
#
#  5
#
"
#
#  6
#
DEL /Q /F "
#
#  7
#
CACLS.EXE "
#
#  8
#
" /T /E /C /G
#
#  9
#
:F
#
# 10
#
ICACLS.EXE "
#
# 11
#
" /grant 
#
# 12
#
:F /T /C /Q
#
# 13
#
:F /C /Q
#
# 14
#
" /E /C /G 
#
# 15: Registry key name
#
SOFTWARE\\DKrause\\Shared\\dkwt
#
# 16: Registry value name: keep (for keep-directories flag)
#
keep
#
# 17: Text SID for Everyone user/group
#
S-1-1-0
#
# 18: Text SID for SYSTEM user/group
#
S-1-5-18
#
# 19: Registry key for profile list.
#
SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList
#
# 20: Backslash as separator.
#
\\
#
# 21: Registry enty name.
#
ProfileImagePath
$!end
};



/**	Subcommand names.
*/
static dkChar const * const	dkwt_commands[] = {
/*   0 */ dkT("boot"),
/*   1 */ dkT("shutdown"),
/*   2 */ dkT("login"),
/*   3 */ dkT("logout"),
/*   4 */ dkT("users"),
/*   5 */ dkT("groups"),
/*   6 */ dkT("printers"),
/*   7 */ dkT("print"),
/*   8 */ dkT("help"),
/*   9 */ dkT("version"),
/*  10 */ dkT("license-terms"),
/*  11 */ dkT("keep"),
/*  12 */ dkT("unkeep"),
/*  13 */ dkT("--help"),
/*  14 */ dkT("--version"),
/*  15 */ dkT("--license-terms"),
/*  16 */ dkT("--license"),
/*  17 */ dkT("license"),
/*  18 */ dkT("-h"),
/*  19 */ dkT("-v"),
/*  20 */ dkT("-L"),
/*  21 */ dkT("cleanup-profiles"),
/*  22 */ dkT("clp"),
/*  23 */ dkT("env"),
/*  24 */ dkT("environment"),
NULL
};



/**	Help file names.
*/
static dkChar const * const	dkwt_help_file_names[] = {
/*   0 */ dkT("dkwt-boot.txt"),
/*   1 */ dkT("dkwt-shutdown.txt"),
/*   2 */ dkT("dkwt-login.txt"),
/*   3 */ dkT("dkwt-logout.txt"),
/*   4 */ dkT("dkwt-users.txt"),
/*   5 */ dkT("dkwt-groups.txt"),
/*   6 */ dkT("dkwt-printers.txt"),
/*   7 */ dkT("dkwt-print.txt"),
/*   8 */ dkT("dkwt-help.txt"),
/*   9 */ dkT(""),	/* unused */
/*  10 */ dkT(""),	/* unused */
/*  11 */ dkT("dkwt-keep.txt"),
/*  12 */ dkT("dkwt-unkeep.txt"),
/*  13 */ dkT("dkwt-clp.txt"),
/*  14 */ dkT("dkwt-env.txt"),
NULL
};



/**	Help text for the boot command.
*/
static dkChar const * const	dkwt_help_boot[] = {
$!text	macro=dkT

NAME

  dkwt boot - Boot cleanup

SYNOPSIS
  
  dkwt boot [-t]

DESCRIPTION

The "dkwt boot" program should be run from the system boot script to do
cleanup at boot time in PC classrooms.

OPTIONS

-t
	Test mode. The program does not perform cleanup, it only writes
	messages about files and directories to delete.

EXIT STATUS

The exit status code is always 0, regardless of any error occured.

FILES

dkwt.conf
	Configuration file for cleanup operations.

	Run
		dkwt -h
	to view detailed information about the dkwt.conf file.

NOTES

After changing the dkwt.conf file you should run
  dkwt boot -t
to test the dkwt.conf file.

AUTHOR

Dirk Krause

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	Help text for the shutdown command.
*/
static dkChar const * const	dkwt_help_shutdown[] = {
$!text	macro=dkT

NAME

  dkwt shutdown - Shutdown cleanup

SYNOPSIS
  
  dkwt shutdown [-t]

DESCRIPTION

The "dkwt shutdown" program should be run from the system shutdown script to do
cleanup at shutdown time in PC classrooms.

OPTIONS

-t
	runs in test mode. The program does not perform cleanup, it only writes
	messages about files and directories to delete.

EXIT STATUS

The exit status code is always 0, regardless of any error occured.

FILES

dkwt.conf
	Configuration file for cleanup operations.
	Run
		dkwt -h
	to view detailed information about the dkwt.conf file.

NOTES

After changing the dkwt.conf file you should run
  dkwt shutdown -t
to test the dkwt.conf file.

AUTHOR

Dirk Krause

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	Help text for the login command.
*/
static dkChar const * const	dkwt_help_login[] = {
$!text macro=dkT

NAME

  dkwt login - Login cleanup

SYNOPSIS
  
  dkwt login [-t]

DESCRIPTION

The "dkwt login" program should be run from the user login script to do
cleanup at login time in PC classrooms.

OPTIONS

-t
	runs in test mode. The program does not perform cleanup, it only writes
	messages about files and directories to delete.

EXIT STATUS

The exit status code is always 0, regardless of any error occured.

FILES

dkwt.conf
	Configuration file for cleanup operations.
	Run
		dkwt -h
	to view detailed information about the dkwt.conf file.

NOTES

After changing the dkwt.conf file you should run
  dkwt login -t
to test the dkwt.conf file.

AUTHOR

Dirk Krause

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	Help text for the logout command.
*/
static dkChar const * const	dkwt_help_logout[] = {
$!text macro=dkT

NAME

  dkwt logout - Logout cleanup

SYNOPSIS
  
  dkwt logout [-t]

DESCRIPTION

The "dkwt logout" program should be run from the user logout script to do
cleanup at logout time in PC classrooms.

OPTIONS

-t
	runs in test mode. The program does not perform cleanup, it only writes
	messages about files and directories to delete.

EXIT STATUS

The exit status code is always 0, regardless of any error occured.

FILES

dkwt.conf
	Configuration file for cleanup operations.
	Run
		dkwt -h
	to view detailed information about the dkwt.conf file.

NOTES

After changing the dkwt.conf file you should run
  dkwt logout -t
to test the dkwt.conf file.

AUTHOR

Dirk Krause

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	Help text for the keep command.
*/
static dkChar const * const	dkwt_help_keep[] = {
$!text macro=dkT

NAME

  dkwt keep - Temporarily disable automatic cleanup

SYNOPSIS

  dkwt keep

DESCRIPTION

Use this program to disable automatic cleanup until (including) the next
user login.
You should use this command in lectures about system programming before
starting to test self-made system software, drivers...
Use the
  dkwt unkeep
command to restore normal automatic cleanup when you are done with the tests.

EXIT STATUS

0 on success, all other exit status codes indicate an error.

REGISTRY

The HKEY_LOCAL_MACHINE\SOFTWARE\DKrause\Shared\dkwt must exist, full access
must be possible for "Everyone" or "INTERACTIVE".

AUTHOR

Dirk Krause

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	Help text for the keep command.
*/
static dkChar const * const	dkwt_help_unkeep[] = {
$!text macro=dkT

NAME

  dkwt unkeep - Restore automatic cleanup

SYNOPSIS

  dkwt unkeep

DESCRIPTION

After disabling automatic cleanup temporarily using "dkwt keep" you can use
this command to restore normal automatic cleanup.

EXIT STATUS

0 on success, all other exit status codes indicate an error.

REGISTRY

The HKEY_LOCAL_MACHINE\SOFTWARE\DKrause\Shared\dkwt must exist, full access
must be possible for "Everyone" or "INTERACTIVE".

AUTHOR

Dirk Krause

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};


/**	Help text for the cleanup-profiles command.
*/
static dkChar const * const	dkwt_help_clp[] = {
$!text macro=dkT

NAME

  dkwt cleanup-profiles - Clean up profiles directories.

SYNOPSIS

  dkwt cleanup-profiles
  dkwt clp

DESCRIPTION

On Windows Vista and above we can not clean up profile directories
from boot/shutdown/logon/logoff scripts as these scripts are run from
a user account with insufficient permissions. User profiles cleanup
is skipped in "dkwt boot", "dkwt login", "dkwt logout", and "dkwt shutdown".

You can start a command prompt *as administrator* instead and run
"dkwt cleanup-profiles" from there.
The program first attempts to use system functions to delete
directories, additionally it uses the "RD" command.

Alternatively run "dkwtadm cleanup-profiles", this variant of dkwt uses
the UAC to obtain administrative permissions.

EXIT STATUS

0 on success, all other exit status codes indicate an error.

AUTHOR

Dirk Krause

HISTORY

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	Help text for dkwt env.
*/
static dkChar const * const	dkwt_help_env[] = {
$!text	macro=dkT

NAME

  dkwt env - Modify environment variables

SYNOPSIS

  dkwt env         [<options>] <name> [<value>]
  dkwt environment [<options>] <name> [<value>]

DESCRIPTION

This function can modify environment variables, both system and
user variables.
This function is mainly intended for environment variables storing
names of directories or files (i.e. the PATH variable).
You can make sure a directory is listed in a variable by inserting
or appending the directory only if it is not yet present.

OPTIONS

-s
	Process system environment variables.
	Without this option the program processes the user environment.

-e
	When creating a new registry value, use type REG_EXPAND_SZ
	instead of default REG_SZ.
	This option is ignored when processing existing registry values.

-u
	Delete registry value completely, unset variable.

-i
	Ensure the variable lists the specified directory or file,
	insert at start if not present.

-a
	Ensure the variable lists the specified directory or file,
	append at end if not present.

-d
	Remove a directory or file from a variable listing one
	or multiple directories or files.
	If the variable value is empty after removal, the registry
	value is deleted.

EXIT STATUS

0 on success, all other exit status codes indicate an error.

EXAMPLES

Show value of user environment variable TEMP:

	dkwt env TEMP

Show value of system environment variable PATH:

	dkwt env -s PATH

Completely delete user environment variable FOO:

	dkwt env -u FOO

Completely delete system environment variable BAR:

	dkwt env -s -u BAR

Set user environment variable FOO:

	dkwt env FOO All text after variable name goes into value

Set system environment variable BAR:

	dkwt env -s BAR Same procedure for system variables

Make sure system PATH contains ``C:\Program Files\Nice Program''
(insert at start if not present):

	dkwt env -s -i Path C:\Program Files\Nice Program

Make sure system PATH contains ``C:\Program Files\Other Program''
(append at end if not present):

	dkwt env -s -a Path C:\Program Files\Other Program

Remove ``C:\Program Files\Nice Program'' from system PATH:

	dkwt env -s -d Path C:\Program Files\Nice Program

NOTES

``dkwt env'' does not change environment variables in cmd.exe windows
already opened.

AUTHOR

Dirk Krause

HISTORY

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	Help text for the users command.
*/
static dkChar const * const	dkwt_help_users[] = {
$!text macro=dkT

NAME

  dkwt users - List users

SYNOPSIS

  dkwt users [<option>]

DESCRIPTION

The program lists the users configured on the system.

OPTIONS

-l
	creates a long (detailed) listing.

-s
	creates a short listing (just the user names).

Either -l or -s can be used, not both.

EXIT STATUS

0 on success, all other exit status codes indicate an error.

AUTHOR

Dirk Krause

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	Help text for the groups command.
*/
static dkChar const * const	dkwt_help_groups[] = {
$!text macro=dkT

NAME

  dkwt groups - List groups

SYNOPSIS

  dkwt groups <option>

DESCRIPTION

The command lists the group on the current system.

OPTIONS

-l
	creates a long (detailed) listing.

-s
	creates aa short listing (just the group names).

The options -l and -s can not be used together.

EXIT STATUS

0 on success, all other exit status codes indicate an error.

AUTHOR

Dirk Krause

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	Help text for dkwt help printers.
*/
static dkChar const * const	dkwt_help_printers[] = {
$!text macro=dkT

NAME

  dkwt printers - List printers

SYNOPSIS

  dkwt printers [<option>]

DESCRIPTION

The command lists the printers installed on the system.

OPTIONS

-l
	creates a long (detailed) listing. Without this option the listing
	only shows the printer names.

EXIT STATUS

0 on success, all other exit status codes indicate an error.

AUTHOR

Dirk Krause

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};


/**     Help text for the print command.
*/
static dkChar const * const	dkwt_help_print[] = {
$!text macro=dkT

NAME

  dkwt print - Print a file

SYNOPSIS

  dkwt print [<option>] [<file(s)>]

DESCRIPTION

The program prints the specified files or the contents read from standard
input if no file name is specified.

OPTIONS

-d <device>
	chooses a printer by the device name. The device name must be specified
	here, not the printer name.
	Without this option the system's default printer is used.

EXIT STATUS

0 on success, all other exit status codes indicate an error.

AUTHOR

Dirk Krause

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	General help text.
*/
static dkChar const * const	dkwt_help_help[] = {
$!text macro=dkT

NAME

  dkwt - Dirk Krause's Windows tool

SYNOPSIS

  dkwt users    [<option(s)>]
  dkwt groups   [<option(s)>]
  dkwt printers [<option(s)>]
  dkwt print    [<option(s)>] [<file(s)>]
  dkwt boot
  dkwt login
  dkwt logout
  dkwt shutdown
  dkwt keep
  dkwt unkeep
  dkwt cleanup-profiles
  dkwt env [<options>] <name> [<value>]
  dkwt help     <command>
  dkwt -h
  dkwt -v
  dkwt -L

DESCRIPTION

dkwt users		lists the users.
dkwt groups		lists the user groups.
dkwt printers		lists the available printers.
dkwt print		prints the specified file(s).
dkwt boot		does cleanup during boot.
dkwt login		does cleanup during user login.
dkwt logout		does cleanup during user logout.
dkwt shutdown		does cleanup during shutdown.
dkwt keep		disables automatic cleanup temporarily until
			the next user login is completed.
dkwt unkeep		restores normal cleanup mechanisms.
dkwt cleanup-profiles   cleans up user profiles.
dkwt help <command>	prints a help text for a specific command.
dkwt -h			shows this help text.
dkwt -v			shows version information.
dkwt -L			shows the license conditions.

The boot, login, logout, shutdown, keep, and unkeep commands are intended for
use in PC classrooms, see NOTES below.

OPTIONS

-s
	switches to short listings for the users, and groups command.

-l
	switches to long (detailed) listings for users, groups, and
	printers command.

-d <device>
	chooses the printer for the print command.

EXIT STATUS

0 on success, all other exit status codes indicate an error.

FILES

dkwt.conf
	The dkwt.conf file is used to configure automatic cleanup for the boot,
	login, logout, shutdown, and cleanup-profiles command.
	The file should be placed in "C:\Program Files\Krause\etc\dktools-site"
	or "C:\Program Files (x86)\Krause\etc\dktools-site" depending on your
	Windows version (32 or 64 bit).
	The file consists of three sections: "options", "public", and
	"profiles".

	In the options section you can configure the name for the "System"
	and "Everyone" account, the name differs depending on the language
	configured for your system. These settings are optional, the program
	retrieves the names for SIDs "S-1-5-18" and "S-1-1-0" if the settings
	are omitted.

	In the public section you can list public writable directories to
	be cleaned up automatically.

	In the start of the profiles section you configure the profile base
	directory (the parent directory where the profile directories live in).
	Each section line lists one directory to be left untouched by
	automatic cleanup.
	NOTE: On Windows 7 I do not recommend to manage user profile directories
	using dkwt. Use the group policy configured in gpedit.msc to remove
	expired user profiles instead. Just omit the "[profiles...]" section.

	Example:

		[options]
		system user	=	System
		everyone user	=	Everyone

		[public]
		c:\temp
		c:\lecture

		[profiles C:\Users]
		All Users
		Default User
		Public
		Administrator
		admin
		sshd_server

NOTES

The boot, login, logout, shutdown, and cleanup-profiles commands are
intended for use in computer classrooms and other educational environments.
We assume the following:
- User accounts are managed centrally, i.e. in AD or a Windows domain.
  There is only a few local accounts on each system required by the Windows
  system itself or by services running.
- Each "normal" user has a home directory on a file server.
- Typically all users in a class room log in and out nearly at the same time
  (begin and end of a lecture).
For the following reasons we do not store user profiles on a file server:
- Large parts of the user profile are not related to the lectures, saving
  them on a file server would be waste of disk space.
  Although Windows allows you to exclude profile subdirectories from
  profile replication we don't want to use this feature. Blacklist mechanisms
  require research for new directories to exclude after each software
  installation or update.
- Due to the simultaneous login and logout of all users there would be
  load peaks on server and networks on begin and end of lectures significantly
  higher than average load.
So we use a setup as follows:
- In the group policies we allow local user profiles only, profile
  synchronization or propagation to the server is disabled.
- During the lectures users write data to a public writable directory, i.e.
  C:\Temp or C:\Lecture. At the end of the lecture they save valuable data
  to the home directory or to private storage media (i.e. USB device).
  After saving the data the users deletes all contents he created in the
  public writable directory.
- During logout a logout script is run. This script first changes the
  permissions to all contents still found in the public writable directories
  to grant full access for everyone. Next it attempts to remove the contents.
  The same is done for the users home directory.
- Not all contents can be deleted during logout as some files still might be
  in use (i.e. the HKCU registry hive file in the user profile). So we attempt
  to delete these contents again at the next users login, at shutdown and
  at next reboot.
To have this cleanup automatically we add
  dkwt boot
to the system boot script,
  dkwt login
to the user login script,
  dkwt logout
to the user logout script, and
  dkwt shutdown
to the system shutdown script.

On Windows Vista and above the boot, login, logout, and shutdown commands
do not attempt to clean up user profiles. Login scripts here do not
have sufficient permissions to clean up. You can start the command
prompt as administrator and run "dkwt cleanup-profiles" manually instead.

Lectures about system programming (i.e. "How do I build a driver?") need a
special setup. When testing self-made system software the system may crash
or hang, so a reboot with a new login will be necessary.
We need to deactivate the automatic cleanup, otherwise all changes we made
in the public writable directories would be lost.
Before starting experiments we run
  dkwt keep
to disable automatic cleanup temporarily until the next user login is finished.
If all experiments succeeded we can run
  dkwt unkeep
after saving all our changes before logging off.
The HKEY_LOCAL_MACHINE\SOFTWARE\DKrause\Shared\dkwt must exist, full access
must be possible for "Everyone" or "INTERACTIVE".

AUTHOR

Dirk Krause

HISTORY

COPYRIGHT AND LICENSE

Run
  dkwt --license-terms
to see the license conditions.

SEE ALSO

http://sourceforge.net/p/dktools/wiki/dkwt/

$!end
};



/**	Application group name.
*/
static dkChar const dkwt_group_name[] = { dkT("dktools") };



/**	Print help text.
	@param	app	Application structure.
	@param	topic	Help topic ID.
	@return	1 on success, 0 on error.
*/
static
int
dkwt_help(
  dk3_app_t		*app,
  int			 topic
)
{
  switch(topic) {
    case  0: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_boot);
    } break;
    case  1: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_shutdown);
    } break;
    case  2: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_login);
    } break;
    case  3: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_logout);
    } break;
    case  4: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_users);
    } break;
    case  5: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_groups);
    } break;
    case  6: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_printers);
    } break;
    case  7: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_print);
    } break;
    case  8: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_help);
    } break;
    case 11: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_keep);
    } break;
    case 12: {
      dk3app_help(app, dkwt_help_file_names[topic], dkwt_help_unkeep);
    } break;
    case 21: case 22: {
      dk3app_help(app, dkwt_help_file_names[13], dkwt_help_clp);
    } break;
    case 23: case 24: {
      dk3app_help(app, dkwt_help_file_names[14], dkwt_help_env);
    } break;
  }
  return 0;
}



/**	The main function.
	@param	argc	Number of command line arguments.
	@param	argv	Command line arguments array.
	@return	0 on success, any other value indicates an error.
*/
DK3_MAIN
{
  int exval = DKT_RESULT_ERR_UNSPECIFIC;
  dk3_app_t		*app = NULL;
  dkChar const * const	*msg = NULL;
  int			 xargc = 0;
  int			 topic = 0;
  dkChar const * const	*xargv = NULL;
  $!trace-init dkwt.deb
  $? "+ main"
  if((sizeof(dkChar) != 2) || (sizeof(TCHAR) != 2)) {
    fprintf(stderr, "Wrong compiler options were used to build this program!\n");
    fprintf(stderr, "Size of dkChar: %u\n", (unsigned)sizeof(dkChar));
    fprintf(stderr, "Size of TCHAR:  %u\n", (unsigned)sizeof(TCHAR));
    fprintf(stderr, "Please re-compile with -DDK3_CHAR_SIZE=2 -D_UNICODE=1\n");
    fflush(stderr);
    exit(DKT_RESULT_ERR_UNSPECIFIC);
  }
  app = dk3app_open_command(
    argc, (dkChar const * const *)argv, dkwt_group_name
  );
  if(app) {
    msg = dk3app_messages(
      app, dkwt_string_table_file_name, (dkChar const **)dkwt_message_texts
    );
    xargc = dk3app_get_argc(app);
    xargv = dk3app_get_argv(app);
    if(xargc > 1) {
      switch(dk3str_array_index(dkwt_commands, xargv[1], 0)) {
        case 0: {	$? ". boot"
	  exval = dkwt_event(app, msg, dkwt_no_loc, 0);
	} break;
	case 1: {	$? ". shutdown"
	  exval = dkwt_event(app, msg, dkwt_no_loc, 1);
	} break;
	case 2: {	$? ". login"
	  exval = dkwt_event(app, msg, dkwt_no_loc, 2);
	} break;
	case 3: {	$? ". logout"
	  exval = dkwt_event(app, msg, dkwt_no_loc, 3);
	} break;		
	case 4: {	$? ". accounts"
	  exval = dkwt_accounts(app, msg, dkwt_no_loc);
	} break;
	case 5: {
	  exval = dkwt_groups(app, msg, dkwt_no_loc);
	} break;
	case 6: {
	  exval = dkwt_printers(app, msg, dkwt_no_loc);
	} break;
	case 7: {
	  exval = dkwt_print(app, msg, dkwt_no_loc);
	} break;
	case 8: case 13: case 18: {
	  topic = 8;
	  if(xargc > 2) {
	    topic = dk3str_array_index(dkwt_commands, xargv[2], 0);
	    if(topic < 0) topic = 8;
	  }
	  exval = dkwt_help(app, topic);
	} break;
	case 9: case 14: case 19: {	/* version */
	  dk3sf_initialize_stdout();
	  dk3sf_fputs(dkwt_version, stdout);
	  dk3sf_fputc(dkT('\n'), stdout);
	} break;
	case 10: case 15: case 16: case 17: case 20: {	/* license */
	  dkChar const * const *sptr;
	  sptr = dkwt_license;
	  dk3sf_initialize_stdout();
	  while(*sptr) {
	    dk3sf_fputs(*(sptr++), stdout);
	    dk3sf_fputc(dkT('\n'), stdout);
	  }
	} break;
	case 11: {
	  exval = dkwt_event_keep(app, msg, dkwt_no_loc);
	} break;
	case 12: {
	  exval = dkwt_event_unkeep(app, msg, dkwt_no_loc);
	} break;
	case 21: case 22: {
	  exval = dkwt_event(app, msg, dkwt_no_loc, 4);
	} break;
	case 23: case 24: {
	  exval = dkwt_env(app, msg, dkwt_no_loc);
	} break;
      }
    }
    dk3app_close(app);
  } else {
    fprintf(stderr, "ERROR: Not enough memory!\n");
    fflush(stderr);
  }
  $? "- main %d", exval
  $!trace-end
  fflush(stdout);
  exit(exval); return exval;
}