-
Notifications
You must be signed in to change notification settings - Fork 9
/
DNXDOScript2.0.cmd
1061 lines (972 loc) · 29.4 KB
/
DNXDOScript2.0.cmd
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
@echo off
setlocal enableextensions enabledelayedexpansion
cd /d "%~dp0"
pushd "%~dp0"
cls
set iXCMD=%1
if "_%iXCMD%"=="_" set iXCMD=0
if %iXCMD%==0 (
echo Re-Launching script with necessary environment setup [Admin and Unrestricted Execution Policy]
set "myF=%~dpnx0"
call :stringPS "!myF!" xRun
rem echo xRun=!xRun!
set "PSRun=powershell -ExecutionPolicy Unrestricted Start-Process powershell -Verb "runAs '!xRun! 1'""
rem echo PSRun=!PSRun!
!PSRun!
goto :ToEnd2
)
rem call :write "ExecutionPolicy: "
rem powershell get-ExecutionPolicy
set bDebug=0
:: Not necessary to check admin.
:: goto :isAdmin2
:: :IsAdminBack
call :InitScript "%0"
Goto :ToStartScript
:: your code must start on ToStartScript label.
:: ================================================================================================
:: ================================================================================================
:: ================================================================================================
:: __________________________________________________________________ Sub isAdmin
:: Check if the current run environment is admin. Need to create ":IsAdminBack" label to return
:isAdmin :{
setlocal disableDelayedExpansion
set myP0=%~1
set myRC=0
net session >nul 2>&1
if %errorLevel% == 0 (
rem echo Success: Administrative permissions confirmed.
set myRC=1
) else (
rem echo Failure: Current permissions inadequate.
set myRC=0
echo "%~0" "%~1" "%~2">%temp%\DNXMainTemp.cmd
set "myPS=powershell Start-Process powershell -Verb "runAs %temp%\DNXMainTemp.cmd""
call %%myPS%%
goto :eof
)
(
endlocal
goto :IsAdminBack
)
:}
:: __________________________________________________________________ sub InitScript
:: Main Initialization routine
:InitScript param0 :{
set mySFN=%~1
call :InitColors
call :writeInitialize
(
exit /b)
:}
:: __________________________________________________________________ sub InitColors
:: Initialize color variables
:InitColors :{
set cReset=[0m
set cBold=[1m
set cUnder=[4m
set cInv=[7m
set caBLACK=0
set caRED=1
set caGREEN=2
set caYELLOW=3
set caBLUE=4
set caMAGENTA=5
set caCYAN=6
set caWHITE=7
set caTEST=88
set coFORE=3
set coNORMAL=3
set coFORENORMAL=3
set coBACK=4
set coBACKNORMAL=4
set coFORESTRONG=9
set coBACKSTRONG=10
set cTAFore=Yellow
set cTAForeType=STRONG
set cTABack=Red
set cTABackType=NORMAL
:: standard colors for powershell window
set cDeFore=white
set cDeType=normal
set cDeBack=blue
set cdeBackType=normal
(
exit /b)
:}
:: __________________________________________________________________ sub InitColors
:: Set string to be printed in colors
:cText varText {outVar} [foreColor] [forType] [backColor] [backType] :{
setlocal disableDelayedExpansion
set myV1=%3
set myVS1=%4
set myV2=%5
set myVS2=%6
rem if "_%myV1%"=="_" set myV1=%cDeFore%
rem if "_%myVS1%"=="_" set myVS1=%cDeType%
rem if "_%myV2%"=="_" set myV2=%cDeBack%
rem if "_%myVS2%"=="_" set myVS2=%cDeBackType%
if defined ca%myV1% (
if /I "_%myVS1%" EQU "_strong" (
call set xFCol=9%%ca%myV1%%%
) else (
call set xFCol=3%%ca%myV1%%%
)
) else (
rem set xFCol=3%caWHITE%
)
if defined ca%myV2% (
if /I "_%myVS2%" EQU "_strong" (
call set xBCol=10%%ca%myV2%%%
) else (
call set xBCol=4%%ca%myV2%%%
)
) else (
rem set xFCol=3%caWHITE%
)
rem set myXCol=%xBCol%;%xFCol%
set iCC=0
if "_%xFCol%" NEQ "_" set /a iCC+=1
if "_%xBCol%" NEQ "_" set /a iCC+=1
if %iCC% == 2 (
set myXCol=%xBCol%;%xFCol%
) else (
set myXCol=%xBCol%%xFCol%
)
set rcVar=[%myXCol%m%~1[0m
if %bDebug%==1 (
echo ====== sub cText [%1] [%2] [%3] [%4] [%5] [%6]
echo * xBCol =%xBCol%
echo * xFCol =%xFCol%
echo * myXCol =%myXCol%
echo * rcVar =%rcVar%
)
(
endlocal
set %2=%rcVar%
exit /b)
:}
:: __________________________________________________________________ sub cTextAlert
:: Quick set alert color for string text
:cTextAlert varText {outVar} [forecolor] [fortype] [backcolor] [backtype] :{
set myT=%~1
set myV1=%3
set mySV1=%4
set myV2=%5
set mySV5=%6
if "_%myV1%" NEQ "_" (
set cTAFore=%myV1%
)
if "_%mySV1%" NEQ "_" (
set cTAForeType=%mySV1%
)
if "_%myV2%" NEQ "_" (
set cTABack=%myV2%
)
if "_%mySV2%" NEQ "_" (
set cTABackType=%mySV2%
)
call :cText "%myT%" %cTAFore% %cTAForeType% %cTABack% %cTABackType% rcVar
(
endlocal
set %2=%rcVar%
exit /b)
:}
:: __________________________________________________________________ sub swriteXY
:: print text on X,Y position
:writeXY X Y text :{
setlocal disableDelayedExpansion
FOR /F %%A in ('ECHO prompt $E^| cmd') DO SET "ESC=%%A"
rem <NUL SET /P "=%ESC%[4;6HBye"
<NUL SET /P "=%ESC%[%2;%1H%~3"
(
endlocal
exit /b)
:}
:: __________________________________________________________________ sub getFolderName
:: Get the parent folder from some file
:getFolderName somePath {outVar} :{
setlocal enableextensions enabledelayedexpansion
SET CDIR=%~dp1
SET _CDIR=%CDIR:~1,-1%
for %%i in ("%_CDIR%") do SET FolderName=%%~nxi
(
endlocal
set %2=%FolderName%
exit /b
)
:}
:: __________________________________________________________________ sub sTrim
:: Clear string spaces from left and right
:sTrim strIn {outVar} :{
setlocal enableextensions enabledelayedexpansion
set str=%~1&rem
call :sTrimL "%str%" strRC
call :sTrimR "%strRC%" strRC2
(
endlocal
set %2=%strRC2%
exit /b
)
:}
:: __________________________________________________________________ sub sTrimL
:: Clear string spaces from left
:sTrimL strIn {outVar} :{
setlocal enableextensions enabledelayedexpansion
set str=%~1&rem
for /l %%a in (1,1,31) do if "!str:~-1!"==" " set str=!str:~0,-1!
(
endlocal
set %2=%str%
exit /b
)
:}
:: __________________________________________________________________ sub sTrimR
:: Clear stringspaces from right
:sTrimR strIn {outVar} :{
setlocal enableextensions enabledelayedexpansion
set str=%~1&rem
for /f "tokens=* delims= " %%a in ("%str%") do set str=%%a
(
endlocal
set %2=%str%
exit /b
)
:}
:: __________________________________________________________________ sub sSplit
:: split variable string by token
:sSplit sVar sToken {outVar1} {outvar2} {outvar3}...{outvar7} :{
setlocal enableextensions enabledelayedexpansion
set tVar=%~1
set tToken=%~2
set tMaxSplit=6
if not defined tMaxSplit set tMaxSplit=9
set iCount=0
set iCountb=-1
set lPos=-1
call :strLen "%tToken%" tTokenLen
call :inStr "%tVar%" "%tToken%" 0 lPos
call set aa=%%tVar:~-%tTokenLen%%%
if "_%aa%" NEQ "_%tToken%" (
rem echo adding token
set tVar=%tVar%%tToken%
)
rem echo tTokenLen=%tTokenLen%
rem echo aa=%aa%.
rem echo tToken=%tToken%.
rem echo tVar=%tVar%.
rem pause
:loopsSplit
set /a iCount+=1
set /a iCountb+=1
set sVar=%tVar:~0,!lPos!%
set /a lPosb=!lPos!-1
set /a lPosDif=!lPosb!+tTokenLen
call set vVar=%%tVar:~0,!lPosb!%%
call set tVar=%%tVar:~!lPosDif!,1000%%
call :inStr "%tVar%" "%tToken%" 0 lPos
if !iCount! GTR %tMaxSplit% (
set tmp_!iCount!=%vVar%%tToken%%tVar%
goto :loopsSplitExit
) else (
set tmp_!iCount!=%vVar%
)
if %bDebug%==10 (
echo ==== Debug sSplit
echo * iCount =%iCount%
echo * var1 =%~1
echo * vVar =%vVar%
echo * tVar =%tVar%
echo * tmp_1 =%tmp_1%
echo * tmp_2 =%tmp_2%
echo * tmp_3 =%tmp_3%
echo * tmp_4 =%tmp_4%
echo * tmp_5 =%tmp_5%
echo * tmp_6 =%tmp_6%
echo * tmp_7 =%tmp_7%
pause
)
if "_%tVar%" NEQ "_" goto :loopsSplit
:loopsSplitExit
(
endlocal
if "_%3" NEQ "_" set %3=%tmp_1%
if "_%4" NEQ "_" set %4=%tmp_2%
if "_%5" NEQ "_" set %5=%tmp_3%
if "_%6" NEQ "_" set %6=%tmp_4%
if "_%7" NEQ "_" set %7=%tmp_5%
if "_%8" NEQ "_" set %8=%tmp_6%
if "_%9" NEQ "_" set %9=%tmp_7%
exit /b
)
:}
:: __________________________________________________________________ sub sSplit5
:: updated split routine
:sSplit5 strVar stToken {outVar1} {outVar2} ... {outVar7} :{
setlocal enableDelayedExpansion
set sTxt=%~1
set sTkn=%~2
set iCount=0
call :strLen "%sTkn%" lTkn
rem set "stxt=uno_dos_tres_cuatro"
:loopsSplit5
call set "strR=%%sTxt:*%sTkn%=%%"
call set "strL=%%stxt:%strR%=%%"
if "_%strL%" NEQ "_" (
call set "strL=%%strL:~0,-%lTkn%%%"
)
rem echo lTkn=%lTkn%
rem echo sTxt=%sTxt%
rem echo strR=%strR%
rem echo strL=%strL%
set "sTxt=%strR%"
set /a iCount+=1
if "_%strL%" NEQ "_" (
set "xOut!icount!=%strL%"
rem call echo xOut!icount!=%%xOut!icount!%%
Goto :loopsSplit5
)
set "xOut!icount!=%strR%"
(
endlocal
if "%3" NEQ "" set "%3=%xOut1%"
if "%4" NEQ "" set "%4=%xOut2%"
if "%5" NEQ "" set "%5=%xOut3%"
if "%6" NEQ "" set "%6=%xOut4%"
if "%7" NEQ "" set "%7=%xOut5%"
if "%8" NEQ "" set "%8=%xOut6%"
if "%9" NEQ "" set "%9=%xOut7%"
exit /b
)
:}
:: __________________________________________________________________ sub sSplitB
:: take the first character on the input parameter and assign as splitter token
:sSplitB sToken+strIn {outVar} :{
setlocal enableextensions enabledelayedexpansion
set tVar=%~1
set tToken=%tVar:~0,1%
set tVar=%tVar:~1,1000%
set tMaxSplit=7
if not defined tMaxSplit set tMaxSplit=9
set iCount=0
set iCountb=-1
set lPos=-1
call :strLen "%tToken%" tTokenLen
call :inStr "%tVar%" "%tToken%" tTokenLen lPos
:loopsSplitB
set /a iCount+=1
set /a iCountb+=1
set sVar=%tVar:~0,!lPos!%
set /a lPosb=!lPos!-1
set /a lPosDif=!lPosb!+tTokenLen
call set vVar=%%tVar:~0,!lPosb!%%
call set tVar=%%tVar:~!lPosDif!,1000%%
if !iCount! GTR %tMaxSplit% (
set tmp_!iCount!=%vVar%%tToken%%tVar%
goto :loopsSplitExitB
) else (
set tmp_!iCount!=%vVar%
)
if %bDebug%==10 (
echo ==== Debug sSplit
echo * iCount =%iCount%
echo * var1 =%~1
echo * vVar =%vVar%
echo * tVar =%tVar%
echo * lPos =!lPos!
echo * tmp_1 =%tmp_1%
echo * tmp_2 =%tmp_2%
echo * tmp_3 =%tmp_3%
echo * tmp_4 =%tmp_4%
echo * tmp_5 =%tmp_5%
echo * tmp_6 =%tmp_6%
echo * tmp_7 =%tmp_7%
pause
)
call :inStr "%tVar%" "%tToken%" 0 lPos
if !lPos! NEQ 0 goto :loopsSplitB
:loopsSplitExitB
if "_%tVar%" NEQ "" (
set /a iCount+=1
set tmp_!iCount!=%tVar%
)
(
endlocal
if "_%2" NEQ "_" set %2=%tmp_1%
if "_%3" NEQ "_" set %3=%tmp_2%
if "_%4" NEQ "_" set %4=%tmp_3%
if "_%5" NEQ "_" set %5=%tmp_4%
if "_%6" NEQ "_" set %6=%tmp_5%
if "_%7" NEQ "_" set %7=%tmp_6%
if "_%8" NEQ "_" set %8=%tmp_7%
if "_%9" NEQ "_" set %9=%tmp_8%
exit /b
)
:}
:: __________________________________________________________________ sub CreateShortCut
:: Create a shortcut
:CreateShortCut sDest sPath sTitle sArgs sIcon sINum :{
setlocal enableextensions enabledelayedexpansion
rem oLink.TargetPath
rem oLink.Arguments
rem oLink.Description
rem oLink.HotKey
rem oLink.IconLocation
rem oLink.WindowStyle
rem oLink.WorkingDirectory
rem oLink.Save
set sDest=%~1
set sPath=%~2
set sTitle=%~3
set sArgs=%~4
set sIcon=%~5
set sWork=%~dp1
set SCRIPT="%TEMP%\DNSPScriptCreateSC-%RANDOM%%RANDOM%%RANDOM%%RANDOM%.vbs"
call :checkDIRF "%sPath%" sPath
if %bDebug%==4 (
echo * sDest =%sPath%
echo * sPath =%sPath%
echo * sTitle =%sTitle%
echo * sArgs =%sArgs%
echo * sIcon =%sIcon%
echo * sWork =%sWork%
echo * SCRIPT =%SCRIPT%
)
rem Creating File
echo Set oWS = WScript.CreateObject("WScript.Shell") > %SCRIPT%
echo sLinkFile = "%sPath%%sTitle%.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "%sDest%" >> %SCRIPT%
echo oLink.Arguments = "%sArgs%" >> %SCRIPT%
echo oLink.WorkingDirectory = "%sWork%" >> %SCRIPT%
echo oLink.IconLocation = "%sIcon%" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%
(
endlocal
exit /b
)
:}
:: __________________________________________________________________ sub inStr
:: search string into another string
:inStr strVar strF stAt {outVar} :{
rem example:
rem call :inStr %RootPath%New New 0 Var3
setlocal enabledelayedexpansion
if %bDebug%==6 echo inStr [%1] [%2] [%3] [%4] [%5]
rem @echo on
set str1=%~1
set sstr=%~2
set stAt=%3
rem set /a stAt=%stAt%-1
call :strlen "%str1%" len1
call :strlen "%sstr%" len2
set /a stop=len1-len2
set fpos=0
if %bDebug%==6 (
echo ==== Debug inStr
echo * str1 =%str1%
echo * sstr =%sstr%
echo * stAt =%stAt%
echo * len1 =%len1%
echo * len2 =%len2%
echo * stop =%stop%
)
if %stop% gtr 0 for /l %%i in (%stAt%,1,%stop%) do (
if "!str1:~%%i,%len2%!"=="%sstr%" (
set /a position=%%i+1
goto ExitinStr1
)
)
:ExitinStr1
if defined position (
set fpos=%position%
) else (
set fpos=0
)
(
endlocal
set %4=%fpos%
exit /b
)
:}
:: __________________________________________________________________ checkDIRF
:: check if the argument (must be an directory) ends with "\"
:checkDIRF strVar {outVar} :{
setlocal enableextensions enabledelayedexpansion
set mySV=%~1
call :strLen "%mySV%" mySVLen
rem start counting from zero
set /a mySVLen=%mySVLen%-1
set mySVLen=%mySVLen%
call set myLL=%%mySV:~%mySVLen%,1%%%
if "_%myLL%" NEQ "_\" (
set sRC=%mySV%\
) else (
set sRC=%mySV%
)
(
endlocal
set %2=%sRC%
exit /b
)
:}
:: __________________________________________________________________ Sub IsFile
:: Check if the argument is a file or directory (must exist)
:IsFile strVar {outVar} :{
SETLOCAL ENABLEEXTENSIONS
set ATTR=%~a1
set DIRATTR=%ATTR:~0,1%
if /I "%DIRATTR%"=="d" (
set sRC=DIR
) else (
set sRC=FILE
)
(
endlocal
set %2=%sRC%
exit /b
)
:}
:: __________________________________________________________________ Sub strLen
:: Get the lenght of a string
:strLen strVar {outVar} :{
(
setlocal EnableDelayedExpansion
rem (set^ xtmp="!%~1!")
set "xtmp=%~1"
rem echo var1=%1
rem echo var1b=%~1
rem echo xtmp=!xtmp!
rem pause
if defined xtmp (
set "len=1"
for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!xtmp:~%%P,1!" NEQ "" (
set /a "len+=%%P"
set "xtmp=!xtmp:~%%P!"
)
)
) ELSE (
set len=0
)
)
(
endlocal
set "%~2=%len%"
exit /b
)
:}
:: __________________________________________________________________ sub Write
:: Write a string without return line, stripping quotes
:write strVar :{
setlocal disableDelayedExpansion
::
:: Write the literal string Str to stdout without a terminating
:: carriage return or line feed. Enclosing quotes are stripped.
::
:: This routine works by calling :writeVar
::
set "strVar=%~1"
set "strLen=%~2"
call :writeVar strVar strLen
endlocal
(
exit /b
)
:}
:: __________________________________________________________________ sub WriteVar
:: Write a string without return line
:writeVar strVar :{
if not defined %~1 exit /b
setlocal enableDelayedExpansion
::
:: Writes the value of variable StrVar to stdout without a terminating
:: carriage return or line feed.
::
:: The routine relies on variables defined by :writeInitialize. If the
:: variables are not yet defined, then it calls :writeInitialize to
:: temporarily define them. Performance can be improved by explicitly
:: calling :writeInitialize once before the first call to :writeVar
::
if not defined $write.sub call :writeInitialize
set $write.special=1
if "!%~1:~0,1!" equ "^!" set "$write.special="
for /f delims^=^ eol^= %%A in ("!%~1:~0,1!") do (
if "%%A" neq "=" if "!$write.problemChars:%%A=!" equ "!$write.problemChars!" set "$write.special="
)
if not defined $write.special (
<nul set /p "=!%~1!"
exit /b
)
>"%$write.temp%_1.txt" (echo !str!!$write.sub!)
copy "%$write.temp%_1.txt" /a "%$write.temp%_2.txt" /b >nul
type "%$write.temp%_2.txt"
del "%$write.temp%_1.txt" "%$write.temp%_2.txt"
set "str2=!str:*%$write.sub%=%$write.sub%!"
if "!str2!" neq "!str!" <nul set /p "=!str2!"
endlocal
(
exit /b
)
:}
:: __________________________________________________________________ sub writeInitialize
:: Write function initialization
:writeInitialize :{
::
:: Defines 3 variables needed by the :write and :writeVar routines
::
:: $write.temp - specifies a base path for temporary files
::
:: $write.sub - contains the SUB character, also known as <CTRL-Z> or 0x1A
::
:: $write.problemChars - list of characters that cause problems for SET /P
:: <carriageReturn> <formFeed> <space> <tab> <0xFF> <equal> <quote>
:: Note that <lineFeed> and <equal> also causes problems, but are handled elsewhere
::
set "$write.temp=%temp%\writeTemp%random%"
copy nul "%$write.temp%.txt" /a >nul
for /f "usebackq" %%A in ("%$write.temp%.txt") do set "$write.sub=%%A"
del "%$write.temp%.txt"
for /f %%A in ('copy /z "%~f0" nul') do for /f %%B in ('cls') do (
set "$write.problemChars=%%A%%B ""
REM the characters after %%B above should be <space> <tab> <0xFF>
)
(
exit /b
)
:}
:: __________________________________________________________________ sub stringPS
:: Replace spaces on string, adding a ` character, to be used on powershell parameters
:stringPS strVar {outVar} :{
setlocal enableextensions enabledelayedexpansion
set var1=%~1
set varRC=%var1: =` %
(
endlocal
set %2=%varRC%
exit /b
)
:}
:: __________________________________________________________________ sub LoCase
:: Subroutine to convert a variable VALUE to all lower case.
:LoCase strVar {outVar} :{
set myV=%~1
FOR %%i IN ("A=a" "B=b" "C=c" "D=d" "E=e" "F=f" "G=g" "H=h" "I=i" "J=j" "K=k" "L=l" "M=m" "N=n" "Ñ=ñ" "O=o" "P=p" "Q=q" "R=r" "S=s" "T=t" "U=u" "V=v" "W=w" "X=x" "Y=y" "Z=z") DO (
CALL SET "myV=%%myV:%%~i%%"
)
(
set %2=%myV%
exit /b
)
:}
:: __________________________________________________________________ sub UpCase
:: Subroutine to convert a variable VALUE to all UPPER CASE.
:UpCase strVar {outVar} :{
set myV=%~1
FOR %%i IN ("a=A" "b=B" "c=C" "d=D" "e=E" "f=F" "g=G" "h=H" "i=I" "j=J" "k=K" "l=L" "m=M" "n=N" "o=O" "p=P" "q=Q" "r=R" "s=S" "t=T" "u=U" "v=V" "w=W" "x=X" "y=Y" "z=Z") DO (
CALL SET "myV=%%myV:%%~i%%"
)
(
set %2=%myV%
exit /b
)
:}
:: __________________________________________________________________ sub TCase
:: Subroutine to convert a variable VALUE to Title Case.
:TCase strVar {outVar} :{
set myV=%~1
call :LoCase "%myV%" myV
set myV= %myV%
FOR %%i IN (" a= A" " b= B" " c= C" " d= D" " e= E" " f= F" " g= G" " h= H" " i= I" " j= J" " k= K" " l= L" " m= M" " n= N" " o= O" " p= P" " q= Q" " r= R" " s= S" " t= T" " u= U" " v= V" " w= W" " x= X" " y= Y" " z= Z") DO (
CALL SET "myV=%%myV:%%~i%%"
)
set myV=%myV:~1,1000%
(
set %2=%myV%
exit /b
)
:}
:: __________________________________________________________________ sub EndMessage
:: write a standard exit message from the script
:EndMessage :{
echo No olvides visitarnos en:
echo Portable Master Race (ESP) https://t.me/gpdwinhispano
echo Deen0X's Blog: https://www.deen0x.com
echo DNX Projects: https://github.com/Deen0x
echo Zalu2^^!
echo Have a nice day!
(
exit /b
)
:}
:: __________________________________________________________________ sub writeL
:: Write a string without return line, stripping quotes, adding spaces up to len specified
:writeL strVar [strLen] [strText2] :{
setlocal enableDelayedExpansion
set "sVar=%~1"
set lVar=%2
if "_%2" NEQ "_" (
set "sFill= ."
:: sFill = 1000 spaces
set sFill=!sFill!!sFill!!sFill!!sFill!!sFill!!sFill!!sFill!!sFill!!sFill!!sFill!
set "sVar=!sVar!!sFill!"_
call set sVar=!!sVar:~0,%lVar%!!
) else (
set sVar=%2
)
call :write "!sVar!%~3"
(
endlocal
exit /b
)
:}
:: __________________________________________________________________ sub getFreeRAM
:: get available ram
:getFreeRAM {outVar} :{
for /f "skip=1" %%p in ('wmic os get freephysicalmemory') do (
set m=%%p
goto :getFreeRAMdone
)
:getFreeRAMdone
(
endlocal
set %1=%m%
exit /b
)
:}
:: __________________________________________________________________ sub getTotalRAM
:: Get total ram
:getTotalRAM :{
setlocal enableDelayedExpansion
if not defined tempFN set tempFN=%temp%\PS-%RANDOM%%RANDOM%%RANDOM%%RANDOM%.out.txt
for /F "TOKENS=2 DELIMS==" %%A in ('WMIC memorychip GET Capacity /VALUE') DO (
set SLO=%%A
set /a myGB=1024*1024*1024
set "myC=powershell -Command "!SLO:~0,-1!/!myGB!""
!myC! >"%tempFN%"
set /p xGB=<"%tempFN%"
)
(
endlocal
set %1=%xGB%
exit /b
):}
:: __________________________________________________________________ sub SetWallpaper
:: Set the Windows Wallpaper
:SetWallpaper strVar :{
set myWP=%~1
copy "%myWP%" "C:\Windows\DNXWallPaper.jpg" >nul
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "C:\Windows\DNXWallPaper.jpg" /f >nul
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
powershell sleep 5
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
(
exit /b
)
:}
:: ================================================================================================
:: ================================================================================================
:: ================================================================================================
:: __________________________________________________________________ sub InitMyScript
:: Initialization user script
:InitMyScript :{
set "BaseDirProc=%~dp1"
set "ScriptPath=%~1"
:: subscripts windows mode when launched. MAX MIN NORMAL FILEOUT
set rSUBPROC=NORMAL
::Color for subscript windows
set rSUBPROCCOLOR=8F
::filename for temp outfiles
set tempFN=%temp%\PS-%RANDOM%%RANDOM%%RANDOM%%RANDOM%.out.txt
rem echo BaseDirProc=%BaseDirProc%
set xmyIcon=%BaseDirProc%Extras\DNXDOScript.ico
set myIconN=0
set myIcon=%xmyIcon%
if NOT exist "%xmyIcon%" (
echo asignando icono por defecto
set myIcon=%SystemRoot%\System32\SHELL32.dll,130
set myIconN=126
)
(
exit /b
)
:}
:: __________________________________________________________________ sub ProcessDir
:: Process files in folder
:ProcessDir strFolder strMask strTitle :{
set strFolder=%~1
set strMask=%~2
set sTitle=%~3
echo.
call :ctext "%sTitle%" sTXT yellow strong
echo %sTXT%
for /r "%strFolder%" %%i in (%strMask%) do (
call :sSplit "%%~ni" "_" sVar1 sVar2 sVar3 sVar4 sVar5 sVar6 sVar7
call :writeL "- !sVar2!" 76 "["
call :stringPS "%%i" sPS
set "sCMD=start /WAIT /%rSUBPROC% powershell -Command "cmd /C color %rSUBPROCCOLOR%; !sPS!""
set myXT=%%~xi
set sLet=!myXT:~1,1!
if "%%~xi"==".reg" (
regedit /s !sCMD!
) else (
!sCMD!
rem !sCMD! >!tempFN!
)
call :write "!sLet!"
%sELOK%
)
(
exit /b
)
:}
:: __________________________________________________________________ sub ToStartScript
:: Start User Script
:ToStartScript :{
call :initMyScript "%~0" "%~1" "%~2" "%~3" "%~4" "%~5" "%~6" "%~7" "%~8" "%~9"
call :ctext "W4RHH4WK" sW4R black normal green normal
call :ctext "## DNX ##" sDNX black normal green normal
call :ctext "OK" sOK yellow normal blue strong
call :ctext "NO" sNO black normal red strong
set sELOK=echo ] %sOK%!
set sELNOK=echo ] %sNO%!
set RunMode=%1
if "_%RunMode%"=="_/safe" (
set "RunMode=SAFE"
set "RMFilter=.safe"
) else (
set "RMFilter="
set "RunMode=NORMAL"
)
:: ___________________
:: goto :ToStartScript2
cls
rem goto :ToStartScript2
call :ctext "Deen0X Debloat and Optimization Script for Windows 10 v2.0: DNXDOScript" sTXT white strong cyan normal
title Deen0X Debloat and Optimization Script [DNXDOScript]
echo %sTXT%
echo -----------------------------------------------------------------------
echo.
echo The original script was created with focus on GPD gaming devices, for improve their performance
echo (basically GPD-WIN/WIN2) but you can try this on any windows 10 based device.
echo.
echo The original idea is based on the "Debloat Windows 10" project from "%sW4R%"
call :ctext "https://github.com/W4RH4WK/Debloat-Windows-10" sTXT blue strong white normal
echo %sTXT%
echo But i add my own code with stuff i found on internet, researching about how to gain performance
echo on low-powered machines for gaming.
echo.
echo For more information about this script and updates, visit the main page:
call :ctext "https://www.github.com/DNXDOScript" sTXT blue strong white normal
echo %sTXT%
echo.
echo.
echo.
call :cText "ATTENTION" sTXT black normal red strong
echo ===============================================================================================
echo ================================== %sTXT% ==================================================
echo ===============================================================================================
call :cText "WILL MODIFY IN DEEP YOUR CURRENT WINDOWS INSTALLATION" sTXT black normal red strong
echo This procedure %sTXT% and cannot
echo be reverted
echo.
echo There is any kind of warranty about their execution, so i recommend to create a
echo backup/recover point on windows before running this script.
call :ctext "You will use this at your own risk." sTXT red strong white normal
echo %sTXT%
echo.
echo ===============================================================================================
echo ===============================================================================================
Timeout /T 5
echo (10 seconds timer. default answer is No)
call :ctext "Do you want to contine?" sTXT black normal white strong
call :write "%sTXT%"
choice /C YN /N /T 10 /D N /M " [Y]es/[N]o "
if errorlevel 2 goto :ToEnd
echo.
echo This script can run in two modes:
echo SAFE - Run only scripts considered safe to run on any machine. This
echo mode will not in-deep modify the system, but their effect is
echo limited compared than the NORMAL mode.
echo Use this mode for machines that you will use for working.
echo NORMAL - Run all enabled scripts. In deep modifications on the system.
echo Use this mode for machines that you will use basically for
echo gaming, such GPD-WIN/WIN2, Tablets, etc.
choice /c SN /M "Run in Safe or Normal mode?"
if errorlevel 2 (
set "RMFilter="
set "RunMode=NORMAL"
)
if errorlevel 1 (
set "RMFilter=.safe"
set "RunMode=SAFE"
)
echo selected %RunMode% mode
echo.
echo (10 seconds timer. default Minimized)
choice /c NM /D M /T 10 /M "Run SubScripts in Normal or Minimized mode?"
if errorlevel 2 (
set "rSUBPROC=MIN"
)
if errorlevel 1 (
set "rSUBPROC=NORMAL"
)
echo selected %rSUBPROC% mode
echo (10 seconds timer. default is Yes)
choice /c YN /D Y /T 10 /M "Create restore point?"
if errorlevel 1 (
powershell Enable-ComputerRestore -Drive 'C:\'
powershell.exe -ExecutionPolicy Bypass -Command "Checkpoint-Computer -Description "MyRestorePoint" -RestorePointType "MODIFY_SETTINGS""